Solution (source code)

= Solution

Since $xp_n-p_{n+1}$ has <degree of a polynomial> at most $n$, expand it in the <basis> $p_0,\ldots,p_n$. Multiplication by $x$ is <self-adjoint> for this weighted <inner product>: $\langle xp,q\rangle=\langle p,xq\rangle$. For $k\leq n-2$, the polynomial $xp_k$ has degree at most $n-1$, so
$$
\langle xp_n-p_{n+1},p_k\rangle=\langle p_n,xp_k\rangle=0.
$$
Only the $p_n$ and $p_{n-1}$ coefficients remain. Taking their <inner products> gives \b[the three-term recurrence]
$$
\boxed{p_{n+1}=(x-\alpha_n)p_n-\beta_n p_{n-1},\qquad \alpha_n=\frac{\langle xp_n,p_n\rangle}{\langle p_n,p_n\rangle},\quad \beta_n=\frac{\langle p_n,p_n\rangle}{\langle p_{n-1},p_{n-1}\rangle}>0\ (n\geq1).}
$$
For the second formula, $xp_{n-1}=p_n+$ a polynomial of lower degree, hence $\langle xp_n,p_{n-1}\rangle=\langle p_n,xp_{n-1}\rangle=\langle p_n,p_n\rangle$. At $n=0$, take $p_{-1}=0$, $\beta_0=0$ and the same formula for $\alpha_0$. Positivity of the weight ensures that all the squared <norms> in the denominators are nonzero.