Opened 11 years ago
Closed 6 years ago
#9635 closed defect (fixed)
symbolic sum gives wrong answer
Reported by:  Henryk.Trappmann  Owned by:  burcin 

Priority:  major  Milestone:  sage6.5 
Component:  calculus  Keywords:  
Cc:  Merged in:  
Authors:  Ralf Stephan, KarlDieter Crisman  Reviewers:  KarlDieter Crisman, Ralf Stephan 
Report Upstream:  N/A  Work issues:  
Branch:  b8569fe (Commits, GitHub, GitLab)  Commit:  b8569fe48be69b143ea64205cb6f018547b67805 
Dependencies:  Stopgaps: 
Description
sage: (n,k,j)=var('n,k,j') sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) 0 sage: (n,j)=(5,3) sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j) for k in range(j +1,n+1)) 1
The above sum should be 1 for n>=j and 0 otherwise.
From kcrisman: This appears to be a bug in Maxima.
(%i1) load(simplify_sum); <snip> (%i3) simplify_sum(sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j +1,n)); (%o3) 0 (%i4) simplify_sum(sum(binomial(5,k)*binomial(k1,3)*(1)**(k13),k, 4,5)); (%o4) 1 (%i5) 5*1*1+1*4*(1); (%o5) 1
Change History (12)
comment:1 Changed 11 years ago by
 Component changed from basic arithmetic to calculus
 Owner changed from AlexGhitza to burcin
 Report Upstream changed from N/A to Reported upstream. Developers acknowledge bug.
comment:2 Changed 10 years ago by
Maxima 5.23.2 still has this, and no movement on the original bug report.
comment:3 Changed 9 years ago by
 Report Upstream changed from Reported upstream. Developers acknowledge bug. to Fixed upstream, in a later stable release.
The bug report got updated over a year ago.
In the current Sage:
(%i1) load(simplify_sum); (%o1) /Users/karldietercrisman/Downloads/sage5.0/local/share/maxima/5.26.0/s\ hare/contrib/solve_rec/simplify_sum.mac (%i2) simplify_sum(sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j +1,n)); Is j + 1 positive, negative, or zero? pos; (%o2) 1
So just need a doctest.
sage: (n,k,j)=var('n,k,j') sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) sum((1)^(j + k)*binomial(k  1, j)*binomial(n, k), k, j + 1, n) sage: assume(j>1) sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) 1 sage: forget() sage: assume(n>=j) sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) sum((1)^(j + k)*binomial(k  1, j)*binomial(n, k), k, j + 1, n) sage: forget() sage: assume(j==1) sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) 1 sage: forget() sage: assume(j<1) sage: sum(binomial(n,k)*binomial(k1,j)*(1)**(k1j),k,j+1,n) sum((1)^(j + k)*binomial(k  1, j)*binomial(n, k), k, j + 1, n)
Was the original report here wrong? Maxima currently says that the sign of j+1
is all that matters, which sort of makes sense
comment:4 Changed 6 years ago by
 Milestone set to sageduplicate/invalid/wontfix
 Status changed from new to needs_review
Now it's no longer solved at all, i.e., the sum is returned. Since there is no longer an erroneous result the ticket can be closed I think.
comment:5 Changed 6 years ago by
 Status changed from needs_review to needs_info
All closures like this should be doctested  in case the bad behavior returns.
comment:6 Changed 6 years ago by
 Branch set to u/rws/symbolic_sum_gives_wrong_answer
comment:7 Changed 6 years ago by
 Commit set to 5479dd1c8e524759f71933421e4557ac2d36189b
 Milestone changed from sageduplicate/invalid/wontfix to sage6.5
 Report Upstream changed from Fixed upstream, in a later stable release. to N/A
 Status changed from needs_info to needs_review
New commits:
5479dd1  9635: doctest

comment:8 Changed 6 years ago by
 Branch changed from u/rws/symbolic_sum_gives_wrong_answer to u/kcrisman/ticket/9635
 Commit changed from 5479dd1c8e524759f71933421e4557ac2d36189b to b8569fe48be69b143ea64205cb6f018547b67805
 Reviewers set to KarlDieter Crisman
Actually, in this case the doctest I pasted above is absolutely correct. One still has to assume the right thing for it to return anything other than the original sum! Your part is fine, you can just review the additional ones (unless you think they are too much).
New commits:
b8569fe  Add full doctest

comment:9 Changed 6 years ago by
Somehow I still expect results like a (for x<0); b (for x==0); c (else)
but I digress...
comment:10 Changed 6 years ago by
 Reviewers changed from KarlDieter Crisman to KarlDieter Crisman, Ralf Stephan
 Status changed from needs_review to positive_review
Tests OK, is fine.
comment:11 Changed 6 years ago by
Somehow I still expect results like a (for x<0); b (for x==0); c (else) but I digress...
That isn't possible with the current Maxima setup (at least not in a useful way, given the crazy number of branches Maxima gives us) but perhaps via sympy? That would be a very, very good improvement.
comment:12 Changed 6 years ago by
 Branch changed from u/kcrisman/ticket/9635 to b8569fe48be69b143ea64205cb6f018547b67805
 Resolution set to fixed
 Status changed from positive_review to closed
This is now Maxima bug 3036579.