Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Background: Mac OSX 10.9.4, Mathematica 9.0.1 vs. Mathematica 10.0 (both versions are Student Editions).

I have a notebook. It used to evaluate fine in Mathematica 9. I upgraded to 10 and, without doing any modification at all to the notebook, an integral stopped converging. I even tried after quitting/restarting the kernel and doing an OS reboot.

In an attempt to provide a minimal test case I wrote a code snippet that had a typo (epsilon instead of 'element of ') which caused a great deal of confusion. The code would not work, neither in 9 nor 10. Thanks to Michael for identifying it. The original code in my notebook did not suffer from this typo, although I'm afraid most people thought it did.


I narrowed the problem down to the following code:

ClearAll["Global`*"];
u[n_, x_] := If[x <= 0 || x >= L, 0, Sqrt[2/L] Sin[n π x /L]]
φ[n_, k_] =
Assuming[{n \[Element] Integers, L > 0},
    Simplify@
        (1/Sqrt[2 π]) Integrate[u[n, x] Exp[-I k x], {x, 0, L}]]

Δk[n_] :=
Assuming[{n \[Element] Integers},
Simplify@
    ((Integrate[
        φ[n, k]\[Conjugate] k^2 φ[n, k], {k, -Infinity, +Infinity}] -
    Integrate[
        φ[n, k]\[Conjugate] k φ[n, k], {k, -Infinity, +Infinity}]^2)^(1/2))]
L = 1;
(* If I replace ParallelTable[] with Table[], the problem disappears *)
ParallelTable[Δk[n], {n, 1, 1}]

(* If I uncomment the following line, the problem disappears no matter
   whether I use ParallelTable[] or just Table[] *)
(*Quit[]*)

