#164 simpsum bug

closed
Lisp Core (471)
5
2005-12-02
2002-10-18
Anonymous
No

Hi!

Unfortunately I have found a bug in simpsum (it seems):

(C1)
'SUM(BINOMIAL(2,2-k)-BINOMIAL(2,1-k),k,1,2),simpsum;

(D1) 3

***************** wrong **********************

(C2) 'SUM(BINOMIAL(2,2-k)-BINOMIAL(2,1-k),k,1,2),sum;

(D2) 2

***************** correct ********************

***************** however : ******************

(C3)
'SUM(BINOMIAL(x,2-k)-BINOMIAL(x,1-k),k,1,2),simpsum;

(D3) x

(C4) 'SUM(BINOMIAL(x,2-k)-BINOMIAL(x,1-k),k,1,2),sum;

(D4) x
(C5) bug_report();

Maxima version: 5.9.0rc1
Maxima build date: 11:40 9/3/2002
host type: i686-pc-linux-gnu
lisp-implementation-type: Kyoto Common Lisp
lisp-implementation-version: GCL-2-5.0

Martin

Discussion

  • Martin Rubey

    Martin Rubey - 2002-11-26

    Logged In: YES
    user_id=651552

    OK, I got the bug now:

    The fix is rather obvious (except that I had to dig through
    all of sum,
    see below) and the bug is rather serious (I can produce lots of
    everyday examples,

    (C1) sum(f(k)+1,k,1,n),simpsum;

    (D2) n

    so I propose to include it in 5.9.0 !!!

    I didn't change some things I would like to, I think this is
    for after
    5.9.0...

    fix and explanation below
    Martin

    -----------------------------fix-------------------------------------
    diff combin.lisp combin.lisp.~1.2.~
    915,920d914
    < ; Kratt5, 26.11.2002
    < ; adsum's and adusum's the sum of e.
    <
    < ; It's result is discarded. (at least I think that this
    function is
    < ; only called by sumsum, but there are lots of places
    where a variable
    < ; is called "sum"...)
    930,939d923
    < ; this is to deal with linearity Kratt5, 26.11.2002
    < ((let (*a *n (var *var*))
    < (cond ((prog2 (m2 e '((mtimes) ((coefftt) (var*
    (set) *a freevar))
    < ((coefftt) (var*
    (set) *n true)))
    < nil)
    < (not (equal *a 1)))
    < ;; we have to return T, so that sum is exited if the test
    was successful
    < (prog2 (sum *n (list '(mtimes) y *a))
    < T)))))
    < ;;
    943,944c927
    < #+cl (adusum (list '(mtimes) e y)) ;; Kratt5 26.11.2002
    < ;; nil
    ---
    > nil

    --------------------------end
    fix------------------------------------

    I tested it with

    Maxima version: 5.9.0rc3
    Maxima build date: 13:52 11/18/2002
    host type: i686-pc-linux-gnu
    lisp-implementation-type: Kyoto Common Lisp
    lisp-implementation-version: GCL-2-5.0

    ----------------------------explanation ------------------
    (lisp level)

    the structure of $sum is roughly as follows:

    $sum: argcheck, call dosum with meval'd bounds

    dosum: didn't look at this too much

    after this, meval calls simpsum

    **** if you type 'sum(f(k),k,1,n),simpsum; meval calls only
    simpsum ****

    $simpsum: call simpsum1

    simpsum1: checks lo=hi, otherwise
    exp not depending on the summation index, otherwise
    if $simpsum, call simpsum2

    **** simpsum2 is found in combin.lisp ****

    simpsum2: sets up a variable *plus, which will contain
    all the stuff
    which is added together at the end
    calls sumsum

    sumsum: returns the part of the expression it was able
    to sum up
    (this is the contents of the variable "usum"),
    all the rest
    (the contents of the variable "sum") is put
    into the
    variable *plus, which is then used by simpsum2
    calls sum

    sum: adsum's and adusum's the sum of e.
    It's result is discarded. (at least I think
    that this
    function is only called by sumsum, but there
    are lots of
    places where a variable is called "sum"...)

     
  • Martin Rubey

    Martin Rubey - 2002-11-26

    Logged In: YES
    user_id=651552

    > Can you explain why there is a conditionalization
    > for #+cl there? I don't see any reason for this
    > code to depend on common lisp or not. My thought
    > on fixing the code previously displayed was to
    > just remove #-cl
    > RJF

    Yes, I can explain it. It's there because I was very stupid.
    Here is the
    right fix:
    (and THANK YOU, I feel a little ashamed...)

    diff combin.lisp combin.lisp.~1.2.~
    915,920d914
    < ; Kratt5, 26.11.2002
    < ; adsum's and adusum's the sum of e.
    <
    < ; It's result is discarded. (at least I think that this
    function is
    < ; only called by sumsum, but there are lots of places
    where a variable
    < ; is called "sum"...)
    933,935c927,929
    < ;; nil ;; Kratt5 26.11.2002
    < ; #-cl
    < (let (*a *n) (var *var*)) ; freevar expects "var",
    not "*var*"
    ---
    > nil
    > #-cl
    > (let (*a *n)

     
  • Martin Rubey

    Martin Rubey - 2002-11-26

    Logged In: YES
    user_id=651552

    sorry, below was a typo (a parenthesis didn't get deleted)

    933,935c927,929
    < ;; nil ;; Kratt5 26.11.2002
    < ; #-cl
    < (let (*a *n (var *var*)) ; freevar expects "var",
    not "*var*"
    ---
    > nil
    > #-cl
    > (let (*a *n)

     
  • Stavros Macrakis

    Logged In: YES
    user_id=588346

    Thanks for the patch. You might also be interested to know
    that nusum does very nicely on this case (generalized) with a
    little massaging:

    summand: binomial(q,2-k)-binomial(q,1-k);
    sum0: nusum( minfactorial(makefact(summand)), k,1,n);
    factcomb(minfactorial(sum0)) =>
    q-q!/((1-n)!*(q+n-1)!)

    For more fun, try summand: binomial(q,7-k)-binomial(q,3-k);

    PS Could you please post the complete patched 'sum'
    function? I am more confident with that than with merged
    patches. Thanks.

     
  • Robert Dodier

    Robert Dodier - 2005-11-24
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2005-11-24

    Logged In: YES
    user_id=501686

    The reported bug is not present in the current cvs version of
    Maxima.

    Thank you for your report. If you see this bug in a later version
    of Maxima, please submit a new bug report.

     
  • Robert Dodier

    Robert Dodier - 2005-11-25

    Logged In: YES
    user_id=501686

    Reopening this report because the example shown below
    (sum(f(k)+1,k,1,n),simpsum;) is still present. Not clear to
    me whether any of the patches shown below was ever applied.

     
  • Robert Dodier

    Robert Dodier - 2005-11-25
    • status: closed --> open
    • assigned_to: nobody --> robert_dodier
     
  • Robert Dodier

    Robert Dodier - 2005-12-02
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 2005-12-02

    Logged In: YES
    user_id=501686

    sum(f(k)+1,k,1,n),simpsum; => n+'sum(f(k),k,1,n)
    now, due to r1.10 src/combin.lisp.
    (need to call ADUSUM in SUM to add up parts
    of summand which depend on summation index.)
    I wasn't able to decipher the patches stated below, so I
    figured out a different patch, which works for the examples
    which I added to tests/rtestsum.mac. Closing this bug as fixed.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks