So an online friend of mine saw a tweet about a secret society of scholars who plan to create a universe where everything is square.
The difference between circles and squares is something I've been thinking about of late because a world in which circles are squares is a world without Pythagoras' Theorem, and that's been on my mind a bit recently.
More precisely, if we take either the or norm on then the "unit circle" is actually a square.
But that's not replacing circles with squares. A circle or a square can be defined without regard to the ambient norm. So to actually replace circles with squares, we need something with some circles in it where replacing them by squares makes an actual difference.
1 Epicycles
Enter Epicycles. Every now and again I see a post on epicycles. Every now and again I get annoyed by a post on epicycles.
I'm not a historian of mathematics, but my reading of the story of epicycles goes something like this. Circles were viewed as a form of perfection, and the heavens (by which I really mean everything outside the atmosphere) were perfect, so therefore the heavenly bodies must move on circles. They clearly don't. So they must move on some complicated path that involves circles moving along circles. These are epicycles.
Along came Brahe, Copernicus, Kepler, and ultimately Newton who pointed out that actually everything moved on ellipses and so epicycles faded back into the aether. Until Fourier, that is, who showed that everything (for some definition of "everything") was actually made up of circles providing you used an infinite number of them. In other words, along came Fourier series.
Cue lots of posts on the internet showing how to take a shape and draw it by lots of cute circles rotating about each other at different speeds. These tend to irritate me a little, mainly because they gloss over some detail or other. For a while I had in mind writing about those details, but I couldn't think of an "in" other than that all the other posts I'd read irritated me and that didn't feel like a good basis for a post.
The theme of replacing circles with squares, however, does feel like a good basis for a post.
I do need to explain one thing about what irritates me about the way epicycles are presented. There seems to be some "wow" factor about drawing a picture with a lot of circles. To me, it is more impressive to draw a picture with as few circles as possible.
I did write a little program with the idea of fixing the number of circles and playing around with the various pictures one could get by varying the coefficients in the resulting Fourier series. But that was as far as I got until the idea of squares and circles reared its head.
2 From Circles to Squares
The key idea of replacing circles by squares is very simple: take a finite Fourier series and replace the circle functions (either and or depending on whether you are enlightened or not) by their equivalent square functions.
Let's unpack that a bit. We can think of the function as the function which tracks the –coordinate of a point moving around the unit circle at such a speed as to go around times in unit of time. Similarly does the same for the –coordinate. We want to replace these by functions that track the and –coordinates of a point that moves around the unit square.
Just as for the circle, we start from and travel anticlockwise. The graphs of the coordinate functions look like Figure 1.
Their definitions look a little tricksey, but aren't all that complicated.
Implementing them in code is straightforward, so I could easily add them to my little program.
My proposal, therefore, for "replacing circles with squares" is to take a finite Fourier series and replace the circle functions with their square equivalents.
It would be nice to do this for a general Fourier series, but there's a slight hitch. The square functions do not form an orthonormal basis for the appropriate space of functions. So there's no guarantee that the result of swapping the circle functions for square ones in a general Fourier series will result in a well-defined square integrable function. It may be that there is some obvious way to change the norm to make the square functions orthogonal, but I'll leave that question open for now.
3 Ticking of the Clock
The replacement idea is still not enough. I need a ready source of curves to apply this to. I quite like the idea of "a curve a day", so I started thinking about how to change a date into coefficients.
To give enough scope for variation, I considered series of the form:
with each . I skipped as that would only shift the resulting shape.
So I wanted a way to convert a date into a set of values for the . The first step is to discretise the possibilities, so rather than we consider , namely complex numbers with integer real and imaginary parts (so-called Gaussian integers).
There are a few transformations that essentially preserve the resulting shape. Multiplying every coefficient by the same complex number scales and rotates the shape, while swapping reflects the shape in the –axis. Also, replacing by means that we go round the shape times.
To ensure that we don't get essentially repeated shapes, we want to allow only two possibilities for , namely or . If we insist that have real and imaginary components one of , , or then we get choices for for each choice of , but some of these should be viewed as equivalent. We regard two as equivalent if they are related by a rotation, reflection, or interchanging the pair (or any combination of the two). This leaves the following choices for :
-
When , can be one of , , , , , .
-
When , can be one of , , , .
This gives choices in all.
That accounts for and , leaving us with four complex parameters to play with. Ideally, I'd like to say that there is a fixed set of choices and each is drawn from that set. Given a set of size , we therefore have a total parameter space of . With days, this gives a set of size a little under , which is not very big and therefore doesn't give us much freedom in generating curves. I wanted something a little more to play with.
Calendars and clocks go hand in hand, so let's try making it a time and date concept. There are seconds in an hour and hours in a day. So the number of seconds in a year is roughly
Now it just so happens that which is very close to both and . In fact, and , a discrepancy of a little over a thousand which is almost nothing in this context. So if we fix on a set of Gaussian integers and draw and from this set, we can use one lot to account for days and the other to account for s of seconds (so the "tick" for our clock will be every seconds). It gets a bit confusing to refer to "s of seconds" with all the numbers flying around, so I'm going to use the term "decasecond".
This leaves us with just the hours. We have a factor of from the choices of and . If we could just leverage that up to then we'd have the hours up to a.m. and p.m., with then a factor of to finish with. We have options when , but only when . So if we add in two more for when we'll be home and dry. Adding in and provides a pleasing symmetry, and while the choice of, say, and is related to the choice of and by multiplication by , if we pick our points for the other coefficients carefully we won't get any duplicated pictures.
Let's choose those points. I have to admit, is a strange number to be choosing as it affords very little symmetry. Figure 2 is what I ended up with. (Though if you count the points, you'll find that there are twenty – so for each of the four coefficients I remove one of the four innermost points.)
The final step is the factor of from the morning and afternoon split. But here's where the circles and squares comes to the rescue: one is circles, the other squares.
4 Mixing it up
The final step was to mix up the choices. The way I have laid it out above, the obvious course is to take a date and time and write it as a triple using days (of the year), hours (of the day), and decaseconds (of the hour).
At time of writing, we are at the th day of the year, th hour of the day, and approximately th decasecond of the hour. Then we take the and the and write them in base as and , respectively. Finally, we write the in base as . We therefore have our numbers as:
So we can use the and to choose and , the and to choose the and , the tells us which pair to pick for and , and the tells us whether to use squares or circles.
The problem with this is that it is all rather too predictable. Only one number is guaranteed to change every decasecond and all morning pictures will use circles.
So let's mix it up.
I'll show what I do with the numbers given above: th day of the year, th hour of the day, and th decasecond of the hour.
The first thing is to use the parity (by which I mean "odd/even"ness) of the decasecond number to set the circle/square choice. Rather than swapping every decasecond, what I decided to do was to swap every odd decasecond, so the sequence goes "square", "circle", "circle", "square". This means that every decasecond we either swap between using squares and using circles, or we change our coefficients. I quite like the effect of this as it means that the change in type and change of coefficients happen at different steps.
Once we've used the parity of the decaseconds to determine whether we're using squares or circles, we need to remove it from consideration. This means that we round down to the nearest even number, in this case .
Our decaseconds count now only has half the information it had before, so we augment it back up to full strength using the "morning/afternoon"ness of the hour. In this case, is afternoon so we add to the decaseconds and replace by its equivalent on a hour clock (with a slight modification that we use instead of ). So we're back to decaseconds but now have hours.
We'll use the hours to set and . We start by using its "odd/even"ness to set : is odd so we take . Then we divide by and throw away any remainder to get . We use this number to choose one of the choices for . The formula I used was to use its "odd/even"ness to choose the imaginary component (in this case ), then again dividing by and throwing away the remainder gives us one of , , or , in this case . Subtracting maps this to , , or which gives us the real part, in this case . So our resulting number is actually . Finally, we multiply that by to get the correct choice for .
Now we look at our two numbers for days of the year and decaseconds of the hour. We want to mix these together in a fashion that means that we still get a unique set of choices for the remaining (ignoring, that is, the minor issue of the discrepancy between and – we basically ignore that).
Our numbers of days and decaseconds will be changing by one each time they change (apart from on the wrap around). So we make it so that a change by one in these numbers means a bigger change in the numbers we actually use. To do that we multiply them by some fixed number, and then take remainders on dividing by . To ensure that when we do that we don't lose any information, we need to pick our fixed number carefully – it needs to be invertible modulo , meaning that it must not have any factors in common with . We'd also like it to be quite big, somewhere in the middle of , to have the biggest disruptive effect. I picked .
So we multiply our numbers by and then take remainders modulo . This mixes up the numbers without losing information. It doesn't, though, change the fact that one of the numbers only changes each day. My solution to that is to combine the number of decaseconds with the number of days in such a fashion that if we know the combination and the number of decaseconds then we could recover the number of days (this means that we don't lose any information). By combining this with multiplying by , we can mix up these numbers quite considerably without changing the amount of information contained in them.
The procedure I went for was the following. Start by multiplying the decaseconds by , in our example we get . We'll take its remainder after dividing by to get one of our numbers, which will be . This throws away the quotient, which is , so we'll add that to our other number, to get in our example. Now multiply that by and take its remainder on dividing by , in our case we get .
So from our original numbers of and we have generated two new numbers and . Let's see what happens to those numbers as the seconds tick by.
And finally, we convert each of those numbers to a pair of numbers less than to pick one of our chosen points as the coefficient.
The last step in designing the clock is to figure out what to do with the seconds between each change. As we're drawing a shape, I use of those seconds to trace round it and then the final seconds to morph from one shape to the next.
The result is the animation at the top of the page. A more intricate version (showing the construction details) can be found on my code pages with source on github.