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

Commit

Permalink
set up permutahedron with precomputed data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Kliem committed Mar 13, 2020
1 parent 6db1a26 commit 33e4490
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2212,11 +2212,35 @@ def permutahedron(self, n, project=False, backend=None):
sage: p4 = polytopes.permutahedron(4,backend='normaliz') # optional - pynormaliz
sage: TestSuite(p4).run() # optional - pynormaliz
Check that precomputed data is correct::
sage: P = polytopes.permutahedron(5, backend='field')
sage: assert P == Polyhedron(P.vertices())
sage: assert P == Polyhedron(ieqs=P.inequalities(), eqns=P.equations())
"""
verts = list(itertools.permutations(range(1, n + 1)))
verts = tuple(itertools.permutations(range(1, n + 1)))
if project:
verts = project_points(*verts)
return Polyhedron(vertices=verts, backend=backend)
return Polyhedron(vertices=verts, backend=backend)
else:
parent = Polyhedra(ZZ, n, backend=backend)
def tri(m):
return (m*(m+1))//2

# Each proper `S \subset [n]` corresponds exactly to
# a facet that minimizes the coordinates in `S`.
# The minimal sum for `m` coordinates is `(m*(m+1))/2`.
ieqs = tuple((-tri(sum(x)),) + x
for x in itertools.product([0,1], repeat=n)
if 0 < sum(x) < n)

# Adding the defining equality.
eqns = ((-tri(n),) + tuple(1 for _ in range(n)),)

return parent([verts, [], []], [ieqs, eqns],
Vrep_minimal=True, Hrep_minimal=True)


def generalized_permutahedron(self, coxeter_type, point=None, exact=True, regular=False, backend=None):
r"""
Expand Down

0 comments on commit 33e4490

Please sign in to comment.