# Algebraic to symbolic expression

Hello! When I write AA(sqrt(3)+sqrt(2)) i get 3.146264369941973?, and I use to recover the original symbolic expression sqrt(2)+sqrt(3) simply by asking the minimal polynomial of 3.146264369941973?, which is of degree 4, and looking for the appropiate root. But I want to know if there is a reasonable way to get the symbolic expression from an algebraic expression which I know it comes from a lot of operations, knowing that the function "minpoly()" in that case does not give an answer for hours. I hope you can help me!!!

edit retag close merge delete

Sort by » oldest newest most voted

You can use the radical_expression method:

sage: a = AA(sqrt(3)+sqrt(2))
sage: a
3.146264369941973?
sqrt(2*sqrt(6) + 5)


Note that this is not a "complete" feature, as there might be some algebraic numbers admitting a radical decomposition that this feature will not find.

more

The first thing this method does is compute a.minpoly()...

( 2020-08-14 00:03:40 +0100 )edit

I'm not sure how minpoly() works but I'm pretty sure the following numerical approach (using PSLQ) is different:

z = AA(sqrt(3)+sqrt(2))
max_degree = 4
from mpmath import mp, findpoly
mp.dps = 15 # decimal places
f = ZZ['x'](findpoly(z.numerical_approx(digits=mp.dps), max_degree))
print(f)
print(f(z.numerical_approx(digits=mp.dps)))
print(f(z).is_zero())
print(f.roots(SR))


Output:

x^4 - 10*x^2 + 1
1.31006316905768e-14
True
[(-sqrt(2*sqrt(6) + 5), 1), (sqrt(2*sqrt(6) + 5), 1), (-sqrt(-2*sqrt(6) + 5), 1), (sqrt(-2*sqrt(6) + 5), 1)]


It can be used to find minimal polynomials with some degree of uncertainty, but likely at a higher speed. I hope it can be useful.

Edit: The uncertainty of z being a root can be eliminated by checking f(z).is_zero(), and the uncertainty of minimality could be eliminated e.g. by checking f.is_irreducible().

more

thanks rburing, i was looking for something exact, and "minpoly()" is exact (I verified checking if f(z))=0 with your polinomial and, as you said, it is approximately 0, and the exactitude is reached by the function obtained in minpoly()). Thanks for your help in this and my other question :-)

( 2020-08-12 16:18:25 +0100 )edit

You're welcome :) This approach is not exact but if for an algebraic number z you manage to find an f in this way, then you can check whether it is actually exact e.g. with f(z).is_zero(). (If this is the case, it is not guaranteed that f will be of minimal degree, but it is likely, and you could check it in another way, e.g. by f.is_irreducible().)

( 2020-08-12 16:52:34 +0100 )edit