TITLE: Understanding inequality in Keane's proof of the ergodic theorem
QUESTION [5 upvotes]: I know a few proofs of the ergodic theorem but I just cannot figure out this inequality. Let's take $(X, B_X, \mu, T)$ to be a measure preserving system and $B \in B_X$. Let 
$$S_n(x):= \left|\{i < n \ | \ T^ix \in B \}\right| = \sum_{i=0}^{n-1}\chi_B(T^ix)$$
$$A_n(x):= \frac{1}{n}S_n(x)\mbox{ and } \bar A(x) =\limsup_{n\to \infty}A_n(x)$$.
The ergodic theorem is proved for indicators if $\int_X \bar A(x)d\mu \leq \mu (B)$ by replacing $B$ with $X - B$. Defining for a given $\varepsilon > 0$
$\tau (x):=\min \left\{ n \ | \ A_n(x) \geq \bar A(x) - \varepsilon \right\}$. Assuming that $\tau(x) \leq M$ for all $x$ he claims that 
$$S_n(x) \geq (n-M)\left(\bar A(x) - \varepsilon\right).$$
can someone please explain this inequality?
Thanks in advance.

REPLY [3 votes]: The idea here is to iterate. Fix some $x$ and define $x_0 = x$. Notice that if $n \le M$ the claim is imediate. Let us assume that $n > M$ then. We have by definition
\begin{equation}
S_{\tau(x)}(x) \geq \tau(x) (\bar{A}(x) - \varepsilon).
\end{equation}
Now, define $x_1 = T^{\tau(x)}x$ and more generally, $x_k = T^{\tau(x_{k-1})}(x_{k-1})$. We have once again by definition:
\begin{equation}
S_{\tau(x_i)}(x_i) \geq \tau(x_i)(\bar{A}(x_i) - \varepsilon).
\end{equation}
Notice that since all the $x_i$ belong to the orbit of $x$, we have the equality $\bar{A}(x_i) = \bar{A}(x)$. Now, let us define $j = \max\{k; \tau(x_0) + \ldots + \tau(x_k) \le n\}$. Since all $\tau(y)$ are uniformly less than $M$, we have
\begin{equation}
n - (\tau(x_0) + \ldots + \tau(x_j)) \le M
\end{equation}
Thus, we can write
\begin{align}
S_n(x) &= S_n(x) - S_{\tau(x_0) + \ldots + \tau(x_j)}(x) + \sum_{i=1}^{j} \left( S_{\tau(x_0) + \ldots + \tau(x_i)}(x) - S_{\tau(x_0) + \ldots + \tau(x_{i-1})}(x) \right) + S_{\tau(x)}(x)\\
&= S_n(x) - S_{\tau(x_0) + \ldots + \tau(x_j)}(x) + \sum_{i=1}^{j} S_{\tau(x_i)}(x_i) + S_{\tau(x)}(x)\\
&\geq  0 + \sum_{i=0}^j \tau(x_i)(\bar{A}(x) - \varepsilon) \geq (n - M)(\bar{A}(x) - \varepsilon).
\end{align}