[top][index]
search for:

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

Synopsis:

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

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

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

    o1 : List

    Code:

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

    [top][index]
    search for: