3

I have done a symbolic integration in mathematica 13.2 as follow

Integrate[-((Sqrt[-r(r - 2 l)] l)/(r(r - 2 l) (-r + l))), r] // Simplify[#, r > 0] &

Integrate[-((Sqrt[-r(r - 2 l)] l)/(r(r - 2 l) (-r + l))) /. {l -> \[ScriptL]}, r] // Simplify[#, r > 0] &

All that I have done is simply the replacement of "l" with "scl", but mathematica gives two very different symbolic outputs

OutPut[1]enter image description here

OutPut[2]enter image description here

Why? Can I use special symbols in integration safely?

xzczd
  • 65,995
  • 9
  • 163
  • 468
Lain
  • 133
  • 5
  • 2
    Related: https://mathematica.stackexchange.com/q/25182/1871 https://mathematica.stackexchange.com/q/223577/1871 https://mathematica.stackexchange.com/q/22071/1871 https://mathematica.stackexchange.com/q/103323/1871 https://mathematica.stackexchange.com/q/43108/1871 There may be more. – xzczd Jul 16 '23 at 13:40
  • 1
    Definite integrals are more reliable since they cannot differ by a constant but usually slower to compute. However, in V13.3.0, while these produce the same answer, the answer is Undefined under the assumptions: Integrate[-((Sqrt[-r (r - 2 l)] l)/(r (r - 2 l) (-r + l))), {r, 0, r}, Assumptions -> {2 l > r > 0}] and Integrate[-((Sqrt[-r (r - 2 l)] l)/(r (r - 2 l) (-r + l))) /. {l -> \[ScriptL]}, {r, 0, r}, Assumptions -> {2 \[ScriptL] > r > 0}]. This is seems a bug, whereas the different results in the indefinite integrals above I would call unsurprising and not a bug. – Michael E2 Jul 16 '23 at 14:25

1 Answers1

6

I'd call this a bug. I've seen cases where the letter makes difference in result (internally some code seems to use lexicographic ordering in some places? and this have this side effect of changing the expression form which affects some code). So this is not really new in Mathematica. It does not have to be special character for this to happen. I've put some related links at bottom

Here is a simpler example than your's showing this, also using Rubi to compare

Mathematica 13.3

ClearAll["Global`*"]
integrand1=z/Sqrt[-(r*(r-2*z))]

Mathematica graphics

anti1=Integrate[integrand1,r]

Mathematica graphics

ReImPlot[anti1/.z->2,{r,-Pi,Pi},PlotRange->All]

Mathematica graphics

Now simply change z to q in the integrand. Now the anti-derivative is completely different

integrand2=integrand1/.z->q

Mathematica graphics

You see the integrand is same as before, just q instead of z

anti2=Integrate[integrand2,r]

Mathematica graphics

ReImPlot[anti2/.q->2,{r,-Pi,Pi},PlotRange->All]

Mathematica graphics

Rubi

Here changing the letter did not make difference as expected.

Quit[]
<<Rubi`
integrand1=z/Sqrt[-(r*(r-2*z))]
anti1=Int[integrand1,r]

Mathematica graphics

ReImPlot[anti1/.z->2,{r,-Pi,Pi},PlotRange->All]

Mathematica graphics

integrand2 = integrand1 /. z -> q
anti2 = Int[integrand2, r]

Mathematica graphics

ReImPlot[anti2 /. q -> 2, {r, -Pi, Pi}, PlotRange -> All]

Mathematica graphics

related links

Simplification depends on the names of variables

Why does simplification in Mathematica depend on variable names

Variable naming changes everything

Apart behaves differently depending on specific alphabetic letters of variables

DSolve—different solutions for same set of equations using different symbols?

Evaluating two equivalent integrals apparently gives two different results

Nasser
  • 143,286
  • 11
  • 154
  • 359
  • Thanks for your helpful reply. I wonder if there are some effective methods or say packages as you have shown, Rubi, to avoid this bug? – Lain Jul 16 '23 at 14:21
  • (+1) I would not call this a bug. Variable ordering makes a difference in symbolic algebra. (Simple example: Reduce[x < y < x^2 - x - 6, {x, y}] and Reduce[x < y < x^2 - x - 6, {y, x}].) Obviously, Integrate[] cannot know what ordering was used or will be used in the next call to Integrate[]. (Maybe it could be improved. For example, parameters after integration variables. That's Daniel's call.) – Michael E2 Jul 16 '23 at 14:33
  • @LAIN One does not have even to go Reduce for an example. The standard ordering leads to a different coefficient on r after simplification: {-((Sqrt[-r (r - 2 l)] l)/(r (r - 2 l) (-r + l))), -((Sqrt[-r (r - 2 l)] l)/(r (r - 2 l) (-r + l))) /. {l -> \[ScriptL]}} // Simplify. And the different coefficient leads to a different antiderivative. I think that would make it hard to give a consistent result, because it depends on the internal ordering. I doubt WRI would implement a option-defined ordering to be used in sorting Orderless functions like Plus. – Michael E2 Jul 16 '23 at 14:53
  • @MichaelE2 It is true that in indefinite integrals, the difference between two results can often be a constant. However, based on the figures that Nasser has shown, it appears that the difference in the imaginary part is not a constant. – Lain Jul 17 '23 at 01:52
  • 1
    @LAIN The difference appeared to be locally constant in my tests. – Michael E2 Jul 17 '23 at 02:09