
(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 5 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 (cbrt (PI))))
(if (<= (- 1.0 u1) 0.9998199939727783)
(* (sin (* (* (pow t_0 2.0) (* 2.0 u2)) t_0)) (sqrt (- (log (- 1.0 u1)))))
(* (sin (* (* (PI) 2.0) u2)) (sqrt u1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;1 - u1 \leq 0.9998199939727783:\\
\;\;\;\;\sin \left(\left({t\_0}^{2} \cdot \left(2 \cdot u2\right)\right) \cdot t\_0\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999819994Initial program 89.1%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lift-PI.f32N/A
lower-cbrt.f3289.2
Applied rewrites89.2%
if 0.999819994 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.2%
Applied rewrites36.7%
Taylor expanded in u1 around 0
lower-sqrt.f3291.8
Applied rewrites91.8%
Final simplification90.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.9998199939727783)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* t_0 (sqrt u1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9998199939727783:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999819994Initial program 89.1%
if 0.999819994 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.2%
Applied rewrites34.5%
Taylor expanded in u1 around 0
lower-sqrt.f3291.8
Applied rewrites91.8%
Final simplification90.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9997000098228455)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sin t_0) (sqrt u1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9997000098228455:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin t\_0 \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.99970001Initial program 90.3%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.8
Applied rewrites80.8%
if 0.99970001 < (-.f32 #s(literal 1 binary32) u1) Initial program 38.4%
Applied rewrites35.4%
Taylor expanded in u1 around 0
lower-sqrt.f3291.1
Applied rewrites91.1%
Final simplification87.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sin (* (* (PI) 2.0) u2)) (sqrt u1)))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}
\end{array}
Initial program 54.6%
Applied rewrites35.0%
Taylor expanded in u1 around 0
lower-sqrt.f3278.9
Applied rewrites78.9%
Final simplification78.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* (PI) 2.0) u2) (sqrt u1)))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}
\end{array}
Initial program 54.6%
Applied rewrites34.7%
Taylor expanded in u1 around 0
lower-sqrt.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.f3268.5
Applied rewrites68.5%
Final simplification68.5%
herbie shell --seed 2024263
(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))))