Calculating Pi Terribly


I’m not really a fan of Pi Day. I’m not fond of the 3/14 format for writing dates to start with — it feels intolerably ambiguous to me for the first third of the month — and it requires reading the / as a . to make sense, when that just is not how the slash works. To use the / in any of its normal forms then Pi Day should be the 22nd of July, but that’s incompatible with the normal American date-writing conventions and leaves a day that’s nominally a promotion of the idea that “mathematics is cool” in the middle of summer vacation. This particular objection evaporates if you use . as the separator between month and day, but I don’t like that either, since it uses something indistinguishable from a decimal point as something which is not any kind of decimal point.

Also it encourages people to post a lot of pictures of pies, and make jokes about pies, and that’s really not a good pun. It plays on the coincidence of sounds without having any of the kind of ambiguity or contrast between or insight into concepts that normally make for the strongest puns, and it hasn’t even got the spontaneity of being something that just came up in conversation. We could use better jokes is my point.

But I don’t want to be relentlessly down about what’s essentially a bit of whimsy. (Although, also, dropping the ’20’ from 2015 so as to make this the Pi Day Of The Century? Tom Servo has a little song about that sort of thing.) So, here’s a neat and spectacularly inefficient way to generate the value of pi, that doesn’t superficially rely on anything to do with circles or diameters, and that’s probability-based. The wonderful randomness of the universe can give us a very specific and definite bit of information.

Suppose that you have a floor with a set of uniformly spaced parallel lines across it. And suppose that you have a short stick, like a needle or toothpick or match, which is not as long as the lines are apart. If you have a great deal of patience, and are able to drop the needle repeatedly so that there’s no predicting where on the floor it’ll land, and what angle it’ll make relative to the parallel lines, then you can work out the value of pi. In principle, you can work it out to as many decimal places as you want, although in practice, you’re a crazy person to try it.

But here’s how. Suppose that the parallel lines are each a length D from their nearest neighbors. And suppose the needle (toothpick, match, whatever) is some shorter length L . If you drop the needle a grand total of N times, and if the needle crosses the lines some n of those times, then the value of pi is estimated by

\pi \approx 2 \cdot \frac{L}{D}\cdot \frac{N}{n}

This little problem of dropping things on floors is known as Buffon’s Needle Problem, Buffon in this case being Georges-Louis Leclerc, Comte de Buffon, the 18th-century naturalist and mathematician and encyclopedia-writer. In mathematics he’s known for advancing the study of probability, particularly in bringing calculus into it. In cosmology he’s known for proposing the idea that planets were formed when comets collided with stars, which is not generally accepted these days, although it was a strong rival to the condensing-nebula idea we now take to be so. He also noted, based on experiments with how spheres of iron cooled, that the Earth had to be considerably more than a mere six thousand years old. He only estimated the age of the world to be about 75,000 years, but it’s hard to discover Deep Time except incrementally, and the problem of the flow of heat into and out of the Earth would be critical to the 19th-century struggle between geologists and physicists about how old the Earth could be. As a naturalist he’s regarded as one of the forerunners to modern evolutionary theory; as an anthropologist he’s known with a fair amount of embarrassed coughing and attempts to place him in historical context.

Nevertheless, I find this needle-dropping result to be wonderful. It shows one of the strange truths about probability, which is that pure randomness carries predictability within it. You can know with certainty the result of a group of many experiments even though you cannot predict the result of any one of them. If a falling needle can be said to have liberty, it has it; we do not need to know any details of its plummet, much less do we need to control it, to know something precise about what happens in uncountably many trillions of unique needle-drops.

That said, why is this such a terrible method of finding pi? Besides the problem of cleaning up the floor after all these needle-drops, the method is very much like working out the value of 1/2 by flipping a fair coin and counting the number of tails that come up compared to the number of flips. While the average of the number of tails to the number of flips will tend toward 0.5, and get closer to it the more flips you try, after any finite number of flips the number of tails will probably be a little high or a little low of the “true” value. This variation is unavoidable. The variation will shrink as the number of attempts grows, but it can’t be counted on to drop to zero unless you do infinitely many flips.

