Skip to content

Commit 2590c05

Browse files
committed
fixes in Lorentzian polynomials
1 parent 6aeb1da commit 2590c05

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,14 +2701,18 @@ cdef class MPolynomial(CommutativeRingElement):
27012701
[HMMS2019]_. The second reference gives the characterization of
27022702
Lorentzian polynomials applied in this implementation explicitly.
27032703
"""
2704+
from sage.rings.imaginary_unit import I
2705+
27042706
# function to handle return value when reason requested
27052707
def result(val, explanation=None):
2706-
if explain:
2707-
return (val, explanation)
2708-
else:
2709-
return val
2708+
return (val, explanation) if explain else val
27102709

2711-
if not self.base_ring().is_subring(RealField()):
2710+
try:
2711+
# this would better be handled by a category of RealFields()
2712+
self.base_ring()(I)
2713+
except (ValueError, TypeError):
2714+
pass
2715+
else:
27122716
raise NotImplementedError("is_lorentzian only implemented for real polynomials")
27132717

27142718
if self.is_zero():
@@ -2811,8 +2815,7 @@ def _is_M_convex_(points):
28112815
points_set = set(map(tuple, points))
28122816
if not points_set:
28132817
return True
2814-
elt = next(islice(points_set, 0, 1)))
2815-
dim = len(elt)
2818+
dim = len(next(iter(points_set)))
28162819
if any(len(p) != dim for p in points_set):
28172820
raise ValueError("input points are not the same dimension")
28182821
if any(entry not in ZZ for p in points_set for entry in p):

0 commit comments

Comments
 (0)