Understanding the construction of a set to show compactness I am just trying to understand the proof of the following exercise:

Define $l^2(\mathbb{N}) = \{(x_n)_n \in \mathbb{C} | \sum_n |x_n|^2 < + \infty \}$. Let $(a_n)_n \subset \mathbb{R}_+$ such that $\sum_n a_n^2 < + \infty$. Show that $B = \{(x_n) \in l^2(\mathbb{N}) | |x_n| \leq a_n\}$ is compact in $l^2(\mathbb{N})$.

It is easy to show that $B$ is closed. We want to show that $B$ is totally bounded: Let $\epsilon > 0$. Because of the convergence of $\sum_n | a_n|^2$, there exists a $N_{\epsilon} \in \mathbb{N}$ such that $\sum_{n \geq N_{\epsilon}}|a_n|^2 < \epsilon^2$.
Now we define $D = \{ (x_n)_n \in l^2(\mathbb{N}) \ | \ |x_n| \in \{ 0, \frac{\epsilon}{\sqrt{N_\epsilon}} , \frac{2\epsilon}{\sqrt{N_{\epsilon}}}, \cdots, \frac{K_n \epsilon}{\sqrt{N_{\epsilon}}} \} \text{ if } 0 \leq n \leq N_\epsilon -1 , x_n = 0 \text{ if } n \geq N_{\epsilon} + 1\}$ such that $a_n \leq K_n \frac{\epsilon}{\sqrt{N_{\epsilon}}} < a_n + \frac{\epsilon}{\sqrt{N_{\epsilon}}} $ and $K_n = \left\lfloor\dfrac{a_n \sqrt{N_{\epsilon}}}{\epsilon}\right\rfloor + 1$. $D$ is finite and with this set $D$ we can show that $B$ is totally bounded.
I don't really understand the construction of the set $D$. Why does this help us to show that $B$ is totally bounded, i.e. compact?
 A: I like this question. Here is an argument that assumes that one knows Tychonoff's famous theorem which says that the product of compact spaces, endowed with the product topology is again compact.
Call the set $B_a:=\{(x_n)\in\ell^2:|x_n|\le a_n\text{ for all }n\}$
I will assume for simplicity that we are working with the real $\ell^2$, but the same argument works for the complex $\ell^2$. For each $n\ge1$, we consider the intervals $[-a_n,a_n]$ with their usual topology inherited by the real line. These are all compact. we consider the product space $X=\prod_{n=1}^\infty[-a_n,a_n]$ with the product topology. Note that points of $X$ are sequences $(x_1,x_2,\dots)$ such that $x_i\in[-a_i,a_i]$ for all $i$. So we will write a point $x\in X$ as the sequence $\{x(n)\}_{n=1}^\infty$.
Also recall that, a net $(x_\lambda)_{\lambda\in\Lambda}\subset X$ converges to the point $x\in X$ if and only if, for each $\varepsilon>0$ and each finite set $F\subset\mathbb{N}$, there exists $\lambda_0\in\Lambda$ such that $|x_\lambda(n)-x(n)|<\varepsilon$ for all $n\in F$ and all $\lambda\ge\lambda_0$.
Now Consider the identity map $X\to\ell^2$ that maps a sequence to itself. Note that the image of $X$ in $\ell^2$ is precisely our set $B_a$. If we show that the identity map is continuous, we have that $B_a$ is the image of a compact space under a continuous map and thus compact. So let $(x_\lambda)\subset X$ be a net converging to $x\in X$. What we have to show is that $(x_\lambda)$ converges to $x$ when we see everything in $\ell^2$, i.e. we must show that $\lim_{\lambda}\|x_\lambda-x\|_2=0$.
Let $\varepsilon>0$. Since $\sum_na_n^2<\infty$, there exists some finite set $F\subset\mathbb{N}$ such that $\sum_{n\in\mathbb{N}\setminus F}a_n^2<\varepsilon$. Since $x_\lambda\to x$ in $X$, by the description of net convergence we gave earlier, for the finite set $F$ and the tolerance $\sqrt{\frac{\varepsilon}{|F|}}>0$, we can find $\lambda_0\in\Lambda$ such that, for all $\lambda\ge\lambda_0$ and all $n\in F$ we have $|x_\lambda(n)-x(n)|<\sqrt{\frac{\varepsilon}{|F|}}$. But then, for $\lambda\ge\lambda_0$ we have that
$$\|x_\lambda-x\|_2^2=\sum_{n\in\mathbb{N}}|x_\lambda(n)-x(n)|^2=\sum_{n\in F}|x_\lambda(n)-x(n)|^2+\sum_{n\in\mathbb{N}\setminus F}|x_\lambda(n)-x(n)|^2\leq$$
$$\leq\sum_{n\in F}\frac{\varepsilon}{|F|}+\sum_{n\in\mathbb{N}\setminus F}(2a_n)^2\leq\varepsilon+4\varepsilon=5\varepsilon$$
This shows exactly that $x_\lambda\to x$ in $\|\cdot\|_2$, which is the continuity of the identity map that we were after.
A: Of course I can understand that an undergraduate student might not feel comfortable using Tychonoff's theorem, so I will give another answer that seems also to be closer to OP's idea. Let's use the notation of my other answer. Again, I will work with real vector spaces but the same arguments work for the complex ones.
The functionals $\phi_n:\ell^2\to\mathbb{R}$ given by $x\mapsto x(n)$ (i.e. we map a sequence $x=\{x(n)\}$ to its $n$ term) is of course continuous, since $|x(n)|\leq(\sum_{k=1}^\infty|x(k)|^2)^{1/2}$. Now one immediately sees that
$$B_a=\bigcap_{n=1}^\infty\phi_n^{-1}([-a_n,a_n])$$
Now each interval $[a_n,a_n]$ is closed, so their preimages under continuous maps are closed, so their intersection is an intersection of closed sets, thus $B_a$ is closed. In particular, the set $B_a$ is complete, as we do know that $\ell^2$ is complete. Now to show compactness all we must do is show that $B_a$ is totally bounded, as it is a general fact that for metric spaces, completeness and totally boundedness is equivalent to compactness.
By definition, a space is totally bounded when for each $\varepsilon>0$ there exists a finite collection of open balls of radius $\varepsilon$ that covers the space.
The idea is very simple. Let $\varepsilon>0$. Since $\sum_na_n^2<\infty$, find an integer $N\ge1$ so that $\sum_{n=N+1}^\infty a_n^2<\varepsilon^2$. Now have a look at the intervals $[-a_n,a_n]$ for $n=1,\dots,N$. We can find a partition of each interval $-a_n=t_{0,n}<t_{1,n}<\dots<t_{d_n,n}=a_n$ so that $|t_{i,n}-t_{i+1,n}|<\frac{\varepsilon}{\sqrt{N}}$ for all $i=0,\dots,d_n-1$ and all $n=1,\dots,N$.
Now we simply have to consider all these sequences that, in slot $1$ have a value from the partition of $[-a_1,a_1]$ we chose, in slot $2$ they have a value from the partition of $[-a_2,a_2]$ that we chose and so on up to the $N$-th slot, where we want them to have a value from the partition of $[-a_N,a_N]$ that we chose. Let them have $0$ from that point on.
Note that these sequences are finitely many: how many of them are there? well, for the first slot we have $d_1+1$ choices. For the second slot we have $d_2+1$ choices and so on until the $N$th slot, for which we have $d_N+1$ choices. So there exist precisely $D:=\prod_{n=1}^N(d_n+1)$ such seqeunces, this is a finite number.
We now claim that the balls centered at these sequences and of radius $\sqrt{2}\varepsilon$ actually cover the entire set $B_a$. Let's prove this.
Suppose that we are given a sequence $x=\{x(n)\}\in B_a$. How do we determine in which one of the $D$ balls (with center one of the $D$ sequences we constructed and radius $\sqrt{2}\varepsilon$) $x$ will lie in? Well, there's only one natural thing to do! look at its first $N$ terms. For $x(1)\in[-a_1,a_1]$, there exist some interval of our partition that contains $x(1)$. Note that our partition is so thin that each of the subintervals has length at most $\frac{\varepsilon}{\sqrt{N}}$. Let $t_1$ be one of the end points of the interval that contains $x(1)$. In particular, we have $|t_1-x(1)|<\frac{\varepsilon}{\sqrt{N}}$. Similarly for $x(2)$ and so on ..., up to $x(N)$: $x(N)\in[-a_N,a_N]$, so $x(N)$ belongs to some interval of our partition that contains $x(N)$. Let $t_N$ be one of the end points of the subinterval of the partition that contains $x(N)$. Then we have $|x(N)-t_N|<\frac{\varepsilon}{\sqrt{N}}$.
Now take the sequence $$t=(t_1,\dots,t_N,0,0,0,\dots)$$
This is actually one of the finite set (with cardinality $D$) of the sequences that we described earlier. But look:
$$\|x-t\|_2^2=\sum_{n=1}^N|x(n)-t_n|+\sum_{n\ge N+1}|x(n)|^2\leq\varepsilon^2+\sum_{n\ge N+1}a_n^2\leq2\varepsilon^2$$
so $\|x-t\|_2<\sqrt{2}\varepsilon$. This shows that the set $B_a$ is totally bounded.
A final comment: There is nothing special about intervals and partitions. What is being used here actually, is the fact that each of the intervals $[-a_N,a_N]$ is totally bounded, as a set. This is how one would work the complex case for example.
