Question

I have the following problem - I need to minimize the sum in the maple. For example, suppose I have this:

EXPESSION:=A[0]+A[1]+A[2]+A[3]+A[4]+A[5];

And I want to use some function

someFunction(EXPRESSION);

which will return a symbol of the Sum (like sum(A[i], i = 0 .. 5));

Is some function like that exists?

Was it helpful?

Solution

Okay, I guess that you need something to compress an existing expession. If you're willing to specify the summand, index, and index range, then someFunction could subtract the terms and add the (unevaluated) Sum of those terms.

convert_to_Sum:= (ex, summand, index)->
    simplify(ex - sum(summand, index) + Sum(summand, index))
;

Example:

ex:= A[0]+A[1]+A[2]+A[3]+A[4]+A[5];
convert_to_Sum(ex, A[i], i= 0..5);

OTHER TIPS

Use Sum(A[i], i= 0..5) Note that Sum is uppercase. I realize that this does not handle the case where the expression already exists, which may be what you are primarily interested in.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top