[top][index]
search for:

sum(ZZ,Function) -- sum consecutive values of a function

Synopsis:

  • Function: sum -- compute the sum
  • Input:
  • an instance of class ZZ.
  • an instance of class Function.
  • sum(n,f) -- compute the sum f(0) + f(1) + ... + f(n-1).

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

    o1 = 285

    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: