<s>[INST] Is it possible to integrate $\int \frac{1} {{\sin x+\sec^2x}}{d}x$ I am a newbie in learning topic of integration.  My friend asked me to find indefinite integral shown below
$$y=\int \frac{1} {{\sin(x)+\sec^2(x)}} \, \mathrm{d}x \tag 1$$
What I tried until now is the substitution
$m=\sin(x)$ and
$$\frac{\textrm{d}m}{\textrm{d}x}=\cos(x)$$
Now, converting equation $(1)$ in terms of $m$ to get
$$y=\int \frac{(1-m^2)^{1/2}} {{1+m(1-m^2)}} \, \mathrm{d}m$$
But, as you can see, it became more complicated than the original equation $(1)$. So, can anybody help me to integrate this integral?
 [/INST] Rewrite the integral as
\begin{align}
I=&\int \frac{1} {{\sin x+\sec^2x}}dx\\
=&\int \frac{\sin^2x-1} {{\sin^3x-\sin x-1}}dx\\
 =&\ \frac1{2a+3}\int \frac1{\sin x -a}+ \frac{2(a+1)\sin x+a(2a+1)} {{\sin^2x+a\sin x+a^{-1}}}\ dx\\
\end{align}
where $a$ satisfies the cubic equation $a^3-a-1=0$, given by
$$a =\sqrt[3]{\frac12+\frac12\sqrt{\frac{23}{27}}}+ \sqrt[3]{\frac12-\frac12\sqrt{\frac{23}{27}}}\approx 1.3247
$$
Then, integrate with the substitution $t=\tan(\frac\pi4-\frac x2)$ to obtain
\begin{align}
I =&\ \frac2{2a+3}\int \frac1{a^3t^2+a^{-4}}-\frac{a^8+a^{-6}\ t^2} {a^{-3}\ t^4-2a^{-5}\ t^2 +a^4}\ dt\\
=& \ \frac2{2a+3}\bigg(
\sqrt{a}\tan^{-1}(a^{7/2}t)
 - \frac{1+a^{21/2}}{2a^2\sqrt{2(a^{11/2}-1)}}\tan^{-1}\frac{at-{a^{9/2}}t^{-1}}{\sqrt{2(a^{11/2}-1)}}\\
&\hspace{3cm}+ \frac{1-a^{21/2}}{2a^2\sqrt{2(a^{11/2}+1)}}\coth^{-1}\frac{at+{a^{9/2}}t^{-1}}{\sqrt{2(a^{11/2}+1)}}\ \bigg)
\end{align}
As an example, the definition integral below evaluates to
$$\int_{-\frac\pi2}^{\frac\pi2} \frac{1} {{\sin x+\sec^2x}}dx
=\frac\pi{2a+3}\bigg(\ \frac{a^{21/2}+1}{a^2\sqrt{2(a^{11/2}-1)}}-\sqrt a \bigg)
$$
</s>