# Problem calculating the variation of this action

If we take a Hamiltonian density to be as following

$$\mathscr{H}=\frac{1}{2}\Pi^2+\frac{1}{2}\partial_i\varphi\partial_i\varphi+\frac{1}{2}m^2\varphi^2+\frac{1}{4}\lambda\varphi^4,$$

and we have the following action

$$\mathcal{S}=\int \mathrm{d}^{d+1}x(\Pi\dot\varphi-\mathscr{H}).$$

How am I suppose to calculate

$$\delta\mathcal{S}=\int\mathrm{d}^{d+1}x\frac{\delta\mathcal{S}[\varphi]}{\delta\varphi(x)}\delta\varphi(x)+\dots$$

and

$$\delta\mathcal{S}=\int\mathrm{d}^{d+1}x\frac{\delta\mathcal{S}[\Pi]}{\delta\Pi(x)}\delta\Pi(x)+\dots$$

For example with $\varphi$:

$$\frac{\delta\mathcal{S}[\varphi(x)]}{\delta\varphi(x)}=\int\mathrm{d}^{d+1}y\frac{\delta}{\delta\varphi(x)}(\Pi\dot\varphi+\mathscr{H}),$$

which gives me

$$\frac{\delta\mathcal{S}[\varphi(x)]}{\delta\varphi(x)}=\int\mathrm{d}^{d+1}y\left(\partial_0(\Pi\delta^{d+1}(x-y))-\dot\Pi\delta^{d+1}(x-y)-\frac{\delta\mathscr{H}}{\delta\varphi(x)}\right).$$

I know I am supposed to get to the Hamilton's equations

$$\dot\Pi=-\frac{\delta\mathcal{H}}{\delta\varphi}$$

where $$\mathcal{H}=\int\mathrm{d}^{d}x\mathscr{H},$$ but it seems like it won't work.

I think I came up with a solution: $$\frac{\delta\mathcal{S}[\varphi]}{\delta\varphi(x)}={\frac{\delta}{\delta\varphi(x)}\int\mathrm{d}^{d+1}y\left(\Pi\dot\varphi-\mathscr{H}\right)\nonumber\\ =\frac{\delta}{\delta\varphi(x)}\int\mathrm{d}^{d+1}y\left(\Pi\dot\varphi\right)-\frac{\delta}{\delta\varphi(x)}\int\mathrm{d}^{d+1}y\mathscr{H}\nonumber\\ =-\frac{\delta}{\delta\varphi(x)}\int\mathrm{d}^{d+1}y\left(\Pi\dot\varphi\right)-\frac{\delta}{\delta\varphi(x)}\int\mathcal{H}\mathrm{d} t+\underbrace{\text{boundary terms}}_\textrm{=0}\nonumber\\ =-\int\mathrm{d}^{d+1}y\left(\dot\Pi\frac{\delta\varphi}{\delta\varphi(x)}\right)-\int\frac{\delta\mathcal{H}}{\delta\varphi(x)}\mathrm{d} t\nonumber\\ =-\int\mathrm{d}^{d+1}y\left(\dot\Pi\delta^{d}(x-y)\right)-\int\frac{\delta\mathcal{H}}{\delta\varphi(x)}\mathrm{d} t\nonumber\\ =\int\left(-\dot\Pi-\frac{\delta\mathcal{H}}{\delta\varphi(x)}\right)\mathrm{d} t\nonumber.}$$ Since the variation of the action must vanish, it implies that $$-\dot\Pi-\frac{\delta\mathcal{H}}{\delta\varphi}=0 \implies \dot\Pi=-\frac{\delta\mathcal{H}}{\delta\varphi},$$ as desired. We can do exactly the same for the $\Pi$ equation.