\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\begin{array}{l}
t_0 := \frac{cos2phi}{alphax \cdot alphax}\\
\mathbf{if}\;1 - u0 \leq 0.9546453952789307:\\
\;\;\;\;\frac{-\log \left(1 - u0\right)}{t_0 + sin2phi \cdot \frac{1}{alphay \cdot alphay}}\\
\mathbf{else}:\\
\;\;\;\;\frac{u0 + \left(0.25 \cdot {u0}^{4} + u0 \cdot \left(u0 \cdot \left(0.5 + u0 \cdot 0.3333333333333333\right)\right)\right)}{t_0 + \frac{sin2phi}{alphay \cdot 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
(let* ((t_0 (/ cos2phi (* alphax alphax))))
(if (<= (- 1.0 u0) 0.9546453952789307)
(/ (- (log (- 1.0 u0))) (+ t_0 (* sin2phi (/ 1.0 (* alphay alphay)))))
(/
(+
u0
(+
(* 0.25 (pow u0 4.0))
(* u0 (* u0 (+ 0.5 (* u0 0.3333333333333333))))))
(+ t_0 (/ 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 t_0 = cos2phi / (alphax * alphax);
float tmp;
if ((1.0f - u0) <= 0.9546453952789307f) {
tmp = -logf(1.0f - u0) / (t_0 + (sin2phi * (1.0f / (alphay * alphay))));
} else {
tmp = (u0 + ((0.25f * powf(u0, 4.0f)) + (u0 * (u0 * (0.5f + (u0 * 0.3333333333333333f)))))) / (t_0 + (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.954645395Initial program 1.5
rmApplied div-inv_binary321.6
if 0.954645395 < (-.f32 1 u0) Initial program 14.6
Taylor expanded around 0 0.5
Simplified0.5
rmApplied *-un-lft-identity_binary320.5
Applied associate-/r*_binary320.5
Simplified0.5
Final simplification0.7
herbie shell --seed 2021205
(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)))))