In Peter Walter's Ergodic Theory book in theorem 1.6 we want to prove that if a measure preserving map $T:X \to X$ is ergodic for a probability space $(X,\mathbb{B},m)$ then if $f$ is measurable and $(f \circ T)(x)=f(x)$ a.e then $f$ is constant a.e.
In the proof a set has been constructed $X(k,n)= \{x : \frac{k}{2^n} \leq f(x) \leq \frac{k+1}{2^n} \}$ and it is said that for a fixed $n$ we have
\begin{align} \bigcup_{k \in \mathbb{Z}} X(k,n) = X \end{align}
I can't see why it is true? Could you please help me understand it in detail?
Suppose that $f$ take values on $\mathbb{R}$, otherwise the above equality it's not true. In other words, assume that $-\infty<f(x)<\infty$ for every $x\in X$. Fix some $n$ and $x\in X$. Then, $$-\infty<2^nf(x)<\infty.$$ In other words, $k\leq 2^nf(x)<k+1$, where $k=[2^nf(x)]$ is the integer part of $2^nf(x)$. Divide both sides by $2^n$ to get $$\frac{k}{2^n}\leq f(x)<\frac{k+1}{2^n}.$$ In other words, $x\in X(n,k)$. Hence, $x\in \bigcup_{k\in \mathbb{Z}}X(n,k)$. As $x$ was arbitrary chosen it follows that $X\subseteq \bigcup_{k\in \mathbb{Z}}X(n,k)$. As the other inclusion is obvious we obtain the desired equality.