The University of Illinois’s Office for Mathematics, Science, and Technology Education has a pretty nice, Javascript-and-HTML5-based, simulator and you can try tossing down thousands of needles of any length up to the line spacing, and see what estimate of pi you come up with.

We can work out an error estimate, and we can use that to say how many needle drops we can expect to need to do if we want, say, two decimal digits of accuracy. Sadly, the formula requires the actual value of pi in the right-hand side of the formula so there’s a bit of a bootstrapping problem here. (Well, we could use a preliminary estimate of pi to help us figure out how much work would be needed to make a better estimate.) If the length of the needle L is shorter than the distance between lines D , then to get an estimate of pi that’s not any more than E away from the true value implies the number of needle-drops N has to be big enough that

N > 2\pi^2 \cdot \left( \pi\cdot\frac{D}{L} - 2\right) \cdot \frac{1}{E^2}

If the needle length is half the spacing between parallel lines, this works out to approximately N > 84.55 \div E^2 and you see how really huge numbers of needle-drops are needed if you want the error margin E to be all that small. To have an error margin smaller than 0.005 implies running over 3,380,000 needle-drops.

Now, that you need a huge number of needle-drops to be sure the error is small doesn’t mean that you can’t get lucky. But if you truly didn’t know the value of pi beforehand, you wouldn’t know to stop when your running total got lucky, and while you might after a couple million needle-drops feel pretty sure you had got the “3.14” part of pi down I daresay you aren’t going to keep on doing needle drops to try getting the next digit after that.

This is, though, an example of the ways that probabilistic methods can be used to give reliable and true results. These kinds of probabilistic methods are described by many terms: “stochastic” is a popular one, and “Monte Carlo” another, and yes, that name derives from the famed casinos. Probabilistic approaches tend to make it possible to study problems using experimental methods that are not hard — there’s nothing tricky about dropping a needle and seeing if it crosses a line, once you’ve decided what to do in case the end of the needle touches but doesn’t cross over the line — but they do tend to require a lot of simple work. As a result, they’re usually best done in computer simulation. This presents a subtle but real problem of how to produce random results on a machine that follows algorithms precisely, but that’s a grand set of problems on its own.

Advertisements

Author: Joseph Nebus

I was born 198 years to the day after Johnny Appleseed. The differences between us do not end there.

10 thoughts on “Calculating Pi Terribly”

  1. When I first read about this method for calculating pi before, I have entertained the idea of trying it myself but I quickly discarded that idea, since who knows how long it would take before I would reach pi :)

    Btw, I’m also very confused with the American way of writing dates since I’m used to either ddmmyyyy format or yyyymmdd format. So, March 14, 2015 for me is 14/3/2015. I’ve also just posted some of my reasons why I don’t celebrate pi day…

    Like

    1. Oh, it would just take forever to find pi using needles and ruled lines. You’d do considerably better if you drew a quarter-circle on a square dartboard, and tossed darts at it, counting the ratio of darts that hit inside the quarter-circle to darts outside. At least you’d have a better night of it.

      I don’t know why the United States uses the month-day-year format, particularly since it hasn’t got much (any?) use elsewhere in the world. My suspicion is that there probably was a time when both month-day and day-month were common enough in English-speaking nations and the United States settled on one format while the United Kingdom another back in the 19th Century back when stuff standardized.

      Like

      1. Well, it seems widespread because of US websites like Google use mmddyyyy format by default and most of the top sites are from the US…

        Though I have noticed that they are now slowly changing the date format of many wikipedia articles to ddmmyyyy format.

        Like

        1. I have noticed what looks like a slow shift in american use to day-month-year format, at least when the month is given its proper name rather than a number. The year-month-day order seems irresistible if you’re determined to stick to writing things as digits, for reasons I have to agree are pretty solid.

          Anyway, there does seem to be something logical about sticking to one logical path about whether the thing written first should be the thing most likely to change and the thing written last the least likely, or the other way around.

          Liked by 1 person

Please Write Something Good

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s