cutcutcodec.core.compilation.sympy_to_torch.preprocess.evalf

cutcutcodec.core.compilation.sympy_to_torch.preprocess.evalf(expr: Basic, prec: int = 37, simplify: bool = False) Basic[source]

Numerical eval and simplification of the expression.

Parameters

exprsympy.Expr

The sympy expression to symplify as numerical evaluable.

precint, default=37

The number of decimals, to comply with the standards, you can use the following values: * float128 -> 37 * float64 -> 18 * float32 -> 10

simplifyboolean, default=False

If set to True, it tries to simplify the expression in order to improve the numerical evaluation.

Returns

sympy.Expr

The quite equivalent expression with floats.

Examples

>>> import sympy
>>> from cutcutcodec.core.compilation.sympy_to_torch.preprocess import evalf
>>> evalf(sympy.pi)
3.141592653589793238462643383279502884
>>> evalf(sympy.sin(sympy.sin(1)))
0.7456241416655578888931510704303837921
>>> evalf(sympy.sqrt(2))
1.414213562373095048801688724209698079
>>> evalf(sympy.sympify("-2.0*x"))
-2.0*x
>>> evalf(sympy.sympify("(x/(2.0*x+2.0))**100.0"))
(x/(2.0*x + 2.0))**100.0
>>> evalf(sympy.sympify("sqrt(x)"))
x**0.5
>>>