﻿ AccumulateList – Algosim documentation
Algosim documentation: AccumulateList

# AccumulateList

Computes a value by accumulating the values in a container and returns a list with every partial value obtained in the process.

## Syntax

• `AccumulateList(X, x, f)`

• `X` is an ordered container

• `x` is any object

• `f` is a function

## Description

If `X` is an ordered container, `x` a value, and `f` a function, then `AccumulateList(X, x, f)` returns the list containing the partially accumulated values in `X` using `x` as the initial value and `f` as the function. Specifically, `AccumulateList(X, x, f)` returns the list `L` of length `n` defined by

```L ≔ f( x  , X)
L ≔ f(L, X),
L ≔ f(L, X),
⋮
L[n] ≔ f(L[n−1], X[n])```

where `n = #X`.

## Examples

`X ≔ ❨5, 1, 2, −6, 4, 2, 1, 1, −6❩`
`(5, 1, 2, −6, 4, 2, 1, 1, −6)`
`AccumulateList(X, 0, add)`
```5
6
8
2
6
8
9
10
4
```
`AccumulateList(X, 1, multiply)`
```5
5
10
−60
−240
−480
−480
−480
2880
```
`AccumulateList(X, 1, lcm)`
```5
5
10
30
60
60
60
60
60
```