Convex Sets#

class sage.geometry.convex_set.AffineHullProjectionData(image: Any | None = None, projection_linear_map: Any | None = None, projection_translation: Any | None = None, section_linear_map: Any | None = None, section_translation: Any | None = None)[source]#

Bases: object

image: Any = None#
projection_linear_map: Any = None#
projection_translation: Any = None#
section_linear_map: Any = None#
section_translation: Any = None#
class sage.geometry.convex_set.ConvexSet_base[source]#

Bases: SageObject, Set_base

Abstract base class for convex sets.

affine_hull(*args, **kwds)[source]#

Return the affine hull of self as a polyhedron.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_compact
sage: class EmbeddedDisk(ConvexSet_compact):
....:     def an_affine_basis(self):
....:         return [vector([1, 0, 0]), vector([1, 1, 0]), vector([1, 0, 1])]
sage: O = EmbeddedDisk()
sage: O.dim()
2
sage: O.affine_hull()
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 2 lines
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_compact
>>> class EmbeddedDisk(ConvexSet_compact):
...     def an_affine_basis(self):
...         return [vector([Integer(1), Integer(0), Integer(0)]), vector([Integer(1), Integer(1), Integer(0)]), vector([Integer(1), Integer(0), Integer(1)])]
>>> O = EmbeddedDisk()
>>> O.dim()
2
>>> O.affine_hull()
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 2 lines
affine_hull_projection(as_convex_set=None, as_affine_map=False, orthogonal=False, orthonormal=False, extend=False, minimal=False, return_all_data=False, **kwds)[source]#

Return self projected into its affine hull.

Each convex set is contained in some smallest affine subspace (possibly the entire ambient space) – its affine hull. We provide an affine linear map that projects the ambient space of the convex set to the standard Euclidean space of dimension of the convex set, which restricts to a bijection from the affine hull.

The projection map is not unique; some parameters control the choice of the map. Other parameters control the output of the function.

EXAMPLES:

sage: P = Polyhedron(vertices=[[1, 0], [0, 1]])
sage: ri_P = P.relative_interior(); ri_P
Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
sage: ri_P.affine_hull_projection(as_affine_map=True)
(Vector space morphism represented by the matrix:
[1]
[0]
Domain: Vector space of dimension 2 over Rational Field
Codomain: Vector space of dimension 1 over Rational Field,
(0))
sage: P_aff = P.affine_hull_projection(); P_aff
A 1-dimensional polyhedron in ZZ^1 defined as the convex hull of 2 vertices
sage: ri_P_aff = ri_P.affine_hull_projection(); ri_P_aff
Relative interior of a 1-dimensional polyhedron in QQ^1 defined as the convex hull of 2 vertices
sage: ri_P_aff.closure() == P_aff
True
>>> from sage.all import *
>>> P = Polyhedron(vertices=[[Integer(1), Integer(0)], [Integer(0), Integer(1)]])
>>> ri_P = P.relative_interior(); ri_P
Relative interior of a 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 2 vertices
>>> ri_P.affine_hull_projection(as_affine_map=True)
(Vector space morphism represented by the matrix:
[1]
[0]
Domain: Vector space of dimension 2 over Rational Field
Codomain: Vector space of dimension 1 over Rational Field,
(0))
>>> P_aff = P.affine_hull_projection(); P_aff
A 1-dimensional polyhedron in ZZ^1 defined as the convex hull of 2 vertices
>>> ri_P_aff = ri_P.affine_hull_projection(); ri_P_aff
Relative interior of a 1-dimensional polyhedron in QQ^1 defined as the convex hull of 2 vertices
>>> ri_P_aff.closure() == P_aff
True
ambient()[source]#

Return the ambient convex set or space.

The default implementation delegates to ambient_vector_space().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def ambient_vector_space(self, base_field=None):
....:         return (base_field or QQ)^2001
sage: ExampleSet().ambient()
Vector space of dimension 2001 over Rational Field
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def ambient_vector_space(self, base_field=None):
...         return (base_field or QQ)**Integer(2001)
>>> ExampleSet().ambient()
Vector space of dimension 2001 over Rational Field
ambient_dim()[source]#

