Skip to content

Commit

Permalink
Trac #18213: A lot of polytope constructors are broken
Browse files Browse the repository at this point in the history
A lot of polytopes constructors in `sage.geometry.polyhedron.library`.
For example

1. The Rhombicuboctahedron does not return what it should (as Python
division was thought as Sage integer divisions). There is in the code
{{{
verts = [ [-3/2, -1/2, -1/2], [-3/2, -1/2, 1/2], [-3/2, 1/2, -1/2],
...
}}}

2. The `great_rhombicuboctahedron` is defined over `QQ` but it should be
defined over `QQ[sqrt(2)]`! There are in two places rough approximation
of sqrt(2) in the code
{{{
v1 = QQ(131739771357/54568400000)   # ~ sqrt(2) + 1 but actually 2 due
to Python division
v2 = QQ(104455571357/27284200000)   # ~ 2 sqrt(2) but actually 3 due to
Python division
}}}
Instead, we should use the `base_ring` argument (with appropriate
defaults) and use `base_ring(2).sqrt()` instead.

3. The functions unrelated to construction of Polytopes are moved out of
the class `Polytopes`:
 - `Polytopes.orthonormal_1`, `Polytopes.project_1` will be renamed
respectively `zero_sum_projection` and `project_points`
 - the one line `Polytopes._pfunc` is just removed

While we're at it, remove the deprecations from #11634.

During the process I discovered two annoying bugs:
 - #18214 Bug in volume computation of polyhedron
 - #18220 Bug when creating a polyhedron with coefficients in RR
Moreover, we can get a great speed up with the following because many
polytopes have now coordinates in a quadratic number fields:
 - #18215: Huge speed up for hash of quadratic number field elements
 - #18226: Native _mpfr_ method on quadratic number field elements

URL: http://trac.sagemath.org/18213
Reported by: vdelecroix
Ticket author(s): Vincent Delecroix
Reviewer(s): Nathann Cohen
  • Loading branch information
Release Manager authored and vbraun committed Apr 18, 2015
2 parents 4f7d737 + a58da00 commit 4f541c8
Show file tree
Hide file tree
Showing 15 changed files with 877 additions and 547 deletions.
6 changes: 3 additions & 3 deletions src/doc/en/thematic_tutorials/polytutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,9 @@ list of pre\-built polytopes.

::

sage: P5 = polytopes.n_cube(5)
sage: P5 = polytopes.hypercube(5)
sage: P6 = polytopes.cross_polytope(3)
sage: P7 = polytopes.n_simplex(7)
sage: P7 = polytopes.simplex(7)


.. end of output
Expand All @@ -307,7 +307,7 @@ Let's look at a 4\-dimensional polytope.

::

sage: P8 = polytopes.n_cube(4)
sage: P8 = polytopes.hypercube(4)
sage: P8.plot()
Graphics3d Object

Expand Down
8 changes: 4 additions & 4 deletions src/sage/geometry/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ def FaceFan(polytope, lattice=None):
sage: cuboctahed = polytopes.cuboctahedron()
sage: FaceFan(cuboctahed)
Rational polyhedral fan in 3-d lattice M
sage: cuboctahed.is_lattice_polytope(), cuboctahed.dilation(2).is_lattice_polytope()
(False, True)
sage: cuboctahed.is_lattice_polytope(), cuboctahed.dilation(1/2).is_lattice_polytope()
(True, False)
sage: fan1 = FaceFan(cuboctahed)
sage: fan2 = FaceFan(cuboctahed.dilation(2).lattice_polytope())
sage: fan1.is_equivalent(fan2)
Expand Down Expand Up @@ -745,8 +745,8 @@ def NormalFan(polytope, lattice=None):
TESTS::
sage: cuboctahed.is_lattice_polytope(), cuboctahed.dilation(2).is_lattice_polytope()
(False, True)
sage: cuboctahed.is_lattice_polytope(), cuboctahed.dilation(1/2).is_lattice_polytope()
(True, False)
sage: fan1 = NormalFan(cuboctahed)
sage: fan2 = NormalFan(cuboctahed.dilation(2).lattice_polytope())
sage: fan1.is_equivalent(fan2)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/geometry/hyperplane_arrangement/arrangement.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
Notation (v): from the bounding hyperplanes of a polyhedron::
sage: a = polytopes.n_cube(3).hyperplane_arrangement(); a
sage: a = polytopes.cube().hyperplane_arrangement(); a
Arrangement of 6 hyperplanes of dimension 3 and rank 3
sage: a.n_regions()
27
Expand Down Expand Up @@ -540,7 +540,7 @@ def rank(self):
sage: B.rank()
2
sage: p = polytopes.n_simplex(5)
sage: p = polytopes.simplex(5, project=True)
sage: H = p.hyperplane_arrangement()
sage: H.rank()
5
Expand Down Expand Up @@ -2095,7 +2095,7 @@ def _element_constructor_(self, *args, **kwds):
sage: L._element_constructor_([[0, 1, 0], [0, 0, 1]])
Arrangement <y | x>
sage: L._element_constructor(polytopes.n_cube(2))
sage: L._element_constructor(polytopes.hypercube(2))
Arrangement <-x + 1 | -y + 1 | y + 1 | x + 1>
sage: L(x, x, warn_duplicates=True)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/hyperplane_arrangement/hyperplane.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def intersection(self, other):
sage: h = x + y + z - 1
sage: h.intersection(x - y)
A 1-dimensional polyhedron in QQ^3 defined as the convex hull of 1 vertex and 1 line
sage: h.intersection(polytopes.n_cube(3))
sage: h.intersection(polytopes.cube())
A 2-dimensional polyhedron in QQ^3 defined as the convex hull of 3 vertices
"""
from sage.geometry.polyhedron.base import is_Polyhedron
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/integral_points.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ def rectangular_box_points(box_min, box_max, polyhedron=None,
Optionally, return the information about the saturated inequalities as well::
sage: cube = polytopes.n_cube(3)
sage: cube = polytopes.cube()
sage: cube.Hrepresentation(0)
An inequality (0, 0, -1) x + 1 >= 0
sage: cube.Hrepresentation(1)
Expand Down
Loading

0 comments on commit 4f541c8

Please sign in to comment.