Taking derivative of an integral involving an indicator function Edit: I realized this problem might be better solved as 'derivative of integral with variable in bounds and integrand', e.g. this post.
I'm trying to take the derivative of a double integral, and the variable to be differentiated is inside the integral limits, so I use the indicator function to move the variable $a$ to the integrand. The original integral is
$$
\frac{d}{da} \int_{-\infty}^{+\infty} \int_{-a-z}^{a-z} b^2 f(b) g(z) db dz.
$$
Use the indicator function for the integration limits $b \in [-a-z, a-z]$, the integral becomes
$$
\frac{d}{da} \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 1\{ -a \leq b+z \leq a \} f(b) g(z) db dz,
$$
where $f,g: \mathbb{R} \to (0, +\infty)$ and their form unknown, and $b^2 f(b) g(z)>0$ for any $(b,z) \in \mathbb{R}^2 \setminus \{(0,0)\} $. What I tried is below, taking derivative of the indicator function inside the integral:
\begin{align}
\begin{split}
&\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 \frac{d}{da} [ 1\{ a \geq -(b+z) \} \cdot 1\{ b+z \leq a \} ] f(b) g(z) db dz \\
=& \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 \frac{d}{da} [ 1\{ a \geq -(b+z) \} ] \cdot 1\{ b+z \leq a \} f(b) g(z) db dz \\
&+ \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 1\{ a \geq -(b+z) \} \cdot \frac{d}{da} [ 1\{ b+z \leq a \}] f(b) g(z) db dz \\
=& \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2  \delta(-(b+z)-a) \cdot 1\{ a \geq b+z \} f(b) g(z) db dz \\
&+ \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 1\{ a \geq -(b+z) \} \cdot \delta((b+z)-a) f(b) g(z) db dz,
\end{split}
\end{align}
and $\delta(\cdot)$ is the dirac measure. So $\delta(-(b+z)-a) =1$ if and only if $-(b+z)-a=0$, if and only if $a = -(b+z)$, which means $1\{ a \geq b+z \} = 1\{ -(b+z) \geq b+z \} = 1\{ b+z\leq0 \}$. Similarly $\delta((b+z)-a) =1$ if and only if $a=b+z$, which means $1\{ a \geq -(b+z) \} = 1\{ b+z \geq -(b+z) \} = 1\{b+z \geq0 \}$. Plug into the integral, get
\begin{align}
\begin{split}
&\int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2  1\{ b+z\leq0 \} f(b) g(z) db dz + \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 1\{b+z \geq0 \} f(b) g(z) db dz\\
=& \int_{-\infty}^{+\infty} \int_{-\infty}^{+\infty} b^2 f(b) g(z) db dz,
\end{split}
\end{align}
which is obviously wrong. I have trouble identifying the mistake. For the derivative of the indicator function, I used this post and
$$
\frac{d}{da} 1\{ a \geq b+z \} = \frac{d}{da} [1 - 1\{ a \leq b+z \}]
= -(-\delta(a-(b+z))) = \delta(a-(b+z)) = \delta((b+z)-a),
$$
and the last equality is because 'symmetry' of dirac measure.
Can anyone take a look and point out my mistake? Thank you.
 A: I'd avoid the indicator function entirely, since such expressions tend to be awkward to work with due to their limited algebraic properties. Instead, tackle the problem using the first expression for the integral. Take the $\frac{\mathrm{d}}{\mathrm{d}a}$ sign under the integral signs using two applications of the Leibniz integral rule, and factor out the $g(z)$ term from the inner integral since it is independent of the variable being integrated against, $b$. This leaves you with a single integral of an expression in $f, g$, which will definitely not have a general closed form. So that will be the most general solution you can hope for, without knowing more about the particular properties of $f,g$.
$$\begin{align}
I&=\frac{\mathrm{d}}{\mathrm{d}a} \int_{-\infty}^{+\infty} \int_{-a-z}^{a-z} b^2 f(b) g(z) \,\mathrm{d}b \,\mathrm{d}z
\\
&=\frac{\mathrm{d}}{\mathrm{d}a} \int_{-\infty}^{+\infty} g(z)\int_{-a-z}^{a-z} b^2 f(b)  \,\mathrm{d}b \,\mathrm{d}z
\\
&=\int_{-\infty}^{+\infty} g(z)\frac{\mathrm{d}}{\mathrm{d}a}\int_{-a-z}^{a-z} b^2 f(b)  \,\mathrm{d}b \,\mathrm{d}z
\\
&=\int_{-\infty}^{+\infty} g(z)\left((a-z)'(a-z)^2 f(a-z) -(-a-z)'(-a-z)^2 f(-a-z) -\int 0\right) \,\mathrm{d}z
\\
&=\int_{-\infty}^{+\infty} g(z)\left[(a-z)^2 f(a-z) +(-a-z)^2 f(-a-z)\right]\,\mathrm{d}z
\end{align}$$
As a general word of advice, I'd avoid attempting to solve problems by reframing them in terms of the unwieldy sorts of functions associated with discontinuous, chopped-up ranges, including $1(\cdot),\operatorname{sign}(\cdot),|\cdot|,\lfloor\cdot\rfloor,\lceil\cdot\rceil, \max(),\min()$, and so on. They have very few useful algebraic properties, and unless your problem actually involved them to begin with, I don't think they tend to help. For instance, by virtue of their abundant useful properties, it's straightforward to integrate a polynomial, such as $\int (x^2-2x-1) \,\mathrm{d}x=\frac13x^3-x^2-x+C$, but doing so with the sign value of the same expression requires some awkward evaluations of conditions $\int \operatorname{sign}(x^2-2x-1) \,\mathrm{d}x=\begin{cases}x+C_1,&x<-(\sqrt{2}-1)\\-x+C_2,&-(\sqrt{2}-1)<x<(\sqrt{2}+1)\\\ldots\end{cases}$
And I'd also suggest avoiding using overpowered methods where elementary ones are sufficient, such as using the theory of distributions on an elementary integral of real-valued functions. We call this approach "using a sledgehammer to crack a nut". See MSE Q798215. It is generally considered inelegant as it tends to skip all the logical directness and intuition that the elementary proof should have been providing. It's like using a Rube Goldberg machine to achieve something that could have been done directly.
