rationalroot function



An easy way to do this is to use solve and post-filter the solutions.
 Basically:

   rationalroots(p,v) := subset(setify(map(rhs,solve(p,v))),ratnump))$

A bit more robustly (catching various edge cases and bad input):

    rationalroots(p,v) :=
       (p: ratsimp(lhs(p)-rhs(p)),
         if not polynomialp(p,[v],lambda([c],freeof(v,c))) then error(p,"is
not a polynomial in",v),
         if p=0 then 'all          /* handle degenerate cases */
         elseif freeof(v,p) then {}
         else  subset(setify(map(rhs,solve(p,v))),ratnump))$

Examples:

rationalroots(x^4-1,x) => {-1,1}      ... real rationals only
rationalroots(x*y-x,y) => {1}            ... solution depends on variable
rationalroots(x*y-x,x) => {0}
rationalroots(x-(2*x-1)/2-1/2,x) => all   ...expression is identical to 0,
so all x's are solutions
rationalroots(8*x^4+16*x^3-x-2,x) => {-2,1/2}
rationalroots(cos(x),x) => error           ...has no rational roots, but
isn't a polynomial
rationalroots(sqrt(x^2-1),x) => error ... has 2 rational roots, but isn't a
polynomial
rationalroots(sin(%pi*x),x) => error  ...has infinitely many rational
roots, but isn't a polynomial

Hope this is useful.

                -s


On Wed, Mar 20, 2013 at 12:17 PM, Konstantinos Anastasiou <
konanast at gmail.com> wrote:

> In xcas algebra system there is a function *rationalroot(Poly(P)) *which *Returns
> the list of rational roots of P without indicating the multiplicity*.
>
> I'm looking for a corresponding function in Maxima. Can anyone help me?
>
> Thanks a lot!
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>