TITLE: Are Complex Substitutions Legal in Integration?
QUESTION [7 upvotes]: This question has been irritating me for awhile so I thought I'd ask here.
Are complex substitutions in integration okay?  Can the following substitution used to evaluate the Fresnel integrals:
$$\int_{0}^{\infty} \sin x^2\, dx=\operatorname {Im}\left( \int_0^\infty\cos x^2\, dx + i\int_0^\infty\sin x^2\, dx\right)=\operatorname {Im}\left(\int_0^\infty \exp(ix^2)\, dx\right)$$
Letting $ix^2=-z^2 \implies x=\pm\sqrt{iz^2}=\pm \sqrt{i}z \implies z=\pm \sqrt{-i} x \implies dx = \pm\sqrt{i}\, dz$
Thus the integral becomes
$$\operatorname {Im}\left(\pm \sqrt{i}\int_0^{\pm\sqrt{-i}\infty} \exp(z^2)\, dz\right)$$
This step requires some justification, and I am hoping someone can help me justify this step as well:
$$\pm \sqrt{i}\int_0^{\pm\sqrt{-i}\infty} \exp(z^2)\, dz=\pm\sqrt{i}\int^\infty_0\exp(z^2)\, dz=\pm\sqrt{i}\left(\frac{\sqrt{\pi}}{2}\right)$$
Thus
$$\operatorname {Im}\left(\int_0^\infty \exp(ix^2)\, dx\right)=\operatorname {Im}\left(\pm\frac{\sqrt{i\pi}}{2}\right)=\operatorname {Im}\left(\pm\frac{(1+i)\sqrt{\pi}}{2\sqrt{2}}\right)=\pm\frac{1}{2}\sqrt{\frac{\pi}{2}}$$
We find that the correct answer is the positive part (simply prove the integral is positive, perhaps by showing the integral can be written as an alternating sum of integrals).
Can someone help justify this substitution?  Is this legal?

REPLY [11 votes]: A correct way to do this might go as follows.  Consider the contour integral
$$ \oint_\Gamma e^{iz^2}\ dz $$
where $\Gamma$ is the positively oriented triangle with vertices $0, R, R+Ri$ for large $R$.
Since the integrand is analytic, Cauchy's Theorem says the result is $0$.  This can be written as $J_1 + J_2 + J_3=0$, where $J_1, J_2, J_3$ are the integrals over the segments
$[0, R]$, $[R, R+Ri]$, and $[R+Ri,0]$ respectively.
Show that as $R \to +\infty$, $J_2 \to 0$ and $J_3 \to  -(1+i) \dfrac{\sqrt{2 \pi}}{4}$.
Thus $J_1  \to (1+i) \dfrac{\sqrt{2 \pi}}{4}$, which says that
$$ \int_0^\infty \cos(t^2)\ dt = \int_0^\infty \sin(t^2)\ dt = \dfrac{\sqrt{2 \pi}}{4}$$