Constructing Martingales from Markov Processes I know that for a Markov process $X_t$ with generator $L$ and $f,f^2\in D(L)$, $$M_t=f(X_t)-\int_0^t Lf(X_s)\ ds$$ is a martingale (w.r.t. $P^x$). And I want to show that $$M_t^2-\int_0^t (Lf^2(X_s)-2f(X_s)Lf(X_s))\ ds$$ is a martingale. Using the first martingale, I know that $f^2(X_t)-\int_0^t Lf^2(X_s)\ ds$ and so this would reduce the problem to showing that $$M_t^2 = f^2(X_t) + \int_0^t 2f(X_s)Lf(X_s)\ ds,$$ but I am having trouble showing that. Is this the right avenue of attack or should I try something else? 
 A: Unfortunately, we cannot expect that the equality
$$M_t^2 = f^2(X_t) + \int_0^t 2f(X_s) L f(X_s) \, ds$$
holds, so we have to use a different approach.

By the very definition of $M_t$, we have
$$f^2(X_t) = \left( M_t+ \int_0^t Lf(X_r) \, dr \right)^2,$$
i.e.
$$M_t^2 = f^2(X_t) - 2 M_t \int_0^t Lf(X_r) \, dr - \left( \int_0^t Lf(X_r) \, dr \right)^2.$$
Obviously, this implies
$$M_t^2 - \int_0^t (Lf^2(X_r)-2f(X_r) Lf(X_r)) \, dr = \left[ f^2(X_t)- \int_0^t L f^2(X_r) \, dr \right] - N_t$$
where
$$N_t := 2 M_t \int_0^t Lf(X_r) \, dr + \left( \int_0^t Lf(X_r) \, dr \right)^2 -2 \int_0^t f(X_r) Lf(X_r) \, dr.$$
Since we already know that $(f^2(X_t) - \int_0^t L f^2(X_r) \, dr)_t$ is a martingale, it suffices to show that $(N_t)_{t \geq 0}$ is a martingale. This is a rather messy calculation. First of all, since $(M_t)_{t \geq 0}$ is a martingale we obtain from the tower property that
$$\begin{align*}&\quad  \mathbb{E}\left( M_t \int_0^t Lf(X_r) \, dr \mid \mathcal{F}_s \right) \\&= \mathbb{E}(M_t \mid \mathcal{F}_s) \int_0^s Lf(X_r) \, dr + \int_s^t \mathbb{E} \bigg[ \mathbb{E}(M_t Lf(X_r) \mid \mathcal{F}_r) \mid \mathcal{F}_s \bigg] \, dr \\ &= M_s \int_0^s Lf(X_r) \, dr + \mathbb{E} \left( \int_s^t M_r Lf(X_r) \, dr \mid \mathcal{F}_s \right). \end{align*}$$
The first term at the right-hand side is rather convenient, but we have to rewrite the second one. It follows from the definition of $M_t$ that
$$\begin{align*} &\quad \int_s^t M_r Lf(X_r) \, dr \\ &= \int_s^t f(X_r) Lf(X_r) \, dr - \int_s^t \int_0^r Lf(X_v) \, dv Lf(X_r) \, dr \\ &= \int_s^t f(X_r) Lf(X_r) \, dr - \int_s^t \int_0^s Lf(X_v) Lf(X_r) \, dv \, dr - \int_s^t \int_s^r Lu(X_v) Lf(X_r) \, dr \, dv \\ &= \int_s^t f(X_r) Lf(X_r) \, dr -\frac{1}{2} \left( \int_0^t Lf(X_r) \, dr \right)^2 + \frac{1}{2} \left( \int_0^s Lf(X_r) \, dr \right)^2 \end{align*}$$
for any $r \leq s \leq t$. In the last step we have used that$$2 \int_s^t \int_s^r Lf(X_v) Lf(X_r) \, dv \, dr = \left( \int_s^t Lf(X_r) \, dr \right)^2 \tag{1}$$
implies
$$\begin{align*} &\quad \int_s^t \int_0^s Lf(X_v) Lf(X_r) \, dv \, dr + \int_s^t \int_s^r Lf(X_v) Lf(X_r) \, dr \, dv \\ &\stackrel{(1)}{=} \int_s^t \int_0^s Lf(X_v) Lf(X_r) \, dv \, dr + \frac{1}{2} \left( \int_0^t Lf(X_r) \, dr - \int_0^s Lf(X_r) \, dr \right)^2 \\ &= \frac{1}{2} \left( \int_0^t Lf(X_r) \, dr \right)^2 + \frac{1}{2} \left( \int_0^s Lf(X_r) \, dr \right)^2 \end{align*}$$
Adding all up, we find that $(N_t)_{t \geq 0}$ is a martingale.

Remark: If you are interested in more general results, then have a look at the so-called carré-du-champ operator (or mean field operator).
