It might be overkill for this use case, but you can also use the
extremely nice real_roots functions that give guaranteed intervals and
multiplicities:

sage: from sage.rings.polynomial.real_roots import *
sage: x = polygen(ZZ)
sage: real_roots((x^2 + 1) * (x^2 - x - 1))
[((-3/4, -1/8), 1), ((1/2, 7/4), 1)]

You can restrict to certain intervals, and go to arbitrary precision:

sage: real_roots((x^2 + 1) * (x^2 - x - 1),max_diameter=1/10^14,
bounds = [0,2])
[((295594915476877884107369019065608127654139919973/182687704666362864775460604089535377456991567872,
605378386896645906651894226927171110065727063886243/374144419156711147060143317175368453031918731001856),
1)]

Or converting the first end of the interval to a numeric value:

sage:[N(q[0][0],200) for q in real_roots((x^2 + 1)*(x^2 - x -
1),max_diameter=1/10^14, bounds = [0,2])]
6180339887498948482045824713181755587457888095347418966031

-Marshall Hampton
On Dec 10, 5:49 pm, Vincent D <[email protected]> wrote:
> I prefer Polynomials than symbolic expression :
>
> sage: R.<x> = PolynomialRing(QQ, 'x')
> sage: P = (x^2 + 1) * (x^2 - x - 1)
> sage: P.roots()  # no root in QQ
> []
> sage: P.roots(RR)  # two roots in RR
> [(-0.618033988749895, 1), (1.61803398874989, 1)]
> sage: P.roots(CC) #  four roots in CC
> [(-0.618033988749895, 1), (1.61803398874989, 1),
> (-8.79016911342623e-17 - 1.00000000000000*I, 1),
> (-8.79016911342623e-17 + 1.00000000000000*I, 1)]
>
> But it can also be done with symbolics
>
> sage: x = var('x')
> sage: P = (x^2 + 1) * (x^2 - x - 1)
> sage: P.roots(x, ring=QQ)
> []
> sage: P.roots(x, ring=RR)  # two roots in RR
> [(-0.618033988749895, 1), (1.61803398874989, 1)]
> sage: P.roots(x, ring=CC) #  four roots in CC
> [(-0.618033988749895, 1), (1.61803398874989, 1),
> (-8.79016911342623e-17 - 1.00000000000000*I, 1),
> (-8.79016911342623e-17 + 1.00000000000000*I, 1)]
> sage: P.roots(x, ring=SR) # the symbolic ring
> [(-1/2*sqrt(5) + 1/2, 1), (1/2*sqrt(5) + 1/2, 1), (-I, 1), (I, 1)]

--

You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-edu?hl=en.


Reply via email to