# Using subscripted symbol affects integration — why?

Below is a sample program that shows that Integrate is giving different results depending on whether I name the variable duration1 or duration. Anyone know why? Am I better off not using subscripts?

Remove["Global*"]
$Assumptions = duration > 0 && duration1 > 0 && duration2 > 0 && t > 0 && t < duration + duration2 && t < duration1 + duration2 jer1a = Sin[(Pi*t)/duration] ; jer1b = Sin[(Pi*t)/duration1] ; jer2 = 1; constants = {duration -> 6, duration1 -> 6, duration2 -> 5}; jerks1a = {jer1a, jer2}; jerks1b = {jer1b, jer2}; boundaries1a = {t <= duration, True}; boundaries1b = {t <= duration1, True}; jer1a = Piecewise[Transpose[{jerks1a, boundaries1a}]] jer1b = Piecewise[Transpose[{jerks1b, boundaries1b}]] acc1a = Integrate[jer1a /. t -> $$t, {t, 0, t}, Assumptions -> {t \[Element] Reals}] // Simplify; acc1b = Integrate[jer1b /. t ->$$t, {$t, 0, t},
Assumptions -> {t \[Element] Reals}] // Simplify;
Print["Original: ", jer];
Print["Integrate with duration: ", acc1a];
Print["Integrate with duration1: ", acc1b];


Here's the output: I know the results are equivalent mathematically. But why would the use of indexing cause one result to specially handle the case of t == duration while the other does not?

that Integrate is giving different results

It is the same result. Just written different. I suppose due to lexical ordering difference between a and a? and may be some different internal code path was used when variable was indexed vs. not? But both final results are equivalent.

Plot[acc1a /. duration -> 2, {t, -3, 3}] Plot[acc1b /. duration1 -> 2, {t, -3, 3}] Table[(acc1a - acc1b) /. {duration -> n, duration1 -> n,
t -> 1}, {n, -3, 3}] // N Update

it is surprising and counter-intuitive (to me at least) that one piecewise function explicitly handles the case of t== duration while the other doesn't.

It is the same. In the case of duration1 it says

 (duration1 - duration1*Cos[(Pi*t)/duration1])/Pi, duration1 >= t   (*1*)


It combined the = with the > in one statement. While in the case of duration it handled the = on its own, and > on its own.

For = it said

     (2*duration)/Pi, t == duration    (*2*)


And if we plug in duration1=t in (1) it gives

 (duration1 - duration1*Cos[(Pi*t)/t])/Pi


Which simplifies to

 (duration1 - duration1*Cos[Pi])/Pi


Which simplifies to

 (duration1 + duration1)/Pi


Which simplifies to

 2 * duration1 /Pi


Which is the same as (2) for duration1=t

So they are the same Piecewise` in both cases.

Why are they written differently? Who knows. We do not have the source code of Mathematica internals to look and find out. It is clearly related to using index variable, which made it go to different code path.

But as long as the result is the same Mathematically, why is it so important they are written differently?

• Yeah, I didn't mean that the results were different mathematically. I should have been more specific -- it is surprising and counter-intuitive (to me at least) that one piecewise function explicitly handles the case of t== duration while the other doesn't. I'll edit the question to be more specific. – Dan Sandberg Apr 21 at 22:28
• I'm doing a complex integration of integration of integration, and so keeping the results as simple as possible is important to keep things performant. My understanding was that symbols were treated the same as an indexed symbol, and the fact that this isn't true is surprising and good to know. Ideally there'd be some way to get the results both ways, so that I could keep using symbols since they make the code a little cleaner. – Dan Sandberg Apr 22 at 8:45