Solution (source code)

= Solution

The <filtration> is generated by the successive <independent random variables> $X_k$. Each $S_n$ is <adapted>, and $|S_n|\leq n$ makes it an <integrable random variable>. Since <independence> gives $\mathbb E[X_{n+1}\mid\mathcal F_n]=0$,
$$
\mathbb E[S_{n+1}\mid\mathcal F_n]=S_n.
$$
Thus $(S_n)$ is a <martingale>.

Write the accumulated number of visits to zero as
$$
L_n=\sum_{k=0}^{n-1}\mathbf1_{\{S_k=0\}},\qquad L_0=0.
$$
It is <adapted>, and $0\leq L_n\leq n$. Thus $M_n=|S_n|-L_n$ is also <adapted> and an <integrable random variable>. For every integer $s$,
$$
\frac{|s+1|+|s-1|}{2}-|s|
=\begin{cases}1,&s=0,\\0,&s\ne0.\end{cases}
$$
Conditioning on $S_n$ and using <independence> of the next step therefore gives
$$
\mathbb E[|S_{n+1}|-|S_n|\mid\mathcal F_n]
=\mathbf1_{\{S_n=0\}}
=L_{n+1}-L_n.
$$
The drift of the absolute value is cancelled exactly by the visit count, so $\mathbb E[M_{n+1}-M_n\mid\mathcal F_n]=0$. Hence \b[both $(S_n)$ and $(M_n)$ are martingales]. The latter is the <absolute value martingale of a simple symmetric random walk>, a <discrete Tanaka formula> in which visits to zero supply the correction at the corner of the absolute-value <function>.