Manipulation of operators in quantum mechanics I'm reading some notes on quantum mechanics that state the following.
$$\langle x\rvert \left( \hat{x} + \frac{i\hat{p}}{m\omega}\right) \lvert E \rangle = 0 \Rightarrow \left( x+ \frac{\hbar}{m\omega}\frac{d}{dx}\right)\langle x \lvert E\rangle=0$$
Why is this true? By linearity, we know that
$$\langle x\rvert \left( \hat{x} + \frac{i\hat{p}}{m\omega}\right)\lvert E \rangle = \langle x\rvert \hat{x}\lvert E \rangle + \langle x\rvert \frac{i\hat{p}}{m\omega}\lvert E \rangle$$
$$= \langle x\rvert x\lvert E \rangle + \langle x\rvert \frac{\hbar}{m\omega}\frac{d}{dx}\lvert E \rangle$$
$$= x\langle x\lvert E \rangle + \frac{\hbar}{m\omega} \langle x\rvert \frac{d}{dx}\lvert E \rangle$$
So we require
$$\langle x\rvert \frac{d}{dx}\lvert E \rangle=\frac{d}{dx}\langle x\rvert E \rangle$$
These seem like two very different expressions. On the left hand side, the operator is acting on an energy eigenstate in a Hilbert space whereas the operator is acting on a probability amplitude on the right hand side.
 A: The relevant identity is $$\langle x| \hat{p}|\psi\rangle =−i \hbar \frac{d}{dx}\langle x|\psi\rangle\tag{1}$$ which is nothing but the definition of the operator $\hat{p}$. 
Instead $\frac{d}{dx}|\psi\rangle$ does not make sense as it stands. Because $\frac{d}{dx}$ acts on functions of $x$  whereas $|\psi\rangle$ is a vector in a Hilbert space.  Conversely $\langle x|\psi \rangle = \psi (x)$ defines a function of $x$ when $x$ varies in $\mathbb R$
so that $\frac{d}{dx}\langle x|\psi\rangle$ makes sense. 
The operator $\hat{p}$ must be viewed as an operator working on abstract vectors of the abstract Hilbert space $\cal H$ and it has different equivalent definitions depending on the representation you fix for $\cal H$ in terms of a Hilbert space of functions. As a matter of fact, if dealing with the so-called position representation, i.e.,  representing the vectors $|\psi\rangle$ in terms of wavefunctions $\psi= \psi(x)$, the corresponding Hilbert space isomorphism is
$$U: \cal H \ni |\psi\rangle \mapsto \psi\quad \mbox{with $\psi(x) = \langle x|\psi \rangle$ for $x \in \mathbb R$}\:.$$
That is  a Hilbert-space isomorphism from $\cal H$ to $L^2(\mathbb R, dx)$. Definition (1) can be rephrased as 
$$\hat{p} = U \left(-i \hbar \frac{d}{dx}\right)\: U^{-1}$$ 
and it holds, obviously, when dealing with a suitably smooth domain of functions in $L^2(\mathbb R, dx)$. 
An alternate equivalent definition is obtained by dealing with the so-called momentum representation, where the wavefunctions are function of the momentum values: $\hat{\psi}= \hat{\psi}(p)$. Here, 
$$\hat{p} = V  p \: V^{-1}\tag{2}$$ 
where $p$ in the right-hand side is the multiplicative operator and 
$$V: \cal H \ni |\psi\rangle \mapsto \hat\psi\quad \mbox{with $\hat{\psi}(p) = \langle p|\psi \rangle$ for $p \in \mathbb R$.}$$
Above, $$\langle p|\psi \rangle = \frac{1}{\sqrt{2\pi \hbar}}\int_{\mathbb R} e^{-i\frac{px}{\hbar}}\psi(x) dx$$ and $V : {\cal H} \to L^2(\mathbb R, dp)$ is another Hilbert-space isomorphism.
Clearly, here $VU^{-1} : L^2(\mathbb R, dx) \to L^2(\mathbb R, dp)$ is the Fourier transform.  
Within this framework, another way to write (2) is
$$\langle p| \hat{p}|\psi\rangle =p\langle p|\psi\rangle\tag{3}\:.$$
A: Your treatment of the $\hat x$ operator is correct, so I'll focus on the $\langle x|\hat p |E\rangle$ term. The expression $\frac{d}{dx}|E\rangle$ only makes sense if $|E\rangle$ is, for example, some one-parameter family of wave functions indexed by the parameter $x$. This occurs for instance, when computing a geometric phase. Meanwhile, the expression $\frac{d}{dx}\langle x|E\rangle$ involves differentiating a wave function that depends on $x$. In other words, the operator $p$ can be represented by the differential operator $-i\hbar\partial_x$, which acts on the components of wave functions when expanded in the $|x\rangle$ basis.
To see why $\langle x|\hat p|E\rangle=-i\hbar\partial_x\langle x|E\rangle$, it helps to recall the original definition of $\hat p$ as the generator of translations: $e^{i\hat p \Delta x/\hbar}|x\rangle=|x+\Delta x\rangle$, or $(1+i\hat p \epsilon/\hbar)|x\rangle\approx |x+\epsilon\rangle$, which implies (keeping terms up to linear order in $\epsilon$ and setting $\psi_E(x)\equiv\langle x|E\rangle$)
$$
\langle x|(1+i\epsilon\hat p/\hbar)|E\rangle=\int d^3x'\langle x|(1+i\epsilon\hat p/\hbar)|x'\rangle\langle x'|E\rangle=\int d^3x'\langle x|x'+\epsilon\rangle\langle x'|E\rangle\\=\int d^3x'\delta(x-x'-\epsilon)\langle x'|E\rangle=\langle x-\epsilon|E\rangle\\
\Rightarrow\psi_E(x)+i\epsilon/\hbar\langle x|\hat p|E\rangle=\psi_E(x-\epsilon)=\psi_E(x)-\epsilon\partial_x\psi_E(x)+\mathcal O(\epsilon^2).
$$
Hence, cancelling terms on both sides we have (with our conventions) $\langle x|\hat p|E\rangle=-i\hbar\partial_x\psi_E(x)$.
