Let $A$ be the set of all rational numbers $p$ such that $p^2<2$, and let $B$ be the set of all rational numbers $p$ such that $p^2>2$. It can be shown that $A$ has no largest element and that $B$ has no smallest element by associating to each $p>0$ the number $$q=p-\frac{p^2-2}{p+2}$$
and then proving that $p\in A \Rightarrow q\in A$ and $p\in B\Rightarrow q\in B$.
Where is this value of $q$ coming from?