Given is a sequence of natural numbers: $1,2,...,n$. I want to choose two elements $a,b$ of this sequence, calculate $c=ab+a+b$ and write $c$ back to the sequence. After $n-1$ iterations, there is only one element left. When I choose $n=10$ this element is: $39916799$
I have written this algorithm in Haskell:
foldl (\a b -> a*b+a+b) 0 [1..10]
and in Scala:
((1 to 10) foldLeft 0) {(a,b) => a*b+a+b}
Both work fine. Now I want to define this algorithm, which uses a fold, in mathematics. I came to this:
$f: [1,n]n\in \mathbb N \rightarrow \mathbb N$ $f(p)=\cases{p_0p_1+p_0+p_1, &if\ |p|=2\cr f(p_0p_1+p_0+p_1+\sum\limits_{i=2}^n i), & else}$
I don't think this is completely correct. For example, a interval is defined on $\mathbb R$ not $\mathbb N$ thus I don't know if it is possible to narrow it on $\mathbb N$. Can someone say me if it is possible to write a fold in mathematics and if yes, how?
Notice: I know, the fold is unnecessary because the result can be calculated with $(n+1)!-1$, but I want to know how to write such a fold in mathematics.