On Mon, 3 Nov 2025 at 16:47, Ashutosh Chauhan <[email protected]> wrote:
>
> I suggest enhancing SymPy’s numeric evaluation process by adding a step to
> algebraically rewrite expressions into simpler or more numerically stable
> forms before substituting numeric values.
There have been previous proposals around the Herbie algorithm which
is for this. In general a difficulty of using something like this is
that SymPy expressions don't preserve things like the order of
associative operations e.g. there is no distinction between (x + y) +
z and x + (y + z) even though these can be very different for floating
point accuracy.
Note that in your example it is recommended to use
expr.evalf(subs={x:0.1})
rather than
expr.subs({x:0.1}).evalf()
The former is recommended because it is more accurate.
--
Oscar
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/sympy/CAHVvXxRyJfQmsXS5%2Bm3zLDGmiWe2fO6v8tpmn565Kk1XLAcHRA%40mail.gmail.com.