# Seeking methods to solve $\int_{0}^{\frac{\pi}{2}} \ln\left|2 + \tan^2(x) \right| \:dx$

As part of going through a set of definite integrals that are solvable using the Feynman Trick, I am now solving the following:

$$\int_{0}^{\frac{\pi}{2}} \ln\left|2 + \tan^2(x) \right| \:dx$$

I'm seeking methods using the Feynman Trick (or any method for that matter) that can be used to solve this definite integral.

If one wishes to use "Feynman's Trick," then begin by defining a function $$I(a)$$, $$a>1$$ as given by

$$I(a)=\int_0^{\pi/2}\log(a+\tan^2(x))\,dx \tag1$$

Differentiation of $$(1)$$ reveals

\begin{align} I'(a)&=\int_0^{\pi/2} \frac{1}{a+\tan^2(x)}\,dx\\\\ &=\frac{\pi/2}{a-1}-\frac{\pi/2}{\sqrt a (a-1)}\tag2 \end{align}

Integration of $$(2)$$ yields

\begin{align} I(a)&=\frac\pi2\left(\log(a-1)+\log\left(\frac{\sqrt a+1}{\sqrt{a}-1}\right) \right)\\\\ &=\pi \log(\sqrt a+1)\tag3 \end{align}

Finally, setting $$a=2$$ in $$(3)$$, we obtain the coveted result

$$\int_0^{\pi/2}\log(2+\tan^2(x))\,dx=\pi \log(\sqrt 2+1)$$

• How did you resolve the constant of Integration in Step (3)?
– user150203
Commented Nov 21, 2018 at 4:38
• @davidg Apology for the sign error. Note $I(0)=0$. Commented Nov 21, 2018 at 5:08
• Hi Mark ! Long time no speak. Nice solution $\to +1$. Cheers. Commented Nov 21, 2018 at 6:22
• @MarkViola do you know of any other ‘tricks that would work?
– user150203
Commented Nov 21, 2018 at 6:51
• Hi David. You could try writing the logarithm as $\log(1+\cos^2(x))-\log(\sin^2(x))$ and expanding the first term as $\sum_{n=1}^\infty \frac{(-1)^{n-1}\cos^{2n}(x)}{n}$ and proceeding. I haven't tried this, but it might be worth pursuing. Commented Nov 21, 2018 at 15:47

My approach

Let

\begin{align} \int_{0}^{\frac{\pi}{2}} \ln\left|2 + \tan^2(x) \right| \:dx &= \int_{0}^{\frac{\pi}{2}} \ln\left|1 + \left(1 + \tan^2(x)\right) \right| \:dx \\ &= \int_{0}^{\frac{\pi}{2}} \ln\left|1 + \sec^2(x) \right| \:dx \\ &= \int_{0}^{\frac{\pi}{2}} \ln\left|\frac{\cos^2(x) + 1}{\cos^2(x)} \right| \:dx \\ &= \int_{0}^{\frac{\pi}{2}} \left[ \ln\left|\cos^2(x) + 1 \right| - \ln\left|\cos^2(x)\right| \right]\:dx \\ &= \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + 1 \right|\:dx - \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x)\right|\:dx \end{align}

Now

$$\int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x)\right|\:dx = 2\int_{0}^{\frac{\pi}{2}} \ln\left|\cos(x)\right|\:dx = 2\cdot-\frac{\pi}{2}\ln(2) = -\pi \ln(2)$$

For detail on this definite integral, see guidance here

We now need to solve

$$\int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + 1 \right|\:dx$$

Here, Let

$$I(t) = \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + t \right|\:dx$$

Thus,

$$\frac{dI}{dt} = \int_{0}^{\frac{\pi}{2}} \frac{1}{\cos^2(x) + t}\:dx = \int_{0}^{\frac{\pi}{2}} \frac{1}{\frac{\cos(2x) + 1}{2} + t}\:dx = 2\int_{0}^{\frac{\pi}{2}} \frac{1}{\cos(2x) + 2t + 1}\:dx$$

Employ a change of variable $$u = 2x$$:

$$\frac{dI}{dt} = \int_{0}^{\pi} \frac{1}{\cos(u) + 2t + 1}\:du$$

Employ the Weierstrass substitution $$\omega = \tan\left(\frac{u}{2} \right)$$:

