TITLE: The integral of $\mathrm{e}^{-\frac{1}{\sin^2 x}}$
QUESTION [6 upvotes]: I have tried playing around an integral
$$
\int \mathrm{e}^{-\frac{1}{\sin^2 x}} \,\mathrm{d}x
.
$$
I know this integral does not have a closed form (Wolfram Alpha and many more resources!), but I appreciate an approximation that holds as close as possible to this integral. The Taylor series is not accurate. It can be assumed that the bounds of the integral are $0$ and $x$, where $0<x<\frac{\pi}{2}$.
Appendix
Thanks to the @robjohn's useful answer, I have simulated his three approaches (in the original order presented) for $0<x<\frac{\pi}{2}$ in the following figure:

The blue solid line denotes the integral which should be approximated and the other curves are three closed forms for that. Unfortunately, there is a bad divergence between the approximations and the integral after about $x=0.9$.

REPLY [9 votes]: A First Approach
Since
$$
\frac1{\sin^2(t)}=\frac1{t^2}+\frac13+O\!\left(t^2\right)\tag1
$$
we have
$$
\begin{align}
\int_0^xe^{{}-\csc^2(t)}\,\mathrm{d}t
&=e^{-1/3+O(x^2)}\int_0^xe^{-1/t^2}\,\mathrm{d}t\tag{2a}\\
&=e^{-1/3+O(x^2)}\int_{1/x}^\infty\frac{e^{-t^2}}{t^2}\,\mathrm{d}t\tag{2b}\\
&=\frac12e^{-1/3+O(x^2)}\int_{1/x^2}^\infty\frac{e^{-t}}{t^{3/2}}\,\mathrm{d}t\tag{2c}\\
&=\frac12e^{-1/3+O(x^2)}\left(x^3+O\!\left(x^5\right)\right)e^{-1/x^2}\tag{2d}\\
&=\frac12e^{-1/3}x^3e^{-1/x^2}\left(1+O\!\left(x^2\right)\right)\tag{2e}
\end{align}
$$
Explanation:
$\text{(2a)}$: apply $(1)$
$\text{(2b)}$: substitute $t\mapsto1/t$
$\text{(2c)}$: substitute $t\mapsto t^{1/2}$
$\text{(2d)}$: integrate by parts
$\text{(2e)}$: collect the error terms

Verification of Fit

This shows that the error seems to be within a factor of $1+O\!\left(x^2\right)$.

A Better Approach
$$\newcommand{\arccsc}{\operatorname{arccsc}}
\begin{align}
&\int_0^xe^{{}-\csc^2(t)}\,\mathrm{d}t\tag{3a}\\
&=\int_0^{\sin(x)}e^{-1/t^2}\,\mathrm{d}\arcsin(t)\tag{3b}\\
&=\int_0^{\sin(x)}e^{-1/t^2}\left(1+\frac{t^2}2+\frac{3t^4}8+\frac{5t^6}{16}+O\!\left(t^8\right)\right)\mathrm{d}t\tag{3c}\\
&=\int_{\csc^2(x)}^\infty e^{-t}\left(\frac{t^{-\frac32}}2+\frac{t^{-\frac52}}4+\frac{3t^{-\frac72}}{16}+\frac{5t^{-\frac92}}{32}+O\!\left(t^{-\frac{11}2}\right)\right)\mathrm{d}t\tag{3d}\\
&=\left.e^{-t}\left(-\frac{t^{-\frac32}}2+\frac{t^{-\frac52}}2-\frac{23t^{-\frac72}}{16}+\frac{39t^{-\frac92}}8+O\!\left(t^{-\frac{11}2}\right)\right)\right|_{\csc^2(x)}^\infty\tag{3e}\\
&=e^{{}-\csc^2(x)}\left(\frac{\sin^3(x)}2-\frac{\sin^5(x)}2+\frac{23\sin^7(x)}{16}-\frac{39\sin^9(x)}8+O\!\left(x^{11}\right)\right)\tag{3f}
\end{align}
$$
Explanation:
$\text{(3b)}$: substitute $t\mapsto\arcsin(t)$
$\text{(3c)}$: use the Taylor Series for $\arcsin(t)$
$\text{(3d)}$: substitute $t\mapsto t^{-\frac12}$
$\text{(3e)}$: integrate by parts repeatedly
$\text{(3f)}$: evaluate
Instead of a relative error of $1+O\!\left(x^2\right)$ this formula has a relative error of $1+O\!\left(x^8\right)$.

Extending the Formula
We can easily extend $(3)$ to higher order. The formula with the next few terms is
$$
\begin{align}
e^{{}-\csc^2(x)}&\left(\frac{\sin^3(x)}2-\frac{\sin^5(x)}2+\frac{23\sin^7(x)}{16}-\frac{39\sin^9(x)}8\right.\\
&\left.+\frac{5651\sin^{11}(x)}{256}-\frac{31049\sin^{13}(x)}{256}+\frac{1614779\sin^{15}(x)}{2048}+O\!\left(x^{17}\right)\right)\tag4
\end{align}
$$
which has a relative error of $1+O\!\left(x^{14}\right)$.

