# Why do Integrate and DSolve/DSolveValue yield such complex expressions for Piecewise functions?

This code uses two different methods for integrating a very simple piecewise function but yields surprisingly complicated integrals:

jer1 = Sin[(Pi*t)/duration1] ;
jer2 = 1;
constants = {duration1 -> 6, duration2 -> 5};

jerks = {jer1, jer2};
boundaries = {t < duration1, t < duration1 + duration2};

jer = Piecewise[Transpose[{jerks, boundaries}]]
acc1 = Integrate[jer /. t -> $$t, {$$t, 0, t},
Assumptions -> {t \[Element] Reals}] // Simplify;
acc2 = DSolveValue[{y'[t] == jer, y == 0}, y[t], t] // Simplify;
Print["Original: ", jer];
Print["Integrate gives: ", acc1];
Print["DSolveValue gives: ", acc2];
domain = {t, 0, duration1 + duration2} /. constants;
Plot[jer /. constants, domain, PlotRange -> Full]
Plot[acc1 /. constants, domain, PlotRange -> Full]
Plot[acc2 /. constants, domain, PlotRange -> Full]


The expressions created in acc1 and acc2 are much more complicated than I would expect. Any idea why neither of these functions yield a simple "Piecewise" function like the input? The complexity ends up mattering as I integrate to get velocity and position Mathematica gets bogged down and isn't able to get an answer in a reasonable amount of time.

Here's the output: • It doesn't look that complicated to me, it's just covering all the cases. Try adding more assumptions, like duration1 > 0 && duration2 > 0, that shortens it somewhat. Apr 21 '20 at 17:16
• Oh, strange, I got rid of those assumptions when simplifying the problem for posting, but I guess this means more assumptions would be helpful. In particular if I add the assumption t < duration1+duration2, then it simplifies to be as simple as the original formula being integrated. Thanks! Apr 21 '20 at 18:15

You need to provide everything you know about the problem and use that information at all opportunities. For example, presumably duration1 and duration2 are positive. If so, this needs to be included in the assumptions. And the assumptions need to be provided to all functions that accept the option Assumptions. The Assuming construct makes this easier.

jer1 = Sin[(Pi*t)/duration1];
jer2 = 1;
constants = {duration1 -> 6, duration2 -> 5};

jerks = {jer1, jer2};


Presumably, you do not want the function undefined at t == duration1, change boundaries to

boundaries = {t < duration1, t <= duration1 + duration2};

jer = Piecewise[Transpose[{jerks, boundaries}]];

acc1 = Assuming[
{t ∈ Reals, duration1 > 0, duration2 > 0},
Integrate[jer /. t -> $$t, {$$t, 0, t}] //
FullSimplify] acc2 = Assuming[
{t ∈ Reals, duration1 > 0, duration2 > 0},
DSolveValue[{y'[t] == jer, y == 0}, y[t], t] //
FullSimplify] 