Peter Occil

Correctness and Performance Charts

The following charts show the correctness of many of the algorithms in “Bernoulli Factory Algorithms” and show their performance in terms of the number of bits they use on average. For each algorithm, and for each of 100 λ values evenly spaced from 0.0001 to 0.9999:

For each algorithm, if a single run was detected to use more than 5000 bits for a given λ, the entire data point for that λ was suppressed in the charts below.

In addition, for each algorithm, a chart appears showing the minimum number of input coin flips that any fast Bernoulli factory algorithm will need on average to simulate the given function, based on work by Mendo (2019)[^1]. Note that some functions require a growing number of coin flips as λ approaches 0 or 1. Note that for the 2014, 2016, and 2019 algorithms—

Points with invalid ϵ values were suppressed. For the low-mean algorithm, an m of max(0.49999, x_c_1.02) was used unless noted otherwise.

The Charts

Algorithm Simulated Mean Average Bits Consumed Coin Flips
(1-x)*tan(x) **Simulated Mean for (1-x)*tan(x)** **Expected Bits Consumed by (1-x)*tan(x)** **Coin Flips for the Function**
(1-x)/cos(x) **Simulated Mean for (1-x)/cos(x)** **Expected Bits Consumed by (1-x)/cos(x)** **Coin Flips for the Function**
(1/3)*x/(1+(1/3)*x) **Simulated Mean for (1/3)*x/(1+(1/3)*x)** **Expected Bits Consumed by (1/3)*x/(1+(1/3)*x)** **Coin Flips for the Function**
(2/3)*x/(1+(2/3)*x) **Simulated Mean for (2/3)*x/(1+(2/3)*x)** **Expected Bits Consumed by (2/3)*x/(1+(2/3)*x)** **Coin Flips for the Function**
(3/2)*x/(1+(3/2)*x) **Simulated Mean for (3/2)*x/(1+(3/2)*x)** **Expected Bits Consumed by (3/2)*x/(1+(3/2)*x)** **Coin Flips for the Function**
0.5*x/(1+0.5*x) **Simulated Mean for 0.5*x/(1+0.5*x)** **Expected Bits Consumed by 0.5*x/(1+0.5*x)** **Coin Flips for the Function**
1 - ln(1+x) (Alt. Series) **Simulated Mean for 1 - ln(1+x) (Alt. Series)** **Expected Bits Consumed by 1 - ln(1+x) (Alt. Series)** **Coin Flips for the Function**
1/(1+x) (Alt. Series) **Simulated Mean for 1/(1+x) (Alt. Series)** **Expected Bits Consumed by 1/(1+x) (Alt. Series)** **Coin Flips for the Function**
1/(1+x) (Even Parity) **Simulated Mean for 1/(1+x) (Even Parity)** **Expected Bits Consumed by 1/(1+x) (Even Parity)** **Coin Flips for the Function**
1/(1+x) (Two-Coin Special Case) **Simulated Mean for 1/(1+x) (Two-Coin Special Case)** **Expected Bits Consumed by 1/(1+x) (Two-Coin Special Case)** **Coin Flips for the Function**
1/(3+x) **Simulated Mean for 1/(3+x)** **Expected Bits Consumed by 1/(3+x)** **Coin Flips for the Function**
1/(5+x) **Simulated Mean for 1/(5+x)** **Expected Bits Consumed by 1/(5+x)** **Coin Flips for the Function**
2014 1.200000 eps=0.050000 **Simulated Mean for 2014 1.200000 eps=0.050000** **Expected Bits Consumed by 2014 1.200000 eps=0.050000** **Coin Flips for the Function**
2014 1.500000 eps=0.050000 **Simulated Mean for 2014 1.500000 eps=0.050000** **Expected Bits Consumed by 2014 1.500000 eps=0.050000** **Coin Flips for the Function**
2014 2.000000 eps=0.050000 **Simulated Mean for 2014 2.000000 eps=0.050000** **Expected Bits Consumed by 2014 2.000000 eps=0.050000** **Coin Flips for the Function**
2014 3.000000 eps=0.050000 **Simulated Mean for 2014 3.000000 eps=0.050000** **Expected Bits Consumed by 2014 3.000000 eps=0.050000** **Coin Flips for the Function**
2014 5.000000 eps=0.050000 **Simulated Mean for 2014 5.000000 eps=0.050000** **Expected Bits Consumed by 2014 5.000000 eps=0.050000** **Coin Flips for the Function**
2014 Add. x+0.1 **Simulated Mean for 2014 Add. x+0.1** **Expected Bits Consumed by 2014 Add. x+0.1** **Coin Flips for the Function**
2014 Add. x+0.2 **Simulated Mean for 2014 Add. x+0.2** **Expected Bits Consumed by 2014 Add. x+0.2** **Coin Flips for the Function**
2014 Add. x+0.3 **Simulated Mean for 2014 Add. x+0.3** **Expected Bits Consumed by 2014 Add. x+0.3** **Coin Flips for the Function**
2014 Add. x+0.5 **Simulated Mean for 2014 Add. x+0.5** **Expected Bits Consumed by 2014 Add. x+0.5** **Coin Flips for the Function**
2014 Lin. x*1.3 **Simulated Mean for 2014 Lin. x*1.3** **Expected Bits Consumed by 2014 Lin. x*1.3** **Coin Flips for the Function**
2014 Lin. x*1.5 **Simulated Mean for 2014 Lin. x*1.5** **Expected Bits Consumed by 2014 Lin. x*1.5** **Coin Flips for the Function**
2014 Lin. x*2.0 **Simulated Mean for 2014 Lin. x*2.0** **Expected Bits Consumed by 2014 Lin. x*2.0** **Coin Flips for the Function**
2014 Lin. x*4.0 **Simulated Mean for 2014 Lin. x*4.0** **Expected Bits Consumed by 2014 Lin. x*4.0** **Coin Flips for the Function**
2014 Lin. x*6.0 **Simulated Mean for 2014 Lin. x*6.0** **Expected Bits Consumed by 2014 Lin. x*6.0** **Coin Flips for the Function**
2014 Lin. x*8.0 **Simulated Mean for 2014 Lin. x*8.0** **Expected Bits Consumed by 2014 Lin. x*8.0** **Coin Flips for the Function**
2016 1.200000 eps=0.050000 **Simulated Mean for 2016 1.200000 eps=0.050000** **Expected Bits Consumed by 2016 1.200000 eps=0.050000** **Coin Flips for the Function**
2016 1.500000 eps=0.050000 **Simulated Mean for 2016 1.500000 eps=0.050000** **Expected Bits Consumed by 2016 1.500000 eps=0.050000** **Coin Flips for the Function**
2016 2.000000 eps=0.050000 **Simulated Mean for 2016 2.000000 eps=0.050000** **Expected Bits Consumed by 2016 2.000000 eps=0.050000** **Coin Flips for the Function**
2016 3.000000 eps=0.050000 **Simulated Mean for 2016 3.000000 eps=0.050000** **Expected Bits Consumed by 2016 3.000000 eps=0.050000** **Coin Flips for the Function**
2016 5.000000 eps=0.050000 **Simulated Mean for 2016 5.000000 eps=0.050000** **Expected Bits Consumed by 2016 5.000000 eps=0.050000** **Coin Flips for the Function**
2019 1.200000 eps=0.050000 **Simulated Mean for 2019 1.200000 eps=0.050000** **Expected Bits Consumed by 2019 1.200000 eps=0.050000** **Coin Flips for the Function**
2019 1.500000 eps=0.050000 **Simulated Mean for 2019 1.500000 eps=0.050000** **Expected Bits Consumed by 2019 1.500000 eps=0.050000** **Coin Flips for the Function**
2019 2.000000 eps=0.050000 **Simulated Mean for 2019 2.000000 eps=0.050000** **Expected Bits Consumed by 2019 2.000000 eps=0.050000** **Coin Flips for the Function**
2019 3.000000 eps=0.050000 **Simulated Mean for 2019 3.000000 eps=0.050000** **Expected Bits Consumed by 2019 3.000000 eps=0.050000** **Coin Flips for the Function**
2019 5.000000 eps=0.050000 **Simulated Mean for 2019 5.000000 eps=0.050000** **Expected Bits Consumed by 2019 5.000000 eps=0.050000** **Coin Flips for the Function**
Bernstein 0.2,0.6,0.3 **Simulated Mean for Bernstein 0.2,0.6,0.3** **Expected Bits Consumed by Bernstein 0.2,0.6,0.3** **Coin Flips for the Function**
arcsin(x)+sqrt(1-x*x)-1 **Simulated Mean for arcsin(x)+sqrt(1-x*x)-1** **Expected Bits Consumed by arcsin(x)+sqrt(1-x*x)-1** **Coin Flips for the Function**
arcsin(x)/2 **Simulated Mean for arcsin(x)/2** **Expected Bits Consumed by arcsin(x)/2** **Coin Flips for the Function**
arctan(x) (Flajolet) **Simulated Mean for arctan(x) (Flajolet)** **Expected Bits Consumed by arctan(x) (Flajolet)** **Coin Flips for the Function**
arctan(x) (Two-Coin Special Case) **Simulated Mean for arctan(x) (Two-Coin Special Case)** **Expected Bits Consumed by arctan(x) (Two-Coin Special Case)** **Coin Flips for the Function**
cos(x) **Simulated Mean for cos(x)** **Expected Bits Consumed by cos(x)** **Coin Flips for the Function**
exp(-x) (Alg. 2) **Simulated Mean for exp(-x) (Alg. 2)** **Expected Bits Consumed by exp(-x) (Alg. 2)** **Coin Flips for the Function**
exp(-x) (Alt. Series) **Simulated Mean for exp(-x) (Alt. Series)** **Expected Bits Consumed by exp(-x) (Alt. Series)** **Coin Flips for the Function**
exp(-x) (Flajolet) **Simulated Mean for exp(-x) (Flajolet)** **Expected Bits Consumed by exp(-x) (Flajolet)** **Coin Flips for the Function**
exp(x)*(1-x) **Simulated Mean for exp(x)*(1-x)** **Expected Bits Consumed by exp(x)*(1-x)** **Coin Flips for the Function**
ln(1+x) (Flajolet) **Simulated Mean for ln(1+x) (Flajolet)** **Expected Bits Consumed by ln(1+x) (Flajolet)** **Coin Flips for the Function**
ln(1+x) (Two-Coin Special Case) **Simulated Mean for ln(1+x) (Two-Coin Special Case)** **Expected Bits Consumed by ln(1+x) (Two-Coin Special Case)** **Coin Flips for the Function**
pow(x,1/3) **Simulated Mean for pow(x,1/3)** **Expected Bits Consumed by pow(x,1/3)** **Coin Flips for the Function**
pow(x,2/1) **Simulated Mean for pow(x,2/1)** **Expected Bits Consumed by pow(x,2/1)** **Coin Flips for the Function**
pow(x,2/4) **Simulated Mean for pow(x,2/4)** **Expected Bits Consumed by pow(x,2/4)** **Coin Flips for the Function**
pow(x,3/4) **Simulated Mean for pow(x,3/4)** **Expected Bits Consumed by pow(x,3/4)** **Coin Flips for the Function**
pow(x,4/5) **Simulated Mean for pow(x,4/5)** **Expected Bits Consumed by pow(x,4/5)** **Coin Flips for the Function**
pow(x,5/1) **Simulated Mean for pow(x,5/1)** **Expected Bits Consumed by pow(x,5/1)** **Coin Flips for the Function**
pow(x,5/4) **Simulated Mean for pow(x,5/4)** **Expected Bits Consumed by pow(x,5/4)** **Coin Flips for the Function**
sin(x) **Simulated Mean for sin(x)** **Expected Bits Consumed by sin(x)** **Coin Flips for the Function**
sqrt(x) **Simulated Mean for sqrt(x)** **Expected Bits Consumed by sqrt(x)** **Coin Flips for the Function**