# Why the difference in the results of Integrate and NIntegrate?

Bug introduced in version 12.0.0, and persisting through 12.2.0.

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) + Log

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.) – J. M.'s ennui Feb 26 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)$ – yarchik Feb 26 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 – Nasser Feb 26 at 8:47
• @Nasser: In fact, Maple reduces the integral under consideration to the sum of other integrals. – user64494 Feb 26 at 8:50
• Version 12.1 gives also: -0.162858 – Daniel Huber Feb 26 at 9:13

## 4 Answers

This bug was introduced in version 12.0. Please submit bug report to support@wolfram.com or https://www.wolfram.com/support/contact/  • Submitted. No response. – user64494 Feb 26 at 9:26
• @user64494. General, you have to wait a few days. – Mariusz Iwaniuk Feb 26 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}]. – user64494 Feb 27 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. – user64494 Feb 27 at 6:53
• -1. I repeat again: you calculate its numerical value in a weird way only. The symbolic result is not obtained. – user64494 Feb 27 at 10:07
• @user64494 You made a mistake. – Michael E2 Feb 27 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. – J. M.'s ennui Feb 27 at 17:06

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

(1/(4*Sqrt))*(Pi*Log - Log[(Sqrt + 1)^2]*Log +
PolyLog[2, -(Sqrt + 1)^2] - PolyLog[2, (Sqrt - 1)^4]/2 +
Re[4*PolyLog[2, I*(Sqrt - 1)] - 4*PolyLog[2, I*(Sqrt + 1)] +
PolyLog[2, (Sqrt + 1)^2 + I/1000000000000]] +
Im[-8*(PolyLog[2, I*(Sqrt - 1)] + PolyLog[2, I*(Sqrt + 1)]) +
2*PolyLog[2, (Sqrt + 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 + 1]


so the result can be written

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


2.Addendum: The last may be further simplified to

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

• Thank you. In fact, Rubi reduces the improper integral under consideration to other integrals through PolyLog. – user64494 Feb 27 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]+... – user64494 Feb 27 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.)" – Roman Feb 27 at 14:40 • @user64494 Concerning evaluation at$a=1$: yes, that's precisely why I used a Limit instead of simply asking for f. 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$. – Roman Feb 27 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. – user64494 Feb 27 at 16:16