TITLE: Is there an algorithm for determining whether an expression involving nested radicals is rational?
QUESTION [30 upvotes]: Specifically, consider expressions involving integers, addition, multiplication, division, and nth roots for any positive integer n. Is there an algorithm that can determine whether such an expression is a rational number? If the expression is a rational number, is it possible to determine which rational number (e.g. test whether an expression is 0?
I've seen papers on denesting radicals, but I couldn't find anything on testing for rationality.

REPLY [5 votes]: Yes, you can do so exactly, as long as you can express arbitrary rational numbers exactly.
One way of doing this (though probably not the most efficient one) is to explicitly construct a field extension $E$ (as a rational vector space) through iterative adjoining of roots of equations x^k-a. (This can be done e.g. using resultants, but is hard to get to work efficiently in larger cases.) In this extension you can express the radical expression (or one interpretation of the radical expression) exactly.
Then choose a basis of $E$ that has one rational basis vector (say $1$), then an element of $E$ is rational if its coefficients for all other basis vectors are zero.
To take the famous Daniel Shanks example given by Esteban Crespi, a polynomial for the field $E$ is
$x^8-8x^7-196x^6+1208x^5+8742x^4-43224x^3-41476x^2+227880x+8609$. (I calculated this as iterated extension.)
Now, using GAP (not that it is the best tool for this, but its the one I know), we can construct the extension $E$:
gap> pol:=x^8-8*x^7-196*x^6+1208*x^5+8742*x^4-43224*x^3-41476*x^2+227880*x+8609;;
x^8-8*x^7-196*x^6+1208*x^5+8742*x^4-43224*x^3-41476*x^2+227880*x+8609
gap> e:=AlgebraicExtension(Rationals,pol);;
gap> x:=X(e,"x");; # define variable

Now we take roots of certain quadratic polynomials to get the various radical expressions (here a is a root of the degree 8 polynomial, we work in the basis $1,a,a^2,\ldots$).
gap> r5:=RootsOfUPol(x^2-5)[1]; # root 5
-609/61755136*a^7+2095/30877568*a^6+133959/61755136*a^5-26101/30877568*a^4-7625627/61755136*a^3+12216013/30877568*a^2+92459893/61755136*a-67326631/30877568
gap> r29:=RootsOfUPol(x^2-29)[1]; #root 29
20639/111931184*a^7-113083/111931184*a^6-290319/111931184*a^5+13886605/111931184*a^4+206942825/111931184*a^3-340055609/111931184*a^2-1241123913/111931184*a+556675495/111931184
gap> r22:=RootsOfUPol(x^2-(22+2*r5))[1]; # root of expression starting with 22
-312563/1790898944*a^7+843909/895449472*a^6+64760293/1790898944*a^5-101635911/895449472*a^4-3089942017/1790898944*a^3+2366180495/895449472*a^2+18967544655/1790898944*a-3396381133/895449472
gap> r11:=RootsOfUPol(x^2-(11+2*r29))[1]; # root of expression starting with 11
-318289/3581797888*a^7+1674531/3581797888*a^6+66219455/3581797888*a^5-200118013/3581797888*a^4-3175703931/3581797888*a^3+4847083105/3581797888*a^2+19761660493/3581797888*a-15977491783/3581797888
gap> r55:=RootsOfUPol(x^2-(55-10*r29))[1]; # root of expression starting with 55
-587121/3581797888*a^7+2690715/3581797888*a^6+125087039/3581797888*a^5-281976997/3581797888*a^4-6353565723/3581797888*a^3+4276345801/3581797888*a^2+54570779021/3581797888*a-1796485759/3581797888
gap> r16:=RootsOfUPol(x^2-(16-2*r29+2*r55))[1]; # root of expression starting with 16    -342159/3581797888*a^7+1944125/3581797888*a^6+71070753/3581797888*a^5-244253347/3581797888*a^4-3446466469/3581797888*a^3+6034696383/3581797888*a^2+23536102611/3581797888*a-5417921945/3581797888

Finally we can calculate left and right side and e.g. subtract.
gap> left:=r5+r22;
-20639/111931184*a^7+113083/111931184*a^6+4290319/111931184*a^5-13886605/111931184*a^4-206942825/111931184*a^3+340055609/111931184*a^2+1353055097/111931184*a-668606679/111931184
gap> right:=r11+r16;
-20639/111931184*a^7+113083/111931184*a^6+4290319/111931184*a^5-13886605/111931184*a^4-206942825/111931184*a^3+340055609/111931184*a^2+1353055097/111931184*a-668606679/111931184
gap> left-right;
!0

Thu everything works exactly, but even in this tiny example the coefficients are a mess, so this in not something to do by hand.