Derivative of an integral on a set-intersection If $f$ is a real-valued integrable function, $a\in \mathbb{R}$ is some constant, and 
$$F(x):= \int_{t\in [a,x]}f(t)dt,$$
then:
$$F'(x) = f(x)$$
What if, for some constant set $B\subseteq \mathbb{R}$:
$$F(x):= \int_{t\in [a,x]\cap B}f(t)dt,$$
How can $F'(x)$ be expressed (in terms of $f$ and $B$) in this case?
 A: Let $\mu$ denote Lebesgue measure. Assume $f$ is measurable on $[a, b]$, that $B \subset [a, b]$ is measurable, and define
$$
F(x) = \int_{[a, x] \cap B} f,\quad a < x < b.
$$
If $f$ is continuous at $x$, and if the "local density of $B$ at $x$"
$$
\delta(x) := \lim_{h \to 0} \frac{1}{h}\, \mu([x, x + h] \cap B)
$$
exists, then
$$
F'(x) = f(x) \delta(x).
$$
Indeed,
\begin{align*}
\left\lvert F'(x) - f(x) \delta(x)\right\rvert
  &= \left\lvert\left(\lim_{h \to 0} \frac{F(x + h) - F(x)}{h}\right) - f(x) \delta(x)\right\rvert \\
  &= \lim_{h \to 0} \left\lvert\frac{1}{h} \int_{[x, x+h] \cap B} \bigl(f - f(x)\bigr)\right\rvert \\
  &\leq \lim_{h \to 0} \frac{1}{|h|} \int_{[x, x+h] \cap B} \bigl|f - f(x)\bigr| \\
  &\leq \lim_{h \to 0} \frac{1}{|h|} \int_{x}^{x+h} \bigl|f - f(x)\bigr|,
\end{align*}
which is zero because $f$ is continuous at $x$.
(The preceding conditions on $f$ and $B$ are not necessary. For instance, $|f|$ could be sufficiently small in a neighborhood of $x$ and the local density of $B$ at $x$ fails to exist, or $f$ could be discontinuous but the local density of $B$ at $x$ is zero.)
