Maxima CAS : summation with symbolic upper limit n not simplifying when the upper limit is specified later with ev()

StackOverflow https://stackoverflow.com/questions/21842488

Question

The following two pieces of maxima code should be equivalent:

sum(x[i], i, 1, 2);
ev(%, x[1] = 5, x[2] = 3);

and:

sum(x[i], i, 1, n);
ev(%, n = 2, x[1] = 5, x[2] = 3);

In the first case, maxima knows to evaluate the expression to 8. In the second case, it doesn't simplify and leaves me with a symbolic summation of x[i] for i = 1 to 2.

Why is it that maxima is unable to recognize the second expression as being the same as the first?

Short of hardcoding the answer (as in the first piece of code), how do I get maxima to fully evaluate a summation with indexed variables when evaluating a summation where the upper limit is specified later?

Était-ce utile?

La solution

sum is in the noun form (see a leading % in the lisp expression)

(%i76) expr: sum(x[i], i, 1, n);
                                    n
                                   ====
                                   \
(%o76)                              >    x
                                   /      i
                                   ====
                                   i = 1
(%i77) :lisp $expr

((%SUM SIMP) (($X SIMP ARRAY) $I) $I 1 $N)

You need to tell ev to evaluate nouns

(%i77) ev(expr, n = 2, x[1] = 5, x[2] = 3, nouns);
(%o77)                              x  + x
                                     2    1

and request an extra post-evaluation

(%i78) ev(expr, n = 2, x[1] = 5, x[2] = 3, nouns, eval);
(%o78)                                 8
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top