Starting at the Other End
Since $e^{{}-\csc^2(x)}$ is not analytic at $x=0$, the expansion above is asymptotic and does not converge; it is not good for $x$ far from $x=0$. To compute the integral near $x=\frac\pi2$, we first compute the integral over the entire interval $\left[0,\frac\pi2\right]$:
$$\newcommand{\erfc}{\operatorname{erfc}}
\begin{align}
\int_0^{\pi/2}e^{{}-\csc^2(x)}\,\mathrm{d}x
&=\int_0^{\pi/2}e^{{}-\sec^2(x)}\,\mathrm{d}x\tag{5a}\\
&=\int_0^\infty e^{-1-x^2}\frac{\mathrm{d}x}{1+x^2}\tag{5b}\\
&=\int_0^\infty\int_0^\infty e^{-t(1+x^2)}e^{-1-x^2}\,\mathrm{d}t\,\mathrm{d}x\tag{5c}\\
&=\frac{\sqrt\pi}2\int_0^\infty\frac{e^{-1-t}}{\sqrt{1+t}}\,\mathrm{d}t\tag{5d}\\
&=\sqrt\pi\int_1^\infty e^{-t^2}\,\mathrm{d}t\tag{5e}\\[3pt]
&=\frac\pi2\erfc(1)\tag{5f}
\end{align}
$$
Explanation:
$\text{(5a)}$: substitute $x\mapsto\frac\pi2-x$
$\text{(5b)}$: substitute $x\mapsto\arctan(x)$
$\text{(5c)}$: $\int_0^\infty e^{-t(1+x^2)}\,\mathrm{d}t=\frac1{1+x^2}$
$\text{(5d)}$: integrate in $x$
$\text{(5e)}$: substitute $t\mapsto t^2-1$
$\text{(5f)}$: $\int_a^\infty e^{-t^2}\,\mathrm{d}t=\frac{\sqrt\pi}2\erfc(a)$
We will also use the following integral, which can be evaluated by repeated integration by parts
$$
\begin{align}
\int_0^{\tan^2(x)}e^{-t}t^{k-1/2}\,\mathrm{d}t
&=e^{{}-\tan^2(x)}\frac{\tan^{2k+1}(x)}{k+1/2}+\frac1{k+1/2}\int_0^{\tan^2(x)}e^{-t}t^{k+1/2}\,\mathrm{d}t\tag{6a}\\
&=e^{{}-\tan^2(x)}\frac{(2k)!}{4^kk!}\sum_{j=k}^\infty\frac{4^{j+1}(j+1)!}{(2j+2)!}\tan^{2j+1}(x)\tag{6b}
\end{align}
$$
Thus, we get
$$\newcommand{\erfc}{\operatorname{erfc}}
\begin{align}
\int_0^xe^{{}-\sec^2(t)}\,\mathrm{d}t
&=\int_0^{\tan(x)}e^{-1-t^2}\frac{\mathrm{d}t}{1+t^2}\tag{7a}\\
&=\frac12\int_0^{\tan^2(x)}e^{-1-t}\sum_{k=0}^\infty(-1)^kt^{k-1/2}\mathrm{d}t\tag{7b}\\
&=\sum_{k=0}^\infty\frac{(-1)^k}2\int_0^{\tan^2(x)}e^{-1-t}t^{k-1/2}\mathrm{d}t\tag{7c}\\
&=\frac{e^{{}-\sec^2(x)}}{2}\sum_{k=0}^\infty(-1)^k\frac{(2k)!}{4^kk!}\sum_{j=k}^\infty\frac{4^{j+1}(j+1)!}{(2j+2)!}\tan^{2j+1}(x)\tag{7d}\\
&=\frac{e^{{}-\sec^2(x)}}{2}\sum_{j=0}^\infty\sum_{k=0}^j(-1)^k\frac{(2k)!}{4^kk!}\frac{4^{j+1}(j+1)!}{(2j+2)!}\tan^{2j+1}(x)\tag{7e}\\
&=e^{{}-\sec^2(x)}\left(\tan(x)+\frac13\tan^3(x)+\frac13\tan^5(x)-\frac1{21}\tan^7(x)\right.\\
&\phantom{=e^{{}-\sec^2(x)}}\left.+\frac{19}{189}\tan^9(x)-\frac{151}{2079}\tan^{11}(x)+O\!\left(x^{13}\right)\right)\tag{7f}
\end{align}
$$
Explanation:
$\text{(7a)}$: substitute $t\mapsto\arctan(t)$
$\text{(7b)}$: substitute $t\mapsto t^{1/2}$ and expand $\frac{t^{-1/2}}{1+t}$
$\text{(7c)}$: exchange order of summation and integration
$\text{(7d)}$: apply $(6)$
$\text{(7e)}$: change the order of summation
$\text{(7f)}$: generate the coefficients

Putting the Two Ends Together
Since the formula in $(3)$ is designed to be very accurate near $x=0$, and the extra terms do not behave well for larger $x$, we will only use the first term for $x\in\left[0,\frac\pi4\right]$, which actually matches better than the formula in $(2)$.
For $x\in\left[\frac\pi4,\frac\pi2\right]$, we will use $(5)$ and $(7)$.
$$
f(x)=\left\{\begin{array}{}
e^{{}-\csc^2(x)}\frac{\sin^3(x)}2&\text{if }x\in\left[0,\frac\pi4\right]\\
\frac\pi2\erfc(1)-e^{{}-\csc^2(x)}p(\cot(x))&\text{if }x\in\left[\frac\pi4,\frac\pi2\right]
\end{array}\right.\tag{8a}
$$
where
$$
p(x)=x+\frac13x^3+\frac13x^5-\frac1{21}x^7+\frac{19}{189}x^9-\frac{151}{2079}x^{11}\tag{8b}
$$