Skip to content

Commit 99fd653

Browse files
author
Release Manager
committed
Trac #14602: Symbolic expression to number fields
The ticket stands to improve the `AlgebraicConverter` in `sage.symbolic.expression_converters` and make it works with number fields. As mentioned on [http://ask.sagemath.org/question/2581/convert- expression-to-quadraticfield ask] the following fails {{{ sage: K = QuadraticField(3) sage: K(sqrt(3)) Traceback (most recent call last): ... TypeError: ... }}} The following gives an answer with a wrong parent {{{ sage: x = K(3)**(1/2); x sqrt(3) sage: a.parent() Symbolic Ring }}} while it is possible to do {{{ sage: y = K(3).sqrt(); y a sage: y == K.gen() True }}} Finally, we hopefully have {{{ sage: K.gen() == sqrt(3) sqrt(3) == sqrt(3) sage: bool(K.gen() == sqrt(3)) True }}} URL: https://trac.sagemath.org/14602 Reported by: vdelecroix Ticket author(s): Dave Morris Reviewer(s): Vincent Delecroix
2 parents b4c66dc + a5fc9f9 commit 99fd653

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/sage/symbolic/expression_conversions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,21 @@ def arithmetic(self, ex, operator):
10731073
Traceback (most recent call last):
10741074
...
10751075
TypeError: unable to convert pi^6 to Algebraic Field
1076+
1077+
Test that :trac:`14602` is fixed::
1078+
1079+
sage: K = QuadraticField(3)
1080+
sage: K(sqrt(3)).parent() is K
1081+
True
1082+
sage: sqrt(K(3)).parent() is K
1083+
True
1084+
sage: (K(3)^(1/2)).parent()
1085+
Symbolic Ring
1086+
sage: bool(K.gen() == K(3)^(1/2) == sqrt(K(3)) == K(sqrt(3)) == sqrt(3))
1087+
True
1088+
sage: L = QuadraticField(3, embedding=-AA(3).sqrt())
1089+
sage: bool(L.gen() == -sqrt(3))
1090+
True
10761091
"""
10771092
# We try to avoid simplifying, because maxima's simplify command
10781093
# can change the value of a radical expression (by changing which

0 commit comments

Comments
 (0)