Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
ConvexSet_base.is_finite, cardinality: New
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Jun 20, 2021
1 parent f1db666 commit 6237fbc
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/sage/geometry/convex_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,60 @@ def is_empty(self):
"""
return self.dim() < 0

def is_finite(self):
r"""
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
"""
return self.dim() < 1

def cardinality(self):
"""
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
"""
if self.dim() < 0:
return ZZ(0)
if self.dim() == 0:
return ZZ(1)
return infinity

def is_universe(self):
r"""
Test whether ``self`` is the whole ambient space.
Expand Down

0 comments on commit 6237fbc

Please sign in to comment.