I'm running Mathematica 7.0.0 and came across this weird calculation (lines 1-14).
f[x_, r_] := x*(r - x)*Exp[-Pi*I/(2 r)*x^2];
g[x_, r_] := Exp[-Pi*I/(2 r)*x^2]*(r - Pi*I*x^2 - 2*x + Pi*I/r*x^3);
int[r_] :=
FullSimplify[
Integrate[f[x, r], {x, 0, r}] +
Integrate[-Sum[Sin[2*Pi*n*x]/(n*Pi), {n, 1, Infinity}]*
g[x, r], {x, 0, r}], r > 0 && Element[r, Integers]];
int[r] // N
int[12] // N
Output:
0.
2.64102 - 39.4256 I
So I've got two functions, $f$ and $g = f'$, and I'm interested in a certain expression (as shown). However, the general expression that Mathematica 7 gives for positive integers $r$ is $0$, whereas it gives something non-zero for particular integers $r$ (as it should).
Can somebody with Mathematica 8 verify this or tell me why I shouldn't be surprised? Thanks.
First note that $h(x) = \sum_{n=1}^\infty \frac{\sin(2\pi n x)}{ n \pi} = \frac{1}{2} - \{ x \}$.
Second, the first integral is easy to compute integrating by parts: $$ \mathcal{I}_f = \int_0^r f(x,r) \mathrm{d} x = \int_0^r x (r-x) \exp\left(-i \frac{\pi}{2} \frac{x^2}{r}\right) \mathrm{d} x = i \frac{r}{\pi } \left( \sqrt{r} C\left(\sqrt{r}\right)-i \sqrt{r} S\left(\sqrt{r}\right)- r\right) $$
The second integral will have to be split: $$ \begin{eqnarray} \mathcal{I}_g &=& \int_0^r h(x) g(x,r) \mathrm{d} x = \sum_{k=0}^{r-1} \int_0^1 h(k+x) g(k+x,r) \mathrm{d} x = \sum_{k=0}^{r-1} \int_0^1 \left( \frac{1}{2} -x \right) g(k+x,r) \mathrm{d} x \\ &=& \phantom{+} \sum_{k=0}^{r-1} \frac{1}{2\pi} (k-r+1)(\pi(k+1)-2 i r) \exp\left( -i \frac{\pi}{2} \frac{(k+1)^2}{r} \right) \\ &\phantom{=}& + \sum_{k=0}^{r-1} \frac{1}{2\pi} (k-r)( \pi k + 2i r) \exp\left( -i \frac{\pi}{2} \frac{k^2}{r} \right) \\ &\phantom{=}& + \sum_{k=0}^{r-1} \frac{1+i}{2 \pi} r^{3/2} \left( \operatorname{erf}\left( \frac{1+i}{2} \sqrt{\frac{\pi}{r}} k \right) - \operatorname{erf}\left( \frac{1+i}{2} \sqrt{\frac{\pi}{r}} (k+1) \right) \right) \end{eqnarray} $$
Now, with explicit evaluations of the integrals for explicit $r$ neither Fresnel integrals, nor error functions do appear, so they must be cancelling. One can probably show they do using integral representations. Anyway, assuming they do we have a "closed-form" expression for the expression you were computing:
$$ \mathcal{I}_f - \mathcal{I}_g = \sum_{k=1}^r k (r-k) \exp\left( -i \frac{\pi}{2} \frac{k^2}{r} \right) $$
You can verify with explicit computations that the formula is correct: