# Deriving Klein-Gordon from Hamilton's equations for fields using functional derivatives

I have found two different ways of doing this and I am seeking commentary on the fine nuance. Suppose there is a Hamiltonian

$$H=\frac{1}{2}\int\!d^3x \left[ \pi^2+(\nabla\varphi)^{\!2}+m^2\varphi^2 \right] ~~. \tag{1}$$

Hamilton's equations are

$$\dot\pi=-\dfrac{\delta H}{\delta \varphi} \qquad\text{and}\qquad \dot\varphi=\dfrac{\delta H}{\delta \pi}~~. \tag{2}$$

It follows that

$$\dot \varphi=\int\!d^3x\,\pi~~, \tag{3}$$

but I have a question about how to compute $$\dot\pi$$. If I trivially take the derivative with respect to $$\varphi$$ as $$\frac{\delta}{\delta\varphi}\equiv\frac{\partial}{\partial\varphi},\tag{4}$$ skipping over the gradient term, I get the wrong answer $$\dot\pi=\int d^4x\, m^2\varphi$$. I have found two different ways to get the correct answer. The first is to use the identity

$$(\nabla\varphi)^2=\nabla(\varphi\nabla\varphi)-\varphi\nabla^2\varphi ~~,\tag{5}$$

to rewrite the Hamiltonian as

$$H=\frac{1}{2}\int\!d^3x \left[ \pi^2+\nabla(\varphi\nabla\varphi)-\varphi\nabla^2\varphi +m^2\varphi^2 \right] ~~.\tag{6}$$

Now when I take the partial with respect to $$\varphi$$ I get the correct answer

$$\dot \pi=\int\!d^3x\, \left[\nabla^2\varphi-m^2\varphi\right]~~. \tag{7}$$

Mainly my question is this: What rule is it that dictates that $$\frac{\delta}{\delta\varphi}$$ has to hit the $$\nabla\varphi$$ term? Something about the linearity of the operators, I am sure, but I am not certain exactly what my reasoning is. I found another way to compute the correct answer and that is also what my question is about because the other method suggests the derivative does not have to hit that term. I saw something on the internet that says Hamilton's equations for fields use the "functional derivative"

$$\dfrac{\delta}{\delta \varphi} \equiv\dfrac{\partial}{\partial \varphi}-\nabla\dfrac{\partial}{\partial (\nabla \varphi)} ~~.\tag{8}$$

I can apply this to the original Hamiltonian as

\begin{align} \dot\pi=-\dfrac{\delta}{\delta \varphi} H&=-\left(\dfrac{\partial}{\partial \varphi}-\nabla\dfrac{\partial}{\partial (\nabla \varphi)} \right)\frac{1}{2}\int\!d^3x \left[ \pi^2+(\nabla\varphi)^{\!2}+m^2\varphi^2 \right]\\ &=-\int\!d^3x \,m^2\varphi+\int\!d^3x\, \nabla\nabla\varphi\\ &=\int\!d^3x\,\nabla^2\varphi-m^2\varphi\tag{9} \end{align}

Once I have to correct $$\dot\varphi,\dot\pi$$, I can easily proceed to derive the KG equations of motion. I am seeking input regarding the relative merits and uses of these two procedures for computing $$\dot\pi$$. Initially, I got the wrong answer because I thought $$\frac{\delta}{\delta\varphi}(\nabla\varphi)=0$$ and I want to better understand why I was wrong.

OP's question is not about the Klein-Gordon equation per se, but rather about the very definition of the functional/variational derivative (FD). OP's eq. (4) is just plain wrong.

To complicate matters, OP's eqs. (8) refers to a misleading 'same-space' FD notation, which when applied naively, leads to a mismatch of integral signs in OP's eqs. (3), (7) & (9).

For more details, see e.g. this, this & this related Phys.SE posts.

• Thanks. One of those links explained how the functional derivative generated the Dirac delta, and it finally clicked for me. – hodop smith Oct 30 '20 at 23:03

