I'm following this book on QFT called "Quantum Field Theory of Point Particles and Strings" by Brian Hatfield. After the end of the scalar field theory section on Exercise 3.6, it asks us to express the number operator
$$N=\int \frac{d^3k}{(2\pi)^3}\frac{1}{2\omega_k}a^\dagger(\vec{k}) a(\vec{k})$$
In terms of $\varphi(x,t)$ and $\pi(x,t)$.
My attempt
My first thought was to express the creation and annihilation operators in terms of the field and conjugate momentum
$$a(\vec{k})=\int d^3x \, e^{ik\cdot x}\,(\omega_k\varphi(x)+i\pi(x))$$ $$a^\dagger(\vec{k})=\int d^3x \, e^{-ik\cdot x}\,(\omega_k\varphi(x)-i\pi(x))$$ So substituting these definitions into the number operator we get the following $$N=\int \frac{d^3k}{(2\pi)^3}\frac{1}{2\omega_k}\int d^3x \int d^3x' \, e^{i(x-x')\cdot k}\,(\omega_k\varphi(x')-i\pi(x'))(\omega_k\varphi(x)+i\pi(x))$$ So, I rearrange the expression in the following way $$N=\int d^3x \int d^3x' \int \frac{d^3k}{(2\pi)^3}\frac{1}{2\omega_k} \, e^{i(x-x')\cdot k}\,(\omega_k\varphi(x')-i\pi(x'))(\omega_k\varphi(x)+i\pi(x))$$
However, I do not know how to do the $k$ integration over the exponential term to get the delta function, because we also have to integrate over the energy terms which may give a different result.
$$\int \frac{d^3 k}{(2\pi)^3} e^{i(\vec{x}-\vec{x}')\cdot \vec{k}} =\delta(\vec{x}-\vec{x}') $$ $$\int \frac{d^3 k}{(2\pi)^3} \frac{1}{2\omega_k} e^{i(\vec{x}-\vec{x}')\cdot \vec{k}} = \int \frac{d^3 k}{(2\pi)^3} \frac{1}{2\sqrt{|\vec{k}|^2 +m^2}} e^{i(\vec{x}-\vec{x}')\cdot \vec{k}} = ?$$
Also, I knew from inspection that if you expanded it out, there aren't any terms that you can combine into a commutator, so the commutation relations would not be useful.
I was thinking the number operator may take the form
$$N = \int d^3 x \varphi(x)\pi(x)$$
As in the complex case (judging by the charge operator), it takes
$$N_A - N_B = \int d^3 x( \varphi(x)\pi_\varphi(x) - \varphi^*(x)\pi_{\varphi^*}(x))$$
How would you find an operator which is originally in terms of creation and annihilation operators to an operator that is dependent on fields?
Note: This question is about how do you actually reverse the process to find an operator in terms of the field operators where using this computation as an example and may be useful to other users.