Skip to content
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

Multiple subs in Succession or Iterable inside subs in different orders would fail in critical cases involving 0/oo #22412

Open
anutosh491 opened this issue Nov 3, 2021 · 3 comments
Labels

Comments

@anutosh491
Copy link
Member

anutosh491 commented Nov 3, 2021

I discovered this while dealing with issue #17528, which I guess could be easily solved once we can correct this .
Multiple subs in Succession or Iterable inside subs in different orders would fail in critical cases like Division/Multiplication by 0/oo
See following examples

from sympy import *
n, m=symbols('n m')
a, b=symbols('a b')
>>> binomial( n, m).subs([( m, 0), ( n, -1 )]) # Correct answer
1
>>> binomial(n, m).subs([(n, -1), (m, 0)])
zoo
>>> cos(m/n).subs(m, 0).subs(n, 0)
1
>>> cos(m/n).subs(n, 0).subs(m, 0)
nan
>>> (sin(m)*csc(n)).subs(m,0).subs(n, 0)
0
>>> (sin(m)*csc(n)).subs(n,0).subs(m, 0)
nan
>>> (log(b/a)).subs(a, 0).subs(b, 0)
nan
>>> (log(b/a)).subs(b, 0).subs(a, 0) 
zoo

I could imagine how sympy conveniently substitutes the values for the first argument , simplifies it and then substitutes the second value in the new expression . I did a shallow read through the code and currently didn't find any code patch to catch these cases leading to wrong answers mathematically .

@anutosh491 anutosh491 changed the title Multiple subs in Succession or Iterable inside subs would fail in critical cases like Division/Multiplication by 0/oo Multiple subs in Succession or Iterable inside subs in different orders would fail in critical cases Nov 3, 2021
@anutosh491
Copy link
Member Author

I'll try to approach this sometime soon . Any suggestions/ Thoughts are welcome !!!

@anutosh491 anutosh491 changed the title Multiple subs in Succession or Iterable inside subs in different orders would fail in critical cases Multiple subs in Succession or Iterable inside subs in different orders would fail in critical cases involving 0/oo Nov 3, 2021
@ThePauliPrinciple
Copy link
Contributor

ThePauliPrinciple commented Nov 3, 2021

I think the issue here is that 0/n simply returns S.Zero even when 0/n could be S.NaN for some values of n.
Even evaluate=False in the subs method seems to not supress this

@oscarbenjamin
Copy link
Contributor

There are definitely old issues about this. See e.g. #17224 (comment) and all of the other issues linked from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants