<s>[INST] Distance between point and a line - problems simplifying the minimised distance equation Someone asked how to prove the distance between a point $(x_1,y_1)$ and a line $Ax + By + C = 0$ is:$$\text{Distance} = \frac{\left | Ax_{1} + By_{1} + C\right |}{\sqrt{A^2 + B^2} }$$ The currently accepted answer shows that a point on the line can be expressed as $(x, {-Ax-C\over B})$, then explains an approach using calculus to find the value of $x$ when the square distance is minimised, and then plug it into the distance formula: $$\tag{1}D=\sqrt{ (x_1-x)^2 + {\Bigl(y_1-  { \textstyle{-Ax-C\over B}}\Bigr)^2 }}$$ and simplify.
I understand the approach. My problem is with the simplification part. I found $x$ to be minimised when $x = \dfrac{B^2x_1 - A(By_1 + C)}{A^2 + B^2}$. How would you plug this into $(1)$ and simplify effectively?
My first approach was to plug $x$ into the two places it appears in the $(1)$ but expanding $(x_1 - \frac{B^2x_1 - A(By_1 + C)}{A^2 + B^2})^2$ (let alone the rest of it) made me give up as it just seemed to get even more complex. I tried some substitutions:

but this route didn't seem to be getting me closer to the formula to be proven.
I understand there are other far simpler ways to arrive at the formula (see other answers to the linked question), but it irked me that my algebraic manipulation skills are too weak to follow through this one. What I'm wondering is how an expert would approach this. How would you break the problem down and proceed?
I was deliberating over whether to post this question because part of me is telling me I'm lazy for not just trying to plough on through it.
 [/INST] Since you wanted to see how this is done algebraically, we'll need to look at a particular property of quadratic functions.  As I've said in a comment, if $r > 0$, then $ f(x) = rx^2 + sx + t \ $ represents an "upward-opening" parabola.  By completing the square, we can write this as 
$$f(x) \ = \ r \cdot (x^2 \ + \ \frac{s}{r} \cdot x \ + \ \frac{s^2}{4r^2}) \ + \ (t  \ - \ r \cdot \frac{s^2}{4r^2}) \ = \ r \cdot ( \ x  +  \frac{s}{2r} \ )^2 \ + \ ( \ t  -  \frac{s^2}{4r} \  ) \ . $$
The vertex of this parabola lies at  $ \ x = -\frac{s}{2r} \ $ , with the y-coordinate of the vertex being the minimum value of the function $ \ f(-\frac{s}{2r}) \ = \ t  -  \frac{s^2}{4r} .$  We will exploit this to reduce the amount of writing we will need to do.
We will label the closest point on the line to $ \ (x_1 , y_1) \ $ as $ \ (X,Y) \ $ . The distance-squared function is
$$D^2 \ = \ ( X - x_1 )^2 \ + \ (Y - y_1)^2 \ = \ ( X - x_1 )^2 \ + \ ( \ [-\frac{AX + C}{B} \ ] - y_1)^2 \    $$
$$= \ ( X - x_1 )^2 \ + \ (  \frac{A}{B} \cdot X  \ + \ \frac{C}{B}  + \  y_1)^2 \ = \ ( X - x_1 )^2 \ + \ (  \frac{A}{B} \cdot X  \ + \ K \ )^2 \ ,  $$
where we will make a temporary substitution, $ \ K = \frac{C+By_1}{B} \ $ , to further save some writing. (This is often a good idea when working out complicated algebraic expressions, as it reduces the risk of embarrassing, time-wasting errors.)  We will see that we can hold out for some time before needing to replace $K$ .  
From here, we have
$$D^2 \ = \ ( \ X^2 \ - \  2x_1X \ + \ x_1^2 \ ) \ + \ ( \ \frac{A^2}{B^2} \cdot X^2  \ + \ 2\frac{A}{B} K \cdot X \ + \ K^2 \ ) \   $$
$$= \   ( \ 1 + \frac{A^2}{B^2} \ ) \cdot X^2 \ + \  2 ( \ \frac{A}{B} K - x_1 \ ) \cdot X \ + \ (  \ K^2 \ + x_1^2 \ ) ,   $$
which now has the "general form" for a quadratic function.  Since we already know how to convert this to "standard form" by completing the square, we can simply use the results we discussed back at the start.  The vertex of the parabola described by this equation lies at
$$X \ = \ -\frac{s}{2r} \ = \ -\frac{2 ( \ \frac{A}{B} K - x_1 \ )}{2( \ 1 + \frac{A^2}{B^2} \ )} \cdot \frac{B^2}{B^2} \ = \ \frac{ B^2 x_1 \ - \ AB K}{A^2 \ + \ B^2 \ } $$
$$= \ \frac{ B^2 x_1 \ - \ AB \cdot (\frac{C+By_1}{B})}{A^2 \ + \ B^2 \ } \ = \ = \ \frac{ B^2 x_1 \ - \ A \cdot (C \ + \ By_1)}{A^2 \ + \ B^2 \ } \ . $$
So here is the x-coordinate of the point on the line that is closest to $(x_1,y_1)$, confirming the stated result without the use of calculus.
We do not bother substituting this into either the quadratic function or the equation for the line, since we know from the standard form of the quadratic function that its minimal value is
$$D^2_{min} \ = \ t  -  \frac{s^2}{4r} \ = \ ( \ K^2 \ + \ x_1^2 \ ) \ - \ \frac{[ \ 2 ( \ \frac{A}{B} K - x_1 \ ) \ ]^2}{4( \ 1 + \frac{A^2}{B^2} \ )} \cdot \frac{B^2}{B^2}  $$
$$= \ ( \ K^2 \ + \ x_1^2 \ ) \ - \ \frac{ ( \ A K \ - \ Bx_1 \ )^2}{ A^2 + B^2} \ = \  \frac{( \ K^2 \ + \ x_1^2 \ )(A^2 + B^2)  \ - \ ( \ A K - Bx_1 \ )^2}{ A^2 + B^2} $$
$$= \  \frac{( \ A^2K^2 \ + \ B^2K^2 \ + \ A^2x_1^2 \ + \ B^2x_1^2 \ ) \ - \ ( \ A^2K^2 \ - \ 2ABKx_1 \ + \ B^2x_1^2 \ )}{ A^2 + B^2} $$
$$= \  \frac{ A^2x_1^2 \ + \ 2ABKx_1 \ + \ B^2K^2 \ }{ A^2 + B^2} \ = \  \frac{ ( \ Ax_1 \  + \ BK \ )^2 }{ A^2 + B^2}$$
$$= \  \frac{ ( \ Ax_1 \  + \ B \cdot [\frac{C+By_1}{B}] \ )^2 }{ A^2 + B^2} \ = \frac{ ( \ Ax_1 \  + \ By_1 \ + C  \ )^2 }{ A^2 + B^2} \ .$$
Since $ \ \sqrt{x^2} = |x| \ , $ we at last have the relation for the minimum distance, 
$$D_{min} \ = \ \frac{ | \ Ax_1 \  + \ By_1 \ + C  \ | }{ \sqrt{A^2 + B^2}} \ .$$
It took me a few goes to find a reasonably clean way to develop this by algebra alone.  The straight answer to your question about how "an expert" would set this up and proceed is that they wouldn't, but instead would use a more efficient method (such as the ones I linked to in my other answer).  That may also explain why one doesn't have much luck finding an approach like this by looking around the internet.  In any event, I hope this is what you were inquiring about.
</s>