Is there a way of checking that a number can be written as a perfect square and hence finding it if the number is given in the surd form?
For example, if I expand and simplify $$(1+\sqrt{2})^{2}=3+2\sqrt{2}$$.
Is there a way of finding that perfect square (assuming it has one or after checking it has one) from $3+2\sqrt{2}$?
$$(a + b \sqrt{c})^2 = a^2 + b^2 c + 2 a b \sqrt{c}$$
So if you are given $s + t \sqrt{c}$ (with $s, t, c$ rational, $t \ne 0$ and $c$ not a square) and want to write it in this form, you want to find rationals $a$ and $b$ to solve the equations $$ \eqalign{a^2 + b^2 c &= s\cr 2 a b &= t\cr}$$ Since $a=0$ won't work, we can write $b = t/(2a)$ and the equation becomes $$ a^2 + \frac{c t^2}{4a^2} = s $$ which we can solve for $a^2$ and then for $a$: $$ a = \pm \frac{\sqrt{ 2\,s+2\,\sqrt {s^2-c{t}^{2}}}}{2} $$ That is, $s^2 - c t^2$ must be the square of a rational, and then $2s + 2 \sqrt{s^2 - ct^2}$ must be the square of a rational, and if so we get a solution with this $a$ and $b = t/(2a)$.