Solution (source code)

= Solution

The <Birkhoff ergodic theorem> states: for a <measure-preserving transformation> $\theta$ of a <finite measure> space and $f\in L^1$, the averages $A_nf=n^{-1}\sum_{j=0}^{n-1}f\circ\theta^j$ converge <almost everywhere> and in $L^1$ to an invariant function $f^*$. On a <probability space>,
$$
\boxed{f^*=\mathbb E[f\mid\mathcal I],}
$$
where $\mathcal I$ is the <invariant sigma-algebra> modulo null sets. In particular the integral is preserved, and if $\theta$ is ergodic then $f^*=\int f\,d\mu$ <almost everywhere>; for a finite space of nonunit mass, this constant is $\mu(E)^{-1}\int f\,d\mu$ when $\mu(E)>0$.

The <maximal ergodic lemma> says that for real integrable $f$, with $S_kf=\sum_{j=0}^{k-1}f\circ\theta^j$ and $E_N=\{\max_{1\leq k\leq N}S_kf>0\}$,
$$
\boxed{\int_{E_N}f\,d\mu\geq0.}
$$
The same inequality holds on $E_\infty=\{\sup_{k\geq1}S_kf>0\}$, by taking the increasing <limit> and dominated convergence. These statements do not require the transformation to be invertible or the space to be ergodic.