Recently I was watching this television show called "Person's of Interest", episode 11 of season 2. In this episode they had an explanation about pi, this was an interesting explanation that I actually encountered in a classroom myself. I could not believe a television show was giving me memories about math class. Who watches a television show to end up thinking about math? Turns out, the same experience I found in elementary school shows up in a fictional scenario on television. You can catch a clip of it on Youtube, as Mr. Finch explains pi (transcript from the episdoe):

Pi.

The ratio of the circumference of a circle to its diameter.

And this is just the beginning.

It keeps on going.

Forever.

Without ever repeating.

Which means that contained within this string of decimals is every single other number.

Your birth date, combination to your locker, your social security number.

It's all in there somewhere.

And if you convert these decimals into letters, you would have every word that ever existed in every possible combination.

The first syllable you spoke as a baby, the name of your latest crush, your entire life story from beginning to end.

Everything we ever say or do All of the world's infinite possibilities rest within this one simple circle.

Now what you do with that information What it's good for Well, that would be up to you.~

Mr. Finch

Can you imagine it?

Now this got me thinking, what if we could write a simple program that could check the number pi and see if it actually worked. Don't get me wrong, I am not going to prove or disprove if this notion of pi is true or false. Leave that up to some other mathematician, I am simply here to try out an experiment. The main problem we will run into is that we don't have a large number of pi at our finger tips. Even if we did, where would we have stored such information? Can you imagine viewing a text file on computer with a billion digits of pi? Your computer might crash, or at least take a long time to load the file.

With mathematics the way it is today, people have actually computed pi to a large amount of digits. With the aid of computer science, we can actually obtain such feats ourselves. I will go over some ways you can calculate pi, then I will show you some python code. After all that is said and done, we will get a file that has a billion digits of pi and try to see if we can find ourselves in it.

Our first stop is to think about how people computed pi by hand. Why? Because I believe you should know the origin about pi a little bit if your going to experiment with it. So how did the great Archimedes do it? If you look online, you can find a lot of examples describing a modern approach. I viewed this video to learn more about how Archimedes applied his "method of exhaustion". I won't show you how he originally applied this method, I am merely showing you a modern interpretation of this method.

The video shows us a simple formula:

I am sure your thinking, is that really it? No, that is not really it. The actual work it takes to compute pi by hand is tremendous, its no small feat without the help of computer science. This is not even the original way Archimedes did his work, its just a modern way to calculate with a computer (either a calculator or some computer language). You may wonder why can't we calculate this formula by hand with out calculators, well that is a good question. If you notice in the formula above, there is 180 degrees in the equation. In order to calculate this by hand we would have to convert 180 degrees to radians. The formula for converting degrees to radians is this:

So if we go back to our formula and convert 180 degrees into radians we will end up with a formula that looks like this:

Now we have the problem of having pi in the formula, we can not calculate by hand this formula. The formula contains pi itself in the equation, and we are trying to find pi!! Can you see the problem. If you type this into a calculator then it will work just fine, another solution is to take a certain amount digits of pi. We could have used 3.141592 in the formula, instead of pi. But then our answer would be limited in its accuracy of the original pi we use. I suppose you could keep updating pi as you calculate more and more numbers of pi, but that takes on other factors which are not relevant to us right now.

The way we could produce accurate numbers of pi is to keep increasing the value of n in the equation.

When n = 12:

When n = 24 (double the n):

When n = 96 (5 times the original n):

When n = 576 (48 times the original n):

And finally when n = 100,000 (about 8333.333333 times the original n):

As you can see, when we increase our n we produce a much more accurate representation of pi. I started to wonder, is there a way to do this by hand if one desired too? There is! Luckily for me, I have a friend who is a computer scientist that endures my mathematical endeavors. He recently posted an article that talked about computing pi with python, you can view his blogs on the living pearl. The specific article talks about ways you can compute pi in python. He shows you a couple of different methods, and he introduces three distinct formulas. The three methods he talks about are Bailey–Borwein–Plouffe formula, Bellard’s formula, and Chudnovsky algorithm.

The first formula is the Bailey–Borwein–Plouffe formula:

If your going to compute this by hand, then I would suggest making tables of all the denominators in the formula first. I won't list out the accuracy, he already did that in his article. Note, that with this formula it is possible to do by hand with out a calculator. We don't run into the problem of the first formula I showed you.

The second formula is Bellard’s formula:

This guy is even worse by hand then the previous one we just looked at, this took me a good hour just to do by hand for only a small number of iterations. I would again advise you to work out a table of all the denominators before taking the summation. Also, list a table of base 2. Again, you can see the results here.

The last formula is the Chudnovsky algorithm:

This is the worst formula I ever computed by hand, I will never remember another formula that hurt so much. I mean this guy will make you bleed a little, I had to use all three of my whiteboards to work out this algorithm. Take my advice and just look at the results here.

If you take his python code and print out a table of pi through each iteration from the three formulas, you can see a good comparison of which one is faster. All this work is to show you how hard it is to compute pi. Now imagine we are about to reap the work of brilliant mathematicians, just to find a number inside a number. Take each line of code and paste it into your editor. Make sure you save your file with a ".py" extension, then when your all done save and run the file in command prompt or terminal.

