0
$\begingroup$

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.

  • 0
    Well, I get the same results with 8.0.1.0 on a Mac.2011-11-17
  • 1
    @Sasha: I'm not quite sure what you mean; the expression is a sum of two integrals, neither of which are constant in $r$.2011-11-17
  • 0
    @SørenFugledeJørgensen Yes, you are right, of course. The value of the integral depends on `r`, my bad. As castal said, v 8.0.1, but also v 8.0.4 produce the same result as v7.2011-11-17
  • 0
    Thanks to both of you; I'll report it.2011-11-17
  • 0
    Some quick notes. Symbolically integrating both pieces, I get `(-i r^2 + r^(3/2) (i FresnelC[Sqrt[r]] + FresnelS[Sqrt[2]]))/Pi` for $\int f$ and its negative for the second integral. However, integrating them both with a definite value of $r$, I get different results. For $r=5$, the sum is $1.19-5.00i$, and for $r=6$, the sum is $3.30-9.00i$, rounded, of course. I wonder if this is similar to the problem of integrating $\cos(q x)$ with $q \in \mathbb{Z}$.2011-11-17
  • 0
    @rcollyer: The first integral being the sum of Fresnel's is fairly immediate, and it gives the correct values for definite $r$, but it's a mystery to me how the second one ends up as the exact negative as the first one. I guess I'll try to do that one by hand when I get the chance.2011-11-17
  • 0
    I have no idea why it ends being the exact negative. A guess is that like $\int^\pi_{-\pi} \cos(qx)$ with $q\in\mathbb{Z}$, there are multiple solutions depending on $r$, and by not fixing its value, Mathematica blithely chooses the incorrect one.2011-11-17
  • 0
    @rcollyer: I'm not quite following you; what's the parameter in $\int_{-\pi}^\pi \cos(qx)$ that the solution depends on (you wrote $r$ but that's probably a typo?)?2011-11-17
  • 0
    Sorry, mixing messages there. $\int^\pi_{-\pi} \cos(qx) = 2$ when $q = 0$, but $0$ otherwise. But, you get the wrong answer if you integrate first and then set $q=0$. So, I was wondering if we're running into something similar with regards to $r$ in your integrals, but I didn't write it out as fully as I should have.2011-11-17
  • 0
    @rcollyer: That sounds likely; in this case Mathematica would give two results for the last integral, depending on the sign of $r$. In fact, if one changes every single $r$ to $r-1$, theoretically the value of the sum would change only by $f(r-1)/2$, but Mathematica gives a result which is not well-defined for integral values of $r$ (more precisely, it gives something like $\mathrm{Log}(1 - exp(2\pi i r))$.2011-11-17
  • 1
    Also, `Integrate` doesn't do anything with an integer assumption ([see the comments](http://stackoverflow.com/q/7743774)), so you have to watch out for them yourself.2011-11-17

1 Answers 1

5

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:

In[94]:= FullSimplify[
 Table[int[r] - Sum[Exp[-((I*k^2*Pi)/(2*r))]*(r - k)*k, {k, 1, r}], 
     {r, 1, 8}]]

Out[94]= {0, 0, 0, 0, 0, 0, 0, 0}
  • 0
    Thanks. Actually, the sum in the end was the one I was trying to approximate, going the other way around, as the integrals would hopefully be easier to manage. But what must be cancelling? We know that the integrals will not. I find it somewhat peculiar that Mathematica acknowledges that the sum of the integrals equals the sum, given that it also believes that int[$r$] = 0 for all $r$.2011-11-17