'Compute numerical approximations of roots of ``f``.
Parameters
n ... the number of digits to calculate
maxsteps ... the maximum number of iterations to do
If the accuracy `n` cannot be reached in `maxsteps`, it will raise an
exception. You need to rerun with higher maxsteps.
Examples
>>> from sympy import Poly
>>> from sympy.abc import x
>>> Poly(x**2 - 3).nroots(n=15)
[-1.73205080756888, 1.73205080756888]
>>> Poly(x**2 - 3).nroots(n=30)
[-1.73205080756887729352744634151, 1.73205080756887729352744634151]'

def nroots(f, n=15, maxsteps=50, cleanup=True):

    if f.is_multivariate:
        raise MultivariatePolynomialError(("can't    compute    numerical    roots    of    %s" % f))
    if (f.degree() <= 0):
        return []
    if (f.rep.dom is ZZ):
        coeffs = [int(coeff) for coeff in f.all_coeffs()]
    elif (f.rep.dom is QQ):
        denoms = [coeff.q for coeff in f.all_coeffs()]
        from sympy.core.numbers import ilcm
        fac = ilcm(*denoms)
        coeffs = [int((coeff * fac)) for coeff in f.all_coeffs()]
    else:
        coeffs = [coeff.evalf(n=n).as_real_imag() for coeff in f.all_coeffs()]
        try:
            coeffs = [mpmath.mpc(*coeff) for coeff in coeffs]
        except TypeError:
            raise DomainError(('Numerical    domain    expected,    got    %s' % f.rep.dom))
    dps = mpmath.mp.dps
    mpmath.mp.dps = n
    try:
        roots = mpmath.polyroots(coeffs, maxsteps=maxsteps, cleanup=cleanup, error=False, extraprec=(f.degree() * 10))
        roots = list(map(sympify, sorted(roots, key=(lambda r: ((1 if r.imag else 0), r.real, r.imag)))))
    except NoConvergence:
        raise NoConvergence(('convergence    to    root    failed;    try    n    <    %s    or    maxsteps    >    %s' % (n, maxsteps)))
    finally:
        mpmath.mp.dps = dps
    return roots
