Integral of the month: \( \int_{-1}^1\frac{1}{x}\sqrt{\frac{1+x}{1-x}}\log\left(\frac{2 x^2+2x+1}{2x^2-2x+1}\right) dx \)

\(\require{cancel}\) \(\require{boldsymbol}\)

I have been very busy for the last several months and didn’t have time to have fun with integrals, let alone posting to my “integral of the month” series. It is not really “the integral of the month” if I don’t post monthly, is it? To make up for the missing months, we will look into a crazy-ass integral which became famous on the internet. This integral was post on stackexchange and a user, Cleo, posted an answer with no details of her work. Then the wizard of integrals, Ron Gordon, worked out the solution, which matched Cleo’s answer. Today we will follow Ron’s solution and I have to emphasize that he deserves all the credit for the derivation. I am just here to walk you through it and enjoy the sneaky tricks he used.

Getting started

The first thing is to define a new variable

\[\begin{eqnarray} t=\frac{1-x}{1+x} \iff x=\frac{1-t}{1+t} \tag{1}, \end{eqnarray}\] and \[\begin{eqnarray} dt=d\left(\frac{1-x}{1+x}\right) =\frac{-dx(1+x)-dx(1-x)}{(1+x)^2}=-2\frac{dx}{(1+x)^2} \tag{2}. \end{eqnarray}\] Plugging \(x\) from Eq. (1) yields: \[\begin{eqnarray} dt=-2\frac{dx}{(1+x)^2}=-2\frac{dx}{(1+\frac{1-t}{1+t})^2}=-dx\frac{(1+t)^2}{2} \iff dx=-\frac{2}{(1+t)^2}dt \tag{3}. \end{eqnarray}\] The factor in front of the logarithm and the integral measure simplify to: \[\begin{eqnarray} \frac{dx}{x}\sqrt{\frac{1+x}{1-x}}=-\frac{2 dt}{(1+t)^2}\frac{1+t}{1-t}\frac{1}{\sqrt{t}}= \frac{-2 dt}{(1-t^2)\sqrt{t}} \tag{4}. \end{eqnarray}\] The argument of the logarithm becomes: \[\begin{eqnarray} \frac{2 x^2+2x+1}{2x^2-2x+1}=\frac{2 (1-t)^2+2(1-t)(1+t)+(1+t)^2}{2(1-t)^2-2(1-t)(1+t)+(1+t)^2} =\frac{t^2-2t+5}{5t^2-2t+1} \tag{5}. \end{eqnarray}\] Just stare at coefficients of the polynomial in the numerator and denominator in the logarithm. They are flipped with respect to each other. In fact, one can switch form one to the other simply by transforming \(t\to 1/t\). This will become critical later!

The limits of the \(x\) integral, \([-1,1]\), get mapped to \([\infty,0]\). Therefore, the integral looks like this:

\[\begin{eqnarray} I=2\int_0^\infty \frac{dt}{\sqrt{t} (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right) \tag{6}. \end{eqnarray}\]

Inversion symmetry

Let’s split the integral into two domains as \([0,1]\) and \([1,\infty]\): \[\begin{eqnarray} I&=&2\int_0^\infty \frac{dt}{\sqrt{t} (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right)\nonumber\\ &=&2\int_0^1 \frac{dt}{\sqrt{t} (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right)+ 2\int_1^\infty \frac{dt}{\sqrt{t} (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right) \tag{7} \end{eqnarray}\]

We will do an inversion for the second piece by defining \(s=\frac{1}{t}\) \[\begin{eqnarray} I_2&=&2\int_1^\infty \frac{dt}{\sqrt{t} (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right) =-2\int_1^0 \frac{(-ds/s^2)\sqrt{s}}{ (s^2-1)/s^2}\log\left(\frac{s^{-2}-2s^{-1}+5}{5s^{-2}-2s^{-1}+1}\right)\nonumber\\ &=&-2\int_0^1 \frac{ds\sqrt{s}}{ s^2-1}\log\left(\frac{1-2s+5s^2}{5-2s+s^2}\right) =2\int_0^1 \frac{ds\sqrt{s}}{ 1-s^2}\log\left(\frac{5-2s+s^2}{1-2s+5s^2}\right) \tag{8}. \end{eqnarray}\] \(s\) is a dummy integration variable, and we can rename it as \(t\). Now let’s add \(I_2\) back in:

\[\begin{eqnarray} I&=& 2\int_0^1 dt \left(\frac{1}{\sqrt{t}}+\sqrt{t}\right)\frac{1}{ (1-t^2)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right) =2\int_0^1 dt \left(\frac{1+t}{\sqrt{t}}\right)\frac{1}{ 1-t^2}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right)\nonumber\\ &=&2\int_0^1\frac{dt}{ \sqrt{t}(1-t)}\log\left(\frac{t^2-2t+5}{5t^2-2t+1}\right) \tag{9}. \end{eqnarray}\]

More transformations

Let’s first get rid of the pest \(\sqrt{t}\) by defining \(t=u^2\): \[\begin{eqnarray} I&=&4\int_0^1\frac{du}{1-u^2}\log\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right). \tag{10} \end{eqnarray}\] We ten massage the \(\frac{du}{1-u^2}\) term a bit using fractional expansion: \[\begin{eqnarray} \frac{4du}{1-u^2}&=&\frac{4du}{(1-u)(1+u)}=2du\left(\frac{1}{1+u}+\frac{1}{1-u} \right)=2 \left(d \left[\log(1+u)\right]-d \left[\log(1-u)\right] \right)\nonumber\\ &=&2 d \left[\log\left(\frac{1+u}{1-u}\right)\right], \tag{11} \end{eqnarray}\] which basically prepares us for an integration by parts.

\[\begin{eqnarray} I&=&2\int_0^1 d \left[\log\left(\frac{1+u}{1-u}\right)\right]\log\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right)\nonumber\\ &=&2\int_0^1 d \left[\log\left(\frac{1+u}{1-u}\right)\log\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right)\right]-2\int_0^1 \log\left(\frac{1+u}{1-u}\right)d \left[\log\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right)\right] \nonumber\\ &=&\left[\log\left(\frac{1+u}{1-u}\right)\log\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right)\right]_0^1-2\int_0^1du \log\left(\frac{1+u}{1-u}\right)\frac{5u^4-2u^2+1}{u^4-2u^2+5} \frac{d}{du}\left(\frac{u^4-2u^2+5}{5u^4-2u^2+1}\right) \nonumber\\ &=&-2\int_0^1du \log\left(\frac{1+u}{1-u}\right)\frac{5u^4-2u^2+1}{u^4-2u^2+5} \frac{(4u^3-4u)(5u^4-2u^2+1)-(5u^4-2u^2+1)(4u^3-4u)}{(5u^4-2u^2+1)^2} \nonumber\\ &=&-32\int_0^1du \log\left(\frac{1+u}{1-u}\right) \frac{u^5-6u^3+u}{(u^4-2u^2+5)(5u^4-2u^2+1)}. \tag{12} \end{eqnarray}\] Finally, it is more convenient to have a simple variable as th argument of the logarithm. We get that by defining \(u=\frac{v-1}{v+1}\):

\[\begin{eqnarray} I&=&8\int_0^\infty dv \log v \frac{(v^2-1)(v^4-6v^2+1)}{v^8+4v^6+70v^4+4v^2+1}. \tag{13} \end{eqnarray}\] This is practically begging for complex integration with a branch cut!

Complex contour integral

We are going to use a trick that I discussed in one of my earlier posts. When we are dealing with integrand of the form \(\frac{P(x)}{Q(x)}\), we can introduce a \(\log\) multiplier and do the integral over a key-hole contour as in Fig. 1. As I showed in that post, the real parts of the \(\log(z)\) integrals will cancel out as we traverse the contour above (\(C_2\)) and below (\(C_1\)) the real axis.
Key-hole contour to evaluate the integral.

Figure 1: Key-hole contour to evaluate the integral.

