PI: 3.1415926535...

Calculate Pi with
Reciprocals of Squares


Slightly faster convergence to pi: Use the following formula:

PI from a series

This well-known series still converges slowly, but certainly faster than Gregory's series.


A better formula: Below I show how to use an experiment to derive a better formula based on this series, although this does not give a proof of the formula.

The coefficients in the numerators above (leaving off the first 1): 1, 1, 3, 17, 155, 2073, etc. are called Genocchi numbers (after an Italian mathematician). In some applications they have alternating signs, as is the case here.

The first 15 of these numbers are: 1, 1, 3, 17, 155, 2073, 38227, 929569, 28820619, 1109652905, 51943281731, 2905151042481, 191329672483963, 14655626154768697, 1291885088448017715, ... There are equations to generate these numbers.


Initial calculations: This time we will just work with the basic sum of alternating reciprocals of squares, which converges to pi2/12. We calculate the sum for N = 1000, 10000, 100000, 1000000, 10000000. The calculations were carried out to 100-digit accuracy, using Mathematica. Below we are using the same notation as before: Initial correct digits are in blue. Incorrect digits are given in red. Any corect digits after the first incorrect digit are shown in green.

Calculate Pi, slow convergence. 100-digit accuracy using Mathematica.
         2
Exact, pi /12:0.8224670334241132182362075833230125946094749506033992188677791146850037352016004369168144503098793527

N=1000:       0.822466533924112718237707574823090093572994063638629128622478632373389371470175218659987899857060146
N=10000:      0.822467028424613218231207583473012586109475725603295568886892610037160176231995610724030713707422893
N=100000:     0.822467033374113718236207533323012609609474942103399226617779104320003754315100390438364594412973798
N=1000000:    0.822467033423613218736207583322512594609476450603399210367779114762503735200563936916833563809878888
N=10000000:   0.822467033424108218236707583323012589609474950603549218867779106185003735202375436916814346659879353


Guessing the formula above (without proof): Once again, we look for a term that will correct a block of red digits. Focus on the entry above for N = 1000000.

Get the ninth term using N = 100000 in the calculation. (This value of N works for the other terms as well.)


Use the formula: Now let's try out the formula above as we did before: formula for Gregory's series:

Calculate Pi Using Genocchi Terms
// Genocchi: compute pi approximately
import java.text.DecimalFormat;
public class Genocchi {
   public static DecimalFormat d16 = new
                 DecimalFormat("0.0000000000000000");
   public static void main(String[] args) {
      double N = Integer.parseInt(args[0]);
      double sum = 0.0;      // final sum
      double term;           // each term, without sign
      double sign = 1.0;     // sign on each term
      for (int k = 1; k <= N; k++) {
         term = 1.0/k/k;
         sum += sign*term;
         sign = -sign;
      }
      // assuming that N is even
      // for odd N, reverse all signs below
      System.out.println("0: " + d16.format(sum));
      sum += 1.0/2/N/N;
      System.out.println("1: " + d16.format(sum));
      sum -= 1.0/2/N/N/N;
      System.out.println("2: " + d16.format(sum));
      sum += 1.0/2/N/N/N/N/N;
      System.out.println("3: " + d16.format(sum));
      sum -= 3.0/2/N/N/N/N/N/N/N;
      System.out.println("4: " + d16.format(sum));
      sum += 17.0/2/N/N/N/N/N/N/N/N/N;
      System.out.println("5: " + d16.format(sum));
      sum -= 155.0/2/N/N/N/N/N/N/N/N/N/N/N;
      System.out.println("6: " + d16.format(sum));
      sum += 2073.0/2/N/N/N/N/N/N/N/N/N/N/N/N/N;
      System.out.println("7: " + d16.format(sum));
      sum -= 38227.0/2/N/N/N/N/N/N/N/N/N/N/N/N/N/N/N;
      System.out.println("8: " + d16.format(sum));
      System.out.println("p: " +
         d16.format(Math.PI*Math.PI/12));
   }
}


Here are results of a run with different values of N in different columns. The exact value is pi2/12 = 0.8224670334241132. The labels 0 through 8 on the rows give the number of extra correction terms added in. The correct digits are in green. With N = 18, the full formula gives 15 significant digits of accuracy. With odd values for N, and with the signs in the program reversed, the results are consistent with those below.

N = 2N = 4N = 6N = 8N = 10
0
1
2
3
4
5
6
7
8
0.7500000000000000
0.8750000000000000
0.8125000000000000
0.8281250000000000
0.8164062500000000
0.8330078125000000
0.7951660156250000
0.9216918945312500
0.3383941650390625
0.7986111111111112
0.8298611111111112
0.8220486111111112
0.8225368923611112
0.8224453396267362
0.8224777645534940
0.8224592871136136
0.8224747321671910
0.8224569313331611
0.8108333333333334
0.8247222222222222
0.8224074074074075
0.8224717078189301
0.8224663494513031
0.8224671928980593
0.8224669792800083
0.8224670586402627
0.8224670179892410
0.8156164965986396
0.8234289965986396
0.8224524340986396
0.8224676928877020
0.8224669776319647
0.8224670409618998
0.8224670319397124
0.8224670338250949
0.8224670332818566
0.8179621756109852
0.8229621756109852
0.8224621756109852
0.8224671756109853
0.8224670256109853
0.8224670341109853
0.8224670333359854
0.8224670334396353
0.8224670334205219

N = 12 N = 14N = 16N = 18N = 20
0
1
2
3
4
5
6
7
8
0.8192821939764581
0.8227544161986803
0.8224650643468284
0.8224670737346885
0.8224670318724414
0.8224670335197983
0.8224670334154927
0.8224670334251802
0.8224670334239397
0.8200973129234452
0.8226483333316085
0.8224661175881682
0.8224670472603286
0.8224670330306527
0.8224670334420550
0.8224670334229172
0.8224670334242230
0.8224670334241001
0.8206355073678897
0.8225886323678897
0.8224665620553897
0.8224670388925479
0.8224670333046125
0.8224670334283037
0.8224670334238984
0.8224670334241285
0.8224670334241120
0.8210092952272601
0.8225525051038033
0.8224667712217731
0.8224670358325201
0.8224670333824207
0.8224670334252722
0.8224670334240662
0.8224670334241160
0.8224670334241131
0.8212793783297532
0.8225293783297531
0.8224668783297532
0.8224670345797532
0.8224670334078782
0.8224670334244798
0.8224670334241014
0.8224670334241141
0.8224670334241135