Can every symmetric Jacobian matrix be a Hessian matrix? Say we have a function $\mathbf{f}(\mathbf{x})$ where $\mathbf{x}\in\mathbb{R}^n$ and $\mathbf{f}:\mathbb{R}^n\rightarrow\mathbb{R}^n$ with a Jacobian matrix $\mathbf{J} = \partial \mathbf{f}/\partial \mathbf{x}\in\mathbb{R}^{n\times n}$.
If the Jacobian matrix $\mathbf{J}$ is real and symmetric everywhere, does a function $y:\mathbb{R}^n\rightarrow\mathbb{R}$ that satisfies $\mathbf{J}=\frac{\partial^2 y}{\partial \mathbf{x}\partial \mathbf{x}}$ exist?
 A: This is true, as a consequence of the Poincaré lemma for differential forms.
In $\mathbb{R}^3$, you may be familiar with the fact that a vector field $\mathbf{f}$ is a gradient $\mathbf{f}=\operatorname{grad}y$ if and only if $\operatorname{curl}\mathbf{f}=0$. The Poincaré lemma generalizes this, and the curl is replaced by the antisymmetrized derivative, which vanishes in your case.
For a more elementary argument, note that if such a $y$ exists, then we must have $y(p)-y(q)=\int_\gamma\mathbf{f}\cdot dl$, where $\gamma$ is any smooth path from $p$ to $q$. Setting $y(0)=0$, we must therefore have
$$
y(\mathbf{x})=\int_0^1\mathbf{f}(t\mathbf{x})\cdot\mathbf{x}dt
$$
To check that this $y$ satisfies $\mathbf{f}=\operatorname{grad} y$, we can compute the gradient using index notation. Let $F_i(\mathbf{x},t)=f_i(t\mathbf{x})$, and note that $\frac{\partial F_i}{\partial t}(\mathbf{x},t)=x_j\frac{\partial f_i}{\partial x_j}(t\mathbf{x})$
$$
\frac{\partial y}{\partial x_i}(\mathbf{x})=\frac{\partial}{\partial x_i}\left(x_j\int_0^1 f_j(t\mathbf{x})dt\right) \\
=\int_0^1 f_i(t\mathbf{x})dt+x_j\int_0^1t\frac{\partial f_j}{\partial x_i}(t\mathbf{x})dt \\
=\int_0^1 f_i(t\mathbf{x})dt+x_j\int_0^1t\frac{\partial f_i}{\partial x_j}(t\mathbf{x})dt \\
=\int_0^1 f_i(t\mathbf{x})dt+\int_0^1t\frac{\partial F_i}{\partial t}(\mathbf{x},t)dt \\
=\int_0^1 f_i(t\mathbf{x})dt+tF_i(\mathbf{x},t)|_{t=0}^{t=1}-\int_0^1F_i(\mathbf{x},t)dt \\
=f_i(\mathbf{x})
$$
A: Of course, just put for $f(x) = \sum {\frac{d{f}}{d{x_i}d{x_j}}*x_{i}*x_j}$
