This question is purely out of curiosity and mainly to question my intuitions about independence of random variables.
Q: Take two non trivial random variables, with non disjoint support (see edit below) $X,Y \in \mathbb{L}_2(\Omega, \mathcal{F}, \mathbb{P})$, so that projections and covariance formulas are well defined. If $X$ is uncorrelated with any function $g$ of $Y$, i.e. $\operatorname{Corr}(X,g(Y)) = 0, \: \forall \: g$ measurable, this implies $X$ and $Y$ are independent.
Is the above statement true? I could not find any post on mathstack on this.
One way I tried to prove the above is by proving the following:
Assume that $X$ and $Y$ are dependent, then there exists a function $f$ such that the correlation between $X$ and $f(Y)$ is nonzero.
Reason why $\mathbb{L}_2$ is important:
This is also the reason why we have to take the random variables in $\mathbb{L}_2$, otherwise one could find counterexamples to the second statement by taking $X$ with undefined variance or expectation and show that the covariance can never be nonzero, as it is not well defined.
Thoughts:
Any ideas or references? Maybe something additional must be assumed about the functions $g$? Maybe instead of this, one should assume that the correlation is zero with any random variable $Z$ which is $X$-measurable?
Thank you very much for your help and time.
Reason why non disjoint support is important:
EDIT. Here I post a counterexample that contradicts the second statement, if we do not assume that the random variables have non disjoint support, i.e.:
Assume that $X$ and $Y$ are dependent, then there exists a function $f$ such that the correlation between $X$ and $f(Y)$ is nonzero.
Take $([0,1], \mathcal{B}([0,1]), \lambda)$, where $\lambda$ is the Lebesgue measure. The key idea is that if they have disjoint support we can find a counterexample. Take: $$ X(x) = \left(x - \frac{1}{2} \right) \mathbb{1}_{[0,1/2]}(x)$$ and: $$ Y(x) = \left(x - \frac{3}{2} \right) \mathbb{1}_{[1/2,1]}(x)$$ Take any function $f$, then $f(Y(x)) = f(0)$ constant for any $x \in [0,1/2]$ thus: $$ X(x)f(Y(x)) = f(0)X(x) \mathbb{1}_{[0,1/2]}(x)$$ which, as $\int X d\lambda = 0$, implies: $$\int X f(Y) d \lambda = 0$$ for any $f$. This implies they are uncorrelated and it provides a counterexample.