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$?
 A: 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)<b(\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(\omega, 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)\} =\bigcap_{m<n}(\{\omega: a(\omega)>q_m\}\cup\{\omega:b(\omega)<q_m\})
$$ 
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.
A: You want $f'(C)=\frac{f(X)-f(Y)}{X-Y}$ on $\{X\not=Y\}$ and $C=X$ on $\{X=Y\}$.
Mean value theorem says that for all $x,y$ there exists $c\in[x,y]$ s.t. $$f(x)-f(y)=f'(c)(x-y).$$
Furthermore the usual proof shows that $c$ can be chosen to be either an argmin or the argmax of $$h_{x,y}:t\in[x,y]\mapsto f(t)-\left(f(x)+\frac{f(x)-f(y)}{x-y}(t-x)\right).$$
If we let:
$$M(x,y)=\max |h_{x,y}|$$
it follows from the Theorem of the Maximum that $M$ is continuous and that the mapping
$$A : (x,y) \mapsto \{t \in [x,y] \: | \: |h_{x,y}(t)| = M(x,y) \}$$
is upper semi-continuous (usc).
Furthermore, let:
$$c_\epsilon(x,y)=\inf\{t \in [x,y] \: | \: |h_{x,y}(t)|>M(x,y)-\epsilon\}.$$
Let $\delta > 0$ and approximate $c_\epsilon(x,y)$ by $t$ s.t. $|h_{x,y}(t)| > M(x,y) - \epsilon$ and $t<c_\epsilon(x,y) + \delta$.
By continuity these two inequalities remain true in the neighborhood of $(x,y)$, so in this neighborhood $c_\epsilon$ remains lower than $t$, and thus lower than $c_\epsilon(x,y) + \delta$.
This proves that $c_\epsilon$ is upper semi-continuous.
An upper semi-continuous function $g$ is also measurable, because for each $\alpha$, the set $g^{-1}(]-\infty,\alpha[)$ is open.
Furthermore, by continuity of $f$, for all $x,y$ when $n \rightarrow +\infty$:
$$c_{n^{-1}}(x,y) \longrightarrow c(x,y) := \min \{t \in [x,y] \: | \: |h_{x,y}(t)|=M(x,y)\}.$$
A simple limit of measurable functions is also measurable, and by construction we want to just let $C=c(X,Y)$.
