Why should the format of an integral affect the result

This has been reported to Wolfram and confirmed as a bug in Mathematica V12

This follows on from This question

I get a different answer for the same integral input in different ways e.g.

Integrate[Log[(Sin[k] + Sqrt[1 + Sin[k]^2])^2], {k, 0, π}]
(* 4 Catalan + π Log[2] *)

\!$$\*SubsuperscriptBox[\(∫$$, $$0$$, $$π$$]$$Log[\((Sin[ k] + Sqrt[1 + Sin[k]^2])$$^2] \[DifferentialD]k\)\)
(* 4 Catalan *)


Numerical integration confirms that the second result is correct.

See the screenshot for a clearer view of what I did

As a further point of evidence, I get the correct answer if I wrap it in Hold, and then release it:

ReleaseHold[
Hold[Integrate[Log[(Sin[k] + Sqrt[1 + Sin[k]^2])^2], {k, 0, π}]]]
(* 4 Catalan *)

• On 12.0.0 for Mac OS X x86 (64-bit) (April 7, 2019) the result is 4 Catalan for both. Sep 28 '19 at 20:35
• On 10.4.1 for Microsoft Windows (64-bit) (April 11, 2016) the result is 4 Catalan for both. Sep 28 '19 at 23:27
• @mikado, I found another amazing behavior. If you change the order of inputs: In[3] and next In[1], then both results are correct. So, probably the correct result is with integral sign (your In[3]) and then MMA caches this somehow and uses with Integrate[...] (your In[1]) and gives right answer. MMA 12, Windows 10.
– Alx
Sep 29 '19 at 1:05

1 Answer

The format appears to be a distraction. I get a different answer on the second time I evaluate the integral.

Quit[]

Hold[
Integrate[Log[(Sin[k] + Sqrt[1 + Sin[k]^2])^2], {k, 0, π}]]

ReleaseHold[%]
(* 4 Catalan + π Log[2] *)

ReleaseHold[%%]
(* 4 Catalan *)

\$Version
(* "12.0.0 for Linux x86 (64-bit) (April 7, 2019)" *)