# Closed form for some integrals related to the complementary error function

While studying the use of the trapezoidal rule for numerically evaluating the complementary error function $\mathrm{erfc}(z)$, the following integrals showed up when I was trying to derive expressions for the truncation error:

$$\int_0^\pi \exp\left(-z^2\tan^2\frac{u}{2}\right)\cos(2mu) \mathrm du$$

where $z$ is positive and $m$ is a positive integer.

Evaluating a bunch of these integrals in Mathematica, I gather that these integrals follow the pattern

$$\pi z^2\exp(z^2)\mathrm{erfc}(z)R_n(z)-2\sqrt{\pi}z S_n(z)$$

where $R_n(z)$ and $S_n(z)$ are polynomials.

Are there any closed forms for these two polynomials?

The substitution $t=\tan(u/2)$ turns your integral into $$\int_0^\infty e^{-z^2 t^2} \cos(4 m \arctan t) \frac{2 dt}{1+t^2}.$$ Since $\exp(i \arctan t) = \frac{1+it}{\sqrt{1+t^2}}$, this can be written as $$\Re \int_{-\infty}^\infty e^{-z^2 t^2} \frac{(1+it)^{4m}}{(1+t^2)^{2m+1}} dt = \sum_{k=0}^{2m} \int_{-\infty}^\infty e^{-z^2 t^2} \frac{\binom{4m}{2k}(-1)^k t^{2k}}{(1+t^2)^{2m+1}} dt.$$ By writing $t^{2k} = ((t^2+1)-1)^k$ and expanding using the binomial theorem, this integral can be reduced to a sum of integrals of the form $$J_n(z) = \int_{-\infty}^\infty e^{-z^2 t^2} \frac{1}{(1+t^2)^n} dt.$$ We have $J_0(z) = \sqrt{\pi}/z$ right away, and also $J_1(z) = \pi \exp(z^2) \mathrm{erfc}(z)$; the latter equality follows since both sides satisfy the differential equation $(d/dz)(\exp(-z^2) f(z)) = -2 \sqrt{\pi} \exp(-z^2)$, and both sides agree at $z=0$. Moreover, the following two-term recursion relation holds: $$(2m-2) J_m(z) - (2m-3-2z^2) J_{m-1}(z) - 2z^2 J_{m-2}(z) = 0.$$ Proof: Verify by direct calculation that left-hand side is the integral of $\frac{\partial}{\partial t} \left( \frac{t \exp(-t^2 z^2)}{(1+t^2)^{(m-1)}} \right)$.
From this it follows that each $J_n$ is a linear combination of $J_0$ and $J_1$ with coefficients that are polynomials in $z^2$, and this also implies that the pattern that you've observed really is correct, but it seems tricky to get a nice explicit form for those polynomials...