Euler' s number (e), approximately equal to 2.71828, is a fundamental mathematical constant that appears in various fields, from calculus to physics and beyond. While it' s common to find examples of estimating π using probability, estimating e probabilistically is less frequently discussed . In this blog post, we' ll explore a fascinating algorithm that leverages the properties of the exponential distribution to estimate e using random numbers.

The Exponential Distribution and e

The exponential distribution is a continuous probability distribution that models the time between events in a Poisson process. One intriguing property of the exponential distribution is that the probability of generating a random number greater than the previous one is always 1/e, regardless of the value of the previous number. This property forms the basis of our algorithm.

The Algorithm

Here' s a step - by - step breakdown of the algorithm :
1
.
Generate a large number (n) of random real numbers between 0 and 1.
2
.
For each random number :
2
.
1
.
Initialize a counter variable (count) to 1.
2
.
2
.
Generate another random real number between 0 and 1.
2
.
3
.
If the new random number is less than the previous one, increment the counter by 1 and repeat step 2.2
3
.
If the new random number is greater than or equal to the previous one, stop and record the final value of the counter.
4
.
Calculate the average (m) of all the final counter values. The estimate of e is equal to m.

Intuition Behind the Algorithm

The algorithm relies on the idea that the number of random numbers generated until a larger number is encountered follows a geometric distribution with a success probability of 1/e. By counting these numbers and averaging them, we obtain an estimate of the expected value of the geometric distribution, which is e.  

Implementing the Algorithm in Mathematica

Here' s the Mathematica code that implements the algorithm. The code generates n random numbers, counts the number of random numbers until a larger number is encountered for each starting number, and calculates the average of the counts.
In[]:=
estimateE[n_]:=Module[{count,randomList,m},randomList=RandomReal[{0,1},n];​​count=Table[Module[{prev=randomList[[i]],curr,c=1},While[curr=RandomReal[];​​curr<prev,prev=curr;​​c++];​​c],{i,1,n}];​​m=Mean[count]//N;​​1+m]
The code can be speeded up by compilation (in a way that allows for parallelization) :
compiledEstimateE=Compile[{{n,_Integer}},Module[{count=0.,total=0.},Do[Module[{prev=RandomReal[],curr=0.,c=1},While[curr=RandomReal[];​​curr>prev,prev=curr;​​c++;];​​count+=c;],{n}];​​total=count/n;​​1.+total],CompilationTarget->"C",RuntimeAttributes->{Listable},Parallelization->True,RuntimeOptions->"Speed"];​​​​estimateE[n_Integer]:=compiledEstimateE[n]

Convergence and Accuracy

The accuracy of the estimate improves as the number of random numbers (n) increases. Here' s a table showing how the estimate converges to e as n grows. As we can see, the estimate gets closer to the true value of e (2.71828...) as n increases:
In[]:=
estE=Association[Table[<|i->compiledEstimateE[10^i]|>,{i,4,8}]];
In[]:=
Dataset[estE]
Out[]=
4
2.7279
5
2.71549
6
2.71961
7
2.71849
8
2.71831
In[]:=
ListPlot[estE,AxesLabel->{"10^","Estimate"}]
Out[]=

Comparison with Other Methods

While the probabilistic method provides an interesting approach to estimating e, there are other well - known methods, such as using the limit definition or the Taylor series expansion. These methods often provide faster convergence and higher accuracy. However, the probabilistic method offers a unique perspective and showcases the connection between e and probability theory.

Conclusion

Estimating Euler' s number (e) using probability is a fascinating application of the exponential distribution. By generating random numbers and counting the number of samples until a larger number is encountered, we can obtain an estimate of e. This method, while not as efficient as some other approaches, provides an intuitive understanding of the relationship between e and probability. It' s a testament to the beauty and interconnectedness of mathematics, where seemingly unrelated concepts can be brought together to solve problems in elegant ways.

CITE THIS NOTEBOOK

Estimating Euler's number (e) using probability: a fascinating approach​
by Jonathan Kinlay​
Wolfram Community, STAFF PICKS, March 14, 2024
​https://community.wolfram.com/groups/-/m/t/3140700