4
Monte Carlo estimations of e Pirooz Mohazzabi Citation: Am. J. Phys. 66, 138 (1998); doi: 10.1119/1.18831 View online: http://dx.doi.org/10.1119/1.18831 View Table of Contents: http://ajp.aapt.org/resource/1/AJPIAS/v66/i2 Published by the American Association of Physics Teachers Additional information on Am. J. Phys. Journal Homepage: http://ajp.aapt.org/ Journal Information: http://ajp.aapt.org/about/about_the_journal Top downloads: http://ajp.aapt.org/most_downloaded Information for Authors: http://ajp.dickinson.edu/Contributors/contGenInfo.html Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

Monte Carlo Estimation of e

Embed Size (px)

DESCRIPTION

An interesting article on the estimation of e using Monte Carlo techniques.

Citation preview

Page 1: Monte Carlo Estimation of e

Monte Carlo estimations of ePirooz Mohazzabi Citation: Am. J. Phys. 66, 138 (1998); doi: 10.1119/1.18831 View online: http://dx.doi.org/10.1119/1.18831 View Table of Contents: http://ajp.aapt.org/resource/1/AJPIAS/v66/i2 Published by the American Association of Physics Teachers Additional information on Am. J. Phys.Journal Homepage: http://ajp.aapt.org/ Journal Information: http://ajp.aapt.org/about/about_the_journal Top downloads: http://ajp.aapt.org/most_downloaded Information for Authors: http://ajp.dickinson.edu/Contributors/contGenInfo.html

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT license or copyright; see http://ajp.aapt.org/authors/copyright_permission

Page 2: Monte Carlo Estimation of e

Monte Carlo estimations of ePirooz MohazzabiDepartment of Physics, University of Wisconsin-Parkside, Kenosha, Wisconsin 53141

~Received 4 April 1997; accepted 2 July 1997!

Three physical processes and the corresponding Monte Carlo algorithms are outlined, in which thenumbere, the base of the natural logarithm, can be obtained. The value ofe is estimated in eachcase, and the three algorithms are compared. ©1998 American Association of Physics Teachers.

otho

of

ins

c

eedin

oI

thoteeof

h-

r,

inre

nnehe

u

e

t,

no

-

andotal

eis

is

-

off

ard

I. INTRODUCTION

The nameMonte Carlowas for the first time applied to aclass of mathematical techniques by scientists workingthe development of nuclear weapons in Los Alamos in1940s.1 The method consists of applications of deviceschance to randomly generate and sample the outcomesexperiment. One of the oldest documented applicationsthis technique, suggested by Comte de Buffon2 in 1777 andnow known as Buffon’s needle problem, can be foundmany textbooks on probability.3–5 The experiment proceedas follows. A needle of lengthl is thrown randomly onto ahorizontal plane ruled with straight parallel lines a distand(d. l ) apart. Buffon showed that the probability,p, of aneedle intersecting a line is given by

p52l

pd. ~1!

He also carried out the actual needle experiment. Some ylater, Laplace suggested that this technique should be usevaluatep.6 More historical background can be foundRefs. 1 and 5.

Another simple Monte Carlo method for the estimationp is as follows.1 Consider a square and its inscribed circle.we place a large number of points randomly insidesquare, some will fall within the circle and some do nSince the ratio of the area of the circle to that of the squarp/4, four times the ratio of the points that fall inside thcircle to the total number of points will give an estimatep.

Another naturally occurring irrational number in matematics that is perhaps as interesting asp, is the base of thenatural logarithm,e. Monte Carlo estimation of this numbehowever, has not received much attention, even thoughe hasbeen used in the theory of probability for a long time.7 Itseemed intriguing therefore to find algorithms for estimate using Monte Carlo simulations. Outlined in this article athree Monte Carlo algorithms for the estimation ofe, alongwith actual values obtained through computer simulatioThe three algorithms are then compared for reliability ademand on computer resources. It is believed that these tniques will be of interest to students as well as some teacof mathematics and physics.

II. THE DERANGEMENT METHOD

Consider a permutation ofN objects$1,2,...,N%, in whichevery member has ‘‘moved’’~i.e., no object is left in itsoriginal place!. In other words, we are considering a permtation that has no fixed point,P ( i )Þ i . Such a permutation is

138 Am. J. Phys.66 ~2!, February 1998

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT lic

nefan

of

e

arsto

ffe.is

g

s.dch-rs

-

called aderangementof the objects. It can be shown that thnumber of derangements ofN objects is given by8,9

