# Do symbolic integration of function including \[ScriptCapitalL]

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]

OutPut[2]

Why? Can I use special symbols in integration safely?

• Commented Jul 16, 2023 at 13:40
• 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. Commented Jul 16, 2023 at 14:25

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))]


anti1=Integrate[integrand1,r]


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


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

integrand2=integrand1/.z->q


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

anti2=Integrate[integrand2,r]


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


## Rubi

Here changing the letter did not make difference as expected.

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


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


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


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


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

• 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
Commented Jul 16, 2023 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.) Commented Jul 16, 2023 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. Commented Jul 16, 2023 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
Commented Jul 17, 2023 at 1:52
• @LAIN The difference appeared to be locally constant in my tests. Commented Jul 17, 2023 at 2:09