Return the dimension of the ambient convex set or space.

The default implementation obtains it from ambient().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def ambient(self):
....:         return QQ^7
sage: ExampleSet().ambient_dim()
7
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def ambient(self):
...         return QQ**Integer(7)
>>> ExampleSet().ambient_dim()
7
ambient_dimension()[source]#

Return the dimension of the ambient convex set or space.

This is the same as ambient_dim().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def ambient_dim(self):
....:         return 91
sage: ExampleSet().ambient_dimension()
91
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def ambient_dim(self):
...         return Integer(91)
>>> ExampleSet().ambient_dimension()
91
ambient_vector_space(base_field=None)[source]#

Return the ambient vector space.

Subclasses must provide an implementation of this method.

The default implementations of ambient(), ambient_dim(), ambient_dimension() use this method.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.ambient_vector_space()
Traceback (most recent call last):
...
NotImplementedError: <abstract method ambient_vector_space at ...>
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> C = ConvexSet_base()
>>> C.ambient_vector_space()
Traceback (most recent call last):
...
NotImplementedError: <abstract method ambient_vector_space at ...>
an_affine_basis()[source]#

Return points that form an affine basis for the affine hull.

The points are guaranteed to lie in the topological closure of self.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: C = ConvexSet_base()
sage: C.an_affine_basis()
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> C = ConvexSet_base()
>>> C.an_affine_basis()
Traceback (most recent call last):
...
TypeError: 'NotImplementedType' object is not callable
an_element()[source]#

Return a point of self.

If self is empty, an EmptySetError will be raised.

The default implementation delegates to _some_elements_().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_compact
sage: class BlueBox(ConvexSet_compact):
....:     def _some_elements_(self):
....:         yield 'blue'
....:         yield 'cyan'
sage: BlueBox().an_element()
'blue'
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_compact
>>> class BlueBox(ConvexSet_compact):
...     def _some_elements_(self):
...         yield 'blue'
...         yield 'cyan'
>>> BlueBox().an_element()
'blue'
cardinality()[source]#

Return the cardinality of this set.

OUTPUT:

Either an integer or Infinity.

EXAMPLES:

sage: p = LatticePolytope([], lattice=ToricLattice(3).dual()); p
-1-d lattice polytope in 3-d lattice M
sage: p.cardinality()
0
sage: q = Polyhedron(ambient_dim=2); q
The empty polyhedron in ZZ^2
sage: q.cardinality()
0
sage: r = Polyhedron(rays=[(1, 0)]); r
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray
sage: r.cardinality()
+Infinity
>>> from sage.all import *
>>> p = LatticePolytope([], lattice=ToricLattice(Integer(3)).dual()); p
-1-d lattice polytope in 3-d lattice M
>>> p.cardinality()
0
>>> q = Polyhedron(ambient_dim=Integer(2)); q
The empty polyhedron in ZZ^2
>>> q.cardinality()
0
>>> r = Polyhedron(rays=[(Integer(1), Integer(0))]); r
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray
>>> r.cardinality()
+Infinity
cartesian_product(other)[source]#

Return the Cartesian product.

INPUT:

  • other – another convex set

OUTPUT:

The Cartesian product of self and other.

closure()[source]#

Return the topological closure of self.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_closed
sage: C = ConvexSet_closed()
sage: C.closure() is C
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_closed
>>> C = ConvexSet_closed()
>>> C.closure() is C
True
codim()[source]#

Return the codimension of self in self.ambient().

EXAMPLES:

sage: P = Polyhedron(vertices=[(1,2,3)], rays=[(1,0,0)])
sage: P.codimension()
2
>>> from sage.all import *
>>> P = Polyhedron(vertices=[(Integer(1),Integer(2),Integer(3))], rays=[(Integer(1),Integer(0),Integer(0))])
>>> P.codimension()
2

An alias is codim():

sage: P.codim()
2
>>> from sage.all import *
>>> P.codim()
2
codimension()[source]#

Return the codimension of self in self.ambient().

EXAMPLES:

sage: P = Polyhedron(vertices=[(1,2,3)], rays=[(1,0,0)])
sage: P.codimension()
2
>>> from sage.all import *
>>> P = Polyhedron(vertices=[(Integer(1),Integer(2),Integer(3))], rays=[(Integer(1),Integer(0),Integer(0))])
>>> P.codimension()
2

