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

Weird value of a sum #19745

Open
proy87 opened this issue Jul 11, 2020 · 1 comment
Open

Weird value of a sum #19745

proy87 opened this issue Jul 11, 2020 · 1 comment
Labels

Comments

@proy87
Copy link

proy87 commented Jul 11, 2020

Sum(x,(x,1,Integer(3)/2)).doit() gives 15/8. How is it calculated and how sympy handles non-integer bounds?

@oscarbenjamin
Copy link
Contributor

There is an issue #5822 for this.

It's calculated like this:

In [1]: Sum(x, (x, y, z)).doit()                                                                                       
Out[1]: 
   2        2    
  y    y   z    z
- ── ++ ── +2    2   2    2

In [2]: Sum(x, (x, y, z)).doit().subs({y:1, z:Rational(3, 2)})                                                         
Out[2]: 15/8

Some parts of the implementation of Sum assume that the bounds are integers but nothing prevents giving non-integer bounds. There have been suggestions to disallow non-integer bounds and also suggestions to make sense of them in some way.

The behaviour of Sum in a number of ways does not match the definition given in the docstring:
https://docs.sympy.org/latest/modules/concrete.html#sympy.concrete.summations.Sum

Karr's definition referred to there would imply that Sum(f(x), (x, 1, 4)) == f(1) + f(2) + f(3) but that's not what we get:

In [8]: Sum(f(x), (x, 1, 4)).doit()                                                                                    
Out[8]: f(1) + f(2) + f(3) + f(4)

Also Karr's definition would imply that flipping the limits is equivalent to introducing a minus sign but that isn't what we get:

In [17]: Sum(f(x), (x, 4, 1)).doit()                                                                                   
Out[17]: -f(2) - f(3)

So the current behaviour does not match Karr's definition at all as far as I can tell. The behaviour for inverted limits is non-sensical and the behaviour for ordinary limits does not match the documented definition.

Also having looked at Karr's paper there doesn't seem to be any definition of a summation with non-integer bounds. The paper seems to take it as implicitly obvious that the bounds are integers.

It seems that we need to fix what is the actual definition of Sum and then fix the behaviour to make it consistent.

skirpichev added a commit to skirpichev/diofant that referenced this issue Aug 19, 2021
skirpichev added a commit to skirpichev/diofant that referenced this issue Aug 27, 2021
The Karr summation convention explained in more details to
prevent misunderstanding (e.g. see example in
sympy/sympy#19745 (comment)).

Few doctests provided.
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

2 participants