Suppose we have a double Markov relation for three random variables $X$, $Y$ and $W$ as follows
$$X\to W\to Y,$$ and $$X\to Y\to W.$$


How to prove that there exist functions $f$ and $g$ such that 
$$X\to f(Y)\to Y, W$$ and $$\Pr(f(Y)=g(W))=1?$$



Double Markovity
I think I could prove the existence of such functions but however, I can not show that we must have $X\to f(Y)\to Y, W$. However the proof for the first part might give some insight for the latter. 


Suppose random variables $X$, $Y$ and $W$ are defined over alphabets $\mathcal{X}$, $\mathcal{Y}$ and $\mathcal{W}$.


Note than we can write $P\_{X|YW}(\cdot|y, w)=P\_{X|Y}(\cdot|y)=P\_{X|W}(\cdot| w)$ from the double Markov relation. Now define $E\_{x}:=\{y:~P\_{X|Y}(x|y)=P\_{X|Y}(x|1)\}$. Since $1\in E\_{x}$, we have $P\_{Y}(E\_{x})>0$. The fact that $P\_{Y}(E\_{x})=1$ for all $x\in\mathcal{X}$ implies that $X$ and $Y$ are independent. Hence if they are not independent, then there exist $x\_0\in\mathcal{X}$ such that $0<P\_Y(E\_{x\_0})<1$. Now setting $F:=\{w:~P\_{X|W}(x\_0|w)=P\_{X|Y}(x\_0|1)\}$, we conclude from the fact $P\_{X|Y}(\cdot|y)=P\_{X|W}(\cdot|w)$ that $P\_{YW}(E\_{x\_0}^c\times F)=P\_{YW}(E\_{x\_0}\times F^c)=0$.


Hence there exist some subsets of $\mathcal{Y}$ and $\mathcal{W}$ like $E$ and $F$ such that each $(y, w)$ belong to each of $E\times F$. Let $J$ be the random variable which indexes this subsets. It is clear that $J$ is a deterministic function of $Y$ and $W$ and so there exist functions $f$ and $g$ such that $J=f(Y)=g(W)$. 


