# Summation with restrictions

I am a beginner with Mathematica, so I apologise in advance if this question might sound trivial for most people. I am interested in evaluating a sum of the form

$$\underset{j \, \equiv \, n \pmod2}{\sum_{j=0}^{k/2}\sum_{n=-j}^{j}}f(n)g(j)$$

with $k\in\mathbb{Z}$ and $j\in\frac{1}{2}\mathbb{Z}$, subject to the restriction $j\equiv n \pmod2$. Also the step in the sum is $1/2$.

My question is how do I perform a sum with a restriction like this in Mathematica?

• I tried for example Sum[1,{n,Mod[-j,2],Mod[j,2],1/2}] but I realized that the step $1/2$ is added to the the result of Mod[...] and not to $j$. Well as I said I am just a beginner with Mathematica. – Dimitris May 8 '17 at 12:24
• Is the step in both sums 1/2? – MikeY May 8 '17 at 12:56
• Not sure the equation makes sense. j restricted to n(mod 2) means j takes values {0,1/2,1,3/2}, but what if k = 1,000,000? – MikeY May 8 '17 at 12:57
• @MikeY Yes the step is 1/2 in both sums. Say k=1 then $$\underset{j \, \equiv \, n \pmod2}{\sum_{j=0}^{1/2}\sum_{n=-1/2}^{1/2}}f(n)g(j)$$ This will give $$f(0)g(0)+\underset{1/2 \, \equiv \, n \pmod2}{\sum_{n=-1/2}^{1/2}}f(n)g(1/2)=f(0)g(0)+f(1/2)g(1/2)$$ – Dimitris May 8 '17 at 16:06
• What if k=6? How does that summation work? – MikeY May 8 '17 at 16:35

## 1 Answer

I'd write

Sum[If[Mod[j, 2] == Mod[n, 2], f[n] g[j], 0], {j, 0, k/2, 1/2}, {n, -j, j, 1/2}]


Let k=3;

f g + f[1/2] g[1/2] + f[-1] g + f g + f[-(1/2)] g[3/2] + f[3/2] g[3/2]