Skip to content

Commit

Permalink
Polyhedron_ZZ.normal_form: New
Browse files Browse the repository at this point in the history
  • Loading branch information
mkoeppe committed Aug 23, 2023
1 parent 757f0e6 commit 593a860
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sage/geometry/lattice_polytope.py
Original file line number Diff line number Diff line change
Expand Up @@ -5023,7 +5023,7 @@ def _palp_convert_permutation(permutation):
OUTPUT:
A :class:`permutation group element <sage.groups.perm_gps.permgroup_element.PermmutationGroupElement>`.
A :class:`permutation group element <sage.groups.perm_gps.permgroup_element.PermutationGroupElement>`.
EXAMPLES::
Expand Down
38 changes: 38 additions & 0 deletions src/sage/geometry/polyhedron/base_ZZ.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,3 +833,41 @@ def is_known_summand(poly):
decompositions.append((X, Y))
summands += [X, Y]
return tuple(decompositions)

def normal_form(self, algorithm="palp_native", permutation=False):
r"""
EXAMPLES:
We compute the normal form of the "diamond"::
sage: d = Polyhedron([(1,0), (0,1), (-1,0), (0,-1)])
sage: d.vertices()
(A vertex at (-1, 0),
A vertex at (0, -1),
A vertex at (0, 1),
A vertex at (1, 0))
sage: d.normal_form()
[(1, 0), (0, 1), (0, -1), (-1, 0)]
It is not possible to compute normal forms for polytopes which do not
span the space::
sage: p = Polyhedron([(1,0,0), (0,1,0), (-1,0,0), (0,-1,0)])
sage: p.normal_form()
Traceback (most recent call last):
...
ValueError: normal form is not defined for A 2-dimensional polyhedron in ZZ^3 defined as the convex hull of 4 vertices
"""
from sage.geometry.palp_normal_form import _palp_PM_max, _palp_canonical_order

if self.dim() < self.ambient_dim():
raise ValueError("normal form is not defined for %s" % self)

PM = self.slack_matrix().transpose()
PM_max, permutations = _palp_PM_max(PM, check=True)
out = _palp_canonical_order(self.vertices(), PM_max, permutations)

if permutation:
return out
else:
return out[0]

0 comments on commit 593a860

Please sign in to comment.