# Integrate $$\int \mathrm{e}^{-\sqrt{x}}\sin(x) \mathrm{d}x$$

How to evaluate this integral was a question on Mathematics Stack Exchange.

First, we use the exponential form of the sine function, then let $$x=z^{2}$$

\int \mathrm{e}^{-\sqrt{x}}\sin(x) \mathrm{d}x = i \int \left(z\,\mathrm{exp}(-iz^{2}-z) – z\,\mathrm{exp}(iz^{2}-z)\right) \mathrm{d}z
\label{eq:160905-1}
\tag{1}

We begin with
\begin{align}
\tag{a}
\int \mathrm{exp}(ax^{2}-bx) \mathrm{d}x &= \mathrm{exp}(-b^{2}/4a) \int \mathrm{exp}(a(x-b/2a)^{2}) \mathrm{d}x \\
&= \frac{1}{\sqrt{a}} \mathrm{exp}(-b^{2}/4a) \int \mathrm{exp}(z^{2}) \mathrm{d}z \\
&= \frac{1}{2} \sqrt{\frac{\pi}{a}} \,\mathrm{exp}(-b^{2}/4a) \,\mathrm{erfi}(z) \\
&= \frac{1}{2} \sqrt{\frac{\pi}{a}} \,\mathrm{exp}(-b^{2}/4a) \,\mathrm{erfi}\left(x\sqrt{a}-\frac{b}{2\sqrt{a}}\right)
\end{align}
a. Complete the square.
Note that $$\mathrm{erfi}(z)$$ is the imaginary error function.

Integrating both sides of the above equation with respect to $$b$$, we have

\int x\,\mathrm{exp}(ax^{2}-bx) \mathrm{d}x
= \frac{\sqrt{\pi}}{2a} \,\mathrm{exp}(-b^{2}/4a) \,\left[ \frac{b}{\sqrt{a}}\mathrm{erfi}\left(x\sqrt{a}-\frac{b}{2\sqrt{a}}\right)
+ \frac{1}{\sqrt{\pi}} \mathrm{e}^{a(x-b/2a)^{2}} \right]

with $$a=i$$ and $$b=1$$

\int x\,\mathrm{exp}(ix^{2}-x) \mathrm{d}x
= \frac{\sqrt{\pi}}{i2} \,\mathrm{exp}(-1/i4) \,\left[ \frac{1}{\sqrt{i}}\mathrm{erfi}\left(x\sqrt{i}-\frac{1}{2\sqrt{i}}\right)
+ \frac{1}{\sqrt{\pi}} \mathrm{e}^{i(x-1/i2)^{2}} \right]
\label{eq:160905-2}
\tag{2}

which is the second part of the integral on the right hand side of equation \eqref{eq:160905-1}.

With
\begin{align}
\tag{a}
\int \mathrm{exp}(-ax^{2}-bx) \mathrm{d}x &= \mathrm{exp}(b^{2}/4a) \int \mathrm{exp}(-a(x+b/2a)^{2}) \mathrm{d}x \\
&= \frac{1}{\sqrt{a}} \mathrm{exp}(b^{2}/4a) \int \mathrm{exp}(-z^{2}) \mathrm{d}z \\
&= \frac{1}{2} \sqrt{\frac{\pi}{a}} \,\mathrm{exp}(b^{2}/4a) \,\mathrm{erf}(z) \\
&= \frac{1}{2} \sqrt{\frac{\pi}{a}} \,\mathrm{exp}(b^{2}/4a) \,\mathrm{erf}\left(x\sqrt{a}+\frac{b}{2\sqrt{a}}\right)
\end{align}
a. Complete the square.
Note that $$\mathrm{erf}(z)$$ is the error function.

Integrating both sides of the above equation with respect to $$b$$, we have

\int x\,\mathrm{exp}(-ax^{2}-bx) \mathrm{d}x
= -\frac{\sqrt{\pi}}{2a} \,\mathrm{exp}(b^{2}/4a) \,\left[ \frac{b}{\sqrt{a}}\mathrm{erf}\left(x\sqrt{a}+\frac{b}{2\sqrt{a}}\right)
+ \frac{1}{\sqrt{\pi}} \mathrm{e}^{-a(x+b/2a)^{2}} \right]

with $$a=i$$ and $$b=1$$

\int x\,\mathrm{exp}(-ix^{2}-x) \mathrm{d}x
= -\frac{\sqrt{\pi}}{i2} \,\mathrm{exp}(1/i4) \,\left[ \frac{1}{\sqrt{i}}\mathrm{erf}\left(x\sqrt{i}+\frac{1}{2\sqrt{i}}\right)
+ \frac{1}{\sqrt{\pi}} \mathrm{e}^{-i(x+1/i2)^{2}} \right]
\label{eq:160905-3}
\tag{3}

which is the first part of the integral on the right hand side of equation \eqref{eq:160905-1}.

Substituting equations \eqref{eq:160905-2} \eqref{eq:160905-3} into \eqref{eq:160905-1} and changing back to the original variables yields our result.