-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evaluating limits when substuting an expression with infinity. #2599
Conversation
My feeling is that it shouldn't do this. Anyway, why is infinity so special. You can get nan by substituting any number to the right expression. |
Sometimes (and sometimes - not). And these things happens not just with oo. Your example is easy to translate to:
Another example:
Nothing unusual, see the Wolfram's Mathematica:
So, it's not the infinity is special, it's subs. Just stupid (literal) substitutions, no any fancy math and no limits! If that's not clear from docs, we should fix the docstring for subs. Otherwise, -1. |
Infinity is special because substituting with infinity is not well define. We cannot simply multiply, divide, subtract or add infinity to something. We must calculate the limit at infinity to keep things consistent.
but
Other way can be returning nan when every we encounter oo/oo or oo - oo or oo*0 in subs. Anyway, we have to add special case for infinity. |
Yes...substitution is about evaluation at a point. And you might not be |
On Fri, Nov 15, 2013 at 12:31:51PM -0800, Harsh Gupta wrote:
?? (x/(x*x)).subs(x, oo) means just: 1) perform some canonicalization of
In general, we can (but yes, there are some restrictions).
But (evaluate=False!):
Where is inconsistency? Sometimes, subs gives nan, it's fine.
There are many ways to get nan with subs. There is nothing If you want limits - use limit method, not subs. |
I get it. I did this after reading comment of asmeurer at https://code.google.com/p/sympy/issues/detail?id=1769#c9. Where he said
So, I thought (exp(x)/factorial(x)).subs(x, oo) is expected to return 0. Also it is not very clear from the doc what subs do when it encounter expressions like this. I thought evaluating limit might be a good idea. Shall I edit the docs, to make it more explicit what sympy does with subs? |
As I said, if that's not clear - we should fix the documentation. But not to abuse substitution with limits. |
Forgive me I'm new to sympy and open-source development in general. So I'm still getting familiar with the way things are done here. I guess I should discussed before sending a pull request. |
So a few things:
|
I edited the docstring for subs. |
Using subs with oo leads to wrong results.
For example
https://code.google.com/p/sympy/issues/detail?id=1769#c9
This attempts to fix this by adding a special case in the _subs function to evaluate limit when expression being substituted with is infinity.