In this example, it's being demonstrated that for every $p$ ($p>0$), in $A$, ($A$ being the set of all rational numbers $p$ such that $p^2<2$, and for every $p$ in $B$ ($B$ being the set of all rational numbers $p$ such that $p^2>2$, there exists a rational $q$ in $A$ such that $q>p$, and a rational $q$ in $B$ such that $q<p$.
It then goes on to say we can do this by associating each $p$ with a number: $$q=p-\frac{p^2-2}{p+2}$$
Why do we express $q$ in such a manner; how and why is this a good representation of $q$ as it relates to $p$?