[top][index]
search for:

sum({...},Function) -- sum results of applying a function

Synopsis:

  • Function: sum -- compute the sum
  • Input:
  • an instance of class List.
  • an instance of class Function.
  • sum(v,f) -- yields the sum of the expressions obtained by applying f to each of the elements of the list or sequence v.

    i1 : sum(1 .. 10, i -> i^2)

    o1 = 385

    See also:

  • sum -- compute the sum
  • Code:

         -- ../../../Macaulay2/m2/lists.m2:59-65
         sum(ZZ,Function) := (n,f) -> (
              s := 0;
              g := x -> (
                   s = f x; 
                   g = x -> s = s + f x);
              scan(n,x -> g x);
              s);

    [top][index]
    search for: