Show that X and Y are conditionally independent given Z Let X,Y denote the number of heads in the first and last two flips separately, and Z be the indicator random variable of the second flip. Given a fair coin and independently flip it three times.
\begin{equation}
    X =
      \begin{cases}
         0 & \text{if there are no heads in the first two flips}\\
         1 & \text{if there is exactly one head in the first two flips}\\
         2 & \text{if there is exactly two heads in the first two flips}
      \end{cases}       
\end{equation}
\begin{equation}
    Y =
      \begin{cases}
         0 & \text{if there are no heads in the last two flips}\\
         1 & \text{if there is exactly one head in the last two flips}\\
         2 & \text{if there is exactly two heads in the last two flips}
      \end{cases}       
\end{equation}
\begin{equation}
    Z =
      \begin{cases}
         1 & \text{if the second flip is H}\\
         0 & \text{if the second flip is T}\\
      \end{cases}       
\end{equation}
Show that, X is not independent to Y, but X and Y are conditionally independent given Z.
My attempt:
To show that X is not independent to Y is easy. We can take the case where $\{x,y\}=\{0,0\}$. Then we have that
$$\mathbb{P}(X=0)\cdot\mathbb{P}(Y=0)=\frac{1}{4}\cdot\frac{1}{4}=\frac{1}{16}\neq\frac{1}{8}=\mathbb{P}(X\cap Y)$$
To prove that X and Y are conditionally independent given Z, I was thinking that we need to show that $\mathbb{P}(X=x|Z=z)\mathbb{P}(Y=y|Z=z)=\mathbb{P}(X=x,Y=y|Z=z)$ is true for all combinations of x,y,z. However, this would result in showing the equality is true $3\cdot3\cdot2=18$ times, which seems like a lot of work. Is there a more efficient way of showing this independence? Thank you.
 A: Hint: When given the count for heads in the middle coin, the count for heads in the first and last two coins are each determined by the count for heads in the first and last coin, respectively, -- which are independent.
Let $U$ and $V$ be these counts, and so we have: $X=U+Z$ and $Y=V+Z$.
Thus $U,V,Z\overset{iid}\sim\mathcal U[0,1]$ and taking any $i,j,k$ from $\{0,1\}$, you may show: $$\mathsf P(X{=}i{+}k, Y{=}j{+}k\mid Z{=}k)=\mathsf P(X{=}i{+}k\mid Z{=}k)\mathsf P(Y{=}j{+}k\mid Z{=}k)$$
A:         X     Y     Z
H H H   [2    2]    1
H H T   [2    1]    1
H T H   1     1     0
H T T   1     0     0
T H H   [1    2]    1
T H T   [1    1]    1
T T H   0     1     0
T T T   0     0     0

You don't need to show it 18 times. You can just show it 8 times. Start with Z=1.
$$P(X=2|Y=1)=P(X=2|Y=2)=P(X=2)=\frac 1 2\\
P(X=1|Y=2)=P(X=1|Y=1)=P(X=1)=\frac 1 2$$
Now do it once more for the case Z=0 and you're done. (This uses an equivalent definition of independence that $P(A|B)=P(A)$ means that A and B are independent.)