An alias is codim():

sage: P.codim()
2
>>> from sage.all import *
>>> P.codim()
2
contains(point)[source]#

Test whether self contains the given point.

INPUT:

  • point – a point or its coordinates

dilation(scalar)[source]#

Return the dilated (uniformly stretched) set.

INPUT:

  • scalar – A scalar, not necessarily in base_ring()

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_compact
sage: class GlorifiedPoint(ConvexSet_compact):
....:     def __init__(self, p):
....:         self._p = p
....:     def ambient_vector_space(self):
....:         return self._p.parent().vector_space()
....:     def linear_transformation(self, linear_transf):
....:         return GlorifiedPoint(linear_transf * self._p)
sage: P = GlorifiedPoint(vector([2, 3]))
sage: P.dilation(10)._p
(20, 30)
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_compact
>>> class GlorifiedPoint(ConvexSet_compact):
...     def __init__(self, p):
...         self._p = p
...     def ambient_vector_space(self):
...         return self._p.parent().vector_space()
...     def linear_transformation(self, linear_transf):
...         return GlorifiedPoint(linear_transf * self._p)
>>> P = GlorifiedPoint(vector([Integer(2), Integer(3)]))
>>> P.dilation(Integer(10))._p
(20, 30)
dim()[source]#

Return the dimension of self.

Subclasses must provide an implementation of this method or of the method an_affine_basis().

dimension()[source]#

Return the dimension of self.

This is the same as dim().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def dim(self):
....:         return 42
sage: ExampleSet().dimension()
42
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def dim(self):
...         return Integer(42)
>>> ExampleSet().dimension()
42
interior()[source]#

Return the topological interior of self.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_open
sage: C = ConvexSet_open()
sage: C.interior() is C
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_open
>>> C = ConvexSet_open()
>>> C.interior() is C
True
intersection(other)[source]#

Return the intersection of self and other.

INPUT:

  • other – another convex set

OUTPUT:

The intersection.

is_closed()[source]#

Return whether self is closed.

The default implementation of this method only knows that the empty set, a singleton set, and the ambient space are closed.

OUTPUT:

Boolean.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def dim(self):
....:         return 0
sage: ExampleSet().is_closed()
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def dim(self):
...         return Integer(0)
>>> ExampleSet().is_closed()
True
is_compact()[source]#

Return whether self is compact.

The default implementation of this method only knows that a non-closed set cannot be compact, and that the empty set and a singleton set are compact.

OUTPUT:

Boolean.

sage: from sage.geometry.convex_set import ConvexSet_base sage: class ExampleSet(ConvexSet_base): ….: def dim(self): ….: return 0 sage: ExampleSet().is_compact() True

is_empty()[source]#

Test whether self is the empty set.

OUTPUT:

Boolean.

EXAMPLES:

sage: p = LatticePolytope([], lattice=ToricLattice(3).dual()); p
-1-d lattice polytope in 3-d lattice M
sage: p.is_empty()
True
>>> from sage.all import *
>>> p = LatticePolytope([], lattice=ToricLattice(Integer(3)).dual()); p
-1-d lattice polytope in 3-d lattice M
>>> p.is_empty()
True
is_finite()[source]#

Test whether self is a finite set.

OUTPUT:

Boolean.

EXAMPLES:

sage: p = LatticePolytope([], lattice=ToricLattice(3).dual()); p
-1-d lattice polytope in 3-d lattice M
sage: p.is_finite()
True
sage: q = Polyhedron(ambient_dim=2); q
The empty polyhedron in ZZ^2
sage: q.is_finite()
True
sage: r = Polyhedron(rays=[(1, 0)]); r
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray
sage: r.is_finite()
False
>>> from sage.all import *
>>> p = LatticePolytope([], lattice=ToricLattice(Integer(3)).dual()); p
-1-d lattice polytope in 3-d lattice M
>>> p.is_finite()
True
>>> q = Polyhedron(ambient_dim=Integer(2)); q
The empty polyhedron in ZZ^2
>>> q.is_finite()
True
>>> r = Polyhedron(rays=[(Integer(1), Integer(0))]); r
A 1-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex and 1 ray
>>> r.is_finite()
False
is_full_dimensional()[source]#

