Suppose I want to compute the antiderivative of this simple function: $$f(t)=\begin{cases} 1 & \text{if $0\le t\le t_1$,} \\ -1 & \text{if $t_1\le t\le t_2$}, \\ 0 & \text{otherwise,} \end{cases}$$ where $t\in\mathbb R$ and $0\le t_1\le t_2$. I expect the integral to be defined piecewise with four cases: $$\int_0^t f(s)\,\mathrm ds = \begin{cases} 0 & \text{if $t\le0$,} \\ t & \text{if $0\le t\le t_1$,} \\ t_1 - t & \text{if $t_1\le t\le t_2$,} \\ t_1 - t_2 & \text{if $t_2\le t$.} \end{cases}$$
Instead, Mathematica gives me something extremely complicated:
f[t_] := Piecewise[{{1, 0 <= t <= t1}, {-1, t1 <= t <= t2}, {0, True}}] Integrate[f[s], {s, 0, t}, Assumptions -> t ∈ Reals && 0 <= t1 <= t2] Piecewise[{{-t, t - t2 < 0 && t > 0 && t - t1 > 0 && t1 <= 0}, {t, (t - t1 < 0 && t - t2 > 0 && t > 0 && t1 > 0) || (t - t1 < 0 && t - t2 < 0 && t > 0 && t1 > 0) || (t - t1 < 0 && t - t2 > 0 && t > 0 && t2 <= 0)}, {t1, (t - t1 == 0 && t1 - t2 > 0 && t > 0 && t1 > 0) || (t - t1 == 0 && t1 - t2 < 0 && t > 0 && t1 > 0) || (t - t1 == 0 && t1 - t2 > 0 && t - t2 > 0 && t > 0 && t2 <= 0) || (t - t1 == 0 && t1 - t2 < 0 && t - t2 > 0 && t > 0 && t2 <= 0) || (t - t1 >= 0 && t1 - t2 > 0 && t - t2 > 0 && t > 0 && t1 > 0) || (t - t1 > 0 && t1 - t2 == 0 && t - t2 == 0 && t > 0 && t1 > 0)}, {-t + 2*t1, (t - t1 > 0 && t - t2 < 0 && t1 - t2 > 0 && t > 0 && t1 > 0) || (t - t1 > 0 && t - t2 < 0 && t1 - t2 < 0 && t > 0 && t1 > 0)}, {2*t1 - t2, (t - t1 > 0 && t - t2 == 0 && t1 - t2 > 0 && t > 0 && t1 > 0) || (t - t1 > 0 && t - t2 >= 0 && t1 - t2 < 0 && t > 0 && t1 > 0)}, {-t2, (t - t2 == 0 && t > 0 && t - t1 > 0 && t1 <= 0) || (t - t2 >= 0 && t > 0 && t - t1 > 0 && t1 <= 0 && t2 > 0)}, {t2, (t - t1 == 0 && t1 - t2 == 0 && t > 0 && t1 > 0) || (t - t1 == 0 && t1 - t2 == 0 && t > 0 && t - t2 > 0 && t2 <= 0) || (t - t1 >= 0 && t1 - t2 == 0 && t > 0 && t1 > 0 && t - t2 > 0) || (t - t1 < 0 && t > 0 && t1 > 0 && t - t2 == 0)}}, 0]
Running FullSimplify with the same assumptions simplifies the conditions, but does not reduce the number of cases. This is a problem because the actual function I am interested in has many more cases, and the number of cases in its computed antiderivative seems to be growing exponentially instead of linearly. (For example, try adding another case {1, t2 <= t <= t3} to the definition of f.)
How can I work around this?
Update: The strategy in my answer "works" for the function $$g(t)=\begin{cases} 1 & \text{if $0\le t\le t_1$,} \\ -1 & \text{if $t_2\le t\le t_3$,} \\ 1 & \text{if $t_4\le t\le t_5$,} \\ 0 & \text{otherwise,} \end{cases}$$
g[t_] := Piecewise[{{1, 0 <= t <= t1}, {-1, t2 <= t <= t3}, {1, t4 <= t <= t5}}, 0] giving a piecewise-defined solution with seven cases, but the computation takes an inordinately long time (nearly 90 seconds on my machine). @mikado's suggested alternate style for defining the function makes it even slower. So for me the question is still open.
P.S. This is probably a duplicate of the previous question "Piecewise functions Integration with symbol", but that one does not have any answers.