Skip to content

Commit

Permalink
Trac #34235: Error in comparing two Symbolic Ring elements
Browse files Browse the repository at this point in the history
It seems a bug:
{{{
sage: bool(AA(sqrt(2))/pi == sqrt(2)/pi)
TypeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
}}}
The following comparison is fine, though.
{{{
sage: bool(AA(sqrt(2)) == sqrt(2))
True
}}}

To fix this, we provide elements of `AA` and `QQbar` with a
`_maxima_init_` method that
- handles the case of elements for which Sage can find a radical
expression and
- raises an error in all other cases.
This is better than sending the unusable print representation of
algebraic numbers (including `?`) to Maxima.

URL: https://trac.sagemath.org/34235
Reported by: yzh
Ticket author(s): Matthias Koeppe
Reviewer(s): Travis Scrimshaw
  • Loading branch information
Release Manager committed Sep 20, 2022
2 parents 5278916 + 58f4cd1 commit 5c42b1b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4710,6 +4710,34 @@ def radical_expression(self):
roots = candidates
interval_field = interval_field.to_prec(interval_field.prec() * 2)

def _maxima_init_(self, I=None):
r"""
EXAMPLES::
sage: maxima(AA(7))
7
sage: maxima(QQbar(sqrt(5/2)))
sqrt(10)/2
sage: maxima(AA(-sqrt(5)))
-sqrt(5)
sage: maxima(QQbar(sqrt(-2)))
sqrt(2)*%i
sage: maxima(AA(2+sqrt(5)))
sqrt(5)+2
sage: maxima(QQ[x](x^7 - x - 1).roots(AA, False)[0])
Traceback (most recent call last):
...
NotImplementedError: cannot find radical expression
"""
try:
return self._rational_()._maxima_init_()
except ValueError:
pass
rad = self.radical_expression()
if isinstance(rad.parent(), sage.rings.abc.SymbolicRing):
return rad._maxima_init_()
raise NotImplementedError('cannot find radical expression')


class AlgebraicNumber(AlgebraicNumber_base):
r"""
Expand Down

0 comments on commit 5c42b1b

Please sign in to comment.