(* From now on it's the original code snippet I wrote with the typo fixed *)
ClearAll["Global`*"];
u[n_, x_] := If[x <= 0 || x >= L, 0, Sqrt[2/L] Sin[n π x/L]]

\[Phi][n_, k_] =
Assuming[{n \[Element] Integers, L > 0},
    FourierTransform[u[n, x], x, k, FourierParameters -> {0, -1}]]

η[n_, k_] =
    Assuming[{n \[Element] Integers, L > 0, k \[Element] Reals},
        FullSimplify[
            \[Phi][n, k]\[Conjugate] \[Phi][n, k]]]

Δk[n_] =
    Assuming[{n \[Element] Integers, n > 0, L > 0, k \[Element] Reals},
    Simplify@Sqrt@
        Integrate[k^2 η[n, k], {k, -\[Infinity], +\[Infinity]}]]

Mathematica 9 yields $n\pi/L$ as a result for the last expression. In Mathematica 10 I get a convergence error:

enter image description here

Summary

  1. The problem is real.
  2. The problem happens only when I use ParallelTable[] (instead of just Table[]).
  3. The problem goes aways when I run Quit[] just before the 2nd ClearAll command.
share|improve this question
    
I have 9.01 and I am getting Integral does not converge. –  bobbym Aug 20 at 10:03
    
Same output both v9.0.1.0 and v10.0.0.0 on Windows 7 Pro SP1 64bit. Integral does not converge on {-\[Infinity],\[Infinity]} –  rhermans Aug 20 at 10:03
    
I get the same output in MMa 8.0.4 and 10.0.0 under Win7 x64: integral does not converge. –  Alexey Popkov Aug 20 at 10:11
    
You can get the correct result n*Pi/L if you are willing to help MMA a bit. There are appearant poles in k which, however cancel at closer inspection; also the condition that n is an integer must be imposed several times during Integrate and Simplify. It is the "usual" procedure of working hand-in-hand with MMA. I'll show it later in detail when I find the time. I have version 8 by the way. –  Dr. Wolfgang Hintze Aug 20 at 10:52
1  
It seems to me there is a real bug here, which ought to be reported to WRI, and this question should be reopened. –  Michael E2 Aug 22 at 15:46

2 Answers 2

Here is the derivation promised earlier. I have chosen to create a new answer in order not to mix things up and because it shows some handling which I like to call "man-machine" interaction with Mathematica. And, sorry for the "Greeks", but I find it very cumbersome to reedit them :-(

$Version

"8.0 for Microsoft Windows (64-bit) (October 7, 2011)"

First the procedures of Michael E2 en bloc:

u[n_, x_] := If[x <= 0 || x >= L, 0, Sqrt[2/L] Sin[n π x/L]];
φ[n_, k_] := Assuming[{n ∈ Integers, L > 0}, 
   FourierTransform[u[n, x], x, k, FourierParameters -> {0, -1}]];
η[n_, k_] = Assuming[{n ∈ Integers, L > 0, k ∈ Reals}, 
   FullSimplify[Conjugate@φ[n, k] φ[n, k]]];
Δk[n_] = Assuming[{n ∈ Integers, n > 0, L > 0, k ∈ Reals}, 
   FullSimplify[
    Sqrt@Integrate[k^2 η[n, k], {k, -∞, +∞}]]];

During evaluation of In[168]:= Integrate::idiv: Integral of (2 k^2 L n^2 π)/(-k^2 L^2+n^2 π^2)^2-(2 (-1)^n k^2 L n^2 π Cos[k L])/(-k^2 L^2+n^2 π^2)^2 does not converge on {-∞,∞}. >>

Okay, the error message again (i.e. also in version 8). But if we read it carefully we can find out what Mathematica has not "seen": each term in itself is divergent, but the sum is not!


Let's process step by step.

First the intermediate results:

u[n, k]
If[k <= 0 || k >= L, 0, Sqrt[2/L] Sin[(n π k)/L]]
φ[n, k]
(E^(-I k L) (-(-1)^n + E^(I k L)) Sqrt[L] n Sqrt[π])/(-k^2 L^2 + 
 n^2 π^2)
η[n, k]
-((2 L n^2 π (-1 + (-1)^n Cos[k L]))/(k^2 L^2 - n^2 π^2)^2)

Now the notorious integral (again)

Integrate[k^2 η[n, k], {k, -∞, ∞}, 
 Assumptions -> {L > 0, n > 0, k > 0, {k, L, n} ∈ Reals}]

During evaluation of In[181]:= Integrate::idiv: Integral of (2 k^2 L n^2 π)/(-k^2 L^2+n^2 π^2)^2-(2 (-1)^n k^2 L n^2 π Cos[k L])/(-k^2 L^2+n^2 π^2)^2 does not converge on {-∞,∞}. >>

Now the trick: let Mathematica do the integral without any assumptions:

Integrate[k^2 η[n, k], {k, -∞, ∞}]
ConditionalExpression[-((
  L π (-(1/(-(L^2/n^2))^(3/2)) + (
     n^4 (Sqrt[-(1/n^2)] - π) Abs[
       L] (Cos[n π] + I Sin[n π]) (Cosh[π/Sqrt[-(1/n^2)]] + 
        Sinh[Sqrt[-(1/n^2)] n^2 π]))/L^4))/n^2), 
 L ∈ Reals && (L == 0 || n ∉ Reals) && 
  3 Arg[-(L^2/n^2)] <= 2 π]

Very good. No divergence but a conditional expression.

Now, even if it sounds like brute force, we take the result by hand and simplify it under our conditions:

Simplify[-((
  L π (-(1/(-(L^2/n^2))^(3/2)) + (
     n^4 (Sqrt[-(1/n^2)] - π) Abs[
       L] (Cos[n π] + I Sin[n π]) (Cosh[π/Sqrt[-(1/n^2)]] + 
        Sinh[Sqrt[-(1/n^2)] n^2 π]))/L^4))/n^2), {L > 0, n > 0, 
  k > 0, {k, L} ∈ Reals, n ∈ Integers}]
(n^2 π^2)/L^2

And, voilà, the desired result pops up.

This was a demonstration of the cooperation man-Mathematica which in many cases leads to valid results.

Best regards, Wolfgang

share|improve this answer
1  
Thank you very much for taking the time to provide an answer. Also no worries for the greek letters :) –  Zet Aug 20 at 11:25
    
@Öskå: You're very much right, and I'd like to do that. But how? –  Dr. Wolfgang Hintze Aug 20 at 12:51
    
@Öskå: Yes, I can see what you did but - sorry - not HOW (Output indention, Greeks). Please give me a pointer to the detailed description of how to set up a correct text for StackExchange MMA. Up to now I find editing rather cumbersome, and I'd like to avoid bothering others. Thanks in advance. –  Dr. Wolfgang Hintze Aug 20 at 12:59
    
@Öskå: the indention is ok now. But the Greeks remain open since I'm using IE and I don't want to make experiments with scripts only to be able to contribute to the MMA-group properly. IMHO the provided editor should be able to convert the typical strutures of MMA, otherwise it is not particularly suited. –  Dr. Wolfgang Hintze Aug 20 at 13:28
1  
@Dr.WolfgangHintze See meta.mathematica.stackexchange.com/questions/1043/… –  Michael E2 Aug 20 at 21:12

Update

The updated question clarifies the problem. As far as I can tell, this is a bug, a rather strange bug. I've tracked the problem down to the definition L = 1 still existing on the parallel kernels. This removes the problem:

  • Put ParallelEvaluate@ClearAll["Global`L"] after the second ClearAll["Global`*"] halfway through the code.

Then FullSimplify will simplify η so that the integral in Δk will evaluate to n π / L.

The difference can be traced to how φ[n, k] evaluates under the two conditions:

(* OP's code:
  (E^(-I k) Sqrt[L] (-E^(I k) n π + n π Cos[(n π)/L] + I k L Sin[(n π)/L])) /
   (Sqrt[π] (k L - n π) (k L + n π))
*)
(* After ParallelEvaluate@ClearAll["Global`L"]:
  (E^(-I k L) ((-1)^(1 + n) + E^(I k L)) Sqrt[L] n Sqrt[π]) /
   (-k^2 L^2 + n^2 π^2)
*)

Note that the first case is not automatically simplified, and for some reason FullSimplify fails to do so, too.

Other fixes may be used after the second ClearAll["Global`*"]:

CloseKernels[]
ParallelEvaluate[Clear["Global`*"]]

Putting ParallelEvaluate[L = 1] after the fix reintroduces the problem, provided it is done before the definition of φ[n, k] is executed. Something seems to get set in the system that determines how L will be treated; after φ[n, k] is executed, quitting the kernel might be the only way to reset it. (ClearSystemCache[] did not work. There may be something similar I don't know about.)

That such a dependency arises at all is a mystery to me. I imagine the system somehow might engage the parallel kernels, when they exist, in determining internal attributes of the symbol L. I have found no way to test that hypothesis. Then again, bugs themselves should be unlikely.

Original answer - Still works on a fresh kernel

The following returns n Pi / L in both V9 and V10:

u[n_, x_] := If[x <= 0 || x >= L, 0, Sqrt[2/L] Sin[n π x/L]]
φ[n_, k_] := 
 Assuming[{n ∈ Integers, L > 0}, 
  FourierTransform[u[n, x], x, k, FourierParameters -> {0, -1}]]
η[n_, k_] = 
 Assuming[{n ∈ Integers, L > 0, k ∈ Reals}, 
  FullSimplify[Conjugate@φ[n, k] φ[n, k]]]
Δk[n_] = 
 Assuming[{n ∈ Integers, n > 0, L > 0, k ∈ Reals}, 
  FullSimplify[Sqrt@Integrate[k^2 η[n, k], {k, -∞, +∞}]]]
share|improve this answer
1  
@Zet Did you restart your kernel? –  sebhofer Aug 20 at 10:51
    
@Zet I can confirm Michael's observation that this code gives the desired result on V9 and V10 (on Linux, but it's very unlikely this makes a difference) –  sebhofer Aug 20 at 10:56
    
@sebhofer thanks! Restarting the kernel made Michael's code work for me. Restarting didn't help though with my original notebook. I still get errors :( Can it be that prior computations affect subsequent operations? I will upload my notebook for anyone feeling like playing with it. –  Zet Aug 20 at 11:01
    
Of course it can, you are changing the state of your Mathematica session after all. I would suggest that you go through your code step by step and see which symbols/expressions evaluate to something unexpected. Start from the bottom and work your way up. I don't think, however, that someone will do this work for you. –  sebhofer Aug 20 at 11:06
    
I wrote to Wolfram Technical Support. Thank you Michael for not giving up on me. I will post back when/if I get an answer. –  Zet Aug 22 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.