How to compute the unitary transformation with the operator on exponential function? Consider an unitary transformation
\begin{equation}
\hat{D}(f) = e^{-\frac{i}{2\hbar}f(t)\hat{q}^2}
\end{equation}
from the book I find that $\hat{D}\hat{p}\hat{D}^{\dagger} = \hat{p} + f(t)\hat{q}$, where $\hat{q}$ is the coordinate operator and $\hat{p}$ is the momentum operator.
The problem is that I can't get this result by myself, how to compute one operator times another operator that in an exponential function?
 A: So ideally what you want to do is take the $\hat{D}$ in the relation $$\hat{D}\hat{p}\hat{D}^\dagger$$ past the $\hat{p}$ so that it cancels with the $\hat{D}^\dagger$, but you obviously can't do that trivially because $\hat{D}$ and $\hat{p}$ don't commute. To take this into account, we use the definition of the commutator $[\hat{D},\hat{p}] = \hat{D}\hat{p} - \hat{p}\hat{D}$. It should be clear from this definition that: $$\hat{D}\hat{p}\hat{D}^\dagger = \hat{p} + [\hat{D},\hat{p}] \hat{D}^\dagger. \tag{1}\label{1}$$
How would one compute $[\hat{D},\hat{p}]$? Well, you have a relation of the form $[F(\hat{q}), \hat{p}]$, where $F$ is some function (in this case, an exponential), and this commutator is easy to calculate using the standard methods. Start off by expanding $F$ as a series in $q$: $$F(\hat{q}) = \sum_n a_{n} \hat{q}^{n} \quad \quad \implies [F(\hat{q}),\hat{p}] = \sum_n a_n [\hat{q}^n,\hat{p}] = \sum_n a_n\,\, n\,\, \hat{q}^{n-1}[\hat{q},\hat{p}],$$
where in the last step I've used the fact that $[\hat{A}, \hat{B}^n] = n \hat{B}^{n-1}[\hat{A},\hat{B}]$, which is true whenever an operator $\hat{B}$ commutes with the commutator $[\hat{A},\hat{B}]$. (This is true in this case, since $[\hat{q},\hat{p}] = i\hbar$.)
Therefore, we can see that for any function $F$ of the operator $\hat{q}$, $$[F(\hat{q}),\hat{p}] = (i\hbar)\sum_n a_n n \hat{q}^{n-1} = i\hbar \,F'(\hat{q}),$$ where in the last step we realise that that is just the series of the derivative of $F$ with respect to $\hat{q}$.
In your case, $F(\hat{q}) = \exp\left(-\dfrac{i}{2\hbar} f(t) \hat{q}^2 \right)$, and so $$F'(\hat{q}) = -\frac{i}{\hbar} f(t) \hat{q} F(\hat{q}).$$
Putting together everything so far, we have that $$[\hat{D},\hat{p}] = i\hbar\,D'(\hat{q}) = f(t)\,\,\hat{q}\hat{D},$$
and so from (\ref{1}), $$\hat{D}\hat{p}\hat{D}^\dagger = \hat{p} + f(t) \hat{q}.$$

Oooh, I've found a much nicer way to solve this!
Let's call the quantity we want to compute $$\hat{G} = \hat{D}\hat{p}\hat{D}^\dagger.$$ Now,
\begin{align}\frac{\text{d}G}{\text{d}f} &= \frac{\text{d}\hat{D}}{\text{d}f}\hat{p}\hat{D}^\dagger + \hat{D}\hat{p}\frac{\text{d}\hat{D}^\dagger}{\text{d}f}\\
&=-\frac{i}{2\hbar} \hat{D} [\hat{q}^2,\hat{p}] \hat{D}^\dagger\\
&= \hat{D}\hat{q}\hat{D}^\dagger\\
&= \hat{q},\tag{2}\label{2}
\end{align}
where I've used the fact that $$\frac{\text{d}\hat{D}}{\text{d}f} = -\frac{i}{2\hbar}\hat{q}^2 \exp\left(-\frac{i}{2\hbar}f(t) \hat{q}^2\right),$$ and that $[\hat{D},\hat{q}]=0$.
We can now integrate (\ref{2}) to get back an expression for $\hat{G}$! $$\hat{G} = \hat{C} + f(t) \hat{q},$$ where $\hat{C}$ is a constant operator that we get from the "initial" conditions. Clearly, $$\hat{C} \equiv \lim_{f\to0} \hat{G} = \lim_{f\to0}\left( \hat{D}\hat{p}\hat{D}^\dagger\right) = \hat{p},$$ and so $$\hat{G} = \hat{p} + f(t) \hat{q},$$ as required!
