To show that for every rational $p>0$ such that $p^2<2$ one can get a rational $q$ with $p^2<q^2<2$ and $p<q$ Rudin writes,
We now examine this situation a little more closely. Let $A$ be the set of all positive rationals $p$ such that $p^2<2$ and let $B$ consist of all positive rationals $p$ such that $p^2>2$. We shall show that $A$ contains no largest number and $B$ contains no smallest.
More explicitly, for every $p$ in $A$ we can find a rational $q$ in $A$ such that $p<q$, and for every $p$ in $B$ we can find a rational $q$ in $B$ such that $q<p$.
To do this, we associate with each rational $p>0$ the number $$q=p-\frac{p^2-2}{p+2}=\frac{2p+2}{p+2}.$$ Then $$q^2-2=\frac{2(p^2-2)}{(p+2)^2}.$$
This appears many times in analysis, so if the answer can be generalized/a general method can be given then that would be the best thing. My question is how does one come up with the quantity
$$p-\frac{p^2-2}{p+2}$$
My intuition is that can come from any of the rational approximation possibles, by for example using Newton's method, though I'm lacking when it comes to the details.