6

I am running Mathematica 11.1 on an Ubuntu machine and noticed the following unsavory behaviour today:

In[1] := Assuming[ Element[x,Reals],
          Integrate[1/(1 + y^2)*1/(y - x), {y, -Infinity, Infinity}, 
          PrincipalValue -> True]
         ]
Out[1] = Log[(-1)^(1/(1 + x^2)) e^(π /(I - x))]

In[2] := Assuming[ Element[w,Reals],
          Integrate[1/(1 + y^2)*1/(y - w), {y, -Infinity, Infinity}, 
          PrincipalValue -> True]
         ]
Out[2] = -π w/(1+w^2)

Although the two answers are mathematically equivalent, it is not clear to me why the results are presented in different manners (and different enough that Simplify or FullSimplify does not reveal the latter from the former.

Clearly the answer should not depend on what symbol I use, but it does. I have obtained the same result using different kernels on the same computer. I could not reproduce the problem on Mathematica 8.0 or Mathematica 10.0 on two different Linux machines.

Is this perhaps an issue with my machine/setup? I would also like to know if others can reproduce this issue. I would also like to know if this issue persists in 11.2, if it does not I will upgrade.

Note: I believe that this is a different issue than covered here since using u,v, or z gives the same problem as x; only w seems to work as desired.

Jeremy Upsal
  • 336
  • 1
  • 9

2 Answers2

4

They're equivalent:

Assuming[Element[x, Reals], 
 Integrate[1/(1 + y^2)*1/(y - x), {y, -Infinity, Infinity}, PrincipalValue -> True]]
% // ComplexExpand[#, TargetFunctions -> {Re, Im}] &
(*
  Log[(-1)^(1/(1 + x^2)) E^(π/(I - x))]
  -((π x)/(1 + x^2))
*)

[Updated discussion:] I don't know why it depends on the variable name. Symbolic algebra algorithms can depend on the order of variables (affects what is done first sometimes), but I don't see why that would matter here. It's hard to see why w, i, and l are special cases, but it could depend on internal variables. (For instance π is converted to a internal variable by Integrate, and so are x and w.) As to whether it is a bug, for my own part, I do not want Integrate spending a lot of time simplifying the result. I can do that if I need to. However, there is a significant difference timing between the two and that is troubling. I would rather have the faster way, which coincidentally gives the simpler answer. (Each of the following was executed on a fresh kernel, after executing Integrate[1/(x^4 + 1), {x, -Infinity, Infinity}] to preload some internal integration code.)

Assuming[Element[w, Reals], 
  Integrate[1/(1 + y^2)*1/(y - w), {y, -Infinity, Infinity}, PrincipalValue -> True]] //
   AbsoluteTiming
(*  {1.43769, -((π w)/(1 + w^2))}  *)

Assuming[Element[x, Reals], 
  Integrate[1/(1 + y^2)*1/(y - x), {y, -Infinity, Infinity}, PrincipalValue -> True]] //
   AbsoluteTiming
(*  {2.42338, Log[(-1)^(1/(1 + x^2)) E^(π/(I - x))]}  *)

It's not a bug in the sense of giving invalid output, but from a user's point of view, it seems undesirable.


For what it's worth, here's the same problem, which is the source of the difference in answers but not in the difference in timing:

Limit[-((π (2 I + w))/(2 (1 + w^2))) - (π w)/(2 + 2 w^2) -
   (-2 w ArcTan[eps - w] - 2 Log[-eps] + Log[1 + (-eps + w)^2])/(2 + 2 w^2) +
   (2 w ArcTan[eps + w] - 2 Log[eps] + Log[1 + (eps + w)^2])/(2 + 2 w^2),
  eps -> 0, Analytic -> False, Assumptions -> {w ∈ Reals}, 
  Direction -> Automatic, 
  Method -> "InternalClassic"] // AbsoluteTiming

(*  {0.403682, -((π w)/(1 + w^2))}  *)

Limit[-((π (2 I + x))/(2 (1 + x^2))) - (π x)/(2 + 2 x^2) -
   1/(2 + 2 x^2) (-2 x ArcTan[eps - x] - 2 Log[-eps] + Log[1 + (-eps + x)^2]) +
   1/(2 + 2 x^2) (2 x ArcTan[eps + x] - 2 Log[eps] + Log[1 + (eps + x)^2]),
  eps -> 0, Analytic -> False, Assumptions -> {x ∈ Reals}, 
  Direction -> Automatic, 
  Method -> "InternalClassic"] // AbsoluteTiming

(*  {0.202505, Log[(-1)^(1/(1 + x^2)) E^(π/(I - x))]}  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
  • 1
    I agree they are equivalent. I don't see how order of variables matters here since I can use symbols (where the x is) who come before and after x which do not work (except w). I'm mainly curious if this is a bug that was introduced in 11.1 and not fixed in 11.2 or if it was fixed in 11.2 (since it does not appear to exist before 11.1). – Jeremy Upsal Jan 07 '18 at 23:40
  • @JeremyUpsal The same happens in v10.4. Interestingly, the y can be any character, but only i, l and w as the parameter give the simpler form. – corey979 Jan 07 '18 at 23:46
  • @corey979, i and l do not give the simpler form in v11.1. – Jeremy Upsal Jan 07 '18 at 23:50
  • 1
    Strange: If I change the assumption on x to x > 2.78215965, then we get the simpler form, but not if I use x > 2.78215964. – Michael E2 Jan 08 '18 at 01:13
  • @JeremyUpsal Could you check the timings for the two integrals on your system? I'm using V11.2, and I'm curious if you get the same results. Thanks. – Michael E2 Jan 08 '18 at 16:38
  • 1
    @MichaelE2 My timing is 0.746089 and 1.5535 for w and x respectively. If I change the assumption to x>2.78215965 the time increases to 1.66046 but gives the simpler form. If I change the assumption to x>2.78215964 the time increases more to 1.72901 and does not give the correct form. – Jeremy Upsal Jan 08 '18 at 17:33
4

Since both answers are equivalent, there is no bug. The algorithm merely provides different representations due to some internal choice(s).

$Version

"11.2.0 for Mac OS X x86 (64-bit) (September 11, 2017)"

Assuming[Element[#, Reals], 
   Integrate[1/(1 + y^2)*1/(y - #), {y, -Infinity, Infinity}, 
    PrincipalValue -> True]] & /@ {a, b, i, l, t, v, w, x, z}

(* {Log[(-1)^(1/(1 + a^2))*E^(Pi/(I - a))], 
   Log[(-1)^(1/(1 + b^2))*E^(Pi/(I - b))], 
   Log[(-1)^(1/(1 + i^2))*E^(Pi/(I - i))], 
   Log[(-1)^(1/(1 + l^2))*E^(Pi/(I - l))], 
   Log[(-1)^(1/(1 + t^2))*E^(Pi/(I - t))], 
   Log[(-1)^(1/(1 + v^2))*E^(Pi/(I - v))], 
   -((Pi*w)/(1 + w^2)), 
   Log[(-1)^(1/(1 + x^2))*E^(Pi/(I - x))], 
   Log[(-1)^(1/(1 + z^2))*E^(Pi/(I - z))]} *)

To get the simplified form for each

Assuming[Element[#, Reals], 
   Integrate[1/(1 + y^2)*1/(y - #), {y, -Infinity, Infinity}, 
      PrincipalValue -> True] // 
     ComplexExpand[#, TargetFunctions -> {Re, Im}] & // Simplify] & /@ 
  {a, b, i, l, t, v, w, x, z}

(* {-((a*Pi)/(1 + a^2)), -((b*Pi)/(1 + b^2)), -((i*Pi)/(1 + i^2)), 
   -((l*Pi)/(1 + l^2)), -((Pi*t)/(1 + t^2)), -((Pi*v)/(1 + v^2)), 
   -((Pi*w)/(1 + w^2)), -((Pi*x)/(1 + x^2)), -((Pi*z)/(1 + z^2))} *)
Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198