Hi,
First, apologies if this has been discussed before. I'm browsing through
the tutorial and encountered what appears to be an inaccuracy in the
documentation. In particular, I am reading Basic Operations section
<https://docs.sympy.org/latest/tutorial/basic_operations.html> which states
that
*To numerically evaluate an expression with a Symbol at a point, we might
use subs followed by evalf, but it is more efficient and numerically stable
to pass the substitution to evalf using the subs flag, which takes a
dictionary of Symbol: point pairs.*
However, when I test this in jupyter lab using "%timeit" it appears the
reverse is true. I'll avoid posting images, but I got the following results:
expr = cos(x) - 2*sin(exp(x))
%timeit expr.subs(x, 0).evalf()
*92.9 µs* ± 628 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%timeit expr.evalf(subs=dict(x=0))
*264 µs *± 7.21 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
expr = cos(2*x)
%timeit expr.evalf(subs={x: 2.4})
*73.8 µs *± 3.28 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
%timeit expr.subs(x, 2.4).evalf()
*35.1 µs* ± 434 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
Perhaps the documentation needs to elaborate more what it means by "stable"
and "efficient" and under what conditions using one is preferable over the
other because from the tests I performed, it appears using subs().evalf()
is the way to go. The docs are either incorrect or out of date.
Best regards
--
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 on the web visit
https://groups.google.com/d/msgid/sympy/03831493-431b-45e7-809f-6cc691cab191n%40googlegroups.com.