Indefinite Integration

Evaluate $\displaystyle \int \dfrac{dx}{\cos x - \sin x}$ $\;\;\;$ $\left(0 < x < \dfrac{\pi}{4}\right)$


Let $I = \displaystyle \int \dfrac{dx}{\cos x - \sin x}$ $\;\;\; \cdots$ (1)

Put $\tan \left(\dfrac{x}{2}\right) = t$ $\;\;\; \cdots$ (2a)

Then, $\dfrac{1}{2} \sec^2 \left(\dfrac{x}{2}\right) dx = dt$

i.e. $dx = \dfrac{2 \; dt}{\sec^2 \left(\dfrac{x}{2}\right)} = \dfrac{2 \; dt}{1 + \tan^2 \left(\dfrac{x}{2}\right)} = \dfrac{2 \; dt}{1 + t^2}$ $\;\;\; \cdots$ (2b)

Also, $\cos x = \dfrac{1 - \tan^2 \left(\dfrac{x}{2}\right)}{1 + \tan^2 \left(\dfrac{x}{2}\right)} = \dfrac{1 - t^2}{1 + t^2}$ $\;\;\; \cdots$ (2c)

and $\sin x = \dfrac{2 \tan \left(\dfrac{x}{2}\right)}{1 + \tan^2 \left(\dfrac{x}{2}\right)} = \dfrac{2 \; t}{1 + t^2}$ $\;\;\; \cdots$ (2d)

In view of equations (2a), (2b), (2c) and (2d), equation (1) becomes

$\begin{aligned} I & = \int \dfrac{\dfrac{2 \; dt}{1 + t^2}}{\dfrac{1 - t^2}{1 + t^2} - \dfrac{2 \; t}{1 + t^2}} \\\\ & = \int \dfrac{2 \; dt}{1 - t^2 - 2 t} \\\\ & = 2 \int \dfrac{dt}{2 - \left(t^2 + 2 t + 1\right)} \\\\ & = 2 \int \dfrac{dt}{\left(\sqrt{2}\right)^2 - \left(t + 1\right)^2} \\\\ & \left[\text{Note: } \int \dfrac{dx}{a^2 - x^2} = \dfrac{1}{2 a} \log \left|\dfrac{x + a}{x - a}\right| + c \right] \\\\ & = 2 \times \dfrac{1}{2 \sqrt{2}} \log \left|\dfrac{t + 1 + \sqrt{2}}{t - 1 - \sqrt{2}}\right| + c \\\\ & = \dfrac{1}{\sqrt{2}} \log \left|\dfrac{\tan \left(\dfrac{x}{2}\right) + 1 + \sqrt{2}}{\tan \left(\dfrac{x}{2}\right) - 1 - \sqrt{2} }\right| + c \;\;\; \left[\text{From equation (2a)}\right] \end{aligned}$