(expr, n=15, exponent=False)
return rv.xreplace(Transform(
        lambda x: x.func(*nfloat(x.args, n, exponent)),
        lambda x: isinstance(x, Function)))
Make all Rationals in expr Floats except those in exponents
    (unless the exponents flag is set to True).

    Examples
    ========

    >>> from sympy.core.function import nfloat
    >>> from sympy.abc import x, y
    >>> from sympy import cos, pi, sqrt
    >>> nfloat(x**4 + x/2 + cos(pi/3) + 1 + sqrt(y))
    x**4 + 0.5*x + sqrt(y) + 1.5
    >>> nfloat(x**4 + sqrt(y), exponent=True)
    x**4.0 + y**0.5
Make all Rationals in expr Floats except those in exponents
    (unless the exponents flag is set to True).
Make all Rationals in expr Floats except those in exponents ( unless the exponents flag is set to True ) .
def nfloat(expr, n=15, exponent=False):
    """Make all Rationals in expr Floats except those in exponents
    (unless the exponents flag is set to True).

    Examples
    ========

    >>> from sympy.core.function import nfloat
    >>> from sympy.abc import x, y
    >>> from sympy import cos, pi, sqrt
    >>> nfloat(x**4 + x/2 + cos(pi/3) + 1 + sqrt(y))
    x**4 + 0.5*x + sqrt(y) + 1.5
    >>> nfloat(x**4 + sqrt(y), exponent=True)
    x**4.0 + y**0.5

    """
    from sympy.core.power import Pow
    from sympy.polys.rootoftools import RootOf

    if iterable(expr, exclude=string_types):
        if isinstance(expr, (dict, Dict)):
            return type(expr)([(k, nfloat(v, n, exponent)) for k, v in
                               list(expr.items())])
        return type(expr)([nfloat(a, n, exponent) for a in expr])
    rv = sympify(expr)

    if rv.is_Number:
        return Float(rv, n)
    elif rv.is_number:
        # evalf doesn't always set the precision
        rv = rv.n(n)
        if rv.is_Number:
            rv = Float(rv.n(n), n)
        else:
            pass  # pure_complex(rv) is likely True
        return rv

    # watch out for RootOf instances that don't like to have
    # their exponents replaced with Dummies and also sometimes have
    # problems with evaluating at low precision (issue 6393)
    rv = rv.xreplace(dict([(ro, ro.n(n)) for ro in rv.atoms(RootOf)]))

    if not exponent:
        reps = [(p, Pow(p.base, Dummy())) for p in rv.atoms(Pow)]
        rv = rv.xreplace(dict(reps))
    rv = rv.n(n)
    if not exponent:
        rv = rv.xreplace(dict([(d.exp, p.exp) for p, d in reps]))
    else:
        # Pow._eval_evalf special cases Integer exponents so if
        # exponent is suppose to be handled we have to do so here
        rv = rv.xreplace(Transform(
            lambda x: Pow(x.base, Float(x.exp, n)),
            lambda x: x.is_Pow and x.exp.is_Integer))

    return rv.xreplace(Transform(
        lambda x: x.func(*nfloat(x.args, n, exponent)),
        lambda x: isinstance(x, Function)))
def nfloat ( expr , n = 15 , exponent = False ) : from sympy . core . power import Pow from sympy . polys . rootoftools import RootOf if iterable ( expr , exclude = string_types ) : if isinstance ( expr , ( dict , Dict ) ) : return type ( expr ) ( [ ( k , nfloat ( v , n , exponent ) ) for k , v in list ( expr . items ( ) ) ] ) return type ( expr ) ( [ nfloat ( a , n , exponent ) for a in expr ] ) rv = sympify ( expr ) if rv . is_Number : return Float ( rv , n ) elif rv . is_number : # evalf doesn't always set the precision rv = rv . n ( n ) if rv . is_Number : rv = Float ( rv . n ( n ) , n ) else : pass # pure_complex(rv) is likely True return rv # watch out for RootOf instances that don't like to have # their exponents replaced with Dummies and also sometimes have # problems with evaluating at low precision (issue 6393) rv = rv . xreplace ( dict ( [ ( ro , ro . n ( n ) ) for ro in rv . atoms ( RootOf ) ] ) ) if not exponent : reps = [ ( p , Pow ( p . base , Dummy ( ) ) ) for p in rv . atoms ( Pow ) ] rv = rv . xreplace ( dict ( reps ) ) rv = rv . n ( n ) if not exponent : rv = rv . xreplace ( dict ( [ ( d . exp , p . exp ) for p , d in reps ] ) ) else : # Pow._eval_evalf special cases Integer exponents so if # exponent is suppose to be handled we have to do so here rv = rv . xreplace ( Transform ( lambda x : Pow ( x . base , Float ( x . exp , n ) ) , lambda x : x . is_Pow and x . exp . is_Integer ) ) return rv . xreplace ( Transform ( lambda x : x . func ( * nfloat ( x . args , n , exponent ) ) , lambda x : isinstance ( x , Function ) ) )