Nd5N! F 1

2!2

1

3!1

1

4!2•••1~21!N

1

N! G . ~2!

Also known as thehat-checkproblem, the derangemenproblem has many interesting applications. For exampleNpeople check inN different objects~hats!. Later, the objectsare returned to them randomly. The number of ways thatone ends up getting the right object isNd .

The expression in the square brackets in Eq.~2! is a partialsum of the series fore21, and it can be shown that it iswithin 1/(N11)! of e21.9 Since the total number of permutations isN!, therefore, for reasonably largeN, the probabil-ity of finding a derangement ise21. Apparently, this is thefirst time thate has appeared in the theory of probability.10

One can obtain an approximation fore in the followingway: A reasonably large number of objects,N, are chosen.The objects are then shuffled a large number of times,each time the result is checked for derangement. The tnumber of derangements,Nd , is recorded. The ratioN/Nd

gives an estimate ofe.

III. THE DART METHOD

Suppose that we randomly throwN darts at a dart boardthat has been divided intoR equal size regions. In any onthrow, the probability that the dart strikes a given regionclearly p51/R. Being Bernoulli trials, the probability offinding n darts in a given region at the end of the processgiven by the binomial distribution,11

P~n!5CnNpnqN2n, ~3!

whereq512p, andCnN are the binomial coefficients. There

fore, the probability of finding an empty region is

P~0!5qN5~12p!N. ~4!

If we can somehow makep equal to 1/N, then this equationwill reduce to

P~0!5S 121

ND N

, ~5!

which, for large enoughN, estimatese21. To this end, wenote that for the binomial distribution the mean value ofn isgiven by ^n&5Np. We can make the average occupancythe regions, n&, equal to unity by choosing the number odarts equal to the number of regions on the dart bo(N5R). With this condition,Np51, and Eq.~5! will betrue.

138© 1998 American Association of Physics Teachers

ense or copyright; see http://ajp.aapt.org/authors/copyright_permission

Page 3: Monte Carlo Estimation of e

aytoth

e

ns

r

l

th

ong

sa

-foalth

we

lyde-

a

edetoly

sti--ro-reher-

lut

weenach

re

per-r of

ia-eri-

-the

Another version of the above situation is theraisin-bunproblem:11 N raisin buns of equal size are baked frombatch of dough into whichN raisins have been carefullmixed. Although the number of raisins varies from bunbun, the average number of raisins per bun is 1. Thenprobability that any given bun will contain no raisin will bgiven by Eq.~5!.

We also note that forp!1 andN@1, the binomial distri-bution is approximated by the Poisson distribution,11,12

P~n!5^n&n

n!e2^n&. ~6!

With the number of darts equal to the number of regio^n&51, the Poisson distribution reduces to

P~n!5e21

n!, ~7!

which givesP(0)5P(1)5e21.With the above algorithm, an estimate fore can be ob-

tained in the following way: A large number of darts,N, arethrown randomly at a board that has been divided intoNequal size regions~we assume that all darts land somewheon the board!. Either the number of empty cells,N0 , or thenumber of cells with occupancy of one dart,N1 , is recorded.The ratioN/N0 or N/N1 gives an estimate ofe.

IV. THE SALT-SHAKER METHOD

Consider a horizontal sheet of paper of areaA, containinga small hole of areaa. A given amount of salt~or sand!,containingN particles, is shaken onto the paper random~assuming all particles land somewhere on the paper!. Eachsalt particle has a probabilityp5a/A of going through thehole. Therefore, the number of particles remaining onpaper at the end of the process would be

N15~12p!N. ~8!

These particles are then collected, and randomly shakenthe paper again. The number of salt particles that will notthrough the hole in the second trial would be

N25~12p!N15~12p!2N. ~9!

After the third trial the result would beN35(12p)3N, andso on. Continuing this process, the number of remainingparticles on the paper aftern iterations would be

Nn5~12p!nN, ~10!

or, equivalently,

Nn

N5~12p!n. ~11!

Now, if we choose the number of iterations to ben51/p5A/a, then we can write Eq.~11! as

Nn

N5S 12

1

nD n

, ~12!

