
(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 10 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 (log (- 1.0 u1))) (t_1 (sin (* (* (PI) 2.0) u2))))
(if (<= (- t_0) 0.00019999999494757503)
(* t_1 (sqrt (/ (pow u1 3.0) (/ (/ (pow (- u1) 4.0) (- u1)) (- u1)))))
(* (/ 1.0 (sqrt (/ -1.0 t_0))) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
t_1 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;-t\_0 \leq 0.00019999999494757503:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{{u1}^{3}}{\frac{\frac{{\left(-u1\right)}^{4}}{-u1}}{-u1}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{-1}{t\_0}}} \cdot 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 rewrites92.0%
Taylor expanded in u1 around 0
lower-pow.f3292.0
Applied rewrites92.0%
if 1.99999995e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.4%
Applied rewrites22.6%
lift-sqrt.f32N/A
lift--.f32N/A
flip--N/A
clear-numN/A
sqrt-divN/A
metadata-evalN/A
lower-/.f32N/A
lower-sqrt.f32N/A
Applied rewrites24.0%
lift-log1p.f32N/A
lift-neg.f32N/A
sub-negN/A
lift--.f32N/A
lift-log.f3289.5
Applied rewrites89.5%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))) (t_1 (log (- 1.0 u1))))
(if (<= (- t_1) 0.00019999999494757503)
(* (sqrt (/ (pow (- (- u1)) 3.0) (* u1 u1))) t_0)
(* (/ 1.0 (sqrt (/ -1.0 t_1))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\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}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{-1}{t\_1}}} \cdot t\_0\\
\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%
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%
Applied rewrites23.1%
lift-sqrt.f32N/A
lift--.f32N/A
flip--N/A
clear-numN/A
sqrt-divN/A
metadata-evalN/A
lower-/.f32N/A
lower-sqrt.f32N/A
Applied rewrites23.6%
lift-log1p.f32N/A
lift-neg.f32N/A
sub-negN/A
lift--.f32N/A
lift-log.f3289.5
Applied rewrites89.5%
Final simplification91.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00019999999494757503)
(* (sqrt (/ (pow (- (- u1)) 3.0) (* u1 u1))) t_0)
(* (sqrt t_1) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\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}:\\
\;\;\;\;\sqrt{t\_1} \cdot t\_0\\
\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%
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 (* (* (PI) 2.0) u2))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00019999999494757503)
(* (sqrt (/ 1.0 (/ -1.0 (- u1)))) t_0)
(* (sqrt t_1) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{\frac{1}{\frac{-1}{-u1}}} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot t\_0\\
\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 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 (* (* (PI) 2.0) 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(\mathsf{PI}\left(\right) \cdot 2\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%
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%
Applied rewrites88.3%
Final simplification86.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9977999925613403)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(/ (sin t_0) (sqrt (/ -1.0 (- u1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9977999925613403:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin t\_0}{\sqrt{\frac{-1}{-u1}}}\\
\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%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3288.2
Applied rewrites88.2%
lift-sqrt.f32N/A
lift-neg.f32N/A
neg-sub0N/A
flip3--N/A
sqrt-divN/A
lower-/.f32N/A
Applied rewrites88.0%
Applied rewrites88.2%
Final simplification86.0%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) 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(\mathsf{PI}\left(\right) \cdot 2\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 rewrites13.7%
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 (* (* (PI) 2.0) u2))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 57.7%
Applied rewrites13.8%
Taylor expanded in u1 around 0
lower-sqrt.f3276.1
Applied rewrites76.1%
Final simplification76.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (- u1))) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{-\left(-u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\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%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (- (sqrt u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\left(-\sqrt{u1}\right) \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\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%
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))))