\begin{helper}[Leading and terminal zero decomposition]
For an arbitrary finite list $D$ of natural numbers, let $S$ be the result of dropping
its maximal leading run of zeroes and let $R$ be the result of dropping the
maximal terminal run of zeroes from $S$.  There are natural numbers $z,q$
such that
\[
 z=|D|-|S|,\qquad q=|S|-|R|,
\]
\[
 D=0^z\mathbin{++}S,\qquad S=R\mathbin{++}0^q.
\]
Moreover, $S$ is empty or begins with a nonzero entry, and $R$ is empty or
ends with a nonzero entry.
\end{helper}
\begin{proof}
Split $D$ with the standard identity that a list's \texttt{takeWhile} prefix
followed by its \texttt{dropWhile} suffix is the original list.  Every member
of the taken prefix satisfies equality with zero, so extensionality identifies
that prefix with $0^z$, where $z$ is its length.  Taking lengths of the split
gives $z=|D|-|S|$.  If $S$ is nonempty, the defining maximality theorem for
\texttt{dropWhile} says its head fails the zero predicate, hence that entry is
nonzero.

Apply the same construction to the reverse of $S$.  Its taken zero prefix is
$0^q$; reversing the take/drop split gives
$S=R\mathbin{++}0^q$, and lengths give $q=|S|-|R|$.  If $R$ is nonempty,
its last entry is the head of the reversed dropped suffix.  Maximality of
that second \texttt{dropWhile} makes this entry nonzero.  The definition of
$R$ as reverse-after-drop is exactly the trimming expression in the
statement, so all asserted equalities follow.
\end{proof}
