Charles Greathouse on Tue, 24 Sep 2013 19:46:21 +0200


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

Re: rational roots


As Andreas said, factor(x^2-1/4) is the way to go. If you want something tidy, here's a quick command:

polrootsQ(p)={
  my(f=factor(p),v=matrix(0,2));
  for(i=1,#f~,
    if(poldegree(f[i,1])==1,
      v=concat(v,[-polcoeff(f[i,1],0)/polcoeff(f[i,1],1),f[i,2]])
    )
  );
  v
};

You can then use

polrootsQ(x^2-1/4)

Charles Greathouse
Analyst/Programmer
Case Western Reserve University


On Tue, Sep 24, 2013 at 1:20 PM, somayeh didari <somayeh_didari@yahoo.com> 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]!!!!!!!!!
 
somayeh didari