Skip to content

Commit

Permalink
Trac #22310: Use PPL for facet normals of full-dimensional polytopes
Browse files Browse the repository at this point in the history
Before:
{{{
sage: timeit("LatticePolytope(lattice_polytope.cross_polytope(3).vertice
s()).facet_normals()")
5 loops, best of 3: 43.2 ms per loop
}}}
After:
{{{
sage: timeit("LatticePolytope(lattice_polytope.cross_polytope(3).vertice
s()).facet_normals()")
125 loops, best of 3: 6.81 ms per loop
}}}
PPL will of course work for non-full-dimensional polytopes as well,
however the treatment of this case is spread around several places and
its removal will be treated separately. Once this is done the speed up
will be even more significant.

Next in the chain of lattice polytope improvements is #22391

URL: https://trac.sagemath.org/22310
Reported by: novoselt
Ticket author(s): Andrey Novoseltsev
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager authored and vbraun committed Mar 27, 2017
2 parents c97f88d + d244793 commit 29de0d7
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 188 deletions.
68 changes: 34 additions & 34 deletions src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,50 +76,50 @@
The last output is not very illuminating. Let's try to improve it::
sage: for cone in fan1: print(cone.rays())
M(1, 0, 0),
M(0, 1, 0),
M(0, 0, -1)
in 3-d lattice M
M( 0, 1, 0),
M(-1, 0, 0),
M( 0, 0, -1)
M( 0, 1, 0),
M( 0, 0, 1),
M(-1, 0, 0)
in 3-d lattice M
M(1, 0, 0),
M(0, -1, 0),
M(0, 0, -1)
M( 0, 0, 1),
M(-1, 0, 0),
M( 0, -1, 0)
in 3-d lattice M
M(-1, 0, 0),
M( 0, -1, 0),
M( 0, 0, -1)
in 3-d lattice M
M( 0, 1, 0),
M(-1, 0, 0),
M( 0, 0, -1)
in 3-d lattice M
M(1, 0, 0),
M(0, 1, 0),
M(0, 0, -1)
in 3-d lattice M
M(1, 0, 0),
M(0, 1, 0),
M(0, 0, 1)
in 3-d lattice M
M( 0, 1, 0),
M( 0, 0, 1),
M(-1, 0, 0)
in 3-d lattice M
M(1, 0, 0),
M(0, 0, 1),
M(0, -1, 0)
in 3-d lattice M
M( 0, 0, 1),
M(-1, 0, 0),
M( 0, -1, 0)
M(1, 0, 0),
M(0, -1, 0),
M(0, 0, -1)
in 3-d lattice M
You can also do ::
sage: for cone in fan1: print(cone.ambient_ray_indices())
(0, 1, 5)
(1, 3, 5)
(0, 4, 5)
(1, 2, 3)
(2, 3, 4)
(3, 4, 5)
(1, 3, 5)
(0, 1, 5)
(0, 1, 2)
(1, 2, 3)
(0, 2, 4)
(2, 3, 4)
(0, 4, 5)
to see indices of rays of the fan corresponding to each cone.
Expand Down Expand Up @@ -618,17 +618,17 @@ def FaceFan(polytope, lattice=None):
M( 0, -1)
in 2-d lattice M
sage: for cone in P1xP1: print(cone.rays())
M(1, 0),
M(0, -1)
in 2-d lattice M
M(-1, 0),
M( 0, -1)
in 2-d lattice M
M( 0, 1),
M(-1, 0)
in 2-d lattice M
M(1, 0),
M(0, 1)
in 2-d lattice M
M( 0, 1),
M(-1, 0)
M(1, 0),
M(0, -1)
in 2-d lattice M
TESTS::
Expand Down Expand Up @@ -720,12 +720,12 @@ def NormalFan(polytope, lattice=None):
sage: P1xP1.rays()
N( 1, 0),
N( 0, 1),
N( 0, -1),
N(-1, 0)
N(-1, 0),
N( 0, -1)
in 2-d lattice N
sage: for cone in P1xP1: print(cone.rays())
N( 0, -1),
N(-1, 0)
N(-1, 0),
N( 0, -1)
in 2-d lattice N
N(1, 0),
N(0, -1)
Expand Down Expand Up @@ -2797,11 +2797,11 @@ def is_smooth(self, codim=None):
sage: fan.is_smooth(codim=1)
True
sage: fan.generating_cone(0).rays()
N(-1, 1),
N(-1, -1)
N(-1, -1),
N(-1, 1)
in 2-d lattice N
sage: fan.generating_cone(0).rays().matrix().det()
2
-2
"""
if codim is None or codim < 0:
codim = 0
Expand Down
20 changes: 10 additions & 10 deletions src/sage/geometry/fan_morphism.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
Domain fan: Rational polyhedral fan in 2-d lattice N
Codomain fan: Rational polyhedral fan in 2-d lattice N
sage: fm.domain_fan().rays()
N(-1, 1),
N( 1, 1),
N(-1, -1),
N( 1, -1),
N(-1, -1),
N(-1, 1),
N( 0, -1),
N( 0, 1)
in 2-d lattice N
sage: normal.rays()
N(-1, 1),
N( 1, 1),
N( 1, -1),
N(-1, -1),
N( 1, -1)
N(-1, 1)
in 2-d lattice N
As you see, it was necessary to insert two new rays (to prevent "upper" and
Expand Down Expand Up @@ -358,14 +358,14 @@ def _RISGIS(self):
sage: fm = FanMorphism(identity_matrix(2),
....: normal, face, subdivide=True)
sage: fm._RISGIS()
(frozenset({3}),
frozenset({2}),
frozenset({1}),
(frozenset({2}),
frozenset({3}),
frozenset({0}),
frozenset({1, 3}),
frozenset({1}),
frozenset({0, 1}),
frozenset({0, 2}),
frozenset({2, 3}))
frozenset({0, 3}),
frozenset({2, 3}),
frozenset({1, 2}))
"""
if "_RISGIS_" not in self.__dict__:
try:
Expand Down
Loading

0 comments on commit 29de0d7

Please sign in to comment.