Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
normalizing for rational input, when converting polyhedra to RDF
Browse files Browse the repository at this point in the history
  • Loading branch information
mo271 committed Mar 30, 2017
1 parent 8204e97 commit bc1dd36
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 94 deletions.
6 changes: 3 additions & 3 deletions src/sage/geometry/polyhedron/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@
sage: triangle = Polyhedron([(0,0), (1,0), (1/2, sqrt(3)/2)], base_ring=AA)
sage: triangle.Hrepresentation()
(An inequality (-1, -0.5773502691896258?) x + 1 >= 0,
An inequality (1, -0.5773502691896258?) x + 0 >= 0,
(An inequality (-1, -0.5773502691896258?) x + 1 >= 0,
An inequality (1, -0.5773502691896258?) x + 0 >= 0,
An inequality (0, 1.154700538379252?) x + 0 >= 0)
Without specifying the ``base_ring``, the ``sqrt(3)`` would be a
Expand All @@ -196,7 +196,7 @@
sage: K.<sqrt3> = NumberField(x^2-3)
sage: Polyhedron([(0,0), (1,0), (1/2, sqrt3/2)])
A 2-dimensional polyhedron in (Number Field in sqrt3 with defining
A 2-dimensional polyhedron in (Number Field in sqrt3 with defining
polynomial x^2 - 3)^2 defined as the convex hull of 3 vertices
Base classes
Expand Down
24 changes: 21 additions & 3 deletions src/sage/geometry/polyhedron/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,36 @@ def _element_constructor_(self, *args, **kwds):
"""
nargs = len(args)
convert = kwds.pop('convert', True)
def convert_base_ring(lstlst):
return [ [self.base_ring()(x) for x in lst] for lst in lstlst]
# renormalize before converting when going from QQ to RDF, see trac 21270
def convert_base_ring_Hrep(lstlst):
newlstlst = []
for lst in lstlst:
if all(c in QQ for c in lst):
m=max(abs(w) for w in lst)
if m == 0:
newlstlst.append(lst)
else:
newlstlst.append([q/m for q in lst])
else:
newlstlst.append(lst)
return convert_base_ring(newlstlst)
if nargs==2:
Vrep, Hrep = args
def convert_base_ring(lstlst):
return [ [self.base_ring()(x) for x in lst] for lst in lstlst]
if convert and Hrep:
Hrep = [convert_base_ring(_) for _ in Hrep]
if self.base_ring==RDF:
Hrep = [convert_base_ring_Hrep(_) for _ in Hrep]
else:
Hrep = [convert_base_ring(_) for _ in Hrep]
if convert and Vrep:
Vrep = [convert_base_ring(_) for _ in Vrep]
return self.element_class(self, Vrep, Hrep, **kwds)
if nargs==1 and is_Polyhedron(args[0]):
polyhedron = args[0]
Hrep = [ polyhedron.inequality_generator(), polyhedron.equation_generator() ]
if self.base_ring()==RDF:
Hrep = [convert_base_ring_Hrep(_) for _ in Hrep]
return self.element_class(self, None, Hrep, **kwds)
if nargs==1 and args[0]==0:
return self.zero()
Expand Down
Loading

0 comments on commit bc1dd36

Please sign in to comment.