This is a second part of my [previous question](https://mathoverflow.net/questions/382463/rigorous-euler-lagrange-equations-for-fields). I'm trying to figure it out by myself how to deduce Hamilton's equations in classical field theory as it is usually obtained in physics books.


**Notation:** If ${\bf{x}} = (x\_{1},...,x\_{n}) \in \mathbb{R}^{n}$ and $f=f({\bf{x}})$ is real-valued and differentiable, I'll denote:
$$\frac{\partial f}{\partial \bf{x}} := \bigg{(}\frac{\partial f}{\partial x\_{1}},...,\frac{\partial f}{\partial x\_{n}}\bigg{)} \equiv \nabla f.$$


This notation is useful since, if $f$ is a function of more than one variable, e.g. $f=f(\bf{x},\bf{y},\bf{z})$, then $\partial f/{\partial \bf{x}}$ means the gradient with respect to the $\bf{x}$ variable.


Legendre Transforms for many variable functions
-----------------------------------------------


Here, I'm following [Arnold](https://www.springer.com/gp/book/9781475716931). Let $f: \mathbb{R}^{n}\to \mathbb{R}$ be a twice-differentiable function such that its Hessian $\nabla^{2}f$ is positive-definite (so $f$ is strictly convex). Let $G=G({\bf{p}},{\bf{x}}) := \langle {\bf{p}},{\bf{x}}\rangle - f({\bf{x}})$, where $\langle \cdot, \cdot \rangle$ is the usual inner product on $\mathbb{R}^{n}$. Then, the Legendre transform of $f$ is defined to be the function $g=g({\bf{p}}) := \max\_{{\bf{x}}}G({\bf{p}},{\bf{x}})$. Notice that $G$ attains its maximum iff $\frac{\partial G}{\partial \bf{x}} = 0$, so that the vector $\bf{x}$ which maximizes $G$ for a fixed $\bf{p}$ is the solution of:
\begin{eqnarray}
\frac{\partial f}{\partial \bf{x}} = \bf{p} \tag{1}\label{1}
\end{eqnarray}


Classical Field Theory
----------------------


I know that the more general setting of classical field theory (as well as classical mechanics) is defined in terms of manifolds and tangent bundles, but for our purposes I will work in the usual spacetime $\mathbb{R}^{4}$. In the present context, a field is a function $\phi: \mathbb{R}^{4} \to \mathbb{R}^{n}$. A point ${\bf{x}} = (x\_{1},x\_{2},x\_{3},x\_{4}) \in \mathbb{R}^{4}$ is represented by space coordinates $x\_{1},x\_{2},x\_{3}$ and a time coordinate $x\_{4} = t$. It is useful to write the equations that follow in Einstein's notation: $x\_{\mu}$ denotes any coordinate of ${\bf{x}}$ and $\partial\_{\mu}$ denotes the partial derivative with respect to the $\mu$-th entry, $\mu \in \{1,2,3,4\}$.


The action $S = S(\phi)$ is defined by:
\begin{eqnarray}
S({\bf{\phi}}) := \int L(t, \phi(t), \partial\_{\mu}\phi)dt \tag{2}\label{2}
\end{eqnarray}
where the Lagrangian is given by an integral:
\begin{eqnarray}
L(t,\phi(t), \partial\_{\mu}\phi) := \int \mathscr{L}({\bf{x}}, \phi, \partial\_{\mu}\phi)d{\bf{x}} \tag{3}\label{3}
\end{eqnarray}
with $\mathscr{L}$ being the Lagrangian density.


**Question:** Is this a closed form for the Hamiltonian $H$ of such a system, given that $H$ is the Legendre transform of $L$? If there is, how to obtain it?


Let us assume that $L$ and $H$ do not depend explicitly on $t$. As far as I understand, $H$ is the Legendre transform of $L$ with respect to the variable $\dot{\phi} = \partial\_{4}\phi$, so we have to perform a change $\dot{{\bf{\phi}}} \leftrightarrow {\bf{p}}$. Thus, it is natural to define $H(\phi, \frac{\partial \phi}{\partial {\bf{x}}}, {\bf{p}}) = \max\_{\dot{\phi}}(\langle {\bf{p}}, \dot{\phi}\rangle - L(\phi, \frac{\partial \phi}{\partial {\bf{x}}}, \dot{\phi}))$. Using (\ref{1}), we get:


\begin{eqnarray}
{\bf{p}} = \frac{\partial L}{\partial {\bf{x}}} = \frac{\partial}{\partial {\bf{x}}}\int \mathscr{L}({\bf{x}}, \phi, \partial\_{\mu}\phi)d{\bf{x}} \tag{4}\label{4}
\end{eqnarray}


Here is where things become unclear. Physicists usually define:
\begin{eqnarray}
\pi({\bf{x}}) := \frac{\partial \mathscr{L}({\bf{x}})}{\partial {\bf{x}}} \tag{5}\label{5}
\end{eqnarray}
so that:
\begin{eqnarray}
{\bf{p}} = \int \pi({\bf{x}}) d{\bf{x}} \tag{6}\label{6}
\end{eqnarray}
But the Hamiltonian should become:


\begin{eqnarray}
H = \int \pi({\bf{x}})\dot{\phi}({\bf{x}})d{\bf{x}} - L \tag{7}\label{7}
\end{eqnarray}


But this is **really** strange since the $\dot{\phi}$ seems to be being integrated together with $\pi$, and this is not the case if you put (\ref{6}) into $\langle {\bf{p}}, \dot{\phi}\rangle - L(\phi, \frac{\partial \phi}{\partial {\bf{x}}}, \dot{\phi})$.


So, **what am I doing wrong**?



Hamilton equations for Classical Field Theory
There is a fundamental misunderstanding in your translation of Hamilton's formalism to classical field theory, which pertains to the proper identification of dynamical variables.


In classical mechanics, the position variables are dynamical variables, whereas time is the external parameter in terms of which we register the dynamics, i.e. how dynamical variables (position and velocity / momenta, depending on whether you employ the Lagrangian / Hamiltonian formalism) evolve. In classical field theory, position becomes an external parameter *in the same footing as time* and the dynamical variables are the field values $\phi(t,\mathbf{x})$. In other words, classical field theory is about the *space-time evolution* of the field values. That is why in classical field theory the Lagrangian involves field derivatives in time *and* space. **Edit:** actually, as discussed in the comments below and the ensuing [chat discussion](https://chat.stackexchange.com/rooms/119253/discussion-between-mathmath-and-pedro-lauridsen-ribeiro), the appearance of spatial derivatives in the Lagrangian is enforced in the case of *relativistic* fields by the presence of time derivatives *and* finite speed of propagation for the Euler-Lagrange equation.


Another consequence of this is that the configuration space of classical field theory becomes *infinite-dimensional* - after all, we are following the time evolution of the field values $\phi(\cdot,\mathbf{x})$ *at each point in space*, thus comprising a continuum of independent dynamical variables, unlike the $n$ (say) Cartesian position variables in classical mechanics - that is, the "coordinate index" $\mathbf{x}$ no longer takes discrete values $1,\ldots,n$ but the whole of $\mathbb{R}^n$. As such, the field momentum $\pi(t,\mathbf{x})$ *at each position* $\mathbf{x}$ and time $t$ should be defined (and actually is, in physics textbooks) as $$\pi(t,\mathbf{x})=\frac{\partial\mathscr{L}(t,\mathbf{x},\phi(t,\mathbf{x}),\partial\_\mu\phi(t,\mathbf{x}))}{\partial(\partial\_t\phi(t,\mathbf{x}))}\ .$$ In other words, we also have a continuum of independent field momentum variables. This is why the time derivative $\dot{\phi}(t,\mathbf{x})=\partial\_t\phi(t,\mathbf{x})$ of $\phi$ appears paired with $\pi(t,\mathbf{x})$ inside a spatial integral in the definition of the Hamiltonian $H$ - this is just the appropriate choice of (infinite-dimensional) scalar product.


