I'd like to calculate the following sum efficiently
$$S(k, M) = \sum_{m=k}^M (-1)^m \binom{m}{k}$$
I've tried to use generating functions and write
$$ S(k,M) = \sum_{m=k}^M [x^k] (-1-x)^m = [x^k] \frac{(-1-x)^{k+1}-(-1-x)^{M+1}}{2+x} $$
But because there's $2+x$ in the denominator, it will still be a sum and not just coefficient extraction from the numerator as happens in the usual hockey stick formula.
Another thing I tried is to write $\binom{m}{k} = \binom{m+1}{k+1} - \binom{m}{k+1} $, so we have
$$ S(k,M) = \sum_{m=k}^M (-1)^m \binom{m+1}{k+1} - \sum_{m=k}^M (-1)^m \binom{m}{k+1} = \dots $$
Oh, and just noticed: up to sign these are A108561. (The columns or something maybe some sort of diagonals.) There's the formula $T(n,k) = T(n-1,k) + T(n-2,k-1) + T(n-2,k-2)$ there. Could that be helpful, or do we end up generating the whole triangle? That would be too big, I have $M=10^7$. Although, I am calculating this for all $k=1,\dots, M$ so if we can calculate these numbers along as we go that would be great!
You have $$\eqalign{S(k,M) - S(k,M-1) &= (-1)^M {M \choose k} = (-1)^M \left({M-1 \choose k-1} + {M-1 \choose k}\right)\cr &= -S(k-1,M-1) + S(k-1,M-2) - S(k,M-1) + S(k,M-2))} $$ so $$ S(k,M) = -S(k-1,M-1) + S(k-1,M-2) + S(k,M-2) $$ with $S(k,M) = 0$ if $k > M$ or $k = 0$ and $(-1)^M$ if $k=M$.
Note that to compute $S(k,M)$ for all $k = 1, \ldots, M$ you will need $S(\ldots,M-1)$ and $S(\ldots, M-2)$. So you don't need to keep the whole triangle in memory, just the last two $M$'s in addition to the one you're doing now.