diff --git a/src/sage/geometry/convex_set.py b/src/sage/geometry/convex_set.py index fda6fa9d374..82ce25e48c6 100644 --- a/src/sage/geometry/convex_set.py +++ b/src/sage/geometry/convex_set.py @@ -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() diff --git a/src/sage/geometry/polyhedron/base.py b/src/sage/geometry/polyhedron/base.py index 040e09f7df8..a3fb4a6d2b7 100644 --- a/src/sage/geometry/polyhedron/base.py +++ b/src/sage/geometry/polyhedron/base.py @@ -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) diff --git a/src/sage/geometry/polyhedron/constructor.py b/src/sage/geometry/polyhedron/constructor.py index 7f68ca41ce0..351fd2e2bc8 100644 --- a/src/sage/geometry/polyhedron/constructor.py +++ b/src/sage/geometry/polyhedron/constructor.py @@ -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: diff --git a/src/sage/geometry/polyhedron/parent.py b/src/sage/geometry/polyhedron/parent.py index 7f14eb0766e..070917c00ef 100644 --- a/src/sage/geometry/polyhedron/parent.py +++ b/src/sage/geometry/polyhedron/parent.py @@ -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: diff --git a/src/sage/geometry/polyhedron/plot.py b/src/sage/geometry/polyhedron/plot.py index 7b4eace75ef..728ccec4988 100644 --- a/src/sage/geometry/polyhedron/plot.py +++ b/src/sage/geometry/polyhedron/plot.py @@ -11,6 +11,8 @@ # 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 @@ -18,7 +20,6 @@ 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 diff --git a/src/sage/geometry/polyhedron/representation.py b/src/sage/geometry/polyhedron/representation.py index 1fcefddd53b..0e28267b23b 100644 --- a/src/sage/geometry/polyhedron/representation.py +++ b/src/sage/geometry/polyhedron/representation.py @@ -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) @@ -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: @@ -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))