Proper notation and definition of the Hamilton operator The Hamilton operator is often defined as
$$
\hat H = \frac{-\hbar^2 }{2m}\frac{d^2}{dx^2} + V(x)
$$
but shouldn't it rather be
$$\begin{aligned}
\hat H &= \int\int dxdx' |x\rangle \langle x|\hat H|x'\rangle \langle x'|\\
&= \int \int dx dx' |x\rangle \left[ -\frac{\hbar^2}{2m}\left(\frac{\partial}{\partial x'}\frac{\partial}{\partial x}\delta(x-x') \right) + V(x)\delta(x-x') \right ]\langle x'| \\
\hat H &= \int dx |x\rangle \left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]\langle x| \\
\hat H &= \int dx |x\rangle \langle x| \left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]\\
\hat H&=\hat 1\left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]
\end{aligned}$$
Because it seems to me that only in this way we have
$$
\hat H |\psi\rangle = \int dx |x\rangle \left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]\psi(x)
$$
and
$$
\langle x|\hat H | \psi\rangle =\left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]\psi(x)
$$
Am I overly pedantic or even wrong? Is the distinction between
$$
\hat 1 \left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ] = \hat H
$$
and
$$ \left[ -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ]$$ unnecessary/unreasonable or should it be made?
 A: You are not pedantic, you are just wrong!
$$
\hat H= \hat p^2 /2m+ V(\hat x).
$$
Recall
$$
\hat p= -i\hbar \int\! dx ~|x\rangle \partial_x \langle x| ,\\
\hat x=  \int\! dx ~|x\rangle  x \langle x|~, \qquad \langle x| x'\rangle = \delta (x-x'),\\
\leadsto \qquad \hat p^2= -\hbar^2 \int\! dx ~|x\rangle \partial_x^2 \langle x| ,
$$
so that
$$\begin{aligned}
\hat H &= \int\int\! dxdx' ~|x\rangle \langle x|\hat H|x'\rangle \langle x'|\\
&= \int \int\! dx dx' ~|x\rangle \delta(x-x') 
\left( - \frac{\hbar^2}{2m}  \partial_{ x'}^2   + V(x') \right )\langle x'| \\
  &= \int\! dx ~~|x\rangle \left ( -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right )\langle x| ~~.
\end{aligned}$$
Your teacher surely has taught you that the operator in the parenthesis is the hamiltonian in the x-representation! Thus, acting on a ket,
$$
\hat H |\psi\rangle = \int\! dx ~~|x\rangle \left ( -\frac{\hbar^2}{2m}\frac{\partial^2}{\partial x^2}  + V(x) \right ) \psi(x) ~~.
$$
A: The operator (as you've used it in your first equation)
$$H=- \frac{\mathrm d^2}{\mathrm dx^2} + V(x)\tag{1}$$
is defined on (a subspace of) $L^2(\mathbb R)$, whereas the Dirac notation does not make an explicit reference to a particular Hilbert space, i.e. it is some complex separable Hilbert space of infinite dimension and thus isomorphic to $L^2(\mathbb R)$. For example, when we write
$$H=P^2+ V(X) \tag{2} \quad , $$
we a priori do not specify on which Hilbert space these operators ($H$, $P$ and $X$) act on or how they act on the respective vectors (think about position versus momentum representation). To quote B. Hall. Quantum Theory for Mathematicians. Springer. Section 3.12.:

One peculiarity of the physics literature on quantum mechanics is a
conspicuous failure of most articles to state what the Hilbert space is. Rather than starting by defining the Hilbert space in which they are working, physicists generally start by writing down the commutation relations that hold among various operators on the space. Thus, for example, a physicist might begin with position and momentum operators $X$ and $P$, satisfying $[X,P ] = i\hbar I$, without ever specifying what space these operators are operating on. [...] It is, nevertheless, disconcerting for a mathematician to encounter an entire paper full of computations involving certain operators, without any specification of what space these operators are operating on, let alone how the operators act on the space.

