
(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 7 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 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.999904990196228)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(*
(sqrt (* (/ (- u1) (/ -1.0 (- u1))) (/ (- u1) (pow (- u1) 2.0))))
t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.999904990196228:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{-u1}{\frac{-1}{-u1}} \cdot \frac{-u1}{{\left(-u1\right)}^{2}}} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.99990499Initial program 90.2%
if 0.99990499 < (-.f32 #s(literal 1 binary32) u1) Initial program 35.8%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.8
Applied rewrites92.8%
lift-neg.f32N/A
neg-sub0N/A
flip--N/A
div-invN/A
lower-*.f32N/A
Applied rewrites92.8%
lift-*.f32N/A
lift-/.f32N/A
un-div-invN/A
lift-neg.f32N/A
lift-pow.f32N/A
unpow2N/A
distribute-lft-neg-inN/A
unpow1N/A
metadata-evalN/A
pow-prod-upN/A
lift-pow.f32N/A
inv-powN/A
lift-/.f32N/A
Applied rewrites92.8%
Final simplification91.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* (* (PI) 2.0) u2))))
(if (<= (- 1.0 u1) 0.999904990196228)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{if}\;1 - u1 \leq 0.999904990196228:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.99990499Initial program 90.2%
if 0.99990499 < (-.f32 #s(literal 1 binary32) u1) Initial program 35.8%
Applied rewrites41.8%
Taylor expanded in u1 around 0
lower-sqrt.f3292.8
Applied rewrites92.8%
Final simplification91.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.999750018119812)
(* 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.999750018119812:\\
\;\;\;\;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.999750018Initial program 91.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.4
Applied rewrites80.4%
if 0.999750018 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Applied rewrites45.2%
Taylor expanded in u1 around 0
lower-sqrt.f3292.2
Applied rewrites92.2%
Final simplification87.8%
(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.3%
Applied rewrites38.4%
Taylor expanded in u1 around 0
lower-sqrt.f3276.6
Applied rewrites76.6%
Final simplification76.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ -1.0 (/ 1.0 (- u1)))) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{\frac{-1}{\frac{1}{-u1}}} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 57.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.6
Applied rewrites76.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3267.4
Applied rewrites67.4%
/-rgt-identityN/A
clear-numN/A
lift-/.f32N/A
lower-/.f3267.4
Applied rewrites67.4%
Final simplification67.4%
(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.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3276.6
Applied rewrites76.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3267.4
Applied rewrites67.4%
(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.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.6
Applied rewrites4.6%
herbie shell --seed 2024267
(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))))