Why the difference in the results of Integrate and NIntegrate?

Bug introduced in version 12.0.0, and persisting through 13.2.0 on Windows. Doesn't reproduce on ARM Mac versions 13.0.0 and above.

Calculating the integral $$\int\limits_0^1 \frac{x^2\log(1-x^4)} {1+x^4}\,dx$$ symbolically

Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}]


-4 + 2 Catalan - 1/4 \[Pi] (-2 + Log[8]) + Log[8]

N[%]


-0.151021

and numerically

NIntegrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}]


-0.162858

, I obtain different numbers and the difference is too much for round-off errors. How to preclude the end of math?

• This is a bug worth reporting to Support. In 11.3, Integrate[] returns the (complicated but) correct answer, so something happened in between that version and 12.2. (Someone else who can check 12 and 12.1 should add the requisite bug header to this question.) Commented Feb 26, 2021 at 8:29
• Work correctly in MA 11.1.1 with the integration result $\frac{1}{144} \left(8 \left(6 \text{Hypergeometric2F1}^{(0,0,1,0)}\left(\frac{3}{4},1,\frac{7}{4},-1\right)+\sqrt{2} \log (8)-6 \sqrt{2} \log \left(2-\sqrt{2}\right)\right)+3 \sqrt{2} \left(-3 \pi ^2-8 \pi -2 \log ^2(8)+7 \pi \log (8)-6 (\pi -2 \log (8)) \log \left(2-\sqrt{2}\right)\right)\right)$ Commented Feb 26, 2021 at 8:41
• Maple 2020.2 int gives the same result the the numerical one. This looks like bug in integrate. screen shot !Mathematica graphics -0.1628582917 + 0.*I Commented Feb 26, 2021 at 8:47
• @Nasser: In fact, Maple reduces the integral under consideration to the sum of other integrals. Commented Feb 26, 2021 at 8:50
• Version 12.1 gives also: -0.162858 Commented Feb 26, 2021 at 9:13

This bug was introduced in version 12.0. Please submit bug report to [email protected] or https://www.wolfram.com/support/contact/

• Submitted. No response. Commented Feb 26, 2021 at 9:26
• @user64494. General, you have to wait a few days. Commented Feb 26, 2021 at 15:22

One way:

Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, I, 1}]

N@%

(*  -0.162858 - 4.44089*10^-16 I  *)


Another way:

Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1/2, 1}]

N[%]

(*  -0.162858 - 2.28333*10^-16 I  *)

• Thank you. It's interesting. The question arises: why Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, I, 1}]==Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0,1}]? The imaginary unit is a singularity (a branch point) of the integrand so the application of the Cauchy's theorem is not clear to me. Also we deal with improper integrals. The command Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, I, 1}] returns the input on my comp in several minutes. As far as I understand it, you simply do NIntegrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, I, 1}]. Commented Feb 27, 2021 at 6:13
• The same issue with Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1/2, 1}]. Corollary: this is not it. Commented Feb 27, 2021 at 6:53
• -1. I repeat again: you calculate its numerical value in a weird way only. The symbolic result is not obtained. Commented Feb 27, 2021 at 10:07
• @user64494 You made a mistake. Commented Feb 27, 2021 at 15:12
• @user64494 your downvoting is unjustified and unfair. If you omit the evaluation with N[], the Integrate[] does return a (complicated!) symbolic result, which Michael has mercifully omitted. Commented Feb 27, 2021 at 17:06

The integration with help of Rubi gives after inserting the limits:

(1/(4*Sqrt[2]))*(Pi*Log[2] - Log[(Sqrt[2] + 1)^2]*Log[2] +
PolyLog[2, -(Sqrt[2] + 1)^2] - PolyLog[2, (Sqrt[2] - 1)^4]/2 +
Re[4*PolyLog[2, I*(Sqrt[2] - 1)] - 4*PolyLog[2, I*(Sqrt[2] + 1)] +
PolyLog[2, (Sqrt[2] + 1)^2 + I/1000000000000]] +
Im[-8*(PolyLog[2, I*(Sqrt[2] - 1)] + PolyLog[2, I*(Sqrt[2] + 1)]) +
2*PolyLog[2, (Sqrt[2] + 1)^2 + I/1000000000000]]/2)


which I don't know how to further simplify. The small imaginary offset in the argument of the PolyLog 'pushes' the sign of its imaginary part to the positive side. Otherwise the numeric result would be wrong.

Addendum: the imaginary part of the mentioned PolyLog is

2*Pi*Log[Sqrt[2] + 1]


so the result can be written

