Solution (source code)

= Solution

Interpret the comparison at $N$ on $\{N<\infty\}$; values at an infinite <stopping time> are not required. The <stopping time> events make $Y_n$ adapted, and $|Y_n|\leq|X_n^1|+|X_n^2|$ gives <integrability>. On $\{N\leq n\}$ the next value is $X_{n+1}^2$. On $\{N>n\}$ it is $X_{n+1}^1$ unless $N=n+1$, and on that latter event switching only decreases the value. Consequently the pointwise inequality
$$
Y_{n+1}\leq\mathbf1_{\{N>n\}}X_{n+1}^1+\mathbf1_{\{N\leq n\}}X_{n+1}^2
$$
holds even though $\{N=n+1\}$ need not be known at time $n$. Both indicators displayed here are $\mathcal F_n$-<measurable>. Taking <conditional expectations> and using the two <supermartingale> inequalities therefore gives
$$
\mathbb E[Y_{n+1}\mid\mathcal F_n]\leq\mathbf1_{\{N>n\}}X_n^1+\mathbf1_{\{N\leq n\}}X_n^2=Y_n.
$$
Thus $\boxed{Y\text{ is a supermartingale}.}$ This proves <pasting supermartingales with downward jumps> without incorrectly treating the future switching event as predictable.