Message Boards Message Boards

0
|
707 Views
|
9 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Different result integrating with integer bounds vs floating point bounds

I found an interesting bug (I think) involving the difference between using integer bounds and floating point bounds when integrating in Mathematica:

enter image description here

Why is it that this integral evaluates to positive pi when using integer bounds but -pi when using floating point bounds? What am I missing?

POSTED BY: Baiza Mand
9 Replies

As noted in the corresponding MSE post, a bug report has been filed for this.

POSTED BY: Daniel Lichtblau
Posted 1 month ago

There is no problem in version 12.3:

enter image description here

POSTED BY: Hans Milton

Try this:

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

The -2Pi jump discontinuity at zero looks like a branch cut, but of what function?

POSTED BY: Gianluca Gorni

Hmm here is what that looks like: enter image description here

I also did a few tests around the edge cases: enter image description here

Interestingly, if either bound in the integral is floating point, it gives me -pi and if I use an integer lower bound and a floating point 0.99999 upper bound, I still get -pi. But, if I use floating point -0.99999 as lower bound and integer 1 upper bound, it gives me +pi. This also works if the upper bound is 1.0.

Interestingly, y with t set to 0.99999 is +pi, but my output 42 should be equivalent to that and it is -pi. Is anyone able to interpret what is going on?

POSTED BY: Baiza Mand

POSTED BY: Gianluca Gorni

Hmm.. what is the difference between this: enter image description here

and this: enter image description here

POSTED BY: Baiza Mand

It is the order of evaluation. In one example the integral is computed with a symbolic endpoint first, and then the symbol is replaced with numbers. In the other example the numeric endpoint is generated first, and then the integral is computed. It appears that different integration algorithms are called in the two situations, with different branch cuts.

POSTED BY: Gianluca Gorni

Let:

 ExactNumberQ[1]
 (*True*)

Then give exact answer (by symbol and precision) :

 Integrate[2 Sqrt[1 - x^2], {x, -1, 1}]
 (*PI*)

If:

ExactNumberQ[1.0]
(*False*)
Integrate[2 Sqrt[1 - x^2], {x, -1, 1.0}]
(*-3.14159*)

Gives no-exact solution an approximation.

 numbers = {1, 1., Pi, N[Pi, 7]};
 TableForm[
  Table[{x, ExactNumberQ[x], InexactNumberQ[x], Precision[x], 
    Head[x]}, {x, numbers}], 
  TableHeadings -> {{}, {"x", "exact", "approximate", "Precision", 
     "Head"}}]

enter image description here

A minus sign in a numerical calculation suggests an incorrect result.Looks like is a bug.

Regards M.I.

POSTED BY: Mariusz Iwaniuk

Very strange. Here is a variation:

Integrate[2 Sqrt[1 - x^2], {x, -1., 1/1000000}]
-4.712386980384691`

which is close to 3 Pi/2.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract