# Constructing an I-graph

I am attempting to build I-graphs in MMA, i.e. the non-Generalized Petersen graphs, and I found some code from Eric Weisstein, but this is now outdated and doesn't run. I have attempted to switch the old commands from Combinatorica with the new versions, but it is not working. Can anyone help? Here is the old code:

Initialization

<< MathWorldGraphs


Code

IGraph[n_, j_, k_] := Module[{uu, u, vv, v},
uu = Array[u, n, 0];
vv = Array[v, n, 0];
{u, u}, Mod[#1[[1]] - #2[[1]] - j, n] == 0,
{v, v}, Mod[#1[[1]] - #2[[1]] - k, n] == 0,
{u, v}, #1[[1]] == #2[[1]]
] &,
Type -> Directed
], Flatten[Table[r Through[{Cos, Sin}[2 Pi s/n]], {r, 2}, {s, 0, n - 1}],
1]]
]
]

• Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. May 12 '15 at 2:00
• Could you show your updated version, and mention where and why the update is failing? May 12 '15 at 15:03
• @MarcoB, I changed MakeUndirected to UndirectedGraph. IGraph[n_, j_, k_] := Module[{uu, u, vv, v}, uu = Array[u, n, 0]; vv = Array[v, n, 0]; UndirectedGraph[ ChangeVertices[MakeGraph[Join[uu, vv], Switch[Head /@ {##}, {u, u}, Mod[#1[[1]] - #2[[1]] - j, n] == 0, {v, v}, Mod[#1[[1]] - #2[[1]] - k, n] == 0, {u, v}, #1[[1]] == #2[[1]] ] &, Type -> Directed ], Flatten[ Table[r Through[{Cos, Sin}[2 Pi s/n]], {r, 2}, {s, 0, n - 1}], 1]] ] ] IGraph[12, 3, 4]
– Mat
May 12 '15 at 23:51
• @MarcoB UndirectedGraph::graph: A graph object is expected at position 1 in UndirectedGraph[ChangeVertices(<<1>>,(1 0 Sqrt[3]/2 1/2 1/2 Sqrt[3]/2 0 1 -(1/2) Sqrt[3]/2 -(Sqrt[3]/2) 1/2 -1 0 -(Sqrt[3]/2) -(1/2) -(1/2) -(Sqrt[3]/2) 0 -1 1/2 -(Sqrt[3]/2) Sqrt[3]/2 -(1/2) 2 0 Sqrt[3] 1 1 Sqrt[3] 0 2 -1 Sqrt[3] -Sqrt[3] 1 -2 0 -Sqrt[3] -1 -1 -Sqrt[3] 0 -2 1 -Sqrt[3] Sqrt[3] -1 ))]. >>
– Mat
May 12 '15 at 23:52
• A temporary solution that might also help you in figuring out what changes to make would be to work with the old functions from Combinatorica. Let me see how that might work... May 13 '15 at 4:19

You can still use the old functions from Combinatorica, either to tide you over while you figure out the new ones, or as a semi-permanent solution. WRI has also provided a handy guide to transitioning from that package to the new built-in functions: "Upgrading from Combinatorica"

For example, in the case of the obsolete code you mentioned:

<< Combinatorica

IGraph[n_, j_, k_] := Module[
{uu, u, vv, v},
uu = Array[u, n, 0];
vv = Array[v, n, 0];
CombinatoricaMakeUndirected[
CombinatoricaChangeVertices[
CombinatoricaMakeGraph[
Join[uu, vv],
{u, u}, Mod[#1[[1]] - #2[[1]] - j, n] == 0,
{v, v}, Mod[#1[[1]] - #2[[1]] - k, n] == 0,
{u, v}, #1[[1]] == #2[[1]]
] &,
Type -> CombinatoricaDirected
],
Flatten[
Table[r Through[{Cos, Sin}[2 Pi s/n]], {r, 2}, {s, 0, n - 1}], 1]
]
]
]


When you load in Combinatorica, the system will warn you:

General::compat: Combinatorica Graph and Permutations functionality has been superseded by preloaded functionality. The package now being loaded may conflict with this. Please see the Compatibility Guide for details.

... but it will still function. In order to avoid conflicts, I added explicit contexts to the old functions from the Combinatorica package, so you know exactly what you are using.

Having done that, you can now obtain the sample graph you mentioned in the comments:

CombinatoricaShowGraph@IGraph[12, 3, 4]


Just using builtin graph functions:

IGraph[n_, j_, k_, opts : OptionsPattern[]] :=
Block[{vert, u, v}, vert = Join[Array[u, n, 0], Array[v, n, 0]];