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

Commit

Permalink
Merge #31959
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Jun 16, 2021
2 parents 30ee8d6 + 0c9bc94 commit 7d3ae5c
Show file tree
Hide file tree
Showing 7 changed files with 1,509 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/doc/en/reference/discrete_geometry/index.rst
Expand Up @@ -105,8 +105,10 @@ Miscellaneous
.. toctree::
:maxdepth: 1

sage/geometry/convex_set
sage/geometry/linear_expression
sage/geometry/newton_polygon
sage/geometry/relative_interior
sage/geometry/ribbon_graph
sage/geometry/pseudolines
sage/geometry/voronoi_diagram
Expand Down
165 changes: 161 additions & 4 deletions src/sage/geometry/cone.py
Expand Up @@ -181,9 +181,18 @@
"""

# ****************************************************************************
# Copyright (C) 2010 Volker Braun <vbraun.name@gmail.com>
# Copyright (C) 2012 Andrey Novoseltsev <novoselt@gmail.com>
# Copyright (C) 2010 William Stein <wstein@gmail.com>
# Copyright (C) 2010-2014 Volker Braun <vbraun.name@gmail.com>
# Copyright (C) 2010-2018 Andrey Novoseltsev <novoselt@gmail.com>
# Copyright (C) 2010 William Stein <wstein@gmail.com>
# Copyright (C) 2012 Christian Stump
# Copyright (C) 2014-2018 Frédéric Chapoton
# Copyright (C) 2014 Peter Bruin
# Copyright (C) 2015-2017 Jori Mäntysalo
# Copyright (C) 2015-2020 Michael Orlitzky
# Copyright (C) 2016-2020 John H. Palmieri
# Copyright (C) 2018 David Coudert
# Copyright (C) 2019-2020 Jonathan Kliem
# Copyright (C) 2020-2021 Matthias Koeppe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -205,6 +214,7 @@
from sage.geometry.toric_lattice import (ToricLattice, is_ToricLattice,
is_ToricLatticeQuotient)
from sage.geometry.toric_plotter import ToricPlotter, label_list
from sage.geometry.relative_interior import RelativeInterior
from sage.graphs.digraph import DiGraph
from sage.matrix.all import column_matrix, matrix, MatrixSpace
from sage.misc.all import cached_method, flatten, latex
Expand All @@ -213,6 +223,7 @@
from sage.structure.all import SageObject, parent
from sage.structure.richcmp import richcmp_method, richcmp
from sage.geometry.integral_points import parallelotope_points
from sage.geometry.convex_set import ConvexSet_closed

from sage.misc.lazy_import import lazy_import
from sage.features import PythonModule
Expand Down Expand Up @@ -970,6 +981,26 @@ def lattice(self):
"""
return self._lattice

def ambient_vector_space(self, base_field=None):
r"""
Return the ambient vector space.
It is the ambient lattice (:meth:`lattice`) tensored with a field.
INPUT::
- ``base_field`` -- (default: the rationals) a field.
EXAMPLES::
sage: c = Cone([(1,0)])
sage: c.ambient_vector_space()
Vector space of dimension 2 over Rational Field
sage: c.ambient_vector_space(AA)
Vector space of dimension 2 over Algebraic Real Field
"""
return self.lattice().vector_space(base_field=base_field)

@cached_method
def dual_lattice(self):
r"""
Expand Down Expand Up @@ -1009,6 +1040,8 @@ def lattice_dim(self):
r"""
Return the dimension of the ambient lattice of ``self``.
An alias is :meth:`ambient_dim`.
OUTPUT:
- integer.
Expand All @@ -1023,6 +1056,8 @@ def lattice_dim(self):
"""
return self.lattice().dimension()

ambient_dim = lattice_dim

def nrays(self):
r"""
Return the number of rays of ``self``.
Expand Down Expand Up @@ -1210,8 +1245,11 @@ def codim(self):
sage: K.codim() == K.dual().lineality()
True
"""
# same as ConvexSet_base.codim; the main point is the much more detailed
# docstring.
return (self.lattice_dim() - self.dim())

codimension = codim

def span(self, base_ring=None):
r"""
Expand Down Expand Up @@ -1375,7 +1413,7 @@ def classify_cone_2d(ray0, ray1, check=True):
# and ``ambient_ray_indices`` keyword parameters. See ``intersection`` method
# for an example why this is needed.
@richcmp_method
class ConvexRationalPolyhedralCone(IntegralRayCollection, Container):
class ConvexRationalPolyhedralCone(IntegralRayCollection, Container, ConvexSet_closed):
r"""
Create a convex rational polyhedral cone.
Expand Down Expand Up @@ -1711,6 +1749,43 @@ def interior_contains(self, *args):
point = point[0]
return self._contains(point, 'interior')

@cached_method
def interior(self):
r"""
Return the interior of ``self``.
OUTPUT:
- either ``self``, an empty polyhedron, or an instance of
:class:`~sage.geometry.relative_interior.RelativeInterior`.
EXAMPLES::
sage: c = Cone([(1,0,0), (0,1,0)]); c
2-d cone in 3-d lattice N
sage: c.interior()
The empty polyhedron in ZZ^3
sage: origin = cones.trivial(2); origin
0-d cone in 2-d lattice N
sage: origin.interior()
The empty polyhedron in ZZ^2
sage: K = cones.nonnegative_orthant(2); K
2-d cone in 2-d lattice N
sage: K.interior()
Relative interior of 2-d cone in 2-d lattice N
sage: K2 = Cone([(1,0),(-1,0),(0,1),(0,-1)]); K2
2-d cone in 2-d lattice N
sage: K2.interior() is K2
True
"""
if self.is_solid():
return self.relative_interior()
return Polyhedron(ambient_dim=self.lattice_dim())

def relative_interior_contains(self, *args):
r"""
Check if a given point is contained in the relative interior of ``self``.
Expand Down Expand Up @@ -1752,6 +1827,42 @@ def relative_interior_contains(self, *args):
point = point[0]
return self._contains(point, 'relative interior')

