# Discrepancy between the two different equations of the momentum operator

i am doing a thesis on the quantization of a real scalar field in a gravitational wave background. I am doing this in lightcone coordinates, so $$u$$ is $$z-t$$. I start with an action and define a momentum operator by $$\frac{\partial S}{\partial (\partial_u \phi)} = \hat{\pi}$$. Then you want to get an Hamiltonian $$H = \int (\partial_u \phi) \hat{\pi} - \mathcal{L} d^{D-1}x$$. After that you write $$\partial_z \hat{\phi} = \frac{\hat{\pi}}{\sqrt{1-h_+^2 cos^2 (\omega u)}}$$. Now using the standard canonical commutation relations between $$\hat{\phi}$$ and $$\hat{\pi}$$ and the Heisenberg equation of motion, you obtain a different equation for $$\hat{\pi}$$. How is that possible, i can't see where it went wrong?

$$$$S = \int \mathcal{L}d^D x = S_{UdW} - \int d^{D}x \sqrt{-g} \bigg[ \frac{1}{2} g^{\mu\nu}(\partial_\mu \hat{\phi}) (\partial_\nu \hat{\phi}) +\frac{1}{2}m^2 \phi^2 \bigg]$$$$ With $$m$$ the mass of the field $$\phi$$ and $$S_{UdW}$$ the action of the Unruh-deWitt particle detector, that we neglect for now. We also multiply with $$\sqrt{-g}$$ to make $$d^D x \sqrt{-g}$$ constant under coordinate transformations.

Letting $$\mu$$ and $$\nu$$ (non-zero terms are (1,1), (2,2), (3,3), (3,0) and (0,3), respectively) run along every possible combination you can express the action as $$$$\begin{split} S = -\int d^D x \frac{\sqrt{1-h_+^2 cos^2 (\omega u)}}{2}\Bigg[ \frac{(\partial_x \hat{\phi})^2}{1+h_+ cos(\omega u)} + \frac{(\partial_y \hat{\phi})^2}{1-h_+ cos(\omega u) } + (\partial_z \hat{\phi})^2 -2\partial_u \phi \partial_z \hat{\phi} + m^2 \hat{\phi}^2 \Bigg] \end{split}$$$$

Defining the momentum operator $$\hat{\pi}$$ $$$$\hat{\pi} = \frac{\delta S}{\delta (\partial_u \hat{\phi})} = \sqrt{1-h_+^2 cos^2 (\omega u)}\partial_z \hat{\phi}$$$$ Now looking at the Hamiltonian $$$$H = \int \mathcal{H} d^{D-1} x; \hspace{0,7cm} \mathcal{H} = (\partial_u \phi) \hat{\pi} - \mathcal{L}$$$$ Plugging the Lagrangian in $$$$H = \int d^{D-1} x \frac{\sqrt{1-h_+^2 cos^2 (\omega u)}}{2}\Bigg[ \frac{(\partial_x \hat{\phi})^2}{1+h_+ cos(\omega u)} + \frac{(\partial_y \hat{\phi})^2}{1-h_+ cos(\omega u) } + (\partial_z \hat{\phi})^2 + (m \hat{\phi})^2 \Bigg]$$$$ Writing $$\partial_z$$ as a function of $$\hat{\pi}$$, and applying partial integration on $$(\partial_i \phi)^2$$ (for $$i$$ is $$x$$ and $$y$$) and neglecting boundary terms, you can rewrite the Hamiltonian. $$$$\hat{H}(u,\vec{x}) = \int d^{D-1} x \frac{\sqrt{1-h_+^2 cos^2 (\omega u)}}{2}\Bigg[ \frac{\hat{\pi}^2}{1-h_+^2 cos^2 (\omega u)} - \frac{ \hat{\phi} \partial_x^2 \hat{\phi}}{1+h_+ cos(\omega u)} - \frac{ \hat{\phi} \partial_y ^2 \hat{\phi}}{1-h_+ cos(\omega u) } + m^2 \hat{\phi}^2 \Bigg]$$$$ Using the canonical commutation relations of $$\hat{\phi}$$ and $$\hat{\pi}$$ $$$$[\hat{\phi}(u,\vec{x}), \hat{\pi}(u,\vec{x'})] = i\hbar \delta(\vec{x}-\vec{x}'), \hspace{0,7cm} [\hat{\phi}(u,\vec{x}), \hat{\phi}(u,\vec{x}')] = [\hat{\pi}(u,\vec{x}), \hat{\pi}(u,\vec{x}')] = 0$$$$ From the Heisenberg equation of motion and we take the $$\hat{\phi}$$ operator is not a function on $$u$$, we can get an equation for the 'time'-derivative of $$\hat{\phi}$$ $$$$\partial_u \hat{\phi}(u,\vec{x}) = -\frac{[\hat{H}(u,\vec{x}'),\hat{\phi}(u,\vec{x})]}{i\hbar} = -\frac{1}{i\hbar} \int d^{D-1} x' \frac{\sqrt{1-h_+^2 cos^2 (\omega u)}}{2} \Bigg[ \frac{\hat{\pi}(u,\vec{x}')(-i\hbar \delta(\vec{x}-\vec{x}'))}{1-h_+^2 cos^2 (\omega u)} \Bigg]$$$$ Applying the $$\delta$$-function on $$\hat{\pi}(u,\vec{x}')$$, one obtains $$$$\partial_u \hat{\phi}(u,\vec{x}) = \frac{ \hat{\pi}(u,\vec{x}) }{2\sqrt{1-h_+^2 cos^2 (\omega u)}}$$$$