Return whether self is full dimensional.

OUTPUT:

Boolean. Whether the polyhedron is not contained in any strict affine subspace.

EXAMPLES:

sage: c = Cone([(1,0)])
sage: c.is_full_dimensional()
False

sage: polytopes.hypercube(3).is_full_dimensional()
True
sage: Polyhedron(vertices=[(1,2,3)], rays=[(1,0,0)]).is_full_dimensional()
False
>>> from sage.all import *
>>> c = Cone([(Integer(1),Integer(0))])
>>> c.is_full_dimensional()
False

>>> polytopes.hypercube(Integer(3)).is_full_dimensional()
True
>>> Polyhedron(vertices=[(Integer(1),Integer(2),Integer(3))], rays=[(Integer(1),Integer(0),Integer(0))]).is_full_dimensional()
False
is_open()[source]#

Return whether self is open.

The default implementation of this method only knows that the empty set and the ambient space are open.

OUTPUT:

Boolean.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def is_empty(self):
....:         return False
....:     def is_universe(self):
....:         return True
sage: ExampleSet().is_open()
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def is_empty(self):
...         return False
...     def is_universe(self):
...         return True
>>> ExampleSet().is_open()
True
is_relatively_open()[source]#

Return whether self is relatively open.

The default implementation of this method only knows that open sets are also relatively open, and in addition singletons are relatively open.

OUTPUT:

Boolean.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_base
sage: class ExampleSet(ConvexSet_base):
....:     def is_open(self):
....:         return True
sage: ExampleSet().is_relatively_open()
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_base
>>> class ExampleSet(ConvexSet_base):
...     def is_open(self):
...         return True
>>> ExampleSet().is_relatively_open()
True
is_universe()[source]#

Test whether self is the whole ambient space.

OUTPUT:

Boolean.

linear_transformation(linear_transf)[source]#

Return the linear transformation of self.

INPUT:

  • linear_transf – a matrix

relative_interior()[source]#

Return the relative interior of self.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_relatively_open
sage: C = ConvexSet_relatively_open()
sage: C.relative_interior() is C
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_relatively_open
>>> C = ConvexSet_relatively_open()
>>> C.relative_interior() is C
True
representative_point()[source]#

Return a “generic” point of self.

OUTPUT:

A point in the relative interior of self as a coordinate vector.

EXAMPLES:

sage: C = Cone([[1, 2, 0], [2, 1, 0]])
sage: C.representative_point()
(1, 1, 0)
>>> from sage.all import *
>>> C = Cone([[Integer(1), Integer(2), Integer(0)], [Integer(2), Integer(1), Integer(0)]])
>>> C.representative_point()
(1, 1, 0)
some_elements()[source]#

Return a list of some points of self.

If self is empty, an empty list is returned; no exception will be raised.

The default implementation delegates to _some_elements_().

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_compact
sage: class BlueBox(ConvexSet_compact):
....:     def _some_elements_(self):
....:         yield 'blue'
....:         yield 'cyan'
sage: BlueBox().some_elements()
['blue', 'cyan']
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_compact
>>> class BlueBox(ConvexSet_compact):
...     def _some_elements_(self):
...         yield 'blue'
...         yield 'cyan'
>>> BlueBox().some_elements()
['blue', 'cyan']
translation(displacement)[source]#

Return the translation of self by a displacement vector.

INPUT:

  • displacement – a displacement vector or a list/tuple of coordinates that determines a displacement vector

class sage.geometry.convex_set.ConvexSet_closed[source]#

Bases: ConvexSet_base

Abstract base class for closed convex sets.

is_closed()[source]#

Return whether self is closed.

OUTPUT:

Boolean.

EXAMPLES:

sage: hcube = polytopes.hypercube(5)
sage: hcube.is_closed()
True
>>> from sage.all import *
>>> hcube = polytopes.hypercube(Integer(5))
>>> hcube.is_closed()
True
is_open()[source]#

Return whether self is open.

OUTPUT:

Boolean.

