Change order of summation in double sum I need to compute
\begin{align}
S = \sum_{k=-\infty}^j \sum_{m=-1}^2 w_{k,m} f_{k+m-1}
\end{align}
but I only want to access the elements of $f$ once, so I would prefer something like 
\begin{align}
\sum_k f_k \sum_m ...
\end{align}
Here is what I did: substitute $l=m-1+k$ to get
\begin{align}
S &= \sum_{k=-\infty}^j \sum_{m=-1}^2 w_{k,m} f_{k+m-1}
\\
&=\sum_{k=-\infty}^j \sum_{l+1-k=-1}^2 w_{k,l+1-k} f_{l}
\\
&=\sum_{k=-\infty}^j \sum_{l=k-2}^{k+1} w_{k,l+1-k} f_{l}
\end{align}
But when I try to get $f_l$ out of the inner sum I'm messing something up.
Can anyone produce the correct sum for looping over $f$ only once? Thanks in advance.
Since the highest index of $f$ that is accessed is $j+1$, I assume that the outer sum should be
\begin{align}
\sum_{k=-\infty}^{j+1} f_k
\end{align}
 A: The problem is you are introducing a dependency on $k$. To get around this we define
$$s_k := \cases{1&$k\ge0$\\0&$k<0$}$$
Then we have
$$\begin{align*}
\sum_{k=-\infty}^j \sum_{m=-1}^2 w_{k,m} f_{k+m-1} & = \sum_{k=-\infty}^j w_{k,-1} f_{k-2} + w_{k,0} f_{k-1}+w_{k,1} f_k + w_{k,2} f_{k+1} \\
&= \sum_{k=-\infty}^{j-2} w_{k+2,-1} f_k + \sum_{k=-\infty}^{j-1} w_{k+1,0}f_k + \sum_{k=-\infty}^j w_{k,1} f_k + \sum_{k=-\infty}^{j+1} w_{k-1,2} f_k \\
& = \sum_{k=-\infty}^{j+1} s_{j-2-k} w_{k+2,-1} f_k + \sum_{k=-\infty}^{j+1} s_{j-1-k} w_{k+1,0}f_k \\
& \qquad + \sum_{k=-\infty}^{j+1} s_{j-k} w_{k,1} f_k + \sum_{k=-\infty}^{j+1} s_{j+1-k} w_{k-1,2} f_k \\
& = \sum_{k=-\infty}^{j+1} f_k (s_{j-2-k} w_{k+2,-1} + s_{j-1-k} w_{k+1,0} + s_{j-k} w_{k,1} + s_{j+1-k} w_{k-1,2}) \\
& = \sum_{k=-\infty}^{j+1} f_k \sum_{l=-1}^2 s_{j-1+l-k} w_{k+1-l,l}
\end{align*}$$
A final step for simplification would then be an inner substitution to get rid of the $s_\cdot$ terms.
A: Let us assume that:
$$S_l=\sum_{l=-\infty}^{j+1}N_{l} \cdot f_{l}$$
Then we need to figure out what the $N_l$ is.
$$N_l=\sum_{k=-\infty}^{j}\sum_{m=-1}^{2} \omega_{k,m}=\sum_{m=-1}^{2}\sum_{k=-\infty}^{j} \omega_{k,m}$$ 
Under the condition of
$$l=k+m-1$$
Therefor, 
$$k=l-m+1$$
$$N_l=\sum_{m=-1}^{2}\omega_{l-m+1,m}$$ 
A: Step 1: break up the inner sum into 4 parts corresponding to four values of $m$. If the range were larger you could do this for arbitrary upper limit, but I will illustrate this for the specific case of upper limit $u=2$:
$$
S(j,2) = \sum_{k=-\infty}^j \left[  w_{k,-1}f_{k-2}+ w_{k,0}f_{k-1} + w_{k,1}f_l+w_{k,2}f_{k+1} \right] 
$$
The next (and key) step is that we can shift the summation index, but we have to do a different shift for each of the (4 in our case) values of $u$. This leads to different upper limits, and that is where I think you went wrong.  I'm going to let $n=k-2$ in the first sum below, $n=k-1$ in the second sum, and so forth to get $f_n$ in each sum. But because we want to recombine, I will stop all the sums at $n=j-2$, and explicitly write out the left over terms.
$$
S(j,2) = \sum_{n=-\infty}^{j-2}  f_n w_{n+2,-1} + \\
\sum_{n=-\infty}^{j-2}f_n   w_{n+1,0} + f_{j-1}w_{(j-1)+1,0} +\\
\sum_{n=-\infty}^{j-2}f_n   w_{n,1} + f_{j-1}w_{(j-1),1} + f_{j}w_{j,1} + \\
\sum_{n=-\infty}^{j-2}f_n   w_{n-1,2} + f_{j-1}w_{(j-1)-1,2} + f_j w_{j-1,2}
+f_{j+1}w_{(j+1)-1,2}
 $$
And now we can group and simplify:
$$
S = \sum_{n=-\infty}^{j-2}  f_n \left[ 
\sum_{p=-1}^2 w_{n+p,1-p} \right] 
+ f_{j-1}w_{j,0} + f_{j-1}w_{j-1,1} + f_{j}w_{j,1} +  f_{j-1}w_{j-2,2} + f_j w_{j-1,2}+f_{j+1}w_{j,2} \\
S = \sum_{n=-\infty}^{j-2}  f_n \left[ 
\sum_{p=-1}^2 w_{n+p,1-p} \right] + f_{j-1}\left( w_{j,0} + w_{j-1,1} + w_{j-2,2} \right) + f_{j} \left( w_{j,1}  + w_{j-1,2} \right) +f_{j+1}w_{j,2}
$$ 
A: Or you can continue on your method, just make the range of $l$ large enough:
Let $l \in (- \infty, + \infty)$, 
$$S=\sum_{k=-\infty}^{j}\sum_{l=- \infty}^{+ \infty} \Omega_{k,l-k+1} \cdot {f_l}=\sum_{l=- \infty}^{+ \infty} \sum_{k=-\infty}^{j}\Omega_{k,l-k+1} \cdot {f_l}$$
where:
$$
\Omega=\begin{cases}
\omega_{k,l-k+1}, (-1\leq l-k+1 \leq 2) \\0, therwise 
\end{cases}
$$
The fact is that you can always switch the order (under some condition ?) and you can always assume a infinite range. Please comment is I am less than 100% correct.
