Mathieu Avila <mavila@irisa.fr> writes:
> In the dump following, the same expression "expt" is evaluated in two
> different manners, and the result is different (whereas it
> shoulnd't). The EV with the expand flag gives the right result.
[...]
> (C1) exp:2^(-INDICE-1)*(INDICE+1)+2^(-INDICE-1);
> - INDICE - 1 - INDICE - 1
> (D1) (INDICE + 1) 2 + 2
> (C2) expt:sum( exp , indice,0,final);
> FINAL
> ====
> \ - INDICE - 1 - INDICE - 1
> (D2) > ((INDICE + 1) 2 + 2 )
> /
> ====
> INDICE = 0
> (C3) ev(expt,simpsum);
> - FINAL - 1
> (D3) 1 - 2
> (C4) ev(expt,simpsum,expand);
>
> - FINAL - 1
> (D4) 2 - 2 2
I think that both results are wrong.
(C1) expt:2^(-i-1)*(i+1)+2^(-i-1);
- i - 1 - i - 1
(D1) (i + 1) 2 + 2
(C2) testsum(f):=apply('sum,[expt,i,0,f]);
(D2) testsum(f) := APPLY('SUM, [EXPT, i, 0, f])
(C3) testsum(1);
7
(D3) -
4
wheras the two results you got give 3/4 resp. 3/2.
I suggest instead
(C4) closed_form(f):=3-2^(-f-1)*(f+4);
- f - 1
(D4) closed_form(f) := 3 - 2 (f + 4)
(C5) for f from 0 thru 10 do sprint(testsum(f));
1 7/4 9/4 41/16 11/4 183/64 187/64 757/256 381/128 3059/1024 3065/1024
(D5) DONE
(C6) for f from 0 thru 10 do sprint(closed_form(f));
1 7/4 9/4 41/16 11/4 183/64 187/64 757/256 381/128 3059/1024 3065/1024
(D6) DONE
(C7)
Wolfgang