Note that our original integral already has a \(\log\) in it, so we will double down on it and consider a \(\log^2\) term. When all said and done, one of the logs will drop out and we will collect the integral with a single log along with the ratio of the polynomials. We will first upgrade the real parameter \(v\) to a complex parameter \(z\) and consider the following closed contour integral:

\[\begin{eqnarray} I_C&=&8\oint_c dz\left(\log z\right)^2 \frac{(z^2-1)(z^4-6z^2+1)}{z^8+4z^6+70z^4+4z^2+1}\equiv\oint_c dz \log^2(z)\frac{P(z)}{Q(z)}, \tag{14} \end{eqnarray}\] where the contour of the integration is shown in Fig. 1. The paths \(C_1\) and \(C_2\) are almost identical except for the fact that they go in the opposite direction and one is above the real line and the other one is below it. They can be parameterized as \(z=v\pm i \delta\), where we will take \(\delta\to 0\) limit. The polynomials behave nicely, so we can set \(\delta=0\) right away for them. But, \(\log\) is tricky and it will have a jump of \(2\pi\) across the branch cut. An easier parameterization is to take \(z=ve^{i\delta}\) on \(C_1\) and \(z=ve^{i(2\pi-\delta)}\) on \(C_2\) such that the angles are defined from \(0\) to \(2\pi\) and we don’t cross the branch cut. This will enable us to evaluate the logs quickly. Let’s take a close look at the integrand, \(\log^2(z)\frac{P(z)}{Q(z)}\), on the paths \(C_1\) and \(C_2\):

\[\begin{eqnarray} \lim_{\delta\to 0; \epsilon \to 0 }\left\{\int_{C_1+C_2}\log^2(z)\frac{P(z)}{Q(z)}\right\}&=&\lim_{\delta\to 0;\epsilon \to 0}\left\{\int_{\epsilon }^\infty dv \left[\log (ve^{i\delta}) \right]^2 \frac{P(ve^{i\delta})}{Q(ve^{i\delta})} +\int^{\epsilon }_\infty \left[\log (ve^{i(2\pi-\delta)}) \right]^2 \frac{P(ve^{i(2\pi-\delta)})}{Q(ve^{i(2\pi-\delta)})} \right\}\nonumber\\ &=&\int_{0}^\infty dv \log^2 v \frac{P(v)}{Q(v)} +\int^{0}_\infty \left(2\pi i+ \log v \right)^2 \frac{P(v)}{Q(v)}\nonumber\\ &=&\int_{0}^\infty dv\frac{P(v)}{Q(v)}\left[\log^2 v +4\pi^2 -4\pi i \log v -\log^2 v \right] \nonumber\\ &=&\int_{0}^\infty dv \frac{P(v)}{Q(v)}\left[4\pi^2 -4\pi i \log v \right] \tag{15}, \end{eqnarray}\] which is awesome! We have shown that the integration on the horizontal paths reduces down to the integral we were looking for; almost! We ended up getting one additional integral with the coefficient \(4\pi^2\). Let’s deal with it! We can see from Eq.(14) that we still have \(z\to1/z\) symmetry in the polynomials and we can exploit that to split the integral in two pieces: \[\begin{eqnarray} \int_{0}^\infty dv \frac{P(v)}{Q(v)} &=&\int_{0}^1 dv \frac{P(v)}{Q(v)} +\int_{1}^\infty dv \frac{P(v)}{Q(v)} \tag{16}. \end{eqnarray}\] We flip the second integral by defining \(v=1/s\) to get: \[\begin{eqnarray} \int_{0}^\infty dv \frac{P(v)}{Q(v)} &=&\int_{0}^1 dv \frac{P(v)}{Q(v)} +\int_{1}^0 (-ds/s^2) \frac{-s^{-6} P(s)}{s^{-8}Q(s)} = \int_{0}^1 dv \frac{P(v)}{Q(v)} -\int_{0}^1 ds\frac{ P(s)}{Q(s)}=0, \tag{17} \end{eqnarray}\] and how cool is that! It simply vanishes! Let’s be rigorous and show that the other pieces of the integrals on \(C_\epsilon\) and \(C_R\) also vanish in the limit \(\epsilon \to 0\) and \(R\to\infty\).