(1/(4*Sqrt[2]))*( Pi^2/3 + Pi*(2*Log[Sqrt[2] + 1] + Log[2]) -
2*Log[Sqrt[2] + 1]*(Log[Sqrt[2] + 1] + Log[2])-PolyLog[2, (Sqrt[2] - 1)^2] +
PolyLog[2, -(Sqrt[2] + 1)^2] - (1/2)*PolyLog[2, (Sqrt[2] - 1)^4] +
Re[4*PolyLog[2, I*(Sqrt[2] - 1)] - 4*PolyLog[2, I*(Sqrt[2] + 1)]]
-4*Im[PolyLog[2, I*(Sqrt[2] - 1)] + PolyLog[2, I*(Sqrt[2] + 1)]])


2.Addendum: The last may be further simplified to

(1/(4*Sqrt[2]))*(Pi^2/3 + Pi*Log[2]+2*Pi*Log[Sqrt[2]+1] -
2*Log[1+Sqrt[2]]*Log[2*(1+Sqrt[2])]-2*PolyLog[2,(Sqrt[2]-1)^2] - (Sqrt[2]+1)*
LerchPhi[-(Sqrt[2]+1)^2,2,1/2]-(Sqrt[2]-1)*LerchPhi[-(Sqrt[2]-1)^2,2, 1/2])

• Thank you. In fact, Rubi reduces the improper integral under consideration to other integrals through PolyLog. Commented Feb 27, 2021 at 6:05

Strangely, it works when done correctly via limit:

f[a_] = Assuming[0 < a < 1,
Integrate[(x^2 Log[1 - x^4])/(1 + x^4), {x, 0, a}]];
A = Limit[f[a], a -> 1, Direction -> "FromBelow"];
N[A]
(*    -0.162858 - 5.88785*10^-17 I    *)

$Version (* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)  The Limit command throws a Limit::ztest warning though, which may indicate some trouble. • Roman(@ does not work.):+1. Thank you. f[a_] returns a big expression with many PolyLogs. I think Rubi finds that integral in such a way. Also that works with 0<a<=1 too, but Mathematica has problems with its evaluating for a->1: it returns (0.08838834764831844055010555+0.08838834764831844055010555 I) ((-0.9908537560314543211012304-0.1349401132293848328673948 I) \[Infinity]+(0.1349401132293848328673948+0.9908537560314543211012304 I) \[Infinity]+(0.5388161543132108251339676-0.8424233804038929803675840 I) \[Infinity]+... Commented Feb 27, 2021 at 13:24 • @user64494 To quote the commenting instructions: "Note that the author of the post will always be notified of any new comment. You may still use it for clarity, if needed; however, if there are no comments, or only you or the author have commented on the post so far, the @name will be automatically removed from the beginning of the comment, as it adds no value. (To avoid breaking sentences, mentions not at the beginning will not be removed.)" Commented Feb 27, 2021 at 14:40 • @user64494 Concerning evaluation at$a=1$: yes, that's precisely why I used a Limit instead of simply asking for f[1]. Keep in mind that Mathematica returns general results that may be inapplicable on some special points, like$a=1$in this case even if you specify the assumption$0<a\le1$. Commented Feb 27, 2021 at 14:52 • As I understand it, f[a_] produces a very long expression with many compound functions. Its evaluation exeeds some internal Mathematica limitations (something like $MaxIterations=100) and this causes problems. Maybe, it is possible to increase these limitations. Commented Feb 27, 2021 at 16:16

From 13.2.0 we see that is takes a while

int = Integrate[
x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}]; // AbsoluteTiming


and that the results agree

Chop[Chop@N[int] - NIntegrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}]]


I am providing the analytic result as well

int // ToRadicals // Factor


• Fixed in 13.0.0, modified bug comment. Commented Feb 4, 2023 at 9:43
• Cannot reproduce it in 13.2 on Windows 10. I obtain int = Integrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}] // AbsoluteTiming results in {294.976, -4 + 2 Catalan - 1/4 \[Pi] (-2 + Log[8]) + Log[8]} and then Chop[Chop@N[int] [[2]]- NIntegrate[x^2*Log[1 - x^4]/(1 + x^4), {x, 0, 1}]] produces 0.0118378. Maybe, the result depends on a session. See dropbox.com/s/6m39559x8lia92i/… Commented Feb 4, 2023 at 11:30
• @user64494 not sure why this is happening. on my mac it worked fine as you can see. could be session-dependent as you said, but perhaps it relates to the OS(?).
– bmf
Commented Feb 4, 2023 at 11:39