# Unclear result from Leibniz Integral Rule

I was trying to answer this question: $$\frac{\mathrm d}{\mathrm dt}\int_{t-\mathrm d1}^t \int_h^t f(s) \,\mathrm ds\,\mathrm dh$$. I got the accepted answer by hand (using the Leibniz integral rule) but why does Mathematica (and Maple) give the seemingly wrong $$\mathrm d_{{1}}f \left( t \right) \color{orange}{-}\int_{t-\mathrm d_{{1}}}^{t}\!f \left( s \right) \,{\rm d}s=\mathrm d_{{1}}f \left( t \right) \color{orange}{-}F \left( t \right) \color{orange}{+} F \left( t-\mathrm d _{{1}} \right)$$ instead of $$\mathrm d_{{1}}f \left( t \right) \color{lime}{+}\int_{t-\mathrm d_{{1}}}^{t}\!f \left( s \right) \,{\rm d}s=\mathrm d_{{1}}f \left( t \right) \color{lime}{+}F \left( t \right) \color{lime}{-} F \left( t-\mathrm d _{{1}} \right)$$

The Mathematica code I used is D[Integrate[Integrate[f[s], {s, h, t}], {h, t - d1, t}], t].

• I think Mathematica is right, but I have dyslexia. I could be wrong. May 27, 2020 at 13:29
• Until the observed behavior has been confirmed by other users to be a bug, do not use the bugs tag. May 27, 2020 at 13:29
• You can write the integral more simply as D[Integrate[f[s], {h, t - d1, t}, {s, h, t}], t] - you don't need to write Integrate twice. May 27, 2020 at 13:33
• @flinty Note it is a different computation that is supposed to be mathematically equivalent. If you think there's a bug, the form might be important. In this case, I think it's irrelevant. I think Leponzo made a mistake in the by-hand check. May 27, 2020 at 13:39
• Sometimes, to make it easier on myself, I work with a negative-index Derivative[]: D[Integrate[Derivative[-1][f][t] - Derivative[-1][f][h], {h, t - d1, t}], t]. May 27, 2020 at 13:55

Let the inner integral result be $$F(t)-F(h)$$ where $$F$$ is the antiderivative of $$f$$. Then break $$\int_{t-d1}^{t}F(t)-F(h)\mathrm{dh}$$ into $$\int_{t-d1}^{t}F(t)\mathrm{dh}$$ and $$-\int_{t-d1}^{t} F(h)\mathrm{dh}$$.

The first integral is just $$hF(t)\Big|_{t-d1}^{t}=t F(t)-(t-d1)F(t)=d1 F(t)$$.

The second integral is $$-\int_{t-d1}^{t} F(h)\mathrm{dh}=G(t-d1)-G(t)$$ where $$G$$ is the antiderivative of $$F$$.

Differentiate with respect to $$t$$ and we get: $$\frac{d}{dt}\left[d1 F(t) +G(t-d1)-G(t)\right]=d1 F'(t)+G'(t-d1)-G'(t) \\ =d1f(t)+\left[F(t-d1)-F(t)\right]=d1f(t)-\left[F(t)-F(t-d1)\right]$$ I added the brackets for emphasis. Notice how $$\left[F(t)-F(t-d1)\right]$$ is just $$\int_{t-d1}^{t}f(h)\mathrm{dh}$$ we set up at the start. Therefore without needing the Leibniz rule at all Mathematica is correct in saying: D[Integrate[Integrate[f[s], {s, h, t}], {h, t - d1, t}], t] == d1*f[t] - Integrate[f[s], {s, -d1 + t, t}]

• Slightly modifying the code I posted in an earlier comment: D[Integrate[Derivative[-1][f][t], {h, t - d1, t}] - Integrate[Derivative[-1][f][h], {h, t - d1, t}], t]. May 27, 2020 at 15:32
• Ah yes I didn't realize Derivative[-1][f][t] was a thing. Hopefully seeing it step by step assures Leponzo this is not a bug. May 27, 2020 at 15:36
• Thanks! I added my own version of the answer (consistent with Mathematica, Maple, and the Leibniz integral rule) here (although I still can't pinpoint where the accepted answer there went wrong). May 27, 2020 at 17:42
• @MichaelE2 Still didn't get what's wrong :( May 27, 2020 at 22:29
• @Leponzo your answer there looks fine to me. May 27, 2020 at 22:41