
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))) (t_1 (sin (* (* (PI) 2.0) u2))))
(if (<= t_0 0.00019999999494757503)
(* t_1 (sqrt (* (/ -1.0 (pow (- u1) 2.0)) (pow (- u1) 3.0))))
(* (sqrt t_0) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
t_1 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{-1}{{\left(-u1\right)}^{2}} \cdot {\left(-u1\right)}^{3}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_0} \cdot t\_1\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.99999995e-4Initial program 36.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.6
Applied rewrites92.6%
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
div-invN/A
lower-*.f32N/A
metadata-evalN/A
sub0-negN/A
lower-neg.f32N/A
lower-pow.f32N/A
lower-/.f32N/A
Applied rewrites92.6%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.1%
Final simplification91.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (let* ((t_0 (- (log (- 1.0 u1)))) (t_1 (sin (* (* (PI) 2.0) u2)))) (if (<= t_0 0.00019999999494757503) (* (sqrt u1) t_1) (* (sqrt t_0) t_1))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
t_1 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{u1} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_0} \cdot t\_1\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.99999995e-4Initial program 36.0%
Applied rewrites29.2%
Taylor expanded in u1 around 0
lower-sqrt.f3292.6
Applied rewrites92.6%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.1%
Final simplification91.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9994999766349792)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9994999766349792:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999499977Initial program 91.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3278.1
Applied rewrites78.1%
if 0.999499977 < (-.f32 #s(literal 1 binary32) u1) Initial program 39.4%
Applied rewrites27.7%
Taylor expanded in u1 around 0
lower-sqrt.f3290.7
Applied rewrites90.7%
Final simplification87.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* (PI) 2.0) u2))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 54.7%
Applied rewrites25.7%
Taylor expanded in u1 around 0
lower-sqrt.f3278.9
Applied rewrites78.9%
Final simplification78.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (+ u2 u2) (PI)) (sqrt (- (- u1)))))
\begin{array}{l}
\\
\left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\left(-u1\right)}
\end{array}
Initial program 54.7%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3278.9
Applied rewrites78.9%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3266.8
Applied rewrites66.8%
Applied rewrites66.8%
Final simplification66.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (- (sqrt u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\left(-\sqrt{u1}\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 54.7%
Taylor expanded in u1 around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
lower-neg.f32N/A
lower-sqrt.f324.0
Applied rewrites4.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f325.0
Applied rewrites5.0%
herbie shell --seed 2024248
(FPCore (cosTheta_i u1 u2)
:name "Beckmann Sample, near normal, slope_y"
:precision binary32
:pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
(* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))))