# Integral of product of two square waves over [0,1]

In Mathematica notation, I am looking for the function f[m,n] for real numbers m and n defined by

f[m_,n_]:=Integrate[SquareWave[m x]SquareWave[n x],{x,0,1}].

I'm trying to get a closed form for the integral for general m and n, but am having trouble, as Mathematica cannot do it.

I found a closed form for f[m,n] for integer m, n:

f[m,n] = Mod[m,2]Mod[n,2]GCD[m,n]^2/(m n).

I am just wondering if there exists a closed formula for f[m,n] for real values of m and n. It seems like a simple problem but I'm not sure how to solve it, or if a closed form even exists. I found the integer m,n result using Fourier series for the square waves, along with properties of the dilogarithm function (which shows up in Mathematica when I compute the needed sums of products of Fourier coefficients).

Naturally, if this has already been answered I will remove it, but was curious if anyone has any input. I feel like I'm attacking the problem using the wrong method (analysis) and that it would be better to use number theory or something like that. Any insights? This is just for fun, so if no one figures it out there's no harm done.

-
Here is a plot of f[m,n] for m in [2.5,3.5] and n in [4.5,5.5], made by numerical evaluation of f[m,n]. The red regions are positive and the blue regions are negative. The resolution is a bit low (should have used more points) but it certainly appears to have some nontrivial behavior. postimage.org/image/dr1octak5 – PJR Nov 26 '12 at 2:19
Here's a higher res pic: postimage.org/image/3qwpq447j – PJR Nov 26 '12 at 2:42