27.37 Sum

Sum( list )
Sum( list, func )

In the first form Sum returns the sum of the elements of the list list, which must have no holes. If list is empty 0 is returned.

In the second form Sum applies the function func to each element of the list list, which must have no holes, and sums the results. If the list is empty 0 is returned.

    gap> Sum( [ 2, 3, 5, 7, 11, 13, 17, 19 ] );
    77
    gap> Sum( [1..10], x->x^2 );
    385
    gap> Sum( [ [1,2], [3,4], [5,6] ] );
    [ 9, 12 ] 

Product (see Product) computes the product of the elements of a list.

Previous Up Top Next
Index

GAP 3.4.4
April 1997