[step:Use rational superlevel sets to force a fixed real function to be constant, proving $(i)\Rightarrow(ii)$]Assume $T$ is ergodic, and let $[f]\in L^2(X,\mathcal{B},\mu)$ satisfy $U_T[f]=[f]$. We show $[f]$ is $\mu$-a.e. constant.
**Reduction to a finite-valued real representative.** Consider first the real case $\mathbb{K}=\mathbb{R}$. Pick any measurable representative $f_0:X\to[-\infty,+\infty]$ of $[f]$ with $\int_X|f_0|^2\,d\mu<\infty$. Since $|f_0|^2$ is finite $\mu$-a.e. (an extended-real function with finite Lebesgue integral takes the value $\pm\infty$ only on a $\mu$-null set), the set
\begin{align*}
N_\infty=\{x\in X:|f_0(x)|=\infty\}
\end{align*}
satisfies $\mu(N_\infty)=0$. Define a new representative
\begin{align*}
f:X&\to\mathbb{R}\\
x&\mapsto\begin{cases}f_0(x),&x\notin N_\infty,\\ 0,&x\in N_\infty.\end{cases}
\end{align*}
Then $f$ is $(\mathcal{B},\mathcal{B}(\mathbb{R}))$-measurable, finite-valued, and equals $f_0$ outside the $\mu$-null set $N_\infty$, so $[f]=[f_0]$. The condition $f_0\circ T=f_0$ $\mu$-a.e. transfers to $f\circ T=f$ $\mu$-a.e. because modification on the $\mu$-null set $N_\infty$ changes both sides of the equation only on a $\mu$-null set, namely on $N_\infty\cup T^{-1}N_\infty$, which has $\mu$-measure $0$ by measure preservation and subadditivity. Define the exceptional set
\begin{align*}
N=\{x\in X:f(Tx)\ne f(x)\}\in\mathcal{B},\qquad\mu(N)=0.
\end{align*}
**Rational superlevel sets are almost invariant.** Let $\mathbb{Q}\subseteq\mathbb{R}$ denote the rational numbers. For each $q\in\mathbb{Q}$ define
\begin{align*}
A_q=\{x\in X:f(x)>q\}\in\mathcal{B},
\end{align*}
which is measurable because $f$ is. For $x\in X\setminus N$ we have $f(Tx)=f(x)$, so
\begin{align*}
x\in T^{-1}A_q
&\iff f(Tx)>q\\
&\iff f(x)>q\\
&\iff x\in A_q,
\end{align*}
whence $T^{-1}A_q\triangle A_q\subseteq N$. Therefore $\mu(T^{-1}A_q\triangle A_q)\le\mu(N)=0$, i.e. $A_q\in\mathcal{I}$. By the ergodicity hypothesis,
\begin{align*}
\mu(A_q)\in\{0,1\}\quad\text{for every }q\in\mathbb{Q}.
\end{align*}
**Extracting a real constant.** Define
\begin{align*}
S=\{q\in\mathbb{Q}:\mu(A_q)=1\}\subseteq\mathbb{Q}.
\end{align*}
We show $S$ is nonempty. If $S=\varnothing$, then $\mu(A_{-m})=0$ for every $m\in\mathbb{N}$. Because $f$ is finite-valued, $X=\bigcup_{m=1}^{\infty}A_{-m}$, and [Countable Subadditivity](/theorems/1108) yields
\begin{align*}
1=\mu(X)\le\sum_{m=1}^{\infty}\mu(A_{-m})=0,
\end{align*}
a contradiction. Hence $S\ne\varnothing$.
Next we show $S\ne\mathbb{Q}$. If $S=\mathbb{Q}$, then $\mu(A_m)=1$ for every $m\in\mathbb{N}$, so by countable subadditivity
\begin{align*}
\mu\left(X\setminus\bigcap_{m=1}^{\infty}A_m\right)
=\mu\left(\bigcup_{m=1}^{\infty}(X\setminus A_m)\right)
\le\sum_{m=1}^{\infty}\mu(X\setminus A_m)=0,
\end{align*}
so $\mu\bigl(\bigcap_{m=1}^{\infty}A_m\bigr)=1$. But finite-valuedness of $f$ forces $\bigcap_{m=1}^{\infty}A_m=\varnothing$, contradicting $\mu(X)=1$.
The set $S$ is downward closed in $\mathbb{Q}$: if $q,r\in\mathbb{Q}$ with $q<r$ and $r\in S$, then $A_r\subseteq A_q$, so
\begin{align*}
1=\mu(A_r)\le\mu(A_q)\le 1,
\end{align*}
and $q\in S$. Since $S$ is nonempty, downward closed, and not all of $\mathbb{Q}$ (in particular, bounded above by some rational $r\notin S$), the real supremum
\begin{align*}
c_*=\sup_{\mathbb{R}}S\in\mathbb{R}
\end{align*}
is finite. Every rational $q<c_*$ lies in $S$ (otherwise $c_*$ would not be the supremum, by downward closure), and every rational $q>c_*$ lies outside $S$. Hence $\mu(A_q)=1$ for $q\in\mathbb{Q}\cap(-\infty,c_*)$ and $\mu(A_q)=0$ for $q\in\mathbb{Q}\cap(c_*,\infty)$.
Define the full-measure pinning set
\begin{align*}
B_-&=\bigcap_{\substack{q\in\mathbb{Q}\\ q<c_*}}A_q,\\
B_+&=\bigcap_{\substack{q\in\mathbb{Q}\\ q>c_*}}(X\setminus A_q),\\
B&=B_-\cap B_+.
\end{align*}
Each intersection is countable because $\mathbb{Q}$ is countable, so $B_-,B_+,B\in\mathcal{B}$. By countable subadditivity,
\begin{align*}
\mu(X\setminus B_-)&\le\sum_{\substack{q\in\mathbb{Q}\\ q<c_*}}\mu(X\setminus A_q)=0,\\
\mu(X\setminus B_+)&\le\sum_{\substack{q\in\mathbb{Q}\\ q>c_*}}\mu(A_q)=0,
\end{align*}
so $\mu(B)=1$.
Let $x\in B$. If $f(x)<c_*$, then by [Density of Rationals](/theorems/740) there is $q\in\mathbb{Q}$ with $f(x)<q<c_*$; since $q<c_*$ we have $x\in B_-\subseteq A_q$, forcing $f(x)>q$, contradiction. Hence $f(x)\ge c_*$. If $f(x)>c_*$, then density gives $q\in\mathbb{Q}$ with $c_*<q<f(x)$; since $q>c_*$ we have $x\in B_+\subseteq X\setminus A_q$, forcing $f(x)\le q$, contradiction. Hence $f(x)\le c_*$. Therefore $f(x)=c_*$ for every $x\in B$, and $\mu(B)=1$ gives $f=c_*$ $\mu$-a.e.
**The complex case.** Suppose now $\mathbb{K}=\mathbb{C}$. Choose a measurable representative $f:X\to\mathbb{C}$ of $[f]$ with $\int_X|f|^2\,d\mu<\infty$ and $f\circ T=f$ $\mu$-a.e. Then $\operatorname{Re}f,\operatorname{Im}f:X\to\mathbb{R}$ are measurable, satisfy $|\operatorname{Re}f|,|\operatorname{Im}f|\le|f|$, hence both lie in $L^2(X,\mathcal{B},\mu)$ (with real scalars). The identity $f\circ T=f$ $\mu$-a.e. gives, by taking real and imaginary parts,
\begin{align*}
(\operatorname{Re}f)\circ T&=\operatorname{Re}f\ \mu\text{-a.e.},\\
(\operatorname{Im}f)\circ T&=\operatorname{Im}f\ \mu\text{-a.e.}
\end{align*}
Applying the real case to each yields real constants $a_*,b_*\in\mathbb{R}$ with $\operatorname{Re}f=a_*$ and $\operatorname{Im}f=b_*$ $\mu$-a.e., so $f=a_*+ib_*$ $\mu$-a.e.[/step]