4
$\begingroup$

Let list $S_k$ be an arbitrary list of numbers (may not necessarily be ordered).

List $S_{k+1}$ is created via the cumulative sum of elements from list $S_k$.

For example if $S_k$ = [2,5,7,9] then $S_{k+1}$ = [2,7,14,23]

Is there a way to tell what numbers will be in list $S_n$ with $n>k$ without needing to create all the intermediate lists?

3 Answers 3

4

Using $S_k(i)$ to indicate the $i^{th}$ term of $S_k$, then

$S_n(j) = \sum_{i \le j} {n-k-1+j-i \choose j-i} S_k(i)$ so you only need to do weighted sums over the original sequence.

  • 0
    @Henry Is there a faster way to compute the entries that do not require iterating over old S[i] repeatedly? (Should I make this a separate question?)2012-12-31
3

You get the next list by multiplication from the left with a lower triangular matrix $L$ with all $1$'s.

$ L = \begin{pmatrix} 1 & 0 & \dotsc & 0 \\ \vdots & \ddots & \ddots & \vdots \\ \vdots & & \ddots & 0 \\ 1 & \dotsc & \dotsc & 1 \end{pmatrix} $

Then you can quickly find sequence $n$ by computing $L^n$ which can be done fairly quickly, e.g by the square-and-multiply method.

  • 3
    In fact $L^k(i,j) = \dbinom{k-1+i-j}{k-1}$2012-12-31
0

This is an answer to the request in some comments to show how to arrive at the formula for the entries of $L^h$

Here is an example how we can find the entries of $L^h$ symbolically. I do with the $4 \times 4 $ triangular matrix $L$ $ M(h) = \exp( h \cdot \log (L)) = L^h $ and get for $M$ $ M(h) = \left[ \begin{array} {rrrr} 1 & . & . & . \\ 1h & 1 & . & . \\ \frac 12( 1 h^2+ 1 h) & 1h & 1 & . \\ \frac 16( 1h^3+ 3 h^2+ 2 h) & \frac 12 (1h^2+ 1h) & 1h & 1 \end{array} \right]$ Here a trained eye recognizes the Stirling numbers 1st kind as coefficients at the powers of $h$ and because the structure of the matrix has this constant diagonals it is easy to make the formula for the transfer: $ M(h)\cdot S_k = S_{k+h} $ One more step shows, that the evaluation of the polynomials in the entries leads to binomial numbers, which is a well known property of the Stirling numbers first kind (the vandermonde-matrix LDU-decomposes into the matrices of Stirling-numbers 2st kind and of binomial coefficients and thus reduces by the multiplication with the matrix of Stirling numbers 1'st kind (which is the inverse of the 2nd-kind matrix) to binomials)


I had fun to proceed a bit. Factorizing the smbolic entries, assuming the hypothese that we have always the Stirling numbers 1st kind and the fractional cofactors the reciprocal fatorials give
$ M(h) = \left[ \begin{array} {llll} 1 & . & . & . \\ 1(h) & 1 & . & . \\ \frac 12( h(h+1)) & 1(h) & 1 & . \\ \frac 16( h(h+1)(h+2)) & \frac 12 ( h(h+1)) & 1(h) & 1 \end{array} \right]$ and this gives immediately the binomial coefficients $ M(h) = \left[ \begin{array} {cccc} 1 & . & . & . \\ \binom{h}{1} & 1 & . & . \\ \binom{h+1}{2} & \binom{h}{1} & 1 & . \\ \binom{h+2}{3} & \binom{h+1}{2} & \binom{h}{1} & 1 \end{array} \right]$

and a routine could solve the problem given the vector S of dimension n in the following way:

   T = 0*S ;  \\ initialize an empty array of size of S    b  = 1;    \\ contains the current binomial       for(j=1,n,        for(k=j,n, T[k]+=S[k+1-j]*b);        b *= (h+j-1)/j;        );    return(T); 

So we have $n^2/2$ operations by the looping.

  • 0
    @user51819 : to reduce the computing time of pre-multiplication of a vector by a lower triangular matrix below the magical $n^2/2$ scalar operations you might look for something like "karatsuba" multiplication (don't have the name at hand) and discrete fast fourier transformation. I think I remember vaguely that those methods help to break that lower limit.2012-12-31