# Basics on QM, uncertainity of a continous observable

I know that this question may sound silly but i'm truly confused, but if i had a wave function just like one who describes a potential well, let's call it $$\Psi(x)$$ and I want to calculate the uncertainity of a momentum for example, we know that:

$$$$\Delta P=\sqrt{\langle p^{2}\rangle-\langle p\rangle^2}$$$$ Since $$\Psi$$ is a continous wave function I understand that $$\langle P\rangle=\int_{\mathfrak{R}}\left( \Psi^{\ast}i\hbar\cdot - \frac{\partial}{\partial x}\Psi \right)dx$$ But, what about $$\langle p^2 \rangle$$? from the basics on QM I know that: $$\langle\psi|p^2|\psi\rangle=\langle \psi|p(p|\psi\rangle)$$ the question is, for a continous variable the relation for $$\langle p^2 \rangle=\hbar \int _{\mathfrak{R}}\Psi^{\ast} \frac{\partial^2}{\partial x^2} \Psi dx$$ or it is?: $$\langle p^2 \rangle=-i \hbar \int _{\mathfrak{R}}\Psi^{\ast} \frac{\partial^2}{\partial x^2} \Psi dx$$

It is $$p_x=-i\hbar\frac{\partial}{\partial x}$$ $$p_y=-i\hbar\frac{\partial}{\partial y}$$ $$p_z=-i\hbar\frac{\partial}{\partial z}$$ and $${\bf p}^2=-\hbar^2\left(\frac{\partial^2}{\partial x^2}+\frac{\partial^2}{\partial y^2}+\frac{\partial^2}{\partial z^2}\right).$$ The case you are considering is 1-dimensional and you can limit everything to $$x$$.
The momentum operator is a function: $$\hat p (\psi) = -i\hbar \frac{\partial}{\partial x} \psi$$. Applying this function twice:
$$\hat p (\hat p (\psi)) = -i\hbar \frac{\partial}{\partial x} \hat p (\psi ) = -i\hbar \frac{\partial}{\partial x} (-i \hbar) \frac{\partial}{\partial x} \psi =- \hbar^2 \frac{\partial^2 \psi}{\partial x^2}$$
Since $$i\hbar$$ is independent of $$x$$. Thus:
$$\langle p^2 \rangle = -\hbar^2 \int \psi \frac{\partial^2 \psi}{\partial x^2} dx$$