You are most likely confused because methods from functional calculus are often obscured by hacks to make the calculations easier to understands but it also hides a lot of the intuition. So starting with functionals. Functionals are objects that take in functions and spit out a real (complex) number. They are denoted by square brackets to indicate that they are functionals. The simplest functional is probably a plain integral: $$F[\varphi]=\int dx\,\varphi(x)$$ Functional calculus extends the idea of taking derivatives to functionals. This allows you to do things like finding the function that minimizes the functional given some constraint (like the action!). Let's say you want to do this naively by taking the partial derivative. I will take $$F$$ to be a sum to allow us to take the partial derivative. $$F[\varphi]=\sum_i\varphi(x_i)\Delta x$$ Here $$x_i$$ are evenly spaced x-values from some interval $$[a,b]$$. Now we can take the partial derivative if we consider each $$\varphi(x_i)$$ as an independent parameter $$\frac{\partial F[\varphi]}{\partial\varphi(x_j)}=\frac{\partial}{\partial\varphi(x_j)}\sum_i\varphi(x_i)\Delta x=\delta_{ij}\Delta x$$ You might see the issue here. The result depends on $$\Delta x$$ and if we transform this to an integral we always get zero. Now if we define the functional derivative as $$\frac{\delta F[\varphi]}{\delta\varphi(y)}=\lim_{\epsilon\rightarrow 0}\frac{F[\varphi(x)+\epsilon \delta(x-y)]-F[\varphi(x)]}{\epsilon}$$ then we get a definition that doesn't vanish. You can show for yourself that $$\frac{\delta }{\delta\pi(y)}\int dx\,\pi(x)^2=2\pi(y).$$ In general the functional derivative of an integral will give the derivative of the integrand. This is what you try to state in (4). Now to get back to your problem define $$F[\varphi,\nabla\varphi]=\int d^3x\left[(\nabla\varphi(x))^2+m^2\varphi(x)^2\right]$$ We could vary $$F$$ with respect to only its first argument but we are interested the case where the second argument is dependent on $$\varphi$$, similar to a total derivative. Since $$\nabla\delta(x)$$ is kind of a nasty object I will use a better, more general definition of the functional derivative that doesn't use delta functions. $$\int dx\,\frac{\delta F}{\delta\varphi}(x)\rho(x)=\lim_{\epsilon\rightarrow 0}\frac{F[\varphi+\epsilon \rho]-F[\varphi]}{\epsilon}\tag{1}\label{definition}$$ With $$\rho$$ some arbitrary test function. Let's name $$\rho$$ to be $$\rho(x)=\delta\varphi(x)$$ to make the notation nicer. To calculate $$\frac{\delta F}{\delta\varphi}$$ we need to evaluate the right hand side of $$\int dx\,\frac{\delta F}{\delta\varphi}(x)\delta\varphi(x)=\lim_{\epsilon\rightarrow 0}\frac{F[\varphi+\epsilon\delta\varphi,\nabla\varphi+\epsilon\nabla\delta\varphi]-F[\varphi,\nabla\varphi]}{\epsilon}$$ After some work you can show that this becomes $$\lim_{\epsilon\rightarrow 0}\int d^3x\left[2\nabla\varphi\nabla\delta\varphi+\epsilon(\nabla\delta\varphi)^2+2m^2\varphi\delta\varphi+\epsilon m^2\delta\varphi^2\right]\\ =\int d^3x\left[2\nabla\varphi\nabla\delta\varphi+2m^2\varphi\delta\varphi\right]$$ To match the left hand side of (1) we must use partial integration to remove the $$\nabla$$ from $$\delta\varphi$$. This gives us $$\int d^3x\left[-2(\nabla^2\varphi)\delta\varphi+2m^2\varphi\delta\varphi\right]$$ Now reading of (1) gives us $$\frac{\delta F}{\delta\varphi}=-2\nabla^2\varphi+2m^2\varphi$$

Final note: if you plug in $$\rho(x)=\delta(x-y)$$ in (1) you get the first definition of the functional derivative.
• Thanks. What is the unnumbered expression after equation (1) equal to? – hodop smith Oct 31 '20 at 0:48
• I edited my answer – AccidentalTaylorExpansion Oct 31 '20 at 9:25

Your evaluation of the functional derivative in your third equation is wrong. It should read $$\dot \phi(x)= \frac{\delta H}{\delta \pi(x)}= \pi(x)$$ There is no integral. The rest of what you have wirtten has the same problem. Read up on how to define functional derivatives.

Let's actually evaluate the functional derivatives: $$\delta H = \int d^dx\left (\pi(x) \delta \pi(x) + \nabla \phi(x)\cdot \nabla \delta \phi(x) + m \phi(x)\delta \phi(x)\right) \\= \int d^dx\left( \pi(x) \delta \pi(x) - \left((\nabla^2 \phi(x)\right) \delta \phi(x) + m \phi(x)\delta \phi(x)\right).$$ We have integrated by parts and discarded the integrated out term. Compare with the definition of the functional derivative via the variation $$\delta H = \int d^dx\left( \frac{\delta H}{\delta \pi(x)} \delta \pi(x) + \frac {\delta H}{\delta \phi(x)} \delta \phi(x) \right)$$ which is the generalization of $$\delta H(\phi_1,\phi_2,\ldots \phi_n)= \sum_{n=1}^n \frac{\partial f}{\partial \phi_n} \delta \phi_n$$ to the case were the discrete "$$i$$"s are replaced by the continuous label $$x$$ and the sum is replaced by an integral and $$\frac{\partial f}{\partial \phi_n}\to \frac{\delta f}{\delta \phi(x)}$$ Mking the comparison read off that $$\frac{\delta H}{\delta \pi(x)} = \pi(x)$$ and $$\frac {\delta H}{\delta \phi(x)}=-\nabla^2 \phi(x)+m^2\phi(x).$$

