SERIOUS simpsum bug



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"...)