Show that a function $f:\mathbb{R}\rightarrow \mathbb{R}$ is $\mathcal{S}$-measurable. Question: Let $X=\mathbb{R}$ and let $\mathcal{S}=\{A\subseteq \mathbb{R}:$ either $A$ is countable or $\mathbb{R}\setminus A$ is countable $\}$. Show that a function $f:\mathbb{R}\rightarrow \mathbb{R}$ is $\mathcal{S}$-measurable if and only if $f$ satisfies the following condition:
There is $c\in \mathbb{R}$ so that the set $\{x\in \mathbb{R}: f(x)\neq c\}$ is countable.
-->: Suppose $f$ is $\mathcal{S}$-measurable. Then $f^{-1}(B)\in \mathcal{S}$ for every Borel set  $B \subset \mathbb{R}$ and $\mathcal{S}$ is a $\sigma$-algebra on $\mathbb{R}$. Case 1: $A$ is countable and so $\mathbb{R}\setminus A$ is uncountable and so $c$ should be in $f(\mathbb{R}\setminus A)$ for the above set to have the required quality. On the other hand, if $\mathbb{R}\setminus A$ is countable then $A$ is uncountable so $c$ should live in $f(A)$. Does this argument make sense? And where does $f$ being $\mathcal{S}$-measurable have to do with it?
<---: Suppose there is a $c\in \mathbb{R}$ so that the set $\{x\in \mathbb{R}:f(x)\neq c\}$ is countable. Now we need to show that $f^{-1}(B) \in \mathcal{S}$ for every Borel set $B\subset \mathbb{R}$. In the case that $A$ is countable, $f$ maps $x$-values in $A$ to a neighborhood which does not contain $c$. Why is this neighborhood Borel?
Any insight into this problem would be helpful. Thank you.
 A: Suppose $f$ is $\cal S$ measurable. Suppose $A_1,A_2 \subset \mathbb{R}$ are Borel & disjoint. Then at most one of $f^{-1}(A_1)$,  $f^{-1}(A_2)$ can be uncountable.
Since $f^{-1}(\mathbb{R})= \mathbb{R}$, we see that exactly one of $f^{-1}([n,n+1))$ must be uncountable.
So, suppose $f^{-1}([a,b])$ is uncountable (I chose a compact interval for
subsequent convenience).
Consider $f^{-1}([a,{1 \over 2}(a+b)))$, $f^{-1}(\{{1 \over 2}(a+b)\})$, $f^{-1}(({1 \over 2}(a+b),b])$, exactly one of these is uncountable. If it is
$f^{-1}(\{{1 \over 2}(a+b)\})$ we are finished. Otherwise, exactly one of
$f^{-1}([a,{1 \over 2}(a+b)))$, $f^{-1}(({1 \over 2}(a+b),b])$ is uncountable, suppose it is the first for example. Then repeat the process
with $f^{-1}([a,{1 \over 2}(a+b)])$ (not that I have again taken the compact interval).
Either this process terminates with a $c$ such that $f^{-1} ( \{c\})$ is
uncountable, or it never terminates. In the latter case, we have a sequence of nested compact sets $K_n$ such that $f^{-1}(K_n)$ is uncountable and whose diameter goes to zero and hence their
intersection is a single point $\cap_n K_n = \{c\}$.
Note that $f^{-1}(K_n^c)$ is countable for each $n$ hence $f^{-1}(\cup_n K_n^c) = f^{-1}(\{c\}^c)$ is countable and so $f^{-1} ( \{c\})$ is
uncountable.
