Skip to content

Commit

Permalink
Fix doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Aug 26, 2024
1 parent 616e055 commit 5aee342
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/sage/rings/qqbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@
1
sage: QQbar((-8)^(1/3))
1.000000000000000? + 1.732050807568878?*I
sage: AA((-8)^(1/3))
-2
sage: AA(8^(1/3))
2
sage: QQbar((-4)^(1/4))
1 + 1*I
sage: AA((-4)^(1/4))
Expand Down Expand Up @@ -298,8 +298,8 @@
sage: n = (rt2 + rt3)^5; n
308.3018001722975?
sage: sage_input(n)
R.<x> = AA[]
v1 = AA.polynomial_root(AA.common_polynomial(x^2 - 2), RIF(RR(1.4142135623730949), RR(1.4142135623730951))) + AA.polynomial_root(AA.common_polynomial(x^2 - 3), RIF(RR(1.7320508075688772), RR(1.7320508075688774)))
R.<x> = QQbar[]
v1 = QQbar.polynomial_root(AA.common_polynomial(x^2 - 2), CIF(RIF(RR(1.4142135623730949), RR(1.4142135623730951)), RIF(RR(0)))).real() + QQbar.polynomial_root(AA.common_polynomial(x^2 - 3), CIF(RIF(RR(1.7320508075688772), RR(1.7320508075688774)), RIF(RR(0)))).real()
v2 = v1*v1
v2*v2*v1
Expand Down Expand Up @@ -335,8 +335,8 @@
sage: n = rt2^2
sage: sage_input(n, verify=True)
# Verified
R.<x> = AA[]
v = AA.polynomial_root(AA.common_polynomial(x^2 - 2), RIF(RR(1.4142135623730949), RR(1.4142135623730951)))
R.<x> = QQbar[]
v = QQbar.polynomial_root(AA.common_polynomial(x^2 - 2), CIF(RIF(RR(1.4142135623730949), RR(1.4142135623730951)), RIF(RR(0)))).real()
v*v
sage: sage_input(n, verify=True)
# Verified
Expand Down
14 changes: 6 additions & 8 deletions src/sage/symbolic/expression_conversion_algebraic.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def arithmetic(self, ex, operator):
sage: L = QuadraticField(3, embedding=-AA(3).sqrt())
sage: bool(L.gen() == -sqrt(3))
True
Test that :issue:12745 is fixed:
sage: x = exp(2*I*pi/7) + exp(-2*I*pi/7)
sage: AA(x)
1.246979603717467?
"""
# We try to avoid simplifying, because maxima's simplify command
# can change the value of a radical expression (by changing which
Expand All @@ -121,14 +127,6 @@ def arithmetic(self, ex, operator):
except TypeError:
pass

if operator is pow:
from sage.symbolic.constants import e, pi, I
from sage.rings.rational_field import QQ

base, expt = ex.operands()
if base == e and expt / (pi * I) in QQ:
return exp(expt)._algebraic_(self.field)

raise TypeError("unable to convert %r to %s" % (ex, self.field))

def composition(self, ex, operator):
Expand Down

0 comments on commit 5aee342

Please sign in to comment.