3
$\begingroup$

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?

$\endgroup$
2

1 Answer 1

6
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ 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? $\endgroup$
    – Lain
    Commented Jul 16, 2023 at 14:21
  • $\begingroup$ (+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.) $\endgroup$
    – Michael E2
    Commented Jul 16, 2023 at 14:33
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Commented Jul 16, 2023 at 14:53
  • $\begingroup$ @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. $\endgroup$
    – Lain
    Commented Jul 17, 2023 at 1:52
  • 1
    $\begingroup$ @LAIN The difference appeared to be locally constant in my tests. $\endgroup$
    – Michael E2
    Commented Jul 17, 2023 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.