# How to reduce $\int_0^{\pi/2}\frac{\sin x(\sin x+\cos x)}{\sqrt{\sin x\cos x}}\,dx$ to complete elliptic integral?

In a recent answer I showed

$$I = \int_0^\tfrac\pi2 \frac{dx}{\left(\sqrt{\sin x}+\sqrt{\cos x}\right)^2} = \sqrt2 \left[F\left(\frac\pi4,\sqrt2\right) + E\left(\frac\pi4,\sqrt2\right)\right] - 2$$

where $$F(\phi,k)/E(\phi,k)$$ are the incomplete elliptic integrals of first/second kinds, as defined here. For $$\lvert z\rvert<\dfrac\pi2$$, the identities

$$\begin{cases} F(z, \csc z) = \sin z \, K(\sin z) \\ E(z, \csc z) = \csc z \, E(\sin z) - \cos z \cot z \, K(\sin z) \end{cases}$$

where $$E(k)/K(k)$$ are the complete EIs of first/second kinds, allow for the simplification

$$\sqrt2 \left[F\left(\frac\pi4,\sqrt2\right) + E\left(\frac\pi4,\sqrt2\right)\right] = 2 \, E\left(\frac1{\sqrt2}\right)$$

This leads me to believe there is a slightly more direct path to evaluating $$I$$ in terms of $$E(k)$$. Edit: Indeed, the key is to substitute $$\sin x=\dfrac1{\sqrt2}\sin y$$.

On the other hand, retracing only some of the steps of that answer (i.e. rationalization and IBP), we obtain another integral that evaluates to the same complete EI expression.

\begin{align*} I &= \int_0^\tfrac\pi2 \frac{dx}{\sin x + \cos x + 2\sqrt{\sin x\cos x}} \\ &= \int_0^\tfrac\pi2 \frac{\sin x+\cos x - 2\sqrt{\sin x \cos x}}{(\sin x+\cos x)^2 - 4\sin x\cos x} \, dx \\ &= \int_0^\tfrac\pi2 \frac{\sin x+\cos x - 2\sqrt{\sin x \cos x}}{1-2\sin x\cos x} \, dx \\ &= - 2 + \int_0^\tfrac\pi2 \frac{\sin x(\sin x+\cos x)}{\sqrt{\sin x\cos x}} \, dx \end{align*}

so that by some means,

$$J = \int_0^\tfrac\pi2 \frac{\sin x \left(\sin x+\sqrt{1-\sin^2x}\right)}{\sqrt{\sin x \sqrt{1-\sin^2x}}} \, dx \stackrel{?}= 2 \int_0^\tfrac\pi2 \sqrt{1-\frac12\sin^2y} \, dy$$

Q: How can we achieve this, if at all possible?

For the antiderivative, the only way I found to introduce elliptic integrals is the tangent half-angle substitution $$I(x)=\int\frac{\sin (x)(\sin (x)+\cos (x))}{\sqrt{\sin (x)\cos (x)}}\,dx$$

$$I(t)=-2 \sqrt{2} \int \frac{\sqrt{t}\, \left(t^2-2 t-1\right)}{ \,\left(t^2+1\right)^2\, \sqrt{1-t^2}} \,dt$$ Using partial fraction decomposition $$I(t)=-\sqrt 2 \int \Bigg( \frac{(1+i) \sqrt{t}}{(t-i)^2 \sqrt{1-t^2}}+\frac{(1-i) \sqrt{t}}{(t+i)^2 \sqrt{1-t^2}} \Bigg)\,dt$$

Computing (I used a CAS for it)

$$J=\int\frac{\sqrt{t}}{(t+a)^2\,\sqrt{1-t^2} }\,dt$$ $$J=\frac{\sqrt{1-t^2}}{\left(a^2-1\right) \sqrt{t}}\Bigg(-\frac{a}{t+a}+\frac 1a \sqrt{\frac{t}{t^2-1}}\,A(t) \Bigg)$$ where

