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

Sum.doit() gives incorrect results with Random Indexed Variables #19456

Closed
Smit-create opened this issue May 29, 2020 · 3 comments · Fixed by #19459
Closed

Sum.doit() gives incorrect results with Random Indexed Variables #19456

Smit-create opened this issue May 29, 2020 · 3 comments · Fixed by #19459

Comments

@Smit-create
Copy link
Member

While working on #19428, I came across the following error

>>> from sympy.stats import *
>>> from sympy import symbols, S, Eq, Sum
>>> B = BernoulliProcess('B', S(1)/2, 1, -1)
>>> t = symbols('t', positive=True, integer=True)
>>> expr = Sum(B[t], (t,0,5))
>>> expr
Sum(B[t], (t, 0, 5))
>>> expr.doit()  # this should not consider B[t] equal in all the cases as it is random variable
6*B[t]          # incorrect result

Expected behaviour, it should produce: B[0] + B[1] + B[2] + B[3] + B[4] + B[5]

@czgdp1807
Copy link
Member

czgdp1807 commented May 29, 2020

That's quite a problem. Can you please make a PR to fix it?
Does the problem exist with parent class of RandomIndexedSymbol?

@Smit-create
Copy link
Member Author

Does the problem exist with parent class of RandomIndexedSymbol?

I need to look into it

@Smit-create
Copy link
Member Author

Does the problem exist with parent class of RandomIndexedSymbol?

The problem I see here is:

>>> B = BernoulliProcess('B',0.2)
>>> B[t]
B[t]
>>> B[t].free_symbols
{B[t]}

Free symbols is returning B[t], but I think for RandomIndexedSymbol, we should return {B[t], t} if t is symbolic else {B[t]} when t is not symbolic??

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

Successfully merging a pull request may close this issue.

2 participants