$\{r \in \mathbb Q\mid r>0 \text{ and } r^2 < 2\}$ has no least upper bound. In my real analysis book, when they show that the rational numbers does not have the least upper bound property, they show that the set $\{r \in \mathbb Q : r>0 \text{ and } r^2  < 2\}$ is non-empty and bounded above, but does not have a least upper bound. I understand the argument fully, but I'm having trouble understanding where they came up with some of it. Their argument goes as follows
Define $B = \{r \in Q : r>0 \text{ and } r^2  < 2\}$. Suppose $p \in B$.  Define the rational number $q$ by
$$q = p + \frac{2-p^2}{p+2} = \frac{2p+2}{p+2}$$
Then we have
$$q^2-2 = \frac{2(p^2-2)}{(p+2)^2}$$
I understand that this shows for any $p \in B$ there is a $q \in B$ such that $p<q$. My question is why did they decide to define $q$ this way? Where is the logic for choosing $q$ to be that expression?
Thank you.
 A: Well, you want to add something positive to $p$ so that its square is still less than $2$.
Notice that $(p+h)^2=p^2+h^2+2ph$ so our $h$ must satisfy $h^2+2ph< 2-p^2$.
In fact we could finish the proof here, clearly if $h$ is small enough it will work.
But notice that we need $h(p+h)<2-p^2$ If we can find an $h<2$ such that $h(p+2)\leq 2-p^2$ we are done, since $h(p+h)<(p+2)$. So taking $h=\frac{2-p^2}{p+2}$ does the trick (clearly this number is positive and smaller than $2$).
A: If I wanted to write down an example of this sort from scratch, I'd think this way:
Given $p \in B$, I want to get $q \in B$ s.t. $q>p$. To start let's find a rational number which is expressed as some positive (real) multiple of $\sqrt{2}-p$. An easy way to do that is to just consider $2-p^2=(\sqrt{2}+p)(\sqrt{2}-p)$. This is too big by a factor of $p+\sqrt{2}$. So we divide it by a rational number bigger than $p+\sqrt{2}$. The "simplest" such rational number is $p+2$. This $p+2$ part is actually quite arbitrary, we could have chosen any rational number bigger than $p+\sqrt{2}$. The $2-p^2$ part is much less arbitrary.
This uses the reals for the scratchwork, even though you probably haven't constructed the reals yet...but that's OK, because the proof doesn't actually rely on the scratchwork to make sense in order to carry it out.
A: There are so many formulae $f(x)$ with $x<f(x)\in B$ when $x\in B$ that it's hard to say how it was found, except that $$(2p+2)/(p+2)>p\iff 2p+2>p^2+2p\iff 2>p^2,$$ and that if we assume the existence of the number $\sqrt 2$ then
$(2p+2)/(p+2)<\sqrt 2\iff$ $ 2p+2<\sqrt 2 (p+2)\iff$ $ p(2-\sqrt 2)<2(\sqrt 2 -1)\iff$ 
$ \sqrt 2 (p \sqrt 2 -1)<2(\sqrt 2 -1)\iff$ $p\sqrt 2<2\iff p<\sqrt 2.$ 
A method written by Hero (or Heron) of Alexandria about 19 centuries ago is that for $0<A$ and $0<x$ let  $f(x)=(x+A/x)/2 .$ You can verify that $x^2>A\implies x^2>f(x)^2>A.$
Since $f(y)=f(A/y),$ if $0<y$ and $y^2<A$ then $$(A/y)^2>A  \implies (A/y)^2>f(A/y)^2>A \implies y^2<(A/f(A/y))^2<A.$$  (Since $f(A/y)=f(y)$ we can write that last inequality  as $y^2<(A/f(y))^2<A.$
