[step:Construct the orthogonal matrix $P$ from the orthonormal image vectors]
For each $i = 1, \dots, m$, set $u_i := A q_i \in \mathbb{R}^n$. We compute the inner products: for $i, j \in \{1, \dots, m\}$,
\begin{align*}
u_i \cdot u_j = (A q_i)^\top (A q_j) = q_i^\top A^\top A q_j = q_i^\top G q_j = q_i^\top \lambda_j q_j = \lambda_j (q_i \cdot q_j) = \lambda_j \delta_{ij},
\end{align*}
where $\delta_{ij}$ is the Kronecker delta and we used $G q_j = \lambda_j q_j$ together with the orthonormality $q_i \cdot q_j = \delta_{ij}$. In particular,
\begin{align*}
|u_i|^2 = \lambda_i = \sigma_i^2, \qquad u_i \cdot u_j = 0 \text{ for } i \ne j.
\end{align*}
Let $r := \#\{i : \sigma_i > 0\}$, the number of strictly positive singular values. Since the $\sigma_i$ are non-increasing, $\sigma_1, \dots, \sigma_r > 0$ and $\sigma_{r+1} = \cdots = \sigma_m = 0$. For $i = 1, \dots, r$, define
\begin{align*}
p_i := \frac{u_i}{\sigma_i} \in \mathbb{R}^n,
\end{align*}
so $|p_i|^2 = |u_i|^2 / \sigma_i^2 = \sigma_i^2 / \sigma_i^2 = 1$. The orthogonality computation above gives $p_i \cdot p_j = (u_i \cdot u_j)/(\sigma_i \sigma_j) = \delta_{ij}$ for $i, j \in \{1, \dots, r\}$. Hence $\{p_1, \dots, p_r\}$ is an orthonormal set in $\mathbb{R}^n$.
We now invoke the hypothesis of the theorem that $m \le n$. Since $r \le m$ (as $r$ counts a subset of indices $\{1, \dots, m\}$) and $m \le n$ by hypothesis, we have $r \le n$. Therefore the orthonormal set $\{p_1, \dots, p_r\} \subset \mathbb{R}^n$ has at most $n$ elements and can be extended: choose any vectors $w_{r+1}, \dots, w_n \in \mathbb{R}^n$ such that $\{p_1, \dots, p_r, w_{r+1}, \dots, w_n\}$ is a basis of $\mathbb{R}^n$ (possible since $r \le n$), and apply Gram–Schmidt orthonormalisation to this basis, leaving the already-orthonormal vectors $p_1, \dots, p_r$ unchanged and producing orthonormal vectors $p_{r+1}, \dots, p_n \in \mathbb{R}^n$. The result is an orthonormal basis $\{p_1, \dots, p_n\}$ of $\mathbb{R}^n$. Define
\begin{align*}
P := [p_1\ p_2\ \cdots\ p_n] \in \mathbb{R}^{n \times n}.
\end{align*}
Then $P$ is orthogonal: $(P^\top P)_{ij} = p_i \cdot p_j = \delta_{ij}$, so $P^\top P = I_n$.
[/step]