Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sage/rings/polynomial/multi_polynomial_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def _repr_(self):
sage: repr(-I*y - x^2) # indirect doctest
'-x^2 + (-I)*y'
"""
if self.is_gen():
return self.parent().variable_names()[self.degrees().nonzero_positions()[0]]
try:
key = self.parent().term_order().sortkey
except AttributeError:
Expand Down
14 changes: 13 additions & 1 deletion src/sage/rings/semirings/tropical_mpolynomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,28 @@
r"""
Return a string representation of ``self``.

Note that ``x`` equals ``0*x``, which is different from
``1*x``. Therefore, we represent monomials always together
with their coefficients, to avoid confusion.

EXAMPLES::

sage: T = TropicalSemiring(QQ)
sage: R.<x,y> = PolynomialRing(T)
sage: x + R(-1)*y + R(-3)
0*x + (-1)*y + (-3)

"""
if not self.monomial_coefficients():
return str(self.parent().base().zero())
s = super()._repr_()
try:
key = self.parent().term_order().sortkey
except AttributeError:
key = None

Check warning on line 673 in src/sage/rings/semirings/tropical_mpolynomial.py

View check run for this annotation

Codecov / codecov/patch

src/sage/rings/semirings/tropical_mpolynomial.py#L672-L673

Added lines #L672 - L673 were not covered by tests
atomic = self.parent().base_ring()._repr_option('element_is_atomic')
s = self.element().poly_repr(self.parent().variable_names(),
atomic_coefficients=atomic,
sortkey=key)
if self.monomials()[-1].is_constant():
if self.monomial_coefficient(self.parent()(0)) < 0:
s = s.replace(" - ", " + -")
Expand Down
Loading