Ask Your Question
1

find roots with arbitrary precision

asked 2012-10-31 05:44:29 +0100

MvG gravatar image

updated 2012-10-31 05:45:12 +0100

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
        else:
            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
        else:
            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

Comments

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

kcrisman gravatar imagekcrisman ( 2012-10-31 08:12:45 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-10-31 05:58:58 +0100

achrzesz gravatar image

You can compare your function with that in mpmath:

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

Comments

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](http://ask.sagemath.org/question/1937/).

MvG gravatar imageMvG ( 2012-10-31 13:04:34 +0100 )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

Stats

Asked: 2012-10-31 05:44:29 +0100

Seen: 1,129 times

Last updated: Oct 31 '12