Non measurable function but measurable pre-image I am having trouble with a problem. It gives a hint to use the Vitali construction, but I honestly do not understand it.
The question is: Show that there is a function $f:\mathbb{R} \to \mathbb{R}$ is not Lebesgue measurable, but $\forall$ $ a \in \mathbb{R}$ $f^{-1}(a)$ is measurable.
My try: 
Let $E$ be a non-measurable subset of $\mathbb{R}$ , and 
$f(x)= \begin{cases} 
      x & x\in E \\
      -x & x\notin E
     \end{cases}
$
I am not certain that this is correct. Any help would be greatly appreciated, and all apologies for the simplistic inquiries. 
 A: Any bijection from $\mathbb{R}$ to itself has measurable preimages of singletons. So a straightforward way to do it is to biject a nonmeasurable set $E$ with an interval $I$, and then biject $\mathbb{R} \setminus E$ with $\mathbb{R} \setminus I$. Then the preimage of the interval is $E$ which is certainly not measurable. 
What Borel set has nonmeasurable preimages in your example? (I am not claiming it does not work, I am just not entirely clear how it works, if it does work.)
Edit: a variant on your example which more obviously works: let $E$ be a nonmeasurable set contained in $(0,\infty)$, then define
$$f(x)=\begin{cases} 
x & x \in E \\
-x & x \in [0,\infty) \setminus E \\
x & x \in (-\infty,0) \end{cases}.$$
Then $f^{-1}(\{ a \})$ is either empty, a singleton, or two points, but $f^{-1}((0,\infty))=E$ which is not measurable.
A: Nice example.  Each $f^{-1}(a)$ is a singleton (hence measurable) but $f$ is not measurable.
[Added: As @John Ma notes, $f^{-1}(a)$ need not be a singleton, but does have cardinality at most 2.  To see the non-measurability of $f$, let $g$ denote the identity function; then $f=g\cdot (2\cdot 1_E -1)$, where $1_E$ is the indicator function of $E$. If $f$ were measurable, then on ${\Bbb R}\setminus\{0\}$ so too would $1_E = [(f/g)+1]/2$ be measurable, a contradiction of the basic hypothesis.]
