Hi Aaron,
This section of the tutorial may help to clear things up
https://docs.sympy.org/latest/tutorial/gotchas.html. This blog post
also goes into more detail about how variables work in Python
https://nedbatchelder.com/text/names.html.
Thanks for the pointers. I'll study them.
What I might do is to modify MyAbs so that it maintains a global
dictionary of all arguments it has been called with, adding new
arguments if they are not found in the dictionary. Later I can check
that the objects stored in the dictionary have no roots within the small
interval. Does that seem reasonable?
That sounds fine. You can also use functools.lru_cache to get the same effect.
I've thought about this a bit more.
I suspect that the number of distinct arguments to Abs() is at most a
few thousand. Each of these arguments is a polynomial P(a) in 'a',
with rational coefficients. If I maintain a global dictionary of these
arguments, then each time a new P(a) appears, I can check if it has any
roots along the real axis between (say) 0.56 and 0.58.
While P(a) might be high order and not factorizable, any respectable
numerical root-finder could do such a check in a fraction of a
millisecond. Since P(a) is polynomial, its derivative is easily
evaluated, which means that a Newton-Raphson (NR) root-finder could be
employed. Is there a NR or similar root-finder built in to sympy which
I can use for this?
While it is not bullet-proof, I can also do the first pass of NR in my
own code, before adding a new P(a) to the dictionary. Denote the
center-point of my small neighborhood by a_0. I can evaluate the
numerical values of P(a_0) and P'(a_0) and then form |P(a_0)/P'(a_0)|.
If that is significantly larger than the width of my interval around
a_0, then the closest root is very likely to lie outside the interval.
Cheers,
Bruce
--
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 sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/be3c1b93-791a-2214-f568-f247b69e5115%40googlemail.com.