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

Commit

Permalink
Merge #32416
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koeppe committed Aug 28, 2021
2 parents b0ba835 + d3479c7 commit 2991f8d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 25 deletions.
13 changes: 8 additions & 5 deletions src/sage/geometry/convex_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -859,11 +859,14 @@ def _test_contains(self, tester=None, **options):
ext_space = self.ambient_vector_space(AA)
ext_space_point = ext_space(space_point)
tester.assertEqual(contains_space_point, self.contains(ext_space_point))
from sage.symbolic.ring import SR
symbolic_space = self.ambient_vector_space(SR)
symbolic_space_point = symbolic_space(space_point)
# Only test that it can accept SR vectors without error.
self.contains(symbolic_space_point)
try:
from sage.symbolic.ring import SR
symbolic_space = self.ambient_vector_space(SR)
symbolic_space_point = symbolic_space(space_point)
# Only test that it can accept SR vectors without error.
self.contains(symbolic_space_point)
except ImportError:
pass
# Test that elements returned by some_elements are contained.
try:
points = self.some_elements()
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1824,7 +1824,7 @@ def Hrepresentation_str(self, separator='\n', latex=False, style='>=', align=Non
sage: c = polytopes.cube()
sage: c.Hrepresentation_str(separator=', ', style='positive')
'1 >= x0, 1 >= x1, 1 >= x2, x0 + 1 >= 0, x2 + 1 >= 0, x1 + 1 >= 0'
'1 >= x0, 1 >= x1, 1 >= x2, 1 + x0 >= 0, 1 + x2 >= 0, 1 + x1 >= 0'
"""
pretty_hs = [h.repr_pretty(split=True, latex=latex, style=style, **kwds) for h in self.Hrepresentation()]
shift = any(pretty_h[2].startswith('-') for pretty_h in pretty_hs)
Expand Down
5 changes: 4 additions & 1 deletion src/sage/geometry/polyhedron/constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,10 @@ def Polyhedron(vertices=None, rays=None, lines=None,
if base_ring not in Rings():
raise ValueError('invalid base ring')

from sage.symbolic.ring import SR
try:
from sage.symbolic.ring import SR
except ImportError:
SR = None
if base_ring is not SR and not base_ring.is_exact():
# TODO: remove this hack?
if base_ring is RR:
Expand Down
5 changes: 4 additions & 1 deletion src/sage/geometry/polyhedron/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ def Polyhedra(ambient_space_or_base_ring=None, ambient_dim=None, backend=None, *
else:
raise ValueError("no default backend for computations with {}".format(base_ring))

from sage.symbolic.ring import SR
try:
from sage.symbolic.ring import SR
except ImportError:
SR = None
if backend == 'ppl' and base_ring is QQ:
return Polyhedra_QQ_ppl(base_ring, ambient_dim, backend)
elif backend == 'ppl' and base_ring is ZZ:
Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/polyhedron/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
# https://www.gnu.org/licenses/
########################################################################

from math import pi

from sage.rings.all import RDF
from sage.structure.sage_object import SageObject
from sage.modules.free_module_element import vector
from sage.matrix.constructor import matrix, identity_matrix
from sage.matrix.special import diagonal_matrix
from sage.misc.functional import norm
from sage.misc.latex import LatexExpr
from sage.symbolic.constants import pi
from sage.structure.sequence import Sequence

from sage.plot.all import Graphics, point2d, line2d, arrow, polygon2d
Expand Down
35 changes: 19 additions & 16 deletions src/sage/geometry/polyhedron/representation.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ def _latex_(self):
....: print(latex(h))
x_{0} + x_{1} - x_{2} = 1
x_{0} \geq 0
2 \, x_{0} + x_{1} \geq -1
2x_{0} + x_{1} \geq -1
"""
return self.repr_pretty(latex=True)

Expand Down Expand Up @@ -1690,15 +1690,16 @@ def repr_pretty(coefficients, type, prefix='x', indices=None,
sage: print(repr_pretty((1, -1, -1, 1), PolyhedronRepresentation.EQUATION))
-x0 - x1 + x2 == -1
"""
from sage.misc.latex import latex as latex_function
from sage.modules.free_module_element import vector
from sage.symbolic.ring import SR
from sage.misc.repr import repr_lincomb

coeffs = vector(coefficients)
coeffs = list(coefficients)
if indices is None:
indices = range(len(coeffs)-1)
vars = vector([1] + list(SR(prefix + '{}'.format(i)) for i in indices))
f = latex_function if latex else repr
vars = [1]
if latex:
vars += ['x_{{{}}}'.format(i) for i in indices]
else:
vars += ['x{}'.format(i) for i in indices]
if type == PolyhedronRepresentation.EQUATION:
rel = '=' if latex else '=='
elif type == PolyhedronRepresentation.INEQUALITY:
Expand All @@ -1710,18 +1711,20 @@ def repr_pretty(coefficients, type, prefix='x', indices=None,
raise NotImplementedError(
'no pretty printing available: wrong type {}'.format(type))

rvars = range(len(vars))

if style == 'positive':
pos_part = vector([max(c, 0) for c in coeffs])
neg_part = pos_part - coeffs
assert coeffs == pos_part - neg_part
left_part = f(pos_part*vars)
right_part = f(neg_part*vars)
pos_part = [max(c, 0) for c in coeffs]
neg_part = [pos_part[i] - coeffs[i] for i in rvars]
assert all(coeffs[i] == pos_part[i] - neg_part[i] for i in rvars)
left_part = repr_lincomb([[vars[i], pos_part[i]] for i in rvars], is_latex=latex, strip_one=True)
right_part = repr_lincomb([[vars[i], neg_part[i]] for i in rvars], is_latex=latex, strip_one=True)
elif style == '>=':
left_part = f(coeffs[1:]*vars[1:])
right_part = f(-coeffs[0])
left_part = repr_lincomb([[vars[i], coeffs[i]] for i in rvars[1:]], is_latex=latex)
right_part = repr_lincomb([[vars[0], -coeffs[0]]], is_latex=latex, strip_one=True)
elif style == '<=':
left_part = f(-coeffs[1:]*vars[1:])
right_part = f(coeffs[0])
left_part = repr_lincomb([[vars[i], -coeffs[i]] for i in rvars[1:]], is_latex=latex)
right_part = repr_lincomb([[vars[0], coeffs[0]]], is_latex=latex, strip_one=True)
else:
raise NotImplementedError('no pretty printing available: wrong style {}'.format(style))

Expand Down

0 comments on commit 2991f8d

Please sign in to comment.