Skip to content

Triangulation

Triangulation

Triangulation(poly, pts, make_star=False, simplices=None, check_input_simplices=True, heights=None, check_heights=True, backend='cgal', verbosity=1, seed=None)

A triangulation of a lattice point configuration.

This class handles triangulations of point configurations made of lattice points of a polytope. It can compute various properties of the triangulation, such as its simplices, secondary cone, and GKZ vector, and it can construct a ToricVariety or CalabiYau object if the triangulation is suitable.

The triangulation is either given explicitly by a list of simplices, or it is computed with one of the backends, usually as the regular triangulation induced by a height vector (see the heights argument). The points are specified by their labels in the ambient polytope, and their order in pts determines the indexing of the points of the triangulation (e.g. in the output of points and in the as_indices options).

Warning

Generally, objects of this class should not be constructed directly by the end user. Instead, they should be created by functions such as Polytope.triangulate, which pick the points and ordering conventions appropriately.

Parameters:

  • poly (Polytope) –

    The ambient polytope of the points to be triangulated.

  • pts (ArrayLike) –

    The points to be triangulated, specified by their labels in poly.

  • make_star (bool, default: False ) –

    Whether to turn the triangulation into a star triangulation with respect to the origin. With the CGAL backend this is done by decreasing the height of the origin until it is in every simplex. Otherwise it is done by deleting the simplices containing interior lines and connecting the origin to the boundary simplices, which requires the polytope to be reflexive. This flag is ignored if the origin is not one of the points.

  • simplices (ArrayLike | None, default: None ) –

    The simplices specifying the triangulation, each given as a list of point labels. This is useful when a triangulation was previously computed and needs to be used again. If not specified, the triangulation is computed from heights with the chosen backend.

  • check_input_simplices (bool, default: True ) –

    Whether to check that the input simplices define a valid triangulation.

  • heights (list | None, default: None ) –

    The heights specifying the regular triangulation. Only used if simplices is not given, and only supported by the CGAL and QHull backends. If not specified, the triangulation is constructed based on the backend: CGAL uses the Delaunay triangulation, QHull uses random heights near the Delaunay heights, and TOPCOM computes a fine triangulation.

  • check_heights (bool, default: True ) –

    Whether to check that the heights define a unique triangulation, i.e. that they do not lie on a wall of the secondary cone. If they do, they are discarded and recomputed when heights is called.

  • backend (str, default: 'cgal' ) –

    The backend used to compute the triangulation. Options are "cgal", "qhull", and "topcom". CGAL is the default as it is very fast and robust.

  • verbosity (int, default: 1 ) –

    The verbosity level.

  • seed (int | None, default: None ) –

    Seed for the height perturbation used by the QHull backend. Only that backend perturbs its heights, so this has no effect for CGAL or TOPCOM. If not specified, the perturbation is drawn afresh each time and the triangulation is not reproducible.

Raises:

  • ValueError –

    If pts is empty or contains labels that are not in poly, if the backend is invalid, if the number of heights does not match the number of points, or if the input simplices are empty, have the wrong dimension, contain unknown labels, or do not form a valid triangulation.

Examples:

We construct a triangulation of a polytope. Since this class is not intended to be initialized by the end user, we create it via Polytope.triangulate. In this example the polytope is reflexive, so by default the triangulation is fine, regular, and star. Also, since the polytope is reflexive, by default only the lattice points not interior to facets are included in the triangulation.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> print(t)
A fine, regular, star triangulation of a 4-dimensional point configuration...

