How do I know when squaring is valid or not? Question:
The straight-line $x\cos\alpha+y\sin\alpha=p$ intersects the x & y axes at A & B respectively. Considering $\alpha$ as a variable, show that the equation of the locus that the middle point of AB is a part of is $p^2(x^2+y^2)=4x^2y^2$.
Solution:
$$x\cos\alpha+y\sin\alpha=p$$
$$\implies \frac{x}{\sec\alpha}+\frac{y}{\csc\alpha}=p$$
$$\implies \frac{x}{p\sec\alpha}+\frac{y}{p\csc\alpha}=1$$
$\therefore$ The coordinates of A & B are $(p\sec\alpha,0)$ & $(0, p\csc\alpha)$. Moreover, the midpoint of AB is $(\frac{p\sec\alpha}{2}, \frac{p\csc\alpha}{2})$. Let, $(x,y)$ is the midpoint of any straight line AB. So,
$$(x,y)=(\frac{p\sec\alpha}{2}, \frac{p\csc\alpha}{2})$$
Now,
$$x=\frac{p\sec\alpha}{2}$$
$$\implies2x\cos\alpha=p$$
$$\implies\cos\alpha=\frac{p}{2x}...(i)$$
Again,
$$y=\frac{p\csc\alpha}{2}$$
$$\implies 2y\sin\alpha=p$$
$$\implies \sin\alpha=\frac{p}{2y}...(ii)$$
$(i)^2+(ii)^2:-$
$$\frac{p^2}{4x^2}+\frac{p^2}{4y^2}=1$$
$$\implies p^2(\frac{y^2+x^2}{4x^2y^2})=1$$
$$\implies p^2(x^2+y^2)=4x^2y^2(showed)$$
Now, my problem is with the step when we square and add (i) & (ii). How do we know that we are not introducing extraneous roots? I have a bigger question. How do I know when squaring is valid or not so that I don't have to come to Math SE every time I encounter squaring in my book?
This might help you in answering my question.
 A: In this exercise, you are given a premise (the starting condition in the first sentence) and asked to prove a given consequence (the part of the sentence after "show that"). As such, as long as each step is valid, i.e., does not introduce a falsity, your proof is valid; and squaring both sides of an equation is always a valid step.
For example, in $$\sqrt x=2\iff x=4 \color{#C00}\implies x^2=16\iff x=\pm4,$$ the squaring step is logically valid. The issue is that in the context of solving equations, we need to ensure that each of our derived solutions indeed satisfies the equation that we started out with, i.e., that the given equation is a consequence of each of the derived solutions instead of merely vice versa. It is not the squaring per se, but the lack of “reversibility” in that step, that has created an extraneous solution. Other culprits include multiplying by $0,$ absolute-value terms, and implicit conditions on the given equation.
In practice, because trying to ensure “reversibility” at every step is tedious and prone to carelessness, when solving equations, it is best to just work in a forward direction like this $$\sqrt x=2\implies x=4 \implies x^2=16\implies x=\pm4,$$ then plugging the candidate solutions into the given equation to eliminate any extraneous ones. With experience, one develops a better awareness of when it is necessary to perform this filtering step, and when it isn't.
P.S. Peppering mathematical writing with the $\implies$ symbol, as you do, is not good practice: too many connective symbols decreases readability, but more importantly, it's not even the symbol $(\therefore)$ that you probably actually mean. I would omit every single $\implies$ from your above presentation.
