# Different result integrating with integer bounds vs floating point bounds

Someone posted this question at community

https://community.wolfram.com/groups/-/m/t/3178350

Since little attention is paid for it there, I thought here will get more.

Integrate[2  Sqrt[1 - x^2], {x, -1, 1}]


Gives $$\pi$$ but

Integrate[2  Sqrt[1 - x^2], {x, -1.0, 1.0}]


Gives

 -3.14159


Why was the question. Clearly some kind of floating point issue. (Never mind that one should not use real numbers with symbolic function as Integrate, but this is a big difference.)

I verified this on V 14 on windows.

ps. I wanted to make this community question, since it is not my question, but I do not see the tick which is normally on lower right corner to click on? If someone knows how to change this to community question please do so. I do not want to get virtual point credits for asking this since not my question so please do not upvote this question.

Found workaround !

 Integrate[2  Sqrt[1 - x^2], {x, -1.0, 1.0},  GenerateConditions -> True]


Now gives

3.14159


This screen shot shows this including another second example taken also from the link above which was also fixed by adding GenerateConditions -> True

Very strange, since GenerateConditions -> True should be the default. I have no idea why this made it work. I was trying different options to see what happens. May be someone knows why adding this explicit option made it now work.

• Only Version 11.3,12.2, 12.3.1 get the right result 3.14159 Commented May 18 at 1:26
• Another workaround is Integrate[2 Sqrt[1 - x^2], {x, -1.0, 0.0, 1.0}] (* 3.14159 *) in the cloud version 14.0.0. Commented May 18 at 6:22
• Another workaround is Integrate[2 Surd[1-x^2, 2], {x, -1.0, 1.0}] (* 3.14159 *) in the cloud version 14.0.0. But Integrate[2 Surd[1-x^2, 2], {x,-1.0, 0.5, 1.0}] (* -1.73211*10^-9-3.14159 I *) -- complex! Commented May 18 at 7:10
• Assumptions -> -1. < x < 1. is also a workaround. Commented May 18 at 22:41
• The bug seems to be that it offsets the limits of integration by shifting both down by $10^{-9}$, perhaps because of singularities or because of that and floating-point. That is, Integrate[2 Sqrt[1 - x^2], {x, -1.0, 1.0}] is precisely equal to the real part of Limit[Integrate[2 Sqrt[1 - x^2], x], x -> #, Direction -> 1] & /@ {-1 - (1)*10^-9, 1 - (1)*10^-9} // Differences // N. Of course, I've always said that it's better to give exact input to exact solvers. Commented May 19 at 0:12

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

Integrate[2   Sqrt[1 - x^2], {x, -1, 1}]

(* π *)

NIntegrate[2   Sqrt[1 - x^2], {x, -1.0, 1.0}]

(* 3.14159 *)

Integrate[2   Sqrt[1 - x^2], {x, -1.0, 1.0}]

-3.14159


Use higher precision when using inexact numbers with Integrate

Table[
{prec, Integrate[2   Sqrt[1 - x^2],
{x, SetPrecision[-1.0, prec], SetPrecision[1.0, prec]}] //
Chop // N},
{prec, 5, 40, 5}] // Grid[#, Frame -> All] &
`