# Wrong result from integral(log(1+1/(x**2+1)), x, -oo, oo)

Symbolic integration gives result with wrong sign (integrand is positive):

sage: z = integrate(log(1 + 1/(x**2 + 1)), x, -oo, oo); z
2*pi - 2*sqrt(2)*pi
sage: z.n()
-2.60258056913715
sage: numerical_integral(log(1 + 1/(x**2 + 1)), -oo, oo)
(2.6025805691369728, 5.127078281515988e-10)


Sage 8.3

edit retag close merge delete

Sort by » oldest newest most voted

By default, Sage uses Maxima which indeed gets it wrong.

sage: integrate(log(1 + 1/(x**2 + 1)), x, -oo, oo, algorithm='maxima')
2*pi - 2*sqrt(2)*pi


Nonetheless, Sympy and Giac both get it right:

sage: integrate(log(1 + 1/(x**2 + 1)), x, -oo, oo, algorithm='sympy')
-2*pi + 2*sqrt(2)*pi
sage: integrate(log(1 + 1/(x**2 + 1)), x, -oo, oo, algorithm='giac')
2*pi*(sqrt(2) - 1)

more

To elaborate Sebastien's answer, which is quite correct :

sage: foo=log(1+(1/(x^2+1))).integrate(x) ; foo
x*log(1/(x^2 + 1) + 1) + 2*sqrt(2)*arctan(1/2*sqrt(2)*x) - 2*arctan(x)
sage: bar=log(1+(1/(x^2+1))).integrate(x, algorithm="sympy") ; bar
x*log(1/(x^2 + 1) + 1) + 2*sqrt(2)*arctan(1/2*sqrt(2)*x) - 2*arctan(x)
sage: bool(bar==foo)
True


Maxima and Sympy get the same primitive. But

sage: foo.limit(x=oo)
-pi + sqrt(2)*pi


Correct.

sage: foo.limit(x=-oo)
pi - sqrt(2)*pi


Also correct

sage: foo.limit(x=oo)-foo.limit(x=-oo)
-2*pi + 2*sqrt(2)*pi


Still correct.

sage: log(1+(1/(x^2+1))).integrate(x,-oo,oo)
2*pi - 2*sqrt(2)*pi


Wrong. Maxima's problem isn't about primitive determination, but its use...

more

So where should we fix this?

( 2018-08-29 16:10:55 +0200 )edit

So where should we fix this?

In Maxima, it seems...

( 2018-08-29 23:50:09 +0200 )edit