On \(C_\epsilon\), the absolute value of the integrand is smaller than \(log(\epsilon )\), and therefore the integral will be smaller than \(2\pi \epsilon log(\epsilon )\), which converges to \(0\) as \(\epsilon\) goes faster to zero than \(log(\epsilon )\) goes to infinity. If you prefer a bit more rigor, we can do the following: \[\begin{eqnarray} \lim_{\epsilon \to 0 } \epsilon \log(\epsilon)= \lim_{\epsilon \to 0 } \frac{ \log(\epsilon)}{1/\epsilon}= \lim_{\epsilon \to 0 }\frac{\frac{1}{\epsilon}}{-1/\epsilon^2}=0, \tag{18} \end{eqnarray}\] where we used L’Hôpital’s rule.

On \(C_R\), the absolute value of the integrand is smaller than \(log^2(R)/R^2\), and therefore the integral will be smaller than \(2\pi log^2(R)/R\). We can see how it behaves as \(R\to\infty\) as follows: \[\begin{eqnarray} \lim_{R\to\infty}\frac{ \log^2(R)}{R}= 2\lim_{R\to\infty }\frac{\log(R)}{R}=0. \tag{19} \end{eqnarray}\] This shows that

\[\begin{eqnarray} I= \frac{1}{4\pi i}\oint_c dz\left(\log z\right)^2 \frac{8 (z^2-1)(z^4-6z^2+1)}{z^8+4z^6+70z^4+4z^2+1}=\frac{1}{4\pi i} 2\pi i\sum_{k}\text{Residue}(z_k)=\frac{1}{2} \sum_{k}\text{Residue}(z_k), \tag{20} \end{eqnarray}\] where \(z_k\)’s are the poles inside the contour.

Finding the residues

Finding the roots of the denominator and the corresponding residues is no easy task. Let us first explore the symmetries of \(Q(z)=z^8+4z^6+70z^4+4z^2+1\). Note that it is even in the powers of \(z\) and enjoys \(z\to-z\) symmetry, and we might express it as product of two functions: \(Q(z)=q(z)q(-z)\). We can immediately write down the highest and the lowest power terms in \(q(z)\): \(q(z)=z^4+a z^3+bz^2+cz+1\). We can find \(a\) and \(b\) by matching the terms.

\[\begin{eqnarray} Q(z)&=&z^8+4z^6+70z^4+4z^2+1=q(z)q(-z)=(z^4+a z^3+bz^2+cz+1)(z^4-a z^3+bz^2-cz+1)\nonumber\\ &=&z^8+(-a^2+2b)z^6+ (2-2ac+b^2)z^4+(2b -c^2)z^2+1. \tag{21} \end{eqnarray}\] Matching the coefficients, and solving three equations in three unknowns with some help from Mathematica we get:

\[\begin{eqnarray} q(z)=z^4+4z^3+10z^2+4z+1. \tag{22} \end{eqnarray}\]

