# Functions of random variables and conditional probability

Suppose I have two random variables $X,Y$ over some finite set and a function $f$ such that

$\forall z \in Image(f) \, Prob[f(X,Y)=z | X = x] = Prob[f(X,Y) = z]$

Intuitively, I would think that if I now consider the function $h(X,Y) = g(f(X,Y))$ I should have

$\forall w \in Image(h)\, Prob[h(X,Y) = w | X = x] = Prob[h(X,Y) = w].$

However, a simple counterexample shows this is not the case. If we choose $X,Y$ to be uniformly distributed over $\{0,1\}$ and $$f(X,Y) = (-1)^{X+Y}$$ then $f(X,Y)$ and $f(X,Y) | X = x$ both have the same distribution: they are uniformly distributed over $\{-1,1\}.$

However, if I take $g(z) = log_{-1}(z)$, then $h(X,Y) = g(f(X,Y)) = X + Y$ does not have the same distribution as $X + Y | X = x$. For example, we have that $Prob(X+Y=2) = 1/4$, but $Prob(X+Y = 2 | X = 0) = 0.$

What is going on in this counter-example that breaks the intuition? Is it that $\log_{-1}(z)$ is not a well-defined function (it has multiple complex branches)? Is it because $\log_{-1}(z)$ is discontinuous for $z = -1$? Or is the intuition just not true?

• Since you have a counter-example, the intuition is incorrect. Logarithms, complex numbers, and continuity are irrelevant in your example: everything in it could (easily) be described without reference to those things. – whuber Aug 15 '16 at 21:01
• Thanks for your comment. I would agree, but the counter-example seems contrived and dependent on a function $\log_{-1}(z)$ which to my knowledge might not even exist. Originally, when I wrote the question, I wrote $f(X,Y) = X + Y \bmod 2$ (with $X,Y$ uniformly distributed over $\mathbb{Z}_2$ and $h(X,Y) = X + Y$ (with $X,Y$ ordinary integers distributed uniformly over $\{0,1\}$.) However, there does not seem to be a function $g(z)$ such that $g(X+Y \bmod 2) = X+Y$ that can be used to define $h(X,Y)$. – Asterix Aug 15 '16 at 21:06
• There's no need to call $g$ a logarithm. If I have understood your exposition, $g$ merely is the function that maps $1$ to $0$ and $-1$ to $1$. Unfortunately your description following "if I take" is murky because it includes a false series of equations: it is not the case that $X+Y$ can be recovered from $f(X,Y)$. – whuber Aug 15 '16 at 21:10

The "intuitive" claim in the beginning is correct: $$P(h(X,Y) = w \mid X = x) = P(f(X,Y) \in \{z \mid g(z)=w\} \mid X = x) \\ = \sum_{z_i \in \{z \mid g(z)=w\}} P(f(X,Y) = z_i \mid X=x) = \sum_{z_i \in \{z \mid g(z)=w\}} P(f(X,Y) = z_i) = P(f(X,Y) \in \{z \mid g(z)=w\}) = P(h(X,Y) = w).$$
An alternative way of stating it would be that if $f(X,Y)$ and $X$ are independent, then $g(f(X,Y))$ and $X$ are independent. Applying a deterministic mapping to one of independent random variables cannot lose independence.
The counterexample does not work since there is no function $g$ with the property that $g((-1)^{(X+Y)})=X+Y$ for all values $X+Y$ may attain here (as @whuber pointed out in the comments). The example is equivalent to your first try (mentioned in comments) with $f(X,Y)=X+Y~\mathrm{mod}~2$ upto relabeling the range of $f$. As you found that there was no function in that case the first version, there is no applicable function in the new case, either.
$\mathrm{log}_{-1}$ not being such a function could be interpreted as being due to it having 'multiple branches': if we want $(-1)^w = z$ to imply $\mathrm{log}_{-1}(z)=w$, $\mathrm{log}_{-1}(1)$ should equal both $0$ and $2$, which is a proof-by-contradiction for nonexistence of such a function. We may decide to define if as a multivalued function or perhaps define a function of $(X,Y)$ that picks the correct "branch" based on $X+Y$ -- but then the premises of the initial claim do not hold.