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

Commit

Permalink
scale rays, lines, inequalities and equations for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Nov 23, 2020
1 parent 2220595 commit 4c1f295
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/sage/geometry/polyhedron/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,70 @@ def __richcmp__(self, other, op):
(0, 1, 0)
sage: ieq != Polyhedron([(0,1,0)]).Vrepresentation(0)
True
TESTS:
Check :trac:`30954`::
sage: P = (1/2)*polytopes.cube()
sage: Q = (1/2)*polytopes.cube(backend='field')
sage: for p in P.inequalities():
....: assert p in Q.inequalities()
"""
if not isinstance(other, PolyhedronRepresentation):
return NotImplemented
if type(self) != type(other):
return NotImplemented
return richcmp(self._vector, other._vector, op)
return richcmp(self._vector*self._comparison_scalar(), other._vector*other._comparison_scalar(), op)

def _comparison_scalar(self):
r"""
Return a number ``a`` such that ``a*self._vector`` is canonical.
Except for vertices, ``self._vector`` is only unique up to a positive scalar.
This is overwritten for the vertex class.
EXAMPLES::
sage: P = Polyhedron(vertices=[[0,0],[1,5]], rays=[[3,4]])
sage: P.Vrepresentation()
(A vertex at (0, 0), A vertex at (1, 5), A ray in the direction (3, 4))
sage: P.Vrepresentation()[0]._comparison_scalar()
1
sage: P.Vrepresentation()[1]._comparison_scalar()
1
sage: P.Vrepresentation()[2]._comparison_scalar()
1/4
sage: P.Hrepresentation()
(An inequality (5, -1) x + 0 >= 0,
An inequality (-4, 3) x + 0 >= 0,
An inequality (4, -3) x + 11 >= 0)
sage: P.Hrepresentation()[0]._comparison_scalar()
1
sage: P.Hrepresentation()[1]._comparison_scalar()
1/3
sage: P.Hrepresentation()[2]._comparison_scalar()
1/3
::
sage: P = Polyhedron(vertices=[[1,3]], lines=[[-1,3]])
sage: P.Vrepresentation()
(A line in the direction (1, -3), A vertex at (2, 0))
sage: P.Vrepresentation()[0]._comparison_scalar()
-1/3
sage: P.Vrepresentation()[1]._comparison_scalar()
1
"""
if self.type() == self.VERTEX:
return 1

lcf = self._vector.leading_coefficient()
if self.type() == self.EQUATION or self.type() == self.LINE:
return 1/lcf
else:
return 1/lcf.abs()

def vector(self, base_ring=None):
"""
Expand Down

0 comments on commit 4c1f295

Please sign in to comment.