Ask Your Question

find roots with arbitrary precision

asked 2012-10-30 23:44:29 -0500

MvG gravatar image

updated 2012-10-30 23:45:12 -0500

It seems that find_root will always convert its parameter range to float, even if a and b were originally given in some arbitrary precision real number field. Is there a variant of this algorithm that can find roots to arbitrary precision?

Even greater would be some algorithm that can make use of interval arithmetic based on RealIntervalField, which in particular will return an interval that is guaranteed to contain the zero. I have written some code along these lines:

def bisect_interval(f, i, d):
    # find zero of function f in interval i with desired diameter d
    # f must be monotonically increasing and must contain a zero in i
    d2 = d/2
    zero = i.parent()(0)
    hi = i
    while hi.absolute_diameter() > d2:
        l, r = hi.bisection()
        c = l.intersection(r)
        fc = f(c)
        if fc > zero:
            hi = l
            hi = r
    lo = i
    while lo.absolute_diameter() > d2:
        l, r = lo.bisection()
        c = l.intersection(r)
        fc = f(c)
        if fc < zero:
            lo = r
            lo = l
    return lo.union(hi)

Am I reproducing functionality that's already available somewhere in Sage? If not, do you consider this functionality worth adding? Should it use some better algorithm than simple bisection? Is the algorithm even correct? You don't have to answer all of these questions, as my core question remains the one about an arbitrary precision version of find_root. But additional answers would be welcome.

edit retag flag offensive close merge delete


I think this is because `find_root` uses SciPy, which probably doesn't have arbitrary precision.

kcrisman gravatar imagekcrisman ( 2012-10-31 02:12:45 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2012-10-30 23:58:58 -0500

achrzesz gravatar image

You can compare your function with that in mpmath:

sage: import mpmath
sage: mpmath.findroot?
edit flag offensive delete link more


The mpmath package and its findroot function look interesting. I see no mention of any support for interval arithmetic, so this code does something different from my own code even for `solver='bisect'`. And it does not integrate well with Sage functions, as even a simple expression like `2*arccos(x)` causes a `TypeError`. I just wrote [a follow-up question about this](

MvG gravatar imageMvG ( 2012-10-31 07:04:34 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-10-30 23:44:29 -0500

Seen: 439 times

Last updated: Oct 30 '12