Killing Time With Recreational Math: A Slow Boat to "π-na"

in #steemstem6 years ago (edited)

Christie's link Public domain image.

This is the 9th in my series of killing time using recreational math (the others are listed at the bottom of this post).

If you have read my posts before you already know that there are a few prerequisites for this:

  • You like recreational math.
  • You are at a computer and have access to Microsoft Excel.
  • You are bored out of your tree.

So, let's get started.


"A Slow Boat To China" is an old saying, apparently from the game of poker, which means someone who is losing very slowly but inevitably their stake will go to zero. In general, it is used to refer to anyone or anything that is taking an inordinate amount of time to get to its destination.

In this post I am going to present what appears to be the slowest way to calculate the value of pi (hence the punny title).

Calculating The Value of π

Co-prime integers are defined as follows:

In number theory, two integers a and b are said to be relatively prime, mutually prime, or co-prime (also written co-prime) if the only positive integer (factor) that divides both of them is 1.

If you create a long list of random integer pairs and determine the fraction that are co-prime you can calculate the value of π using this relation:

where f is the fraction of integer pairs that are co-prime. Solving for π we get:

So let's get started.

The Spreadsheet

The image below shows the spreadsheet. I will be going through the calculations made in each cell and we will eventually end up with an estimation of pi simply by comparing random numbers.

Column A: This column just counts the rows. It is really there for no reason other than to help me not get lost in the spreadsheet. You don't really need it but it doesn't hurt either. This sequence is copied and pasted right down to the bottom of the spreadsheet (i.e. cell A1048576).

Cell B1: =1+INT(100000000*RAND())
Here is the calculation of the random number. The Excel random function will produce a random number between 0 and 1 with a precision to the 15th decimal digit. I find the accuracy of the calculation improves the bigger you can make your random number and that is why it is multiplied by 100,000,000. The value of 1 is added to the calculation because we are using the set of natural numbers and need to avoid a zero from popping up.

This equation is copied and pasted right down to the bottom of the spreadsheet (i.e.cell B1048576).

Cell C1: =1+INT(100000000*RAND())
This is other random number, the one that the first random number will be compared to. It is the same formula and it too is copied and pasted right down to the bottom of the spreadsheet (i.e.cell C1048576).

Cell D1: =GCD(B1,C1)
Here we use the greatest common denominator function to determine the GCD of the two random numbers. This equation is copied and pasted right down to the bottom of the spreadsheet (i.e.cell D1048576).

Cell E1: =IF(D1=1,1,0)
Here we see if the GCD is equal to 1. If true then the cell value is set to 1, if not then the cell value is set to 0. This equation is copied and pasted right down to the bottom of the spreadsheet (i.e.cell E1048576).

Cell F1: =SUM(E:E)
Here we sum up the results in column E. It will tell us how many random pairs were actually co-prime.

Cell F2:
This cell is simply set to 1048576 because that is the number of random integer pairs that are being compared. This is also the maximum number of rows that Excel will allow in a spreadsheet.

Cell F3: =F1/F2
This cell calculates the fraction of random pairs that were actually co-prime.

Cell F3: =SQRT(6/F3)
This cell applies the formula discussed at the top of the post and it should give us a good approximation of pi.

The Results

The graph above shows you the results of 50 trials of this calculation. You can see that it dances all around the value of pi. In fact I found it was really only good to about 1 or 2 decimals places and that is with over 1,000,000 terms in the series.

The screen capture in my spreadsheet example in the previous section was one of the few times that this calculation was actually accurate. The majority of the times that the calculation was run it wasn't as close.

(To get the spreadsheet to re-calculate just hit the 'F9' key and Excel will refresh all of the random numbers and provide a new estimate of pi).

Closing Words

I created this post because I find that it is somewhat amazing that the transcendental number 'π' is related to the fraction of random natural numbers that are co-prime. It is astonishing that mathematicians were able to root out this weird relationship just by sitting down and thinking about numbers.

On the other hand, this has to be the single-most slowest way to get a series to converge. After 1,000,000 rows in the series which compared over 2,000,000 random numbers, the estimated value of pi is really only good to about 2 decimal places.

After recording the calculated value of pi 50 times the results averaged out to 3.14158851487 which is good to about 5 decimal places (pi = 3.14159265359). This averaged value is the result of comparing 100,000,000 random digits. That's a lot of calculating.

Clearly, if you are choosing a series for calculating pi this is the one to avoid.

Thank you for reading my post.

Other Posts In My Recreational Math Series

  1. Testing the excel random function.
  2. Make Your Own Bell Curve
  3. Strange Attractors.
  4. Let's Travel To Alpha Centauri
  5. Calculate Sunset and Sunrise Times
  6. Conway's Game of Life.
  7. Caffeine Half-Life.
  8. Let's Simulate a Radioactive Sample

Post Sources

[1] YouTube Video: Generating π from 1,000 random numbers.
[2] Co-prime integers.
[3] A Slow Boat To China.

Sort:  

Wow, I love your post!😀

Would be interesting to see the Gaussian distribution of the results.
Would the mean value be very close to pi?

Must be very CPU intensive to calculate the GCD of all these large pairs. I thought there was no mathematical shortcuts to calculate this?

I tried out your suggestion and binned the results of 250 trials. Each trial calculated pi from the comparison of ~1,000,000 random number pairs. This means that the curve below is the result of ~500,000,000 random numbers.

It is starting to look "bell curvish".

Good job! So enough samples would yield quite an accurate value of pi!

.

I got my version cheap through work. I think that there are free spreadsheet apps out there equivalent to Excel but I have never really chased that one down except when I was playing with Linux about 5 years ago.

Good read. It really shows the astonishing intricacies behind every day mathematics!

Your Post Has Been Featured on @Resteemable!
Feature any Steemit post using resteemit.com!
How It Works:
1. Take Any Steemit URL
2. Erase https://
3. Type re
Get Featured Instantly & Featured Posts are voted every 2.4hrs
Join the Curation Team Here | Vote Resteemable for Witness

Coin Marketplace

STEEM 0.29
TRX 0.12
JST 0.033
BTC 63855.79
ETH 3113.00
USDT 1.00
SBD 4.04