Theory problem in complex integration. Few days ago I had been solving this task : prove that $I_K = \displaystyle \int_{0}^{+\infty} x^{k} e^{-x} \sin{x}  = 0$ iff $k = 4n+3$.
I've found two ways to prove it : recurrence equations and complex integration.
The latter method gives me the right answer, but I'm not sure about correctness of my calculations. 
My attempt : 
$$\displaystyle \int_{0}^{+\infty} x^{k} e^{-x} \sin{x} = \Im \int_0^{+\infty} x^k e^{-x(1-i)} dx \stackrel{\text{x(1-i) = z}}{=} \Im \int_0^{+\infty} e^{-3\pi(k+1)/4} e^{-z}z^{k} dz$$And it easy gives me an answer. But how can I explain this substitution? I understand that I should use contour-integration. But maybe if there are some theorem about class of functions for which we can use such substitutions for improper integral?
 A: One problem here is that your substitution also changes the contour of integration. You have also not accounted correctly for the change of variables in $x^k\,\mathrm{d}x$.
Here is how I would do it:
$$
\begin{align}
\int_0^\infty x^ke^{-x(1-i)}\,\mathrm{d}x
&=\lim_{R\to\infty}\int_0^Rx^ke^{-x(1-i)}\,\mathrm{d}x\tag1\\
&=\left(\frac{1+i}2\right)^{k+1}\lim_{R\to\infty}\int_0^{R(1-i)}z^ke^{-z}\,\mathrm{d}z\tag2\\
&=\left(\frac{1+i}2\right)^{k+1}\lim_{R\to\infty}\int_0^Rz^ke^{-z}\,\mathrm{d}z\tag3\\
&=\left(\frac{1+i}2\right)^{k+1}\int_0^\infty z^ke^{-z}\,\mathrm{d}z\tag4\\
&=\left(\frac{1+i}2\right)^{k+1}k!\tag5
\end{align}
$$
In step $(2)$, we have used $z=x(1-i)$, which also means $x=\frac{1+i}2z$; i.e. $x^k\,\mathrm{d}x=\color{#C00}{\left(\frac{1+i}2\right)^{k+1}}z^k\,\mathrm{d}z$. Note that $\left(\frac{1+i}2\right)^{k+1}=2^{-(k+1)/2}e^{-\pi i(k+1)/4}$.
In step $(3)$, we use Cauchy's Integral Theorem and the family of contours $\gamma_R$
$$
\gamma_R=\underbrace{\ \ [0,R]\ \ }_{\substack{\text{the contour}\\\text{in step (3)}}}\cup\underbrace{[R,R-Ri]}_{\substack{\text{this integral}\\\text{vanishes as}\\\text{$R\to\infty$}}}\cup\underbrace{[R-Ri,0]}_{\substack{\text{the reverse of}\\\text{the contour in}\\\text{step (2)}}}
$$
So now we need to show that the integral along $[R,R-Ri]$ vanishes.
A: Using the Laplace transform we have that
$$\mathcal{L}^{-1}(x^k)=\delta^{(k)}(s),\qquad \mathcal{L}(e^{-x}\sin(x)) = \frac{1}{1+(1+s)^2} $$
hence the problem boils down to showing that the derivatives of order $4n+3$ of $\frac{1}{1+(1+s)^2}$ at the origin are zero.
On the other hand
$$ \frac{1}{1+(1+s)^2}=\frac{-\frac{i}{2}}{s-(i-1)}+\frac{\frac{i}{2}}{s-(-i-1)} $$
follows from the residue theorem, and it gives
$$ \frac{1}{1+(1+s)^2} = \sum_{n\geq 0}\frac{s^n(-1)^n}{2^{\frac{n-1}{2}}}\cdot \cos\left(\frac{\pi}{4}(n-1)\right)$$
through $1\pm i = \sqrt{2}\exp\left(\pm \frac{\pi i}{4}\right)$. A simpler way is to notice that
$$ \frac{1}{1+(1+s)^2} = \frac{1}{2+2s+s^2} = \frac{2-2s+s^2}{4+s^4}=\frac{2-2s+s^2}{4}\sum_{h\geq 0}\frac{(-1)^h}{4^h}s^{4h}.$$
A: $$J=\int_0^\infty x^k e^{-x} \sin x \, dx = \frac{1}{2i} \int_0^\infty x^k \left[ e^{-x(1-i)}-e^{-x(1+i)} \right]\, dx\\  $$
We have (for $k$ an integer)
$$\int_0^\infty x^k e^{-sx} \, dx = \mathcal{L}\{x^k\} = \frac{k!}{s^{k+1}}$$
So $$\begin{aligned} 
J &= \frac{1}{2i} \left[ \left. \mathcal{L}\{x^k\} \right|_{s=1-i} - \left. \mathcal{L}\{x^k\} \right|_{s=1+i} \right] \\
&= \frac{k!}{2i} \left[\frac{1}{(1-i)^{k+1}} - \frac{1}{(1+i)^{k+1}}\right] 
= \frac{k!}{2i} \left[\frac{(1+i)^{k+1} - (1-i)^{k+1}}{2^{k+1}} \right] \\
&= \frac{k!}{2i} \cdot \frac{1}{2^\frac{k+1}{2}}\left[\exp \left\{\frac{i\pi}{4}(k+1)\right\} -  \exp \left\{-\frac{i\pi}{4}(k+1) \right\} \right] \\
&= \frac{k!}{2^\frac{k+1}{2}} \sin \left[ \frac{\pi}{4}\left(k+1\right)\right]
\end{aligned}$$
$\sin m\pi$ is zero when $m$ is an integer, so we require $k+1$ to be divisible by $4$, or $k=4n+3$.
A: I can see $3$ reasonable approaches to computing $\int_0^{\infty}x^ke^{-(1+i)x}dx$. Firstly, you could perform a contour integral around a wedge in the complex plane. Consider the following diagram:

We propose to integrate
$$\oint_Cz^ke^{-z}dz=\int_{C_1}z^ke^{-z}dz+\int_{C_2}z^ke^{-z}dz+\int_{C_3}z^ke^{-z}dz$$
Along $C_1$, $z=t$ so
$$\int_{C_1}z^ke^{-z}dz=\int_0^Rt^ke^{-t}dt$$
So
$$\lim_{R\rightarrow\infty}\int_{C_1}z^ke^{-z}dz=\operatorname{\Gamma}(k+1)=k!$$
Along $C_2$. $z=Re^{i\theta}$ so
$$\int_{C_2}z^ke^{-z}dz=\int_0^{\pi/4}\left(Re^{i\theta}\right)^ke^{-Re^{i\theta}}iRe^{i\theta}d\theta$$
Now along contour $C_2$, $0\le\theta\le\frac{\pi}4$ so $\cos\theta\ge1/\sqrt2$ and
$$\left|\int_{C_2}z^ke^{-z}dz\right|\le R^{k+1}e^{-R/\sqrt2}\int_0^{\pi/4}d\theta=\frac{\pi}4R^{k+1}e^{-R/\sqrt2}$$
So
$$\lim_{R\rightarrow\infty}\int_{C_2}z^ke^{-z}dz=0$$
Along contour $C_3$, $z=te^{\pi i/4}$ so
$$\begin{align}\int_{C_3}z^ke^{-z}dz&=\int_R^0\left(te^{\pi i/4}\right)^ke^{-te^{\pi i/4}}e^{\pi i/4}dt=-e^{\pi i(k+1)/4}\int_0^Rt^ke^{-(1+i)t/\sqrt2}dt\\
&=-e^{\pi i(k+1)/4}\int_0^{R/\sqrt2}\left(u\sqrt2\right)^ke^{-(1+i)u}\sqrt2\,du\\
&=-e^{\pi i(k+1)/4}2^{\frac{k+1}2}\int_0^{R/\sqrt2}u^ke^{-(1+i)u}du\end{align}$$
So
$$\lim_{R\rightarrow\infty}\int_{C_3}z^ke^{-z}dz=-e^{\pi i(k+1)/4}2^{\frac{k+1}2}\int_0^{\infty}t^ke^{-(1+i)t}dt$$
Since the integrand is holomorphic on and within contour $C$, we have
$$\oint_Cz^ke^{-z}dz=0=k!+0-e^{\pi i(k+1)/4}2^{\frac{k+1}2}\int_0^{\infty}t^ke^{-(1+i)t}dt$$
So we have
$$\frac{k!}{2^{\frac{k+1}2}}\left(\cos\frac{(k+1)\pi}4-i\sin\frac{(k+1)\pi}4\right)=\int_0^{\infty}t^ke^{-t}\cos t\,dt-i\int_0^{\infty}t^ke^{-t}\sin t\,dt$$
The second method would be to embed the direction of the path of integration in the integral and see how its value changes as the direction changes. Let
$$I(\theta)=\int_0^{\infty}x^ke^{-xe^{i\theta}}dx$$
Then
$$\begin{align}\frac{dI}{d\theta}&=\int_0^{\infty}-ie^{i\theta}x^{k+1}e^{-xe^{i\theta}}dx\\
&=\left.ix^{k+1}e^{-xe^{i\theta}}\right|_0^{\infty}-i(k+1)\int_0^{\infty}x^ke^{-xe^{i\theta}}dx\\
&=-i(k+1)I(\theta)\end{align}$$
The general solution to this differential equation is
$$I(\theta)=Ce^{-i(k+1)\theta}$$
And we have the initial condition
$$I(0)=C=\int_0^{\infty}x^ke^{-x}dx=k!$$
So
$$\begin{align}I\left(\frac{\pi}4\right)=k!e^{-i(k+1)\pi/4}=\int_0^{\infty}x^ke^{-(1+i)x/\sqrt2}dx=2^{\frac{k+1}2}\int_0^{\infty}t^ke^{-(1+i)t}dt\end{align}$$
Same as we had by the first method.  
Finally we could forget trying to build on what we already know about the Gamma function and just try do derive the few properties we need along the current path of integration de novo:
$$\begin{align}I_k&=\int_0^{\infty}x^ke^{-(1+i)x}dx=\left.-\frac1{1+i}x^ke^{-(1+i)x}\right|_0^{\infty}+\frac k{1+i}\int_0^{\infty}x^{k-1}e^{-(1+i)x}dx\\
&=\frac k{i+1}I_{k-1}=\frac k{\sqrt2}e^{\frac{-\pi i}4}I_{k-1}=\frac{2^{\frac k2}k!e^{-\frac{\pi i(k+1)}4}}{2^{\frac{k+1}2}(k-1)!e^{-\frac{\pi ik}4}}I_{k-1}\end{align}$$
So
$$\begin{align}\frac{2^{\frac{k+1}2}I_k}{k!e^{-\frac{\pi i(k+1)}4}}&=\frac{2^{\frac k2}I_{k-1}}{(k-1)!e^{-\frac{\pi ik}4}}=\frac{\sqrt2\,I_0}{e^{-\frac{\pi i}4}}\\
&=\frac{\sqrt2}{e^{-\frac{\pi i}4}}\int_0^{\infty}e^{-(1+i)x}dx=\left.-\frac{\sqrt2}{e^{-\frac{\pi i}4}(1+i)}e^{-(1+i)x}\right|_0^{\infty}=1\end{align}$$
And we are back to
$$I_k=\int_p^{\infty}x^ke^{-(1+i)x}dx=\frac{k!e^{-\frac{\pi i(k+1)}4}}{2^{\frac{k+1}2}}$$
Perhaps the easiest of the three methods. Of course it amounts to a recurrence relation method.  