$$A(t)=\left(a^2+1\right) \Pi \left(-a;\left.u\right|-1\right)+(a-1) F\left(\left.u\right|-1\right)-a E\left(\left.u\right|-1\right)$$ and $$u=\csc ^{-1}\left(\sqrt{t}\right)$$ where appear the complete elliptic integrals of first, second and third kinds.

Simplifying as much as I could $$I(t)=\sqrt{\frac{2}{t}}\,\frac{\sqrt{1-t^2}}{ \left(1-t^4\right)}\,\left((t-1) (t+1)^2 + \sqrt{t \left(t^2-1\right)} \left(t^2+1\right)\,B(t)\right)$$ where $$B(t)= E\left(\left.\csc ^{-1}\left(\sqrt{t}\right)\right|-1\right)-2 F\left(\left.\csc ^{-1}\left(\sqrt{t}\right)\right|-1\right)$$

The problem is that we cannot compute directly $$I(1)$$ and $$I(0)$$ which correspond to indeterminate forms.

But, using series expansion $$I(1)=i \sqrt{2} (E(-1)-2 K(-1))+2 \sqrt{1-t}+O\left((t-1)^{3/2}\right)$$ $$I(0)=(-1+i) \sqrt{2} (-(3-i) K(-1)+(1+i) K(2)+E(-1))+O\left(t^{3/2}\right)$$ Therefore $$L=\int_0^{\frac \pi 2}\frac{\sin (x)(\sin (x)+\cos (x))}{\sqrt{\sin (x)\cos (x)}}\,dx$$ is "just" $$(I(1)-I(0))$$ that is to say $$L=\sqrt{2}\,\, \big(2 K(2)+E(-1)-2(1- i) K(-1)\big)$$

But $$K(2)-(1- i) K(-1)=0 \quad \implies \quad \large\color{blue}{L=\sqrt{2}\,\,E(-1)}$$

which is

$$L=\frac{1}{4 \sqrt{\pi }}\Bigg(\frac {8\pi^2}{\Big(\Gamma \left(\frac{1}{4}\right)\Big)^2 }+ \Bigg(\Gamma \left(\frac{1}{4}\right)\Bigg)^2\Bigg)$$

Mystery solved! The integrand in $$J$$ simplifies to $$\left(\sin x + \cos x\right) \sqrt{\tan x}$$, and we can proceed with evaluating as follows:

\begin{align*} J &= \left\{\int_{-\tfrac\pi4}^0 + \int_0^\tfrac\pi4\right\} \sqrt2\,\cos x \sqrt{\frac{1+\tan x}{1-\tan x}} \, dx \tag1 \\ &= \int_0^\tfrac\pi4 \sqrt2\,\cos x \left(\sqrt{\frac{1+\tan x}{1-\tan x}} + \sqrt{\frac{1-\tan x}{1+\tan x}}\right) \, dx \tag2 \\ &= \int_0^\tfrac\pi4 \frac{2\sqrt2\,\cos^2x}{\sqrt{\cos(2x)}} \, dx \tag3 \\ &= \int_0^\tfrac\pi2 \frac{1+\cos x}{\sqrt{2\cos x}} \, dx \tag3 \\ &= \int_0^\tfrac\pi2 \frac{1+\cos^2y}{\sqrt{2\cos^2y}} \cdot \frac{2 \sin y \cos y}{\sqrt{1-\cos^4y}} \, dy \tag4 \\ &= \sqrt2 \int_0^\tfrac\pi2 \sqrt{1+\cos^2y} \, dy \\ &= 2 \int_0^\tfrac\pi2 \sqrt{1-\frac12\sin^2y} \, dy \end{align*}

$$(1)$$ Substitute $$x\to\dfrac\pi4+x$$ and split the integral at $$x=0$$ to prepare to ...

$$(2)$$ ... substitute $$x\to-x$$ on $$\left(-\dfrac\pi4,0\right]$$.

$$(3)$$ Condense terms with the double angle identity, substituting $$x\to\dfrac x2$$ along the way.

$$(4)$$ Substitute $$\cos x = \cos^2y$$.