## Monday, June 09, 2008

### Apéry's constant using monte Carlo methods

Apéry's Constant (1.20205690315...) "arises naturally in a number of physical problems, including in the second- and third-order terms of the electron's gyromagnetic ratio using quantum electrodynamics."

I described how to use monte carlo methods to estimate mathematical constants here and here. A passion for mathematics select three positive integers at random the odds of them having no common divisor are 1 in 1.202056....

So her is a ruby program that does not work for calculating this
`def findCD(num1, num2, num3, cd) if num1 % cd==0 && num2 % cd==0  && num3 % cd==0 return cd elsif cd < ([num1,num2,num3].max)/2 findCD(num1, num2, num3, cd+1) else return 0 endendi=1 factor =0N=1000while (i < N) x=rand(1000) y=rand(1000) z=rand(1000) ans=findCD(x,y,z,2) if ans >0 factor=factor+1 endendans=(factor).quo(N)puts "Apéry's Constant estimated as #{ans}" ; `

The first problem is that my find common divisor algorithm is idiotic. There are all sorts of clever ways of doing this.

The second one is that computers have trouble creating random integers. The integers go up forever but a computers numbers don't. How do you ask a computer to give you one of any infinite one of the integers? rand(1,000,000) will not do it.