[Maxima] wrong sum with conditional function

Robert Dodier robert.dodier at gmail.com
Sat Dec 19 12:18:19 CST 2009


On 12/19/09, Alexandros Droseltis <ml-maxima at alex-droseltis.com> wrote:

> (%i1) d(k) := if k=0 then 0 else 1;
> (%o1)                   d(k) := if k = 0 then 0 else 1
> (%i2) assume(a>0);
> (%o2)                               [a > 0]
> (%i3) sum(d(k), k, 0, a);
> (%o3)                                a + 1
> (%i4)
>
> How comes this +1 in the result?

This is actually a consequence of the behavior of "=".
a = b is true when a and b are identical expressions,
while equal(a, b) is true when a and b are equivalent.
e.g. is(x*(x + 1) = x^2 + x) => false (not identical)
while is(equal(x*(x + 1), x^2 + x)) => true (equivalent).

Try putting if equal(k, 0) ... in your function.
I think you'll get a different result.

best

Robert Dodier


More information about the Maxima mailing list