Function Repository Resource:

KleinBottleGraph

Source Notebook

Create a grid graph in the shape of a Klein bottle

Contributed by: Richard Hennigan (Wolfram Research)

ResourceFunction["KleinBottleGraph"][{a,b}]

gives an a×b grid connected as a Graph that corresponds to the 1-skeleton of the Klein bottle.

ResourceFunction["KleinBottleGraph"][{a,b,n1,,nk}]

gives a graph corresponding to the product of the Klein bottle and a k-torus.

Details and Options

ResourceFunction["KleinBottleGraph"] takes the same options as Graph.

Examples

Basic Examples (3) 

Make a 3×3 Klein bottle graph:

In[1]:=
ResourceFunction["KleinBottleGraph"][{3, 3}]
Out[1]=

Compare to a torus graph:

In[2]:=
ResourceFunction["TorusGraph"][{3, 3}]
Out[2]=

Make a 10×20 Klein bottle graph:

In[3]:=
ResourceFunction["KleinBottleGraph"][{10, 20}]
Out[3]=

Compare to a torus graph:

In[4]:=
ResourceFunction["TorusGraph"][{10, 20}]
Out[4]=

The Klein bottle is a torus with a "twist":

In[5]:=
Graph3D[ResourceFunction["KleinBottleGraph"][{20, 25}]]
Out[5]=

Compare to a torus graph:

In[6]:=
Graph3D[ResourceFunction["TorusGraph"][{20, 25}]]
Out[6]=

Scope (1) 

Make a 10×15×5 Klein bottle graph:

In[7]:=
ResourceFunction["KleinBottleGraph"][{10, 15, 5}]
Out[7]=

Properties and Relations (4) 

Define a torus graph and Klein bottle graph:

In[8]:=
kleinBottle = Graph3D[ResourceFunction["KleinBottleGraph"][{30, 20}]];
torus = Graph3D[ResourceFunction["TorusGraph"][{30, 20}]];

Much like the torus, cutting the Klein bottle in one direction yields a cylinder:

In[9]:=
VertexDelete[kleinBottle, {{1, _}}]
Out[9]=
In[10]:=
VertexDelete[torus, {{1, _}}]
Out[10]=

However, cutting the Klein bottle in the other direction yields a Möbius strip:

In[11]:=
VertexDelete[kleinBottle, {{_, 1}}]
Out[11]=

The torus still produces a cylinder:

In[12]:=
VertexDelete[torus, {{_, 1}}]
Out[12]=

In one dimension, KleinBottleGraph is equivalent to TorusGraph:

In[13]:=
ResourceFunction["KleinBottleGraph"][{10}]
Out[13]=
In[14]:=
IsomorphicGraphQ[%, ResourceFunction["TorusGraph"][{10}]]
Out[14]=

Compute the volumes of neighborhoods around a node in the Klein bottle graph:

In[15]:=
Take[First[
  ResourceFunction["GraphNeighborhoodVolumes"][
   ResourceFunction["KleinBottleGraph"][{50, 50}], "Random" -> 1]], UpTo[25]]
Out[15]=

Estimate the dimension of the Klein bottle from its graph:

In[16]:=
ListLinePlot[ResourceFunction["LogDifferences"][%]]
Out[16]=

This yields the same estimate as the torus:

In[17]:=
Take[First[
  ResourceFunction["GraphNeighborhoodVolumes"][
   ResourceFunction["TorusGraph"][{50, 50}], "Random" -> 1]], UpTo[25]]
Out[17]=
In[18]:=
ListLinePlot[ResourceFunction["LogDifferences"][%]]
Out[18]=

Perform a three-way comparison between grid graphs, toroidal grid graphs and Klein bottle graphs:

In[19]:=
#[{2, 2}] & /@ {GridGraph, ResourceFunction["TorusGraph"], ResourceFunction["KleinBottleGraph"]}
Out[19]=
In[20]:=
#[{2, 2, 2}] & /@ {GridGraph, ResourceFunction["TorusGraph"], ResourceFunction["KleinBottleGraph"]}
Out[20]=
In[21]:=
LayeredGraphPlot[#[{10, 10}]] & /@ {GridGraph, ResourceFunction[
  "TorusGraph"], ResourceFunction["KleinBottleGraph"]}
Out[21]=

Neat Examples (2) 

Show how a ball of radius r grows in the graph when represented as a flat grid (the red edge indicates where the "twist" occurs):

In[22]:=
DynamicModule[{size, dims, kleinBottle, torus},
 size = 20;
 dims = {size, size};
 kleinBottle = ResourceFunction["KleinBottleGraph"][dims];
 torus = ResourceFunction["TorusGraph"][dims];
 Manipulate[
  Graphics[{
    Cuboid /@ VertexList[NeighborhoodGraph[graph, Floor[pt], r]],
    Red, Thickness[0.025],
    Line[{{1, 1}, {1, size}}],
    Line[{{size + 1, 1}, {size + 1, size}}]
    }, PlotRange -> {{1, size + 1}, {1, size + 1}}],
  {{pt, {2, 6}}, Locator},
  {{r, 5}, 0, size, 1},
  {graph, {kleinBottle -> "Klein Bottle", torus -> "Torus"}}
  ]
 ]
Out[22]=

Visualize the 3D case:

In[23]:=
DynamicModule[{s, dims, kleinBottle, torus},
 s = 20;
 dims = {s, s, s};
 kleinBottle = ResourceFunction["KleinBottleGraph"][dims];
 torus = ResourceFunction["TorusGraph"][dims];
 Manipulate[
  Graphics3D[{
    Cuboid /@ VertexList[NeighborhoodGraph[graph, {x, y, z}, r]],
    Red, Opacity[.25],
    Polygon[{{1, 1, 1}, {1, s + 1, 1}, {1, s + 1, s + 1}, {1, 1, s + 1}}],
    Polygon[{{s + 1, 1, 1}, {s + 1, s + 1, 1}, {s + 1, s + 1, s + 1}, {s + 1, 1, s + 1}}]
    }, PlotRange -> {{1, s + 1}, {1, s + 1}, {1, s + 1}}],
  {{x, 1}, 1, s, 1},
  {{y, 5}, 1, s, 1},
  {{z, 5}, 1, s, 1},
  {{r, 4}, 0, s, 1},
  {graph, {kleinBottle -> "Klein Bottle", torus -> "Torus"}}
  ]
 ]
Out[23]=

Version History

  • 3.0.0 – 28 April 2020
  • 1.0.0 – 22 April 2020

Source Metadata

Related Resources

License Information