Very basic intro to real analysis question In page 2  of baby Rudin,
Rudin wants to prove that $ \forall p  \in   \mathbb{Q} $ such that $ p>0 $ and $p^2 < 2$ there exists a $q \in \mathbb{Q}$ such that $q>p$ and $q^2<2$
In his proof, he starts with let $q=p-(p^2-2)/(p+2)$
and then says $q^2-2 = 2(p^2-2)/(p+2)^2$
and he goes on to finish the proof.
His proof makes sense, my question is how am I supposed to think in order to solve such problems?
I mean how do you know what to set q equal to? How did he think about this problem to get the expressions?
For example, right now I am trying to find $X$ such that $ q=p-X $ different than the one Rudin set. But I can't think of anything.
Thank you!!
Edit: Yes, I apologize I did make a mistake, it's been fixed now
 A: Suppose we just wanted to find any real $q$ which satisfied that. Well, all we'd have to do would be to choose some $q\in (p,\sqrt{2})$ and so the obvious choice would be to take the center of this interval and so set $q=\dfrac{\sqrt{2}-p}{2}$. The problem with this is that because $p$ is rational and $\sqrt{2}$ is irrational, we find that $q$ must be irrational.
So, we have to be a little more clever. We still want $q$ to be in the above stated range, because those values satisfy $q>p$ and $p^2<2$, but how do we guarantee that $q$ is also rational? Well, we need to find a rational number in the range $(0,\sqrt{2}-p)$ which we can add to $p$. Let's call that value $r$ for now. Well $r$ is going to be dependent on $p$ so lets write $r$ as a function $r(p)$ which we want $r(p)<\sqrt{2}-p$ in the interval $0<p<\sqrt{2}$. We want $r(p)$ to take rational values for all rational $p$ so we should write it as a rational function $$r(p)=\dfrac{s_1(p)}{s_2(p)}$$ where $s_i$ is a polynomial in $p$. Now, there are many polynomials we could take to be $s_1$ and $s_2$ so lets put in some simplifying conditions. We want $r(p)<\sqrt{2}-p$ and we note that the RHS has a root at $p=\sqrt{2}$ so lets make $r(p)$ also have a root there. We want $r(\sqrt{2})=0$ which happens precisely when $s_1(\sqrt{2})=0$. Probably the most obvious choice for $s_1(p)$ then would be $s_1(p)=2-p^2$.
Now we need to try and find an $s_2(p)$ which makes $r(p)$ small enough. As we're trying to make $r(p)$ smaller than a linear function, let's make $r(p)$ grow like a linear function away from its singularities, so let's make the denominator linear and set $s_2(p)=ap+b$. So, we want $\frac{-b}{a}$ to be outside of the interval $(0,\sqrt{2})$ and we also want $s_2(p)$ to be large enough to satisfy the condition we impose on $r(p)$. At this point, many values of $a$ and $b$ will work and I can only assume Rudin chooses $a=1$ and $b=2$ to make the algebra a little neater later on.
Given this, we get $$r(p)=\dfrac{2-p^2}{p+2}$$ and after this we need to check that that this choice of $r(p)$ really satisfies the conditions, which it does.
I'll admit, this 'method' of finding a good $q$ involves a lot of trial and error, and some arbitrary choices, but this is because there are many possible $q$ that we could have used and the dependance of $q$ on $p$ just makes things that little bit more complicated. I can offer no advice on how to 'get a feel' for making these choices other than practice and trying to make 'reasonable' choices along the way.
A: There were two cases.One with q such that q>p and q^2<2 and second with q< p and q^2>2. I think this X was chosen (in Rudin) so as to use it again in the case two.You can take any other X say X =(p-q)/2 in 1st case and X=(q-p)/2 in second.In the book it was chosen so as to avoid taking two different X's for the two cases.
A: I'm  working through POMA too, and I had that same exact question when I read that section. Here's how I think you can derive it.
The easy way to create such a real $q$ is to have $q=p + \frac{\sqrt{2} -p}{k}$ for some $k>1$, but you want to avoid using $\sqrt{2}$ and irrational $k$ for $q$ to be rational. To get rid of the square root in the right term $$\frac{\sqrt{2} -p}{k}=\frac{2 -p^{2}}{k(\sqrt{2}+p)}$$
noting that $2+p >   \sqrt{2}+p$ you get$$0<\frac{2 -p^{2}}{k(2+p)}<\frac{2 -p^{2}}{k(\sqrt{2}+p)}$$
where the middle function may be used as a replacement term for rational $k>1$ and, we see this inequality works for $k=1$ as well, which gives$$p<p+\frac{2 -p^{2}}{k(2+p)}<p+\frac{2 -p^{2}}{k(\sqrt{2}+p)}\ \leq \sqrt{2}$$
satisfying all of the conditions for q for rational $k \geq 1$. The case $k=1$ gives Rudin's Formula.
Also, something interesting I noticed when trying to figure this out was that if you view q and p recursively you can use Newton's formula for $f(x)=x^{2}-2$, which gives $q= p-\frac{p^{2}-2}{2p}$: a solution fairly close to the other answer.
