\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9553607702255249:\\
\;\;\;\;\frac{-\log \left(1 - u0\right)}{\frac{\sqrt{cos2phi}}{\frac{alphax}{\frac{\sqrt{cos2phi}}{alphax}}} + \frac{sin2phi}{alphay \cdot alphay}}\\
\mathbf{else}:\\
\;\;\;\;\frac{u0 - \left({u0}^{4} \cdot -0.25 - \left(u0 \cdot u0\right) \cdot \left(0.5 + u0 \cdot 0.3333333333333333\right)\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}\\
\end{array}(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
(FPCore (alphax alphay u0 cos2phi sin2phi)
:precision binary32
(if (<= (- 1.0 u0) 0.9553607702255249)
(/
(- (log (- 1.0 u0)))
(+
(/ (sqrt cos2phi) (/ alphax (/ (sqrt cos2phi) alphax)))
(/ sin2phi (* alphay alphay))))
(/
(-
u0
(-
(* (pow u0 4.0) -0.25)
(* (* u0 u0) (+ 0.5 (* u0 0.3333333333333333)))))
(+ (/ cos2phi (* alphax alphax)) (/ (/ sin2phi alphay) alphay)))))float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return -logf(1.0f - u0) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
float tmp;
if ((1.0f - u0) <= 0.9553607702255249f) {
tmp = -logf(1.0f - u0) / ((sqrtf(cos2phi) / (alphax / (sqrtf(cos2phi) / alphax))) + (sin2phi / (alphay * alphay)));
} else {
tmp = (u0 - ((powf(u0, 4.0f) * -0.25f) - ((u0 * u0) * (0.5f + (u0 * 0.3333333333333333f))))) / ((cos2phi / (alphax * alphax)) + ((sin2phi / alphay) / alphay));
}
return tmp;
}



Bits error versus alphax



Bits error versus alphay



Bits error versus u0



Bits error versus cos2phi



Bits error versus sin2phi
Results
if (-.f32 1 u0) < 0.95536077Initial program 1.7
rmApplied add-sqr-sqrt_binary321.7
Applied associate-/l*_binary321.7
Simplified1.7
if 0.95536077 < (-.f32 1 u0) Initial program 14.3
Taylor expanded around 0 0.5
Simplified0.5
rmApplied associate-/r*_binary320.5
Final simplification0.7
herbie shell --seed 2021173
(FPCore (alphax alphay u0 cos2phi sin2phi)
:name "Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5"
:precision binary32
:pre (and (<= 0.0001 alphax 1.0) (<= 0.0001 alphay 1.0) (<= 2.328306437e-10 u0 1.0) (<= 0.0 cos2phi 1.0) (<= 0.0 sin2phi))
(/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))