Solution (source code)

= Solution

Put $\delta=w-u$, which vanishes on the boundary. Expanding the <Dirichlet energy> gives
$$
\int_S|\nabla w|^2\,dA
=\int_S|\nabla u|^2\,dA+2\int_S\nabla u\cdot\nabla\delta\,dA+\int_S|\nabla\delta|^2\,dA.
$$
The cross term vanishes by integration by parts: it is $\int_{\partial S}\delta\partial_nu\,ds-\int_S\delta\Delta u\,dA=0$, using both the zero boundary values of $\delta$ and <Laplace's equation> for $u$. Thus the <Dirichlet principle> gives the stronger identity
$$
\boxed{\int_S|\nabla w|^2\,dA-\int_S|\nabla u|^2\,dA=\int_S|\nabla(w-u)|^2\,dA\geq0.}
$$
With the usual regular boundary, equality forces $w=u$.

In the unit disc, take boundary data $\cos\theta$. The <harmonic function> $u=r\cos\theta=x$ realizes these data and has constant <gradient> of length one, so its energy is $\pi$. For $w=g(r)\cos\theta$, the polar <gradient> gives
$$
\int_S|\nabla w|^2\,dA
=\int_0^1\int_0^{2\pi}\left[g'^2\cos^2\theta+\frac{g^2}{r^2}\sin^2\theta\right]r\,d\theta\,dr
=\pi\int_0^1\left(rg'^2+\frac{g^2}{r}\right)\,dr.
$$
The energy principle therefore yields the <sharp radial Dirichlet energy inequality>
$$
\boxed{\int_0^1\left(rg'^2+\frac{g^2}{r}\right)dr\geq1.}
$$

There is a small regularity point at the centre: finite energy need not make the polar expression classically smooth there. The bound still holds under the stated finite-energy condition. Indeed for $0<s<t$,
$$
|g(t)^2-g(s)^2|
\leq2\left(\int_s^t rg'^2\,dr\right)^{1/2}
\left(\int_s^t\frac{g^2}{r}\,dr\right)^{1/2}.
$$
The tails tend to zero, so $g^2$ has a limit at zero. That limit must be zero, since a positive limit would make $\int g^2/r$ diverge. Completing the square on $[\varepsilon,1]$ and letting $\varepsilon\to0$ gives
$$
\int_0^1\left(rg'^2+\frac{g^2}{r}\right)dr
=1+\int_0^1r\left(g'-\frac gr\right)^2dr.
$$
This proves the finite-energy extension directly, and also shows that \b[equality holds exactly for $g(r)=r$].