Use of Dirac delta in expectation value In looking at page 2 of these lecture notes:
\begin{align}
\langle p | X | \bar p \rangle
 &= \iint \frac{1}{\sqrt{2 \pi \hbar}} \, e^{-i p \bar x / \hbar} \, X \, \delta(\bar x - \hat x) \frac{1}{\sqrt{2 \pi \hbar}} e^{i \hat x \bar p / \hbar} \, d \bar x \, d \hat x \\
&= \frac{1}{2 \pi i} \frac{d}{d \bar p} \iint  e^{-i p \bar x / \hbar} e^{i \hat x \bar p / \hbar} \, \delta(\bar x - \hat x) \, d \bar x \, d \hat x \\
&= \frac{1}{2 \pi i} \frac{d}{d \bar p} \int e^{i \hat x (\bar p - p) / \hbar} \, d \hat x \\
&= \frac{\hbar}{i} \frac{\partial}{\partial \bar p} \delta(\bar p - p) \, .
\end{align}
The second line in the above calculation of $\langle p |x| \bar{p} \rangle $ confuses me. Knowing that the position operator $\hat{x}$ in momentum space is given by:
$$X = -\frac{\hbar}{i} \frac {d} {dp}.$$
How did the minus sign disappear from the second line (I assume it has to do with the properties of the Dirac delta but I am unsure)?
 A: By setting up the integral the way you have, $X$ does not end up in the integral. The implicit step you left out that is in the notes before the steps you give in your post is
$$\langle p|X|\bar p\rangle=\iint\langle p|\bar x\rangle\langle\bar x|X|\hat x\rangle\langle\hat x|\bar p\rangle\,\text d\bar x\,\text d\hat x$$
And then $\langle\bar x|X|\hat x\rangle=\hat x\delta(\hat x-\bar x)$, which is just saying that $X$ is diagonal in its own eigenbasis. Therefore, you can't then bring in $X=-\frac{\hbar}{i}\frac{\text d}{\text dp}$ into the integral since $X$ shouldn't be there in the first place.
What is really going on in the lecture notes is just that they are exploiting the derivative of $\langle\hat x|\bar p\rangle$:
$$\frac{\text d}{\text d\bar p}\left(e^{i \hat x \bar p / \hbar}\right)=\frac{i}{\hbar}\hat xe^{i \hat x \bar p / \hbar}$$
A: What is true is that
$$
\langle p|\hat x|\psi\rangle = i\hbar \partial_p \langle p|\psi\rangle
$$
so
$$
\langle p|\hat x|\bar p \rangle= i\hbar \partial_p \langle p| \bar p\rangle = i\hbar \partial_p \delta(p-\bar p).
$$
Now
$$
\frac{\partial}{\partial p} \delta(p-\bar p)= - \frac{\partial}{\partial p'}\delta(p-\bar p)
$$
so it all works out.
