Squares in Q[r], a question about algebraic numbers in mathematica

*To*: mathgroup at smc.vnet.net*Subject*: [mg127632] Squares in Q[r], a question about algebraic numbers in mathematica*From*: Kent Holing <KHO at statoil.com>*Date*: Wed, 8 Aug 2012 03:18:45 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net

The code below confuses me: I thought that it should return for example (r^2+1)^2 when applied to (r^2+1)^2 whatever a is. The code is supposed to do the following: Given an element p (say polynomial) in Q[r] for a root r of a given polynomial in Q[x], the code should return p as q^2 for q the square root q of p as an element (polynomial) of Q[r] if q exists. But, it does not! When applied to (r2+1)^2 it returns in fact (r^2/16+1)^2, using r/4 instead of r? The code: SquareQrQ[a_,u_]:=Head@ToNumberField[Sqrt@u,a] === AlgebraicNumber//Quiet; SqrtQr[a_,p_]:=Module[{f,q}, f=Check[ToNumberField[Sqrt[p//Expand],a],"non-square"]//Quiet; q=AlgebraicNumberPolynomial[f,r]//Quiet; Plus[q]^2]; sq[a_,p_]:=SqrtQr[a,p]; If a=Root[x^4+5/8x^2+5/8x+205/256,x,1]; then sq[a,(r^2+1)^2/.r->a] returns (r^2/16+1)^2, not (r^2+1)^2. Any comments are highly appreciated. Kent Holing, Norway

**Follow-Ups**:**Squares in Q[r], a question about algebraic numbers in mathematica***From:*Ralph Dratman <ralph.dratman@gmail.com>