
(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 9 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.9850000143051147)
(* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1)))))
(*
(sin (* (* 2.0 (PI)) u2))
(pow (* (* u1 u1) (+ (+ 1.0 (* (* 0.9166666666666666 u1) u1)) u1)) 0.25))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9850000143051147:\\
\;\;\;\;\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 {\left(\left(u1 \cdot u1\right) \cdot \left(\left(1 + \left(0.9166666666666666 \cdot u1\right) \cdot u1\right) + u1\right)\right)}^{0.25}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.985000014Initial program 96.2%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cbrt.f3295.2
Applied rewrites95.2%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
lift-pow.f32N/A
unpow2N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
Applied rewrites95.5%
lift-*.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lift-pow.f32N/A
pow-plusN/A
lift-cbrt.f32N/A
metadata-evalN/A
rem-cube-cbrtN/A
lift-PI.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
Applied rewrites96.2%
if 0.985000014 < (-.f32 #s(literal 1 binary32) u1) Initial program 49.5%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3284.3
Applied rewrites84.3%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3284.3
Applied rewrites84.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3249.2
Applied rewrites48.7%
Applied rewrites98.5%
Final simplification98.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))) (t_1 (sin (* (+ u2 u2) (PI)))))
(if (<= t_0 0.00019999999494757503)
(* (pow (* u1 u1) 0.25) 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(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\mathbf{if}\;t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;{\left(u1 \cdot u1\right)}^{0.25} \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 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.6
Applied rewrites92.6%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3292.6
Applied rewrites92.6%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.6
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cbrt.f3289.5
Applied rewrites89.5%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
lift-pow.f32N/A
unpow2N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
Applied rewrites89.7%
lift-*.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lift-pow.f32N/A
pow-plusN/A
lift-cbrt.f32N/A
metadata-evalN/A
rem-cube-cbrtN/A
lift-PI.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
Applied rewrites90.0%
Final simplification91.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9980000257492065) (* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1))))) (* (pow (* (+ 1.0 u1) (* u1 u1)) 0.25) (sin (* (* 2.0 (PI)) u2)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9980000257492065:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(1 + u1\right) \cdot \left(u1 \cdot u1\right)\right)}^{0.25} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.998000026Initial program 94.3%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*l*N/A
associate-*l*N/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cbrt.f3293.6
Applied rewrites93.6%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
lift-pow.f32N/A
unpow2N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
Applied rewrites93.8%
lift-*.f32N/A
lift-*.f32N/A
associate-*r*N/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
lift-pow.f32N/A
pow-plusN/A
lift-cbrt.f32N/A
metadata-evalN/A
rem-cube-cbrtN/A
lift-PI.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
Applied rewrites94.3%
if 0.998000026 < (-.f32 #s(literal 1 binary32) u1) Initial program 44.8%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3287.6
Applied rewrites87.6%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3287.6
Applied rewrites87.6%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3251.5
Applied rewrites51.5%
Taylor expanded in u1 around 0
Applied rewrites98.0%
Final simplification96.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998000264167786) (* (* (* 2.0 (PI)) u2) (sqrt (- (log (- 1.0 u1))))) (* (pow (* u1 u1) 0.25) (sin (* (+ u2 u2) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998000264167786:\\
\;\;\;\;\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left(u1 \cdot u1\right)}^{0.25} \cdot \sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.4
Applied rewrites76.4%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.6
Applied rewrites92.6%
lift-sqrt.f32N/A
pow1/2N/A
metadata-evalN/A
pow-sqrN/A
pow-prod-downN/A
lower-pow.f32N/A
lower-*.f3292.6
Applied rewrites92.6%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.6
Applied rewrites92.6%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
lift-*.f32N/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-+.f3292.6
Applied rewrites92.6%
Final simplification85.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* 2.0 (PI)) u2)))
(if (<= (- 1.0 u1) 0.9998000264167786)
(* 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.9998000264167786:\\
\;\;\;\;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.999800026Initial program 90.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.4
Applied rewrites76.4%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Applied rewrites18.0%
Taylor expanded in u1 around 0
lower-sqrt.f3292.6
Applied rewrites92.6%
Final simplification85.8%
(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 59.3%
Applied rewrites14.9%
Taylor expanded in u1 around 0
lower-sqrt.f3275.3
Applied rewrites75.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* u2 (PI)) (* (sqrt (/ (* (- (- u1)) (- u1)) (- u1))) 2.0)))
\begin{array}{l}
\\
\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot \left(\sqrt{\frac{\left(-\left(-u1\right)\right) \cdot \left(-u1\right)}{-u1}} \cdot 2\right)
\end{array}
Initial program 59.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.3
Applied rewrites75.3%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f3275.3
Applied rewrites75.3%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.2
Applied rewrites65.2%
+-lft-identityN/A
flip-+N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
lower-*.f32N/A
lower--.f3265.2
Applied rewrites65.2%
Final simplification65.2%
(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 59.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.3
Applied rewrites75.3%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.2
Applied rewrites65.2%
Final simplification65.2%
(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 59.3%
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.7
Applied rewrites4.7%
Final simplification4.7%
herbie shell --seed 2024271
(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))))