Let $f\colon\mathbb R^2\to\mathbb R$ be a measurable function such that
\begin{equation\*}
 F(t):=\int\_{\mathbb R}dx\,f(t,x) 
\end{equation\*}
exists and is finite for all real $t$. Suppose that
\begin{equation\*}
 f\_t(t,x):=\frac{\partial f(t,x)}{\partial t}
\end{equation\*}
exists and is finite for all real $t,x$, and also suppose that
\begin{equation\*}
 \int\_{\mathbb R}dx\, f\_t(t,x) 
\end{equation\*}
exists and is finite for all real $t$.


Then, under certain additional conditions,
\begin{equation\*}
 F'(t)=\int\_{\mathbb R}dx\, f\_t(t,x) \tag{1}\label{1}
\end{equation\*}
for all real $t$; see e.g. [Folland, Theorem 2.27](http://home.ustc.edu.cn/%7Eluke2001/pdf/realfolland.pdf) or the more general [Lemma 2.3](https://projecteuclid.org/journals/annals-of-probability/volume-43/issue-5/Exact-Rosenthal-type-bounds/10.1214/14-AOP942.full).


Among counterexamples to \eqref{1} are [this](https://mathoverflow.net/a/105773/36721) and [this](https://mathoverflow.net/a/172898/36721). However, in those counterexamples the function $f$ is not continuous.


A [question](https://mathoverflow.net/questions/436209/expected-gradient-vs-gradient-of-expectation/436224#comment1123964_436224) arose whether there is a counterexample to \eqref{1} with a continuous function $f$. Such an example will be given in the answer below.



Counterexamples to differentiation under integral sign, revisited
A simple example is given by
$$
f(t,x)=\cases{\exp(-(x-t^{-2})^2),&$t\neq 0$,\\0,&$t=0.$}
$$
For each fixed $t\neq 0$, $\int f(t,x)\,dx$ is a Gaussian integral equal to $\sqrt{\pi}$, while for $t=0$, the integral equals to zero. Therefore, $F(t)$ is not even continuous at $0$, let alone differentiable.


On the other hand, at $t\neq 0$, any partial derivative of $f$ has a form $P(t^{-1},x)\exp(-(x-t^{-2})^2)$ for some polynomial $P$. This tends to zero as $t\to 0$, uniformly in $x$ in compacts. Therefore, $f$ is smooth with all partial derivatives vanishing on at $\mathbb{R}$. Also, any expression of this form, and in particular $\partial\_t f(t,x)$, is clearly integrable over $x$ for all $t$.


**Update:** The above example may feel like cheating, since in essence the discontinuity of $f$ has just been moved to infinity. Here's a better one in that respect:


$$
f(t,x)=\cases{\mathrm{sign}(t)|t|^\frac{1}{2}\exp\left(-\frac{(x-\sqrt[5]{t})^2}{|t|}\right),&$t\neq 0$,\\0,&$t=0.$}
$$
This has $F(t)=\sqrt{\pi}t$ while still $\partial\_t f(t,x)|\_{t=0}\equiv 0$. It has an additional feature that
$$
\int\_I\partial\_t f(t,x)\,dx\neq\partial\_t \int\_I f(t,x)\,dx
$$
for any non-empty interval $I$ containing the origin. It has smooth restrictions onto vertical and horisontal lines, but it is not overall smooth or even continuously differentiable: indeed, if it were, it would have its derivatives bounded on compacts, thus $\int\_I$ and $\partial\_t$ would commute for any compact interval $I$.


