
(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 11 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 (sqrt (/ 1.0 u1))) (t_1 (cbrt (PI))) (t_2 (pow t_1 2.0)))
(if (<= (- 1.0 u1) 0.9977999925613403)
(*
(sin (* (cbrt t_1) (* (cbrt t_2) (* (* u2 t_2) 2.0))))
(sqrt (- (log (- 1.0 u1)))))
(*
(sin (* (* 2.0 (PI)) u2))
(sqrt
(pow
(+
(*
(* u1 u1)
(fma
(fma
0.16666666666666666
t_0
(* (sqrt u1) (* (+ 0.25 (/ -0.0625 u1)) 0.5)))
u1
(* 0.25 t_0)))
(sqrt u1))
2.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{u1}}\\
t_1 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_2 := {t\_1}^{2}\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;\sin \left(\sqrt[3]{t\_1} \cdot \left(\sqrt[3]{t\_2} \cdot \left(\left(u2 \cdot t\_2\right) \cdot 2\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 \sqrt{{\left(\left(u1 \cdot u1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, t\_0, \sqrt{u1} \cdot \left(\left(0.25 + \frac{-0.0625}{u1}\right) \cdot 0.5\right)\right), u1, 0.25 \cdot t\_0\right) + \sqrt{u1}\right)}^{2}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.997799993Initial program 93.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.f3293.6
Applied rewrites93.6%
lift-*.f32N/A
rem-cbrt-cubeN/A
cube-unmultN/A
unpow2N/A
lift-pow.f32N/A
cbrt-prodN/A
pow1/3N/A
pow1/3N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites93.6%
if 0.997799993 < (-.f32 #s(literal 1 binary32) u1) Initial program 42.8%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3288.2
Applied rewrites88.2%
+-lft-identityN/A
flip3-+N/A
lower-/.f32N/A
metadata-evalN/A
lower-+.f32N/A
lower-pow.f32N/A
metadata-evalN/A
lower-+.f32N/A
Applied rewrites88.3%
lift-/.f32N/A
lift-+.f32N/A
+-lft-identityN/A
lift-pow.f32N/A
sqr-powN/A
lift-+.f32N/A
+-lft-identityN/A
lift--.f32N/A
Applied rewrites88.1%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Final simplification96.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sqrt (/ 1.0 u1))))
(if (<= (- 1.0 u1) 0.9977999925613403)
(*
(sin (* (* (cbrt (* (PI) (PI))) (* u2 2.0)) (cbrt (PI))))
(sqrt (- (log (- 1.0 u1)))))
(*
(sin (* (* 2.0 (PI)) u2))
(sqrt
(pow
(+
(*
(* u1 u1)
(fma
(fma
0.16666666666666666
t_0
(* (sqrt u1) (* (+ 0.25 (/ -0.0625 u1)) 0.5)))
u1
(* 0.25 t_0)))
(sqrt u1))
2.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{1}{u1}}\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;\sin \left(\left(\sqrt[3]{\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)} \cdot \left(u2 \cdot 2\right)\right) \cdot \sqrt[3]{\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 \sqrt{{\left(\left(u1 \cdot u1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, t\_0, \sqrt{u1} \cdot \left(\left(0.25 + \frac{-0.0625}{u1}\right) \cdot 0.5\right)\right), u1, 0.25 \cdot t\_0\right) + \sqrt{u1}\right)}^{2}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.997799993Initial program 93.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.f3293.6
Applied rewrites93.6%
Taylor expanded in u2 around 0
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower-cbrt.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3293.6
Applied rewrites93.6%
if 0.997799993 < (-.f32 #s(literal 1 binary32) u1) Initial program 42.8%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3288.2
Applied rewrites88.2%
+-lft-identityN/A
flip3-+N/A
lower-/.f32N/A
metadata-evalN/A
lower-+.f32N/A
lower-pow.f32N/A
metadata-evalN/A
lower-+.f32N/A
Applied rewrites88.3%
lift-/.f32N/A
lift-+.f32N/A
+-lft-identityN/A
lift-pow.f32N/A
sqr-powN/A
lift-+.f32N/A
+-lft-identityN/A
lift--.f32N/A
Applied rewrites88.1%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Final simplification96.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* 2.0 (PI)) u2))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00019999999494757503)
(* (sqrt (/ (pow (- (- u1)) 3.0) (* u1 u1))) t_0)
(* t_0 (sqrt t_1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{\frac{{\left(-\left(-u1\right)\right)}^{3}}{u1 \cdot u1}} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{t\_1}\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.99999995e-4Initial program 36.7%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.0
Applied rewrites92.0%
+-lft-identityN/A
flip3-+N/A
lower-/.f32N/A
metadata-evalN/A
lower-+.f32N/A
lower-pow.f32N/A
metadata-evalN/A
lower-+.f32N/A
Applied rewrites92.0%
Applied rewrites26.6%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.0
Applied rewrites92.0%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.4%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* 2.0 (PI)) u2))) (t_1 (sqrt (/ 1.0 u1))))
(if (<= (- 1.0 u1) 0.9977999925613403)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(*
t_0
(sqrt
(pow
(+
(*
(* u1 u1)
(fma
(fma
0.16666666666666666
t_1
(* (sqrt u1) (* (+ 0.25 (/ -0.0625 u1)) 0.5)))
u1
(* 0.25 t_1)))
(sqrt u1))
2.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
t_1 := \sqrt{\frac{1}{u1}}\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt{{\left(\left(u1 \cdot u1\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, t\_1, \sqrt{u1} \cdot \left(\left(0.25 + \frac{-0.0625}{u1}\right) \cdot 0.5\right)\right), u1, 0.25 \cdot t\_1\right) + \sqrt{u1}\right)}^{2}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.997799993Initial program 93.6%
if 0.997799993 < (-.f32 #s(literal 1 binary32) u1) Initial program 42.8%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3288.2
Applied rewrites88.2%
+-lft-identityN/A
flip3-+N/A
lower-/.f32N/A
metadata-evalN/A
lower-+.f32N/A
lower-pow.f32N/A
metadata-evalN/A
lower-+.f32N/A
Applied rewrites88.3%
lift-/.f32N/A
lift-+.f32N/A
+-lft-identityN/A
lift-pow.f32N/A
sqr-powN/A
lift-+.f32N/A
+-lft-identityN/A
lift--.f32N/A
Applied rewrites88.1%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Final simplification96.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))) (t_1 (sin (* (* 2.0 (PI)) u2))))
(if (<= t_0 0.00019999999494757503)
(* (sqrt (/ 1.0 (/ 1.0 u1))) t_1)
(* t_1 (sqrt t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
t_1 := \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{\frac{1}{\frac{1}{u1}}} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1 \cdot \sqrt{t\_0}\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.99999995e-4Initial program 36.7%
Applied rewrites35.7%
lift--.f32N/A
flip--N/A
clear-numN/A
lower-/.f32N/A
clear-numN/A
flip--N/A
lift--.f32N/A
lower-/.f3239.0
lift--.f32N/A
lift-log1p.f32N/A
lift-log1p.f32N/A
diff-logN/A
clear-numN/A
Applied rewrites39.1%
Taylor expanded in u1 around 0
lower-/.f3292.0
Applied rewrites92.0%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.4%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* 2.0 (PI)) u2)))
(if (<= (- 1.0 u1) 0.9977999925613403)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt (/ 1.0 (/ 1.0 u1))) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{\frac{1}{u1}}} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.997799993Initial program 93.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.7
Applied rewrites80.7%
if 0.997799993 < (-.f32 #s(literal 1 binary32) u1) Initial program 42.8%
Applied rewrites32.8%
lift--.f32N/A
flip--N/A
clear-numN/A
lower-/.f32N/A
clear-numN/A
flip--N/A
lift--.f32N/A
lower-/.f3235.1
lift--.f32N/A
lift-log1p.f32N/A
lift-log1p.f32N/A
diff-logN/A
clear-numN/A
Applied rewrites37.9%
Taylor expanded in u1 around 0
lower-/.f3288.3
Applied rewrites88.3%
Final simplification86.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* 2.0 (PI)) u2)))
(if (<= (- 1.0 u1) 0.9977999925613403)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;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.997799993Initial program 93.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.7
Applied rewrites80.7%
if 0.997799993 < (-.f32 #s(literal 1 binary32) u1) Initial program 42.8%
Applied rewrites15.8%
Taylor expanded in u1 around 0
lower-sqrt.f3288.2
Applied rewrites88.2%
Final simplification86.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 57.7%
Applied rewrites13.6%
Taylor expanded in u1 around 0
lower-sqrt.f3276.1
Applied rewrites76.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ 1.0 (/ -1.0 (- u1)))) (* (* 2.0 (PI)) u2)))
\begin{array}{l}
\\
\sqrt{\frac{1}{\frac{-1}{-u1}}} \cdot \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 57.7%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.1
Applied rewrites76.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3263.9
Applied rewrites63.9%
Applied rewrites63.9%
Final simplification63.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (- u1))) (* (* 2.0 (PI)) u2)))
\begin{array}{l}
\\
\sqrt{-\left(-u1\right)} \cdot \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 57.7%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.1
Applied rewrites76.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3263.9
Applied rewrites63.9%
Final simplification63.9%
(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 57.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.f324.8
Applied rewrites4.8%
Final simplification4.8%
herbie shell --seed 2024276
(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))))