12
$\begingroup$

First we craft a function to return the quadrant boundary based on Oppermann's Conjecture

a[n_] := (Mod[n, 2] + n^2 + 2 n)/4

Then we create a few lists

r = 10;
q = 1;
q1 = Table[a[q + 4 (n - 1)] <-> a[q + 4 (n)], {n, 1, r}];
q = 2;
q2 = Table[a[q + 4 (n - 1)] <-> a[q + 4 (n)], {n, 1, r}];
q = 3;
q3 = Table[a[q + 4 (n - 1)] <-> a[q + 4 (n)], {n, 1, r}];
q = 4;
q4 = Table[a[q + 4 (n - 1)] <-> a[q + 4 (n)], {n, 1, r}];
u = Flatten[Table[{(n - 1) <-> n}, {n, 2, a[4 + 4 r] + 1}]];

We produce the normal Ulam's Spiral

Graph[u]

Ulam's Spiral

We don't get the spiral when we attempt to combine the diagonal lists by using this

Graph[Union[u, q1, q2, q3, q4]]

Ulam Bad Spiral

How can we overlay the diagonals onto the spiral?

$\endgroup$
  • 2
    $\begingroup$ Honestly, I'm quite surprised that Graph[u] produces a spiral! None of the built-in layout methods give this specific layout. It must be treating this graph as a special case. $\endgroup$ – Szabolcs May 30 '12 at 10:57
  • $\begingroup$ I have linked from here math.stackexchange.com/questions/151902/… $\endgroup$ – Fred Kline May 31 '12 at 6:42
15
$\begingroup$

Starting with Graph[u] you can extract the coordinates of the vertices as follows

gr = Graph[u];
crds = AbsoluteOptions[gr, VertexCoordinates];

The graph including the diagonals can then be drawn according to

Graph[VertexList[gr], Union[u, q1, q2, q3, q4], crds]

Mathematica graphics

$\endgroup$
  • 2
    $\begingroup$ And I was silly enough to sit down and figure out a closed form for the vertex coordinate based on the index ... of course just extract them! $\endgroup$ – Szabolcs May 30 '12 at 11:16
3
$\begingroup$

You can also use GraphEmbedding to get the vertex coordinates:

Graph[VertexList[g = Graph[u]], Union[u, q1, q2, q3, q4],
      VertexCoordinates -> GraphEmbedding[g]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.