Library of commonly used, famous, or interesting polytopes¶
This module gathers several constructors of polytopes that can be reached
through polytopes.<tab>
. For example, here is the hypercube in dimension 5:
sage: polytopes.hypercube(5)
A 5-dimensional polyhedron in ZZ^5 defined as the convex hull of 32 vertices
The following constructions are available
-
class
sage.geometry.polyhedron.library.
Polytopes
¶ A class of constructors for commonly used, famous, or interesting polytopes.
-
Birkhoff_polytope
(n, backend=None)¶ Return the Birkhoff polytope with \(n!\) vertices.
The vertices of this polyhedron are the (flattened) \(n\) by \(n\) permutation matrices. So the ambient vector space has dimension \(n^2\) but the dimension of the polyhedron is \((n-1)^2\).
INPUT:
n
– a positive integer giving the size of the permutation matrices.backend
– the backend to use to create the polytope.
See also
sage.matrix.matrix2.Matrix.as_sum_of_permutations()
– return the current matrix as a sum of permutation matricesEXAMPLES:
sage: b3 = polytopes.Birkhoff_polytope(3) sage: b3.f_vector() (1, 6, 15, 18, 9, 1) sage: b3.ambient_dim(), b3.dim() (9, 4) sage: b3.is_lattice_polytope() True sage: p3 = b3.ehrhart_polynomial() # optional - latte_int sage: p3 # optional - latte_int 1/8*t^4 + 3/4*t^3 + 15/8*t^2 + 9/4*t + 1 sage: [p3(i) for i in [1,2,3,4]] # optional - latte_int [6, 21, 55, 120] sage: [len((i*b3).integral_points()) for i in [1,2,3,4]] [6, 21, 55, 120] sage: b4 = polytopes.Birkhoff_polytope(4) sage: b4.n_vertices(), b4.ambient_dim(), b4.dim() (24, 16, 9)
-
Gosset_3_21
(backend=None)¶ Return the Gosset \(3_{21}\) polytope.
The Gosset \(3_{21}\) polytope is a uniform 7-polytope. It has 56 vertices, and 702 facets: \(126\) \(3_{11}\) and \(576\) \(6\)-simplex. For more information, see the Wikipedia article 3_21_polytope.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: g = polytopes.Gosset_3_21(); g A 7-dimensional polyhedron in ZZ^8 defined as the convex hull of 56 vertices sage: g.f_vector() # not tested (~16s) (1, 56, 756, 4032, 10080, 12096, 6048, 702, 1)
-
Kirkman_icosahedron
(backend=None)¶ Return the Kirkman icosahedron.
The Kirkman icosahedron is a 3-polytope with integer coordinates: \((\pm 9, \pm 6, \pm 6)\), \((\pm 12, \pm 4, 0)\), \((0, \pm 12, \pm 8)\), \((\pm 6, 0, \pm 12)\). See [Fe2012] for more information.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: ki = polytopes.Kirkman_icosahedron() sage: ki.f_vector() (1, 20, 38, 20, 1) sage: ki.volume() 6528 sage: vertices = ki.vertices() sage: edges = [[vector(edge[0]),vector(edge[1])] for edge in ki.bounded_edges()] sage: edge_lengths = [norm(edge[0]-edge[1]) for edge in edges] sage: union(edge_lengths) [7, 8, 9, 11, 12, 14, 16]
-
static
associahedron
(cartan_type, backend='ppl')¶ Construct an associahedron.
The generalized associahedron is a polytopal complex with vertices in one-to-one correspondence with clusters in the cluster complex, and with edges between two vertices if and only if the associated two clusters intersect in codimension 1.
The associahedron of type \(A_n\) is one way to realize the classical associahedron as defined in the Wikipedia article Associahedron.
A polytopal realization of the associahedron can be found in [CFZ2002]. The implementation is based on [CFZ2002], Theorem 1.5, Remark 1.6, and Corollary 1.9.
INPUT:
cartan_type
– a cartan type according tosage.combinat.root_system.cartan_type.CartanTypeFactory
backend
– string ('ppl'
); the backend to use; seesage.geometry.polyhedron.constructor.Polyhedron()
EXAMPLES:
sage: Asso = polytopes.associahedron(['A',2]); Asso Generalized associahedron of type ['A', 2] with 5 vertices sage: sorted(Asso.Hrepresentation(), key=repr) [An inequality (-1, 0) x + 1 >= 0, An inequality (0, -1) x + 1 >= 0, An inequality (0, 1) x + 1 >= 0, An inequality (1, 0) x + 1 >= 0, An inequality (1, 1) x + 1 >= 0] sage: Asso.Vrepresentation() (A vertex at (1, -1), A vertex at (1, 1), A vertex at (-1, 1), A vertex at (-1, 0), A vertex at (0, -1)) sage: polytopes.associahedron(['B',2]) Generalized associahedron of type ['B', 2] with 6 vertices
The two pictures of [CFZ2002] can be recovered with:
sage: Asso = polytopes.associahedron(['A',3]); Asso Generalized associahedron of type ['A', 3] with 14 vertices sage: Asso.plot() # long time Graphics3d Object sage: Asso = polytopes.associahedron(['B',3]); Asso Generalized associahedron of type ['B', 3] with 20 vertices sage: Asso.plot() # long time Graphics3d Object
-
bitruncated_six_hundred_cell
(exact=True, backend=None)¶ Return the bitruncated 600-cell.
The bitruncated 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 3600 vertices. For more information see Wikipedia article Bitruncated 600-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.runcinated_six_hundred_cell(exact=True,backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 3600 vertices
-
buckyball
(exact=True, base_ring=None, backend=None)¶ Return the bucky ball.
The bucky ball, also known as the truncated icosahedron is an Archimedean solid. It has 32 faces and 60 vertices.
See also
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: bb = polytopes.buckyball() # long time - 6secs sage: bb.f_vector() # long time (1, 60, 90, 32, 1) sage: bb.base_ring() # long time Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
A much faster implementation using floating point approximations:
sage: bb = polytopes.buckyball(exact=False) sage: bb.f_vector() (1, 60, 90, 32, 1) sage: bb.base_ring() Real Double Field
Its facets are 5 regular pentagons and 6 regular hexagons:
sage: sum(1 for f in bb.facets() if len(f.vertices()) == 5) 12 sage: sum(1 for f in bb.facets() if len(f.vertices()) == 6) 20
-
cantellated_one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the cantellated 120-cell.
The cantellated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 3600 vertices. For more information see Wikipedia article Cantellated 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.cantellated_one_hundred_twenty_cell(backend='normaliz') # not tested - long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 3600 vertices
-
cantellated_six_hundred_cell
(exact=False, backend=None)¶ Return the cantellated 600-cell.
The cantellated 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 3600 vertices. For more information see Wikipedia article Cantellated 600-cell.
Warning
The coordinates are inexact by default. The computation with inexact coordinates (using the backend
'cdd'
) issues a UserWarning on inconsistencies.INPUT:
exact
- (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.cantellated_six_hundred_cell() # not tested - very long time doctest:warning ... UserWarning: This polyhedron data is numerically complicated; cdd could not convert between the inexact V and H representation without loss of data. The resulting object might show inconsistencies. A 4-dimensional polyhedron in RDF^4 defined as the convex hull of 3600 vertices
It is possible to use the backend
'normaliz'
to get an exact representation:sage: polytopes.cantellated_six_hundred_cell(exact=True,backend='normaliz') # not tested - long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 3600 vertices
-
cantitruncated_one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the cantitruncated 120-cell.
The cantitruncated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 7200 vertices. For more information see Wikipedia article Cantitruncated 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.cantitruncated_one_hundred_twenty_cell(exact=True,backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 7200 vertices
-
cantitruncated_six_hundred_cell
(exact=True, backend=None)¶ Return the cantitruncated 600-cell.
The cantitruncated 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 7200 vertices. For more information see Wikipedia article Cantitruncated 600-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.cantitruncated_six_hundred_cell(exact=True,backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 7200 vertices
-
cross_polytope
(dim, backend=None)¶ Return a cross-polytope in dimension
dim
.A cross-polytope is a higher dimensional generalization of the octahedron. It is the convex hull of the \(2d\) points \((\pm 1, 0, \ldots, 0)\), \((0, \pm 1, \ldots, 0)\), ldots, \((0, 0, \ldots, \pm 1)\). See the Wikipedia article Cross-polytope for more information.
INPUT:
dim
– integer. The dimension of the cross-polytope.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: four_cross = polytopes.cross_polytope(4) sage: four_cross.f_vector() (1, 8, 24, 32, 16, 1) sage: four_cross.is_simple() False
-
cube
(backend=None)¶ Return the cube.
The cube is the Platonic solid that is obtained as the convex hull of the points \((\pm 1, \pm 1, \pm 1)\). It generalizes into several dimension into hypercubes.
See also
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: c = polytopes.cube() sage: c A 3-dimensional polyhedron in ZZ^3 defined as the convex hull of 8 vertices sage: c.f_vector() (1, 8, 12, 6, 1) sage: c.volume() 8 sage: c.plot() Graphics3d Object
-
cuboctahedron
(backend=None)¶ Return the cuboctahedron.
The cuboctahedron is an Archimedean solid with 12 vertices and 14 faces dual to the rhombic dodecahedron. It can be defined as the convex hull of the twelve vertices \((0, \pm 1, \pm 1)\), \((\pm 1, 0, \pm 1)\) and \((\pm 1, \pm 1, 0)\). For more information, see the Wikipedia article Cuboctahedron.
INPUT:
backend
– the backend to use to create the polytope.
See also
EXAMPLES:
sage: co = polytopes.cuboctahedron() sage: co.f_vector() (1, 12, 24, 14, 1)
Its facets are 8 triangles and 6 squares:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 3) 8 sage: sum(1 for f in co.facets() if len(f.vertices()) == 4) 6
Some more computation:
sage: co.volume() 20/3 sage: co.ehrhart_polynomial() # optional - latte_int 20/3*t^3 + 8*t^2 + 10/3*t + 1
-
cyclic_polytope
(dim, n, base_ring=Rational Field, backend=None)¶ Return a cyclic polytope.
A cyclic polytope of dimension
dim
withn
vertices is the convex hull of the points(t,t^2,...,t^dim)
with \(t \in \{0,1,...,n-1\}\) . For more information, see the Wikipedia article Cyclic_polytope.INPUT:
dim
– positive integer. the dimension of the polytope.n
– positive integer. the number of vertices.base_ring
– eitherQQ
(default) orRDF
.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: c = polytopes.cyclic_polytope(4,10) sage: c.f_vector() (1, 10, 45, 70, 35, 1)
-
dodecahedron
(exact=True, base_ring=None, backend=None)¶ Return a dodecahedron.
The dodecahedron is the Platonic solid dual to the
icosahedron()
.INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– (optional) the ring in which the coordinates will belong to. Note that this ring must contain \(\sqrt(5)\). If it is not provided andexact=True
it will be the number field \(\QQ[\sqrt(5)]\) and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: d12 = polytopes.dodecahedron() sage: d12.f_vector() (1, 20, 30, 12, 1) sage: d12.volume() -176*sqrt5 + 400 sage: numerical_approx(_) 6.45203596003699 sage: d12 = polytopes.dodecahedron(exact=False) sage: d12.base_ring() Real Double Field
Here is an error with a field that does not contain \(\sqrt(5)\):
sage: polytopes.dodecahedron(base_ring=QQ) Traceback (most recent call last): ... TypeError: unable to convert 1/4*sqrt(5) + 1/4 to a rational
-
static
flow_polytope
(edges=None, ends=None, backend=None)¶ Return the flow polytope of a digraph.
The flow polytope of a directed graph is the polytope consisting of all nonnegative flows on the graph with a given set \(S\) of sources and a given set \(T\) of sinks.
A flow on a directed graph \(G\) with a given set \(S\) of sources and a given set \(T\) of sinks means an assignment of a nonnegative real to each edge of \(G\) such that the flow is conserved in each vertex outside of \(S\) and \(T\), and there is a unit of flow entering each vertex in \(S\) and a unit of flow leaving each vertex in \(T\). These flows clearly form a polytope in the space of all assignments of reals to the edges of \(G\).
The polytope is empty unless the sets \(S\) and \(T\) are equinumerous.
By default, \(S\) is taken to be the set of all sources (i.e., vertices of indegree \(0\)) of \(G\), and \(T\) is taken to be the set of all sinks (i.e., vertices of outdegree \(0\)) of \(G\). If a different choice of \(S\) and \(T\) is desired, it can be specified using the optional
ends
parameter.The polytope is returned as a polytope in \(\RR^m\), where \(m\) is the number of edges of the digraph
self
. The \(k\)-th coordinate of a point in the polytope is the real assigned to the \(k\)-th edge ofself
. The order of the edges is the one returned byself.edges()
. If a different order is desired, it can be specified using the optionaledges
parameter.The faces and volume of these polytopes are of interest. Examples of these polytopes are the Chan-Robbins-Yuen polytope and the Pitman-Stanley polytope [PS2002].
INPUT:
edges
– (optional, default:self.edges()
) a list or tuple of all edges ofself
(each only once). This determines which coordinate of a point in the polytope will correspond to which edge ofself
. It is also possible to specify a list which contains not all edges ofself
; this results in a polytope corresponding to the flows which are \(0\) on all remaining edges. Notice that the edges entered here must be in the precisely same format as outputted byself.edges()
; so, ifself.edges()
outputs an edge in the form(1, 3, None)
, then(1, 3)
will not do!ends
– (optional, default:(self.sources(), self.sinks())
) a pair \((S, T)\) of an iterable \(S\) and an iterable \(T\).backend
– string orNone
(default); the backend to use; seesage.geometry.polyhedron.constructor.Polyhedron()
Note
Flow polytopes can also be built through the
polytopes.<tab>
object:sage: polytopes.flow_polytope(digraphs.Path(5)) A 0-dimensional polyhedron in QQ^4 defined as the convex hull of 1 vertex
EXAMPLES:
A commutative square:
sage: G = DiGraph({1: [2, 3], 2: [4], 3: [4]}) sage: fl = G.flow_polytope(); fl A 1-dimensional polyhedron in QQ^4 defined as the convex hull of 2 vertices sage: fl.vertices() (A vertex at (0, 1, 0, 1), A vertex at (1, 0, 1, 0))
Using a different order for the edges of the graph:
sage: fl = G.flow_polytope(edges=G.edges(key=lambda x: x[0] - x[1])); fl A 1-dimensional polyhedron in QQ^4 defined as the convex hull of 2 vertices sage: fl.vertices() (A vertex at (0, 1, 1, 0), A vertex at (1, 0, 0, 1))
A tournament on 4 vertices:
sage: H = digraphs.TransitiveTournament(4) sage: fl = H.flow_polytope(); fl A 3-dimensional polyhedron in QQ^6 defined as the convex hull of 4 vertices sage: fl.vertices() (A vertex at (0, 0, 1, 0, 0, 0), A vertex at (0, 1, 0, 0, 0, 1), A vertex at (1, 0, 0, 0, 1, 0), A vertex at (1, 0, 0, 1, 0, 1))
Restricting to a subset of the edges:
sage: fl = H.flow_polytope(edges=[(0, 1, None), (1, 2, None), ....: (2, 3, None), (0, 3, None)]) sage: fl A 1-dimensional polyhedron in QQ^4 defined as the convex hull of 2 vertices sage: fl.vertices() (A vertex at (0, 0, 0, 1), A vertex at (1, 1, 1, 0))
Using a different choice of sources and sinks:
sage: fl = H.flow_polytope(ends=([1], [3])); fl A 1-dimensional polyhedron in QQ^6 defined as the convex hull of 2 vertices sage: fl.vertices() (A vertex at (0, 0, 0, 1, 0, 1), A vertex at (0, 0, 0, 0, 1, 0)) sage: fl = H.flow_polytope(ends=([0, 1], [3])); fl The empty polyhedron in QQ^6 sage: fl = H.flow_polytope(ends=([3], [0])); fl The empty polyhedron in QQ^6 sage: fl = H.flow_polytope(ends=([0, 1], [2, 3])); fl A 3-dimensional polyhedron in QQ^6 defined as the convex hull of 5 vertices sage: fl.vertices() (A vertex at (0, 0, 1, 1, 0, 0), A vertex at (0, 1, 0, 0, 1, 0), A vertex at (1, 0, 0, 2, 0, 1), A vertex at (1, 0, 0, 1, 1, 0), A vertex at (0, 1, 0, 1, 0, 1)) sage: fl = H.flow_polytope(edges=[(0, 1, None), (1, 2, None), ....: (2, 3, None), (0, 2, None), ....: (1, 3, None)], ....: ends=([0, 1], [2, 3])); fl A 2-dimensional polyhedron in QQ^5 defined as the convex hull of 4 vertices sage: fl.vertices() (A vertex at (0, 0, 0, 1, 1), A vertex at (1, 2, 1, 0, 0), A vertex at (1, 1, 0, 0, 1), A vertex at (0, 1, 1, 1, 0))
A digraph with one source and two sinks:
sage: Y = DiGraph({1: [2], 2: [3, 4]}) sage: Y.flow_polytope() The empty polyhedron in QQ^3
A digraph with one vertex and no edge:
sage: Z = DiGraph({1: []}) sage: Z.flow_polytope() A 0-dimensional polyhedron in QQ^0 defined as the convex hull of 1 vertex
-
generalized_permutahedron
(coxeter_type, point=None, exact=True, regular=False, backend=None)¶ Return the generalized permutahedron of type
coxeter_type
as the convex hull of the orbit ofpoint
in the fundamental cone.This generalized permutahedron lies in the vector space used in the geometric representation, that is, in the default case, the dimension of generalized permutahedron equals the dimension of the space.
INPUT:
coxeter_type
– a Coxeter type; given as a pair [type,rank], where type is a letter and rank is the number of generators.point
– a list (default:None
); a point given by its coordinates in the weight basis. IfNone
is given, the point \((1, 1, 1, \ldots)\) is used.exact
- (boolean, defaultTrue
) ifFalse
use floating point approximations instead of exact coordinatesregular
– boolean (default:False
); whether to apply a linear transformation making the vertex figures isometric.backend
– backend to use to create the polytope; (default:None
)
EXAMPLES:
sage: perm_a3 = polytopes.generalized_permutahedron(['A',3]); perm_a3 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 24 vertices
You can put the starting point along the hyperplane of the first generator:
sage: perm_a3_011 = polytopes.generalized_permutahedron(['A',3],[0,1,1]); perm_a3_011 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 12 vertices sage: perm_a3_110 = polytopes.generalized_permutahedron(['A',3],[1,1,0]); perm_a3_110 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 12 vertices sage: perm_a3_110.is_combinatorially_isomorphic(perm_a3_011) True sage: perm_a3_101 = polytopes.generalized_permutahedron(['A',3],[1,0,1]); perm_a3_101 A 3-dimensional polyhedron in QQ^3 defined as the convex hull of 12 vertices sage: perm_a3_110.is_combinatorially_isomorphic(perm_a3_101) False sage: perm_a3_011.f_vector() (1, 12, 18, 8, 1) sage: perm_a3_101.f_vector() (1, 12, 24, 14, 1)
The usual output does not necessarily give a polyhedron with isometric vertex figures:
sage: perm_a2 = polytopes.generalized_permutahedron(['A',2]) sage: perm_a2.vertices() (A vertex at (-1, -1), A vertex at (-1, 0), A vertex at (0, -1), A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1))
Setting
regular=True
applies a linear transformation to get isometric vertex figures and the result is inscribed. Even though there are traces of small numbers, the internal computations are done using an exact embedded NumberField:sage: perm_a2_reg = polytopes.generalized_permutahedron(['A',2],regular=True) sage: perm_a2_reg.vertices() (A vertex at (-1/2, -0.866025403784439?), A vertex at (-1, 0), A vertex at (1/2, -0.866025403784439?), A vertex at (-1/2, 0.866025403784439?), A vertex at (1.000000000000000?, 0.?e-18), A vertex at (0.500000000000000?, 0.866025403784439?)) sage: perm_a2_reg.is_inscribed() True sage: perm_a3_reg = polytopes.generalized_permutahedron(['A',3],regular=True) sage: perm_a3_reg.is_inscribed() True
The same is possible with vertices in
RDF
:sage: perm_a2_inexact = polytopes.generalized_permutahedron(['A',2],exact=False) sage: perm_a2_inexact.vertices() (A vertex at (0.0, 1.0), A vertex at (-1.0, 0.0), A vertex at (-1.0, -1.0), A vertex at (0.0, -1.0), A vertex at (1.0, 0.0), A vertex at (1.0, 1.0)) sage: perm_a2_inexact_reg = polytopes.generalized_permutahedron(['A',2],exact=False,regular=True) sage: perm_a2_inexact_reg.vertices() (A vertex at (-0.5, 0.8660254038), A vertex at (-1.0, 0.0), A vertex at (-0.5, -0.8660254038), A vertex at (0.5, -0.8660254038), A vertex at (1.0, 0.0), A vertex at (0.5, 0.8660254038))
It works also with types with non-rational coordinates:
sage: perm_b3 = polytopes.generalized_permutahedron(['B',3]); perm_b3 A 3-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?)^3 defined as the convex hull of 48 vertices sage: perm_b3_reg = polytopes.generalized_permutahedron(['B',3],regular=True); perm_b3_reg # not tested - long time (12sec on 64 bits). A 3-dimensional polyhedron in AA^3 defined as the convex hull of 48 vertices
It is faster with the backend
'normaliz'
:sage: perm_b3_reg_norm = polytopes.generalized_permutahedron(['B',3],regular=True,backend='normaliz') # optional - pynormaliz sage: perm_b3_reg_norm # optional - pynormaliz A 3-dimensional polyhedron in AA^3 defined as the convex hull of 48 vertices
The backend
'normaliz'
allows further faster computation in the non-rational case:sage: perm_h3 = polytopes.generalized_permutahedron(['H',3],backend='normaliz') # optional - pynormaliz sage: perm_h3 # optional - pynormaliz A 3-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790?)^3 defined as the convex hull of 120 vertices sage: perm_f4 = polytopes.generalized_permutahedron(['F',4],backend='normaliz') # optional - pynormaliz sage: perm_f4 # optional - pynormaliz A 4-dimensional polyhedron in (Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?)^4 defined as the convex hull of 1152 vertices
See also
permutahedron()
permutahedron()
-
grand_antiprism
(exact=True, backend=None, verbose=False)¶ Return the grand antiprism.
The grand antiprism is a 4-dimensional non-Wythoffian uniform polytope. The coordinates were taken from http://eusebeia.dyndns.org/4d/gap. For more information, see the Wikipedia article Grand_antiprism.
Warning
The coordinates are exact by default. The computation with exact coordinates is not as fast as with floating point approximations. If you find this method to be too slow, consider using floating point approximations
INPUT:
exact
- (boolean, defaultTrue
) ifFalse
use floating point approximations instead of exact coordinatesbackend
– the backend to use to create the polytope.
EXAMPLES:
sage: gap = polytopes.grand_antiprism() # not tested - very long time sage: gap # not tested - very long time A 4-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^4 defined as the convex hull of 100 vertices
Computation with the backend
'normaliz'
is instantaneous:sage: gap_norm = polytopes.grand_antiprism(backend='normaliz') # optional - pynormaliz sage: gap_norm # optional - pynormaliz A 4-dimensional polyhedron in (Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?)^4 defined as the convex hull of 100 vertices
Computation with approximated coordinates is also faster, but inexact:
sage: gap = polytopes.grand_antiprism(exact=False) # random sage: gap A 4-dimensional polyhedron in RDF^4 defined as the convex hull of 100 vertices sage: gap.f_vector() (1, 100, 500, 720, 320, 1) sage: len(list(gap.bounded_edges())) 500
-
great_rhombicuboctahedron
(exact=True, base_ring=None, backend=None)¶ Return the great rhombicuboctahedron.
The great rhombicuboctahedron (or truncated cuboctahedron) is an Archimedean solid with 48 vertices and 26 faces. For more information see the Wikipedia article Truncated_cuboctahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: gr = polytopes.great_rhombicuboctahedron() # long time ~ 3sec sage: gr.f_vector() # long time (1, 48, 72, 26, 1)
A faster implementation is obtained by setting
exact=False
:sage: gr = polytopes.great_rhombicuboctahedron(exact=False) sage: gr.f_vector() (1, 48, 72, 26, 1)
Its facets are 4 squares, 8 regular hexagons and 6 regular octagons:
sage: sum(1 for f in gr.facets() if len(f.vertices()) == 4) 12 sage: sum(1 for f in gr.facets() if len(f.vertices()) == 6) 8 sage: sum(1 for f in gr.facets() if len(f.vertices()) == 8) 6
-
hypercube
(dim, backend=None)¶ Return a hypercube in the given dimension.
The \(d\) dimensional hypercube is the convex hull of the points \((\pm 1, \pm 1, \ldots, \pm 1)\) in \(\RR^d\). For more information see the Wikipedia article Hypercube.
INPUT:
dim
– integer. The dimension of the cube.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: four_cube = polytopes.hypercube(4) sage: four_cube.is_simple() True sage: four_cube.base_ring() Integer Ring sage: four_cube.volume() 16 sage: four_cube.ehrhart_polynomial() # optional - latte_int 16*t^4 + 32*t^3 + 24*t^2 + 8*t + 1
-
hypersimplex
(dim, k, project=False, backend=None)¶ Return the hypersimplex in dimension
dim
and parameterk
.The hypersimplex \(\Delta_{d,k}\) is the convex hull of the vertices made of \(k\) ones and \(d-k\) zeros. It lies in the \(d-1\) hyperplane of vectors of sum \(k\). If you want a projected version to \(\RR^{d-1}\) (with floating point coordinates) then set
project=True
in the options.See also
INPUT:
dim
– the dimensionn
– the numbers(1,...,n)
are permutedproject
– (boolean, defaultFalse
) ifTrue
, the polytope is (isometrically) projected to a vector space of dimensiondim-1
. This operation turns the coordinates into floating point approximations and corresponds to the projection given by the matrix fromzero_sum_projection()
.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: h_4_2 = polytopes.hypersimplex(4, 2) sage: h_4_2 A 3-dimensional polyhedron in ZZ^4 defined as the convex hull of 6 vertices sage: h_4_2.f_vector() (1, 6, 12, 8, 1) sage: h_4_2.ehrhart_polynomial() # optional - latte_int 2/3*t^3 + 2*t^2 + 7/3*t + 1 sage: h_7_3 = polytopes.hypersimplex(7, 3, project=True) sage: h_7_3 A 6-dimensional polyhedron in RDF^6 defined as the convex hull of 35 vertices sage: h_7_3.f_vector() (1, 35, 210, 350, 245, 84, 14, 1)
-
icosahedron
(exact=True, base_ring=None, backend=None)¶ Return an icosahedron with edge length 1.
The icosahedron is one of the Platonic solids. It has 20 faces and is dual to the
dodecahedron()
.INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– (optional) the ring in which the coordinates will belong to. Note that this ring must contain \(\sqrt(5)\). If it is not provided andexact=True
it will be the number field \(\QQ[\sqrt(5)]\) and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: ico = polytopes.icosahedron() sage: ico.f_vector() (1, 12, 30, 20, 1) sage: ico.volume() 5/12*sqrt5 + 5/4
Its non exact version:
sage: ico = polytopes.icosahedron(exact=False) sage: ico.base_ring() Real Double Field sage: ico.volume() # known bug (trac 18214) 2.181694990...
A version using \(AA <sage.rings.qqbar.AlgebraicRealField>\):
sage: ico = polytopes.icosahedron(base_ring=AA) # long time sage: ico.base_ring() # long time Algebraic Real Field sage: ico.volume() # long time 2.181694990624913?
Note that if base ring is provided it must contain the square root of \(5\). Otherwise you will get an error:
sage: polytopes.icosahedron(base_ring=QQ) Traceback (most recent call last): ... TypeError: unable to convert 1/4*sqrt(5) + 1/4 to a rational
-
icosidodecahedron
(exact=True, backend=None)¶ Return the icosidodecahedron.
The Icosidodecahedron is a polyhedron with twenty triangular faces and twelve pentagonal faces. For more information see the Wikipedia article Icosidodecahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: id = polytopes.icosidodecahedron() sage: id.f_vector() (1, 30, 60, 32, 1)
-
icosidodecahedron_V2
(exact=True, base_ring=None, backend=None)¶ Return the icosidodecahedron.
The icosidodecahedron is an Archimedean solid. It has 32 faces and 30 vertices. For more information, see the Wikipedia article Icosidodecahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: id = polytopes.icosidodecahedron_V2() # long time - 6secs sage: id.f_vector() # long time (1, 30, 60, 32, 1) sage: id.base_ring() # long time Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
A much faster implementation using floating point approximations:
sage: id = polytopes.icosidodecahedron_V2(exact=False) sage: id.f_vector() (1, 30, 60, 32, 1) sage: id.base_ring() Real Double Field
Its facets are 20 triangles and 12 regular pentagons:
sage: sum(1 for f in id.facets() if len(f.vertices()) == 3) 20 sage: sum(1 for f in id.facets() if len(f.vertices()) == 5) 12
-
octahedron
(backend=None)¶ Return the octahedron.
The octahedron is a Platonic solid with 6 vertices and 8 faces dual to the cube. It can be defined as the convex hull of the six vertices \((0, 0, \pm 1)\), \((\pm 1, 0, 0)\) and \((0, \pm 1, 0)\). For more information, see the Wikipedia article Octahedron.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: co = polytopes.octahedron() sage: co.f_vector() (1, 6, 12, 8, 1)
Its facets are 8 triangles:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 3) 8
Some more computation:
sage: co.volume() 4/3 sage: co.ehrhart_polynomial() # optional - latte_int 4/3*t^3 + 2*t^2 + 8/3*t + 1
-
omnitruncated_one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the omnitruncated 120-cell.
The omnitruncated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 14400 vertices. For more information see Wikipedia article Omnitruncated 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.omnitruncated_one_hundred_twenty_cell(backend='normaliz') # not tested - very long time ~10min A 4-dimensional polyhedron in AA^4 defined as the convex hull of 14400 vertices
-
omnitruncated_six_hundred_cell
(exact=True, backend=None)¶ Return the omnitruncated 120-cell.
The omnitruncated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 14400 vertices. For more information see Wikipedia article Omnitruncated 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.omnitruncated_one_hundred_twenty_cell(backend='normaliz') # not tested - very long time ~10min A 4-dimensional polyhedron in AA^4 defined as the convex hull of 14400 vertices
-
one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the 120-cell.
The 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 600 vertices and 120 facets. For more information see Wikipedia article 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.one_hundred_twenty_cell(backend='normaliz') # not tested - long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 600 vertices
-
parallelotope
(generators, backend=None)¶ Return the zonotope, or parallelotope, spanned by the generators.
The parallelotope is the multi-dimensional generalization of a parallelogram (2 generators) and a parallelepiped (3 generators).
INPUT:
generators
– a list of vectors of same dimensionbackend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.parallelotope([ (1,0), (0,1) ]) A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices sage: polytopes.parallelotope([[1,2,3,4],[0,1,0,7],[3,1,0,2],[0,0,1,0]]) A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 16 vertices sage: K = QuadraticField(2, 'sqrt2') sage: sqrt2 = K.gen() sage: polytopes.parallelotope([ (1,sqrt2), (1,-1) ]) A 2-dimensional polyhedron in (Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095?)^2 defined as the convex hull of 4 vertices
-
pentakis_dodecahedron
(exact=True, base_ring=None, backend=None)¶ Return the pentakis dodecahedron.
The pentakis dodecahedron (orkisdodecahedron) is a face-regular, vertex-uniform polytope dual to the truncated icosahedron. It has 60 facets and 32 vertices. See the Wikipedia article Pentakis_dodecahedron for more information.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: pd = polytopes.pentakis_dodecahedron() # long time - ~10 sec sage: pd.n_vertices() # long time 32 sage: pd.n_inequalities() # long time 60
A much faster implementation is obtained when setting
exact=False
:sage: pd = polytopes.pentakis_dodecahedron(exact=False) sage: pd.n_vertices() 32 sage: pd.n_inequalities() 60
The 60 are triangles:
sage: all(len(f.vertices()) == 3 for f in pd.facets()) True
-
permutahedron
(n, project=False, backend=None)¶ Return the standard permutahedron of (1,…,n).
The permutahedron (or permutohedron) is the convex hull of the permutations of \(\{1,\ldots,n\}\) seen as vectors. The edges between the permutations correspond to multiplication on the right by an elementary transposition in the
SymmetricGroup
.If we take the graph in which the vertices correspond to vertices of the polyhedron, and edges to edges, we get the
BubbleSortGraph()
.INPUT:
n
– integerproject
– (boolean, defaultFalse
) ifTrue
, the polytope is (isometrically) projected to a vector space of dimensiondim-1
. This operation turns the coordinates into floating point approximations and corresponds to the projection given by the matrix fromzero_sum_projection()
.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: perm4 = polytopes.permutahedron(4) sage: perm4 A 3-dimensional polyhedron in ZZ^4 defined as the convex hull of 24 vertices sage: perm4.is_lattice_polytope() True sage: perm4.ehrhart_polynomial() # optional - latte_int 16*t^3 + 15*t^2 + 6*t + 1 sage: perm4 = polytopes.permutahedron(4, project=True) sage: perm4 A 3-dimensional polyhedron in RDF^3 defined as the convex hull of 24 vertices sage: perm4.plot() Graphics3d Object sage: perm4.graph().is_isomorphic(graphs.BubbleSortGraph(4)) True
See also
-
rectified_one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the rectified 120-cell.
The rectified 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 1200 vertices. For more information see Wikipedia article Rectified 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.rectified_one_hundred_twenty_cell(backend='normaliz') # not tested - long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 1200 vertices
-
rectified_six_hundred_cell
(exact=True, backend=None)¶ Return the rectified 600-cell.
The rectified 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 720 vertices. For more information see Wikipedia article Rectified 600-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.rectified_six_hundred_cell(backend='normaliz') # not tested - long time ~14sec A 4-dimensional polyhedron in AA^4 defined as the convex hull of 720 vertices
-
regular_polygon
(n, exact=True, base_ring=None, backend=None)¶ Return a regular polygon with \(n\) vertices.
INPUT:
n
– a positive integer, the number of vertices.exact
– (boolean, defaultTrue
) ifFalse
floating point numbers are used for coordinates.base_ring
– a ring in which the coordinates will lie. It isNone
by default. If it is not provided andexact
isTrue
then it will be the field of real algebraic number, ifexact
isFalse
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: octagon = polytopes.regular_polygon(8) sage: octagon A 2-dimensional polyhedron in AA^2 defined as the convex hull of 8 vertices sage: octagon.n_vertices() 8 sage: v = octagon.volume() sage: v 2.828427124746190? sage: v == 2*QQbar(2).sqrt() True
Its non exact version:
sage: polytopes.regular_polygon(3, exact=False).vertices() (A vertex at (0.0, 1.0), A vertex at (0.8660254038, -0.5), A vertex at (-0.8660254038, -0.5)) sage: polytopes.regular_polygon(25, exact=False).n_vertices() 25
-
rhombic_dodecahedron
(backend=None)¶ Return the rhombic dodecahedron.
The rhombic dodecahedron is a a polytope dual to the cuboctahedron. It has 14 vertices and 12 faces. For more information see the Wikipedia article Rhombic_dodecahedron.
INPUT:
backend
– the backend to use to create the polytope.
See also
EXAMPLES:
sage: rd = polytopes.rhombic_dodecahedron() sage: rd.f_vector() (1, 14, 24, 12, 1)
Its facets are 12 quadrilaterals (not all identical):
sage: sum(1 for f in rd.facets() if len(f.vertices()) == 4) 12
Some more computations:
sage: p = rd.ehrhart_polynomial() # optional - latte_int sage: p # optional - latte_int 16*t^3 + 12*t^2 + 4*t + 1 sage: [p(i) for i in [1,2,3,4]] # optional - latte_int [33, 185, 553, 1233] sage: [len((i*rd).integral_points()) for i in [1,2,3,4]] [33, 185, 553, 1233]
-
rhombicosidodecahedron
(exact=True, base_ring=None, backend=None)¶ Return the rhombicosidodecahedron.
The rhombicosidodecahedron is an Archimedean solid. It has 62 faces and 60 vertices. For more information, see the Wikipedia article Rhombicosidodecahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: rid = polytopes.rhombicosidodecahedron() # long time - 6secs sage: rid.f_vector() # long time (1, 60, 120, 62, 1) sage: rid.base_ring() # long time Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
A much faster implementation using floating point approximations:
sage: rid = polytopes.rhombicosidodecahedron(exact=False) sage: rid.f_vector() (1, 60, 120, 62, 1) sage: rid.base_ring() Real Double Field
Its facets are 20 triangles, 30 squares and 12 pentagons:
sage: sum(1 for f in rid.facets() if len(f.vertices()) == 3) 20 sage: sum(1 for f in rid.facets() if len(f.vertices()) == 4) 30 sage: sum(1 for f in rid.facets() if len(f.vertices()) == 5) 12
-
runcinated_one_hundred_twenty_cell
(exact=False, backend=None)¶ Return the runcinated 120-cell.
The runcinated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 2400 vertices. For more information see Wikipedia article Runcinated 120-cell.
Warning
The coordinates are inexact by default. The computation with inexact coordinates (using the backend
'cdd'
) issues a UserWarning on inconsistencies.INPUT:
exact
- (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.runcinated_one_hundred_twenty_cell(exact=False) # not tested - very long time doctest:warning ... UserWarning: This polyhedron data is numerically complicated; cdd could not convert between the inexact V and H representation without loss of data. The resulting object might show inconsistencies. A 4-dimensional polyhedron in RDF^4 defined as the convex hull of 2400 vertices
It is possible to use the backend
'normaliz'
to get an exact representation:sage: polytopes.runcinated_one_hundred_twenty_cell(exact=True,backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 2400 vertices
-
runcitruncated_one_hundred_twenty_cell
(exact=False, backend=None)¶ Return the runcitruncated 120-cell.
The runcitruncated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 7200 vertices. For more information see Wikipedia article Runcitruncated 120-cell.
Warning
The coordinates are inexact by default. The computation with inexact coordinates (using the backend
'cdd'
) issues a UserWarning on inconsistencies.INPUT:
exact
- (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.runcitruncated_one_hundred_twenty_cell(exact=False) # not tested - very long time doctest:warning ... UserWarning: This polyhedron data is numerically complicated; cdd could not convert between the inexact V and H representation without loss of data. The resulting object might show inconsistencies.
It is possible to use the backend
'normaliz'
to get an exact representation:sage: polytopes.runcitruncated_one_hundred_twenty_cell(exact=True,backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 7200 vertices
-
runcitruncated_six_hundred_cell
(exact=True, backend=None)¶ Return the runcitruncated 600-cell.
The runcitruncated 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 7200 vertices. For more information see Wikipedia article Runcitruncated 600-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.runcitruncated_six_hundred_cell(backend='normaliz') # not tested - very long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 7200 vertices
-
simplex
(dim=3, project=False, base_ring=None, backend=None)¶ Return the
dim
dimensional simplex.The \(d\)-simplex is the convex hull in \(\RR^{d+1}\) of the standard basis \((1,0,\ldots,0)\), \((0,1,\ldots,0)\), ldots, \((0,0,\ldots,1)\). For more information, see the Wikipedia article Simplex.
INPUT:
dim
– The dimension of the simplex, a positive integer.project
– (boolean, defaultFalse
) ifTrue
, the polytope is (isometrically) projected to a vector space of dimensiondim-1
. This corresponds to the projection given by the matrix fromzero_sum_projection()
. By default, this operation turns the coordinates into floating point approximations (seebase_ring
).base_ring
– the base ring to use to create the polytope. Ifproject
isFalse
, this defaults to \(\ZZ\). Otherwise, it defaults toRDF
.backend
– the backend to use to create the polytope.
See also
EXAMPLES:
sage: s5 = polytopes.simplex(5) sage: s5 A 5-dimensional polyhedron in ZZ^6 defined as the convex hull of 6 vertices sage: s5.f_vector() (1, 6, 15, 20, 15, 6, 1) sage: s5 = polytopes.simplex(5, project=True) sage: s5 A 5-dimensional polyhedron in RDF^5 defined as the convex hull of 6 vertices
Its volume is \(\sqrt{d+1} / d!\):
sage: s5 = polytopes.simplex(5, project=True) sage: s5.volume() # abs tol 1e-10 0.0204124145231931 sage: sqrt(6.) / factorial(5) 0.0204124145231931 sage: s6 = polytopes.simplex(6, project=True) sage: s6.volume() # abs tol 1e-10 0.00367465459870082 sage: sqrt(7.) / factorial(6) 0.00367465459870082
Computation in algebraic reals:
sage: s3 = polytopes.simplex(3, project=True, base_ring=AA) sage: s3.volume() == sqrt(3+1) / factorial(3) True
-
six_hundred_cell
(exact=False, backend=None)¶ Return the standard 600-cell polytope.
The 600-cell is a 4-dimensional regular polytope. In many ways this is an analogue of the icosahedron.
Warning
The coordinates are not exact by default. The computation with exact coordinates takes a huge amount of time.
INPUT:
exact
- (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximationsbackend
– the backend to use to create the polytope.
EXAMPLES:
sage: p600 = polytopes.six_hundred_cell() sage: p600 A 4-dimensional polyhedron in RDF^4 defined as the convex hull of 120 vertices sage: p600.f_vector() # long time ~2sec (1, 120, 720, 1200, 600, 1)
Computation with exact coordinates is currently too long to be useful:
sage: p600 = polytopes.six_hundred_cell(exact=True) # not tested - very long time sage: len(list(p600.bounded_edges())) # not tested - very long time 720
-
small_rhombicuboctahedron
(exact=True, base_ring=None, backend=None)¶ Return the (small) rhombicuboctahedron.
The rhombicuboctahedron is an Archimedean solid with 24 vertices and 26 faces. See the Wikipedia article Rhombicuboctahedron for more information.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: sr = polytopes.small_rhombicuboctahedron() sage: sr.f_vector() (1, 24, 48, 26, 1) sage: sr.volume() 80/3*sqrt2 + 32
The faces are \(8\) equilateral triangles and \(18\) squares:
sage: sum(1 for f in sr.facets() if len(f.vertices()) == 3) 8 sage: sum(1 for f in sr.facets() if len(f.vertices()) == 4) 18
Its non exact version:
sage: sr = polytopes.small_rhombicuboctahedron(False) sage: sr A 3-dimensional polyhedron in RDF^3 defined as the convex hull of 24 vertices sage: sr.f_vector() (1, 24, 48, 26, 1)
-
snub_cube
(exact=False, base_ring=None, backend=None, verbose=False)¶ Return a snub cube.
The snub cube is an Archimedean solid. It has 24 vertices and 38 faces. For more information see the Wikipedia article Snub_cube.
The constant \(z\) used in constructing this polytope is the reciprocal of the tribonacci constant, that is, the solution of the equation \(x^3 + x^2 + x - 1 = 0\). See Wikipedia article Generalizations_of_Fibonacci_numbers#Tribonacci_numbers.
INPUT:
exact
– (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximationsbase_ring
– the field to use. IfNone
(the default), construct the exact number field needed (ifexact
isTrue
) or default toRDF
(ifexact
isTrue
).backend
– the backend to use to create the polytope. IfNone
(the default), the backend will be selected automatically.
EXAMPLES:
sage: sc_inexact = polytopes.snub_cube(exact=False) sage: sc_inexact A 3-dimensional polyhedron in RDF^3 defined as the convex hull of 24 vertices sage: sc_inexact.f_vector() (1, 24, 60, 38, 1) sage: sc_exact = polytopes.snub_cube(exact=True) # long time - 30secs sage: sc_exact.f_vector() # long time (1, 24, 60, 38, 1) sage: sc_exact.vertices() # long time (A vertex at (-1, -z, -z^2), A vertex at (-z^2, -1, -z), A vertex at (-z, -z^2, -1), A vertex at (-1, z^2, -z), A vertex at (-z, -1, z^2), A vertex at (z^2, -z, -1), A vertex at (z, -1, -z^2), A vertex at (-z^2, z, -1), A vertex at (-1, -z^2, z), A vertex at (z, z^2, -1), A vertex at (-1, z, z^2), A vertex at (z^2, -1, z), A vertex at (-z, 1, -z^2), A vertex at (z^2, 1, -z), A vertex at (-z^2, -z, 1), A vertex at (-z, z^2, 1), A vertex at (-z^2, 1, z), A vertex at (1, -z^2, -z), A vertex at (1, -z, z^2), A vertex at (1, z, -z^2), A vertex at (z, -z^2, 1), A vertex at (z, 1, z^2), A vertex at (z^2, z, 1), A vertex at (1, z^2, z)) sage: sc_exact.is_combinatorially_isomorphic(sc_inexact) #long time True
-
snub_dodecahedron
(base_ring=None, backend=None, verbose=False)¶ Return the snub dodecahedron.
The snub dodecahedron is an Archimedean solid. It has 92 faces and 60 vertices. For more information, see the Wikipedia article Snub_dodecahedron.
INPUT:
base_ring
– the ring in which the coordinates will belong to. If it is not provided it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
Only the backend using the optional normaliz package can construct the snub dodecahedron in reasonable time:
sage: sd = polytopes.snub_dodecahedron(base_ring=AA, backend='normaliz') # optional - pynormaliz, long time sage: sd.f_vector() # optional - pynormaliz, long time (1, 60, 150, 92, 1) sage: sd.base_ring() # optional - pynormaliz, long time Algebraic Real Field
Its facets are 80 triangles and 12 pentagons:
sage: sum(1 for f in sd.facets() if len(f.vertices()) == 3) # optional - pynormaliz, long time 80 sage: sum(1 for f in sd.facets() if len(f.vertices()) == 5) # optional - pynormaliz, long time 12
-
tetrahedron
(backend=None)¶ Return the tetrahedron.
The tetrahedron is a Platonic solid with 4 vertices and 4 faces dual to itself. It can be defined as the convex hull of the 4 vertices \((0, 0, 0)\), \((1, 1, 0)\), \((1, 0, 1)\) and \((0, 1, 1)\). For more information, see the Wikipedia article Tetrahedron.
INPUT:
backend
– the backend to use to create the polytope.
See also
EXAMPLES:
sage: co = polytopes.tetrahedron() sage: co.f_vector() (1, 4, 6, 4, 1)
Its facets are 4 triangles:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 3) 4
Some more computation:
sage: co.volume() 1/3 sage: co.ehrhart_polynomial() # optional - latte_int 1/3*t^3 + t^2 + 5/3*t + 1
-
truncated_cube
(exact=True, base_ring=None, backend=None)¶ Return the truncated cube.
The truncated cube is an Archimedean solid with 24 vertices and 14 faces. It can be defined as the convex hull of the 24 vertices \((\pm x, \pm 1, \pm 1), (\pm 1, \pm x, \pm 1), (\pm 1, \pm 1, \pm x)\) where \(x = \sqrt(2) - 1\). For more information, see the Wikipedia article Truncated_cube.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\sqrt{2}]\) and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: co = polytopes.truncated_cube() sage: co.f_vector() (1, 24, 36, 14, 1)
Its facets are 8 triangles and 6 octogons:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 3) 8 sage: sum(1 for f in co.facets() if len(f.vertices()) == 8) 6
Some more computation:
sage: co.volume() 56/3*sqrt2 - 56/3
-
truncated_dodecahedron
(exact=True, base_ring=None, backend=None)¶ Return the truncated dodecahedron.
The truncated dodecahedron is an Archimedean solid. It has 32 faces and 60 vertices. For more information, see the Wikipedia article Truncated dodecahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: td = polytopes.truncated_dodecahedron() sage: td.f_vector() (1, 60, 90, 32, 1) sage: td.base_ring() Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
Its facets are 20 triangles and 12 regular decagons:
sage: sum(1 for f in td.facets() if len(f.vertices()) == 3) 20 sage: sum(1 for f in td.facets() if len(f.vertices()) == 10) 12
The faster implementation using floating point approximations does not fully work unfortunately, see https://github.com/cddlib/cddlib/pull/7 for a detailed discussion of this case:
sage: td = polytopes.truncated_dodecahedron(exact=False) # random doctest:warning ... UserWarning: This polyhedron data is numerically complicated; cdd could not convert between the inexact V and H representation without loss of data. The resulting object might show inconsistencies. sage: td.f_vector() Traceback (most recent call last): ... KeyError: ... sage: td.base_ring() Real Double Field
-
truncated_icosidodecahedron
(exact=True, base_ring=None, backend=None)¶ Return the truncated icosidodecahedron.
The truncated icosidodecahedron is an Archimedean solid. It has 62 faces and 120 vertices. For more information, see the Wikipedia article Truncated_icosidodecahedron.
INPUT:
exact
– (boolean, defaultTrue
) IfFalse
use an approximate ring for the coordinates.base_ring
– the ring in which the coordinates will belong to. If it is not provided andexact=True
it will be a the number field \(\QQ[\phi]\) where \(\phi\) is the golden ratio and ifexact=False
it will be the real double field.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: ti = polytopes.truncated_icosidodecahedron() # long time sage: ti.f_vector() # long time (1, 120, 180, 62, 1) sage: ti.base_ring() # long time Number Field in sqrt5 with defining polynomial x^2 - 5 with sqrt5 = 2.236067977499790?
The implementation using floating point approximations is much faster:
sage: ti = polytopes.truncated_icosidodecahedron(exact=False) # random sage: ti.f_vector() (1, 120, 180, 62, 1) sage: ti.base_ring() Real Double Field
Its facets are 30 squares, 20 hexagons and 12 decagons:
sage: sum(1 for f in ti.facets() if len(f.vertices()) == 4) 30 sage: sum(1 for f in ti.facets() if len(f.vertices()) == 6) 20 sage: sum(1 for f in ti.facets() if len(f.vertices()) == 10) 12
-
truncated_octahedron
(backend=None)¶ Return the truncated octahedron.
The truncated octahedron is an Archimedean solid with 24 vertices and 14 faces. It can be defined as the convex hull off all the permutations of \((0, \pm 1, \pm 2)\). For more information, see the Wikipedia article Truncated_octahedron.
This is also known as the permutohedron of dimension 3.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: co = polytopes.truncated_octahedron() sage: co.f_vector() (1, 24, 36, 14, 1)
Its facets are 6 squares and 8 hexagons:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 4) 6 sage: sum(1 for f in co.facets() if len(f.vertices()) == 6) 8
Some more computation:
sage: co.volume() 32 sage: co.ehrhart_polynomial() # optional - latte_int 32*t^3 + 18*t^2 + 6*t + 1
-
truncated_one_hundred_twenty_cell
(exact=True, backend=None)¶ Return the truncated 120-cell.
The truncated 120-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 2400 vertices. For more information see Wikipedia article Truncated 120-cell.
Warning
The coordinates are exact by default. The computation with inexact coordinates (using the backend
'cdd'
) returns a numerical inconsistency error, and thus can not be computed.INPUT:
exact
- (boolean, defaultTrue
) ifTrue
use exact coordinates instead of floating point approximations.backend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.truncated_one_hundred_twenty_cell(backend='normaliz') # not tested - long time A 4-dimensional polyhedron in AA^4 defined as the convex hull of 2400 vertices
-
truncated_six_hundred_cell
(exact=False, backend=None)¶ Return the truncated 600-cell.
The truncated 600-cell is a 4-dimensional 4-uniform polytope in the \(H_4\) family. It has 1440 vertices. For more information see Wikipedia article Truncated 600-cell.
Warning
The coordinates are not exact by default. The computation with exact coordinates takes a huge amount of time.
INPUT:
exact
- (boolean, defaultFalse
) ifTrue
use exact coordinates instead of floating point approximationsbackend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.truncated_six_hundred_cell() # not tested - long time A 4-dimensional polyhedron in RDF^4 defined as the convex hull of 1440 vertices
It is possible to use the backend
'normaliz'
to get an exact representation:sage: polytopes.truncated_six_hundred_cell(exact=True,backend='normaliz') # not tested - long time ~16sec A 4-dimensional polyhedron in AA^4 defined as the convex hull of 1440 vertices
-
truncated_tetrahedron
(backend=None)¶ Return the truncated tetrahedron.
The truncated tetrahedron is an Archimedean solid with 12 vertices and 8 faces. It can be defined as the convex hull off all the permutations of \((\pm 1, \pm 1, \pm 3)\) with an even number of minus signs. For more information, see the Wikipedia article Truncated_tetrahedron.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: co = polytopes.truncated_tetrahedron() sage: co.f_vector() (1, 12, 18, 8, 1)
Its facets are 4 triangles and 4 hexagons:
sage: sum(1 for f in co.facets() if len(f.vertices()) == 3) 4 sage: sum(1 for f in co.facets() if len(f.vertices()) == 6) 4
Some more computation:
sage: co.volume() 184/3 sage: co.ehrhart_polynomial() # optional - latte_int 184/3*t^3 + 28*t^2 + 26/3*t + 1
-
twenty_four_cell
(backend=None)¶ Return the standard 24-cell polytope.
The 24-cell polyhedron (also called icositetrachoron or octaplex) is a regular polyhedron in 4-dimension. For more information see the Wikipedia article 24-cell.
INPUT:
backend
– the backend to use to create the polytope.
EXAMPLES:
sage: p24 = polytopes.twenty_four_cell() sage: p24.f_vector() (1, 24, 96, 96, 24, 1) sage: v = next(p24.vertex_generator()) sage: for adj in v.neighbors(): print(adj) A vertex at (-1/2, -1/2, -1/2, 1/2) A vertex at (-1/2, -1/2, 1/2, -1/2) A vertex at (-1, 0, 0, 0) A vertex at (-1/2, 1/2, -1/2, -1/2) A vertex at (0, -1, 0, 0) A vertex at (0, 0, -1, 0) A vertex at (0, 0, 0, -1) A vertex at (1/2, -1/2, -1/2, -1/2) sage: p24.volume() 2
-
zonotope
(generators, backend=None)¶ Return the zonotope, or parallelotope, spanned by the generators.
The parallelotope is the multi-dimensional generalization of a parallelogram (2 generators) and a parallelepiped (3 generators).
INPUT:
generators
– a list of vectors of same dimensionbackend
– the backend to use to create the polytope.
EXAMPLES:
sage: polytopes.parallelotope([ (1,0), (0,1) ]) A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 4 vertices sage: polytopes.parallelotope([[1,2,3,4],[0,1,0,7],[3,1,0,2],[0,0,1,0]]) A 4-dimensional polyhedron in ZZ^4 defined as the convex hull of 16 vertices sage: K = QuadraticField(2, 'sqrt2') sage: sqrt2 = K.gen() sage: polytopes.parallelotope([ (1,sqrt2), (1,-1) ]) A 2-dimensional polyhedron in (Number Field in sqrt2 with defining polynomial x^2 - 2 with sqrt2 = 1.414213562373095?)^2 defined as the convex hull of 4 vertices
-
-
sage.geometry.polyhedron.library.
project_points
(*points, **kwds)¶ Projects a set of points into a vector space of dimension one less.
INPUT:
points
… – the points to project.base_ring
– (defaults toRDF
if keyword isNone
or not provided inkwds
) the base ring to use.
The projection is isometric to the orthogonal projection on the hyperplane made of zero sum vector. Hence, if the set of points have all equal sums, then their projection is isometric (as a set of points).
The projection used is the matrix given by
zero_sum_projection()
.EXAMPLES:
sage: from sage.geometry.polyhedron.library import project_points sage: project_points([2,-1,3,2]) # abs tol 1e-15 [(2.1213203435596424, -2.041241452319315, -0.577350269189626)] sage: project_points([1,2,3],[3,3,5]) # abs tol 1e-15 [(-0.7071067811865475, -1.2247448713915892), (0.0, -1.6329931618554523)]
These projections are compatible with the restriction. More precisely, given a vector \(v\), the projection of \(v\) restricted to the first \(i\) coordinates will be equal to the projection of the first \(i+1\) coordinates of \(v\):
sage: project_points([1,2]) # abs tol 1e-15 [(-0.7071067811865475)] sage: project_points([1,2,3]) # abs tol 1e-15 [(-0.7071067811865475, -1.2247448713915892)] sage: project_points([1,2,3,4]) # abs tol 1e-15 [(-0.7071067811865475, -1.2247448713915892, -1.7320508075688776)] sage: project_points([1,2,3,4,0]) # abs tol 1e-15 [(-0.7071067811865475, -1.2247448713915892, -1.7320508075688776, 2.23606797749979)]
Check that it is (almost) an isometry:
sage: V = list(map(vector, IntegerVectors(n=5,length=3))) sage: P = project_points(*V) sage: for i in range(21): ....: for j in range(21): ....: assert abs((V[i]-V[j]).norm() - (P[i]-P[j]).norm()) < 0.00001
Example with exact computation:
sage: V = [ vector(v) for v in IntegerVectors(n=4,length=2) ] sage: P = project_points(*V, base_ring=AA) sage: for i in range(len(V)): ....: for j in range(len(V)): ....: assert (V[i]-V[j]).norm() == (P[i]-P[j]).norm()
-
sage.geometry.polyhedron.library.
zero_sum_projection
(d, base_ring=Real Double Field)¶ Return a matrix corresponding to the projection on the orthogonal of \((1,1,\ldots,1)\) in dimension \(d\).
The projection maps the orthonormal basis \((1,-1,0,\ldots,0) / \sqrt(2)\), \((1,1,-1,0,\ldots,0) / \sqrt(3)\), ldots, \((1,1,\ldots,1,-1) / \sqrt(d)\) to the canonical basis in \(\RR^{d-1}\).
OUTPUT:
A matrix of dimensions \((d-1)\times d\) defined over
base_ring
(default:RDF
).EXAMPLES:
sage: from sage.geometry.polyhedron.library import zero_sum_projection sage: zero_sum_projection(2) [ 0.7071067811865475 -0.7071067811865475] sage: zero_sum_projection(3) [ 0.7071067811865475 -0.7071067811865475 0.0] [ 0.4082482904638631 0.4082482904638631 -0.8164965809277261]
Exact computation in
AA
:sage: zero_sum_projection(3, base_ring=AA) [ 0.7071067811865475? -0.7071067811865475? 0] [ 0.4082482904638630? 0.4082482904638630? -0.8164965809277260?]