EXAMPLES:

sage: hcube = polytopes.hypercube(5)
sage: hcube.is_open()
False

sage: zerocube = polytopes.hypercube(0)
sage: zerocube.is_open()
True
>>> from sage.all import *
>>> hcube = polytopes.hypercube(Integer(5))
>>> hcube.is_open()
False

>>> zerocube = polytopes.hypercube(Integer(0))
>>> zerocube.is_open()
True
class sage.geometry.convex_set.ConvexSet_compact[source]#

Bases: ConvexSet_closed

Abstract base class for compact convex sets.

is_compact()[source]#

Return whether self is compact.

OUTPUT:

Boolean.

EXAMPLES:

sage: cross3 = lattice_polytope.cross_polytope(3)
sage: cross3.is_compact()
True
>>> from sage.all import *
>>> cross3 = lattice_polytope.cross_polytope(Integer(3))
>>> cross3.is_compact()
True
is_relatively_open()[source]#

Return whether self is open.

OUTPUT:

Boolean.

EXAMPLES:

sage: hcube = polytopes.hypercube(5)
sage: hcube.is_open()
False

sage: zerocube = polytopes.hypercube(0)
sage: zerocube.is_open()
True
>>> from sage.all import *
>>> hcube = polytopes.hypercube(Integer(5))
>>> hcube.is_open()
False

>>> zerocube = polytopes.hypercube(Integer(0))
>>> zerocube.is_open()
True
is_universe()[source]#

Return whether self is the whole ambient space

OUTPUT:

Boolean.

EXAMPLES:

sage: cross3 = lattice_polytope.cross_polytope(3)
sage: cross3.is_universe()
False
sage: point0 = LatticePolytope([[]]); point0
0-d reflexive polytope in 0-d lattice M
sage: point0.is_universe()
True
>>> from sage.all import *
>>> cross3 = lattice_polytope.cross_polytope(Integer(3))
>>> cross3.is_universe()
False
>>> point0 = LatticePolytope([[]]); point0
0-d reflexive polytope in 0-d lattice M
>>> point0.is_universe()
True
class sage.geometry.convex_set.ConvexSet_open[source]#

Bases: ConvexSet_relatively_open

Abstract base class for open convex sets.

is_closed()[source]#

Return whether self is closed.

OUTPUT:

Boolean.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_open
sage: class OpenBall(ConvexSet_open):
....:     def dim(self):
....:         return 3
....:     def is_universe(self):
....:         return False
sage: OpenBall().is_closed()
False
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_open
>>> class OpenBall(ConvexSet_open):
...     def dim(self):
...         return Integer(3)
...     def is_universe(self):
...         return False
>>> OpenBall().is_closed()
False
is_open()[source]#

Return whether self is open.

OUTPUT:

Boolean.

EXAMPLES:

sage: from sage.geometry.convex_set import ConvexSet_open
sage: b = ConvexSet_open()
sage: b.is_open()
True
>>> from sage.all import *
>>> from sage.geometry.convex_set import ConvexSet_open
>>> b = ConvexSet_open()
>>> b.is_open()
True
class sage.geometry.convex_set.ConvexSet_relatively_open[source]#

Bases: ConvexSet_base

Abstract base class for relatively open convex sets.

is_open()[source]#

Return whether self is open.

OUTPUT:

Boolean.

EXAMPLES:

sage: segment = Polyhedron([[1, 2], [3, 4]])
sage: ri_segment = segment.relative_interior()
sage: ri_segment.is_open()
False
>>> from sage.all import *
>>> segment = Polyhedron([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])
>>> ri_segment = segment.relative_interior()
>>> ri_segment.is_open()
False
is_relatively_open()[source]#

Return whether self is relatively open.

OUTPUT:

Boolean.

EXAMPLES:

sage: segment = Polyhedron([[1, 2], [3, 4]])
sage: ri_segment = segment.relative_interior()
sage: ri_segment.is_relatively_open()
True
>>> from sage.all import *
>>> segment = Polyhedron([[Integer(1), Integer(2)], [Integer(3), Integer(4)]])
>>> ri_segment = segment.relative_interior()
>>> ri_segment.is_relatively_open()
True