No proper measurable subset of real number has density only 0 and 1 Background : Suppose E ⊂ $\mathbb{R}$. The density of E at a number b ∈ $\mathbb{R}$ is
$\lim_{t ↓ 0} \frac{| E ∩ ( b − t, b + t )|}{2t}$
if this limit exists (otherwise the density of E at b is undefined).
My question : Suppose E is a Lebesgue measurable subset of $\mathbb{R}$ such that the density of E equals 1 at every element of E and equals 0 at every element of $\mathbb{R}$ \ E. Prove
that E = ∅ or E = $\mathbb{R}$.
My attempts : Let ∅ $\subsetneq E \subsetneq \mathbb{R}$ such that the density of E equals 1 at every element of E and equals 0 at every element of $\mathbb{R}$ \ E
Consider a= inf$ \{x\in \mathbb{R} : m([x,x+r]\bigcap E)=0 \forall r>0\}$ and b= sup$ \{x\in \mathbb{R} : m([x-s,x]\bigcap E^c)=0 \forall s>0\}$
Clearly $a\neq -\infty$ and $b\neq \infty$, otherwise it will contradict the hypothesis s that the density of E equals 1 at every element of E and equals 0 at every element of $\mathbb{R}$ \ E
Now I want to show a=b
Note $[a,\infty)\subset E^c$ and $(-\infty,b]\subset E$ and therefore $b\leqslant a$
Let c=$ \sup_{x\in E\bigcap [b,a]} x$
Hence $m([c,c+r]\bigcap E)=0$ for all r>0 and so $a\leqslant c$ which implies a=c
Similarly b=c
Thus a=b=c
So now $ m([a,a+r]\bigcap E)=0 \forall r>0 $ and $m([a-s,a]\bigcap E^c)=0 \forall s>0 $
Thus $\frac{m([a-r,a+r]\bigcap E)}{2r}=\frac{1}{2r} r=1/2$ $\longrightarrow$ 1/2 as $r\rightarrow 0+$
$\Rightarrow$ density of E at a is 1/2 .......A contradiction
Hence either E = ∅ or E = R
My problem : Is my proof correct?
I have one doubt in my proof that to define infimum or supremum, first I need to show that $ \{x\in \mathbb{R} : m([x,x+r]\bigcap E)=0 \forall r>0\} \neq$ ∅  and $ \{x\in \mathbb{R} : m([x-s,x]\bigcap E^c)=0 \forall s>0\}\neq$ ∅ but I could not show that.
Please help or give me some other techniques to prove it. Thank you in advance.
 A: Fix $a\in\mathbb{R}$. Let $\chi_A$ be the characteristic function on each set $A\subseteq\mathbb{R}$. Define $F$ and $G$ by
\begin{align}
F(x)&=\int_a^x\chi_E(x)\,dx, \\
G(x)&=\int_a^x\chi_{E^c}(x)\,dx=x-a-F(x).
\end{align}
If the density of $E$ at every $x\in\mathbb{R}$ is $1$ if $x\in E$ and $0$ if $x\notin E$, then every $x\in E$ is a Lebesgue point of $\chi_E$, whereas every $x\in E^c$ is a Lebesgue point of $E^c$. It is known that
\begin{align*}
\frac{d}{dx}\int_{-\infty}^xf(t)\,dt=f(x)
\end{align*}
at every Lebesgue point of $f$, provided that $f$ is $L^1$. Hence $F'(x)=1$ at every $x\in E\cap(a,+\infty)$ and $G'(x)=1$ at every $x\in E^c\cap(a,+\infty)$. In particular, this implies that $F'(x)=0$ at every $E^c\cap(a,+\infty)$. Since $F$ is differentiable on $(a,+\infty)$, given $b>a$ by the mean value theorem $m(E\cap(a,b))$ is either $b-a$ or $0$.
Suppose that $m(E\cap(a,b))=b-a$. Given $x\in(a,b)$, the set $E\cap(x-t,x+t)$ has full measure in $(x-t,x+t)$ whenever $(x-t,x+t)\subseteq(a,b)$. This implies
\begin{align*}
\frac{m(E\cap(x-t,x+t))}{2t}=1
\end{align*}
for small enough $t$, so the density of $E$ at $x$ is $1$. By our assumption $x\in E$. Hence $E^c$ does not intersect $(a,b)$. Similarly, if $E\cap(a,b)=0$, then $E^c\cap(a,b)=b-a$, so $E$ does not intersect $(a,b)$.
Let $\mathscr{U}$ and $\mathscr{V}$ be the collection of open intervals intersecting $E$ and $E^c$ respectively. Then $E=\bigcup\mathscr{U}$ and $E^c=\bigcup\mathscr{V}$ are both open subsets of $\mathbb{R}$. Since $\mathbb{R}$ is connected, one of $E$ and $E^c$ must be empty.
