up previous next
sum

the sum of the elements of a list

Syntax
sum(L: LIST): OBJECT
sum(L: LIST, InitVal: OBJECT): OBJECT

Description
This function returns the sum of the objects in the list L (together with InitVal , if specified). If the list L may be empty, you must specify InitVal .

Example
/**/  use R ::= QQ[x,y];
/**/  sum([3, x, y^2]);
y^2 +x +3

/**/  sum(1..40) = binomial(41,2);
true

/**/  sum(["c","oc","oa"]);
cocoa

/**/ sum([], "");      -- gives empty STRING

/**/ sum([], zero(R)); -- gives type RINGELEM
0

See Also