Now we will attempt to use fractional expansion: \[\begin{eqnarray} \frac{8 (z^2-1)(z^4-6z^2+1)}{z^8+4z^6+70z^4+4z^2+1}=\left[ \frac{A(z)}{q(z)}+\frac{A(-z)}{q(-z)}\right], \tag{23} \end{eqnarray}\] where we assigned \(A(-z)\) as the second coefficient, rather than a new function \(B(z)\), because the whole expression needs to preserve \(z\to-z\) symmetry. We can guess the degree of the \(A(z)\) by observing that \(A(z)q(-z)+A(-z)q(z)\) needs to be at the \(6\) order, however \(A(z)q(-z)\) can have a \(7^{\text {th}}\) degree term which will drop out up on the subtraction. Since \(Q\) is quartic, this leaves \(A\) at the cubic order at most. Let’s try
\[\begin{eqnarray} A(z)=\alpha z^3 + \beta z^2 +\theta z+ \zeta, \tag{24} \end{eqnarray}\] and require \[\begin{eqnarray} 8 (z^2-1)(z^4-6z^2+1)&=&A(z)q(-z)+A(-z)q(z)\nonumber\\ &=&(\alpha z^3 + \beta z^2 +\theta z+ \zeta)(z^4-4z^3+10z^2-4z+1)\nonumber\\ &&+(-\alpha z^3 + \beta z^2 -\theta z+ \zeta)(z^4+4z^3+10z^2+4z+1). \tag{25} \end{eqnarray}\] We can fix \(\zeta\) immediately by tracking the constant terms on the left and on the right: \(-8=2\zeta\implies \zeta= -4.\) And matching \(z^6\) terms results in \(8=-8\alpha+2\beta\). Matching \(z^4\) terms results in \(-56=2\zeta-8\theta+20\beta-8\alpha\). Matching \(z^2\) terms gives: \(-56=2\beta+20\zeta-8\theta\). Solving all of these together we have:

