Solution (source code)

= Solution

The <quantum variational principle> states that the energy expectation of an admissible trial <wavefunction> is at least the <ground state> energy:
$$
\boxed{\frac{\langle f,\widehat Hf\rangle}{\langle f,f\rangle}\ge E_0.}
$$
For the discrete, complete <orthonormal basis> assumed here, expand in <Hamiltonian operator> eigenfunctions, $f=\sum_n c_n\phi_n$, with $\widehat H\phi_n=E_n\phi_n$ and $E_n\ge E_0$. Then
$$
\frac{\langle f,\widehat Hf\rangle}{\langle f,f\rangle}-E_0
=\frac{\sum_n|c_n|^2(E_n-E_0)}{\sum_n|c_n|^2}\ge0.
$$
Every summand is nonnegative. Equality holds precisely when all occupied components lie in the ground eigenspace. Thus minimizing trial energies supplies upper bounds on $E_0$, with exact equality if the trial family contains a <ground state>.