The Big Bad: Squares!

April 05, 2021 | 13 minutes, 41 seconds


This was the post I really wanted to write, and the one I've personally built up to. The square, for me, was the second shape that I ever saw made using Piecewise equations. There are several forms, and all have different geometric meanings - in fact, even the different derivations for the same forms have different geometric meanings. I don't go into detail in the same way this post does, rather I focus on the implications of the derivations, but it's worth a read because it's where I stole my initial ideas from.

The derivation for a single equation of a square took the most time initially for me (I was sitting in the back of class in year 11, trying to figure this insanity of an equation while the teacher was teaching), but it got me deep into working with piecewise equations as a whole and developing a set of techniques that would allow me to help derive it.

In this post, initially, we'll work with a square with side lengths of 1, centred at \((0,0)\) (and, for the purposes of this post, this is our unit square).

If you want a simple TL;DR of this post, we establish a couple of equations for a square:

These two equations are equivalent forms describing a square with side length of \(a\), centered at \((0,0)\) in the Cartesian plane:



Challenge from the last post

If you read the last post, here I challenged you to come up with the equation of a square using the 'technique' I proposed/demonstrated. Suppose we have:

\[ \operatorname{max}\left\{\alpha\left(x-\frac{1}{2}\right),\beta\left(y-\frac{1}{2}\right),\delta\left(x+\frac{1}{2}\right),\gamma\left(y+\frac{1}{2}\right)\right\}=0\]

The values we eventually find are \(\left(\alpha,\beta,\delta,\gamma\right) = \left(1,1,-1,-1\right)\).

Simplifying through we get:

\[ \begin{align} \operatorname{max}\left\{x,y,-x,-y\right\}&=\frac{1}{2}\\ \operatorname{max}\left\{|x|,|y|\right\}&=\frac{1}{2} \end{align}\]


Derivations from Scratch

The very first derivation I started off with. We take the lines \(y=\frac{1}{2}\), \(y=-\frac{1}{2}\), \(x=\frac{1}{2}\) and \(x=-\frac{1}{2}\) and restrict them on the opposite axes. We get this piecewise equation:

\[ \begin{cases} y-\frac{1}{2} & -\frac{1}{2}\leq x\leq \frac{1}{2} \\ x-\frac{1}{2} & -\frac{1}{2}\leq y\leq \frac{1}{2} \\ y+\frac{1}{2} & -\frac{1}{2}\leq x\leq \frac{1}{2} \\ x+\frac{1}{2} & -\frac{1}{2}\leq y\leq \frac{1}{2} \end{cases} = 0\]

This... doesn't really help us. Firstly, our inequalities don't even begin to tell us anything about the cases they're describing, and secondly, nothing can be simplified out of each case. Perhaps we need to perform some substitutions, and rewrite our inequalities. We can do this knowing the definitions of \(y\) and \(x\) in each case. Here, I'll also split up the inequalities for further motivation.

\[ \begin{cases} y-\frac{1}{2} & -y\leq x\leq y \\ x-\frac{1}{2} & -x\leq y\leq x \\ y+\frac{1}{2} & y\leq x\leq -y \\ x+\frac{1}{2} & x\leq y\leq -x \end{cases} = 0\]

From here, there are two ways to go:

Absolute value route

Firstly, let's begin by rewrite our inequalities again. Let's also get rid of our fractions each case, and make the sign of our \(1\) the same so we can then take it out:

\[ \begin{cases} 2y & x+y\geq 0 & x-y\leq 0 \\ 2x & x+y\geq 0 & x-y\geq 0 \\ -2y & x+y\leq 0 & x-y\geq 0 \\ -2x & x+y\leq 0 & x-y\leq 0 \end{cases} = 1\]

In our cases, notice our inequalities are in terms of \(x + y\) and \(x - y\), whereas the cases themselves don't have those. For them, then, we can simply add and subtract either \(x\) or \(y\) depending on what's already there, and appropriately factor:

\[ \begin{cases} (x+y)-(x-y) & x+y\geq 0 & x-y\leq 0 \\ (x+y)+(x-y) & x+y\geq 0 & x-y\geq 0 \\ -(x+y)+(x-y) & x+y\leq 0 & x-y\geq 0 \\ -(x+y)-(x-y) & x+y\leq 0 & x-y\leq 0 \end{cases} = 1\]

We see where this is going. Let's write it all out though:

\[ \begin{align} \begin{cases} \begin{cases} (x+y)-(x-y) & x-y\leq 0 \\ (x+y)+(x-y) & x-y\geq 0 \end{cases} & x+y\geq 0 \\ \begin{cases} -(x+y)+(x-y) & x-y\geq 0 \\ -(x+y)-(x-y) & x-y\leq 0 \end{cases} & x+y\leq 0 \end{cases} &= 1 \\ \begin{cases} (x+y)+\left|x-y\right| & x+y\geq 0 \\ -(x+y)+\left|x-y\right| & x+y\leq 0 \end{cases} &= 1 \\ \left|x+y\right|+\left|x-y\right| &= 1 \end{align}\]

