I was reading Principles of Mathematical Analysis - Walter Rudin. In the start (pg-11), it is shown that the equation $p^2 = 2$ is not satisfied by any rational $p$ i.e. $\sqrt{2}$ is irrational.
After this the book says:
"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 $В$ consist of all positive rationals $p$ such that $p^2 > 2$. We shall show that $A$ contains no largest number and $В$ 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 В$ we can find a rational $q \in В$ such that $q < p$.
To do this, we associate with each rational $p > 0$ the number $$ \begin{align} q &= p - \frac{(p^2 - 2)}{p + 2} &(2)\\ &=\frac{2p + 2}{p + 2} &(3)\\ &\Rightarrow q^2 - 2 = \frac{2(p^2 - 2)}{(p + 2)^2} &(4) \end{align} $$
If $p \in A$ then $p^2 — 2 < 0$, (3) shows that $q > p$, and (4) shows that $q^2 < 2$. Thus $q \in A$. If $p \in В$ then $p^2 — 2 > 0$, (3) shows that $0 < q < p$, and (4) shows that $q^2 > 2$. Thus $q \in B$."
I am unable to follow this part, specially how we construct the equations (3) and (4). Can somebody explain?