
(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 8 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 (pow (PI) 0.16666666666666666)))
(if (<= (- 1.0 u1) 0.9959499835968018)
(*
(sin (* (* (* (* u2 (pow (cbrt (PI)) 2.0)) 2.0) t_0) t_0))
(sqrt (- (log (- 1.0 u1)))))
(*
(- (pow u1 -1.5) (/ -0.25 (sqrt u1)))
(* (* u1 u1) (sin (* (* u2 2.0) (PI))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\mathsf{PI}\left(\right)}^{0.16666666666666666}\\
\mathbf{if}\;1 - u1 \leq 0.9959499835968018:\\
\;\;\;\;\sin \left(\left(\left(\left(u2 \cdot {\left(\sqrt[3]{\mathsf{PI}\left(\right)}\right)}^{2}\right) \cdot 2\right) \cdot t\_0\right) \cdot t\_0\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left({u1}^{-1.5} - \frac{-0.25}{\sqrt{u1}}\right) \cdot \left(\left(u1 \cdot u1\right) \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995949984Initial program 94.6%
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.f3294.3
Applied rewrites94.3%
lift-*.f32N/A
*-commutativeN/A
lift-cbrt.f32N/A
pow1/3N/A
sqr-powN/A
associate-*l*N/A
lower-*.f32N/A
lower-pow.f32N/A
metadata-evalN/A
lower-*.f32N/A
lower-pow.f32N/A
metadata-eval94.8
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites94.8%
if 0.995949984 < (-.f32 #s(literal 1 binary32) u1) Initial program 43.7%
Applied rewrites14.5%
Taylor expanded in u1 around 0
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites87.7%
Taylor expanded in u1 around -inf
Applied rewrites97.4%
Applied rewrites97.6%
Final simplification96.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9959499835968018)
(* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1)))))
(*
(- (pow u1 -1.5) (/ -0.25 (sqrt u1)))
(* (* u1 u1) (sin (* (* u2 2.0) (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9959499835968018:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left({u1}^{-1.5} - \frac{-0.25}{\sqrt{u1}}\right) \cdot \left(\left(u1 \cdot u1\right) \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995949984Initial program 94.6%
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.f3294.3
Applied rewrites94.3%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
*-commutativeN/A
lift-pow.f32N/A
unpow2N/A
pow3N/A
lift-cbrt.f32N/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-+.f3294.6
Applied rewrites94.6%
if 0.995949984 < (-.f32 #s(literal 1 binary32) u1) Initial program 43.7%
Applied rewrites14.9%
Taylor expanded in u1 around 0
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites87.7%
Taylor expanded in u1 around -inf
Applied rewrites97.4%
Applied rewrites97.6%
Final simplification96.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9959499835968018)
(* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1)))))
(*
(* (* (- (pow u1 -1.5) (/ -0.25 (sqrt u1))) u1) (sin (* (* u2 2.0) (PI))))
u1)))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9959499835968018:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left({u1}^{-1.5} - \frac{-0.25}{\sqrt{u1}}\right) \cdot u1\right) \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\right) \cdot u1\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.995949984Initial program 94.6%
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.f3294.3
Applied rewrites94.3%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
*-commutativeN/A
lift-pow.f32N/A
unpow2N/A
pow3N/A
lift-cbrt.f32N/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-+.f3294.6
Applied rewrites94.6%
if 0.995949984 < (-.f32 #s(literal 1 binary32) u1) Initial program 43.7%
Applied rewrites15.8%
Taylor expanded in u1 around 0
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites87.7%
Taylor expanded in u1 around -inf
Applied rewrites97.4%
Applied rewrites97.6%
Final simplification96.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998499751091003) (* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1))))) (* (sqrt u1) (sin (* (* u2 2.0) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998499751091003:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999849975Initial 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.1
Applied rewrites89.1%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
*-commutativeN/A
lift-pow.f32N/A
unpow2N/A
pow3N/A
lift-cbrt.f32N/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.999849975 < (-.f32 #s(literal 1 binary32) u1) Initial program 35.0%
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%
lift-*.f32N/A
*-commutativeN/A
lower-*.f324.1
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
lower-*.f324.1
Applied rewrites93.0%
Final simplification91.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (* (* 2.0 (PI)) u2) 0.013000000268220901)
(*
(* (- (* (sqrt (/ 1.0 u1)) -0.25) (sqrt (/ 1.0 (pow u1 3.0)))) (* u2 (PI)))
(* -2.0 (* u1 u1)))
(* (sqrt u1) (sin (* (* u2 2.0) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2 \leq 0.013000000268220901:\\
\;\;\;\;\left(\left(\sqrt{\frac{1}{u1}} \cdot -0.25 - \sqrt{\frac{1}{{u1}^{3}}}\right) \cdot \left(u2 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot \left(-2 \cdot \left(u1 \cdot u1\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) < 0.0130000003Initial program 60.1%
Applied rewrites13.1%
Taylor expanded in u1 around 0
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
lower-*.f32N/A
Applied rewrites75.2%
Taylor expanded in u1 around -inf
Applied rewrites86.8%
Taylor expanded in u2 around 0
Applied rewrites85.7%
if 0.0130000003 < (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2) Initial program 47.4%
Taylor expanded in u1 around 0
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
mul-1-negN/A
lower-neg.f32N/A
lower-sqrt.f323.6
Applied rewrites3.6%
lift-*.f32N/A
*-commutativeN/A
lower-*.f323.6
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
lower-*.f323.6
Applied rewrites81.1%
Final simplification84.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* u2 2.0) (PI)))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 56.4%
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%
lift-*.f32N/A
*-commutativeN/A
lower-*.f324.0
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
lower-*.f324.0
Applied rewrites76.9%
Final simplification76.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* 2.0 (PI)) u2) (sqrt (- (- u1)))))
\begin{array}{l}
\\
\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\left(-u1\right)}
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.9
Applied rewrites76.9%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites15.1%
Taylor expanded in u2 around 0
Applied rewrites65.6%
Final simplification65.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (- (sqrt u1)) (* (* 2.0 (PI)) u2)))
\begin{array}{l}
\\
\left(-\sqrt{u1}\right) \cdot \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.9
Applied rewrites76.9%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites15.4%
Taylor expanded in u2 around 0
Applied rewrites65.6%
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.6
Applied rewrites4.6%
Final simplification4.6%
herbie shell --seed 2024288
(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))))