Infinitesimal generator of change of basis (Fock Space) I'm trying to find unitary transformation and prove that the infinitesimal generator for a change of basis with spatial depedency $$|\vec{r} \rangle \rightarrow e^{i \theta  (\vec{r}) }|\vec{r}\rangle $$ is the density operator $\hat{\rho} = \hat{\psi}^{\dagger}(\vec{r}) \hat{\psi}(\vec{r})$
My attempt was:
$$\hat{U}{(\theta(\vec{r})}) \hat{\psi}(\vec{r}) \hat{U(\theta(\vec{r}))}^{\dagger} = e^{-i\theta(\vec{r})} \hat{\psi}(\vec{r}) \iff \\ \iff  \hat{\psi}(\vec{r}) - i \theta(\vec{r})[G,\hat{\psi}(\vec{r})] = \hat{\psi}(\vec{r}) - i \theta(\vec{r})\hat{\psi}(\vec{r})  $$
Thus,
$$ [G,\hat{\psi}(\vec{r})] = \hat{\psi}(\vec{r}) \rightarrow  G = \hat{N} $$
Which is not the solution.
What am I doing wrong?
 A: The step where you went wrong is in writing
$$\hat{U}(\theta(\vec{r}))=1-i\theta(\vec{r})G$$
for infinitesimal transformations. This would imply $U(\theta(\vec{r}))$ is an operator-valued function of $\vec{r}$ instead of a single unitary operator. In reality, there should be a separate generator for each point in space:
$$\hat{U}(\theta(\vec{r}))=1-i\int d^3r \theta(\vec{r})G(\vec{r}).$$
Then you get
$$\left[\int d^3r' \theta(\vec{r}')G(\vec{r}'),\hat{\psi}(\vec{r})\right]=\theta(\vec{r})\hat{\psi}(\vec{r})$$
$$\implies \int d^3r' \theta(\vec{r}')\left[G(\vec{r}'),\hat{\psi}(\vec{r})\right]=\theta(\vec{r})\hat{\psi}(\vec{r}).$$
You can plug in $G(\vec{r})=\hat{\psi}^\dagger(\vec{r})\hat{\psi}(\vec{r})$ at this point.
$$\theta(\vec{r})\hat{\psi}(\vec{r})=\int d^3r' \theta(\vec{r}')\left[\hat{\psi}^\dagger(\vec{r}')\hat{\psi}(\vec{r}'),\hat{\psi}(\vec{r})\right]$$
$$=\int d^3r' \theta(\vec{r}')\left(\hat{\psi}^\dagger(\vec{r}')\{\hat{\psi}(\vec{r}'),\hat{\psi}(\vec{r})\} - \{\hat{\psi}^\dagger(\vec{r}'),\hat{\psi}(\vec{r})\}\hat{\psi}(\vec{r}')\right)$$
$$=\int d^3r' \theta(\vec{r}')\left(\hat{\psi}^\dagger(\vec{r}')\cdot 0 - \delta^{(3)}(\vec{r}-\vec{r}')\hat{\psi}(\vec{r}')\right)$$
$$=\theta(\vec{r})\hat{\psi}(\vec{r})$$
A: If you have $\{\psi(r),\psi^\dagger (r')\}= \delta(r-r')$and want a transformation $\psi(r)\to e^{i\theta(r)}\psi(r)$, or its infinitesimal version
$$
[\psi(r),G]=  \theta(r)  \psi(r),
$$
you need to take $G= \int \theta(r') \psi^\dagger(r')\psi(r)\,dr'$.  To get this you need to use the commutator-anticommutator identity
$$
[A,BC]=\{A,B\}C-B\{A,C\}.
$$
