# On the mean value theorem for random variables.

Let $$X,Y$$ be two random variables that take values in $$\mathbb{R}$$ and let $$f$$ be a continuous and differentiable function on $$\mathbb{R}$$.

Then does there always exist a random variable $$C$$ such that $$f(X) - f(Y) = f'(C) (X-Y)$$

If $$X,Y$$ are discrete random variables it seems easy to find such a $$C$$ through the standard mean value theorem. In the continuous case are we guaranteed the existence since $$C$$ would be a (measurable ?) function of $$X,Y$$?

## This question has an open bounty worth +50 reputation from Monolite ending in 3 days.

The question is widely applicable to a large audience. A detailed canonical answer is required to address all the concerns.

The only issue is, of course, the measurable choice. If you recall how the mean value theorem is proved, you'll almost immediately reduce the question to the following:

Let $$\Omega$$ be a measure space, $$a,b:\Omega\to\mathbb R$$ be two measurable functions such that $$a(\omega) for all $$\omega\in\Omega$$, $$g:\Omega\times \mathbb R\to\mathbb R$$ be a function that is continuous in the second variable for each fixed value of the first one and measurable in the first variable for each fixed value of the second one. Show that there exists a measurable function $$z:\Omega\to\mathbb R$$ such that $$a(\omega)\le z(\omega)\le b(\omega)$$ and $$g(z(\omega))=\max_{x\in[a(\omega),b(\omega)]}g(\omega,x)$$ for every $$\omega\in\Omega$$.

Now it is time to recall how one proves that every continuous function attains its maximum on every compact interval. Any pseudo-constructive proof will work; all you need is to make sure that you run a countable procedure and check only countably many conditions at each step. I'll just choose the one that is shortest to write down.

Enumerate the rationals: $$\mathbb Q=\{q_n\}_{n\ge 1}$$. Define $$n_1(\omega)$$ to be the least index such that $$q_{n_1(\omega)}\in [a(\omega),b(\omega)]$$. Then $$n_1:\Omega\to\mathbb N$$ is measurable: $$\{\omega: n_1(\omega)=n\}=\{\omega:a(\omega)\le n\le b(\omega)\}\cap\bigcap_{mq_m\}\cup\{\omega:b(\omega) and, thereby, $$\omega\mapsto g(\omega,q_{n_1(\omega)})$$ is measurable as well: $$\{\omega:g(\omega,q_{n_1(\omega)})>t\}=\bigcup_{n\in\mathbb N}(\{\omega:n_1(\omega)=n\}\cap\{\omega:g(\omega,q_n)>t\})$$ I've spelled these out just to show you what sort of tricks are involved. The measurability of the next one is left to you as an exercise (you can use that $$n_1$$ and $$g(\omega,q_{n_1(\omega)})$$ are measurable, of course).

Define $$n_2(\omega)$$ to be the first index such that $$q_{n_2}\in[a(\omega),b(\omega)]$$ and $$g(\omega, q_{n_2(\omega)})>g(\omega,q_{n_1(\omega)})$$, if such $$n_2$$ exists; otherwise put $$n_2=n_1$$.

Once you figure out how to show the measurability of $$n_2$$ and $$g(\omega,q_{n_2(\omega)})$$, proceed to $$n_3$$, etc. in the same way. Finally just take $$z(\omega)=\limsup_{k\to\infty}q_{n_k(\omega)}$$.

Of course, one can, probably, drop some nuke here (look up "measurable selection theorems") but I thought that it might be instructive to do something like this by hand and from scratch once, hence this post.