# What is my mistake in integrating $\int \frac{dx}{6 + \cot x}$?

I have solved this integral but I know there is an error, because when I check with Mathematica I see that the derivative of my answer does not give the original integrand of the problem.

$$\int \frac{dx}{6 + \cot x}$$

Realizamos la sustitución $$t = \tan\left(\frac{x}{2}\right)$$, con lo cual tenemos: $$\cos x = \frac{1 - t^2}{1 + t^2}$$, $$\sin x = \frac{2t}{1+t^2}$$, and $$dx=\frac{2}{t^2+1}dt$$, por lo que tenemos $$\int \frac{dx}{6 + \cot x} =\int \frac{\frac{2}{1+t^2}}{6+\frac{1-t^2}{2t}}dt=\int\frac{4t}{(1+t^2)(-t^2+12t+6)}dt$$ $$=-4\int\frac{t}{(1+t^2)(t^2-12t-6)}dt=-4\int(\frac{At+B}{1+t^2}+\frac{Ct+D}{t^2-12t-6})dt$$

Entonces $$t=(At+B)(t^2-12t-6)+(Ct+D)(1+t^2)=(A+C)t^3+(-12A+B+D)t^2+(-6A-12B+C)t-6B+D$$

Igualando,

$$\begin{cases} A + C = 0 \\ -12 A + B + D = 0 \\ -6 A - 12 B + C = 1 \\ -6 B + D = 0 \end{cases}$$

por lo que

$$\begin{cases} A = -\frac{7}{193} \\ B = -\frac{12}{193} \\ C = \frac{7}{193} \\ D = -\frac{72}{193} \end{cases}$$

Sustituyendo los valores en el integrando,

$$-4\int(\frac{At+B}{1+t^2}+\frac{Ct+D}{t^2-12t-6})dt=-4\int(\frac{\frac{-7t}{193}-\frac{12}{193}}{1+t^2}+\frac{\frac{7}{193}-\frac{72}{193}}{t^2-12t-6})$$

$$=-4\int-\frac{1}{193}(\frac{7t+12}{1+t^2})dt-4\int\frac{1}{193}(\frac{7t-72}{t^2-12t-6})dt$$

$$=\color{green}{\frac{4}{193}}\color{blue}{\int\frac{7t+12}{1+t^2}dt}-\color{green}{\frac{4}{193}}\color{blue}{\int\frac{7t-72}{t^2-12t-6}dt}$$

Ahora trabajamos con las integrales por separado.

$$\color{blue}{\int\frac{7t+12}{1+t^2}dt}=\frac{7}{2}\int\frac{2t}{1+t^2}dt+12\int\frac{1}{1+t^2}dt=\frac{7}{2}\ln(1+t^2)+12\arctan(t)+k_1$$

$$\color{blue}{\int\frac{7t-72}{t^2-12t-6}dt}=\int\frac{7t-72}{t^2-12t+36-42}dt=\int\frac{7t-72}{(t-6)^2-\sqrt{42}^2}dt$$

Cambiando de variable $$\sqrt{42}u=t-6\rightarrow \sqrt{42}du=dt$$,

$$=\int\frac{7t-72}{(t-6)^2-\sqrt{42}^2}dt=\int\frac{[7(\sqrt{42}+6)-72]\sqrt{42}}{(\sqrt{42}u)^2-\sqrt{42}^2}du=\int\frac{(7\sqrt{42}u-30)\sqrt{42}}{\sqrt{42}^2(u^2-1)}du$$

$$=\int\frac{7(42)u}{42(u^2-1)}du-\frac{30\sqrt{42}}{42}\int\frac{1}{u^2-1}du=\frac{7}{2}\int\frac{2u}{u^2-1}du+\frac{30}{\sqrt{42}}\int\frac{1}{1-u^2}du$$

