Continuous function that equals 0 when 4 points form a square Given the distances between four points that lie in $\mathbb{R^2}: a,b,c,d,e,f$
Is there a continuous function $g(a,b,c,d,e,f) \Rightarrow \mathbb{R}$ such that $g = 0$ if and only if the four points form a square?
I know that it is true that when they form a square, some set of four of the distances will be equal and the other two distances will be equal to each other.
And I know that this formula:
$$\frac{d_1 + d_2 + d_3 + d_4}{d_5 + d_6}\cdot \left( \frac{\sqrt 2}2 \right) - 1$$
Will equal zero when the four points form a square, but I don't think that formula being zero implies the other direction nor am I convinced that it is continuous (or at least able to be analytically continued into a continuous function.
 A: You can abuse some properties of the real numbers. First off, that the square of a non-zero number is positive. That means that if you want to check whether a collection of real numbers are all zero, you can just square them and add them. So, if we want $a = b = c = d$ and $e = f = \sqrt 2 a$, then we can just check whether the following holds:
$$
g_1(a, b, c, d, e, f) = (a-b)^2 + (a-c)^2 + (a-d)^2 + (e-\sqrt2 a)^2 + (f - \sqrt2a)^2 = 0
$$
Now, it might be that the distances do make a square, but that the configuration is wrong. For instance, we might have that $a = b = c = e$ and $d = f = \sqrt2a$. In that case, we would have to check
$$
g_2(a, b, c, d, e, f) = (a-b)^2 + (a-c)^2 + (a-e)^2 + (d-\sqrt2 a)^2 + (f - \sqrt2a)^2
$$
and so on, getting a lot of different $g_n$'s ($15$ of them, to be exact). Finally, since we're only interested in whether one of these hold, we use a second property of the real numbers: If the product of two numbers equals $0$, then one of the numbers have to be zero. Thus, if we set
$$
g(a, b, c, d, e, f) = g_1(a, b, c, d, e, f)\cdot g_2(a, b, c, d, e, f)\cdots g_{15}(a, b, c, d, e, f)
$$
then $g(a, b, c, d, e, f) = 0$ if and only if $g_n(a, b, c, d, e, f) = 0$ for some $n$, which only happens if that configuration actually represents the sides and diagonals of a square.
There is one problem with this, though: It doesn't check whether these numbers are negative. It just checks whether they are proportional and equal as they should be. This is most easily rectified by adding to all the $g_n$'s a term like $(a-|a|)^2$. That way, if the numbers turn out to be negative, none of the $g_n$'s will give zero.
Also, what happens if $a = b = c = d = e = f = 0$? Does that make a square? I don't know. It's not so easy to check for with nice and simple functions, though.
