square of derivative operator = second derivative operator In classical physics, the kinetic energy of an object is given by,
$$KE = p^2 /2m.$$
In quantum mechanics the KE operator in 1D was introduced as
$$\hat {KE} = \hat {p}^2 /2m = \frac{(-i\hbar \ \frac{d}{dx})^2}{2m} = - \frac{\hbar ^2  }{2m} \frac{d^2}{dx^2}.$$
What is the mathematic formalism behind allowing $(d/dx)^2 = d^2/dx^2$
 A: What is meant by an expression of the form $\left(\frac{d}{dx}\right)^2 f$ is the following: take $\frac{d}{dx}$ and apply it twice to $f$. So
$$ \left(\frac{d}{dx}\right)^2 f = \frac{d}{dx} \left( \frac{d}{dx} f \right) .$$
But this is the definition of the second derivative of $f$ which is often denoted by $\frac{d^2}{dx^2} f$. So the theorem
$$ \left(\frac{d}{dx}\right)^2 = \frac{d^2}{dx^2} $$
isn't actually a theorem but rather an artifact of two notations coming together: on the left hand side there is the notation of applying an operator twice, and on the right hand side there is the notation for the second derivative. Since the second derivative is just differentiating twice, the equality holds. Done!
Or are we? One could also look at this as the starting point of a very interesting part of mathematics (which is actually at the heart of the mathematical formalism of quantum mechanics). This part is the so called functional calculus which tries to answer the following question:

Given a function $g$ and some operator $T$ acting on some space (e.g. some function space), is there a way to give meaning to the expression $g(T)$?

In the case of $T = \frac{d}{dx}$ and $g$ being some polynomial of the form $g(x) = \sum_{j=0}^n a_j x^j$ this is rather clear: define
$$ g\left( \frac{d}{dx} \right) := \sum_{j=0}^n a_j \left(\frac{d}{dx}\right)^j, $$
where by the reasoning in the first paragraph $\left(\frac{d}{dx}\right)^j = \frac{d^j}{dx^j}$. But what should e.g. $\sin\left( \frac{d}{dx} \right)$ mean? Or $e^{-i t\frac{1}{\hbar} \frac{d^2}{dx^2}}$ for $t \in \mathbb{R}$ (you might recognise this as the time evolution operator of a free particle)?
It turns out that using spectral theory for self-adjoint or normal operators $T$  and reasonable $g$ there is such a meaning. If you want to learn more about this you can use this Wikipedia article as a starting point or look into some textbooks on functional analysis.
