I have been going through some problems in Sakurai, and at one point have to calculate $\langle \alpha|\hat{p}|\alpha\rangle$ where all we know about the state $|\alpha\rangle$ is that $\langle x|\alpha\rangle=f(x)$ for some known function $f$ ($|\alpha\rangle$ is a Gaussian wave packet). Sakurai says that this is given by: $\langle p\rangle = \int\limits_{-\infty}^{+\infty}\langle\alpha|x\rangle\left(-i\hbar\frac{\partial}{\partial x}\right)\langle x|\alpha\rangle dx$ I am wondering how we get to this expression. I know that we can express $|\alpha\rangle =\int dx\langle x|\alpha\rangle|x\rangle$ and $\langle\alpha|=\int dx\langle\alpha|x\rangle\langle x|$, so my thinking is that we have: $\langle\alpha|\hat{p}|\alpha\rangle=\iint dx dx'\langle\alpha|x\rangle\langle x|\hat{p}\langle x'|\alpha\rangle|x'\rangle$ and if we can 'commute' $|x\rangle$ and $\hat{p}$ this would become: $\iint dxdx'\langle\alpha |x\rangle\hat{p}\langle x'|\alpha\rangle\langle x|x'\rangle$, which is the desired result as $\langle x|x'\rangle=\delta(x-x')$. Is this approach valid? I think my question boils down to: does $\hat{p}$ act on the basis kets $|x\rangle$ or on their coefficients? In the latter case, if we had some state $|\psi\rangle = |x_0\rangle$ for some position $x_0$, then would we say that for this state $\langle p\rangle =\langle x_0|\left(-i\hbar\frac{\partial}{\partial x}\right)|x_0\rangle = 0$ as the single coefficient is $1$ and the derivative of $1$ is $0$?