Three cheers for tau

Leif Johnson — 08 Jul 2012, 18:07

At least on Hacker News, there's been a healthy debate going for a little while about whether tau or pi is “right.” Tau, if you haven't seen it already, is defined as the ratio of a circle's circumference to its radius : $$ \tau = \frac{C}{r} $$ Pi, on the other hand, is well-known from school as the ratio of a circle's circumference to its diameter : $$ \pi \frac{C}{d} $$

Like all healthy debates, there are solid points to be made on both sides, and the winner, to my eye and that of others, seems to depend on your primary intended use. After all, %%\pi = \frac{\tau}{2}%%, or %%\tau = 2\pi%%, so the one substitutes readily for the other. Advocates of %%\tau%% swoon over the absence of %%2%%s floating around in classic phenomena like the natural period of a sine wave, while advocates of %%\pi%% jostle back with the delicate simplicity of %%\pi%% in the formula for the area of a circle.

Aesthetics is a touchy area, partly because many people often have strong feelings about aesthetics hidden beneath the otherwise calm surface of their conscious minds. People claim equanimity, but a secret tumult rages below, only to be unleashed when a debate breaches the surface of one's aesthetic assumptions. Sometimes these debates can get vicious, but the comments I have read from both sides of the %%\tau%%–%%\pi%% debate seem well-considered, and the general conclusion seems to be that %%\tau%% and %%\pi%% are both well-suited for use, but for different specific purposes. In particular, %%\pi%% seems well-suited for cases where you're measuring areas of things, while %%\tau%% seems well-suited for cases where you're measuring angles.

The first time I heard about %%\tau%%, I thought the author of the manifesto was a little bonkers. I mean, who would question the correctness of a constant as fundamental in our universe as %%\pi%% ? But even after a few minutes, just enough of a seed was planted in my brain to think that this might not be such a crazy idea after all. Angles, it turns out, are everywhere in the three-dimensional world. So, although unsurprising in hindsight, I was a little startled the first time I decided to take %%\tau%% out for a spin in my own work. Mostly I was startled to find that I'd already been using %%\tau%%, only I'd defined it in most of my code, up near the top, as

TWOPI = 2 * numpy.pi

That constant appeared at the top of nearly every Python program I wrote that dealt with drawing, from Cairo to OpenGL. As described in the Tau Manifesto, all you have to do to start using %%\tau%% is to define it near the start of your code or paper, either as the ratio of circumference to radius, or even more simply, like above, as %%2\pi%%. Happily, and surprisingly for me, several remaining parts of the code and papers I've worked on have become simpler as a result.

The change doesn't suddenly solve all your programming problems ; it isn't even that pervasive, really. But somehow, the mental load of handling two constants simultaneously—%%2%% and %%\pi%%—is noticeably higher than handling one—%%\tau%%. For example, converting from radians (the lingua franca of most math libraries) to angles (the dialect of many graphics libraries) becomes somehow easy to remember, a simple matter of changing units. I was never able to remember the conversion formula when it was stated in terms of %%\pi%%, since it has a bizarre factor of 180 floating in there :

$$ \theta^\circ = 180 \frac{\theta^r}{\pi} $$

but the same formula, multiplying the top and bottom by 2 and then replacing the %%2\pi%% with %%\tau%%, just sticks in my mind :

$$ theta^\circ = 360 \frac{\theta^r}{\tau} $$

I think it's easier to remember for an embarrassingly simple reason : there are 360 degrees in a circle, and %%\tau%% radians in a circle. So, convert from the latter to the former, we just divide out the number of radians, and multiply by the number of degrees. Somehow that never made sense to me when thinking about %%\pi%%.

A similar simplification appears when converting to a new fundamental frequency in sines and cosines. The natural period of the sine function is %%2\pi%%, so to convert to a new frequency, you need to have all of these expressions floating around in your code :

numpy.sin(2 * numpy.pi * freq)

But, as I mentioned earlier, I already had these definitions at the top of my files :

TWOPI = 2 * numpy.pi

so the line was usually

numpy.sin(TWOPI * freq)

which, syntactically and semantically, is identical to using %%\tau%%. Again, though, I find this strangely harder to wrap my head around than

TAU = 2 * numpy.pi
numpy.sin(TAU * freq)

What's going on here that makes %%\tau%% so much easier ? The code is nearly character-for-character the same. I think the beautiful thing that's happening is that %%\tau%% really does capture a fundamental constant, in a way that makes it look like %%\pi%% is the one that's off by a factor of two.

Of course, these examples are biased towards cases where %%\tau%% shines—dealing with angles—, but in my experience, these cases are the rule rather than the exception when writing scientific code. I think this bias towards angles helps make %%\tau%% the “sensible default” when dealing with many scenarios in scientific and graphics programming.

So, I, for one, have decided to embrace %%\tau%% in my work, because I find it simpler to understand in many common scenarios. Besides, who wouldn't want twice the pie ?