For a more basic example consider a one dimensional calculus-of-variations functional $$F[y]= \int_a^b f(y,y',y'') dx$$ under variations $$y(x)\to y(x)+\delta y(x)$$ with $$\delta y(a)=\delta y(b)= \delta y'(a)=\delta y'(b)=0$$ so that we can freely integrate by parts, then $$\frac{\delta F}{\delta y(x)} = \frac{\partial f}{\partial y(x)} - \frac {d}{dx}\left( \frac{\partial f}{\partial y'(x)}\right)+ \frac {d^2}{dx^2}\left( \frac{\partial f}{\partial y''(x)}\right)$$ in which expression the ordinary partials treat $$y(x)$$, $$y'(x)$$ $$y''(x)$$ as independent variables.

• Whilst it's correct that the functional derivatives should have brought down factors of $\delta(x-x')$ which eat up the integrals, I'm not sure this actually answer's OPs question of what to do for $\frac{\delta}{\delta \phi} \int d^4 x \nabla^2 \phi$? – jacob1729 Oct 29 '20 at 20:58
• @jacob1729 Yes, I think I can see that my units indicate the integral should go away because, for instance, $\dot\varphi$ does not have units of $d^4x\pi$. However, the answer "read up on functional derivatives" to my question "how do functional derivatives work" is obnoxiously unhelpful. Can you say a little more about what you mean by, "Bring down factors of the Dirac delta?" Thank you. – hodop smith Oct 29 '20 at 21:06
• I added text showing how it works. I was assuming you have a book on this subject that you were using. – mike stone Oct 29 '20 at 21:08
• I don't have a book on this subject. Thank you for expanding your answer. The method for comparing the two expressions for $\delta H$ is what I was missing. – hodop smith Oct 29 '20 at 21:17
• When you write "Comparing with the definition of the functional derivative," and then you use something that looks like the total derivative of a function, how do you get terms like $\frac{\delta H}{\delta\pi}\delta\pi$? Shouldn't those terms be like $\frac{\partial H}{\partial\pi}\delta\pi$. I just looked up the definition of the functional derivative on Wikipedia, and they use the partials just like in the total derivative of a function. I need to use the $\delta$ version if I'm going to do the "read off" you use. Can you cite the definition of the functional derivative, or explain it? – hodop smith Oct 30 '20 at 22:07

The answer by Mike Stone is slightly confusing. He writes, "Compare with the definition of the functional derivative via the variation," to give

$$\delta H = \int d^dx\left( \frac{\delta H}{\delta \pi(x)} \delta \pi(x) + \frac {\delta H}{\delta \phi(x)} \delta \phi(x) \right)~~.$$

Then by direct comparison with some other expressions we are supposed to obtain the anticiptated expressions. Maybe the issue is that I don't know the difference between the definition of the "functional derivative via the variation" and just the "definition of the functional derivative," but the latter gives

$$\delta H = \int d^dx\left( \frac{\partial H}{\partial \pi(x)} \delta \pi(x) + \frac {\partial H}{\partial \phi(x)} \delta \phi(x) \right)~~.$$

I used Wikipedia as my source for this definition. (Is it not self-referential for the definition of the functional derivative to have functional derivatives in it?) This definition of the functional derivative mimics the definition of the total derivative of a function and in this form we cannot "read off" the answer because the functional derivatives we would read off have been replaced with partial derivatives. Here is the key thing I will use to give a different answer than Mike:

$$\frac{\delta \phi^{\beta}(y)}{\delta\phi^{\alpha}(x)} ~=~\delta^{\beta}_{\alpha}~\delta^n(x-y)~~.$$

(I got this from one of the links given in the answer by QMechanic.) In the present case we have $$\alpha=\beta$$ but the domain of the function in the derivative has to be different from the domain of the function in the integral (which is just a dummy integration variable.) For

$$H=\frac{1}{2}\int\!d^3x \left[ \pi^2(x)+(\nabla\varphi(x))^{\!2}+m^2\varphi^2(x) \right] ~~,$$

we write