\[\begin{eqnarray} A(z)=- \left(4 z^3 + 12 z^2 +20 z+ 4\right). \tag{26} \end{eqnarray}\] Staring at Eqs. (22) and (26), we realize that we ended up with some remarkable relation: \[\begin{eqnarray} A(z)=- q^{'}(z). \tag{27} \end{eqnarray}\] This allows us to write the whole ratio in a nice and compact way: \[\begin{eqnarray} \frac{8 (z^2-1)(z^4-6z^2+1)}{z^8+4z^6+70z^4+4z^2+1}=-\left[ \frac{q'(z)}{q(z)}+\frac{q'(-z)}{q(-z)}\right], \tag{28} \end{eqnarray}\] with \(q(z)\) defined in Eq. (22). This is more than a gimmick! It will enable us to compute the residues in a very elegant way.

Consider a generic case \(\frac{f(z)}{g(z)}\) for which we want to compute the residues, say, for a first order pole at \(z=z_k\). For analytic function, all we need to do is to look at the around the poles. To this end, we can expand \(g(z)\) around \(z_k\) to get \(g(z)=\cancelto{0}{g(z_k)}+(z-z_k)g'(z_k)+\text{H.O.T. in } (z-z_k)\). And the ratio becomes \(\frac{f(z_k)}{g'(z_k)} \frac{1}{z-z_k}\), which simply integrates to \(2\pi i \frac{f(z_k)}{g'(z_k)}\) if it is the only pole. The beautiful simplification in our case in Eq. (28). is that \(f(z)=g'(z)\), and therefore the contribution of the pole \(z_k\) is simply \(2\pi i\). As for the \(q'(-z)/q(z)\) part, it will be the same except for the sign, which can be shown as follows: \(q'(-z)/q(-z)=\frac{d q(-z)}{dz}/q(-z)=-\frac{d q(-z)}{d(-z)}/q(-z)\), i.e., it picks up a minus sign.

Now it is finally time to compute the location of the poles. We started with an \(8^\text{th}\) order polynomial, which was hopeless. But we split that into two \(4^\text{th}\) order polynomials as in Eq. (22). \(q(z)\) still enjoys \(z\to1/z\) symmetry, and we can say that if there is a pole a \(a\), there should be one at \(1/a\). Furthermore, the other poles should be at the complex conjugate points so that when we expand everything out we get a polynomial with real coefficients. Hence, this is what we conjecture:

\[\begin{eqnarray} q(z)=z^4+4z^3+10z^2+4z+1=(z-a)(z-\frac{1}{a})(z-\bar a)(z-\frac{1}{\bar a}). \tag{29} \end{eqnarray}\] Now, we expand this out and insert \(a=re^{i\theta}\):

\[\begin{eqnarray} (r+\frac{1}{r})\cos\theta=-2,\\ (r^2+\frac{1}{r^2})+4\cos^2\theta=10. \tag{30} \end{eqnarray}\] The solution becomes: \(r=\phi+\sqrt{\phi}\) and \(\cos\theta=1/\phi\), where \(\phi=\frac{1+\sqrt{5}}{2}\) is the golden ratio. Using the relation \(\frac{1}{\phi+\sqrt{\phi}}=\phi-\sqrt{\phi}\), we can list the poles of \(q(z)\) like so:

\[\begin{eqnarray} z_{\pm}=(\phi\pm\sqrt{\phi})e^{i\arctan\sqrt{\phi}}, \text{ and } z_{\bar\pm}=(\phi\pm\sqrt{\phi})e^{-i\arctan\sqrt{\phi}} \tag{31} \end{eqnarray}\] The poles of \(q(-z)\) will simply require a sign change. We can combine all \(8\) poles in a compact notation:

\[\begin{eqnarray} z_{k}=\pm(\phi\pm\sqrt{\phi})e^{\pm i\arctan\sqrt{\phi}}, \tag{32} \end{eqnarray}\] which is shown in Fig. 2.

The poles appear along the $r=\phi +\sqrt{\phi}$ circle (blue), and $r=\phi -\sqrt{\phi}$ circle (red). The green one is the unit circle. The poles of $q(z)$ are shown in orange color and those of $q(-z)$ are shown in purple.

Figure 2: The poles appear along the \(r=\phi +\sqrt{\phi}\) circle (blue), and \(r=\phi -\sqrt{\phi}\) circle (red). The green one is the unit circle. The poles of \(q(z)\) are shown in orange color and those of \(q(-z)\) are shown in purple.

As we have figured out the residues at the poles, we now need to understand \(\log^2z_k\) terms. Using \(z_k=|z_k|e^{i\arg(z_k)}\), we get: \[\begin{eqnarray} \log^2z_k=\left(\log z_k \right)^2=\left(\log |z_k|+i \arg(z_k) \right)^2=\log^2 |z_k|+2 i \log |z_k| \arg(z_k)- ( \arg(z_k))^2. \tag{33} \end{eqnarray}\] \(\log^2 |z_k|\) is the easiest to address because it is a constant across all poles. Remember that the poles, \(z_k\)’s, are at \(a\), \(1/a\), \(\bar a\), and \(1/\bar a\), each of which will have the same \(\log^2 |z_k|\) value. Therefore, as we sum over the residues, which alternate between \(+1\) and \(-1\) due, this constant term will drop out.

Let’s look at \(\log |z_k| \arg(z_k)\) term multiplied by the residues: Consider \(z_0\), which has a residue of \(+1\). Its radius inversion pair, \(z_1\), also has \(+1\) residue, but \(|z_1|=1/|z_0|\) and that causes the \(\log |z_1|=-\log |z_0|\). These two terms cancel each other. We can see the pairwise cancellation for all the remaining poles, therefore \(\log |z_k| \arg(z_k)\) vanish up on summing over all the residues. We are down to single term, we we just need to sum it up and write down our final equation:

\[\begin{eqnarray} I&=& \frac{1}{4\pi i}\oint_c dz\left(\log z\right)^2 \frac{8 (z^2-1)(z^4-6z^2+1)}{z^8+4z^6+70z^4+4z^2+1}=\frac{1}{2} \sum_{k}\text{Residue}(z_k)\nonumber\\ &=&\frac{1}{2}\left[\sum_{k=0}^7\text{Residue}(z_k) ( \arg(z_k))^2=\sum_{k=0}^3 ( \arg(z_k))^2-\sum_{k=4}^7 ( \arg(z_k))^2= 2\left(\arctan\sqrt{\phi}\right)^2 +2\left(2\pi -\arctan\sqrt{\phi}\right)^2\right]\nonumber\\ &=& -2\left(\pi-\arctan\sqrt{\phi}\right)^2 -2\left(\pi +\arctan\sqrt{\phi}\right)^2=2\pi^2-4\pi \arctan \sqrt{\phi} \nonumber\\ &=&4\pi \text{arccot}\sqrt{\phi}, \tag{34} \end{eqnarray}\] which concludes the integration!

Related