In Rudin's book, the following proof is published:
Let $A$ be the set of all positive rationals $p : p^2 < 2$. Let $B$ be the set of all positive rationals $p : p^2 > 2$. $A$ contains no largest number and $B$ contains no smallest.
Let q be a rational. More explicitly, $$\forall p \in A, \exists q \in A : p < q$$
and $$\forall p \in B, \exists q \in B : q < p$$
This needs proof.
Now he introduces a couple of equations which are not clear where they are derived from. As follows,
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}}$$
He then goes on to prove how $p \in A \rightarrow q \in A$; similarly for the set B.
My question is: How did he arrive at those equations - particularly, the first one (since the second is clear)?