Evaluate $\displaystyle \int \limits_{0}^{\frac{\pi}{4}} \dfrac{\sin^2 x}{1 + \sin x \cos x} \; dx$
Let $I = \displaystyle \int \limits_{0}^{\frac{\pi}{4}} \dfrac{\sin^2 x}{1 + \sin x \cos x} \; dx$ $\;\;\; \cdots \; (1)$
Now, $\tan x = \dfrac{\sin x}{\cos x}$ $\implies$ $\sin x = \tan x \cos x$ $\implies$ $\sin x = \dfrac{\tan x}{\sec x}$ $\;\;\; \cdots \; (2a)$
and $\cos x = \dfrac{1}{\sec x}$ $\;\;\; \cdots \; (2b)$
$\therefore$ $\;$ In view of equations $(2a)$ and $(2b)$, equation $(1)$ becomes
$\begin{aligned}
I & = \int \limits_{0}^{\frac{\pi}{4}} \dfrac{\tan^2 x / sec^2 x}{1 + \dfrac{\tan x}{\sec x} \times \dfrac{1}{\sec x}} \; dx \\\\
& = \int \limits_{0}^{\frac{\pi}{4}} \dfrac{\tan^2 x}{\sec^2 x + \tan x} \; dx \\\\
& = \int \limits_{0}^{\frac{\pi}{4}} \dfrac{\tan^2 x}{1 + \tan^2 x + \tan x} \; dx \;\;\; \cdots \; (3)
\end{aligned}$
Let $\tan x = u$ $\;\;\; \cdots \; (4)$
Differentiating equation $(4)$ gives
$\sec^2 x \; dx = du$
$\implies$ $dx = \dfrac{du}{\sec^2 x} = \dfrac{du}{1 + \tan^2 x} = \dfrac{du}{1 + u^2}$ $\;\;\; \cdots \; (4a)$
$\text{When } \begin{cases}
x = 0, & u = \tan \left(0\right) = 0 \\
x = \dfrac{\pi}{4}, & u = \tan \left(\dfrac{\pi}{4}\right) = 1
\end{cases}$ $\;\;\; \cdots \; (4b)$
$\therefore$ $\;$ In view of equations $(4)$, $(4a)$ and $(4b)$, equation $(3)$ becomes
$I = \displaystyle \int \limits_{0}^{1} \dfrac{u^2 \; du}{\left(1 + u + u^2\right) \left(1 + u^2\right)}$ $\;\;\; \cdots \; (5)$
Let $\dfrac{u^2}{\left(1 + u^2\right) \left(1 + u + u^2\right)} = \dfrac{Au + B}{1 + u^2} + \dfrac{Cu + D}{1 + u + u^2}$ $\;\;\; \cdots \; (6)$
i.e. $u^2 = \left(A u + B\right) \left(1 + u + u^2\right) + \left(C u + D\right) \left(1 + u^2\right)$
i.e. $u^2 = Au + Au^2 + Au^3 + B + Bu + Bu^2 + Cu + Cu^3 + D + Du^2$
i.e. $u^2 = u^3 \left(A + C\right) + u^2 \left(A + B + D\right) + u \left(A + B + D\right) + \left(B + D\right)$
Comparing the coefficient of $u^3$ term gives
$A + C = 0$ $\;\;\; \cdots \; (6a)$
Comparing the coefficient of $u^2$ term gives
$A + B + D = 1$ $\;\;\; \cdots \; (6b)$
Comparing the coefficient of $u$ term gives
$A + B + C = 0$ $\;\;\; \cdots \; (6c)$
Comparing the constant term gives
$B + D = 0$ $\;\;\; \cdots \; (6d)$
We have from equations $(6b)$ and $(6d)$, $A = 1$
Substituting the value of A in equation $(6a)$ gives $C = - A = -1$
Substituting the values of A and C in equation $(6c)$ gives $1 + B - 1 = 0$ $\implies$ $B = 0$
Substituting the value of B in equation $(6d)$ gives $D = 0$
$\therefore$ $\;$ Substituting the values of A, B, C and D, equation $(6)$ we have,
$\dfrac{u^2}{\left(1 + u^2\right) \left(1 + u + u^2\right)} = \dfrac{u}{1 + u^2} - \dfrac{u}{1 + u + u^2}$ $\;\;\; \cdots \; (7)$
$\therefore$ $\;$ In view of equation $(7)$ equation $(5)$ can be written as
$\begin{aligned}
I & = \int \limits_{0}^{1} \dfrac{u \; du}{u^2 + 1} - \int \limits_{0}^{1} \dfrac{u \; du}{u^2 + u + 1} \\\\
& = I_1 - I_2 \;\;\; \cdots \; (8)
\end{aligned}$
Consider $I_1 = \displaystyle \int \limits_{0}^{1} \dfrac{u \; du}{u^2 + 1}$ $\;\;\; \cdots \; (9)$
Let $u^2 + 1 = t$ $\;\;\; \cdots \; (10)$
Differentiating equation $(10)$ gives
$2 u \; du = dt$ $\implies$ $u \; du = \dfrac{dt}{2}$ $\;\;\; \cdots \; (10a)$
$\text{When } \begin{cases}
u = 0, & t = 1 \\
u = 1, & t = 2
\end{cases}$ $\;\;\; \cdots \; (10b)$
$\therefore$ $\;$ In view of equations $(10)$, $(10a)$ and $(10b)$, equation $(9)$ becomes
$\begin{aligned}
I_1 & = \dfrac{1}{2} \int \limits_{1}^{2} \dfrac{dt}{t} \\\\
& = \dfrac{1}{2} \left[\log \left|t\right|\right]_{1}^{2} \\\\
& = \dfrac{1}{2} \left[\log \left(2\right) - \log \left(1\right)\right] \\\\
& = \dfrac{1}{2} \log \left(2\right) \;\;\; \cdots \; (11)
\end{aligned}$
$\begin{aligned}
\text{Consider } I_2 & = \int \limits_{0}^{1} \dfrac{u \; du}{u^2 + u + 1} \\\\
& = \dfrac{1}{2} \int \limits_{0}^{1} \dfrac{2 u \; du}{u^2 + u + 1} \\\\
& = \dfrac{1}{2} \left[\int \limits_{0}^{1} \dfrac{2u + 1}{u^2 + u + 1} \; du - \int \limits_{0}^{1} \dfrac{du}{u^2 + u + 1}\right] \;\;\; \cdots \; (12)
\end{aligned}$
Consider $I_3 = \displaystyle \int \limits_{0}^{1} \dfrac{2u + 1}{u^2 + u + 1} \; du$ $\;\;\; \cdots \; (13)$
Let $u^2 + u + 1 = m$ $\;\;\; \cdots \; (14)$
Differentiating equation $(14)$ gives
$\left(2u + 1\right) \; du = dm$ $\;\;\; \cdots \; (14a)$
$\text{When } \begin{cases}
u = 0, & m = 1 \\
u = 1, & m = 3
\end{cases}$ $\;\;\; \cdots \; (14b)$
$\therefore$ $\;$ In view of equations $(14)$, $(14a)$ and $(14b)$, equation $(13)$ becomes
$\begin{aligned}
I_3 & = \int \limits_{1}^{3} \dfrac{dm}{m} \\\\
& = \left[\log \left|m\right|\right]_{1}^{3} \\\\
& = \log \left(3\right) - \log \left(1\right) \\\\
& = \log \left(3\right) \;\;\; \cdots \; (15)
\end{aligned}$
$\begin{aligned}
\text{Consider } I_4 & = \int \limits_{0}^{1} \dfrac{du}{u^2 + u + 1} \\\\
& = \int \limits_{0}^{1} \dfrac{du}{\left(u^2 + u + \dfrac{1}{4}\right) + 1 - \dfrac{1}{4}} \\\\
& = \int \limits_{0}^{1} \dfrac{du}{\left(u + \dfrac{1}{2}\right)^2 + \left(\dfrac{\sqrt{3}}{2}\right)^2} \\\\
& = \dfrac{2}{\sqrt{3}} \left[\tan^{-1} \left(\dfrac{u + \dfrac{1}{2}}{\dfrac{\sqrt{3}}{2}}\right)\right]_{0}^{1} \\\\
& \hspace{3em} \left[\text{Note: } \int \limits_{p}^{q} \dfrac{dx}{x^2 + a^2} = \dfrac{1}{a} \left[\tan^{-1} \left(\dfrac{x}{a}\right)\right]_{p}^{q}\right] \\\\
& = \dfrac{2}{\sqrt{3}} \left[\tan^{-1} \left(\dfrac{2u + 1}{\sqrt{3}}\right)\right]_{0}^{1} \\\\
& = \dfrac{2}{\sqrt{3}} \left[\tan^{-1} \left(\dfrac{3}{\sqrt{3}}\right) - \tan^{-1} \left(\dfrac{1}{\sqrt{3}}\right)\right]_{0}^{1} \\\\
& = \dfrac{2}{\sqrt{3}} \left[\dfrac{\pi}{3} - \dfrac{\pi}{6}\right] \\\\
& = \dfrac{2}{\sqrt{3}} \times \dfrac{\pi}{6} = \dfrac{\pi}{3 \sqrt{3}} \;\;\; \cdots \; (16)
\end{aligned}$
$\therefore$ $\;$ In view of equations $(15)$ and $(16)$, equation $(12)$ becomes
$I_2 = \dfrac{1}{2} \left[\log \left(3\right) - \dfrac{\pi}{3 \sqrt{3}}\right] = \dfrac{1}{2} \log \left(3\right) - \dfrac{\pi}{6 \sqrt{3}}$ $\;\;\; \cdots \; (17)$
$\therefore$ $\;$ In view of equations $(11)$ and $(17)$, equation $(8)$ becomes
$\begin{aligned}
I & = \dfrac{1}{2} \log \left(2\right) - \dfrac{1}{2} \log \left(3\right) + \dfrac{\pi}{6 \sqrt{3}} \\\\
& = \dfrac{\pi}{6 \sqrt{3}} - \dfrac{1}{2} \log \left(\dfrac{3}{2}\right)
\end{aligned}$