Skip to content

Commit

Permalink
Trac #30248: Normaliz backend is broken with double description input
Browse files Browse the repository at this point in the history
This bug was found while manipulating hyperplane arrangements.

A minimal example to reproduce the bug is:

{{{
sage: p1 = Polyhedron(backend='normaliz', base_ring=AA, rays=[(AA(0),
AA(0), AA(1)), (AA(0), AA(1), AA(-1)), (AA(1), AA(0), AA(-1))],
vertices=[(AA(0), AA(0), AA(0))])
sage: p1
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1
vertex and 3 rays
sage: -p1
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1
vertex and 3 lines
sage: p2 = Polyhedron(backend='normaliz', base_ring=AA, rays=[(AA(-1),
AA(0), AA(1)), (AA(-1), AA(1), AA(0)), (AA(0), AA(0), AA(-1))],
vertices=[(AA(0), AA(0), AA(0))])
sage: p2
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1
vertex and 3 rays
sage: -p2
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1
vertex and 3 lines
}}}

Looking at `dilation` it seems that dilation is not the problem, it does
the right thing, but the `parent.element_class` call messes things up.

Notice that changing the base ring to `QQ` or `ZZ` or removing the
`'normaliz'` backend, one does not get the error... This is nasty.

In the hyperplane arrangement, there are some rational regions, and some
irrational regions...

URL: https://trac.sagemath.org/30248
Reported by: jipilab
Ticket author(s): Jean-Philippe Labbé
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Aug 8, 2020
2 parents f55701e + 83453fb commit ed79ba3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sage/geometry/polyhedron/backend_normaliz.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,18 @@ def _init_from_Hrepresentation(self, ieqs, eqns, minimize=True, verbose=False):
sage: p = Polyhedron(ieqs=[(1, a, 0)], backend='normaliz') # optional - pynormaliz
sage: p & p == p # optional - pynormaliz
True
Check that :trac:`30248` is fixed, that maps as input works::
sage: q = Polyhedron(backend='normaliz', base_ring=AA, # optional - pynormaliz
....: rays=[(0, 0, 1), (0, 1, -1), (1, 0, -1)])
sage: make_new_Hrep = lambda h: tuple(x if i == 0 else -1*x for i, x in enumerate(h._vector))
sage: new_inequalities = map(make_new_Hrep, q.inequality_generator()) # optional - pynormaliz
sage: new_equations = map(make_new_Hrep, q.equation_generator()) # optional - pynormaliz
sage: parent = q.parent() # optional - pynormaliz
sage: new_q = parent.element_class(parent,None,[new_inequalities,new_equations]) # optional - pynormaliz
sage: new_q # optional - pynormaliz
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1 vertex and 3 rays
"""

def nmz_ieqs_eqns_NF(ieqs, eqns):
Expand Down Expand Up @@ -829,7 +841,13 @@ def _compute_nmz_data_lists_and_field(self, data_lists, convert_QQ, convert_NF):
...
ValueError: invalid base ring: Number Field in a ... is not real embedded
Checks that :trac:`30248` is fixed::
sage: q = Polyhedron(backend='normaliz', base_ring=AA, # indirect doctest # optional - pynormaliz
....: rays=[(0, 0, 1), (0, 1, -1), (1, 0, -1)]); q
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1 vertex and 3 rays
sage: -q # optional - pynormaliz
A 3-dimensional polyhedron in AA^3 defined as the convex hull of 1 vertex and 3 rays
"""
from sage.categories.number_fields import NumberFields
from sage.rings.all import RDF
Expand All @@ -838,6 +856,9 @@ def _compute_nmz_data_lists_and_field(self, data_lists, convert_QQ, convert_NF):
normaliz_field = QQ
nmz_data_lists = convert_QQ(*data_lists)
else:
# Allows to re-iterate if K is QQ below when data_lists contain
# iterators:
data_lists = [tuple(_) for _ in data_lists]
nmz_data_lists = convert_NF(*data_lists)
if self.base_ring() in NumberFields:
if not RDF.has_coerce_map_from(self.base_ring()):
Expand Down

0 comments on commit ed79ba3

Please sign in to comment.