[top][index]
search for:

accumulate(Function,VisibleList) -- apply binary operator repeatedly

Synopsis:

  • Function: accumulate -- apply binary operator repeatedly
  • Input:
  • an instance of class Function.
  • an instance of class VisibleList.
  • Output:
  • an instance of class VisibleList.
  • accumulate(f,{x0,x1,...,xn}) -- computes the list {f(x0,x1),f(f(x0,x1),x2),...}.

    i1 : accumulate(identity, {a,b,c,d,e})

    o1 = {(a, b), ((a, b), c), (((a, b), c), d), ((((a, b), c), d), e)}

    o1 : List
    i2 : accumulate(plus, 0 .. 10)

    o2 = (1, 3, 6, 10, 15, 21, 28, 36, 45, 55)

    o2 : Sequence

    Code:

         -- ../../../Macaulay2/m2/fold.m2:6-8
         accumulate(Function,VisibleList) := VisibleList => (f,v) -> (
              if #v === 0 then error "expected a nonempty list";
              accumulate(f,v#0,drop(v,1)))

    [top][index]
    search for: