Q:

Construct a set with different upper and lower Lebesgue density at zero.

For $\delta >0,$let $I(\delta)$ be the segment $(- \delta, \delta) \subset \mathbb{R}.$ Given $\alpha,\beta,$ and $0 \leq \alpha < \beta \leq 1,$ construct a measurable set $E \subset \mathbb{R}$ so that the upper and lower limits of 
$$m(E \cap I(\delta))/2 \delta$$ are $\beta$ and $\alpha$ repsectively as $\delta \rightarrow 0.$  
This is a question from Rudin's book on Real and Complex Analysis and it has been taken up before here:
Lebesgue measurable subset of $\mathbb{R}$ with given metric density at zero . 
Yuval Filmus has posted an answer which I'm trying to verify, but I can't make it to work. In his answer, he sets $E$ to be the duplication around zero of
$$\bigcup_{n \geq 1} \left[\frac{1}{(2n)!}-\alpha\left(\frac{1}{(2n)!} - \frac{1}{(2n+1)!}\right),\frac{1}{(2n)!}\right] \cup \left[\frac{1}{(2n+1)!}-\beta\left(\frac{1}{(2n+1)!} - \frac{1}{(2n+2)!}\right),\frac{1}{(2n+1)!}\right].$$
I have no problem with showing that $\beta$ and $\alpha$ can occur as limits, but I can't show that any limit must lie between $\beta$ and $\alpha.$   
My questions are thus:
 1. Is the construction of Yuval correct? Does this work?
 2. If not, what is an example that does work?  
My attempt with Yuval's example 
Let us try to show that any limit must lie between $\alpha$ and $\beta.$ Say that $0< r <1$ and that $ \dfrac{1}{(2n+1)!} < r \leq \dfrac{1}{(2n)!}.$ Then we have that $$m(E \cap I(1/(2n+1)!)) \leq m(E \cap I(r) ) \leq m(E \cap I(1/(2n)!)).$$
We have that $$m(E \cap I(1/(2n+1)!)) = 2\sum_{k=n+1}^\infty  \beta \frac{2k}{(2k+1)!} + 2 \sum_{k=n+2}^\infty \alpha \frac{2k}{(2k+1)!}$$ while
$$m(E \cap I(1/(2n)!)) = 2\sum_{k=n}^\infty  \alpha \frac{2k}{(2k+1)!} + 2 \sum_{k=n+1}^\infty \beta \frac{2k}{(2k+1)!}.$$
We have  $$m(E \cap I(1/(2n+1)!))/(2r) \leq m(E \cap I(r) )/(2r) \leq m(E \cap I(1/(2n)!))/(2r).$$
We now want an upper and a lower bound on $m(E \cap I(r))/(2r).$For the upper bound, the obvious thing would be, since $(2n)!/2 \leq 1/(2r) < (2n+1)!/2$ would be to calculate  $$(2n+1)!/2m(E \cap I(1/(2n)!)).$$ This is $$(2n+1)!\sum_{k=n}^\infty  \alpha \frac{2k}{(2k+1)!} + (2n+1)! \sum_{k=n+1}^\infty \beta \frac{2k}{(2k+1)!}.$$ But this upper bound is much too crude to give us anything valuable. I also tried by taking the midpoint of the interval $[1/(2n+1)!,1/(2n)!]$ but that similarily seemed to give me nothing.

A:

