key identities in the proof of Optional Sampling Theorem Let $(\Omega,\mathscr{F},\mu)$ be a $\sigma$-finite measure space,
let $(\mathscr{F}_n)_{n\in\mathbb{N}}$ be a filtration of sub-sigma-algebras
of $\mathscr{F}$, let $(u_n)_{n\in\mathbb{N}}$ be a submartingale
relative to $(\mathscr{F}_n)_{n\in\mathbb{N}}$,
and let $\sigma$ and $\tau$ be bounded stopping times (relative to $(\mathscr{F}_n)_{n\in\mathbb{N}}$) such that $\color{red}{\sigma\leq\tau\leq N}$.
The Optional Sampling Theorem states that
$$
\int(u_\sigma-u_\tau)d\mu\leq0.
$$
One way to prove this is to use the key identities
$$
\color{black}{\int(u_\sigma-u_\tau)d\mu}
=\color{blue}{\int\sum_{n=\sigma(w)}^{\tau(w)-1}\big(u_n(w)-u_{n+1}(w)\big)\mu(dw)}
=\color{green}{\sum_{n=0}^{N-1}\int(u_n-u_{n+1})1_{[\sigma=n]\cap[\tau>n]}d\mu}.
$$
The identity black=blue is easy. However, I have been struggling with blue-->green. Though it looks simple, I could not find a rigorous way to establish this.
My question: Is there a rigorous way to establish the blue=green identity? I guess there is some telescoping here, but really cannot figure out a way.
Any help/hint is highly appreciated.
 A: The equation doesn't hold true. Consider the submartingale $u_n := n$ and some stopping times $0 \leq \sigma < \tau \leq N$. The right-hand side of your equation equals
$$\int u_{\sigma}-u_{\tau}) \, d\mu = \int (\sigma-\tau) \, d\mu \tag{1}$$
whereas the right-hand side of the equation equals
\begin{align*} \sum_{n=0}^{N-1} \int (u_n-u_{n+1}) 1_{\{\sigma=n\}} 1_{\{\tau>n\}} \, d\mu &\stackrel{\sigma < \tau}{=} \sum_{n=0}^{N-1} \int (u_n-u_{n+1}) 1_{\{\sigma=n\}} \, d\mu \\ &= \int (u_{\sigma}-u_{\sigma+1}) \, d\mu  \\ &= \int (\sigma- (\sigma+1)) \, d\mu =  - \mu(\Omega). \tag{2} \end{align*}
In general, $(1)$ fails to equal $(2)$; consider e.g. deterministic stopping times $\sigma := 2$ and $\tau := 4$.

However, the following equation holds true:
$$\int u_{\sigma}-u_{\tau}) \, d\mu = \sum_{n=0}^{N-1} \int (u_n-u_{n+1}) 1_{\{ \color{red}{\sigma \leq n}\} \cap \{\tau>n\}} \, d\mu \tag{3}$$
The boundedness of $\tau$ implies that the sum $\sum_{n=\sigma(\omega)}^{\tau(\omega)-1}$ is a finite sum: there are at most $N-1$ terms to deal with. This means, in particular that we won't need any limit theorems (as the dominated convergence theorem) to prove the identity which you are looking for.
Since $\tau \leq N$ we can write
$$\sum_{n=\sigma(\omega)}^{\tau(\omega)-1} (u_n(\omega)-u_{n+1}(\omega)) = \sum_{n=0}^{N-1} (u_n(\omega) - u_{n+1}(\omega)) 1_{\{n<\tau(\omega)\}} 1_{\{n \geq \sigma(\omega)\}}.$$
Taking the expectation with respect to $\mu$ gives immediately $(3)$.