Maximum value route

We can rewrite our inequalities in a similar, but different way to the above route.

\[ \begin{cases} y-\frac{1}{2} & -y\leq x\leq y \\ x-\frac{1}{2} & -x\leq y\leq x \\ y+\frac{1}{2} & y\leq x\leq -y \\ x+\frac{1}{2} & x\leq y\leq -x \end{cases} = 0\]

If we move out our \(-\frac{1}{2}\), we get:

\[ \begin{cases} y & x\geq -y & x\leq y \\ x & x\geq -y & x\geq y \\ -y & x\leq -y & x\geq y \\ -x & x\leq -y & x\leq y \end{cases} = \frac{1}{2}\]

There are two ways we could go from here too:

Employ our maximum value definition


\[ \begin{cases} y & x\geq -y & x\leq y \\ x & x\geq -y & x\geq y \\ -y & x\leq -y & x\geq y \\ -x & x\leq -y & x\leq y \end{cases} = \frac{1}{2}\]

we get:

\[ \begin{cases} y & y\geq \operatorname{max}\left\{x,-x,-y \right\} \\ x & x\geq \operatorname{max}\left\{y,-y,x \right\} \\ -y & -y\geq \operatorname{max}\left\{x,-x,y \right\} \\ -x & -x\geq \operatorname{max}\left\{y,-y,x \right\} \end{cases} = \frac{1}{2}\]

Our definition tells us this is the definition of \(\operatorname{max}\left\{x,y,-x,-y\right\}=\frac{1}{2}\). Applying our maximum rules we get \(\operatorname{max}\left\{|x|,|y|\right\}=\frac{1}{2}\).

Note: This derivation method is what we could consider the slightly more rigourous route to the challenge I set in the last post, and for the technique shown - for this case. It'll vary depending on what you're trying to show, but for us, and our example, this is adequate and gives more insight into what we're actually doing. The below derivation also gives some more insight, also.

'Throw' absolute values on each of our variables...and then use the definition

Given we have all the possible values of \(x\) and \(y\) in relation to each other covered by our inequality cases, it would be safe to essentially wrap our variables in absolute values in order to simplify the equation. From

\[ \begin{cases} y & -y\leq x\leq y \\ x & -x\leq y\leq x \\ -y & y\leq x\leq -y \\ -x & x\leq y\leq -x \end{cases} = \frac{1}{2}\]

We get

\[ \begin{align} \begin{cases} |y| & |x|\leq y \\ |x| & |y|\leq x \\ |y| & |x|\leq -y \\ |x| & |y|\leq -x \end{cases} &= \frac{1}{2} \\ \begin{cases} |y| & |x|\leq |y| \\ |x| & |y|\leq |x| \\ \end{cases} &= \frac{1}{2} \\ \operatorname{max}\left\{|x|,|y|\right\} &= \frac{1}{2} \\ \end{align}\]

This derivation, rather than rely on a property itself of the maximum function, describes the conditions under which both sets of equations occur. So rather than considering, say, all quadrants at once, we consider only the first quadrant and extend it to the others; hence the combinations of absolute values in both variables - going backwards (derivation wise), that is. If the property of the maximum function in the previous derivation weren't available to us, this would be the quickest way to reduce and solve our problem.

Another interesting thing to point out is that the equation \(\begin{cases} |y| & |x|\leq |y| \\ |x| & |y|\leq |x| \end{cases} = \frac{1}{2}\) is equivalent to \(\begin{cases} |y| & |x|\leq \frac{1}{2} \\ |x| & |y|\leq \frac{1}{2} \end{cases} = \frac{1}{2}\) which gives a far more intuitive, or readable, piecewise equation. We have \(|y|=\frac{1}{2}\) when \(|x|\leq \frac{1}{2}\) and \(|x|=\frac{1}{2}\) when \(|y|\leq \frac{1}{2}\). Also a shoutout to a friend for pointing this out as another interpretation.

Taking it further

Geometric Interpretation - Maximum

In our above max function-based derivation, we sort of hinted at the interpretation we could make. Here, we're going to explicitly put that to use. Let's reduce our problem to quadrant 1 in the cartesian plane - that is, where \(x \geq 0\) and \(y \geq 0\). Here, our lines \(x = \frac{1}{2}\) and \(y = \frac{1}{2}\) exist. However, what we want to do is note their intersection; notice that they intersect at the coordinates \(\left(\frac{1}{2},\frac{1}{2}\right)\) which suggests to us that we can define our lines by where they lie relative to the line \(y = x\). We know that the line \(y=\frac{1}{2}\) lies above \(y=x\) and that \(x=\frac{1}{2}\) lies below it. So what we can do is sort of meld these two equations and we get:

