Dependent variable substitution of a differential equation. I am attempting to answer a question from a textbook. The question is as follows:
"Use the substitution $y = x^2$ to turn the differential equation $x\frac{d^2x}{(dt)^2} + (\frac{dx}{dt})^2 + x\frac{dx}{dt} = 0$ into a second order differential equation with constant coefficients involving y and t."
The answer according to the textbook is $\frac{d^2y}{(dt)^2} + \frac{dy}{dt} = 0$
I am unsure what to do with the $(\frac{dx}{dt})^2$ term in the original equation. Is it equivalent to $\frac{d}{dt}(x^2)$? If this is the case then my working gets as far as the following before I get stuck:

$x\frac{d^2x}{(dt)^2} + (\frac{dx}{dt})^2 + x\frac{dx}{dt} = 0$


$\Rightarrow x\frac{d^2x}{(dt)^2} + \frac{d}{dt}(x^2) + x\frac{dx}{dt} = 0$


$\frac{dy}{dt} =\frac{dy}{dx}\frac{dx}{dt}=2x\frac{dx}{dt} \Rightarrow \frac{d^2x}{(dt)^2}=\frac{d}{dx}(\frac{1}{2x}\frac{dy}{dt})$


$\Rightarrow x\frac{d}{dx}(\frac{1}{2x}\frac{dy}{dt}) + 2x + x\frac{1}{2x}\frac{dy}{dt} = 0$


$\Rightarrow \frac{1}{2x}\frac{dy}{dt} + \frac{1}{2}\frac{d^2y}{(dt)^2} + 2x + \frac{1}{2}\frac{dy}{dt} = 0$

Please can someone show me where I have gone wrong?

In general, you are incorrect that $\left(\frac{dx}{dt}\right)^2 = \frac{d}{dt}\left(x^2\right)$ since $\frac{d}{dt}\left(x^2\right) = 2x\left(\frac{dx}{dt}\right)$, so they're equal only in the special case where $2x = \frac{dx}{dt}$. Instead, multiply the original equation on both sides by $2$ to get
$$2x\frac{d^2x}{(dt)^2} + 2\left(\frac{dx}{dt}\right)^2 + 2x\frac{dx}{dt} = 0 \tag{1}\label{eq1A}$$
Next, differentiating $y = x^2$ gives
$$\frac{dy}{dt} = 2x\left(\frac{dx}{dt}\right) \tag{2}\label{eq2A}$$
and then differentiating again, using the product rule this time, gives
$$\frac{d^2y}{(dt)^2} = 2\left(\frac{dx}{dt}\right)^2 + 2x\left(\frac{d^2x}{dt^2}\right)  \tag{3}\label{eq3A}$$
As you can see, with the left side of \eqref{eq1A}, we have \eqref{eq3A} matching the first $2$ terms and \eqref{eq2A} matching the final third term. Thus, \eqref{eq1A} can be rewritten as
$$\frac{d^2y}{(dt)^2} + \frac{dy}{dt} = 0 \tag{4}\label{eq4A}$$
