Skip to content

Commit

Permalink
Trac #27533: Improve Polyhedron.is_simple()
Browse files Browse the repository at this point in the history
The method `Polyhedron.is_simple` is pretty slow for large polytopes at
the moment. There is no need for that, as the information can be
directly retrieved from the `Vrepresentation`.

Current timings:

{{{
sage: P = polytopes.hypercube(6)
sage: %time P.is_simple()
CPU times: user 360 ms, sys: 8 ms, total: 368 ms
Wall time: 364 ms
True
sage: P = polytopes.hypercube(7)
sage: %time P.is_simple()
CPU times: user 1.78 s, sys: 48 ms, total: 1.83 s
Wall time: 1.74 s
True
sage: P = polytopes.cross_polytope(7)
sage: %time P.is_simple()
CPU times: user 996 ms, sys: 0 ns, total: 996 ms
Wall time: 992 ms
False
}}}

Timings with this ticket:
{{{
sage: P = polytopes.hypercube(6)
sage: %time P.is_simple()
CPU times: user 4 ms, sys: 4 ms, total: 8 ms
Wall time: 3.53 ms
True
sage: P = polytopes.hypercube(7)
sage: %time P.is_simple()
CPU times: user 4 ms, sys: 4 ms, total: 8 ms
Wall time: 5.39 ms
True
sage: P = polytopes.cross_polytope(7)
sage: %time P.is_simple()
CPU times: user 8 ms, sys: 0 ns, total: 8 ms
Wall time: 5.63 ms
False
sage: P = polytopes.permutahedron(4)
sage: %time P.is_simple()
CPU times: user 0 ns, sys: 0 ns, total: 0 ns
Wall time: 1.03 ms
True
}}}

URL: https://trac.sagemath.org/27533
Reported by: gh-kliem
Ticket author(s): Jonathan Kliem
Reviewer(s): Laith Rastanawi
  • Loading branch information
Release Manager authored and vbraun committed Apr 5, 2019
2 parents efd6ffe + cd714a1 commit 1d51f5f
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/sage/geometry/polyhedron/base.py
Expand Up @@ -2644,11 +2644,10 @@ def is_simple(self):
"""
if not self.is_compact(): return False

for v in self.vertex_generator():
adj = [a for a in v.neighbors()]
if len(adj) != self.dim():
return False
return True
d = self.dim()
return all(len([facet for facet in vertex.incident()
if not facet.is_equation()]) == d
for vertex in self.Vrepresentation())

def is_simplicial(self):
"""
Expand Down

0 comments on commit 1d51f5f

Please sign in to comment.