Any example for a function having domain and range as subset of real line that is NOT Borel function? Suppose there is a function $f:A\to B$ where $A,\,B\subseteq\mathbb{R}$, is there any example for this function being NOT Borel function? 
Well the question came up to be when I was reading the probability theory and it states that the two random variable is independent if and only if $\mathbb{E}[f(X)g(Y)] = \mathbb{E}[f(X)]\,\mathbb{E}[g(Y)]$ for any $f,\,g$ being Borel function. This is not hard to proof but I cannot think of any function that is not Borel when the function takes real value and also provides real value. Any comment is extremely welcomed :)
 A: Royden's book on real analysis discusses a non-measurable subset of the line.  The indicator (or characteristic function in analysis parlance) of this subset is not Borel measurable.  
A: A couple of silly examples, using a well-ordering of the reals: 
There are only $\mathfrak c$ Borel functions whose domain and range are contained in $\mathbb R$ (because Borel functions have Borel graphs, and there are only $\mathfrak c$ Borel subsets of $\mathbb R^2$). List them as $(f_\alpha\mid \alpha<\mathfrak c)$, list $\mathbb R$ as $(x_\alpha\mid\alpha<\mathfrak c)$, and, for each $\alpha<\mathfrak c$, define $f(x_\alpha)=0$ or $1$, whichever is different from $f_\alpha(x_\alpha)$ (including the possibility that $x_\alpha$ is not in the domain of $f_\alpha$). In this example, $f$ only takes the values $0$ and $1$, so it is the characteristic function of a (necessarily, non-Borel) set. 
We can also produce an injective example, by letting $f(x_\alpha)=x_\beta$, where $\beta$ is least such that $x_\beta\notin\{f_\alpha(x_\alpha)\}\cup\{f(x_\tau)\mid \tau<\alpha\}$. Since at each stage only fewer than $\mathfrak c$ values have been excluded, $x_\beta$ is defined.  