Methods:

  • ambient_dimension –

    Return the dimension of the ambient lattice.

  • automorphism_orbit –

    Return the orbit of the triangulation under polytope automorphisms.

  • check_heights –

    Check whether the stored heights uniquely define the triangulation.

  • clear_cache –

    Clear the cached results of any previous computation.

  • dimension –

    Return the dimension of the triangulated point configuration.

  • get_cy –

    Return the Calabi-Yau defined by the triangulation.

  • get_toric_variety –

    Return the toric variety defined by the fan of the triangulation.

  • gkz_phi –

    Return the GKZ phi vector of the triangulation.

  • heights –

    Return a height vector that generates the triangulation.

  • is_equivalent –

    Return whether two triangulations are equivalent.

  • is_fine –

    Return whether the triangulation is fine.

  • is_regular –

    Return whether the triangulation is regular.

  • is_star –

    Return whether the triangulation is star.

  • is_valid –

    Return whether the simplices form a valid triangulation.

  • neighbor_triangulations –

    Return the triangulations that differ by one bistellar flip.

  • points –

    Return the points of the triangulation.

  • points_to_indices –

    Return the indices corresponding to the given points.

  • points_to_labels –

    Return the labels corresponding to the given points.

  • polytope –

    Return the ambient polytope of the triangulated points.

  • random_flips –

    Return a triangulation obtained by performing random bistellar flips.

  • restrict –

    Restrict the triangulation to one or more faces of the polytope.

  • secondary_cone –

    Compute the secondary cone of the triangulation.

  • simplices –

    Return the simplices of the triangulation.

  • sr_ideal –

    Return the Stanley-Reisner ideal of the triangulation.

  • triangulation_to_polytope_indices –

    Map indices of points of the triangulation to indices in the polytope.

Attributes:

  • labels –

    Return the labels of the points in the triangulation.

  • poly –

    Return the ambient polytope of the triangulated points.

labels property

labels

Return the labels of the points in the triangulation.

The order of the labels defines the indexing of the points of the triangulation.

Returns:

  • list | tuple –

    The labels of the points in the triangulation, in the order they were given at construction.

Examples:

We construct a triangulation and find the labels of its points. Since the polytope is reflexive, the points interior to facets (labels 7, 8, and 9 here) are not included by default.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.labels
[0, 1, 2, 3, 4, 5, 6]

poly property

poly

Return the ambient polytope of the triangulated points.

Returns:

ambient_dimension

ambient_dimension()

Return the dimension of the ambient lattice.

Also available as ambient_dim.

Returns:

  • int –

    The dimension of the ambient lattice.

Examples:

We construct a triangulation and find its ambient dimension.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.ambient_dim()
4

automorphism_orbit

automorphism_orbit(automorphism=None, on_faces_dim=None, on_faces_codim=None)

Return the orbit of the triangulation under polytope automorphisms.

This returns all of the triangulations of the point configuration that can be obtained by applying one or more polytope automorphisms to the triangulation. It also has the option of restricting the simplices to faces of the polytope of a particular dimension or codimension. This restriction is useful for checking CY equivalences from different triangulations. The result is cached.

Note

Depending on how the point configuration was constructed, it may be the case that the automorphism group of the point configuration is larger or smaller than the one of the polytope. This function only uses the subset of automorphisms of the polytope that are also automorphisms of the point configuration.

Parameters:

  • automorphism (int | ArrayLike | None, default: None ) –

    The index or list of indices of the polytope automorphisms to use, as ordered by Polytope.automorphisms. The orbit under the group generated by these automorphisms is computed. If not specified, all automorphisms are used.

  • on_faces_dim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given dimension.

  • on_faces_codim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given codimension. Ignored if on_faces_dim is specified.

Returns:

  • ndarray –

    The triangulations in the orbit, as a 3D array. Each entry is a sorted array of (possibly restricted) simplices, each specified by the sorted indices of its vertices in the list of points of the triangulation.

Raises:

Examples:

We construct a triangulation and find some of its automorphism orbits.

>>> from cytools import Polytope
>>> p = Polytope([[-1,0,0,0],[-1,1,0,0],[-1,0,1,0],[2,-1,0,-1],
...               [2,0,-1,-1],[2,-1,-1,-1],[-1,0,0,1],[-1,1,0,1],
...               [-1,0,1,1]])
>>> t = p.triangulate()
>>> orbit_all_autos = t.automorphism_orbit()
>>> len(orbit_all_autos)
36
>>> orbit_all_autos_2faces = t.automorphism_orbit(on_faces_dim=2)
>>> len(orbit_all_autos_2faces)
36
>>> orbit_sixth_auto = t.automorphism_orbit(automorphism=5)
>>> len(orbit_sixth_auto)
3
>>> orbit_list_autos = t.automorphism_orbit(automorphism=[5,6,9])
>>> len(orbit_list_autos)
12

check_heights

check_heights(verbosity=1)

Check whether the stored heights uniquely define the triangulation.

The heights uniquely define the triangulation if they do not lie on (or within \(10^{-6}\) of) a wall of its secondary cone. If they do not, the stored heights are deleted so that they are recomputed the next time heights is called. The simplices are kept unchanged.