\begin{align} \frac{dI}{dt} &= \int_{0}^{\infty} \frac{1}{\frac{1 - \omega^2}{1 + \omega^2} + 2t + 1}\:\frac{2}{1 + \omega^2}\cdot d\omega \\ &= \int_{0}^{\infty} \frac{1}{t\omega^2 + t + 1} \:d\omega \\ &= \frac{1}{t}\int_{0}^{\infty} \frac{1}{\omega^2 + \frac{t + 1}{t}} \:d\omega \\ &= \frac{1}{t}\left[\frac{1}{\sqrt{\frac{t+1}{t}}}\arctan\left( \frac{\omega}{\sqrt{\frac{t+1}{t}}}\right)\right]_{0}^{\infty} \\ &= \frac{1}{t}\frac{1}{\sqrt{\frac{t+1}{t}}}\frac{\pi}{2} \\ &= \frac{1}{\sqrt{t}\sqrt{t + 1}}\frac{\pi}{2} \end{align}

And so,

$$I(t) = \int \frac{1}{\sqrt{t}\sqrt{t + 1}}\frac{\pi}{2}\:dt = \pi\ln\left| \sqrt{t} + \sqrt{t + 1}\right| + C$$

Now

$$I(0) = \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + 0 \right|\:dx = -\pi \ln(2) = \pi\ln\left|\sqrt{0} + \sqrt{0 + 1} \right| + C \rightarrow C = -\pi \ln(2)$$

And so,

$$I(t) = \pi\ln\left| \sqrt{t} + \sqrt{t + 1}\right| -\pi \ln(2) = \pi\ln\left|\frac{\sqrt{t} + \sqrt{t + 1}}{2} \right|$$

Thus,

$$I = I(1) = \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + 1 \right|\:dx = \pi\ln\left|\frac{\sqrt{1} + \sqrt{1 + 1}}{2} \right| = \pi\ln\left|\frac{1 + \sqrt{2}}{2} \right|$$

And Finally

\begin{align} \int_{0}^{\frac{\pi}{2}} \ln\left|2 + \tan^2(x) \right| \:dx &= \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x) + 1 \right|\:dx - \int_{0}^{\frac{\pi}{2}} \ln\left|\cos^2(x)\right|\:dx \\ &= \pi\ln\left|\frac{1 + \sqrt{2}}{2} \right| - \left(-\pi \ln(2)\right) \\ &= \pi\ln\left|1 + \sqrt{2} \right| \end{align}

• Your question and your answer have a gap of just 1 minute. If you did solve the question earlier then you must've included your approach in the question itself. What is the need to post it as an answer? Commented Nov 21, 2018 at 3:56
• @Digamma - Sorry, although I've been a member of Math StackExchange for 4 years, I've only become regularly active recently. When I asked a friend who is a member as to what is the best way of presenting a solution whilst asking for other solutions I was told this is the approach taken within the community. If this violate any of the rules, please advise and I will reposition accordingly. Also, I never assign my solution as 'the solution' to any post of this nature.
– user150203
Commented Nov 21, 2018 at 4:00
• @Digamma The site encourages people to share the questions with answers. Commented Nov 21, 2018 at 4:03
• @Tianlalu - Sorry, just to be clear - Have I employed the correct process here?
– user150203
Commented Nov 21, 2018 at 4:10
• Thanks @mick - much appreciated :-)
– user150203
Commented Dec 3, 2018 at 3:42

\begin{aligned} \int_{0}^{\frac{k}{2}} \ln \left(2+\tan ^{2} x\right) d x=& \underbrace{\int_{0}^{\frac{\pi}{2}} \ln \left(2 \cos ^{2} x+\sin ^{2} x\right) d x }_{\pi \ln \left(\frac{\sqrt{2}+1}{2}\right)} -2 \underbrace{\int_{0}^{\frac{\pi}{2}} \ln (\cos x) d x}_{-\frac{\pi}{2} \ln 2}\\=& \pi \ln (\sqrt{2}+1) \end{aligned} please refer this for the first integral.

\begin{aligned} &\int_{0}^{\frac{\pi}{2}} \ln \left(2+\tan ^{2} x\right) d x\\ =&\ \int_{0}^{\frac{\pi}{2}} \int_0^1 \frac{\sec ^{2} x}{1+t \sec ^{2}x} dt\ dx =\int_0^1\frac{\frac\pi2}{\sqrt{t(1+t)}}dt = \pi \ln (\sqrt{2}+1) \end{aligned}