For positive integers $m$ and $n$, what is the integral of the function $(-1)^{\lfloor x \rfloor + \lfloor y \rfloor}$ on the triangle with vertices $(0,0)$, $(m,0)$, and $(0,n)$?


Pictorially, we are putting a red/black checkerboard coloring on the plane and finding the signed difference between the red region enclosed by the triangle and the black region enclosed by the triangle.


Call this integral $I(m,n)$. Here are some values of $I(m,n)$ (if my calculations of signed sums of areas of little triangles and trapezoids are correct):


$\begin{array}{c|ccccc} & 1 & 2 & 3 & 4 & 5 \\ 
\hline 
1 & 1/2 & 1/2 & 1/2 & 1/2 & 1/2 \\
2 & 1/2 & 0 & -1/6 & 0 & 1/10 \\
3 & 1/2 & -1/6 & 1/2 & 5/6 & 1/2 \\
4 & 1/2 & 0 & 5/6 & 0 & -1/2 \\
5 & 1/2 & 1/10 & 1/2 & -1/2 & 1/2
\end{array}$


It would be good to tabulate more values. Can any computer algebra systems handle such computations for specific $m,n$?


Obviously $I(m,n) = I(n,m)$, and an easy telescoping-sum argument shows that $I(1,n)=1/2$. A symmetry argument shows that $I(m,n)=1/2$ when $m$ and $n$ are both odd, and from this it can be proved that $I(m,n)=0$ when $m$ and $n$ are both even. The values of $I(m,n)$ where $m$ and $n$ have opposite parity seem more subtle.



Area-differences for lattice triangles in a checkerboard
Define
$$ h(x)=(-1)^{\lfloor x\rfloor}\, (x-\lfloor x\rfloor)(x-\lfloor x\rfloor-1) $$
Then we have
$$I(n,m)= \frac{{\rm Mod}(n,2)}{2}+\frac{n}{m} \sum\_{j=1}^{n-1} (-1)^{n-j} \, h\left(\frac{jm}{n}\right)$$
Proof: We use the two primitives
\begin{eqnarray\*}
f(y)=\int\_0^y dx\, (-1)^{\lfloor x\rfloor} &=& {\rm Mod}(y,2)+(-1)^{\lfloor y\rfloor}\,(y-\lfloor y\rfloor)\\
g(z)=\int\_0^z dy \int\_0^y dx\, (-1)^{\lfloor x\rfloor}&=& \frac{z}{2}+(-1)^{\lfloor z\rfloor}\, \frac{(z-\lfloor z\rfloor)(z-\lfloor z\rfloor-1)}{2}
\end{eqnarray\*}
to rewrite
\begin{eqnarray\*}
I(n,m)&=& \int\_0^n dx (-1)^{\lfloor x\rfloor}\, f(m-x \frac{m}{n}) =\frac{n}{m} \int\_0^m dt (-1)^{\lfloor n-t \frac{n}{m}\rfloor}\, f(t)\\
&=&\frac{n}{m} \sum\_{j=1}^{n-1} (-1)^{n-j-1}\, \left\{g\left(\frac{(j+1)m}{n}\right)-g\left(\frac{j m}{n}\right)\right\}\\
&=&\frac{{\rm Mod}(n,2)}{2}+\frac{n}{m} \sum\_{j=1}^{n-1} (-1)^{n-j}\, h\left(\frac{jm}{n}\right)
\end{eqnarray\*}
where we first performed a change of variables $t=m-x m/n$, and then decomposed the integral over intervals $(j\frac{m}{n},(j+1)\frac{m}{n}]$,
over which $\lfloor n-t \frac{n}{m}\rfloor=n-j-1$.


Note that using the 2-periodicity of $h$ we get immediately
$$m \,I(n,m)=(m+2n)\,I(n,m+2n)-n \,{\rm Mod}(n,2).$$
Note also that $h$ is an odd function, so that:
$$m\, I(n,m)+(2n-m)I(n,2n-m)=n\, {\rm Mod}(n,2) .$$


Another consequence of $h(2-x)=-h(x)$ is:
$$I(k n,k(n-s))={\rm Mod}(k,2)\, I(n,n-s)$$
for odd $s$,
and the explicit formula:
$$I(k n,k(n-1))={\rm Mod}(k,2)\, I(n,n-1)=\frac{{\rm Mod}(k,2)}{2}\left( {\rm Mod}(n,2)+(-1)^n \frac{n+1}{3}\right) .$$
Proof: Define $c(n,m,k)=\sum\_{j=k+1}^{k+n-1} (-1)^{n-j}\,h(jm/n)$,
then by the above property of $h$, we have
$$c(n,m,n)+c(n,m,2n)=\sum\_{j=n+1}^{3n-1} (-1)^{n-j}\, h(jm/n)=0$$
by using the $j\to 4n-j$ symmetry, and $h(2m)=0$. We deduce that for $k$ odd:
$$ c(kn,k(n-s),0)=\sum\_{j=1}^{kn-1} (-1)^{n-j}h(j(n-s)/n)=\sum\_{j=1}^{n-1}(-1)^{n-j}h(j(n-s)/n)=c(n,n-s,0)$$
while it vanishes for $k$ even. The above formula follows from $I(n,m)={\rm Mod}(n,2)/2+(n/m)c(n,m,0)$.


Finally, for $s=1$, noting that $\lfloor j(n-1)/n\rfloor]=j-1$ for $1\leq j\leq n-1$, we have:
$$c(n,n-1,0)=\sum\_{j=1}^{n-1}(-1)^{n-j+j-1}\frac{-j(n-j)}{n^2}=(-1)^n\,\frac{n^2-1}{6 n}$$
and the above formula follows.


