Skip to content

Commit

Permalink
Trac #29323: Set up cross polytope with both Vrep and Hrep (if backen…
Browse files Browse the repository at this point in the history
…d supports it)

We set up the cross polytope with precomputed double description, if the
backend supports it. Otherwise, the vertices will be used as before (the
shorter input is selected automatically by #28880).

Before this ticket:

{{{
sage: %time P = polytopes.cross_polytope(8, backend='field')
CPU times: user 14.3 s, sys: 4.01 ms, total: 14.3 s
Wall time: 14.3 s
sage: %timeit P = polytopes.cross_polytope(13, backend='ppl')
1 loop, best of 5: 312 ms per loop
}}}

With this ticket:

{{{
sage: %time P = polytopes.hypercube(8, backend='field')
CPU times: user 29.8 ms, sys: 11.2 ms, total: 41 ms
Wall time: 40.3 ms
sage: %timeit P = polytopes.cross_polytope(13, backend='ppl')
1 loop, best of 5: 312 ms per loop

sage: %timeit P = polytopes.hypercube(13, backend='field')
10 loops, best of 5: 69.5 ms per loop
}}}

Note: This might slow down some backends (e.g. `ppl`) a bit, as the
inequalities are precomputed and then discarded again. However, this
seems to be only minor. The speed up for backend `field` is significant,
as nothing is being computed anymore.

URL: https://trac.sagemath.org/29323
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Mar 23, 2020
2 parents 084838d + a14d5a1 commit bb0b6ae
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/sage/geometry/polyhedron/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -2871,7 +2871,7 @@ def hypercube(self, dim, intervals=None, backend=None):

else:
raise ValueError("the dimension of the hypercube must match the number of intervals")
return parent([cp, [], []], [ieqs, []], convert=convert, Vrep_minimal=True, Hrep_minimal=True )
return parent([cp, [], []], [ieqs, []], convert=convert, Vrep_minimal=True, Hrep_minimal=True)

def cube(self, intervals=None, backend=None):
r"""
Expand Down Expand Up @@ -2960,10 +2960,19 @@ def cross_polytope(self, dim, backend=None):
sage: cp = polytopes.cross_polytope(4,backend='normaliz') # optional - pynormaliz
sage: TestSuite(cp).run() # optional - pynormaliz
Check that double description is set up correctly::
sage: P = polytopes.cross_polytope(6, backend='ppl')
sage: Q = polytopes.cross_polytope(6, backend='ppl')
sage: P == Q
True
"""
verts = list((ZZ**dim).basis())
verts.extend([-v for v in verts])
return Polyhedron(vertices=verts, backend=backend)
verts = tuple((ZZ**dim).basis())
verts += tuple(-v for v in verts)
ieqs = tuple((1,) + x for x in itertools.product([-1,1], repeat=dim))
parent = Polyhedra(ZZ, dim, backend=backend)
return parent([verts, [], []], [ieqs, []], Vrep_minimal=True, Hrep_minimal=True)

def parallelotope(self, generators, backend=None):
r"""
Expand Down

0 comments on commit bb0b6ae

Please sign in to comment.