@cached_method
def relative_interior(self):
r"""
Return the relative interior of ``self``.
OUTPUT:
- either ``self`` or an instance of
:class:`~sage.geometry.relative_interior.RelativeInterior`.
EXAMPLES::
sage: c = Cone([(1,0,0), (0,1,0)]); c
2-d cone in 3-d lattice N
sage: c.relative_interior()
Relative interior of 2-d cone in 3-d lattice N
sage: origin = cones.trivial(2); origin
0-d cone in 2-d lattice N
sage: origin.relative_interior() is origin
True
sage: K1 = Cone([(1,0), (-1,0)]); K1
1-d cone in 2-d lattice N
sage: K1.relative_interior() is K1
True
sage: K2 = Cone([(1,0),(-1,0),(0,1),(0,-1)]); K2
2-d cone in 2-d lattice N
sage: K2.relative_interior() is K2
True
"""
if self.is_relatively_open():
return self
return RelativeInterior(self)

def cartesian_product(self, other, lattice=None):
r"""
Return the Cartesian product of ``self`` with ``other``.
Expand Down Expand Up @@ -3190,6 +3301,21 @@ def is_smooth(self):
return False
return self.rays().matrix().elementary_divisors() == [1] * self.nrays()

def is_empty(self):
"""
Return whether ``self`` is the empty set.
Because a cone always contains the origin, this method returns ``False``.
EXAMPLES::
sage: trivial_cone = cones.trivial(3)
sage: trivial_cone.is_empty()
False
"""
return False

def is_trivial(self):
"""
Checks if the cone has no rays.
Expand All @@ -3208,6 +3334,8 @@ def is_trivial(self):
"""
return self.nrays() == 0

is_compact = is_trivial

def is_strictly_convex(self):
r"""
Check if ``self`` is strictly convex.
Expand Down Expand Up @@ -4447,6 +4575,8 @@ def is_solid(self):
A cone is said to be solid if it has nonempty interior. That
is, if its extreme rays span the entire ambient space.
An alias is :meth:`is_full_dimensional`.
OUTPUT:
``True`` if this cone is solid, and ``False`` otherwise.
Expand Down Expand Up @@ -4486,6 +4616,8 @@ def is_solid(self):
"""
return (self.dim() == self.lattice_dim())

is_full_dimensional = is_solid

def is_proper(self):
r"""
Check if this cone is proper.
Expand Down Expand Up @@ -4536,6 +4668,8 @@ def is_full_space(self):
r"""
Check if this cone is equal to its ambient vector space.
An alias is :meth:`is_universe`.
OUTPUT:
``True`` if this cone equals its entire ambient vector
Expand Down Expand Up @@ -4573,6 +4707,8 @@ def is_full_space(self):
"""
return self.linear_subspace() == self.lattice().vector_space()

is_universe = is_full_space

def lineality(self):
r"""
Return the lineality of this cone.
Expand Down Expand Up @@ -4645,6 +4781,27 @@ def lineality(self):
"""
return self.linear_subspace().dimension()

def is_relatively_open(self):
r"""
Return whether ``self`` is relatively open.
OUTPUT:
Boolean.
EXAMPLES::
sage: K = cones.nonnegative_orthant(3)
sage: K.is_relatively_open()
False
sage: K1 = Cone([(1,0), (-1,0)]); K1
1-d cone in 2-d lattice N
sage: K1.is_relatively_open()
True
"""
return self.lineality() == self.dim()

@cached_method
def discrete_complementarity_set(self):
r"""
Expand Down

0 comments on commit 7d3ae5c

Please sign in to comment.