Let $\lambda=\text{unif}([0,1])$ be uniform distribution on $[0,1]$ and $B$ be any Borel set. Lebesgue's density theorem states that for $\lambda$-almost all $x\in[0,1]$ the limit
$$\lim\_{\epsilon\downarrow o}\frac{\lambda([x-{\epsilon},x+\epsilon]\cap B)}{2\epsilon}$$
exists and is either $0$ or $1$. Im interested in a 'global' approximation.


For $n\geq 1$ let
$$D\_n:=\big\{\frac{0}{2^n},\frac{1}{2^n},\frac{2}{2^n},\dots,\frac{2^n-1}{2^n}\big\}.$$


Now i look at the expression 


$$a\_n:=(1/2)^n\cdot\sum\_{x\in D\_n}\frac{\lambda\big([x,x+(1/2)^n]\cap B\big)}{(1/2)^n}\cdot\bigg[1-\frac{\lambda\big([x,x+(1/2)^n]\cap B\big)}{(1/2)^n}\bigg].$$
So for large $n$ every summand should be close to Zero. Additionally every summand gets weighted by $(1/2)^n$.


The number $a\_n$ tells you something about how 'intervall-like' $B$ is. Since you can approximate every $B$ by finite unions of intervalls you can show that $a\_n\rightarrow 0$ for each $B$. I want to know: How fast does $a\_n$ tend to Zero? Is it true that $\sum\_{n\geq 1}a\_n<\infty$ for any measurable $B$? If this is not the case, can you provide an example of a set $B$ with $\sum\_n a\_n=\infty$? 


Remark: This is a special instance of a more general question I posted on Stackexchange (before I knew that Overflow exists, sorry about that): <https://math.stackexchange.com/questions/1835620/switching-independent-experiments-does-i-ax-1-dots-x-n-y-n1-y-n2-dots>



Speed of convergence in Lebesgue's density theorem
The answer is negative. In fact, let us show that $a\_n$ as defined in the question may converge to $0$ however slowly. Indeed, let $(\epsilon\_j)$ is any sequence in $(0,1]$ converging to $0$ slowly and regularly enough, in the sense that 
\begin{equation}
\epsilon\_{j-1}-\epsilon\_j\ge2^{2-j}\tag{1} 
\end{equation}
eventually in $j$ -- that is, for some natural $j\_0$ and all natural $j\ge j\_0$. For instance, this condition will hold if $\epsilon\_j$ is (eventually in $j$) of the form $2^{2-j}$ or $j^{-a}$ or 
$(\underbrace{\ln\dots\ln}\_N j)^{-a}$ for some real $a$ and some natural $N$. 


In what follows, $j$ is a natural number $\ge j\_0$.  

Let 
$$k\_j:=\lfloor2^j\epsilon\_j\rfloor$$ 
and 
$$r\_j:=k\_j/2^j.$$ Then 
\begin{equation}
\epsilon\_j-\tfrac1{2^j}<r\_j\le\epsilon\_j\tag{2} 
\end{equation}
and hence, by the regularity condition $(1)$, $r\_j<r\_{j-1}$. Let $$\Delta\_j:=(r\_{j},r\_{j-1}].$$ 
Note that the intervals $\Delta\_j$ are pairwise disjoint. 
Let then 
$$s\_{j,\ell}:=r\_{j}+\ell/2^{j+1}$$ 
for $\ell=0,\dots,\ell\_j:=(r\_{j-1}-r\_{j})2^{j+1}$, so that $\ell\_j$ is even, and 
$$\delta\_{j,\ell}:=(s\_{j,\ell},s\_{j,\ell+1}].$$ 
Note that 
$\Delta\_j$ is the disjoint union of the $\delta\_{j,\ell}$'s over $\ell=0,\dots,\ell\_j-1$. 
Let, finally,  

\begin{equation}
 B:=\bigcup\_{j=j\_0}^\infty\bigcup\_{q=0}^{\ell\_j/2-1}\delta\_{j,2q}. 
\end{equation}


Take now any large enough natural $n$. Let 
\begin{equation}
 H\_{n,i}:=\Big(\frac i{2^n},\frac{i+1}{2^n}\Big]
\end{equation}
for $i=0,\dots,2^n-1$. 


From now on, suppose also that $j\ge n\ge j\_0$. 


Then $|\delta\_{j,\ell}|=1/2^{j+1}<1/2^n=|H\_{n,i}|$, where $|\cdot|$ denotes the Lebesgue measure. 
For any given $i=0,\dots,2^n-1$ such that $H\_{n,i}\subseteq\Delta\_j$, we have
$$B\cap H\_{n,i}=\bigcup\_{q=q\_1}^{q\_2}\delta\_{j,2q}
\quad\text{and}\quad
H\_{n,i}=\bigcup\_{\ell=2q\_1}^{2q\_2+1}\delta\_{j,\ell}$$
for some integers $q\_1=q\_{1;n,i}$ and $q\_2=q\_{2;n,i}$ such that $0\le q\_1\le q\_2\le\ell\_j/2-1$. 
Hence, 
$|B\cap H\_{n,i}|=\frac12|H\_{n,i}|=\frac12\frac1{2^n}$.  

So,
\begin{equation}
 \frac{|B\cap H\_{n,i}|}{2^{-n}}\Big(1-\frac{|B\cap H\_{n,i}|}{2^{-n}}\Big)
=\frac14 
\end{equation}
-- for each $j\in\{n,n+1,\dots\}$ and each $i=0,\dots,2^n-1$ such that $H\_{n,i}\subseteq\Delta\_j$.  

By $(2)$ and $(1)$, the length $|\Delta\_j|$ of the dyadic interval $\Delta\_j$ is 
$r\_{j-1}-r\_j\ge\epsilon\_{j-1}-\epsilon\_j-\tfrac1{2^{j-1}}\ge\tfrac12\,(\epsilon\_{j-1}-\epsilon\_j)$, 
and so, for a given natural $n\ge j\_0$, the dyadic interval $\Delta\_j$ contains at least 
$2^{n-1}(\epsilon\_{j-1}-\epsilon\_j)$ 
dyadic intervals $H\_{n,i}$. 
So, for $a\_n$ as defined in the question, we have  

\begin{equation}
 a\_n\ge\frac1{2^n}\sum\_{j=n}^\infty\ \sum\_{i\colon H\_{n,i}\subseteq\Delta\_j}
 \frac{|B\cap H\_{n,i}|}{2^{-n}}\Big(1-\frac{|B\cap H\_{n,i}|}{2^{-n}}\Big)
 \ge
 \frac1{2^n}\sum\_{j=n}^\infty 2^{n-1}(\epsilon\_{j-1}-\epsilon\_j)\frac14
 =\frac{\epsilon\_{n-1}}8. 
\end{equation}
Thus, $a\_n\ge\frac{\epsilon\_{n-1}}8$ for all $n\ge j\_0$. 
For instance, letting $\epsilon\_j=1/j$ for all natural $j$, we have  

$\sum\_n a\_n=\infty$. 


