Why is the random variable $X-Y$ almost sure constant if it is independent of $X$ and $Y$? Is this valid for a general random variable $f(X,Y)$? Good day,
In class we said that if a random variable $X-Y$ is independent of random variables $X$ and $Y$ then $X-Y$ is almost sure constant, i.e. there exists a $c \in \mathbb{R}$ such that $P(X-Y=c)=1$.
First, I don't exactly how to prove this. I know that $X$ is constant if it is independent of itself. Therefore I could prove that $X-Y$ is independent of itself (But the other directions doesn't hold I suppose). Do I know that $X-Y$ is independent of itself?

Is it correct to say: If $Z$ is independent of $X$ and $Y$ then it is independent of $g(X,Y)$ where $g$ is a measurable function.

I don't think so. The definition of independence doesn't give this property.
Then how do I prove that $X-Y$ is almost sure constant? Another approach through expectations:
$$E(X-Y|X)=E(X-Y|Y)=E(X-Y)=EX-EY $$
But is seems not leading me to a goal.

So: Why is the random variable $X-Y$ almost sure constant if it is independent of $X$ and $Y$?
Is this valid for a general random variable $f(X,Y)$ (where $f$ is measurable for example)? i.e. $f(X,Y)$ is almost sure constant it it is independent of $X$ and $Y$?

If not I would ask for a counterexample.
Thanks a lot for your help,
Marvin
 A: Let $\phi_A(t)$ be the characteristic function of random variable $A$.Then you know that if $A,B$ are independent, then $\phi_{A+B}(t)=\phi_A(t)\phi_B(t)$.
You have that $X-Y$ is independent of $X$ and $Y$. Noting that $X=(X-Y)+Y$, you have that $\phi_X(t)=\phi_{(X-Y)+Y}(t)=\phi_{X-Y}(t)\phi_Y(t)$ [using the fact that $X-Y$ and $Y$ are independent] for every $t\in\mathbb R$. Thus $\phi_{X-Y}(t)=\dfrac{\phi_X(t)}{\phi_Y(t)}$.
Also you have, similarly, that $\phi_Y(t)=\phi_{Y-X}(t)\phi_X(t)$ implying $\phi_{Y-X}(t)=\dfrac{\phi_Y(t)}{\phi_X(t)}$.
Let us call $Z:=X-Y$ for brevity of notation. Then the above two give that $\phi_Z(t)=\dfrac{\phi_X(t)}{\phi_Y(t)}$ and $\phi_{-Z}(t)=\dfrac{\phi_Y(t)}{\phi_X(t)}$.
Hence $\phi_Z(t)\phi_{-Z}(t)=1$, for every $t\in\mathbb R$.
Using the fact that $\phi_{-Z}(t)=\overline{\phi_{Z}(t)}$, we have that $|\phi_Z(t)|=1$ for all $t\in\mathbb R$.
Thus, $\phi_Z(t)=e^{ig(t)}$ for some function $g$, for all $t\in\mathbb R$.
Now observe that for all $t$, $e^{ig(t)}=E(e^{itZ})$ implies $E(e^{i(tZ-g(t))})=1$ for all $t$. Noting that $|e^{i(tZ-g(t))}|=1$ we must have that $tZ-g(t)=2k(t)\pi$ for an integer valued function $k$, almost surely.
Thus almost surely, $Z=\dfrac{g(t)+2k(t)\pi}{t}$ for all $t\in\mathbb R$.
Since the LHS is independent of $t$, we may choose any $t$, say $t=1$. Then $Z=g(1)+2k(1)\pi$ which is afterall, a constant, almost surely.
Hence $X-Y$ is constant almost surely.
Now let us see your other questions. You want to know if $Z$ is independent of $X$ and $Y$ then is it true that $Z$ is independent of $g(X,Y)$ for any measurable function $g$?
So consider for Borel sets $A,B$ the following: $P(Z\in A, g(X,Y)\in B)=P[Z\in A, (X,Y)\in g^{-1}(B)]$. This can be written as the product $P[Z\in A]P[(X,Y)\in g^{-1}(B)]$ if and only if $Z$ is JOINTLY INDEPENDENT with $X,Y$. There exist examples where $Z$ is independent of each $X,Y$ but maybe not jointly. Here's one:
Throw two dice independently. Define $A$ to be the event that $7$ is obtained as the sum of the two throws, $B$ be the event that $3$ is obtained on first throw and $C$ be the event that $4$ is obtained on second throw. Then you can check that $A,B,C$ are pairwise independent but not jointly independent ($A$ is NOT jointly independent with $B$ and $C$.) For example with random variables, take $X=1_B,Y=1_C,Z=1_A$.
As you see, we crucially used the structure of $f(X,Y)=X-Y$. I cannot say right now if it can always be said that if $f(X,Y)$ is independent of both $X$ and $Y$ then it is a.s. constant.
A: Extending Landon Carter's answer,

i.e. $f(X,Y)$ is almost sure constant it it is independent of $X$ and $Y$?

No. Flip a coin twice, let $X_i = \mathbf{1}_{\text{H on $i$th flip}}$, $i=1,2$, $Z = \mathbf{1}_{X_1=X_2}$. Then $Z$ is independent of both $X_1$ and $X_2$, but is not constant. (Note that here $Z$ is moreover a function of the difference $X_1-X_2$.)
As Landon Carter wrote, joint independence is enough. A weaker sufficient condition is that $f(X,Y)$ is independent of the vector $(X,Y)$. Indeed, in this case $f(X,Y)$ is independent of any transformation of the vector $(X,Y)$. In particular, it is independent of itself, which means that it is constant a.s.