$$\dot\pi=-\dfrac{\delta H}{\delta \varphi} =-\dfrac{\delta}{\delta\varphi(y)}\frac{1}{2}\int\!d^3x \left[ \pi^2(x)+\big(\nabla\varphi(x)\big)^{\!2}+m^2\varphi^2(x) \right]~~.$$

The trick to evaluating this functional derivative is to use the ordinary rules for calculus supplemented with Dirac delta identity given above. We have

\begin{align} -\dfrac{\delta H}{\delta \varphi} &=-\frac{1}{2}\int\!d^3x\, \dfrac{\delta}{\delta\varphi(y)}\pi^2(x)+\dfrac{\delta}{\delta\varphi(y)}\big(\nabla\varphi(x)\big)^{\!2}+\dfrac{\delta}{\delta\varphi(y)}m^2\varphi^2(x) \\ &=-\frac{1}{2}\int\!d^3x \, \dfrac{\delta}{\delta\varphi(y)}\big(\nabla\varphi(x)\big)^{\!2}+\dfrac{\delta}{\delta\varphi(y)}m^2\varphi^2(x) \\ &=-\frac{1}{2}\int\!d^3x \, \dfrac{\delta}{\delta\varphi(y)}\big(\nabla\varphi(x)\big)^{\!2}+\dfrac{\delta}{\delta\varphi(y)}m^2\varphi^2(x) ~~. \end{align}

To be terribly clear about how it works, now I will use the chain rule.

\begin{align} -\dfrac{\delta H}{\delta \varphi} &=-\frac{1}{2}\int\!d^3x \left[\dfrac{\delta}{\delta\varphi(y)}\nabla\varphi(x)\right]\nabla\varphi(x) + \nabla\varphi(x)\left[\dfrac{\delta}{\delta\varphi(y)}\nabla\varphi(x) \right] + \\ &\qquad\qquad\qquad+m^2\left[\left(\dfrac{\delta}{\delta\varphi(y)}\varphi(x)\right)\varphi(x) + \varphi(x)\left(\dfrac{\delta}{\delta\varphi(y)}\varphi(x)\right)\right] ~~. \end{align}

Doing the chain rule on $$\varphi^2$$ and $$(\nabla\varphi)^2$$ has produced two terms each. Now I use the linearity of the derivative to swtich $$\delta$$ and $$\nabla$$. This gives

\begin{align} -\dfrac{\delta H}{\delta \varphi} &=-\frac{1}{2}\int\!d^3x \left(\nabla\dfrac{\delta\varphi(x)}{\delta\varphi(y)}\right)\nabla\varphi(x) + \nabla\varphi(x)\left(\nabla\dfrac{\delta\varphi(x)}{\delta\varphi(y)} \right)+\\ &\qquad \qquad \qquad \qquad \qquad +m^2\left(\dfrac{\delta\varphi(x)}{\delta\varphi(y)}\varphi(x) + \varphi(x)\dfrac{\delta\varphi(x)}{\delta\varphi(y)}\right) \\ &=-\frac{1}{2}\int\!d^3x \nabla\delta(x-y)\nabla\varphi(x) + \nabla\varphi(x)\nabla\delta(x-y)+\\ &\qquad \qquad \qquad \qquad \qquad +m^2\left[\delta(x-y) \varphi(x) + \varphi(x)\delta(x-y) \right] \\ &=-\int\!d^3x \nabla\varphi(x)\nabla\delta(x-y) +m^2\varphi(x)\delta(x-y)\\ &=m^2\varphi(y)-\int\!d^3x \nabla\varphi(x)\nabla\delta(x-y) ~~. \end{align}

To get rid of the gradient of the delta fucntion, we integrate by parts with

\begin{align} u&=\nabla\varphi(x)\\ du&=\nabla^2\varphi(x)\,d^3x\\ v&=\delta(x-y)\\ dv&=\nabla\delta(x-y)\,d^3x~~. \end{align}

Then we have

$$\int\!d^3x \nabla\varphi(x)\nabla\delta(x-y) =\nabla\varphi(x) \delta(x-y)\bigg|- \int\!d^3x \,\delta(x-y) \nabla^2\varphi(x)~~.$$

The Dirac delta function is zero except where $$x=y$$ so the first term disappears. We are left with

$$\int\!d^3x \nabla\varphi(x)\nabla\delta(x-y) =- \nabla^2\varphi(y)~~.$$

Finally, we complete the functional derivative as

$$\dot \pi= -\dfrac{\delta H}{\delta \varphi}= m^2\varphi(y)+\nabla^2\varphi(y)~~.$$

From here, it is very easy to derive the KG equation.