I'll deal with the cases $0<\alpha < \beta <1.$ Suppose $b_1 > a_1 > b_2 > a_2 > \cdots \to 0.$ Let $E=\cup_n [a_n,b_n].$ For $0<x<b_1,$ define
$$f(x) = \frac{m(E\cap [0,x])}{x}.$$
Check that $f$ increases on each $[a_n,b_n],$ and decreases on each $[b_{n+1},a_n].$ Thus the maximum of $f$ on $[b_{n+1},b_n]$ is one of the values $f(b_n), f(b_{n+1}),$ while the minimum equals $f(a_n).$ Thus if we can find $a_n,b_n$ such that $f(b_n) = \beta, f(a_n) = \alpha$ for all $n,$ we'll be done.
Note the following:
$$\tag 1 f(b_n)=\frac{(b_n-a_n) + (b_{n+1}-a_{n+1}) + \cdots  }{b_n}, \,\, \,\,f(a_n)=\frac{(b_{n+1}-a_{n+1}) + (b_{n+2}-a_{n+2})\cdots  }{a_n}.$$
It turns out that we can choose $a_n,b_n$ to be geometric sequences. Define
$$c = \frac{1-\beta}{1-\alpha}, b= c\frac{\alpha}{\beta}.$$
Put $b_n = b^n, a_n = cb^n.$ Then these $b_n,a_n$ do exactly what we want. To check this, use $(1)$ to see
$$f(b_n) = \frac{(1-c)b^n + (1-c)b^{n+1} + \cdots  }{b^n} = \frac{1-c}{1-b}.$$
Do some algebra to see the last fraction equals $\beta.$ The same kind of argument gives $f(a_n)=\alpha.$ That completes the proof.
I realize that some of this seems like rabbits out of hats, but it's really not that unintuitive. If you entertain the idea that geometric sequences $a_n,b_n,$ might work, even if the $a_n$ sequence is a fixed constant times the sequence $b_n,$ then the definitions of $b,c$ arise naturally.

A:

To estimate $m(E\cap I(\delta))/2\delta$, consider the function
$$x\mapsto \frac{m(E\cap I(\delta+x))}{2(\delta+x)}.$$
Given a symmetric set $E$, we can for simplicity work with only $E\cap\mathbb{R}_+$, i.e. consider the function
$$M(x)=\frac{m(E\cap [0,\delta+x])}{\delta+x}.$$
Suppose first $x>0$. Then we can decompose $E\cap [0,\delta+x]$ into the parts $E\cap [0,\delta]$ and $E\cap[\delta,\delta+x]$. Whenever the interval $[\delta,\delta+x]$ is contained in $E$, using this decomposition gives
$$m(E\cap [0,\delta+x]) = m(E\cap[0,\delta])+m([\delta,\delta+x])=m(E\cap[0,\delta])+x.$$
We actually get the same formula also for $x<0$ whenever $[\delta+x,\delta]\subset E$.
Therefore, when $\delta$ is contained in an interval $\delta\in(a,b)\in E$, as long as $\delta+x$ is in the same interval, we have
$$M(x) = \frac{m(E\cap [0,\delta+x])}{\delta+x} = \frac{m(E\cap[0,\delta])+x}{\delta+x}.$$
Since $m(E\cap[0,\delta])\leq m([0,\delta])=\delta$, we get $M'(x)\geq 0$, so the function $M$ is non-decreasing near $\delta$. Hence given $\delta\in(a,b)\subset E$ we get the estimates $M(a-\delta)\leq M(0)\leq M(b-\delta)$, i.e.
$$\frac{m(E\cap [0,a])}{a}\leq\frac{m(E\cap [0,\delta])}{\delta}\leq \frac{m(E\cap [0,b])}{b}.$$
Applying similar reasoning when $\delta$ is on some interval $\delta\in(a,b)\subset \mathbb{R}\setminus E$ of the complement of $E$, we get $M(x) = m(E\cap [0,\delta])/(\delta+x)$. Since this is non-increasing, we get
$$\frac{m(E\cap [0,b])}{b}\leq\frac{m(E\cap [0,\delta])}{\delta}\leq \frac{m(E\cap [0,a])}{a}.$$
Therefore when the set $E$ is comprised of disjoint intervals $[a_k-l_k,a_k]$, it suffices to compute the upper bound along the endpoints $a_k$, and the lower bound along the endpoints $a_k-l_k$.
More explicitly, by the previous estimates one gets
\begin{align}
\limsup_{\delta\to 0}\frac{m(E\cap [0,\delta])}{\delta} &= \limsup_{k\to \infty}\frac{m(E\cap [0,a_k])}{a_k}=\limsup_{k\to\infty}\frac{1}{a_k}\sum_{n=k}^\infty l_k\quad\text{and}\\
\liminf_{\delta\to 0}\frac{m(E\cap [0,\delta])}{\delta} &= \liminf_{k\to \infty}\frac{m(E\cap [0,a_k-l_k])}{a_k-l_k}=\liminf_{k\to\infty}\frac{1}{a_k-l_k}\sum_{n=k+1}^\infty l_k.
\end{align}
Getting the precise bounds $\alpha$ and $\beta$ for the densities is then just a matter of fine-tuning the lengths $l_k$ and positions $a_k$ of the intervals.

