(f, a, b, tol)
return (a+b)/2
Implements bisection. This function is used in RootOf.eval_rational() and
    it needs to be robust.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.polys.rootoftools import bisect
    >>> bisect(lambda x: x**2-1, -10, 0, S(1)/10**2)
    -1025/1024
    >>> bisect(lambda x: x**2-1, -10, 0, S(1)/10**4)
    -131075/131072
Implements bisection. This function is used in RootOf.eval_rational() and
    it needs to be robust.
Implements bisection . This function is used in RootOf . eval_rational () and it needs to be robust .
def bisect(f, a, b, tol):
    """
    Implements bisection. This function is used in RootOf.eval_rational() and
    it needs to be robust.

    Examples
    ========

    >>> from sympy import S
    >>> from sympy.polys.rootoftools import bisect
    >>> bisect(lambda x: x**2-1, -10, 0, S(1)/10**2)
    -1025/1024
    >>> bisect(lambda x: x**2-1, -10, 0, S(1)/10**4)
    -131075/131072

    """
    a = sympify(a)
    b = sympify(b)
    fa = f(a)
    fb = f(b)
    if fa * fb >= 0:
        raise ValueError("bisect: f(a) and f(b) must have opposite signs")
    while (b-a > tol):
        c = (a+b)/2
        fc = f(c)
        if (fc == 0): return c # We need to make sure f(c) is not zero below
        if (fa * fc < 0):
            b = c
            fb = fc
        else:
            a = c
            fa = fc
    return (a+b)/2
def bisect ( f , a , b , tol ) : a = sympify ( a ) b = sympify ( b ) fa = f ( a ) fb = f ( b ) if fa * fb >= 0 : raise ValueError ( "bisect: f(a) and f(b) must have opposite signs" ) while ( b - a > tol ) : c = ( a + b ) / 2 fc = f ( c ) if ( fc == 0 ) : return c # We need to make sure f(c) is not zero below if ( fa * fc < 0 ) : b = c fb = fc else : a = c fa = fc return ( a + b ) / 2