Possible error in solving Improper integral

NIntegrate[ArcTan/(x^2 - x + 1), {x, 0, Infinity}]

1.89941
 Integrate[ArcTan[x]/(x^2 - x + 1), {x, 0, Infinity}] // N

1.89941 - 3.64593 I !!!

Integrate[ArcTan[x]/(
  x^2 - x + 1), {x, 0, Infinity}] -> ( x -> (1 - y)/(1 + y )) -> 
  Integrate[(2 ArcTan[(1 - y)/(1 + y)])/(1 + 3 y^2), {y, -1, 1}] -> 
   2 Integrate[(Pi/4 - ArcTan[y])/(1 + 3 y^2), {y, -1, 1}] -> 
    Pi/2  Integrate[ 1/(1 + 3 y^2), {y, -1, 1}] - 
      2 Integrate[ArcTan[y]/(1 + 3 y^2), {y, -1, 1}] -> \[Pi]^2/(
      3 Sqrt[3])  - 0

N[\[Pi]^2/(3 Sqrt[3])]

1.89941

improper-integral.nb (6.97 KB)

Let us try a workaround. The primitive given by Mathematica is discontinuous:

f[x_] = Integrate[ArcTan[x]/(x^2 - x + 1), x]
Plot[f[x], {x, 0, Infinity}]

This is where the discontinuity occurs:

FunctionDiscontinuities[f[x], x, Complexes];
FullSimplify[%, Element[x, Reals]]

The full integral can be calculated this way:

disc = 2 + Sqrt[3];
f0 = f[0];
fdisc0 = Limit[f[x], x -> disc, Direction -> "FromBelow"];
fdisc1 = Limit[f[x], x -> disc, Direction -> "FromAbove"];
finfinity = Limit[f[x], x -> Infinity];
finfinity - fdisc1 + fdisc0 - f0 // FullSimplify
% // N

This appears to be a bug in Integrate.

This comment can be deleted.

Another way:

It seems that FullSimplify changes the numerical value of an expression a lot:

In[69]:= a = finfinity - fdisc1 + fdisc0 - f0;
a // N
FullSimplify[a] // N

Out[70]= -0.474852 - 1.19435 I

Out[71]= 1.89941 + 0. I

FullSimplify might not have changed the numeric value at all. What might instead have changed is their numerical conditioning. This can be checked by using e.g. N[...,50].

In[21]:=
Integrate[ArcTan/(x^2 - x + 1), {x, 0, Infinity}] // FullSimplify

Out[21]= 1/(
 288 Sqrt[
  3]) (121 \[Pi]^2 - 
   36 (ArcCos[2]^2 - 4 Log[2] Log[28 - 16 Sqrt[3]] + 
      2 Log[8 - 4 Sqrt[3]]^2 + 
      4 (PolyLog[2, 1 - (-1)^(1/6)] + 
         PolyLog[2, 1/2 ((2 + I) - Sqrt[3])] + 
         PolyLog[2, 2/((2 - I) + Sqrt[3])] + 
         PolyLog[2, 2/((2 + I) + Sqrt[3])])))

In[22]:= N[%]

Out[22]= 1.89941 - 3.20494*10^-17 I

Is it Accuracy that does a poor job here?

int = Integrate[ArcTan[x]/(x^2 - x + 1), {x, 0, Infinity}];
int // N
% // Accuracy

When you used N without a second argument, it works with machine numbers and Accuracy/Precision are not really meaningful since they are not tracked.

Jose,

What you show using FullSimplify is fine of course. I believe there may be a version- or timing-dependent bug wherein it can give an inequivalent result. Yours is correct and the use of simplification also makes it numerically “nice” (as in well-conditioned).

I may need to file a report about this, if I find that it is incorrect in our development version.

— edit —
I have filed a report.
— end edit —