which approachese21 as n→`. Therefore, in such an experiment with a large number of iterations, an estimatione can be obtained. Note that it is not necessary to actucount the number of salt particles in an experiment. Since

139 Am. J. Phys., Vol. 66, No. 2, February 1998

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT lic

e

,

e

y

e

too

lt

rlye

number of particles is proportional to the mass of the salt,have

Nn

N5

mn

m, ~13!

wherem is the initial mass of the salt, andmn is that of theremaining salt aftern iterations.

One might think thate could be estimated experimentalfrom another closely related problem, that of the nuclearcay, in which the fraction of remaining unstable nuclei asfunction of time is given by13

N

N05e2lt, ~14!

wherel is the probability of decay per unit time~known asthe decay constant!. This process, however, cannot be usto estimate the value ofe, because one must first know thvalue of l for the nuclei under consideration. In orderdeterminel, however, a natural logarithm, which is closerelated toe, must be used, leading to a cyclic argument.

V. COMPUTER SIMULATIONS

The three algorithms described above were used to emate the value ofe by Monte Carlo simulations. All computations were performed on an Intel Pentium 150-MHz pcessor, usingFORTRAN 77 source codes. The results ashown in Table I, along with the total CPU time for eacsimulation for comparison. The estimate of the probableror in each case is the standard deviation of the mean,sm

5s/AN, wheres is the standard deviation of the individuaestimates.14,15 In each case, the numerical values of the inpparameters are chosen so that a balance is obtained betaccuracy of the results and the CPU time. The details of esimulation are given below.

A. The derangement method

With N510, the reciprocal of the expression in the squabrackets of Eq.~2! reproducese to six decimal places.Therefore, an ordered array of 10 numbers,x( i )5 i , i51,2,3,...,10, is chosen. The array is then shuffled 105 times,using a random number generator. After each step, themutation is checked for derangement. The total numbederangements found,Nd , is recorded. An estimate fore isobtained byN/Nd . An average value and a standard devtion for these estimates are obtained by repeating the expment 103 times.

B. The dart method

In the simulation, a dart board is divided into 105 equalsize regions~or cells!. A dart is thrown randomly at the

Table I. Monte Carlo estimations ofe52.718 281... by three different methods and their estimates of the probable error. The total CPU time ofprogram in each case is also given for comparison.

Method ^e&6sm CPU time~s!

Derangement 2.718160.0004 1 969Dart 2.718260.0002 186Salt shaker 2.718360.0010 32 896

139Pirooz Mohazzabi

ense or copyright; see http://ajp.aapt.org/authors/copyright_permission

Page 4: Monte Carlo Estimation of e

tin

s

n

ohasf

iled

n

then

es

stdhs

thtott

-tey

dho

rs,,theren-

hm,bedes,

ent

of

od,of

ul-

tion

trateands

aith

,

,

board, and the cell where it hits is determined by generaan integer random number in the range of 1 to 105. Clearly,the probability of the dart striking any given cell is 1025. Atotal of N5105 darts are thrown~to establish n&51!. At theend of the process, the number of the empty cells,N0 , iscounted. The ratioN/N0 is an estimate ofe. Again, an av-erage value and a standard deviation for these estimateobtained by repeating the experiment 103 times.

The rationale for usingN5105 in this simulation is thatwith this number, Eq.~5! reproducese to better than 1.3631025 ~or an accuracy of about 0.0005%!.

C. The salt-shaker method

The experiment is simulated starting with 53104 salt par-ticles. Note that assuming cubic salt particles, 0.5 mm oside, this corresponds to only 6.25 cm3 of salt. The salt isshaken randomly onto a large piece of horizontal paper, ctaining a small hole. The ratio of the area of the hole to tof the entire paper is 1024. We assume that all salt particleland somewhere on the paper. Each particle is checkedgoing through the hole, as its probability is simply 1024. Thenumber of particles that do not go through the hole,N1 , isdetermined, and the simulation is repeated beginning wthis number. After the second trial, the number of particthat do not go through the hole,N2 , is again determined, anso on. This process is iterated 104 times (n5104), and thefinal number of salt particles that have survived,Nn , is de-termined. The ratioN/Nn is an estimate fore. The entireexperiment is repeated 100 times, and an average value astandard deviation for the estimates ofe are obtained.

The rationale for usingn5104 iterations is that with thisnumber, Eq.~12! approximatese to better than 1.3631024

~or an accuracy of about 0.005%!. Higher iterations call forunreasonably extensive computer resources.

VI. COMPARISON OF ALGORITHMS

Comparing the values in Table I, we see that amongthree algorithms, the dart method is by far the most efficialgorithm, in terms of both reliability~judged by standarddeviation of the mean! and demand on computer resourc~judged by the CPU time!. The least efficient algorithm, onthe other hand, is the salt-shaker algorithm, with an emated error of about five times that of the dart method, anCPU time of about 177 times higher. The reason for suctremendously high difference among the three algorithmas follows.

The dart method involves only one parameter, i.e.,number of darts,N, which needs to be chosen very largeguarantee a reasonable estimate ofe. The derangemenmethod, on the other hand, involves two parameters, i.e.,number of objects in the array,N, and the number of permutations or shufflings. The former needs to be only moderalarge ~ten in our simulation!, but the latter has to be verlarge to ensure sufficient convergence. This causes therangement method to be less efficient than the dart met

140 Am. J. Phys., Vol. 66, No. 2, February 1998

Downloaded 20 Apr 2013 to 160.129.112.129. Redistribution subject to AAPT lic

g

are

a

n-t

or

ths

d a

et

i-aais

e

he

ly

e-d.

Finally, the salt-shaker algorithm involves two parametei.e., the number of particles,N, and the number of iterationsn, both of which have to be very large. This causescomputations to be exceedingly slow and, consequently,ders the algorithm very inefficient.

VII. CONCLUSION

In conclusion we see that the base of the natural logarite, can be estimated by Monte Carlo simulations as describy the three algorithms in this article. There are differenchowever, between simulations ofe and p, arising mainlyfrom the fact that these numbers emerge from two differmathematical contexts;p being of geometric origin, whileeis of analytic origin and is closely related to the conceptlimit. Consequently, unlike simulations ofp, simulations ofe involve a limiting process. Thus, in the salt-shaker methfor example, the simulation estimates the right-hand sideEq. ~12! ~which, in this case, can also be calculated by mtiplication!, rather thane itself. As a result of these differ-ences, the above simulational algorithms for the estimaof e are not as appealing as those for the estimation ofp.Nevertheless, these simulations are presented to demonsa connection between mathematics and physical reality,not to claim invention of elegant Monte Carlo algorithmcomparable to, for example, Buffon’s needle problem.

ACKNOWLEDGMENT

I would like to thank Professor Thomas A. Fournelle fordiscussion of the derangement method, and for sharing wme his estimation ofe usingMATHEMATICA .

1M. H. Kalos and P. A. Whitlock,Monte Carlo Methods~Wiley, NewYork, 1986!, Vol. 1, pp. 1–5.

2G. Comte de Buffon, ‘‘Essai d’arithme´tique morale,’’ in Supplement al’Histoire Naturelle ~de L’Imprimerie Royale, Paris, 1777!, Vol. 4.

3W. Feller, An Introduction to Probability Theory and Its Applications~Wiley, New York, 1971!, Vol. II, 2nd ed., pp. 61–62.

4B. V. Gnedenko,The Theory of Probability,translated from the Russianby B. D. Seckler~Chelsea, New York, 1962!, pp. 41–43.

5J. V. Uspensky,Introduction to Mathematical Probability~McGraw-Hill,New York, 1937!, pp. 112–115, 251–255.

6Marquis Pierre-Simon de Laplace, ‘‘Theorie Analytique des Probabilite´s,’’in Oeuvres Comple´tes de Laplace~de L’Academie des Sciences, Paris1886!, Vol. 7, Part 2, pp. 365–366.

7P. R. de Montmort,Essay d’analyse sur les jeux de hazard~Quillau, Paris,1708!.

8V. Bryant,Aspects of Combinatorics~Cambridge U.P., Cambridge, 1993!,p. 47.

9K. H. Rosen,Discrete Mathematics and Its Applications~Random House,New York, 1988!, pp. 269–272.

10F. N. David,Games, Gods and Gambling~Griffin, London, 1962!, p. 146.11Y. A. Rozanov,Probability Theory: A Concise Course, translated and

edited by R. A. Silverman~Dover, New York, 1969!, revised ed., pp.54–58.

12H. Gould and J. Tobochnik,An Introduction to Computer SimulationMethods~Addison-Wesley, New York, 1996!, 2nd ed., p. 191.

13F. J. Blatt,Modern Physics~McGraw-Hill, New York, 1992!, p. 354.14Reference 12, pp. 370–371.15P. R. Bevington and D. K. Robinson,Data Reduction and Error Analysis

for the Physical Sciences~McGraw-Hill, New York, 1992!, 2nd ed., pp.55–56.

140Pirooz Mohazzabi

ense or copyright; see http://ajp.aapt.org/authors/copyright_permission