accumulate

accumulate(f,x0,{x1,...,xn}) -- computes the list {f(x0,x1),f(f(x0,x1),x2),...}.
accumulate({xn,...,x1},x0,f) -- computes the list {...,f(x2,f(x1,x0)),f(x1,x0)}.
accumulate(f,{x0,x1,...,xn}) -- computes the list {f(x0,x1),f(f(x0,x1),x2),...}.
accumulate({xn,...,x1,x0},f) -- computes the list {...,f(x2,f(x1,x0)),f(x1,x0)}.

i1 : accumulate(plus,1,{10,100,1000})

o1 = {11, 111, 1111}

o1 : List
i2 : accumulate(toList,{a,b,c,d})

o2 = {{a, b}, {{a, b}, c}, {{{a, b}, c}, d}}

o2 : List

See also fold.


topindexpreviousupnext