Parameters:

  • verbosity (int, default: 1 ) –

    The verbosity level. A message is printed when the heights are discarded if this is greater than 1.

Returns:

  • bool –

    True if the heights uniquely define the triangulation, and False if they are within \(10^{-6}\) of a wall of the secondary cone.

clear_cache

clear_cache(recursive=False)

Clear the cached results of any previous computation.

Parameters:

  • recursive (bool, default: False ) –

    Whether to also clear the cache of the ambient polytope.

Examples:

We construct a triangulation, compute its GKZ vector, clear the cache and then compute it again.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> gkz_phi = t.gkz_phi()  # computes the GKZ vector
>>> t.clear_cache()
>>> gkz_phi = t.gkz_phi()  # the GKZ vector is recomputed

dimension

dimension()

Return the dimension of the triangulated point configuration.

This is the dimension of the affine span of the points, which can be smaller than the dimension of the ambient lattice.

Also available as dim.

Returns:

  • int –

    The dimension of the triangulation.

Examples:

We construct a triangulation and find its dimension.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> print(t.dimension())
4

get_cy

get_cy(nef_partition=None)

Return the Calabi-Yau defined by the triangulation.

By default this is the anti-canonical hypersurface in the toric variety defined by the fine, regular, star triangulation. If a nef-partition is specified then it returns the complete intersection Calabi-Yau that it specifies. This is a shortcut for calling ToricVariety.get_cy on the toric variety returned by get_toric_variety.

Also available as compute_cy and cy.

Note

Only Calabi-Yau 3-fold hypersurfaces are fully supported. Other dimensions and CICYs require enabling the experimental features of CYTools.

Parameters:

  • nef_partition (list[tuple[int]] | None, default: None ) –

    A list of tuples of indices specifying a nef-partition of the polytope, which correspondingly defines a complete intersection Calabi-Yau. If not specified, the anti-canonical hypersurface is used.

Returns:

  • CalabiYau –

    The Calabi-Yau arising from the triangulation.

Raises:

Examples:

We construct a triangulation and obtain the Calabi-Yau hypersurface in the resulting toric variety.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.get_cy()
A Calabi-Yau 3-fold hypersurface with h11=2 and h21=272 in a...

get_toric_variety

get_toric_variety()

Return the toric variety defined by the fan of the triangulation.

The fan is obtained by taking the cones over the simplices of the triangulation. The result is cached.

Returns:

  • ToricVariety –

    The toric variety arising from the triangulation.

Raises:

Examples:

We construct a triangulation and obtain the resulting toric variety.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.get_toric_variety()
A simplicial compact 4-dimensional toric variety with 9 affine patches

gkz_phi

gkz_phi()

Return the GKZ phi vector of the triangulation.

The \(i\)-th component is defined to be the sum of the normalized volumes of the simplices that have the \(i\)-th point as a vertex:

\[ \varphi^i = \sum_{\sigma\in\mathcal{T} \,:\, p_i\in\text{vert}(\sigma)} \text{vol}(\sigma). \]

The components are ordered as the points of the triangulation. The result is cached.

Returns:

  • ndarray –

    The GKZ phi vector of the triangulation.

Examples:

We construct a triangulation and find its GKZ vector.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.gkz_phi()
array([18, 12,  9, 12, 12, 12, 15])

heights

heights(integral=False, backend=None)

Return a height vector that generates the triangulation.

If the triangulation was constructed from heights (and they uniquely define it), those heights are returned, normalized to be non-negative with minimum 0. Otherwise, a point in the strict interior of the secondary cone is found with an optimizer and cached. Heights found this way are not normalized. An exception is raised if no height vector can be found, either because the optimizer failed or because the triangulation is not regular.

Parameters:

  • integral (bool, default: False ) –

    Whether to find an integral height vector. If the stored heights are non-integral, they are rescaled and rounded, which may introduce rounding errors (a warning is issued).

  • backend (str | None, default: None ) –

    The optimizer used for the computation. The available options are the backends of Cone.find_interior_point. If not specified, it is picked automatically.

Returns:

  • ndarray –

    A height vector giving rise to the triangulation, with one entry per point of the triangulation. Integral heights are returned as a signed integer array (so that differences of heights behave correctly), while non-integral heights are returned as float64.

Examples:

We construct a triangulation and find a height vector that generates it.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.heights()
array([0, 4, 1, 1, 1, 1], dtype=int8)

is_equivalent

is_equivalent(other, use_automorphisms=True, on_faces_dim=None, on_faces_codim=None)

Return whether two triangulations are equivalent.

The triangulations can be compared with or without allowing automorphism transformations, and with the option of restricting to faces of a particular dimension or codimension. Triangulations of different polytopes are never equivalent.

Parameters:

  • other (Triangulation) –

    The other triangulation that is being compared.

  • use_automorphisms (bool, default: True ) –

    Whether to check the equivalence using automorphism transformations. This flag is ignored for point configurations that are not full-dimensional.

  • on_faces_dim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given dimension.

  • on_faces_codim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given codimension. Ignored if on_faces_dim is specified.

Returns:

  • bool –

    Whether the triangulations are equivalent under the specified parameters.

Examples:

We construct two triangulations and check whether they are equivalent under various conditions.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[-1,1,1,0],
...               [0,-1,-1,0],[0,0,0,1],[1,-2,1,1],[-2,2,1,-1],
...               [1,1,-1,-1]])
>>> triangs_gen = p.all_triangulations()
>>> t1 = next(triangs_gen)
>>> t2 = next(triangs_gen)
>>> t1.is_equivalent(t2)
False
>>> t1.is_equivalent(t2, on_faces_dim=2)
True
>>> t1.is_equivalent(t2, on_faces_dim=2, use_automorphisms=False)
True

is_fine

is_fine()

Return whether the triangulation is fine.

A triangulation is fine if all the points are used as vertices of some simplex. Note that this only checks if it is fine with respect to the point configuration, not with respect to the full set of lattice points of the polytope.

Returns:

  • bool –

    Whether the triangulation is fine.

Examples:

We construct a triangulation and check if it is fine.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.is_fine()
True

is_regular

is_regular(backend=None)

Return whether the triangulation is regular.

A triangulation is regular if it is induced by some height vector, which happens if and only if its secondary cone is solid. The result is cached.

Parameters:

  • backend (str | None, default: None ) –

    The optimizer used for the computation. The available options are the backends of Cone.is_solid. If not specified, it is picked automatically.

Returns:

  • bool –

    Whether the triangulation is regular.

Examples:

We construct a triangulation and check if it is regular.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.is_regular()
True

is_star

is_star(star_origin=None)

Return whether the triangulation is star.

A triangulation is star with respect to a point if that point is a vertex of every simplex. By default the star origin is taken to be the origin, so for point configurations that don't contain the origin this function always returns False unless star_origin is specified.

Parameters:

  • star_origin (int | None, default: None ) –

    The label of the point to use as the star origin. If not specified, the origin is used.

Returns:

  • bool –

    Whether the triangulation is star.

Examples:

We construct a triangulation and check if it is star.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.is_star()
True

is_valid

is_valid(backend=None, verbosity=0)

Return whether the simplices form a valid triangulation.

The simplices must cover the full volume of the convex hull of the points, and they cannot intersect at full-dimensional regions. If the triangulation is regular, this is checked by verifying that a height vector in its secondary cone generates the same triangulation. Otherwise, the volumes and pairwise intersections of the simplices are checked directly, which can be quite slow for large polytopes. The result is cached.

Parameters:

  • backend (str | None, default: None ) –

    The optimizer used to check regularity. The available options are the backends of Cone.is_solid. If not specified, it is picked automatically.

  • verbosity (int, default: 0 ) –

    The verbosity level.

Returns:

  • bool –

    Whether the triangulation is valid.

Examples:

This function is useful when constructing a triangulation from a given set of simplices. Note that, unless check_input_simplices=False is passed, the validity of the input simplices is already checked when the triangulation is constructed.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> simps = [[0,1,2,3,4],[0,1,2,3,5],[0,1,2,4,5],[0,1,3,4,5],[0,2,3,4,5]]
>>> t = p.triangulate(simplices=simps, check_input_simplices=False)
>>> t.is_valid()
True

neighbor_triangulations

neighbor_triangulations(only_fine=False, only_regular=False, only_star=False, two_neighbors=False, two_neighbors_track_flips=False, backend=None, verbose=False)

Return the triangulations that differ by one bistellar flip.

The flips are computed with TOPCOM (through triangulumancer). There is the option of limiting the flips to fine, regular, and star triangulations. Regularity is checked with a separate optimizer, since checking it with TOPCOM is very slow for large polytopes. For fine 2-dimensional triangulations with only_fine=True, a faster native implementation is used. A trivial triangulation (with a single simplex) has no neighbors computed, and an empty list is returned with a warning.

Also available as neighbors.

Parameters:

  • only_fine (bool, default: False ) –

    Whether to restrict to fine triangulations.

  • only_regular (bool, default: False ) –

    Whether to restrict to regular triangulations.

  • only_star (bool, default: False ) –

    Whether to restrict to star triangulations.

  • two_neighbors (bool, default: False ) –

    Whether to return the 2-neighbors instead. FRSTs with the same restrictions to 2-faces give equivalent Calabi-Yau hypersurfaces, so each FRST represents an equivalence class. The 2-neighbors are representatives of the classes that differ by a single diagonal flip of one 2-face, which gives the neighboring Calabi-Yaus more directly. The 2-neighbors are fine and regular by construction, so only_fine and only_regular are ignored. They are star if only_star is true or if this triangulation is star.

  • two_neighbors_track_flips (bool, default: False ) –

    Only valid with two_neighbors. If true, return (triangulation, face_index, circuit) tuples instead of bare triangulations. face_index indexes polytope.faces(2) and circuit is the sorted tuple of the four point labels spanning the flipped quadrilateral.

  • backend (str | None, default: None ) –

    The backend used to check regularity. The options are the backends of Cone.is_solid. If not specified, it is picked automatically. When two_neighbors is true, it is instead passed on as the triangulation backend of Polytope.triangulate.

  • verbose (bool, default: False ) –

    Currently unused.

Returns:

  • list –

    The triangulations that differ by one bistellar flip from the current triangulation, or the 2-neighbors if two_neighbors is true. If two_neighbors_track_flips is also true, the entries are (triangulation, face_index, circuit) tuples.

Raises:

  • ValueError –

    If two_neighbors_track_flips is true but two_neighbors is not.

Examples:

We construct a triangulation and find its neighbor triangulations.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],
...               [-1,-1,-1,-1]]).dual()
>>> t = p.triangulate()
>>> triangs = t.neighbor_triangulations()
>>> len(triangs)  # print how many triangulations it found
263

We now find the 2-neighbors of an FRST, keeping track of the flipped 2-faces.

>>> p = Polytope([[0,0,1,0],[-2,-2,-1,-2],[0,0,1,2],[-1,0,1,0],
...               [1,2,-2,-1],[-1,0,0,-1],[0,1,0,0],[1,0,0,0]])
>>> t = p.triangulate()
>>> nbrs = t.neighbor_triangulations(two_neighbors=True,
...                                  two_neighbors_track_flips=True)
>>> [(face_index, circuit) for _, face_index, circuit in nbrs]
[(0, (1, 6, 7, 9)), (21, (4, 8, 10, 12))]

points

points(which=None, optimal=False, as_poly_indices=False, as_triang_indices=False, check_labels=True)

Return the points of the triangulation.

Note that these are not necessarily equal to the lattice points of the polytope they define. The points are returned in the order of labels (or in the order given by which).

Also available as pts.

Parameters:

  • which (int | Iterable | None, default: None ) –

    Which points to return, specified by a single label or a list of labels (not indices). If not specified, all points of the triangulation are returned.

  • optimal (bool, default: False ) –

    Whether to return the points in their optimal coordinates. For triangulations that are not full-dimensional, the points are expressed in an LLL-reduced lattice basis of their affine span, so they have dim() coordinates.

  • as_poly_indices (bool, default: False ) –

    Whether to return the indices of the points in the full list of points of the polytope instead of their coordinates.

  • as_triang_indices (bool, default: False ) –

    Whether to return the indices of the points in the list of points of the triangulation instead of their coordinates.

  • check_labels (bool, default: True ) –

    Whether to check that the labels in which belong to the triangulation.

Returns:

  • ndarray | list[int] –

    The points, one per row. If as_triang_indices is true, a 1D array of indices is returned instead, and if as_poly_indices is true, a list of indices is returned.

Raises:

  • ValueError –

    If both as_poly_indices and as_triang_indices are true, or if check_labels is true and some of the labels in which are not labels of the triangulation.

Examples:

We construct a triangulation and print the points in the point configuration. Note that since the polytope is reflexive, by default only the lattice points not interior to facets are used.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.points()
array([[ 0,  0,  0,  0],
       [-1, -1, -6, -9],
       [ 0,  0,  0,  1],
       [ 0,  0,  1,  0],
       [ 0,  1,  0,  0],
       [ 1,  0,  0,  0],
       [ 0,  0, -2, -3]])
>>> t.points(which=[1, 6])
array([[-1, -1, -6, -9],
       [ 0,  0, -2, -3]])

If the triangulation does not include all the points of the polytope, the indices in the triangulation and in the polytope can differ.

>>> t2 = p.triangulate(points=[0,1,2,3,4,5,6,8])
>>> t2.points(which=[8], as_triang_indices=True)
array([7])
>>> t2.points(which=[8], as_poly_indices=True)
[8]

points_to_indices

points_to_indices(points, is_optimal=False, as_poly_indices=False)

Return the indices corresponding to the given points.

It also accepts a single point, in which case it returns the corresponding index. By default, the indices refer to the list of points of the triangulation.

Parameters:

  • points (ArrayLike) –

    A point or a list of points.

  • is_optimal (bool, default: False ) –

    Whether the points are given in the optimal coordinates of the polytope (True) or in the input coordinates (False).

  • as_poly_indices (bool, default: False ) –

    Whether to return the indices in the full list of points of the polytope instead of in the list of points of the triangulation.

Returns:

  • ndarray | list[int] | int –

    The indices corresponding to the given points, or the index of the point if only one is given. The indices are returned as an array, or as a list if as_poly_indices is true.

Examples:

We construct a triangulation and find the indices of some of its points.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.points_to_indices([-1,-1,-6,-9])  # a single point
np.int64(1)
>>> t.points_to_indices([[-1,-1,-6,-9],[0,0,0,0],[0,0,1,0]])
array([1, 0, 3])

points_to_labels

points_to_labels(points, is_optimal=False)

Return the labels corresponding to the given points.

It also accepts a single point, in which case it returns the corresponding label. This simply calls Polytope.points_to_labels on the ambient polytope.

Parameters:

  • points (ArrayLike) –

    A point or a list of points.

  • is_optimal (bool, default: False ) –

    Whether the points are given in the optimal coordinates of the polytope (True) or in the input coordinates (False).

Returns:

  • list | int –

    The list of labels corresponding to the given points, or the label of the point if only one is given.

Examples:

We construct a triangulation and find the labels of some points.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.points_to_labels([[-1,-1,-6,-9],[0,0,0,0]])
[1, 0]

polytope

polytope()

Return the ambient polytope of the triangulated points.

This is the method form of the poly property.

Returns:

Examples:

We construct a triangulation and obtain its ambient polytope.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.polytope() == p
True

random_flips

random_flips(N, only_fine=None, only_regular=None, only_star=None, backend=None, seed=None)

Return a triangulation obtained by performing random bistellar flips.

At each step, a random neighbor triangulation (see neighbors) satisfying the requested restrictions is chosen. There is the option of limiting the flips to fine, regular, and star triangulations. Regularity is checked with a separate optimizer, since checking it with TOPCOM is very slow for large polytopes.

Parameters:

  • N (int) –

    The number of bistellar flips to perform.

  • only_fine (bool | None, default: None ) –

    Whether to restrict the flips to fine triangulations. If not specified, it is set to whether this triangulation is fine.

  • only_regular (bool | None, default: None ) –

    Whether to restrict the flips to regular triangulations. If not specified, it is set to whether this triangulation is regular.

  • only_star (bool | None, default: None ) –

    Whether to restrict the flips to star triangulations. If not specified, it is set to whether this triangulation is star.

  • backend (str | None, default: None ) –

    The backend used to check regularity. The options are the backends of Cone.is_solid. If not specified, it is picked automatically.

  • seed (int | None, default: None ) –

    A seed for the random number generator. This can be used to obtain reproducible results.

Returns:

  • Triangulation –

    A new triangulation obtained by performing N random flips.

Raises:

  • RuntimeError –

    If at some step no neighbor satisfies the requested restrictions.

Examples:

We construct a triangulation and perform 5 random flips to find a new triangulation.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],
...               [-1,-1,-1,-1]]).dual()
>>> t = p.triangulate()
>>> t.random_flips(5)  # takes a few seconds
A fine, regular, star triangulation of a 4-dimensional point...

