
(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
(if (<= (- 1.0 u1) 0.9998692274093628)
(*
(sin
(*
(pow (PI) 0.16666666666666666)
(* (cbrt (PI)) (* (* 2.0 u2) (sqrt (PI))))))
(sqrt (- (log (- 1.0 u1)))))
(* (sin (* (* 2.0 (PI)) u2)) (/ u1 (sqrt u1)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998692274093628:\\
\;\;\;\;\sin \left({\mathsf{PI}\left(\right)}^{0.16666666666666666} \cdot \left(\sqrt[3]{\mathsf{PI}\left(\right)} \cdot \left(\left(2 \cdot u2\right) \cdot \sqrt{\mathsf{PI}\left(\right)}\right)\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \frac{u1}{\sqrt{u1}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999869227Initial program 89.3%
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.0
Applied rewrites89.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-pow.f32N/A
pow-plusN/A
lift-cbrt.f32N/A
metadata-evalN/A
rem-cube-cbrtN/A
lift-PI.f32N/A
add-sqr-sqrtN/A
associate-*r*N/A
lift-PI.f32N/A
pow1/2N/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow3N/A
sqr-powN/A
pow1/3N/A
lift-cbrt.f32N/A
Applied rewrites89.4%
if 0.999869227 < (-.f32 #s(literal 1 binary32) u1) Initial program 39.8%
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.1
Applied rewrites4.1%
Applied rewrites91.7%
Final simplification90.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998692274093628) (* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1))))) (* (sin (* (* 2.0 (PI)) u2)) (/ u1 (sqrt u1)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998692274093628:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \frac{u1}{\sqrt{u1}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999869227Initial program 89.3%
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.0
Applied rewrites89.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
*-commutativeN/A
lift-pow.f32N/A
pow-plusN/A
lift-cbrt.f32N/A
metadata-evalN/A
rem-cube-cbrtN/A
associate-*r*N/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3289.3
Applied rewrites89.3%
if 0.999869227 < (-.f32 #s(literal 1 binary32) u1) Initial program 39.8%
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.1
Applied rewrites4.1%
Applied rewrites91.7%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sin (* (* 2.0 (PI)) u2)) (/ u1 (sqrt u1))))
\begin{array}{l}
\\
\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \frac{u1}{\sqrt{u1}}
\end{array}
Initial program 59.9%
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%
Applied rewrites75.8%
Final simplification75.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* 2.0 u2) (PI)))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(2 \cdot u2\right) \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 59.9%
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%
Applied rewrites75.7%
Final simplification75.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* u2 (PI)) 2.0) (sqrt u1)))
\begin{array}{l}
\\
\left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot \sqrt{u1}
\end{array}
Initial program 59.9%
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%
Applied rewrites75.7%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3264.4
Applied rewrites64.4%
Final simplification64.4%
herbie shell --seed 2024285
(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))))