Base class for polyhedra: Initialization and access to Vrepresentation and Hrepresentation¶
- class sage.geometry.polyhedron.base0.Polyhedron_base0(parent, Vrep, Hrep, Vrep_minimal=None, Hrep_minimal=None, pref_rep=None, mutable=False, **kwds)[source]¶
Bases:
Element
,Polyhedron
Initialization and basic access for polyhedra.
See
sage.geometry.polyhedron.base.Polyhedron_base
.- Hrep_generator()[source]¶
Return an iterator over the objects of the H-representation (inequalities or equations).
EXAMPLES:
sage: p = polytopes.hypercube(3) sage: next(p.Hrep_generator()) An inequality (-1, 0, 0) x + 1 >= 0
>>> from sage.all import * >>> p = polytopes.hypercube(Integer(3)) >>> next(p.Hrep_generator()) An inequality (-1, 0, 0) x + 1 >= 0
- Hrepresentation(index=None)[source]¶
Return the objects of the H-representation. Each entry is either an inequality or a equation.
INPUT:
index
– either an integer orNone
OUTPUT:
The optional argument is an index running from
0
toself.n_Hrepresentation()-1
. If present, the H-representation object at the given index will be returned. Without an argument, returns the list of all H-representation objects.EXAMPLES:
sage: p = polytopes.hypercube(3, backend='field') sage: p.Hrepresentation(0) An inequality (-1, 0, 0) x + 1 >= 0 sage: p.Hrepresentation(0) == p.Hrepresentation()[0] True
>>> from sage.all import * >>> p = polytopes.hypercube(Integer(3), backend='field') >>> p.Hrepresentation(Integer(0)) An inequality (-1, 0, 0) x + 1 >= 0 >>> p.Hrepresentation(Integer(0)) == p.Hrepresentation()[Integer(0)] True
- Hrepresentation_str(separator='\n', latex=False, style='>=', align=None, **kwds)[source]¶
Return a human-readable string representation of the Hrepresentation of this polyhedron.
INPUT:
separator
– string (default:'\n'
)latex
– boolean (default:False
)style
– either'positive'
(making all coefficients positive)or
'<='
, or'>='
; default is'>='
align
– boolean orNone''; default is ``None
in which casealign
isTrue
ifseparator
is the newline character. If set, then the lines of the output string are aligned by the comparison symbol by padding blanks.
Keyword parameters of
repr_pretty()
are passed on:prefix
– stringindices
– tuple or other iterable
OUTPUT: string
EXAMPLES:
sage: P = polytopes.permutahedron(3) sage: print(P.Hrepresentation_str()) x0 + x1 + x2 == 6 x0 + x1 >= 3 -x0 - x1 >= -5 x1 >= 1 -x0 >= -3 x0 >= 1 -x1 >= -3 sage: print(P.Hrepresentation_str(style='<=')) -x0 - x1 - x2 == -6 -x0 - x1 <= -3 x0 + x1 <= 5 -x1 <= -1 x0 <= 3 -x0 <= -1 x1 <= 3 sage: print(P.Hrepresentation_str(style='positive')) x0 + x1 + x2 == 6 x0 + x1 >= 3 5 >= x0 + x1 x1 >= 1 3 >= x0 x0 >= 1 3 >= x1 sage: print(P.Hrepresentation_str(latex=True)) \begin{array}{rcl} x_{0} + x_{1} + x_{2} & = & 6 \\ x_{0} + x_{1} & \geq & 3 \\ -x_{0} - x_{1} & \geq & -5 \\ x_{1} & \geq & 1 \\ -x_{0} & \geq & -3 \\ x_{0} & \geq & 1 \\ -x_{1} & \geq & -3 \end{array} sage: print(P.Hrepresentation_str(align=False)) x0 + x1 + x2 == 6 x0 + x1 >= 3 -x0 - x1 >= -5 x1 >= 1 -x0 >= -3 x0 >= 1 -x1 >= -3 sage: c = polytopes.cube() sage: c.Hrepresentation_str(separator=', ', style='positive') '1 >= x0, 1 >= x1, 1 >= x2, 1 + x0 >= 0, 1 + x2 >= 0, 1 + x1 >= 0'
>>> from sage.all import * >>> P = polytopes.permutahedron(Integer(3)) >>> print(P.Hrepresentation_str()) x0 + x1 + x2 == 6 x0 + x1 >= 3 -x0 - x1 >= -5 x1 >= 1 -x0 >= -3 x0 >= 1 -x1 >= -3 >>> print(P.Hrepresentation_str(style='<=')) -x0 - x1 - x2 == -6 -x0 - x1 <= -3 x0 + x1 <= 5 -x1 <= -1 x0 <= 3 -x0 <= -1 x1 <= 3 >>> print(P.Hrepresentation_str(style='positive')) x0 + x1 + x2 == 6 x0 + x1 >= 3 5 >= x0 + x1 x1 >= 1 3 >= x0 x0 >= 1 3 >= x1 >>> print(P.Hrepresentation_str(latex=True)) \begin{array}{rcl} x_{0} + x_{1} + x_{2} & = & 6 \\ x_{0} + x_{1} & \geq & 3 \\ -x_{0} - x_{1} & \geq & -5 \\ x_{1} & \geq & 1 \\ -x_{0} & \geq & -3 \\ x_{0} & \geq & 1 \\ -x_{1} & \geq & -3 \end{array} >>> print(P.Hrepresentation_str(align=False)) x0 + x1 + x2 == 6 x0 + x1 >= 3 -x0 - x1 >= -5 x1 >= 1 -x0 >= -3 x0 >= 1 -x1 >= -3 >>> c = polytopes.cube() >>> c.Hrepresentation_str(separator=', ', style='positive') '1 >= x0, 1 >= x1, 1 >= x2, 1 + x0 >= 0, 1 + x2 >= 0, 1 + x1 >= 0'
- Vrep_generator()[source]¶
Return an iterator over the objects of the V-representation (vertices, rays, and lines).
EXAMPLES:
sage: p = polytopes.cyclic_polytope(3,4) sage: vg = p.Vrep_generator() sage: next(vg) A vertex at (0, 0, 0) sage: next(vg) A vertex at (1, 1, 1)
>>> from sage.all import * >>> p = polytopes.cyclic_polytope(Integer(3),Integer(4)) >>> vg = p.Vrep_generator() >>> next(vg) A vertex at (0, 0, 0) >>> next(vg) A vertex at (1, 1, 1)
- Vrepresentation(index=None)[source]¶
Return the objects of the V-representation. Each entry is either a vertex, a ray, or a line.
See
sage.geometry.polyhedron.constructor
for a definition of vertex/ray/line.INPUT:
index
– either an integer orNone
OUTPUT:
The optional argument is an index running from
0
toself.n_Vrepresentation()-1
. If present, the V-representation object at the given index will be returned. Without an argument, returns the list of all V-representation objects.EXAMPLES:
sage: p = polytopes.simplex(4, project=True) sage: p.Vrepresentation(0) A vertex at (0.7071067812, 0.4082482905, 0.2886751346, 0.2236067977) sage: p.Vrepresentation(0) == p.Vrepresentation() [0] True
>>> from sage.all import * >>> p = polytopes.simplex(Integer(4), project=True) >>> p.Vrepresentation(Integer(0)) A vertex at (0.7071067812, 0.4082482905, 0.2886751346, 0.2236067977) >>> p.Vrepresentation(Integer(0)) == p.Vrepresentation() [Integer(0)] True
- backend()[source]¶
Return the backend used.
OUTPUT:
The name of the backend used for computations. It will be one of the following backends:
ppl
the Parma Polyhedra Librarycdd
CDDnormaliz
normalizpolymake
polymakefield
a generic Sage implementation
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1, 0], [0, 1], [1, 1]]) sage: triangle.backend() 'ppl' sage: D = polytopes.dodecahedron() # needs sage.groups sage.rings.number_field sage: D.backend() # needs sage.groups sage.rings.number_field 'field' sage: P = Polyhedron([[1.23]]) sage: P.backend() 'cdd'
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1), Integer(0)], [Integer(0), Integer(1)], [Integer(1), Integer(1)]]) >>> triangle.backend() 'ppl' >>> D = polytopes.dodecahedron() # needs sage.groups sage.rings.number_field >>> D.backend() # needs sage.groups sage.rings.number_field 'field' >>> P = Polyhedron([[RealNumber('1.23')]]) >>> P.backend() 'cdd'
- base_extend(base_ring, backend=None)[source]¶
Return a new polyhedron over a larger base ring.
This method can also be used to change the backend.
INPUT:
base_ring
– the new base ringbackend
– the new backend, seePolyhedron()
IfNone
(the default), attempt to keep the same backend. Otherwise, use the same defaulting behavior as described there.
OUTPUT: the same polyhedron, but over a larger base ring and possibly with a changed backend
EXAMPLES:
sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)], base_ring=ZZ); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray sage: P.base_extend(QQ) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray sage: P.base_extend(QQ) == P True
>>> from sage.all import * >>> P = Polyhedron(vertices=[(Integer(1),Integer(0)), (Integer(0),Integer(1))], rays=[(Integer(1),Integer(1))], base_ring=ZZ); P A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray >>> P.base_extend(QQ) A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray >>> P.base_extend(QQ) == P True
- base_ring()[source]¶
Return the base ring.
OUTPUT:
The ring over which the polyhedron is defined. Must be a sub-ring of the reals to define a polyhedron, in particular comparison must be defined. Popular choices are
ZZ
(the ring of integers, lattice polytope),QQ
(exact arithmetic using gmp),RDF
(double precision floating-point arithmetic), orAA
(real algebraic field).
EXAMPLES:
sage: triangle = Polyhedron(vertices = [[1,0],[0,1],[1,1]]) sage: triangle.base_ring() == ZZ True
>>> from sage.all import * >>> triangle = Polyhedron(vertices = [[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> triangle.base_ring() == ZZ True
- cdd_Hrepresentation()[source]¶
Write the inequalities/equations data of the polyhedron in cdd’s H-representation format.
See also
write_cdd_Hrepresentation()
– export the polyhedron as a H-representation to a file.OUTPUT: string
EXAMPLES:
sage: p = polytopes.hypercube(2) sage: print(p.cdd_Hrepresentation()) H-representation begin 4 3 rational 1 -1 0 1 0 -1 1 1 0 1 0 1 end sage: triangle = Polyhedron(vertices=[[1,0], [0,1], [1,1]], base_ring=AA) # needs sage.rings.number_field sage: triangle.base_ring() # needs sage.rings.number_field Algebraic Real Field sage: triangle.cdd_Hrepresentation() # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: the base ring must be ZZ, QQ, or RDF
>>> from sage.all import * >>> p = polytopes.hypercube(Integer(2)) >>> print(p.cdd_Hrepresentation()) H-representation begin 4 3 rational 1 -1 0 1 0 -1 1 1 0 1 0 1 end <BLANKLINE> >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)], [Integer(0),Integer(1)], [Integer(1),Integer(1)]], base_ring=AA) # needs sage.rings.number_field >>> triangle.base_ring() # needs sage.rings.number_field Algebraic Real Field >>> triangle.cdd_Hrepresentation() # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: the base ring must be ZZ, QQ, or RDF
- cdd_Vrepresentation()[source]¶
Write the vertices/rays/lines data of the polyhedron in cdd’s V-representation format.
See also
write_cdd_Vrepresentation()
– export the polyhedron as a V-representation to a file.OUTPUT: string
EXAMPLES:
sage: q = Polyhedron(vertices = [[1,1],[0,0],[1,0],[0,1]]) sage: print(q.cdd_Vrepresentation()) V-representation begin 4 3 rational 1 0 0 1 0 1 1 1 0 1 1 1 end
>>> from sage.all import * >>> q = Polyhedron(vertices = [[Integer(1),Integer(1)],[Integer(0),Integer(0)],[Integer(1),Integer(0)],[Integer(0),Integer(1)]]) >>> print(q.cdd_Vrepresentation()) V-representation begin 4 3 rational 1 0 0 1 0 1 1 1 0 1 1 1 end
- change_ring(base_ring, backend=None)[source]¶
Return the polyhedron obtained by coercing the entries of the vertices/lines/rays of this polyhedron into the given ring.
This method can also be used to change the backend.
INPUT:
base_ring
– the new base ringbackend
– the new backend orNone
(default), seePolyhedron()
. IfNone
(the default), attempt to keep the same backend. Otherwise, use the same defaulting behavior as described there.
EXAMPLES:
sage: P = Polyhedron(vertices=[(1,0), (0,1)], rays=[(1,1)], base_ring=QQ); P A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray sage: P.change_ring(ZZ) A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray sage: P.change_ring(ZZ) == P True sage: P = Polyhedron(vertices=[(-1.3,0), (0,2.3)], base_ring=RDF); P.vertices() (A vertex at (-1.3, 0.0), A vertex at (0.0, 2.3)) sage: P.change_ring(QQ).vertices() (A vertex at (-13/10, 0), A vertex at (0, 23/10)) sage: P == P.change_ring(QQ) True sage: P.change_ring(ZZ) Traceback (most recent call last): ... TypeError: cannot change the base ring to the Integer Ring sage: P = polytopes.regular_polygon(3); P # needs sage.rings.number_field A 2-dimensional polyhedron in AA^2 defined as the convex hull of 3 vertices sage: P.vertices() # needs sage.rings.number_field (A vertex at (0.?e-16, 1.000000000000000?), A vertex at (0.866025403784439?, -0.500000000000000?), A vertex at (-0.866025403784439?, -0.500000000000000?)) sage: P.change_ring(QQ) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: cannot change the base ring to the Rational Field
>>> from sage.all import * >>> P = Polyhedron(vertices=[(Integer(1),Integer(0)), (Integer(0),Integer(1))], rays=[(Integer(1),Integer(1))], base_ring=QQ); P A 2-dimensional polyhedron in QQ^2 defined as the convex hull of 2 vertices and 1 ray >>> P.change_ring(ZZ) A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices and 1 ray >>> P.change_ring(ZZ) == P True >>> P = Polyhedron(vertices=[(-RealNumber('1.3'),Integer(0)), (Integer(0),RealNumber('2.3'))], base_ring=RDF); P.vertices() (A vertex at (-1.3, 0.0), A vertex at (0.0, 2.3)) >>> P.change_ring(QQ).vertices() (A vertex at (-13/10, 0), A vertex at (0, 23/10)) >>> P == P.change_ring(QQ) True >>> P.change_ring(ZZ) Traceback (most recent call last): ... TypeError: cannot change the base ring to the Integer Ring >>> P = polytopes.regular_polygon(Integer(3)); P # needs sage.rings.number_field A 2-dimensional polyhedron in AA^2 defined as the convex hull of 3 vertices >>> P.vertices() # needs sage.rings.number_field (A vertex at (0.?e-16, 1.000000000000000?), A vertex at (0.866025403784439?, -0.500000000000000?), A vertex at (-0.866025403784439?, -0.500000000000000?)) >>> P.change_ring(QQ) # needs sage.rings.number_field Traceback (most recent call last): ... TypeError: cannot change the base ring to the Rational Field
Warning
The base ring
RDF
should be used with care. As it is not an exact ring, certain computations may break or silently produce wrong results, for example changing the base ring from an exact ring intoRDF
may cause a loss of data:sage: P = Polyhedron([[2/3,0],[6666666666666667/10^16,0]], base_ring=AA); P # needs sage.rings.number_field A 1-dimensional polyhedron in AA^2 defined as the convex hull of 2 vertices sage: Q = P.change_ring(RDF); Q # needs sage.rings.number_field A 0-dimensional polyhedron in RDF^2 defined as the convex hull of 1 vertex sage: P.n_vertices() == Q.n_vertices() # needs sage.rings.number_field False
>>> from sage.all import * >>> P = Polyhedron([[Integer(2)/Integer(3),Integer(0)],[Integer(6666666666666667)/Integer(10)**Integer(16),Integer(0)]], base_ring=AA); P # needs sage.rings.number_field A 1-dimensional polyhedron in AA^2 defined as the convex hull of 2 vertices >>> Q = P.change_ring(RDF); Q # needs sage.rings.number_field A 0-dimensional polyhedron in RDF^2 defined as the convex hull of 1 vertex >>> P.n_vertices() == Q.n_vertices() # needs sage.rings.number_field False
- equation_generator()[source]¶
Return a generator for the linear equations satisfied by the polyhedron.
EXAMPLES:
sage: p = polytopes.regular_polygon(8,base_ring=RDF) sage: p3 = Polyhedron(vertices = [x+[0] for x in p.vertices()], base_ring=RDF) sage: next(p3.equation_generator()) An equation (0.0, 0.0, 1.0) x + 0.0 == 0
>>> from sage.all import * >>> p = polytopes.regular_polygon(Integer(8),base_ring=RDF) >>> p3 = Polyhedron(vertices = [x+[Integer(0)] for x in p.vertices()], base_ring=RDF) >>> next(p3.equation_generator()) An equation (0.0, 0.0, 1.0) x + 0.0 == 0
- equations()[source]¶
Return all linear constraints of the polyhedron.
OUTPUT: a tuple of equations
EXAMPLES:
sage: test_p = Polyhedron(vertices = [[1,2,3,4],[2,1,3,4],[4,3,2,1],[3,4,1,2]]) sage: test_p.equations() (An equation (1, 1, 1, 1) x - 10 == 0,)
>>> from sage.all import * >>> test_p = Polyhedron(vertices = [[Integer(1),Integer(2),Integer(3),Integer(4)],[Integer(2),Integer(1),Integer(3),Integer(4)],[Integer(4),Integer(3),Integer(2),Integer(1)],[Integer(3),Integer(4),Integer(1),Integer(2)]]) >>> test_p.equations() (An equation (1, 1, 1, 1) x - 10 == 0,)
- equations_list()[source]¶
Return the linear constraints of the polyhedron. As with inequalities, each constraint is given as [b -a1 -a2 … an] where for variables x1, x2,…, xn, the polyhedron satisfies the equation b = a1*x1 + a2*x2 + … + an*xn.
Note
It is recommended to use
equations()
orequation_generator()
instead to iterate over the list ofEquation
objects.EXAMPLES:
sage: test_p = Polyhedron(vertices = [[1,2,3,4],[2,1,3,4],[4,3,2,1],[3,4,1,2]]) sage: test_p.equations_list() [[-10, 1, 1, 1, 1]]
>>> from sage.all import * >>> test_p = Polyhedron(vertices = [[Integer(1),Integer(2),Integer(3),Integer(4)],[Integer(2),Integer(1),Integer(3),Integer(4)],[Integer(4),Integer(3),Integer(2),Integer(1)],[Integer(3),Integer(4),Integer(1),Integer(2)]]) >>> test_p.equations_list() [[-10, 1, 1, 1, 1]]
- inequalities()[source]¶
Return all inequalities.
OUTPUT: a tuple of inequalities
EXAMPLES:
sage: p = Polyhedron(vertices = [[0,0,0],[0,0,1],[0,1,0],[1,0,0],[2,2,2]]) sage: p.inequalities()[0:3] (An inequality (1, 0, 0) x + 0 >= 0, An inequality (0, 1, 0) x + 0 >= 0, An inequality (0, 0, 1) x + 0 >= 0) sage: # needs sage.combinat sage: p3 = Polyhedron(vertices=Permutations([1, 2, 3, 4])) sage: ieqs = p3.inequalities() sage: ieqs[0] An inequality (0, 1, 1, 1) x - 6 >= 0 sage: list(_) [-6, 0, 1, 1, 1]
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(0),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(1)],[Integer(0),Integer(1),Integer(0)],[Integer(1),Integer(0),Integer(0)],[Integer(2),Integer(2),Integer(2)]]) >>> p.inequalities()[Integer(0):Integer(3)] (An inequality (1, 0, 0) x + 0 >= 0, An inequality (0, 1, 0) x + 0 >= 0, An inequality (0, 0, 1) x + 0 >= 0) >>> # needs sage.combinat >>> p3 = Polyhedron(vertices=Permutations([Integer(1), Integer(2), Integer(3), Integer(4)])) >>> ieqs = p3.inequalities() >>> ieqs[Integer(0)] An inequality (0, 1, 1, 1) x - 6 >= 0 >>> list(_) [-6, 0, 1, 1, 1]
- inequalities_list()[source]¶
Return a list of inequalities as coefficient lists.
Note
It is recommended to use
inequalities()
orinequality_generator()
instead to iterate over the list ofInequality
objects.EXAMPLES:
sage: p = Polyhedron(vertices = [[0,0,0],[0,0,1],[0,1,0],[1,0,0],[2,2,2]]) sage: p.inequalities_list()[0:3] [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] sage: # needs sage.combinat sage: p3 = Polyhedron(vertices=Permutations([1, 2, 3, 4])) sage: ieqs = p3.inequalities_list() sage: ieqs[0] [-6, 0, 1, 1, 1] sage: ieqs[-1] [-3, 0, 1, 0, 1] sage: ieqs == [list(x) for x in p3.inequality_generator()] True
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(0),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(1)],[Integer(0),Integer(1),Integer(0)],[Integer(1),Integer(0),Integer(0)],[Integer(2),Integer(2),Integer(2)]]) >>> p.inequalities_list()[Integer(0):Integer(3)] [[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] >>> # needs sage.combinat >>> p3 = Polyhedron(vertices=Permutations([Integer(1), Integer(2), Integer(3), Integer(4)])) >>> ieqs = p3.inequalities_list() >>> ieqs[Integer(0)] [-6, 0, 1, 1, 1] >>> ieqs[-Integer(1)] [-3, 0, 1, 0, 1] >>> ieqs == [list(x) for x in p3.inequality_generator()] True
- inequality_generator()[source]¶
Return a generator for the defining inequalities of the polyhedron.
OUTPUT: a generator of the inequality Hrepresentation objects
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]]) sage: for v in triangle.inequality_generator(): print(v) An inequality (1, 1) x - 1 >= 0 An inequality (0, -1) x + 1 >= 0 An inequality (-1, 0) x + 1 >= 0 sage: [ v for v in triangle.inequality_generator() ] [An inequality (1, 1) x - 1 >= 0, An inequality (0, -1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0] sage: [ [v.A(), v.b()] for v in triangle.inequality_generator() ] [[(1, 1), -1], [(0, -1), 1], [(-1, 0), 1]]
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> for v in triangle.inequality_generator(): print(v) An inequality (1, 1) x - 1 >= 0 An inequality (0, -1) x + 1 >= 0 An inequality (-1, 0) x + 1 >= 0 >>> [ v for v in triangle.inequality_generator() ] [An inequality (1, 1) x - 1 >= 0, An inequality (0, -1) x + 1 >= 0, An inequality (-1, 0) x + 1 >= 0] >>> [ [v.A(), v.b()] for v in triangle.inequality_generator() ] [[(1, 1), -1], [(0, -1), 1], [(-1, 0), 1]]
- is_compact()[source]¶
Test for boundedness of the polytope.
EXAMPLES:
sage: p = polytopes.icosahedron() # needs sage.groups sage.rings.number_field sage: p.is_compact() # needs sage.groups sage.rings.number_field True sage: p = Polyhedron(ieqs=[[0,1,0,0],[0,0,1,0],[0,0,0,1],[1,-1,0,0]]) sage: p.is_compact() False
>>> from sage.all import * >>> p = polytopes.icosahedron() # needs sage.groups sage.rings.number_field >>> p.is_compact() # needs sage.groups sage.rings.number_field True >>> p = Polyhedron(ieqs=[[Integer(0),Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(0),Integer(1)],[Integer(1),-Integer(1),Integer(0),Integer(0)]]) >>> p.is_compact() False
- is_immutable()[source]¶
Return
True
if the polyhedron is immutable, i.e. it cannot be modified in place.EXAMPLES:
sage: p = polytopes.cube(backend='field') sage: p.is_immutable() True
>>> from sage.all import * >>> p = polytopes.cube(backend='field') >>> p.is_immutable() True
- is_mutable()[source]¶
Return
True
if the polyhedron is mutable, i.e. it can be modified in place.EXAMPLES:
sage: p = polytopes.cube(backend='field') sage: p.is_mutable() False
>>> from sage.all import * >>> p = polytopes.cube(backend='field') >>> p.is_mutable() False
- line_generator()[source]¶
Return a generator for the lines of the polyhedron.
EXAMPLES:
sage: pr = Polyhedron(rays = [[1,0],[-1,0],[0,1]], vertices = [[-1,-1]]) sage: next(pr.line_generator()).vector() (1, 0)
>>> from sage.all import * >>> pr = Polyhedron(rays = [[Integer(1),Integer(0)],[-Integer(1),Integer(0)],[Integer(0),Integer(1)]], vertices = [[-Integer(1),-Integer(1)]]) >>> next(pr.line_generator()).vector() (1, 0)
- lines()[source]¶
Return all lines of the polyhedron.
OUTPUT: a tuple of lines
EXAMPLES:
sage: p = Polyhedron(rays = [[1,0],[-1,0],[0,1],[1,1]], vertices = [[-2,-2],[2,3]]) sage: p.lines() (A line in the direction (1, 0),)
>>> from sage.all import * >>> p = Polyhedron(rays = [[Integer(1),Integer(0)],[-Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]], vertices = [[-Integer(2),-Integer(2)],[Integer(2),Integer(3)]]) >>> p.lines() (A line in the direction (1, 0),)
- lines_list()[source]¶
Return a list of lines of the polyhedron. The line data is given as a list of coordinates rather than as a Hrepresentation object.
Note
It is recommended to use
line_generator()
instead to iterate over the list ofLine
objects.EXAMPLES:
sage: p = Polyhedron(rays = [[1,0],[-1,0],[0,1],[1,1]], vertices = [[-2,-2],[2,3]]) sage: p.lines_list() [[1, 0]] sage: p.lines_list() == [list(x) for x in p.line_generator()] True
>>> from sage.all import * >>> p = Polyhedron(rays = [[Integer(1),Integer(0)],[-Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]], vertices = [[-Integer(2),-Integer(2)],[Integer(2),Integer(3)]]) >>> p.lines_list() [[1, 0]] >>> p.lines_list() == [list(x) for x in p.line_generator()] True
- n_Hrepresentation()[source]¶
Return the number of objects that make up the H-representation of the polyhedron.
OUTPUT: integer
EXAMPLES:
sage: p = polytopes.cross_polytope(4) sage: p.n_Hrepresentation() 16 sage: p.n_Hrepresentation() == p.n_inequalities() + p.n_equations() True
>>> from sage.all import * >>> p = polytopes.cross_polytope(Integer(4)) >>> p.n_Hrepresentation() 16 >>> p.n_Hrepresentation() == p.n_inequalities() + p.n_equations() True
- n_Vrepresentation()[source]¶
Return the number of objects that make up the V-representation of the polyhedron.
OUTPUT: integer
EXAMPLES:
sage: p = polytopes.simplex(4) sage: p.n_Vrepresentation() 5 sage: p.n_Vrepresentation() == p.n_vertices() + p.n_rays() + p.n_lines() True
>>> from sage.all import * >>> p = polytopes.simplex(Integer(4)) >>> p.n_Vrepresentation() 5 >>> p.n_Vrepresentation() == p.n_vertices() + p.n_rays() + p.n_lines() True
- n_equations()[source]¶
Return the number of equations. The representation will always be minimal, so the number of equations is the codimension of the polyhedron in the ambient space.
EXAMPLES:
sage: p = Polyhedron(vertices = [[1,0,0],[0,1,0],[0,0,1]]) sage: p.n_equations() 1
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(1)]]) >>> p.n_equations() 1
- n_facets()[source]¶
Return the number of inequalities. The representation will always be minimal, so the number of inequalities is the number of facets of the polyhedron in the ambient space.
EXAMPLES:
sage: p = Polyhedron(vertices = [[1,0,0],[0,1,0],[0,0,1]]) sage: p.n_inequalities() 3 sage: p = Polyhedron(vertices = [[t,t^2,t^3] for t in range(6)]) sage: p.n_facets() 8
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(1)]]) >>> p.n_inequalities() 3 >>> p = Polyhedron(vertices = [[t,t**Integer(2),t**Integer(3)] for t in range(Integer(6))]) >>> p.n_facets() 8
- n_inequalities()[source]¶
Return the number of inequalities. The representation will always be minimal, so the number of inequalities is the number of facets of the polyhedron in the ambient space.
EXAMPLES:
sage: p = Polyhedron(vertices = [[1,0,0],[0,1,0],[0,0,1]]) sage: p.n_inequalities() 3 sage: p = Polyhedron(vertices = [[t,t^2,t^3] for t in range(6)]) sage: p.n_facets() 8
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(1)]]) >>> p.n_inequalities() 3 >>> p = Polyhedron(vertices = [[t,t**Integer(2),t**Integer(3)] for t in range(Integer(6))]) >>> p.n_facets() 8
- n_lines()[source]¶
Return the number of lines. The representation will always be minimal.
EXAMPLES:
sage: p = Polyhedron(vertices = [[0,0]], rays=[[0,1],[0,-1]]) sage: p.n_lines() 1
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(0),Integer(0)]], rays=[[Integer(0),Integer(1)],[Integer(0),-Integer(1)]]) >>> p.n_lines() 1
- n_rays()[source]¶
Return the number of rays. The representation will always be minimal.
EXAMPLES:
sage: p = Polyhedron(vertices = [[1,0],[0,1]], rays=[[1,1]]) sage: p.n_rays() 1
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(1),Integer(0)],[Integer(0),Integer(1)]], rays=[[Integer(1),Integer(1)]]) >>> p.n_rays() 1
- n_vertices()[source]¶
Return the number of vertices. The representation will always be minimal.
Warning
If the polyhedron has lines, return the number of vertices in the
Vrepresentation
. As the represented polyhedron has no 0-dimensional faces (i.e. vertices),n_vertices
corresponds to the number of \(k\)-faces, where \(k\) is the number of lines:sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0]]) sage: P.n_vertices() 1 sage: P.faces(0) () sage: P.f_vector() (1, 0, 1, 1) sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0],[0,1,1]]) sage: P.n_vertices() 1 sage: P.f_vector() (1, 0, 0, 1, 1)
>>> from sage.all import * >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)]]) >>> P.n_vertices() 1 >>> P.faces(Integer(0)) () >>> P.f_vector() (1, 0, 1, 1) >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(1),Integer(1)]]) >>> P.n_vertices() 1 >>> P.f_vector() (1, 0, 0, 1, 1)
EXAMPLES:
sage: p = Polyhedron(vertices = [[1,0],[0,1],[1,1]], rays=[[1,1]]) sage: p.n_vertices() 2
>>> from sage.all import * >>> p = Polyhedron(vertices = [[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]], rays=[[Integer(1),Integer(1)]]) >>> p.n_vertices() 2
- ray_generator()[source]¶
Return a generator for the rays of the polyhedron.
EXAMPLES:
sage: pi = Polyhedron(ieqs = [[1,1,0],[1,0,1]]) sage: pir = pi.ray_generator() sage: [x.vector() for x in pir] [(1, 0), (0, 1)]
>>> from sage.all import * >>> pi = Polyhedron(ieqs = [[Integer(1),Integer(1),Integer(0)],[Integer(1),Integer(0),Integer(1)]]) >>> pir = pi.ray_generator() >>> [x.vector() for x in pir] [(1, 0), (0, 1)]
- rays()[source]¶
Return a list of rays of the polyhedron.
OUTPUT: a tuple of rays
EXAMPLES:
sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0],[1,1,0,0]]) sage: p.rays() (A ray in the direction (1, 0, 0), A ray in the direction (0, 1, 0), A ray in the direction (0, 0, 1))
>>> from sage.all import * >>> p = Polyhedron(ieqs = [[Integer(0),Integer(0),Integer(0),Integer(1)],[Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(1),Integer(1),Integer(0),Integer(0)]]) >>> p.rays() (A ray in the direction (1, 0, 0), A ray in the direction (0, 1, 0), A ray in the direction (0, 0, 1))
- rays_list()[source]¶
Return a list of rays as coefficient lists.
Note
It is recommended to use
rays()
orray_generator()
instead to iterate over the list ofRay
objects.OUTPUT: list of rays as lists of coordinates
EXAMPLES:
sage: p = Polyhedron(ieqs = [[0,0,0,1],[0,0,1,0],[1,1,0,0]]) sage: p.rays_list() [[1, 0, 0], [0, 1, 0], [0, 0, 1]] sage: p.rays_list() == [list(r) for r in p.ray_generator()] True
>>> from sage.all import * >>> p = Polyhedron(ieqs = [[Integer(0),Integer(0),Integer(0),Integer(1)],[Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(1),Integer(1),Integer(0),Integer(0)]]) >>> p.rays_list() [[1, 0, 0], [0, 1, 0], [0, 0, 1]] >>> p.rays_list() == [list(r) for r in p.ray_generator()] True
- vertex_generator()[source]¶
Return a generator for the vertices of the polyhedron.
Warning
If the polyhedron has lines, return a generator for the vertices of the
Vrepresentation
. However, the represented polyhedron has no 0-dimensional faces (i.e. vertices):sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0]]) sage: list(P.vertex_generator()) [A vertex at (0, 0, 0)] sage: P.faces(0) ()
>>> from sage.all import * >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)]]) >>> list(P.vertex_generator()) [A vertex at (0, 0, 0)] >>> P.faces(Integer(0)) ()
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]]) sage: for v in triangle.vertex_generator(): print(v) A vertex at (0, 1) A vertex at (1, 0) A vertex at (1, 1) sage: v_gen = triangle.vertex_generator() sage: next(v_gen) # the first vertex A vertex at (0, 1) sage: next(v_gen) # the second vertex A vertex at (1, 0) sage: next(v_gen) # the third vertex A vertex at (1, 1) sage: try: next(v_gen) # there are only three vertices ....: except StopIteration: print("STOP") STOP sage: type(v_gen) <... 'generator'> sage: [ v for v in triangle.vertex_generator() ] [A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1)]
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> for v in triangle.vertex_generator(): print(v) A vertex at (0, 1) A vertex at (1, 0) A vertex at (1, 1) >>> v_gen = triangle.vertex_generator() >>> next(v_gen) # the first vertex A vertex at (0, 1) >>> next(v_gen) # the second vertex A vertex at (1, 0) >>> next(v_gen) # the third vertex A vertex at (1, 1) >>> try: next(v_gen) # there are only three vertices ... except StopIteration: print("STOP") STOP >>> type(v_gen) <... 'generator'> >>> [ v for v in triangle.vertex_generator() ] [A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1)]
- vertices()[source]¶
Return all vertices of the polyhedron.
OUTPUT: a tuple of vertices
Warning
If the polyhedron has lines, return the vertices of the
Vrepresentation
. However, the represented polyhedron has no 0-dimensional faces (i.e. vertices):sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0]]) sage: P.vertices() (A vertex at (0, 0, 0),) sage: P.faces(0) ()
>>> from sage.all import * >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)]]) >>> P.vertices() (A vertex at (0, 0, 0),) >>> P.faces(Integer(0)) ()
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]]) sage: triangle.vertices() (A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1)) sage: a_simplex = Polyhedron(ieqs = [ ....: [0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1] ....: ], eqns = [[1,-1,-1,-1,-1]]) sage: a_simplex.vertices() (A vertex at (1, 0, 0, 0), A vertex at (0, 1, 0, 0), A vertex at (0, 0, 1, 0), A vertex at (0, 0, 0, 1))
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> triangle.vertices() (A vertex at (0, 1), A vertex at (1, 0), A vertex at (1, 1)) >>> a_simplex = Polyhedron(ieqs = [ ... [Integer(0),Integer(1),Integer(0),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(0),Integer(0),Integer(1)] ... ], eqns = [[Integer(1),-Integer(1),-Integer(1),-Integer(1),-Integer(1)]]) >>> a_simplex.vertices() (A vertex at (1, 0, 0, 0), A vertex at (0, 1, 0, 0), A vertex at (0, 0, 1, 0), A vertex at (0, 0, 0, 1))
- vertices_list()[source]¶
Return a list of vertices of the polyhedron.
Note
It is recommended to use
vertex_generator()
instead to iterate over the list ofVertex
objects.Warning
If the polyhedron has lines, return the vertices of the
Vrepresentation
. However, the represented polyhedron has no 0-dimensional faces (i.e. vertices):sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0]]) sage: P.vertices_list() [[0, 0, 0]] sage: P.faces(0) ()
>>> from sage.all import * >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)]]) >>> P.vertices_list() [[0, 0, 0]] >>> P.faces(Integer(0)) ()
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]]) sage: triangle.vertices_list() [[0, 1], [1, 0], [1, 1]] sage: a_simplex = Polyhedron(ieqs = [ ....: [0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1] ....: ], eqns = [[1,-1,-1,-1,-1]]) sage: a_simplex.vertices_list() [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] sage: a_simplex.vertices_list() == [list(v) for v in a_simplex.vertex_generator()] True
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> triangle.vertices_list() [[0, 1], [1, 0], [1, 1]] >>> a_simplex = Polyhedron(ieqs = [ ... [Integer(0),Integer(1),Integer(0),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(1),Integer(0),Integer(0)],[Integer(0),Integer(0),Integer(0),Integer(1),Integer(0)],[Integer(0),Integer(0),Integer(0),Integer(0),Integer(1)] ... ], eqns = [[Integer(1),-Integer(1),-Integer(1),-Integer(1),-Integer(1)]]) >>> a_simplex.vertices_list() [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] >>> a_simplex.vertices_list() == [list(v) for v in a_simplex.vertex_generator()] True
- vertices_matrix(base_ring=None)[source]¶
Return the coordinates of the vertices as the columns of a matrix.
INPUT:
base_ring
– a ring orNone
(default); the base ring of the returned matrix. If not specified, the base ring of the polyhedron is used.
OUTPUT:
A matrix over
base_ring
whose columns are the coordinates of the vertices. ATypeError
is raised if the coordinates cannot be converted tobase_ring
.Warning
If the polyhedron has lines, return the coordinates of the vertices of the
Vrepresentation
. However, the represented polyhedron has no 0-dimensional faces (i.e. vertices):sage: P = Polyhedron(rays=[[1,0,0]],lines=[[0,1,0]]) sage: P.vertices_matrix() [0] [0] [0] sage: P.faces(0) ()
>>> from sage.all import * >>> P = Polyhedron(rays=[[Integer(1),Integer(0),Integer(0)]],lines=[[Integer(0),Integer(1),Integer(0)]]) >>> P.vertices_matrix() [0] [0] [0] >>> P.faces(Integer(0)) ()
EXAMPLES:
sage: triangle = Polyhedron(vertices=[[1,0],[0,1],[1,1]]) sage: triangle.vertices_matrix() [0 1 1] [1 0 1] sage: (triangle/2).vertices_matrix() [ 0 1/2 1/2] [1/2 0 1/2] sage: (triangle/2).vertices_matrix(ZZ) Traceback (most recent call last): ... TypeError: no conversion of this rational to integer
>>> from sage.all import * >>> triangle = Polyhedron(vertices=[[Integer(1),Integer(0)],[Integer(0),Integer(1)],[Integer(1),Integer(1)]]) >>> triangle.vertices_matrix() [0 1 1] [1 0 1] >>> (triangle/Integer(2)).vertices_matrix() [ 0 1/2 1/2] [1/2 0 1/2] >>> (triangle/Integer(2)).vertices_matrix(ZZ) Traceback (most recent call last): ... TypeError: no conversion of this rational to integer
- write_cdd_Hrepresentation(filename)[source]¶
Export the polyhedron as a H-representation to a file.
INPUT:
filename
– the output file
See also
cdd_Hrepresentation()
– return the H-representation of the polyhedron as a string.EXAMPLES:
sage: from sage.misc.temporary_file import tmp_filename sage: filename = tmp_filename(ext='.ext') sage: polytopes.cube().write_cdd_Hrepresentation(filename)
>>> from sage.all import * >>> from sage.misc.temporary_file import tmp_filename >>> filename = tmp_filename(ext='.ext') >>> polytopes.cube().write_cdd_Hrepresentation(filename)
- write_cdd_Vrepresentation(filename)[source]¶
Export the polyhedron as a V-representation to a file.
INPUT:
filename
– the output file
See also
cdd_Vrepresentation()
– return the V-representation of the polyhedron as a string.EXAMPLES:
sage: from sage.misc.temporary_file import tmp_filename sage: filename = tmp_filename(ext='.ext') sage: polytopes.cube().write_cdd_Vrepresentation(filename)
>>> from sage.all import * >>> from sage.misc.temporary_file import tmp_filename >>> filename = tmp_filename(ext='.ext') >>> polytopes.cube().write_cdd_Vrepresentation(filename)