[proofplan]
We encode the recurrence by multiplying the standard $2 \times 2$ matrices associated to the partial quotients. The product records the current and previous numerators and denominators, so the continued fraction identity follows by applying the corresponding fractional linear transformation to $\infty$, equivalently by reading off the first column. Positivity of the denominators follows directly from the recurrence and the convention $\mathbb{N}=\{1,2,3,\dots\}$, so each partial quotient $a_i$ with $i \geq 1$ is positive. The determinant identity follows because each matrix has determinant $-1$.
[/proofplan]
[step:Encode the recurrence by a matrix product]
The theorem statement defines the integer sequences $(p_n)_{n\geq -2}$ and $(q_n)_{n\geq -2}$ by the initial values
\begin{align*}
p_{-2}=0,\qquad p_{-1}=1,\qquad q_{-2}=1,\qquad q_{-1}=0,
\end{align*}
and by the recurrence relations
\begin{align*}
p_n=a_np_{n-1}+p_{n-2},\qquad q_n=a_nq_{n-1}+q_{n-2}
\end{align*}
for every integer $n\geq 0$. We will use these initial values and recurrence relations whenever we refer to the defining recurrences for the convergents.
For each integer $i \geq 0$, define the matrix $A_i \in M_2(\mathbb{Z})$ by declaring its entries as follows:
\begin{align*}
(A_i)_{11}=a_i.
\end{align*}
\begin{align*}
(A_i)_{12}=1.
\end{align*}
\begin{align*}
(A_i)_{21}=1.
\end{align*}
\begin{align*}
(A_i)_{22}=0.
\end{align*}
For each $n \geq 0$, define
\begin{align*}
P_n := A_0 A_1 \cdots A_n \in M_2(\mathbb{Z}).
\end{align*}
We prove by induction on $n \geq 0$ that the entries of $P_n$ are given by the following four identities:
\begin{align*}
(P_n)_{11}=p_n.
\end{align*}
\begin{align*}
(P_n)_{12}=p_{n-1}.
\end{align*}
\begin{align*}
(P_n)_{21}=q_n.
\end{align*}
\begin{align*}
(P_n)_{22}=q_{n-1}.
\end{align*}
For $n = 0$, we have $P_0=A_0$. The entry identities are
\begin{align*}
(P_0)_{11}=a_0=p_0.
\end{align*}
\begin{align*}
(P_0)_{12}=1=p_{-1}.
\end{align*}
\begin{align*}
(P_0)_{21}=1=q_0.
\end{align*}
\begin{align*}
(P_0)_{22}=0=q_{-1}.
\end{align*}
Here $p_0 = a_0p_{-1}+p_{-2}=a_0$, $q_0=a_0q_{-1}+q_{-2}=1$, $p_{-1}=1$, and $q_{-1}=0$.
Assume the identity holds for some $n-1 \geq 0$. Since $P_n=P_{n-1}A_n$, ordinary matrix multiplication gives
\begin{align*}
(P_n)_{11}=p_{n-1}a_n+p_{n-2}=p_n.
\end{align*}
\begin{align*}
(P_n)_{12}=p_{n-1}.
\end{align*}
\begin{align*}
(P_n)_{21}=q_{n-1}a_n+q_{n-2}=q_n.
\end{align*}
\begin{align*}
(P_n)_{22}=q_{n-1}.
\end{align*}
The two equalities involving $p_n$ and $q_n$ are exactly the defining recurrences. This completes the induction.
[guided]
The theorem statement defines the integer sequences $(p_n)_{n\geq -2}$ and $(q_n)_{n\geq -2}$ by
\begin{align*}
p_{-2}=0,\qquad p_{-1}=1,\qquad q_{-2}=1,\qquad q_{-1}=0,
\end{align*}
and by
\begin{align*}
p_n=a_np_{n-1}+p_{n-2},\qquad q_n=a_nq_{n-1}+q_{n-2}
\end{align*}
for every integer $n\geq 0$. The matrix method is a compact way to store these two second-order recurrences at once: one column records the current values, and the other column records the previous values.
The recurrence has exactly the same shape as multiplication by the matrix $A_i \in M_2(\mathbb{Z})$ whose entries are
\begin{align*}
(A_i)_{11}=a_i.
\end{align*}
\begin{align*}
(A_i)_{12}=1.
\end{align*}
\begin{align*}
(A_i)_{21}=1.
\end{align*}
\begin{align*}
(A_i)_{22}=0.
\end{align*}
Indeed, right multiplication by $A_i$ replaces a pair consisting of a current term and a previous term by the next term and the current term. This is why the product $P_n := A_0A_1\cdots A_n$ should contain both the $n$th and the $(n-1)$st convergent data.
We prove the precise entry formula for $P_n$ by induction. The formula consists of the four identities
\begin{align*}
(P_n)_{11}=p_n.
\end{align*}
\begin{align*}
(P_n)_{12}=p_{n-1}.
\end{align*}
\begin{align*}
(P_n)_{21}=q_n.
\end{align*}
\begin{align*}
(P_n)_{22}=q_{n-1}.
\end{align*}
For $n=0$, the initial recurrence gives
\begin{align*}
p_0=a_0p_{-1}+p_{-2}=a_0\cdot 1+0=a_0.
\end{align*}
\begin{align*}
q_0=a_0q_{-1}+q_{-2}=a_0\cdot 0+1=1.
\end{align*}
Since $P_0=A_0$, its four entries are $(P_0)_{11}=a_0$, $(P_0)_{12}=1$, $(P_0)_{21}=1$, and $(P_0)_{22}=0$. These are exactly $p_0$, $p_{-1}$, $q_0$, and $q_{-1}$, respectively.
Now assume the formula is known for $P_{n-1}$, where $n \geq 1$. Multiplying by the next matrix gives $P_n=P_{n-1}A_n$. By the row-column rule for matrix multiplication,
\begin{align*}
(P_n)_{11}=p_{n-1}a_n+p_{n-2}=p_n.
\end{align*}
\begin{align*}
(P_n)_{12}=p_{n-1}.
\end{align*}
\begin{align*}
(P_n)_{21}=q_{n-1}a_n+q_{n-2}=q_n.
\end{align*}
\begin{align*}
(P_n)_{22}=q_{n-1}.
\end{align*}
The two entries in the first column are exactly $p_n$ and $q_n$ by the recurrence, while the second column shifts the previous values forward. Therefore the asserted entry formula holds for $P_n$.
[/guided]
[/step]
[step:Recover the finite continued fraction from the matrix product]
For a real number $t > 0$ and an integer $i \geq 0$, define the fractional [linear map](/page/Linear%20Map) $T_i:(0,\infty)\to\mathbb{R}$ by
\begin{align*}
T_i(t)=a_i+\frac{1}{t}=\frac{a_i t+1}{t}.
\end{align*}
For every $i\geq 1$, the hypothesis $a_i\in\mathbb{N}$ gives $a_i>0$, so $T_i(t)>0$ whenever $t>0$. Thus the maps $T_1,\dots,T_{n-1}$ send positive inputs to positive outputs; no positivity of $T_0(t)$ is required because $T_0$ is applied only as the final map. For $n \geq 1$, the finite continued fraction satisfies
\begin{align*}
[a_0;a_1,\dots,a_n]=T_0\bigl(T_1(\cdots T_{n-1}(a_n)\cdots)\bigr).
\end{align*}
Since $a_n>0$ and each intermediate output under $T_i$ with $i\geq 1$ remains positive, all denominators occurring in this expression are positive, so the expression is defined.
We next record the composition formula. For every $n\geq 0$ and every positive input $t>0$ for which the nested expression $T_0(T_1(\cdots T_n(t)\cdots))$ is defined, the denominator in the rational expression below is nonzero and
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)=\frac{p_n t+p_{n-1}}{q_n t+q_{n-1}}.
\end{align*}
This follows by induction on $n$. For $n=0$, the formula is the identity $T_0(t)=(p_0t+p_{-1})/(q_0t+q_{-1})$. For the induction step, assume
\begin{align*}
T_0\bigl(T_1(\cdots T_{n-1}(s)\cdots)\bigr)=\frac{p_{n-1}s+p_{n-2}}{q_{n-1}s+q_{n-2}}
\end{align*}
for every admissible positive input $s$. Substitute
\begin{align*}
s=T_n(t)=\frac{a_n t+1}{t}.
\end{align*}
Then
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)
=\frac{p_{n-1}(a_n t+1)+p_{n-2}t}{q_{n-1}(a_n t+1)+q_{n-2}t}
=\frac{(a_np_{n-1}+p_{n-2})t+p_{n-1}}{(a_nq_{n-1}+q_{n-2})t+q_{n-1}}.
\end{align*}
Using the defining recurrences for $p_n$ and $q_n$, this becomes
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)=\frac{p_n t+p_{n-1}}{q_n t+q_{n-1}}.
\end{align*}
For $n\geq 1$, apply this formula to the positive input $t=a_n$ after stopping the composition at $T_{n-1}$. This input is admissible because $a_n>0$ and, as checked above, each intermediate tail obtained by applying $T_i$ with $i\geq 1$ remains positive. Hence the denominator in the displayed rational expression is nonzero. The preceding formula with index $n-1$ gives
\begin{align*}
[a_0;a_1,\dots,a_n]=\frac{p_{n-1}a_n+p_{n-2}}{q_{n-1}a_n+q_{n-2}}.
\end{align*}
By the defining recurrences, the numerator is $p_n$ and the denominator is $q_n$. Hence
\begin{align*}
[a_0;a_1,\dots,a_n]=\frac{p_n}{q_n}.
\end{align*}
For $n=0$, the same identity is immediate:
\begin{align*}
[a_0]=a_0=\frac{p_0}{q_0}.
\end{align*}
[guided]
We now connect the matrix identity to the actual continued fraction. For each integer $i\geq 0$, the map $T_i:(0,\infty)\to\mathbb{R}$ is defined by
\begin{align*}
T_i(t)=a_i+\frac{1}{t}=\frac{a_i t+1}{t}.
\end{align*}
The codomain is only $\mathbb{R}$ because $a_0$ may be negative. This causes no problem: $T_0$ is applied last, while the maps applied before it are $T_i$ with $i\geq 1$. For those indices, $a_i\in\mathbb{N}$ gives $a_i>0$, and hence $T_i(t)>0$ whenever $t>0$.
For $n\geq 1$, the recursive definition of the finite continued fraction gives
\begin{align*}
[a_0;a_1,\dots,a_n]=T_0\bigl(T_1(\cdots T_{n-1}(a_n)\cdots)\bigr).
\end{align*}
The input $a_n$ is positive, and every intermediate map $T_i$ with $i\geq 1$ preserves positivity, so all reciprocal operations in the expression are defined.
The product matrix $P_n$ represents the composition of these fractional linear maps. More precisely, for every $n\geq 0$ and every positive input $t>0$ for which the nested expression $T_0(T_1(\cdots T_n(t)\cdots))$ is defined, the denominator in the rational expression below is nonzero and
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)=\frac{p_n t+p_{n-1}}{q_n t+q_{n-1}}.
\end{align*}
This is proved by induction on $n$. For $n=0$, the formula is
\begin{align*}
T_0(t)=a_0+\frac{1}{t}=\frac{a_0t+1}{t}=\frac{p_0t+p_{-1}}{q_0t+q_{-1}},
\end{align*}
using $p_0=a_0$, $p_{-1}=1$, $q_0=1$, and $q_{-1}=0$.
Now assume the formula holds with index $n-1$. For an admissible positive input $t$, define
\begin{align*}
s=T_n(t)=\frac{a_nt+1}{t}.
\end{align*}
Substituting this value of $s$ into the induction hypothesis gives
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)
=\frac{p_{n-1}s+p_{n-2}}{q_{n-1}s+q_{n-2}}
=\frac{p_{n-1}\frac{a_nt+1}{t}+p_{n-2}}{q_{n-1}\frac{a_nt+1}{t}+q_{n-2}}.
\end{align*}
Multiplying numerator and denominator by the positive number $t$ gives
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)
=\frac{(a_np_{n-1}+p_{n-2})t+p_{n-1}}{(a_nq_{n-1}+q_{n-2})t+q_{n-1}}.
\end{align*}
The recurrence relations identify $a_np_{n-1}+p_{n-2}$ with $p_n$ and $a_nq_{n-1}+q_{n-2}$ with $q_n$, so
\begin{align*}
T_0\bigl(T_1(\cdots T_n(t)\cdots)\bigr)=\frac{p_nt+p_{n-1}}{q_nt+q_{n-1}}.
\end{align*}
Now apply this composition formula with index $n-1$ and input $t=a_n$. The input is admissible because $a_n>0$, and each map $T_i$ with $i\geq 1$ preserves positivity on positive inputs. Therefore the nested continued fraction tail is defined, and the denominator in the rational expression is nonzero. We obtain
\begin{align*}
[a_0;a_1,\dots,a_n]=\frac{p_{n-1}a_n+p_{n-2}}{q_{n-1}a_n+q_{n-2}}.
\end{align*}
By the defining recurrences for the convergents, the numerator is $p_n$ and the denominator is $q_n$. Therefore
\begin{align*}
[a_0;a_1,\dots,a_n]=\frac{p_n}{q_n}.
\end{align*}
For $n=0$, the identity is
\begin{align*}
[a_0]=a_0=\frac{p_0}{q_0},
\end{align*}
since $p_0=a_0$ and $q_0=1$.
[/guided]
[/step]
[step:Prove positivity of the denominators]
We prove $q_n>0$ for every $n\geq 0$ by induction. The initial values are
\begin{align*}
q_0 = 1 > 0,
\qquad
q_1 = a_1 q_0 + q_{-1} = a_1 > 0.
\end{align*}
Now let $n \geq 2$ and assume $q_{n-1}>0$ and $q_{n-2}>0$. Since $a_n\in\mathbb{N}=\{1,2,3,\dots\}$, we have $a_n\geq 1$, and hence
\begin{align*}
q_n = a_n q_{n-1}+q_{n-2} > 0.
\end{align*}
Thus $q_n>0$ for all $n\geq 0$.
[guided]
We prove the denominator positivity by induction because the recurrence for $q_n$ only involves the two preceding denominators. The initial values are
\begin{align*}
q_0=1>0.
\end{align*}
Also,
\begin{align*}
q_1=a_1q_0+q_{-1}=a_1\cdot 1+0=a_1>0,
\end{align*}
because $a_1\in\mathbb{N}$.
Now let $n\geq 2$ and assume the induction hypotheses $q_{n-1}>0$ and $q_{n-2}>0$. Since $a_n\in\mathbb{N}=\{1,2,3,\dots\}$, we have $a_n\geq 1$. Therefore both summands in the recurrence
\begin{align*}
q_n=a_nq_{n-1}+q_{n-2}
\end{align*}
are nonnegative, and in fact $q_{n-2}>0$. Hence
\begin{align*}
q_n=a_nq_{n-1}+q_{n-2}>0.
\end{align*}
By induction, $q_n>0$ for every $n\geq 0$.
[/guided]
[/step]
[step:Take determinants to obtain the alternating identity]
For every $i\geq 0$, the determinant formula for a $2\times 2$ matrix gives
\begin{align*}
\det A_i=a_i\cdot 0-1\cdot 1=-1.
\end{align*}
Therefore, for every $n\geq 0$,
\begin{align*}
\det P_n=\prod_{i=0}^n \det A_i=(-1)^{n+1}.
\end{align*}
Using the entry formula for $P_n$ from the first step, the determinant formula gives
\begin{align*}
\det P_n=p_n q_{n-1}-p_{n-1}q_n.
\end{align*}
Thus, for every $n\geq 1$,
\begin{align*}
p_n q_{n-1}-p_{n-1}q_n=(-1)^{n+1}=(-1)^{n-1},
\end{align*}
because the exponents $n+1$ and $n-1$ differ by $2$. This proves the determinant identity and completes the proof.
[guided]
The determinant identity is the invariant carried by the matrix product. For each $i\geq 0$, the determinant formula for a $2\times 2$ matrix gives
\begin{align*}
\det A_i=a_i\cdot 0-1\cdot 1=-1.
\end{align*}
The determinant is multiplicative for square matrices, so for
\begin{align*}
P_n=A_0A_1\cdots A_n
\end{align*}
we obtain
\begin{align*}
\det P_n=\prod_{i=0}^n \det A_i=(-1)^{n+1}.
\end{align*}
There are $n+1$ factors because the product runs from $0$ through $n$.
The first step identified the entries of $P_n$ as
\begin{align*}
(P_n)_{11}=p_n,
\end{align*}
\begin{align*}
(P_n)_{12}=p_{n-1},
\end{align*}
\begin{align*}
(P_n)_{21}=q_n,
\end{align*}
\begin{align*}
(P_n)_{22}=q_{n-1}.
\end{align*}
Applying the $2\times 2$ determinant formula to this entry description gives
\begin{align*}
\det P_n=p_nq_{n-1}-p_{n-1}q_n.
\end{align*}
Combining the two computations of $\det P_n$, we get
\begin{align*}
p_nq_{n-1}-p_{n-1}q_n=(-1)^{n+1}.
\end{align*}
For $n\geq 1$, the integers $n+1$ and $n-1$ differ by $2$, so the two powers of $-1$ agree:
\begin{align*}
(-1)^{n+1}=(-1)^{n-1}.
\end{align*}
Therefore
\begin{align*}
p_nq_{n-1}-p_{n-1}q_n=(-1)^{n-1},
\end{align*}
which is the claimed alternating determinant identity.
[/guided]
[/step]