Sample Python Sessions

Several sample Python sessions are reproduced below. Each session was started by running regina-python from the command line.

Working with a triangulation

example$ regina-python
Regina 7.0
Software for low-dimensional topology
Copyright (c) 1999-2021, The Regina development team
>>> ################################
>>> #
>>> #  Sample Python Script
>>> #
>>> #  Illustrates different queries and actions on a 3-manifold triangulation
>>> #  and its normal surfaces.
>>> #
>>> #  See the file "triangulation.session" for the results of running this
>>> #  script.
>>> #
>>> ################################
>>>
>>> # Create a new (3,4,7) layered solid torus.  This is a 3-tetrahedron
>>> # triangulation of a solid torus.
>>> t = Example3.lst(3, 4)
>>> print(t)
Bounded orientable 3-D triangulation, f = ( 1 5 7 3 )
>>>
>>> # Print the full skeleton of the triangulation.
>>> print(t.detail())
Size of the skeleton:
  Tetrahedra: 3
  Triangles: 7
  Edges: 5
  Vertices: 1

Tetrahedron gluing:
  Tet  |  glued to:      (012)      (013)      (023)      (123)
  -----+-------------------------------------------------------
    0  |              boundary   boundary    1 (012)    1 (130)
    1  |               0 (023)    0 (312)    2 (013)    2 (120)
    2  |               1 (312)    1 (023)    2 (312)    2 (230)

Vertices:
  Tet  |  vertex:    0   1   2   3
  -----+--------------------------
    0  |             0   0   0   0
    1  |             0   0   0   0
    2  |             0   0   0   0

Edges:
  Tet  |  edge:   01  02  03  12  13  23
  -----+--------------------------------
    0  |           0   1   2   2   1   3
    1  |           1   2   3   3   2   4
    2  |           2   4   3   3   4   3

Triangles:
  Tet  |  face:  012 013 023 123
  -----+------------------------
    0  |           0   1   2   3
    1  |           2   3   4   5
    2  |           5   4   6   6


>>>
>>> # Calculate some algebraic properties of the triangulation.
>>> print(t.homology())
Z
>>> print(t.homologyBdry())
2 Z
>>>
>>> # Test for 0-efficiency, which asks Regina to search for certain types
>>> # of normal surfaces.
>>> print(t.isZeroEfficient())
False
>>>
>>> # Make our own list of vertex normal surfaces in standard coordinates.
>>> surfaces = NormalSurfaces(t, NS_STANDARD)
>>>
>>> # Print the full list of vertex normal surfaces.
>>> print(surfaces.detail())
Embedded, vertex surfaces
Coordinates: Standard normal (tri-quad)
Number of surfaces is 9
1 1 1 1 ; 0 0 0 || 1 1 0 0 ; 1 0 0 || 0 0 0 0 ; 0 2 0
0 0 1 1 ; 1 0 0 || 1 1 1 1 ; 0 0 0 || 1 1 1 1 ; 0 0 0
0 0 0 0 ; 0 2 0 || 0 0 1 1 ; 1 0 0 || 1 1 1 1 ; 0 0 0
0 0 0 0 ; 0 0 2 || 0 0 0 0 ; 0 2 0 || 0 0 1 1 ; 1 0 0
1 1 0 0 ; 0 0 1 || 1 1 0 0 ; 0 0 0 || 0 0 0 0 ; 0 1 0
3 3 0 0 ; 0 0 1 || 1 1 0 0 ; 0 0 2 || 1 1 0 0 ; 0 0 1
0 0 1 1 ; 1 0 0 || 1 1 0 0 ; 1 0 0 || 0 0 0 0 ; 0 2 0
0 0 0 0 ; 0 1 0 || 0 0 0 0 ; 1 0 0 || 0 0 0 0 ; 0 1 0
1 1 1 1 ; 0 0 0 || 1 1 1 1 ; 0 0 0 || 1 1 1 1 ; 0 0 0