restrict

restrict(restrict_to=None, restrict_dim=2, as_poly=False, verbosity=0)

Restrict the triangulation to one or more faces of the polytope.

The restriction of the triangulation to a face consists of the intersections of the simplices with the face that are full-dimensional simplices of the face.

Parameters:

  • restrict_to (PolytopeFace | Iterable[PolytopeFace] | None, default: None ) –

    The face or faces to restrict to. If not specified, the triangulation is restricted to each face of dimension restrict_dim.

  • restrict_dim (int, default: 2 ) –

    The dimension of the faces to restrict to. Only used if restrict_to is not specified.

  • as_poly (bool, default: False ) –

    Whether to return each restriction as a Triangulation object instead of as a list of simplices.

  • verbosity (int, default: 0 ) –

    The verbosity level.

Returns:

  • list | Triangulation –

    If a single face is given, the restriction to that face, as a sorted list of simplices (each a sorted list of point labels) or as a Triangulation if as_poly is true. Otherwise, a list with the restriction to each face.

Examples:

We construct a triangulation and restrict it to the 2-faces of the polytope.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.restrict()[:3]
[[[1, 2, 3]], [[1, 2, 4]], [[1, 2, 5]]]
>>> t.restrict(as_poly=True)[0]
A fine, regular, non-star triangulation of a 2-dimensional point...

secondary_cone

secondary_cone(backend=None, include_points_not_in_triangulation=True, as_cone=True, on_faces_dim=None, use_cache=True)

Compute the secondary cone of the triangulation.

This cone is also called the cone of strictly convex piecewise linear functions (CPL cone). It lives in the space of height vectors, with one coordinate per point of the triangulation. The triangulation is regular if and only if this cone is solid (i.e. full-dimensional), in which case the points in its strict interior are exactly the heights that give rise to the triangulation.

This function also allows the computation of the secondary cone of the \(N\)-skeleton, with \(N\) set by on_faces_dim. This cone is defined as either of the following equivalent descriptions:

  1. the intersection of the secondary cones of the restrictions of this triangulation to all \(N\)-dimensional faces of the polytope, or
  2. the union of the secondary cones of all triangulations with the same restrictions to \(N\)-dimensional faces.

Any point in the strict interior of this cone corresponds to heights that generate a triangulation with the same restrictions to the \(N\)-faces. Some cases of interest are:

  • \(N\) equal to the dimension of the triangulation, which gives the secondary cone of the triangulation.
  • \(N=2\), which gives the union of the secondary cones of all triangulations with the same 2-face restrictions (for FRSTs, these give rise to equivalent Calabi-Yau hypersurfaces). This is akin to \(\mathcal{K}_\cup\).

The secondary cone of the triangulation is cached, while the secondary cones of skeletons are always recomputed.

Also available as cpl_cone.

Parameters:

  • backend (str | None, default: None ) –

    The backend to use. Options are "native", which uses a native implementation of an algorithm by Berglund, Katz and Klemm, and "topcom", which uses differences of GKZ vectors of neighboring triangulations. If not specified, "native" is used when possible, i.e. when the triangulation is fine or include_points_not_in_triangulation is false, and "topcom" otherwise. Only the native backend is supported for skeletons.

  • include_points_not_in_triangulation (bool, default: True ) –

    Whether to include the points of the point configuration that are not vertices of any simplex. Excluding them can be done to check regularity faster, but it cannot be used if the actual cone in the secondary fan is needed.

  • as_cone (bool, default: True ) –

    Whether to return a Cone object. Otherwise, the list of hyperplane normals defining the cone is returned.

  • on_faces_dim (int | None, default: None ) –

    Compute the secondary cone of the restriction to each face of this dimension and return their intersection. This has the interpretation of fixing the triangulations of these faces, while being agnostic about the rest of the structure. If not specified, the full secondary cone of the triangulation is computed.

  • use_cache (bool, default: True ) –

    Whether to use the cached secondary cone, if available. The newly computed cone is cached either way.

Returns:

  • Cone | list –

    The secondary cone, or the list of hyperplane normals defining it if as_cone is false.

Raises:

  • ValueError –

    If an invalid backend is specified.

Examples:

We construct a triangulation and find its secondary cone.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.secondary_cone()
A rational polyhedral cone in RR^7 defined by 3 hyperplanes

simplices