\[ \begin{cases} y-\frac{1}{2} & y\geq x \\ x-\frac{1}{2} & x\geq y \end{cases} = 0\]

And if we simplify we get \(\operatorname{max}\left\{x,y\right\}=\frac{1}{2}\) which should already be familiar to us.

But notice, this is a reduced problem in only quadrant 1, so we've only solved it there. What we want to do is also have it hold in quadrants 2, 3, and 4, and luckily for us, they're simply combinations of reflections on \(x\) and \(y\) axes. This translates thusly:

  1. Quadrant 2: \(\operatorname{max}\left\{-x,y\right\}=\frac{1}{2}\).
  2. Quadrant 3: \(\operatorname{max}\left\{-x,-y\right\}=\frac{1}{2}\).
  3. Quadrant 4: \(\operatorname{max}\left\{x,-y\right\}=\frac{1}{2}\).

We want all of these to hold. If we think back to combining our equations using maximum, we could employ that - we'd get the same result as one of our from-scratch derivations, which is fine. Alternatively, we think about it like this: If we want both \(x\) and \(-x\) to hold, we know that \(|x|\) will always hold. Similarly for \(|y|\). Given that we know \(\operatorname{max}\left\{|x|,|y|\right\}=\frac{1}{2}\) would give us all the combinations of the above, we can take that as our result.


Connecting \(|x-y|+|x+y|=1\) to \(\operatorname{max}\left\{|x|,|y|\right\}=\frac{1}{2}\)

Firstly, this post should already tell you that the two are connected via the same piecewise equation. But if we want to get from the former equation to the latter, we can simply apply the rules we established a few posts back with the maximum function. Furthermore, I challenge you to find a method of going from the latter equation to the former; you'll need to use a few tricks, but it's fairly straightforward in the end.

Going from the former to the latter, I'll lay out all of the steps:

\[ \begin{align} |x-y|+|x+y| &=1 \\ |x-y|+\operatorname{max}\left\{x+y,-x-y\right\} &=1 \\ \operatorname{max}\left\{|x-y|+x+y,|x-y|-x-y\right\} &=1 \\ \operatorname{max}\left\{\operatorname{max}\left\{x-y,y-x\right\}+x+y,\operatorname{max}\left\{x-y,y-x\right\}-x-y\right\} &=1 \\ \operatorname{max}\left\{\operatorname{max}\left\{2x,2y\right\},\operatorname{max}\left\{-2y,-2x\right\}\right\} &=1 \\ \operatorname{max}\left\{2x,2y,-2x-2y\right\} &=1 \\ \operatorname{max}\left\{x,y,-x-y\right\} &=\frac{1}{2} \\ \operatorname{max}\left\{\operatorname{max}\left\{x,-x\right\},\operatorname{max}\left\{y,-y\right\}\right\} &=\frac{1}{2} \\ \operatorname{max}\left\{|x|,|y|\right\} &=\frac{1}{2} \\ \end{align}\]

The Diamond

In our previous post, we considered two forms of the diamond. You can see this post here. In fact, the equations we established look incredibly, suspiciously even, similar to the equations we established in this post (albeit with this post being more in-depth). The simple reason for this is, they are. Both are squares, just rotated by 45 degrees.

The way we can go from the square to the diamond, or vice versa, is via the Rotation Matrix. Note, though, that in order to go from a unit square to unit diamond or vice versa, you'll have to use the unit diamond equation; the diamond we initially derived has a side length of \(\sqrt{2}\). If your memory needs jogging, here's the link to that post.

It's fairly straightforward to apply the rotation matrix to our equations using the rules we've got; I in fact encourage you, the reader, to do so for some practice.

Transformation, Size and Rectangles??

With our derivation, we can impose different sizes on the square through different methods. The first method would be to go through this post again, and replace all the \(\frac{1}{2}\) lines with \(\frac{a}{2}\) and re-derive from there. That's the easiest way to do it. It's also intuition, too.

Because we derived the 'unit' square, you can also simply apply transformations on \(x\) and \(y\) to our final equations. You could even do so with our original piecewise equations and derive that again. Ouch, sounds painful, though. In fact, you can even create rectangles with this. You could make rotated rectangles if you're that ambitious too - let me know how that goes.


And so brings us to the end of another thrilling (less obvious but still very connected) series of posts. This time, it's for real - I don't currently, at time of writing, have anywhere further to go with this current line of thinking. The fun thing is though, with all that I've shown, everyone who knows and understands this can themselves play with the concepts I've presented. And to me, that's what matters. Being able to interact with people who can read these posts, challenge me on some of the concepts I've presented, and then finally see them work with them is the (second-)most satisfying part of this all. Even to the people I can't see, I hope you can work with these too.

To those who do make the effort to read these posts - thank you so much. ~Ally