[proofplan]
The forward implication follows by restricting a $C^2$ function to an open subset. For the reverse implication, we fix an arbitrary point and use its local $C^2$ neighbourhood to prove that the global first and second partial derivatives exist there and agree with the corresponding derivatives of the restriction. Since the local derivatives are continuous on that neighbourhood, the global derivatives are continuous at the chosen point. As the point was arbitrary, the defining conditions for $f \in C^2(U)$ hold on all of $U$.
[/proofplan]
[step:Restrict a globally $C^2$ function to open neighbourhoods]
Assume $f \in C^2(U)$. For each $x \in U$, choose $V_x := U$. Then $V_x$ is open, $x \in V_x$, and $V_x \subset U$. The restriction $f|_{V_x}=f$ belongs to $C^2(V_x)$, so the stated local condition holds.
[/step]
[step:Recover the global partial derivatives from the local restrictions]
Assume conversely that for every $x \in U$ there exists an [open set](/page/Open%20Set) $V_x \subset U$ with $x \in V_x$ such that $f|_{V_x} \in C^2(V_x)$. Fix $x \in U$ and choose such a neighbourhood $V_x$.
Let $i,j \in \{1,\dots,n\}$. Since $V_x$ is open, for each $y \in V_x$ there exists $\rho_y > 0$ such that $y + t e_i \in V_x$ whenever $|t| < \rho_y$, where $e_i \in \mathbb R^n$ denotes the $i$-th standard basis vector. For such $t \ne 0$,
\begin{align*}
\frac{f(y+t e_i)-f(y)}{t}=\frac{(f|_{V_x})(y+t e_i)-(f|_{V_x})(y)}{t}.
\end{align*}
Because $f|_{V_x} \in C^2(V_x)$, the limit of the right-hand side as $t \to 0$ exists. Hence $\partial_{x_i}f(y)$ exists and
\begin{align*}
\partial_{x_i}f(y)=\partial_{x_i}(f|_{V_x})(y).
\end{align*}
Applying the same argument to the function $\partial_{x_i}(f|_{V_x}): V_x \to \mathbb R$, the second [partial derivative](/page/Partial%20Derivative) $\partial_{x_j}\partial_{x_i}f(y)$ exists and
\begin{align*}
\partial_{x_j}\partial_{x_i}f(y)=\partial_{x_j}\partial_{x_i}(f|_{V_x})(y).
\end{align*}
[guided]
We prove the local-to-global derivative statement directly from the definition of partial derivatives. Fix $x \in U$ and choose an open set $V_x \subset U$ with $x \in V_x$ and $f|_{V_x} \in C^2(V_x)$. Let $i \in \{1,\dots,n\}$, and let $e_i \in \mathbb R^n$ be the $i$-th standard basis vector.
Take any point $y \in V_x$. The openness of $V_x$ is the key point: it guarantees that the line segment in the $e_i$ direction remains inside $V_x$ for all sufficiently small parameters. More precisely, there exists $\rho_y > 0$ such that $y+t e_i \in V_x$ whenever $|t| < \rho_y$. Therefore, for every nonzero $t$ with $|t| < \rho_y$, the difference quotient for $f$ at $y$ is exactly the difference quotient for the restriction $f|_{V_x}$ at $y$:
\begin{align*}
\frac{f(y+t e_i)-f(y)}{t}=\frac{(f|_{V_x})(y+t e_i)-(f|_{V_x})(y)}{t}.
\end{align*}
Since $f|_{V_x} \in C^2(V_x)$, in particular $f|_{V_x}$ has a first partial derivative with respect to $x_i$ at $y$. Thus the limit of the right-hand side as $t \to 0$ exists, and the equality of the difference quotients forces the global partial derivative of $f$ to exist at $y$ with the same value:
\begin{align*}
\partial_{x_i}f(y)=\partial_{x_i}(f|_{V_x})(y).
\end{align*}
Now let $j \in \{1,\dots,n\}$. Because $f|_{V_x} \in C^2(V_x)$, the function
\begin{align*}
\partial_{x_i}(f|_{V_x}): V_x \to \mathbb R
\end{align*}
has a partial derivative with respect to $x_j$ at every point of $V_x$. The equality just proved holds on a whole neighbourhood of $y$, not merely at the single point $y$. Therefore the difference quotients defining $\partial_{x_j}\partial_{x_i}f(y)$ agree with the difference quotients defining $\partial_{x_j}\partial_{x_i}(f|_{V_x})(y)$ for sufficiently small parameters. Hence the second partial derivative of $f$ exists at $y$ and satisfies
\begin{align*}
\partial_{x_j}\partial_{x_i}f(y)=\partial_{x_j}\partial_{x_i}(f|_{V_x})(y).
\end{align*}
[/guided]
[/step]
[step:Transfer continuity from each local restriction to the global derivatives]
We now prove continuity at the fixed point $x$. Since $f|_{V_x} \in C^2(V_x)$, the function $f|_{V_x}: V_x \to \mathbb R$ is continuous at $x$. Because $f$ and $f|_{V_x}$ agree on the neighbourhood $V_x$ of $x$, the function $f: U \to \mathbb R$ is continuous at $x$.
For each $i \in \{1,\dots,n\}$, the function
\begin{align*}
\partial_{x_i}(f|_{V_x}): V_x \to \mathbb R
\end{align*}
is continuous at $x$. By the derivative equality established on $V_x$,
\begin{align*}
\partial_{x_i}f(y)=\partial_{x_i}(f|_{V_x})(y)
\end{align*}
for every $y \in V_x$. Hence $\partial_{x_i}f: U \to \mathbb R$ is continuous at $x$.
For each $i,j \in \{1,\dots,n\}$, the function
\begin{align*}
\partial_{x_j}\partial_{x_i}(f|_{V_x}): V_x \to \mathbb R
\end{align*}
is continuous at $x$. Again using equality on $V_x$, the global second partial derivative $\partial_{x_j}\partial_{x_i}f: U \to \mathbb R$ is continuous at $x$.
[/step]
[step:Conclude the defining conditions for $C^2(U)$ hold everywhere]
The point $x \in U$ was arbitrary. Therefore $f$ is continuous on $U$, every first partial derivative $\partial_{x_i}f$ exists on $U$ and is continuous on $U$, and every second partial derivative $\partial_{x_j}\partial_{x_i}f$ exists on $U$ and is continuous on $U$. By the definition of $C^2(U)$, this proves $f \in C^2(U)$.
Combining this reverse implication with the restriction argument proves the equivalence.
[/step]