Skip to content

Commit a007379

Browse files
author
Release Manager
committed
gh-39523: multi polynomial element/repr This is an identical replacement for #39502 which had to be closed. URL: #39523 Reported by: Martin Rubey Reviewer(s): Travis Scrimshaw
2 parents 8504934 + dc38269 commit a007379

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/sage/rings/polynomial/multi_polynomial_element.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,8 @@ def _repr_(self):
467467
sage: repr(-I*y - x^2) # indirect doctest
468468
'-x^2 + (-I)*y'
469469
"""
470+
if self.is_gen():
471+
return self.parent().variable_names()[self.degrees().nonzero_positions()[0]]
470472
try:
471473
key = self.parent().term_order().sortkey
472474
except AttributeError:

src/sage/rings/semirings/tropical_mpolynomial.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,16 +653,28 @@ def _repr_(self):
653653
r"""
654654
Return a string representation of ``self``.
655655
656+
Note that ``x`` equals ``0*x``, which is different from
657+
``1*x``. Therefore, we represent monomials always together
658+
with their coefficients, to avoid confusion.
659+
656660
EXAMPLES::
657661
658662
sage: T = TropicalSemiring(QQ)
659663
sage: R.<x,y> = PolynomialRing(T)
660664
sage: x + R(-1)*y + R(-3)
661665
0*x + (-1)*y + (-3)
666+
662667
"""
663668
if not self.monomial_coefficients():
664669
return str(self.parent().base().zero())
665-
s = super()._repr_()
670+
try:
671+
key = self.parent().term_order().sortkey
672+
except AttributeError:
673+
key = None
674+
atomic = self.parent().base_ring()._repr_option('element_is_atomic')
675+
s = self.element().poly_repr(self.parent().variable_names(),
676+
atomic_coefficients=atomic,
677+
sortkey=key)
666678
if self.monomials()[-1].is_constant():
667679
if self.monomial_coefficient(self.parent()(0)) < 0:
668680
s = s.replace(" - ", " + -")

0 commit comments

Comments
 (0)