run_this_first.ipynb.This script converts the first billion digits of pi into tau by the incredible algorithm of multiplying by two.
In order to avoid carry-the-one problems (which would occur at more than half the positions), the program does it in chunks, for every string of digits starting with the number 4, because no decimal-based number starting with a numeral of 0, 1, 2, 3 or 4 will gain a digit via carry-the-one when doubled. (It's true, think about it. Or just multiply 49999999999999999 by 2 in your calculator and see what happens.)
In [1]:
import time
import os
for i in range(10):
infilename = 'data/pi100m.dectxt.00' + str(i)
outfilename = 'data/tau100m.dectxt.00' + str(i)
if not os.path.isfile(outfilename):
start=time.time()
with open(infilename, 'r') as fin:
pi = fin.read()
overallcount = 100000000
for subset in range(9):
pisub = pi[subset*10000000:(subset+1)*10000000]
pos = 0
tau = ''
pisect=''
counter = 0
print "Processing " + infilename + ", remaining (million): ",
while pos < len(pisub):
if overallcount % 1000000 == 0:
print (overallcount / 1000000),
overallcount -= 1
if pisub[pos] == '4':
counter += 1 # I put in this counter to work on larger chunks, but I'm not convinced it makes a difference
if counter % 5 == 0:
numsect=int(pisect)
pisect='4'
numsect *= 2
tau+=str(numsect)
else:
pisect+=pisub[pos]
else:
pisect+=pisub[pos]
pos += 1
#for the remainder
numsect = int(pisect)
numsect *= 2
tau+=str(numsect)
with open(outfilename, 'a+') as fout:
fout.write(tau)
print 'Finished, %0.1f minutes elapsed' % ((time.time() - start)/60)
else:
print outfilename + 'already exists.'
print '\nScript finished.'
In [3]:
tauday_file = open('data/tau100K-tauday.com.txt', 'r')
tauday_string = tauday_file.read()
tauday_file.close()
this_file = open('data/tau100m.dectxt.000', 'r')
this_string = this_file.read()
this_file.close()
print len(tauday_string)
print tauday_string[:10]
print this_string[:10]
if tauday_string[:99999] == this_string[:99999]:
print "Verification successful. Yay."
In [8]:
filelist = ['data/tau100m.dectxt.001', 'data/tau100m.dectxt.002', 'data/tau100m.dectxt.003',
'data/tau100m.dectxt.004', 'data/tau100m.dectxt.005', 'data/tau100m.dectxt.006',
'data/tau100m.dectxt.007', 'data/tau100m.dectxt.008', 'data/tau100m.dectxt.009']
for filename in filelist:
current = open(filename, 'r')
string1K = current.read()[:1000]
current.close()
newfile = open(filename+'.1K', 'w+')
newfile.write(string1K)
newfile.close()
In [4]:
# verify that pi has a fibonacci sequence of 11235813 at position 48300973
this_file = open('data/pi100m.dectxt.000', 'r')
this_string = this_file.read()
this_file.close()
print this_string[48300973:48300993]
In [5]:
# verify that tau has a fibonacci sequence of 1123581321 at position 809073288
this_file = open('data/tau100m.dectxt.008', 'r')
this_string = this_file.read()
this_file.close()
print this_string[9073288:9073300]
In [6]:
# verify that tau recapitulates pi at position 52,567,169
this_file = open('data/tau100m.dectxt.000', 'r')
this_string = this_file.read()
this_file.close()
print this_string[52567169:52567189]
In [7]:
# verify that tau recapitulates tau at position 405747241
this_file = open('data/tau100m.dectxt.004', 'r')
this_string = this_file.read()
this_file.close()
print this_string[5747241:5747261]
In [ ]: