In the 18th century, Georges-Louis Leclerc, Count of Buffon, proposed an experiment to estimate . The experiment (now somewhat famous as it appears in almost all probability textbooks) consists in dropping randomly matches on a floor made of parallel floorboards and using the number of time the matches land across a junction to estimate .

To perform the Count’s experiment, you do not need a lot of math. You only need to test if

with and are both uniform random variables, and is the width of the floorboards. You may remark that we use and that it looks like a circular definition until you think that radians is 45°, and you can estimate it using other means. Then you start throwing zillions of virtual matches and count the number of intersections, then use a laboriously obtained probability distribution to estimate .

Lucky for us, there’s a variant that does not require the call to sines, not complicated integrals. Just squaring, counting, and a division. Let’s have a look.

Let’s first start by a refresher. The area of a circle of radius is

If is conveniently 1, then we have a unit circle and the area is just, now, .

This suggests a variation on Buffon’s experiment to estimate . Instead of throwing matches, let’s say we rather would throw darts at a board. A square board, 2&time;2 units with a unit circle placed in it. Something like this:

Now suppose I have a really bad dart player that throws dart uniformly randomly on the square board. If I count the numbers of darts that land in the circle vs the total number of darts, I can get an estimate for . Because the area of the circle is and the area of the square is four, the proportion of darts hitting the board inside the circle is (asymptotically).

I’m somewhat lazy and did not want to deal with uniformly random numbers on , just , so I cut the board in four. Let us look at the upper-right corner:

Now, the quadrant (well, yes, that’s the correct name for a quarter of circle, methinks) as an area of , and the square is now a unit square, so the quadrant occupies ths of the square (since ). And then we play the dart throwin’ game:

If it lands outside,

I get 0 points, if it lands inside,

I get one point.

Now, checking if my uniformly random point is inside the circle is easy: if , then it’s inside (and then we count the infinitesimal border as inside).

The code is:

double pitify(size_t rounds) { size_t in=0; for (size_t i=0;i<rounds;i++) { float x= std::rand()/(double)RAND_MAX; float y= std::rand()/(double)RAND_MAX; if (sqr(x)+sqr(y)<=1) in++; } return 4*(in/(double)rounds); // estimate pi }

Which is straightforward enough. Now, how efficient is it at estimating ? Well, not very. Not very much at all.

To measure the efficiency of the quadrant method (let’s call it that even though I’m quite sure it has an official name), let us look at the estimates produced by varying the number of rounds in powers of ten: , , , all the way to . Since it’s random, we could be unlucky and get a very bad result, so let’s repeat every experiments 1000 times. This allows us to get the box-plots:

The dashed line is at . At rounds=1, we get either 0 or 4, since one dart is either in or outside the circle (and it breaks gnumeric’s box plot routine) and the estimate is 3.08. Then as the number of rounds increases, error goes down. But not terribly fast. Let’s see how close it gets:

Number of darts, repeated 1000&time; |
Estimation of |
Correct digits |

0 | ||

1 | ||

2 | ||

2 | ||

2 | ||

3 | ||

5 | ||

4 | ||

4 | ||

5 |

So the closest to we got after darts (and about 4h CPU) is , which isn’t great. Which is somewhat counter-intuitive since the variance is reduced by a factor 10 each time.

*

* *

So this method is très mauvaise to estimate . Fortunately for us, there are analytic methods to get good estimates of , like Plouffe’s incredible spigot formula, that can yield the nth digit of .

*To be continued*

[…] a previous episode, we looked at how we could use random sampling to get a good estimate of , and found that we […]

[…] ancient Egyptians, but can we do better? In previous posts, we have examined how to approximate by rejection and by approximating the area of a circle on a discrete grid. The rejection method showed very slow […]