Tau Day MMXVII

Today it is June the 28th which means that it is \tau day!
The irrational and transcendental constant \tau is what defines \pi = \frac{\tau}{2}, which obviously makes it an important constant. To celebrate this day, I created a C program which calculates \tau by randomly creating 9-dimensional points inside the 9-dimensional hypercube and testing if they are inside the 9-dimensional hypersphere with its center located at (0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5).

Today’s \tau time is 3:18:53 as \tau = 6.2831853 \dots. As one does not know if the time is specified as ante or post meridiem, there are actually two perfectly acceptable \tau times.

            ;b$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$b
        h$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
     .$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+ 
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  
  ,$$$$$$$$$kn}~I"`($$$$$$$x````````````````   
 )$$$m             $$$$$$$$                    
+$$c              q$$$$$$$>                    
$$                $$$$$$$$                     
                 $$$$$$$$.                     
                '$$$$$$$$                      
                $$$$$$$$                       
               ?$$$$$$$a                       
               $$$$$$$$                        
              Q$$$$$$$f                        
              $$$$$$$$                         
             $$$$$$$$i                         
             $$$$$$$$                          
            $$$$$$$$;                          
            $$$$$$$$                           
           J$$$$$$$w                           
           $$$$$$$$;             $$~           
           $$$$$$$$             $$$            
          '$$$$$$$$C          "$$$             
           $$$$$$$$$w       '$$$$              
           $$$$$$$$$$$$$$$$$$$$B               
            $$$$$$$$$$$$$$$$$$.                
             $$$$$$$$$$$$$$$'                  
                8$$$$$$$q                      

The formula used for calculating \tau is derived from a 9-dimensional hypersphere’s hypervolume formula V = \frac{32 \cdot \pi^4}{945} \cdot R^9 (see this Wikipedia article).
V = \frac{2^5 \cdot \tau^4 \cdot R^9}{945 \cdot 2^4} = \frac{2 \cdot R^9}{945} \cdot \tau^4
\tau^4 = \frac{V \cdot 945}{2 \cdot R^9}; R = 0.5
\tau^4 = \frac{V \cdot 945 \cdot 2^9}{2}
\tau = \sqrt[4]{V \cdot 241920}

The constant gets calculated to \tau^* = 6.293700. The real value is approximately \tau = 6.283185 \dots, which makes the percent error \left|\frac{\tau^*-\tau}{\tau}\right| = \left|\frac{6.293700-6.283185}{6.283185}\right| = 0.001673514 = 0.167\%.
Thereby this C program’s approximation is not too far off. The source code is listed below and can also be downloaded here. Instructions on how to compile it using GCC can be seen below or in the source code.

gcc tau.c -o tau -lm; ./tau
tau = 6.293700

Resources worth checking out regarding \tau are The Tau Manifesto and 2 Pi or Not 2 Pi?. I wish everybody a happy \tau day.


// C Code
// Jonathan Frech, 27th of June 2017


// === COMPILATION AND EXECUTION ===
// gcc tau.c -o tau -lm; ./tau
// tau = 6.293700

// This program creates random 9-dimensional
// points inside the unit 9-dimensional hyper-
// cube and tests, if they are in the hyper-
// sphere with radius .5. From this information
// it calculates the constant tau.
// Happy tau day to everyone!

// inclusion
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>

// number of iterations
#define ITR 1e8

// generate random number in the intervall [0, 1]
double rnd() { return (double) rand()/RAND_MAX; }

// main funtion
int main() {
	// seed random number generator
	srand(time(NULL));
	
	// number of points in hypersphere, outer part of the hypercube
	long sph = 0, cub = 0;
	
	// look at randomly generated 9-dimensional points
	for (int i = 0; i < ITR; i++) {
		// generate random 9-dimensional point
		double vec[9] = {rnd(), rnd(), rnd(), rnd(), rnd(), rnd(), rnd(), rnd(), rnd()};
		
		// point's distance to (.5, .5, .5, .5, .5, .5, .5, .5, .5)
		double dst = sqrt((vec[0]*vec[0]+vec[1]*vec[1]+vec[2]*vec[2]+vec[3]*vec[3]+vec[4]*vec[4]+vec[5]*vec[5]+vec[6]*vec[6]+vec[7]*vec[7]+vec[8]*vec[8])/4.);	
		
		// determine if point is inside hypersphere
		if   (dst <= .5) { sph++; }
		else             { cub++; }
	}
	
	// calculate hypersphere's volume
	double vol = (double) sph/cub;
	
	// calculate tau
	double tau = pow(241920*vol, .25);
	
	// output result
	printf("tau = %f\n", tau);
}
Advertisements

Leave a Reply

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