Summing problem



Stavros Macrakis wrote:

>It is easier to see what is going on with Sum and evaluation if you use
>Makelist instead of Sum:
>
>(C1) makelist(q,i,1,3);
>(D1)                           [q, q, q]
>
>(C2) q:i^3;
>                                    3
>(D2)                               i
>
>(C3) makelist(q,i,1,3);
>                                3   3   3
>(D3)                          [i , i , i ]
>
>(C4) makelist('(q),i,1,3);
>(D4)                           [q, q, q]
>
>(C5) makelist(ev(q),i,1,3);
>(D5)                           [1, 8, 27]
>
>This is all rather confusing, but perhaps internally consistent.  Even
>more confusing when you add subst or buildq and ev to the mix.  But that
>is another story.
>
>       -s
>
>_______________________________________________
>Maxima mailing list
>Maxima@www.math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
>
>  
>
Hello, and thank you all for your advice.

It seems the problem is a bit more complicated than your makelist 
example. In my precedent example, the results were not simplified in the 
most simple cases, when the expression, or the upper bound were 
integers. Example:

(C21) sum(subst(Indice,i,1),indice,1,I12);
                        I12
                        ====
                        \
(D21)                    >         SUBST(INDICE, I, 1)
                        /
                        ====
                        INDICE = 1

I found a combination of EV and SUM and SUBST which evaluated well,  be 
this is certainly not the right way of doing this.

Sommation_workaround(exp,indice,fin):=
    block([exp2,exp3,exp4,final,I],
    exp4:subst('indice,INDICE,exp),
    exp2:ev(sum( exp4 , indice,0,final),simpsum,subst,sum),
    exp3:subst(fin,'final,exp2),
    return(exp3)
    );

You may think this is a really strange (and ugly) construction, but if 
you try with simple examples, you will see it works in all cases.

Note that the problem is that I don't know which variable will be the 
index at the time i write the expression to be summed. This is why a 
have to "subst". I tried to use the "indice" variable into the sum, 
hoping it would sum the expression with the value of indice, not its 
name, but it didn't worked and used its name instead. Then i had to 
subst it, and use "subst('indice,INDICE,exp)" with a ' in the first 
argument to protect it, and no ' in the second argument to replace it by 
the variable to be summed up.
I agree this is a bad solution. I would *love* to have another cleaner 
solution, so if  ever experienced this problem, don't hesitate to  give 
me your solution.

--
Mathieu Avila ( mavila@irisa.fr )