# Integrals Involving GCD Function

Recently I got interested in Integrals involving GCD.
I was wondering if I could get more such Integrals,
Here are some examples: $$\int_0^\pi \sin^2(ab x) \cot(ax)\cot(bx)dx=\left(\frac{2\color{red}{\gcd(a,b)}-1}{2}\right)\pi$$ $$\int_0^{\pi/2}\ln{\lvert\sin(mx)\rvert}\cdot \ln{\lvert\sin(nx)\rvert}\, dx=\frac{\pi^3}{24}\frac{\color{red}{\gcd^2(m,n)}}{mn}+\frac{\pi\ln^2(2)}{2}$$ $$\int_{0}^{\pi}\arctan\left(\cot\left(mt\right)\right)\arctan\left(\cot\left(nt\right)\right)dt=\frac{\pi^{3}}{12}\cdot\frac{\color{red}{\gcd^2\left(m,n\right)}}{mn}$$ $$\int_{0}^{1}\lfloor{ax}\rfloor \lfloor{bx}\rfloor dx=\frac{\color{red}{\gcd^2\left(a,b\right)}}{12ab}-\frac{a}{4}-\frac{b}{4}-\frac{b}{12a}-\frac{a}{12b}+\frac{ab}{3}+\frac{1}{4}$$
Here is a Conditional One:
If $$c$$ is not a multiple of $$\gcd(a,b)$$ then, $$\int_{0}^{\pi/2}\cos^{2}\left(ct\right)\ln\left(\left|\sin at\right|\right)\ln\left(\left|\sin bt\right|\right)dt= \frac{\pi^{3}}{48}\frac{\color{red}{\gcd^{2}\left(a,b\right)}}{ab}+\frac{\pi\ln^{2}\left(2\right)}{4}$$
This is not a question per say but I am just curious about more of these Integrals.
You can answer with a new Integral and maybe its solution.
I will also keep adding more such Integrals.

• Just out of curiosity, what happens in the last one when $c$ is a multiple of $gcd$?
– Zima
Aug 30 at 18:18
• @Zima I am actually not sure, I was deriving it in rough and during my derivation I came across the digamma function but that term vanished when $c$ is not a multiple of $\gcd(a, b)$. I think the closed form will be messy without this condition. Aug 30 at 18:20
• Nice question. I was interested in the same thing a few years ago (though I was looking for broader classes of arithmetic functions). I imagine you know this, but most of these results can be found by appealing to the fourier series of the factors of each integrand (though those are of course not the only methods). If you want to generate more, picking functions with simple fourier series might be a way forward. Aug 31 at 2:14
• In case what I'm saying about Fourier series is not something you already knew, would you be interested in a full answer explaining the more general phenomenon? Aug 31 at 2:49
• @C-RAM I have not actually formally or rigorously studied Fourier Series yet maybe will in College, but I use the formulas as is. So yeah would like your insights! Also I was thinking of making this post the go-to collection of Integrals related to GCD so anyone can refer them. Aug 31 at 3:15

UPDATE: I added a second example.

Let $$m$$ and $$n$$ be positive integers.

We can use oO_ƲRF_Oo's approach to your previous question to quickly show that $$\int_{0}^{\pi} \operatorname{Cl}_{2}(m \theta) \operatorname{Cl}_{2} (n \theta) \, \mathrm d \theta = \frac{\pi^{5}}{180} \left( \frac{\gcd(m,n)}{\operatorname{lcm}(m,n)} \right)^{2},$$ where $$\operatorname{Cl}_{2}(\phi)$$ is the Clausen function $$\operatorname{Cl}_{2}(\phi) = - \int_{0}^{\phi} \log \left|2 \sin \left( \frac{x}{2} \right)\right| \, \mathrm dx = \sum_{k=1}^{\infty} \frac{\sin (k \phi)}{k^{2}}.$$

Specifically, we have

\begin{align} \int_{0}^{\pi} \operatorname{Cl}_{2}(m \theta) \operatorname{Cl}_{2} (n \theta) \, \mathrm d \theta &= \int_{0}^{\pi} \sum_{j=1}^{\infty} \frac{\sin(j m \theta)}{j^{2}} \sum_{k=1}^{\infty} \frac{\sin(k n \theta)}{k^{2}} \, \mathrm d\theta \\ &= \sum_{j=1}^{\infty} \sum_{k=1}^{\infty} \frac{1}{j^{2}k^{2}} \int_{0}^{\pi} \sin(j m\theta) \sin(k n \theta) \, \mathrm d \theta \\ &= \frac{\pi}{2}\sum_{j=1}^{\infty} \sum_{k=1}^{\infty} \frac{1}{j^{2}k^{2}} \delta_{jm, kn} \\ &= \frac{\pi}{2} \sum_{p=1}^{\infty} \frac{m^{2} \, n^{2}}{p^{2}\operatorname{lcm}^{2}(m,n) \, p^{2} \operatorname{lcm}^{2}(m,n)} \\ &= \frac{\pi}{2} \frac{\gcd^{2}(m,n)}{\operatorname{lcm}^{2}(m,n)} \sum_{p=1}^{\infty} \frac{1}{p^{4}} \\ &= \frac{\pi}{2} \frac{\gcd^{2}(m,n)}{\operatorname{lcm}^{2}(m,n)} \, \zeta(4) \\ &= \frac{\pi^{5}}{180} \left( \frac{\gcd(m,n)}{\operatorname{lcm}(m,n)} \right)^{2}. \end{align}

Changing the order of the integration and the summations is justified by Fubini's theorem since $$\int_{0}^{\pi} \sum_{j=1}^{\infty} \sum_{k=1}^{\infty} \left|\frac{\sin(jm \theta)\sin(k n \theta)}{j^{2}k^{2}} \right| \, \mathrm d \theta \le \int_{0}^{\pi} \sum_{j=1}^{\infty} \sum_{k=1}^{\infty} \frac{1}{j^{2} k^{2}} \, \mathrm d \theta= \left(\frac{\pi^{2}}{6} \right)^{2} \pi < \infty.$$

And assuming that changing the order of the integration and the summations can be justified, we also have $$\int_{0}^{\pi} \ln \left| \cot \left(\frac{m\theta }{2} \right) \right| \, \ln \left| \cot \left(\frac{n\theta }{2} \right) \right| \, \mathrm d \theta = \frac{\pi^{3}}{4} \frac{\gcd(m,n)}{\operatorname{lcm}(m,n)}$$ if $$m$$ and $$n$$ have the same number of powers of $$2$$ in their prime factorizations. The value of the integral is zero otherwise.

Using the Fourier series $$\sum_{k=0}^{\infty} \frac{\cos \left((2k+1) \theta\right)}{2k+1} = \Re \operatorname{artanh}(e^{i \theta}) = \Re \, \frac{1}{2} \, \ln \left(i \cot \left(\frac{\theta}{2} \right) \right) = \frac{1}{2} \, \ln \left|\cot \left(\frac{\theta}{2} \right) \right| ,$$ we have

\begin{align} \int_{0}^{\pi} \ln \left| \cot \left(\frac{m \theta}{2} \right) \right| \, \ln \left| \cot \left(\frac{n \theta}{2} \right) \right| \, \mathrm d \theta &= 4 \int_{0}^{\pi} \sum_{j=0}^{\infty} \frac{\cos\left((2j+1)m \theta \right)}{2j+1} \sum_{k=0}^{\infty}\frac{\cos\left((2k+1)n \theta\right)}{2k+1} \, \mathrm d \theta \\ &= 2 \pi \sum_{j=0}^{\infty} \sum_{k=0}^{\infty} \frac{1}{(2j+1)(2k+1)} \, \delta_{(2j+1)m, (2k+1)n}. \end{align}

If $$m$$ and $$n$$ have the same number of powers of $$2$$ in their prime factorizations, then $$(2p+1) \operatorname{lcm}(m,n), p=0,1,2, \ldots$$ are the common odd multiples of $$m$$ and $$n$$.

If $$m$$ and $$n$$ don't have the same number of powers of $$2$$ in their prime factorization, then $$m$$ and $$n$$ don't have any odd multiples in common.

See this question for an explanation.

Therefore, if $$m$$ and $$n$$ have the same number of powers of $$2$$ in their prime factorizations, then $$\int_{0}^{\pi} \ln \left| \cot \left(\frac{m \theta}{2} \right) \right| \, \ln \left| \cot \left(\frac{n \theta}{2} \right) \right| \, \mathrm d \theta = 2 \pi \sum_{p=0}^{\infty} \frac{mn}{(2k+1)^{2} \operatorname{lcm}^{2}(m,n)} = \frac{\pi^{3} }{4} \frac{\gcd(m,n)}{\operatorname{lcm}(m,n)}.$$

