I am attempting to solve a double integral $ $ I(t) = \int_0^t dt’ \int_0^{t’} dt” f(t”)$ $ of a piecewise function of the type $ $ f(t) = \begin{cases}1 & \text{for } 0 \leq t < a \ -1 & \text{for } t>a\end{cases}$ $ with Mathematica. One can easily verify that for $ t>a$ this should evaluate to $ $ I(t) = \frac12 t (4 a – t) – a^2 $ $ However, if I try to solve in Mathematica using

`Simplify[Integrate[Integrate[Piecewise[{{1, 0 <= ttt < a}, {-1, a <= ttt}}], {ttt, 0, tt}], {tt,0, t}], {t > a > 0}] `

The result I get is

`-(1/2) t (-4 a + t) `

I.e. it is obviously missing the $ -a^2$ .

I am puzzled why this is happening. Am I simply too stupid to use Mathematica’s Piecewise/Integrate function correctly? If instead of the variable $ a$ I plug in a number, say 1, everything seems to evaluate correctly.