# Comparing Closed-form to Numerical Integral Result

When I numerically calculate this integral

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


The result is $$0.416217488896557$$ and I verified it using another tool.

However, when I use

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


The result is

$$\frac{1}{48} \left(-96 C \log (2)+i \left(-192 \text{Li}_3\left(\frac{1}{2}+\frac{i}{2}\right)+105 \zeta (3)+4 \log ^3(2)\right)+7 \pi ^3-24 \pi \log ^2(2)-5 i \pi ^2 \log (2)\right)$$

Numerically, this evaluates to $$4.777566543250842 -2.9605947323337506\times 10^{-16} i$$

Am I doing something wrong?

I am using Mathematica 14.0.0.0 on an x86, 64-bit, Windows 10 machine.

Update I tried it on Mathematica 12.2.0.0 and it left the integral unevaluated and I expected this because I couldn't imagine it would have a closed-form solution.

• This is weird. What is that $C$ supposed to represent in your result? I get the correct result in v14.0 (Win). Can you please try your code again on a fresh kernel (use Quit[]) to remove any possible effects of caching? Commented Apr 2 at 13:37
• @Domen: From a fresh kernel, resolves the problem $$\frac{1}{48} \left(2 i \left(-192 \text{Li}_3\left(\frac{1}{2}+\frac{i}{2}\right)+105 \zeta (3)+4 \log ^3(2)\right)-7 \pi ^3+12 \pi \log ^2(2)-10 i \pi ^2 \log (2)\right)$$ Using Chop, that gives the correct result. I did the same thing earlier by restarting Mathematica, ut the issue persisted.
– Moo
Commented Apr 2 at 13:57
• Good! These things happen ... Please let us know if you can reproduce this issue again (ie. find a sequence of integrations that lead to the wrong result). In this case, it can then be further analyzed or reported to the WRI as a "bug". Commented Apr 2 at 14:04
• @Domen: Just FYI - Please see the latest answer - another person was able to see what I saw and provided a nice workaround.
– Moo
Commented Apr 3 at 1:49

If you do

p = Integrate[(1/2)*Log[1 + Sin[x]]^2, x]
Limit[p, x -> \[Pi], Direction -> "FromBelow"] -
Limit[p, x -> 0, Direction -> "FromAbove"] // FullSimplify


you get

(7*Pi^3)/24 + Pi*Log[2]^2 -
4*I*(PolyLog[3, 1 - I] - PolyLog[3, 1 + I])]


which gives the same result as NIntegrate.

• Thanks - in a new iteration, after restarting the kernel, it produces the correct results - which I had done earlier. The problem persisted but in this round it worked.
– Moo
Commented Apr 2 at 14:01

For me, like the OP's original result,

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


yields

(*
1/48 (7 \[Pi]^3 - 96 Catalan Log[2] - 5 I \[Pi]^2 Log[2] -
24 \[Pi] Log[2]^2 +
I (4 Log[2]^3 - 192 PolyLog[3, 1/2 + I/2] + 105 Zeta[3]))
*)


But

Integrate[(1/2)*Log[1 + Sin[x]]^2, {x, 0, Pi/2, Pi},
Assumptions -> 0 < x < Pi]


yields

(*
1/48 (-7 \[Pi]^3 - 10 I \[Pi]^2 Log[2] + 12 \[Pi] Log[2]^2 +
2 I (4 Log[2]^3 - 192 PolyLog[3, 1/2 + I/2] + 105 Zeta[3]))
*)

N[%, 80]
(*
0.416217488896552119403646053625517279786339361782973377550142 + 0.*10^-61 I
*)


which agrees with the numerical integration.

I've found that sometimes specifying the integration path helps, as it does in this case.

• Thanks for showing that you got the same thing as I did as I felt I had not done anything to cause an errant result. What is even stranger is that using a fresh kernel then generated the correct result. I like your approach of providing as much input as possible to try and avoid these things. +1.
– Moo
Commented Apr 3 at 1:47