Solution (source code)

= Solution

The <continued-fraction matrix> for the original finite continued fraction is
$$
M(a_0)\cdots M(a_n)
=\begin{pmatrix}p_n&p_{n-1}\\q_n&q_{n-1}\end{pmatrix}.
$$
Each $M(a_j)$ is a <symmetric matrix>, so reversing the order gives the transpose:
$$
M(a_n)\cdots M(a_0)
=\begin{pmatrix}p_n&q_n\\p_{n-1}&q_{n-1}\end{pmatrix}.
$$
Reading off the columns proves the <reversal identity for a finite continued fraction>:
$$
\boxed{[a_n,\ldots,a_0]=\frac{p_n}{p_{n-1}},
\qquad
[a_n,\ldots,a_1]=\frac{q_n}{q_{n-1}}.}
$$
These are respectively the $n$th and $(n-1)$th convergents of the reversed continued fraction.