I'm working on a numerical evaluation using the sympy evalf() package. Consider the mpmath library's introduction to precision and accuracy https://mpmath.org/doc/current/technical.html, where on https://docs.sympy.org/latest/modules/evalf.html mentioned that
Exact SymPy expressions can be converted to floating-point approximations (decimal numbers) using either the .evalf() method or the N() function. ...
where, it also mentioned that
By default, numerical evaluation is performed to an accuracy of 15 decimal digits.
By "floating-point approximation", it sounded like the sympy's internal arithmetic is binary. However, when comparing an input value such as value=1.2
, I found that the Float(value)
was needed to feed into a function f_sympy(Float(value))
match the results from mpmath f_mpmath(value)
and f_mpmath(mp.mpf(value))
, where f_sympy(value)
and f_mpmath(mp.mpf(str(value)))
provided somewhat distinct decimal values. (precision to 200 decimal, where the deviation showed up on the 20th decimal places.)
Is sympy evalf() using binary or decimal arithmetic? Why Float(value)
was required for sympy and why mp.mpf(str(value))
also changed the evaluation in mpmath?