'Return a Rational approximation to ``self`` with the tolerance ``tol``.
This method uses bisection, which is very robust and it will always
converge. The returned Rational instance will be at most \'tol\' from the
exact root.
The following example first obtains Rational approximation to 1e-7
accuracy for all roots of the 4-th order Legendre polynomial, and then
evaluates it to 5 decimal digits (so all digits will be correct
including rounding):
>>> from sympy import S, legendre_poly, Symbol
>>> x = Symbol("x")
>>> p = legendre_poly(4, x, polys=True)
>>> roots = [r.eval_rational(S(1)/10**7) for r in p.real_roots()]
>>> roots = [str(r.n(5)) for r in roots]
>>> roots
[\'-0.86114\', \'-0.33998\', \'0.33998\', \'0.86114\']'

def eval_rational(self, tol):

    if (not self.is_real):
        raise NotImplementedError('eval_rational()    only    works    for    real    polynomials    so    far')
    func = lambdify(self.poly.gen, self.expr)
    interval = self._get_interval()
    a = Rational(str(interval.a))
    b = Rational(str(interval.b))
    return bisect(func, a, b, tol)
