I am going over my high school calculus and I can't find my mistake.
Given function $f\left( x,y\left( x\right) \right) =xy+\frac{1}{y}$ and I wanted to take its total derivative w.r.t. to $x$, i.e. $\frac{df}{dx}$, so I used chain rule (notice that $y$ is function of $x$)
\begin{align} \frac{df}{dx} & =\frac{\partial f}{\partial x}\frac{dx}{dx}+\frac{\partial f}{\partial y}\frac{dy}{dx}\nonumber\\ & =\frac{\partial f}{\partial x}+\frac{\partial f}{\partial y}\frac{dy} {dx}\tag{1} \end{align}
Is the above correct so far? Now $\frac{\partial f}{\partial x}$ is the partial derivative of $xy+\frac{1}{y}$ w.r.t. $x$ which is \begin{equation} \frac{\partial f}{\partial x}=y+x\frac{dy}{dx}\tag{2} \end{equation} and $\frac{\partial f}{\partial y}$ is partial derivative of $xy+\frac{1} {y}\ $w.r.t. $y$ which is \begin{equation} \frac{\partial f}{\partial y}=x-\frac{1}{y^{2}}\tag{3} \end{equation}
So far ok? Now the problem comes in when substituting (2,3) back into (1) which gives
\begin{align} \frac{df}{dx} & =\left( y+x\frac{dy}{dx}\right) +\left( x-\frac{1}{y^{2} }\right) \frac{dy}{dx}\nonumber\\ & =y+2x\frac{dy}{dx}-\frac{1}{y^{2}}\frac{dy}{dx}\tag{4} \end{align}
But the above is wrong. The final result should be just $\frac{df} {dx}=y+x\frac{dy}{dx}-\frac{1}{y^{2}}\frac{dy}{dx}$. This is seen by doing the following instead of the above
\begin{align} \frac{df}{dx} & =\frac{d}{dx}\left( xy+\frac{1}{y}\right) \nonumber\\ & =\frac{d}{dx}\left( xy\right) +\frac{d}{dx}\left( \frac{1}{y}\right) \nonumber\\ & =y+x\frac{dy}{dx}-\frac{1}{y^{2}}\frac{dy}{dx}\tag{5} \end{align}
Comparing 4,5 shows they are not the same. Where is my error in using the formula (1)? Why using (1) gives an extra term $x\frac{dy}{dx}$?