Andreas Enge on Tue, 24 Sep 2013 19:42:00 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: rational roots


On Tue, Sep 24, 2013 at 10:20:17AM -0700, somayeh didari wrote:
> I need to find rational roots of a polynomial in Pari/gp. But when I use polroots command, Pari gives all complex roots. On the other hand rational points are returned in complex type, too. How can i find rational roots in rational type? for example
> 
> ? polroots(x^2-0.25)
> %14 = [-0.5000000000000000000000000000 + 0.E-28*I, 0.500000000000000000000000000
> 0 + 0.E-28*I]~
> 
> But I need [-0.5, 0.5]!!!!!!!!!

Try factor, and prefer to specify the coefficient as a rational if you look
for rational roots:

? factor (x^2-1/4)
%1 = 
[2*x - 1 1]

[2*x + 1 1]


? factor (x^2-0.25)
%2 = 
[x + 0.50000000000000000000000000000000000000 1]

[x - 0.50000000000000000000000000000000000000 1]

seems to work and look for real roots. Otherwise, you still have the option
to round rounding errors away:

? real (polroots (x^2-0.25))
%3 = [-0.50000000000000000000000000000000000000, 0.50000000000000000000000000000000000000]

Andreas