simplices(on_faces_dim=None, on_faces_codim=None, split_by_face=False, as_np_array=True, as_indices=False)

Return the simplices of the triangulation.

It also has the option of restricting the simplices to faces of the polytope of a particular dimension or codimension. This restriction is useful for checking CY equivalences from different triangulations. The simplices are specified by the labels of their vertices unless as_indices is true.

Also available as simps.

Parameters:

  • on_faces_dim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given dimension.

  • on_faces_codim (int | None, default: None ) –

    Restrict the simplices to faces of the polytope of the given codimension (relative to the dimension of the triangulation). Ignored if on_faces_dim is specified.

  • split_by_face (bool, default: False ) –

    Whether to return the restricted simplices separately for each face, in the order of Polytope.faces, instead of merging them. Only used when restricting to faces.

  • as_np_array (bool, default: True ) –

    Whether to return the simplices as a numpy array. Otherwise, they are returned as a set of frozensets.

  • as_indices (bool, default: False ) –

    Whether to specify the simplices by the indices of their vertices in the list of points of the triangulation instead of by their labels.

Returns:

  • ndarray | set[frozenset] | list –

    The simplices of the triangulation, either as a 2D array with one simplex per row (sorted) or as a set of frozensets. If split_by_face is true, a list with one such array or set per face is returned.

Raises:

  • ValueError –

    If the requested face dimension is negative or larger than the dimension of the triangulation.

Examples:

We construct a triangulation and find its simplices. We also find the simplices that lie on 2-faces of the polytope.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-1,-1]])
>>> t = p.triangulate()
>>> t.simplices()
array([[0, 1, 2, 3, 4],
       [0, 1, 2, 3, 5],
       [0, 1, 2, 4, 5],
       [0, 1, 3, 4, 5],
       [0, 2, 3, 4, 5]], dtype=uint8)
>>> t.simplices(on_faces_dim=2)
array([[1, 2, 3],
       [1, 2, 4],
       [1, 2, 5],
       [1, 3, 4],
       [1, 3, 5],
       [1, 4, 5],
       [2, 3, 4],
       [2, 3, 5],
       [2, 4, 5],
       [3, 4, 5]])

sr_ideal

sr_ideal()

Return the Stanley-Reisner ideal of the triangulation.

The Stanley-Reisner (SR) ideal is generated by the monomials corresponding to the sets of points (other than the origin) that are not all contained in any single simplex. This function returns the minimal such sets, i.e. the generators of the ideal, and not their multiples. The result is cached.

For example, the simplicial complex with simplices \(\{1,2,3\}\), \(\{1,2,4\}\), \(\{2,3,4\}\), and \(\{1,2,5\}\) has the sets \(\{3,5\}\), \(\{4,5\}\), \(\{1,3,4\}\), \(\{1,3,5\}\), \(\{1,4,5\}\), \(\{2,3,5\}\), \(\{2,4,5\}\), and \(\{3,4,5\}\) of points that do not appear together in a simplex. The SR ideal is generated by \(x_3x_5\), \(x_4x_5\), and \(x_1x_3x_4\), while monomials such as \(x_2x_3x_5\) are not included since they are multiples of these.

Returns:

  • tuple[tuple[int, ...], ...] –

    The generators of the SR ideal, each given as a sorted tuple of point labels. They are sorted by length and then lexicographically.

Raises:

Examples:

We construct a triangulation and find its SR ideal.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate()
>>> t.sr_ideal()
((np.uint8(1), np.uint8(4), 5), (np.uint8(2), np.uint8(3), 6))

triangulation_to_polytope_indices

triangulation_to_polytope_indices(inds)

Map indices of points of the triangulation to indices in the polytope.

Takes a list of indices of points in the triangulation (i.e. positions in labels) and returns the indices of the same points in the full list of points of the polytope.

Also available as points_to_poly_indices.

Parameters:

  • inds (Iterable[int]) –

    The indices of points in the triangulation.

Returns:

  • list[int] –

    The corresponding indices in the list of points of the polytope.

Examples:

We construct a triangulation that excludes some points of the polytope, and map triangulation indices to polytope indices.

>>> from cytools import Polytope
>>> p = Polytope([[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1],[-1,-1,-6,-9]])
>>> t = p.triangulate(points=[0,1,2,3,4,5,6,8])
>>> t.triangulation_to_polytope_indices([1, 7])
[1, 8]