Opened 11 years ago

Last modified 10 years ago

#10682 closed defect

sum fails with lower bound != 0 or 1 (upgrade maxima to 5.26) — at Version 8

Reported by: fmaltey Owned by: burcin
Priority: critical Milestone: sage-5.0
Component: symbolics Keywords: maxima 5.26.0 binomial sum
Cc: mjo Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by dimpase)

I test

sage: var ('n,k')
sage: sum (binomial(n,k)*k^2, k, 0, n)  # is right
sage: sum (binomial(n,k)*k^2, k, 1, n)  # is right n(n+1)2^(n-2)
sage: sum (binomial(n,k)*k^2, k, 2, n)  # is false : I get 0 

This works correctly on Maxima 5.26 - we need to upgrade! The new spkg is here. Needs makeinfo to be installed at the moment (which should probably be disabled).

Change History (8)

comment:1 Changed 11 years ago by mboratko

  • Description modified (diff)

comment:2 Changed 10 years ago by was

  • Priority changed from major to critical

This is not some general issue where sum fails on all inputs with lower bound != 0, 1. For example, this is fine:

sage: var('n,k')
(n, k)
sage: sum(k, k, 1, n)  
1/2*n^2 + 1/2*n
sage: sum(k, k, 2, n)  
1/2*n^2 + 1/2*n - 1

Starting at 2, I guess this should be the answer:

sage: (sum (binomial(n,k)*k^2, k, 1, n) - sum (binomial(n,k)*k^2, k, 1, 1))
(n^2 + n)*2^(n - 2) - n

The answer seems fine for starting at 3,4, by the way:

sage: a = (sum (binomial(n,k)*k^2, k, 1, n) - sum (binomial(n,k)*k^2, k, 1, 2))
sage: b = sum (binomial(n,k)*k^2, k, 3, n)
sage: bool(a==b)
True
sage: a = (sum (binomial(n,k)*k^2, k, 1, n) - sum (binomial(n,k)*k^2, k, 1, 3))
sage: b = sum (binomial(n,k)*k^2, k, 4, n)
sage: bool(a==b)
True

This is probably a serious bug in Maxima, since the real work is done by the function

sage.calculus.calculus.maxima.sr_sum

which just calls maxima in some complicated way.

I am raising the priority since this is a subtle and very serious mathematically incorrect result. Also, somebody needs to isolate this to a pure-maxima session exhibiting the bug (if it is in maxima!) and report upstream. I tried for a minute and failed.

comment:3 Changed 10 years ago by nbruin

Maxima 5.23.2 http://maxima.sourceforge.net
using Lisp ECL 11.1.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) load(simplify_sum);
(%o1) /usr/local/sage/4.7.1/local/share/maxima/5.23.2/share/contrib/solve_rec/simplify_sum.mac
(%i2) simplify_sum(sum(binomial(n,k)*k^2,k,2,n));
(%o2)                                  0

comment:4 follow-up: Changed 10 years ago by nbruin

Possibly the following ticket is relevant:

maxima: binomial sums - ID: 2919296

If so, it might be fixed. I don't have access to maxima 5.26 to test.

comment:5 in reply to: ↑ 4 ; follow-up: Changed 10 years ago by dimpase

  • Status changed from new to needs_info

Replying to nbruin:

Possibly the following ticket is relevant:

maxima: binomial sums - ID: 2919296

If so, it might be fixed. I don't have access to maxima 5.26 to test.

It is fixed. (What's a big deal of having access to maxima 5.26? It compiles with ECL supplied with Sage 4.8):

$ ./maxima-local
;;; Loading #P"/usr/local/src/sage/sage-4.8.alpha4/local/lib/ecl-11.1.1/sb-bsd-sockets.fas"
;;; Loading #P"/usr/local/src/sage/sage-4.8.alpha4/local/lib/ecl-11.1.1/sockets.fas"
;;; Loading #P"/usr/local/src/sage/sage-4.8.alpha4/local/lib/ecl-11.1.1/defsystem.fas"
;;; Loading #P"/usr/local/src/sage/sage-4.8.alpha4/local/lib/ecl-11.1.1/cmp.fas"
Maxima 5.26.0_41_gbc6210e http://maxima.sourceforge.net
using Lisp ECL 11.1.1
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) load(simplify_sum);
(%o1)        /tmp/maxima/share/contrib/solve_rec/simplify_sum.mac
(%i2) simplify_sum(sum(binomial(n,k)*k^2,k,2,n));

                                 2       n
                               (n  + n) 2  - 4 n
(%o2)                          -----------------
                                       4
(%i3) 

Thus, we need to update maxima spkg to 5.26.

By the way, I never understood why sum() is hardcoded this way in Sage. Sometimes I'd rather use Python's sum(), but I don't know how to do this.

comment:6 Changed 10 years ago by dimpase

  • Description modified (diff)
  • Summary changed from sum fails with lower bound != 0 or 1 to sum fails with lower bound != 0 or 1 (upgrade maxima to 5.26)

comment:7 in reply to: ↑ 5 Changed 10 years ago by nbruin

Replying to dimpase:

Sometimes I'd rather use Python's sum(), but I don't know how to do this.

This is off-topic but a good question. It shows people don't think of checking the python documentation for something like this, so perhaps a more prominent pointer is necessary

sage: import __builtin__
sage: __builtin__.sum?
...
Docstring:
    sum(sequence[, start]) -> value

(What's a big deal of having access to maxima 5.26? It compiles with ECL supplied with Sage 4.8)

I tried on sage.math.washington.edu with the 4.8 precompiled tarball there and it didn't work for me. Luckily there are other people more skilled at compiling maxima.

comment:8 Changed 10 years ago by dimpase

  • Description modified (diff)
  • Status changed from needs_info to needs_review
Note: See TracTickets for help on using tickets.