And if $$m$$ and $$n$$ don't have the same number of powers of $$2$$ in their prime factorizations, then $$\int_{0}^{\pi} \ln \left| \cot \left(\frac{m \theta}{2} \right) \right| \, \ln \left| \cot \left(\frac{n \theta}{2} \right) \right| \, \mathrm d \theta =0.$$

Numerical approximations of the integral for specific values of $$m$$ and $$n$$ using Wolfram Alpha and the midpoint method seem to confirm this is correct.

To make this rigorous, I think you would need to use $$\sum_{k=0}^{\infty} \frac{r^{2k+1} \cos \left((2k+1)\theta \right)}{2k+1} = \Re \operatorname{artanh}(re^{i \theta})$$ and take the limit as $$r \to 1^{-}$$.

• Thank You! This is a nice one. As a side note, do these integrals have have any practical use in calculating GCD? Sep 9 at 15:17
• @BlackEmperor That's a good question. I don't know. Sep 9 at 15:21
• @BlackEmperor Knowledge without application is an intellectual exercise. Sep 9 at 16:30
• And exercising one’s intellect is an important way to develop it. Sep 11 at 22:37
• Wow! The second one is such a nice addition, I love the conditional ones. Sep 12 at 17:06

I have a third example that I'm going to post as an separate answer: namely, $$I(m,n, \phi) = \int_{0}^{\pi} \frac{\sin(m \theta) \sin(n \theta )}{\left(\cosh(\phi) -\cos(m\theta)\right)\left(\cosh(\phi)- \cos(n \theta)\right)} \, \mathrm d \theta = \frac{2 \pi}{\exp \left( \frac{m+n}{\gcd(m,n)} \, \phi \right)-1}.$$

Let $$m$$ and $$n$$ be positive integers, and assume $$\phi >0$$.

Using the series identity $$\sum_{k=0}^{\infty} e^{-k \phi } \sin(k \theta) = \sum_{k=\color{red}{1}}^{\infty} e^{-k \phi } \sin(k \theta) = \frac{1}{2} \frac{\sin(\theta)}{\cosh(\phi) - \cos(\theta)},$$ which can be derived by extracting the imaginary part of the identity $$\sum_{k=0}^{\infty} \left(e^{-\phi} e^{i \theta}\right)^{k} = \frac{1}{1-e^{-\theta}e^{i \theta}},$$ we have

\begin{align} I(m,n, \phi) &= 4\int_{0}^{\pi} \sum_{j=1}^{\infty} e^{- j \phi} \sin(jm \theta) \sum_{k=1}^{\infty} e^{- k \phi } \sin(kn \theta) \, \mathrm d \theta \\ &= 4 \sum_{j=1}^{\infty} \sum_{k=1}^{\infty} e^{-(j+k)\phi} \int_{0}^{\pi} \sin(jm \theta) \sin(kn \theta) \, \mathrm d \theta \\ &= 2 \pi \sum_{j=1}^{\infty} \sum_{k=1}^{\infty} e^{-(j+k)\phi} \, \delta_{jm, kn} \\ &= 2 \pi \sum_{p=1}^{\infty} \exp \left( - \left(\frac{p \operatorname{lcm}(m,n)}{m} + \frac{p \operatorname{lcm}(m,n)}{n} \right) \phi\right) \\ &=2 \pi \sum_{p=1}^{\infty} \exp \left(-p \, \frac{m+n}{\gcd(m,n)} \, \phi \right) \\ &=2 \pi \, \frac{\exp\left(-\frac{m+n}{\gcd(m,n)} \, \phi \right)}{1- \exp\left(-\frac{m+n}{\gcd(m,n)} \, \phi \right)} \\ &= \frac{2 \pi}{\exp \left( \frac{m+n}{\gcd(m,n)} \, \phi\right)-1}. \end{align}

For "large" values of the parameters, Wolfram Alpha sometimes says the value of the integral is zero when it actuality the value is nonzero but very small.

More generally, $$\int_{0}^{\pi} \frac{\sin(m \theta) \sin(n \theta )}{\left(\cosh(\phi) -\cos(m\theta)\right)\left(\cosh(\lambda)- \cos(n \theta)\right)} \, \mathrm d \theta = \frac{2 \pi}{\exp \left( \frac{m \lambda+n \phi}{\gcd(m,n)} \right)-1}$$ for $$\phi, \lambda >0$$.