I am new to quantum mechanics. I tried using the identity matrix to find the expectation value of momentum square in the position basis. And here is what I got.
I started with the fact that one of the postulates(According to Shankar)states that $$<x|P|x'> = -i\hbar\delta '(x-x')$$ so from here:
$$<\psi|P^2|\psi>=<\psi|PP|\psi>\int_{-\infty}^{\infty}<\psi|P|x><x|P|\psi>dx$$ by inserting the identity between the two P's,Then after that I inserted the identity again between $<\psi|$ and P to get: $$<\psi|P^2|\psi>=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}<\psi|x'><x'|P|x><x|P|\psi>dx'dx$$ and again inserting the identity between $|\psi>$ and P to get: $$<\psi|P^2|\psi>=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}<\psi|x'><x'|P|x><x|P|x''><x''|\psi>dx''dx'dx$$ so using the result from the postulate, this becomes: $$<\psi|P^2|\psi>=\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}\int_{-\infty}^{\infty}(\psi(x')(-i\hbar\delta '(x'-x))((-i\hbar\delta '(x-x'')\psi(x''))dx''dx'dx$$ At this part I used the fact that: $\int_{-\infty}^{\infty}(\psi(x')(-i\hbar\delta '(x'-x))dx'=i\hbar\frac{\mathrm{d} \psi(x))}{\mathrm{d} x}$ and $\int_{-\infty}^{\infty}(\psi(x'')(-i\hbar\delta '(x-x''))dx''=-i\hbar\frac{\mathrm{d} \psi(x))}{\mathrm{d} x}$ so the final answer is : $$<\psi|P^2|\psi>=\hbar^2\int_{-\infty}^{\infty}(\frac{\mathrm{d} \psi(x)}{\mathrm{d} x})^2dx$$ however from what I saw the correct answer is $$<\psi|P^2|\psi> = \int_{-\infty}^{\infty}\psi^*(x) \left(-\hbar^2 \frac{d^2}{dx^2}\psi(x)\right)dx $$
Therefore, I want to know what is wrong with my calculations, is my inserting of the identity like this is wrong?