Janus
Janus

Reputation: 5681

Bug in Mathematica's Integrate with PrincipalValue->True

It seems that Mathematica's handling of principal value integrals fails on some corner cases. Consider these two expressions (which should give the same result):

Integrate[UnitBox[x]/(x0 - x), {x, -Infinity, Infinity},
  PrincipalValue -> True, Assumptions -> {x0 > 0}] /. x0 -> 1 // Simplify
Integrate[UnitBox[x]/(x0 - x) /. x0 -> 1, {x, -Infinity, Infinity}, 
  PrincipalValue -> True]

In Mathematica 7.0.0 I get

I Pi+Log[3]
Log[3]

Has this been fixed in later versions? Does anybody have an idea for a (more or less) general workaround?

EDIT: The two expressions above should calculate the same result, the first by calculating a general form of the integral and evaluating it at x0=1, the second by performing the integral with x0 set to 1. Since the Cauchy principal value has a precise mathematical definition, Mathematica should give the same result or decline to answer.

EDIT 2: A perhaps simpler example of the same bug, putting a factor of -1 inside and outside the Integral give different answers (second one gives the correct answer, first one doesn't):

-Integrate[ UnitBox[x]/(x0 - x), {x, -Infinity, Infinity}, PrincipalValue -> True, Assumptions -> {x0 > 0}]
 Integrate[-UnitBox[x]/(x0 - x), {x, -Infinity, Infinity}, PrincipalValue -> True, Assumptions -> {x0 > 0}]

Upvotes: 3

Views: 1561

Answers (3)

tba
tba

Reputation: 6571

Seems to be fixed in 8.0:

In[1]:= $Version
Out[1]= "8.0 for Mac OS X x86 (32-bit) (November 13, 2010)"

In[2]:= 
Integrate[UnitBox[x]/(x0 - x), {x, -Infinity, Infinity}, 
   PrincipalValue -> True, Assumptions -> {x0 > 0}] /. 
  x0 -> 1 // Simplify

Out[2]= Log[3]

In[3]:= Integrate[
 UnitBox[x]/(x0 - x) /. x0 -> 1, {x, -Infinity, Infinity}, 
 PrincipalValue -> True]

Out[3]= Log[3]

Upvotes: 2

Timo
Timo

Reputation: 4326

I don't think this is a bug in PrincipalValue. In the first line PrincipalValue does not work "correctly" because the position of the pole is not known until after Integrate is done.

EDIT: I played around in Mathematica a bit and this is exactly what happens. You can see for yourself by using the Trace[] command. The output is a bit messy (which is why I don't replicate it here), but you can see where the integration gets done and where the value for x0 is substituted and how that messes with PrincipalValue.

EDIT2: So back to solving your actual problem. If you use an Assumption that specifies which side of x=1/2 x0 lies, then the two examples give the same answer.

Upvotes: 3

daveangel
daveangel

Reputation: 573

Well Wolfram Alpha, which I would assume uses the latest version of Mathematica, doesn't like your first expression and gives this for the second: log(3)+constant

http://www.wolframalpha.com/input/?i=Integrate[UnitBox[x]%2F%28x0+-+x%29+%2F.+x0+-%3E+1%2C+{x%2C+-Infinity%2C+Infinity}%2C++++PrincipalValue+-%3E+True]

It may be that this article applies in this case but I'm not a math expert so I wouldn't know? There are some situations, however, where several different answers are all equally consistent with the formal mathematical definitions. Thus, for example, in computing symbolic integrals, there are often several different expressions which all yield the same derivative. Which of these expressions is actually generated by Integrate can then depend on how Integrate works inside.

Upvotes: 0

Related Questions