From ccc84213906ff6bf34d2e5c6b50d146a2901ec9c Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 6 Jun 2021 22:54:52 -0700 Subject: [PATCH] ConvexSet_base.is_compact, ConvexSet_compact: New --- src/sage/geometry/convex_set.py | 43 +++++++++++++++++++++++++++ src/sage/geometry/lattice_polytope.py | 4 +-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/sage/geometry/convex_set.py b/src/sage/geometry/convex_set.py index 56189f2518c..37ef89ae39e 100644 --- a/src/sage/geometry/convex_set.py +++ b/src/sage/geometry/convex_set.py @@ -101,6 +101,21 @@ def is_closed(self): """ + def is_compact(self): + r""" + Return whether ``self`` is compact. + + OUTPUT: + + Boolean. + + """ + if not self.is_closed(): + return False + if self.dimension() < 1: + return True + raise NotImplementedError + def closure(self): r""" Return the topological closure of ``self``. @@ -152,6 +167,34 @@ def is_open(self): return self.is_empty() or self.is_universe() +class ConvexSet_compact(ConvexSet_closed): + + r""" + Abstract base class for compact convex sets. + """ + + def is_universe(self): + r""" + Return whether ``self`` is the whole ambient space + + OUTPUT: + + Boolean. + """ + return self.ambient_dim() == 0 and not self.is_empty() + + def is_compact(self): + r""" + Return whether ``self`` is compact. + + OUTPUT: + + Boolean. + + """ + return True + + class ConvexSet_relatively_open(ConvexSet_base): r""" diff --git a/src/sage/geometry/lattice_polytope.py b/src/sage/geometry/lattice_polytope.py index 10866bc8c31..a063657e30a 100644 --- a/src/sage/geometry/lattice_polytope.py +++ b/src/sage/geometry/lattice_polytope.py @@ -135,7 +135,7 @@ from sage.structure.all import Sequence from sage.structure.sage_object import SageObject from sage.structure.richcmp import richcmp_method, richcmp -from sage.geometry.convex_set import ConvexSet_closed +from sage.geometry.convex_set import ConvexSet_compact from copy import copy from collections.abc import Hashable @@ -465,7 +465,7 @@ def is_LatticePolytope(x): return isinstance(x, LatticePolytopeClass) @richcmp_method -class LatticePolytopeClass(ConvexSet_closed, Hashable): +class LatticePolytopeClass(ConvexSet_compact, Hashable): r""" Create a lattice polytope.