- [
**Step 1**]: To start us off, first you must find a source with a large amount of digits of pi. I looked at MIT's work and found they had posted pi with a billion digits past the decimal point. So download the file, but I recommend that you do not open it. If you want, copy the first 100 digits of pi on a text file and use that as test.

- [
**Step 2**]: We have to first recognize the file that contains a billion digits of py

pi_file = open("pi-billion.txt","r")

- Now, we have set up the program to read the file one digit at a time.

- [
**Step 3**]: The problem I got stuck on was how do you compare the number your looking for in pi. I figured I had to use a list, because we can easily add and drop elements inside the list. The thing that confused me was how to keep track of your current position inside pi.

- So finally, my friend suggested that I check for the number I am searching for one digit at a time in pi.

- I first receive the number from the user input, I check its length, and make and empty list to add each digit of our new string. Then I make an empty list to add numbers from pi. We now have two list to compare.

number = raw_input('Input number to search in Pi: ') print 'this is length of the given number', len(number) number_list = [] pi_list = []

- [
**Step 4**]: Now the next part is to split up the number we get from the input into a blank list. The reason for this is because we are going to check if your number exists in pi by comparing two lists. So iterate through each number in the user input and add it to our empty list. At the end, it should print a list with all the digits from the original string.

for integer in number: number_list.append(integer) print 'this is the number list', number_list

- [
**Step 5**]: We are now ready to set a while loop and check pi for our given number:

checking_pi = True while checking_pi == True: current_digit = pi_file.read(1) if len(pi_list) < len(number): if current_digit == ".": print 'Throwing out the decimal' else: pi_list.append(current_digit) # print 'this is pi list', pi_list else: if pi_list == number_list: # print 'this is pi list', pi_list print 'I found the number, it ends at this position: ', (pi_file.tell() - 1) checking_pi = False print 'exiting the loop' else: pi_list.pop(0) if current_digit == ".": print 'Throwing out the decimal' else: pi_list.append(current_digit) # print 'this is pi list', pi_list pi_file.close()

- At the end of the file, I close the file that contains our digits of pi.

We are now done, open up a terminal and test the file. Check for any number you desire, it could be a date of birth, phone number, address, zip code, time, social security number, etc....

Here is an example: I entered the time I finished writing up the bulk of this post, which was 11: 51 pm.

- It found the position of the time in the file at 27002, so our time starts in pi at position 26998. Remember, the position that the program gives you is the last spot where the reader stops before it matches the two lists. Once the comparison is made, and both list turn out equal, then the loop breaks and you get a position.

There might be a number you do not find, this is a possibility you have to consider going into this experiment. Any result you get from this program does not prove or disprove the theory that pi contains every number. We are simply just exploring pi with the notion a part of you might exist in it.

The entire code looks like this:

pi_file = open("pi-billion.txt","r") number = raw_input('Input number to search in Pi: ') print 'this is length of the given number', len(number) number_list = [] pi_list = [] for integer in number: number_list.append(integer) print 'this is the number list', number_list # for i in range(10): # print 'this is i: ', i # print 'this is the current digit in pi: ', pi_file.read(1) # print 'this is the position in pi: ', pi_file.tell() checking_pi = True while checking_pi == True: current_digit = pi_file.read(1) #print 'this is the current digit in Pi: ',current_digit if len(pi_list) < len(number): if current_digit == ".": print 'Throwing out the decimal' else: pi_list.append(current_digit) # print 'this is pi list', pi_list else: if pi_list == number_list: # print 'this is pi list', pi_list print 'I found the number, it ends at this position: ', (pi_file.tell() - 1) checking_pi = False print 'exiting the loop' else: pi_list.pop(0) if current_digit == ".": print 'Throwing out the decimal' else: pi_list.append(current_digit) # print 'this is pi list', pi_list pi_file.close()

References:

*CBS*. N.p., n.d. Web. 19 June 2013. <http://www.cbs.com>. Path: http://www.cbs.com/shows/person_of_interest/.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/List_of_Person_of_Interest_episodes.*Youtube*. N.p., n.d. Web. 19 June 2013. <https://www.youtube.com>. Path: https://www.youtube.com/watch?v=yGmYCfWyVAM.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Archimedes.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Method_of_exhaustion.*Youtube*. N.p., n.d. Web. 19 June 2013. <https://www.youtube.com>. Path: https://www.youtube.com/watch?v=DLZMZ-CT7YU.- DeadBones, Cpt.
*The Living Pearl*. N.p., n.d. Web. 19 June 2013. <http://thelivingpearl.com>. Path: http://thelivingpearl.com/2013/05/28/computing-pi-with-python/. *Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Python_(programming_language).*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Bailey–Borwein–Plouffe_formula.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Bellard%27s_formula.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Chudnovsky_algorithm.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Command_Prompt.*Wikipedia, the free encyclopedia*. N.p., n.d. Web. 19 June 2013. <http://en.wikipedia.org>. Path: http://en.wikipedia.org/wiki/Terminal_(OS_X).- "One billion digits of π."
*MIT Edu*. N.p., n.d. Web. 19 June 2013. <http://stuff.mit.edu>. Path: http://stuff.mit.edu/afs/sipb/contrib/pi/.

Pingback: Math Teachers at Play #64 - Mathematical Mischief()