$$=\frac{7}{2}\operatorname{ln}\vert u^2-1 \vert + \frac{30}{\sqrt{42}}\operatorname{arctanh}u+k_2=\frac{7}{2}\operatorname{ln} \vert (\frac{t-6}{\sqrt{42}})^2-1 \vert +\frac{30}{\sqrt{42}}\operatorname{arctanh{}\frac{t-6}{\sqrt{42}}}+k_2$$

$$=\frac{7}{2}\operatorname{ln} \vert t^2-12t-6 \vert +\frac{30}{\sqrt{42}}\operatorname{arctanh\frac{t-6}{\sqrt{42}}}+k_2$$

Volviendo a la integral de arriba:

$$=\color{green}{\frac{4}{193}}(\color{blue}{\frac{7}{2}\ln(1+t^2)+12\arctan(t)+k_1})-\color{green}{\frac{4}{193}}(\color{blue}{\frac{7}{2}\operatorname{ln} \vert t^2-12t-6 \vert +\frac{30}{\sqrt{42}}\operatorname{arctanh\frac{t-6}{\sqrt{42}}}+k_2})$$

Finalmente, como $$t=\tan(\frac{x}{2})$$, nos queda:

$$\int \frac{dx}{6 + \cot x} = \frac{4}{193}[\frac{7}{2}\ln(1 + \tan^2(x/2))+12\arctan(\tan(x/2))] - \frac{4}{193}[\frac{7}{2}\operatorname{ln} \vert \tan^2(x/2)-12\tan(x/2)-6 \vert +\frac{30}{\sqrt{42}}\operatorname{arctanh(\frac{\tan(x/2)-6}{\sqrt{42}}})]+k$$

But

In the first line, after you applied the substitution of $$\tan\frac{x}{2}$$, your integral is wrong, $$\int\frac{4t}{(1+t^2)(-t^2+12t+6)}dt$$ is wrong, $$\int\frac{4t}{(1+t^2)(-t^2+12t+1)}dt$$ is correct

Here's a simple alternate approach (to refer to):

$$I=\int\frac{1}{6+\cot x}\,dx$$

$$I=\int\frac{\tan x}{6\tan x +1}\,dx$$

$$\tan x = t \implies \sec^2 x \,dx=dt$$

$$I=\int\frac{t}{(6t +1)(t^2+1)}\,dt$$

Performing partial fractions;

$$\frac{t}{(6t +1)(t^2+1)}=\frac{a}{6t+1}+\frac{bt+c}{t^2+1}\implies a=\frac{-6}{37}, b=\frac{1}{37}, c=\frac{6}{37}$$

$$I=\frac{1}{37}\left(\int\frac{t+6}{(t^2+1)}\,dt-\int\frac{6}{6t+1}\,dt\right)$$

The above integrals, can be further split and easily evaluated against standard integrals;

This approach gives the following closed form:

$$I=\frac{1}{74}\left[ln\left(\frac{\sec^2 x}{(6\tan x+1)^2}\right)+12x\right]+C$$

Tangent-half-angle substitution is rather clumsy. It is easier to evaluate the integral by splitting $$\sin x=\frac{6}{37}(6 \sin x+\cos x)-\frac{1}{37}(6 \cos x-\sin x)$$ as \begin{aligned} \int \frac{d x}{6+\cot x} & =\int \frac{\sin x}{6 \sin x+\cos x} d x \\ & =\int \frac{\frac{6}{37}(6 \sin x+\cos x)-\frac{1}{37}(6 \cos x-\sin x)}{6 \sin x+\cos x} d x \\ & =\frac{6}{37} x-\frac{1}{37} \int \frac{d(6 \sin x+\cos x)}{6 \sin x+\cos x} \\ & =\frac{6}{37} x-\frac{1}{37} \ln |6 \sin x+\cos x|+C \\ &= \frac{1}{37}\left[\ln \left|\frac{\sec x}{6 \tan x+1}\right|+6 x\right]+C \end{aligned} which matches the answer provided by @whatamidoing.