>>>
>>> # Print the Euler characteristic and orientability of each surface.
>>> for s in surfaces:
...     print("Chi =", s.eulerChar(), "; Or =", s.isOrientable())
...
Chi = -1 ; Or = True
Chi = 0 ; Or = True
Chi = 0 ; Or = True
Chi = 0 ; Or = True
Chi = 0 ; Or = False
Chi = 1 ; Or = True
Chi = -2 ; Or = True
Chi = -1 ; Or = False
Chi = 1 ; Or = True
>>>
>>> # List all surfaces with more than one quad in the first tetrahedron.
>>> for s in surfaces:
...     if s.quads(0,0) + s.quads(0,1) + s.quads(0,2) > 1:
...         print(s)
...
0 0 0 0 ; 0 2 0 || 0 0 1 1 ; 1 0 0 || 1 1 1 1 ; 0 0 0
0 0 0 0 ; 0 0 2 || 0 0 0 0 ; 0 2 0 || 0 0 1 1 ; 1 0 0
>>>

Working with a packet tree

example$ regina-python
Regina 7.0
Software for low-dimensional topology
Copyright (c) 1999-2021, The Regina development team
>>> ################################
>>> #
>>> #  Sample Python Script
>>> #
>>> #  Illustrates the traversal and manipulation of an entire packet tree.
>>> #
>>> #  See the file "tree.session" for the results of running this script.
>>> #
>>> ################################
>>>
>>> # Recreate the original SnapPea census of cusped hyperbolic manifolds
>>> # triangulated by at most 5 tetrahedra.
>>> #
>>> # Since we are building a packet tree, we need to use PacketOfTriangulation3,
>>> # not the plain type Triangulation3 (which is not a packet type).
>>> census = Container()
>>> for i in range(415):
...     mfd = SnapPeaCensusManifold(SnapPeaCensusManifold.SEC_5, i)
...     census.append(make_packet(mfd.construct(), mfd.name()))
...
>>> # The triangulations are now all children of the "census" container.
>>> # Remove all triangulations with more than two tetrahedra.
>>> #
>>> # Since we are deleting children, we step through the children manually
>>> # instead of just iterating over children().
>>> tri = census.firstChild()
>>> while tri != None:
...     next = tri.nextSibling()
...     if tri.size() > 2:
...         tri.makeOrphan()
...     tri = next
...
>>> # Print the homology of each remaining triangulation.
>>> # This time we are not adding or removing children, so we can just iterate.
>>> for tri in census.children():
...     print(tri.label() + ":", tri.homology())
...
Gieseking manifold: Z
SnapPea m001: Z + Z_2
SnapPea m002: Z + Z_2
SnapPea m003: Z + Z_5
Figure eight knot complement: Z
>>>

Reporting progress of long operations

example$ regina-python
Regina 7.0
Software for low-dimensional topology
Copyright (c) 1999-2021, The Regina development team
>>> ################################
>>> #
>>> #  Sample Python Script
>>> #
>>> #  Illustrates progress reporting during long operations.
>>> #
>>> #  See the file "progress.session" for the results of running this script.
>>> #
>>> ################################
>>>
>>> import threading
>>> import time
>>>
>>> # Create an 18-tetrahedron triangulation of a knot complement with real
>>> # boundary faces (not an ideal vertex).  The knot is L106003 from the
>>> # knot/link census.  We used Regina to truncate the ideal vertex, and
>>> # then copied the isomorphism signature so that we can reconstruct the
>>> # triangulation here.
>>> sig = 'sfLfvQvwwMQQQccjghjkmqlonrnrqpqrnsnksaisnrobocksks'
>>> tri = Triangulation3(sig)
>>> print(tri)
Bounded orientable 3-D triangulation, f = ( 1 20 37 18 )
>>>
>>> # Create a progress tracker to use during the normal surface enumeration.
>>> # This will report the state of progress while the enumeration runs in
>>> # the background.
>>> tracker = ProgressTracker()
>>>
>>> # Start the normal surface enumeration in a new thread.
>>> surfaces = None
>>> def run():
...     global surfaces, tracker
...     surfaces = NormalSurfaces(tri, NS_STANDARD, NS_VERTEX,
...         NS_ALG_DEFAULT, tracker)
...
>>> thread = threading.Thread(target = run)
>>> thread.start()
>>>
>>> # At this point the enumeration is up and running.
>>> # Output a progress report every quarter-second until it finishes.
>>> while not tracker.isFinished():
...     print('Progress:', tracker.percent(), '%')
...     time.sleep(0.25)
...
Progress: 0.17578125 %
Progress: 54.20654296875 %
Progress: 91.80555555555556 %
>>>
>>> # The surface enumeration is now complete.
>>> thread.join()
>>> print(surfaces)
2319 embedded, vertex surfaces (Standard normal (tri-quad))
>>>