[guided]Assume that $u$ is a classical solution. This means that the pointwise identity
\begin{align*}
-\Delta u(x)=f(x)
\end{align*}
holds for every $x \in U$. To prove that $u$ is a weak solution, we must show the weak identity for an arbitrary test function. Let
\begin{align*}
\phi: U \to \mathbb{R}
\end{align*}
be any function in $C_c^\infty(U)$, and let $K:=\operatorname{supp}\phi$. The compact support condition matters because it removes boundary terms: all integrations by parts happen inside a compact subset of $U$.
Fix an index $i \in \{1,\dots,n\}$. Since $u \in C^2(U)$, the partial derivative $\partial_{x_i}u$ is $C^1$ on $U$. Since $\phi \in C_c^\infty(U)$, the product
\begin{align*}
x \mapsto \phi(x)\,\partial_{x_i}u(x)
\end{align*}
is a compactly supported $C^1$ function on $U$. The integral of its $x_i$ derivative over $U$ is zero, because the compact support lies away from the boundary of $U$:
\begin{align*}
\int_U \partial_{x_i}\bigl(\phi(x)\,\partial_{x_i}u(x)\bigr)\, d\mathcal{L}^n(x) = 0.
\end{align*}
Expanding the derivative gives
\begin{align*}
\partial_{x_i}\bigl(\phi\,\partial_{x_i}u\bigr)=\partial_{x_i}\phi\,\partial_{x_i}u+\phi\,\partial_{x_i}^2u.
\end{align*}
Substituting this identity into the integral gives
\begin{align*}
\int_U \partial_{x_i}\phi(x)\,\partial_{x_i}u(x)\, d\mathcal{L}^n(x) + \int_U \phi(x)\,\partial_{x_i}^2u(x)\, d\mathcal{L}^n(x)=0.
\end{align*}
Rearranging, we obtain
\begin{align*}
\int_U \partial_{x_i}u(x)\,\partial_{x_i}\phi(x)\, d\mathcal{L}^n(x) = -\int_U \phi(x)\,\partial_{x_i}^2u(x)\, d\mathcal{L}^n(x).
\end{align*}
Now sum this identity over all coordinate directions $i=1,\dots,n$. The left-hand side becomes the gradient [inner product](/page/Inner%20Product), and the right-hand side becomes the negative Laplacian:
\begin{align*}
\int_U \nabla u(x)\cdot \nabla \phi(x)\, d\mathcal{L}^n(x) = \int_U \bigl(-\Delta u(x)\bigr)\phi(x)\, d\mathcal{L}^n(x).
\end{align*}
Finally, the classical equation says $-\Delta u=f$ pointwise, so the last display becomes
\begin{align*}
\int_U \nabla u(x)\cdot \nabla \phi(x)\, d\mathcal{L}^n(x) = \int_U f(x)\phi(x)\, d\mathcal{L}^n(x).
\end{align*}
This is exactly the weak formulation, and since $\phi$ was arbitrary, $u$ is a weak solution.[/guided]