Independence of the results of an XOR operation to the operands

1.8k Views Asked by At

I had a doubt regarding a question in the book Introduction to Probability by Joseph K. Blitzstein and Jessica Hwang. I seem to have gotten stuck in the second part of the question. The question goes as the follows

For x and y binary digits (0 or 1), let $x \oplus y$ be 0 if x = y and 1 if x != y (this operation is called exclusive or (often abbreviated to XOR), or addition mod 2 ).

(a) Let X ~ Bern(p) and Y ~ Bern(1/2), independently. What is the distribution of $X \oplus Y$ ?

(b) With notation as in (a), is $X \oplus Y$ independent of X? Is $X \oplus Y$ independent of Y ? Be sure to consider both the case $p = 1/2$ and the case $p != 1/2$

My approach

a) X ~ $Bern(p)$ and Y~ $Bern(1/2)$ independently So to construct the distribution of $X \oplus Y$ we create a table for the results. The table is as follows. Let $X \oplus Y$ be Z

           X       Y       Z
           0       0       0
           0       1       1
           1       0       1
           1       1       0      

As X ~ $Bern(p)$ and Y~ $Bern(1/2)$ independently ,$P(X=1) = p$ and $P(Y=1) = 1/2$

So using the above information, we can construct the PMF of Z

$P(Z=0|X=0,Y=0)$= $(1-p)*(1/2)$

$P(Z=1|X=0,Y=1)$= $(1-p)*(1/2)$

$P(Z=1|X=1,Y=0)$= $(p)*(1/2)$

$P(Z=0|X=1,Y=1)$= $(p)*(1/2)$

So therefore the PMF of $Z$ will be [$(1-p)/2$,$(1-p)/2$,$(p)/2$,$(p)/2$].

The distribution will look like a step function.

Sanity Check: The PMF of all the instances of Z should add up to 1.

$(1-p)/2$+$(1-p)/2$+$(p)/2$+$(p)/2$= $(1-p+1-p+p+p)/2$ = $2/2$ = $1$

b) For independence between $X$ and $Z$ to satisfy we need to check if the following condition holds true.

$P(Z=i,X=j) = P(Z=i)* P(X=j)$

Let $i$ be 1 and $j$ be 0

So, $P(Z=1) = (1-p)*(1/2)+ (p)*(1/2) = 1/2$

and $P(X=0) = 1-p$

But $P(Z=1,X=0) = 1/4$ because this happens in 1 in 4 cases.

So Z and X are independent as long as $p=1/2$.

Similarly, we find the Z is independent of Y as $P(Y=1)=P(Y=0)=1/2$

I am not sure if this approach is correct as I have not taken the contribution of the third variable (X and Y) into account. Should the concept of LOTP be used here? Thank You in advance!

1

There are 1 best solutions below

0
On

I know this is old but I stumbled on it.

You're reasoning is correct. But If we're concerned with the distribution of $Z = X \oplus Y $, then similarly to $X$ and $Y$, it's also the case that $Z$ takes the values $0$ and $1$. So for the distribution, we're concerned about the Probabilities $P(Z=0)$ and $P(Z=1)$.

The event $\{Z = 0 \}$ is the same event as $(\{X=0\}\cap\{Y=0\}) \cup(\{X=1\}\cap\{Y=1\})$.

Similarly, The event $\{Z=1\}$ is the same as $(\{X=0\}\cap\{Y=1\}) \cup(\{X=1\}\cap\{Y=0\})$.

Because $X$ and $Y$ are independent, we have, $P(\{X=x\}\cap\{Y=y\}) = P(X=x)P(Y=y)$

And Because the events $(\{X=x_i\}\cap\{Y=y_i\})$ and $(\{X=x_j\}\cap\{Y=y_j\})$ are mutually exclusive, The probability of their union is the sum of their probabilities.

So putting it all together we have, $$\begin{aligned} P(Z=1) &= P((\{X=1\}\cap\{Y=0\}) \cup(\{X=0\}\cap\{Y=1\})) \\ \\ &=P(\{X=1\}\cap\{Y=0\}) + P(\{X=0\}\cap\{Y=1\}) \\ \\ &= P(X=1)P(Y=0) + P(X=0)P(Y=1) \\ \\ &= p\times\frac{1}{2} + (1-p) \times \frac{1}{2} \\ \\ &= \frac{1}{2}\end{aligned}$$

And of course $P(Z=0) = 1-P(Z=1) = \frac{1}{2}$

So $Z \sim Bern(\frac{1}{2})$ this answers a.

As for b, It asks if $Z$ is independent of $X$ and if it's independent of $Y$.

$Z$ is independent of $Y$ $\iff$ $ \forall z,y \in \{0,1\}, \, P(Z=z,Y=y) = P(Z=z)P(Y=y)$

Lets consider $P(Z=0,Y=1)$. This corresponds to the event that $(\{Z=0\} \cap \{Y=1\})$ which is equivalent to the event $(\{X=1\}\cap\{Y=1\})$

Similarly, $P(Z=0,Y=0)$, $P(Z=1,Y=1)$, $P(Z=1,Y=0)$

respectively correspond to the events $(\{X=0\}\cap\{Y=0\})$, $(\{X=0\}\cap\{Y=1\})$, $(\{X=1\}\cap\{Y=0\})$

And so we have $$\begin{aligned} P(Z=0,Y=1) &= P(\{X=1\}\cap\{Y=1\}) \\ \\ &= P(X=1)P(Y=1) \\ \\ &= p \times \frac{1}{2} \\ \\ P(Z=0,Y=0) &= P(\{X=0\}\cap\{Y=0\}) \\ \\ &= P(X=0)P(Y=0) \\ \\ &= (1-p) \times \frac{1}{2}\\ \\ P(Z=1,Y=1) &= P(\{X=0\}\cap\{Y=1\}) \\ \\ &= P(X=0)P(Y=1) \\ \\ &= (1-p) \times \frac{1}{2}\\ \\P(Z=1,Y=0) &= P(\{X=1\}\cap\{Y=0\}) \\ \\ &= P(X=1)P(Y=0) \\ \\ &= p \times \frac{1}{2} \end{aligned}$$

So, $\forall z,y \in \{0,1\}$, $P(Z=z,Y=y)$ is either $\frac{p}{2}$ or $\frac{1-p}{2}$. And we know that $P(Z=z)P(Y=y) = \frac{1}{2} \times \frac{1}{2} = \frac{1}{4}$

So $Z$ is independent of $Y$ $\iff$ $\frac{p}{2} = \frac{1-p}{2} = \frac{1}{4}$ $\iff$ $p=\frac{1}{2}$

We can make a very similar argument about $Z$ being independent of $X$ for any $p \in [0,1]$