
(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.9998239874839783)
(*
(* 2.0 (* (sin (* (* (log (E)) (PI)) u2)) (cos (* (PI) u2))))
(sqrt (- (log (- 1.0 u1)))))
(/ (sin (* (* 2.0 (PI)) u2)) (pow (- (- u1)) -0.5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998239874839783:\\
\;\;\;\;\left(2 \cdot \left(\sin \left(\left(\log \mathsf{E}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \cos \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)}{{\left(-\left(-u1\right)\right)}^{-0.5}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999823987Initial program 89.4%
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
*-commutativeN/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-*.f3289.5
Applied rewrites89.5%
lift-PI.f32N/A
add-log-expN/A
*-un-lft-identityN/A
lift-PI.f32N/A
exp-prodN/A
log-powN/A
lower-*.f32N/A
lower-log.f32N/A
exp-1-eN/A
lower-E.f3289.6
Applied rewrites89.6%
if 0.999823987 < (-.f32 #s(literal 1 binary32) u1) Initial program 38.5%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.8
Applied rewrites91.8%
lift-sqrt.f32N/A
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
sqrt-divN/A
lower-/.f32N/A
Applied rewrites91.8%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
clear-numN/A
un-div-invN/A
lower-/.f32N/A
Applied rewrites91.9%
Final simplification91.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (PI) u2)))
(if (<= (- 1.0 u1) 0.9998239874839783)
(* (* (* (sin t_0) (cos t_0)) 2.0) (sqrt (- (log (- 1.0 u1)))))
(/ (sin (* (* 2.0 (PI)) u2)) (pow (- (- u1)) -0.5)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9998239874839783:\\
\;\;\;\;\left(\left(\sin t\_0 \cdot \cos t\_0\right) \cdot 2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)}{{\left(-\left(-u1\right)\right)}^{-0.5}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999823987Initial program 89.4%
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
*-commutativeN/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-*.f3289.5
Applied rewrites89.5%
if 0.999823987 < (-.f32 #s(literal 1 binary32) u1) Initial program 38.5%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.8
Applied rewrites91.8%
lift-sqrt.f32N/A
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
sqrt-divN/A
lower-/.f32N/A
Applied rewrites91.8%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
clear-numN/A
un-div-invN/A
lower-/.f32N/A
Applied rewrites91.9%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* 2.0 (PI)) u2))))
(if (<= (- 1.0 u1) 0.9998239874839783)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(/ t_0 (pow (- (- u1)) -0.5)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9998239874839783:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{{\left(-\left(-u1\right)\right)}^{-0.5}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999823987Initial program 89.4%
if 0.999823987 < (-.f32 #s(literal 1 binary32) u1) Initial program 38.5%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.8
Applied rewrites91.8%
lift-sqrt.f32N/A
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
sqrt-divN/A
lower-/.f32N/A
Applied rewrites91.8%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
clear-numN/A
un-div-invN/A
lower-/.f32N/A
Applied rewrites91.9%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9810000061988831)
(*
(* (* (fma (* -1.3333333333333333 (* u2 u2)) (* (PI) (PI)) 2.0) (PI)) u2)
(sqrt (- (log (- 1.0 u1)))))
(/ (sin (* (* 2.0 (PI)) u2)) (pow (- (- u1)) -0.5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9810000061988831:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)}{{\left(-\left(-u1\right)\right)}^{-0.5}}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.981000006Initial program 96.6%
Taylor expanded in u2 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites87.7%
if 0.981000006 < (-.f32 #s(literal 1 binary32) u1) Initial program 50.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3284.1
Applied rewrites84.1%
lift-sqrt.f32N/A
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
sqrt-divN/A
lower-/.f32N/A
Applied rewrites84.1%
lift-*.f32N/A
*-commutativeN/A
lift-/.f32N/A
clear-numN/A
un-div-invN/A
lower-/.f32N/A
Applied rewrites84.1%
Final simplification74.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9810000061988831)
(*
(* (* (fma (* -1.3333333333333333 (* u2 u2)) (* (PI) (PI)) 2.0) (PI)) u2)
(sqrt (- (log (- 1.0 u1)))))
(* (pow (* u1 u1) 0.25) (sin (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9810000061988831:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 2\right) \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(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.981000006Initial program 96.6%
Taylor expanded in u2 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites87.7%
if 0.981000006 < (-.f32 #s(literal 1 binary32) u1) Initial program 50.0%
Applied rewrites30.3%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3284.1
Applied rewrites84.1%
Final simplification77.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9810000061988831)
(*
(* (* (fma (* -1.3333333333333333 (* u2 u2)) (* (PI) (PI)) 2.0) (PI)) u2)
(sqrt (- (log (- 1.0 u1)))))
(* (sqrt (/ (* (- (- u1)) (- u1)) (- u1))) (sin (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9810000061988831:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{\left(-\left(-u1\right)\right) \cdot \left(-u1\right)}{-u1}} \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.981000006Initial program 96.6%
Taylor expanded in u2 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites87.7%
if 0.981000006 < (-.f32 #s(literal 1 binary32) u1) Initial program 50.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3284.1
Applied rewrites84.1%
+-lft-identityN/A
flip-+N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
lower-*.f32N/A
lower--.f3284.1
Applied rewrites84.1%
Final simplification79.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (- 1.0 u1) 0.9810000061988831)
(*
(* (* (fma (* -1.3333333333333333 (* u2 u2)) (* (PI) (PI)) 2.0) (PI)) u2)
(sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9810000061988831:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \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.981000006Initial program 96.6%
Taylor expanded in u2 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites87.7%
if 0.981000006 < (-.f32 #s(literal 1 binary32) u1) Initial program 50.0%
Applied rewrites42.0%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3284.1
Applied rewrites84.1%
Final simplification79.7%
(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 56.2%
Applied rewrites38.6%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3278.3
Applied rewrites78.3%
Final simplification78.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (sqrt u1) u2) (* 2.0 (PI))))
\begin{array}{l}
\\
\left(\sqrt{u1} \cdot u2\right) \cdot \left(2 \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 56.2%
Applied rewrites37.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-sin.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f3278.3
Applied rewrites78.3%
Taylor expanded in u2 around 0
Applied rewrites70.4%
Applied rewrites70.5%
Final simplification70.5%
herbie shell --seed 2024308
(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))))