Message Boards Message Boards

1
|
2254 Views
|
8 Replies
|
9 Total Likes
View groups...
Share
Share this post:

Integrate function yielding two different answers

I am really hoping someone can help with this. I am getting two different results when using Integrate in Mathematica using the exact same integrand. When there is a new Kernel, the integral evaluates to one values, and after that, successive running of the Kernal yields a different result running the exact same integrand. Except, after the Kernel has been run more than once, the result doesnt change. The problem is that when you compare the two results, they are not equal.

Why would Mathematica evaluate the exact same integrand to two different results just because of successive running of the Kernel? And more concerning, why are the two results not equal.

Outline of Evaluations below:

In[1]:= Integrate[  (m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/Sqrt[
  1 - v^2/c^2] + (m0 v^3)/(
  c0^2 Sqrt[1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(
  c^2 (1 - v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(
  Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v  ]

Out[1]= (m0 (-2 v^2 + 2 c^2 Sqrt[-1 + v^2/c0^2] - 
   Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
     ArcTan[(c^2 + c0^2 - 2 v^2)/(
     2 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2])]))/(2 Sqrt[
 1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

In[2]:= Integrate[  (m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/Sqrt[
  1 - v^2/c^2] + (m0 v^3)/(
  c0^2 Sqrt[1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(
  c^2 (1 - v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(
  Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v  ]

Out[2]= (m0 (-v^2 + c^2 Sqrt[-1 + v^2/c0^2] + 
   Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
     ArcTan[Sqrt[-c0^2 + v^2]/Sqrt[c^2 - v^2]]))/(Sqrt[
 1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

In[3]:= (
 m0 (-2 v^2 + 2 c^2 Sqrt[-1 + v^2/c0^2] - 
    Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
      ArcTan[(c^2 + c0^2 - 2 v^2)/(
      2 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2])]))/(
 2 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]) === (
 m0 (-v^2 + c^2 Sqrt[-1 + v^2/c0^2] + 
    Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
      ArcTan[Sqrt[-c0^2 + v^2]/Sqrt[c^2 - v^2]]))/(
 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

Out[3]= False
Attachments:
POSTED BY: Tim Kirkpatrick
8 Replies

Thank you, all, for your replies in input. This has all been extremely helpful. Seeing the comments about internal cahce states actually sounds familiar, and would explain why futher reduction might be possible after running the initial cache, but not subsequent runs.

Again, thank you, all.

POSTED BY: Tim Kirkpatrick

What Henrik Schachner and Gianluca Gorni wrote sums it up.

(1) An antiderivative is correct if its derivative recovers the integrand.

(2) Different antiderivatives can result from differences in the internal cache states or timing differences in various places that might use time-constrained attempts.

POSTED BY: Daniel Lichtblau

I think I heard that Integrate caches some intermediate results when it is run. Next time you run it, Integrate is in a different internal state, and this may be the reason it gives a different answer, but still valid. Someone from Wolfram may comment on this.

POSTED BY: Gianluca Gorni

Tim,

you made a good observation! But I guess that both results are correct: They do not need to be identical because you are just asking for an antiderivative:

(* -- start with a fresh kernel -- *)
li = List[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
     Sqrt[1 - v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
        1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
          v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
        1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v];
(* here you get different results: *)
i1 = Integrate @@ li
i2 = Integrate @@ li
(* but: *)
D[i1, v] - D[i2, v] // FullSimplify
(*  Out:   0 *)

Nevertheless this is a somewhat strange effect.

POSTED BY: Henrik Schachner

Henrik, Thank you for this analysis. This is a good test and a creative way to test their equivalence. It is an oddity though; even when I pass values for all of the parameters and test i1===i2, it still returns False.

It occurs to me, testing D[i1,v]===D[i2,v] is testing the equivalence of the integrand though; which we know to be correct because the integrand doesn't change in either of the inputs i1,i2. I think this is relevant because it appears that the issue is with the function "Integrate[]"; something odd is going on where it returns two different values that are not equivalent. Is there some kind of simplification that is occurring in error?

POSTED BY: Tim Kirkpatrick

I just copied and pasted the results directly from Mathematica. And yes, the arguments within ArcTan change after the same expression is run more than once in the same Kernel. That is what doesn't make any sense.

I ran your script and I still get False for comparison.

In[1]:= i1 = 
 Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
    Sqrt[1 - 
      v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
       1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
         v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
       1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]

i2 = Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
    Sqrt[1 - 
      v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
       1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
         v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
       1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]

i1 === i2

Out[1]= (m0 (-2 v^2 + 2 c^2 Sqrt[-1 + v^2/c0^2] - 
   Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
     ArcTan[(c^2 + c0^2 - 2 v^2)/(
     2 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2])]))/(2 Sqrt[
 1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

Out[2]= (m0 (-v^2 + c^2 Sqrt[-1 + v^2/c0^2] + 
   Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
     ArcTan[Sqrt[-c0^2 + v^2]/Sqrt[c^2 - v^2]]))/(Sqrt[
 1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

Out[3]= False
POSTED BY: Tim Kirkpatrick

Actually, using Expand really highlights the problem even more. It is entirely associated with the ArcTan function. The answer changes after being run more than once in the same Kernel.

In[1]:= i1 = 
 Expand[  
  Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
     Sqrt[1 - 
       v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
        1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
          v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
        1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]  ]

i2 = Expand[  
  Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
     Sqrt[1 - 
       v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
        1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
          v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
        1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]  ]

i1 === i2

Out[1]= (c^2 m0)/Sqrt[1 - v^2/c^2] - (m0 v^2)/(
 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]) - (
 m0 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
   ArcTan[(c^2 + c0^2 - 2 v^2)/(
   2 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2])])/(
 2 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

Out[2]= (c^2 m0)/Sqrt[1 - v^2/c^2] - (m0 v^2)/(
 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]) + (
 m0 Sqrt[c^2 - v^2] Sqrt[-c0^2 + v^2]
   ArcTan[Sqrt[-c0^2 + v^2]/Sqrt[c^2 - v^2]])/(
 Sqrt[1 - v^2/c^2] Sqrt[-1 + v^2/c0^2])

Out[3]= False
POSTED BY: Tim Kirkpatrick

Look at the ArcTan arguments in the comparison. Copy/paste error?

i1 = Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
    Sqrt[1 - 
      v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
       1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
         v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
       1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]

i2 = Integrate[(m0 v^3)/(c^2 (1 - v^2/c^2)^(3/2)) + (m0 v)/
    Sqrt[1 - 
      v^2/c^2] + (m0 v^3)/(c0^2 Sqrt[
       1 - v^2/c^2] (-1 + v^2/c0^2)^(3/2)) - (m0 v^3)/(c^2 (1 - 
         v^2/c^2)^(3/2) Sqrt[-1 + v^2/c0^2]) - (m0 v)/(Sqrt[
       1 - v^2/c^2] Sqrt[-1 + v^2/c0^2]), v]

i1 === i2
(* True *)

$Version
(* 13.2.0 for Mac OS X ARM (64-bit) (November 18, 2022) *)
POSTED BY: Rohit Namjoshi
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