Solution (source code)

= Solution

A real <inner product> is a symmetric bilinear map $\langle\cdot,\cdot\rangle:V\times V\to\mathbb R$ with $\langle v,v\rangle>0$ for $v\ne0$. It defines $\|v\|=\sqrt{\langle v,v\rangle}$. Set $W=\operatorname{span}\{e_1,\ldots,e_k\}$ and $Pv=\sum_i\langle v,e_i\rangle e_i$. Orthonormality gives $v-Pv\perp W$, hence the <Pythagorean identity> gives
$$
\|v\|^2=\|v-Pv\|^2+\sum_i\langle v,e_i\rangle^2.
$$
This proves <Bessel's inequality>. \b[Equality holds exactly when $v\in W$.]