
(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 8 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)))))
(if (<= t_0 0.00015500000154133886)
(* (sin (* (* (PI) 2.0) u2)) (* (/ 1.0 u1) (pow u1 1.5)))
(* (sin (* (+ u2 u2) (PI))) (sqrt t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq 0.00015500000154133886:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \left(\frac{1}{u1} \cdot {u1}^{1.5}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{t\_0}\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.55000002e-4Initial program 33.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.1
Applied rewrites4.1%
Applied rewrites92.9%
Applied rewrites92.9%
if 1.55000002e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.9%
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
associate-*r*N/A
lift-*.f32N/A
associate-*r*N/A
lift-pow.f32N/A
pow-plusN/A
metadata-evalN/A
lift-cbrt.f32N/A
rem-cube-cbrtN/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3289.9
Applied rewrites89.9%
Final simplification91.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))))
(if (<= t_0 0.00015500000154133886)
(*
(/ (- (* u1 u1) (* (sqrt u1) 0.0)) (* (sqrt u1) u1))
(sin (* (* (PI) 2.0) u2)))
(* (sin (* (+ u2 u2) (PI))) (sqrt t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq 0.00015500000154133886:\\
\;\;\;\;\frac{u1 \cdot u1 - \sqrt{u1} \cdot 0}{\sqrt{u1} \cdot u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{t\_0}\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.55000002e-4Initial program 33.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.1
Applied rewrites4.1%
Applied rewrites92.9%
Applied rewrites92.7%
Applied rewrites92.8%
if 1.55000002e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 89.9%
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
associate-*r*N/A
lift-*.f32N/A
associate-*r*N/A
lift-pow.f32N/A
pow-plusN/A
metadata-evalN/A
lift-cbrt.f32N/A
rem-cube-cbrtN/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
count-2N/A
lift-*.f32N/A
lift-*.f32N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-+.f3289.9
Applied rewrites89.9%
Final simplification91.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9998000264167786)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (/ (- (* u1 u1) (* (sqrt u1) 0.0)) (* (sqrt u1) 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.9998000264167786:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{u1 \cdot u1 - \sqrt{u1} \cdot 0}{\sqrt{u1} \cdot u1} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.3
Applied rewrites76.3%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 34.4%
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.1
Applied rewrites4.1%
Applied rewrites92.4%
Applied rewrites92.3%
Applied rewrites92.4%
Final simplification86.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (PI) 2.0) u2)))
(if (<= (- 1.0 u1) 0.9998000264167786)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (/ 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.9998000264167786:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{u1}{\sqrt{u1}} \cdot \sin t\_0\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.3
Applied rewrites76.3%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 34.4%
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.1
Applied rewrites4.1%
Applied rewrites92.4%
Final simplification86.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998000264167786) (* (* (* (PI) 2.0) u2) (sqrt (- (log (- 1.0 u1))))) (* (sqrt u1) (sin (* (* u2 2.0) (PI))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998000264167786:\\
\;\;\;\;\left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999800026Initial program 90.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3276.3
Applied rewrites76.3%
if 0.999800026 < (-.f32 #s(literal 1 binary32) u1) Initial program 34.4%
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.1
Applied rewrites4.1%
Applied rewrites92.4%
Final simplification86.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* u2 2.0) (PI)))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(u2 \cdot 2\right) \cdot \mathsf{PI}\left(\right)\right)
\end{array}
Initial program 55.4%
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%
Applied rewrites77.0%
Final simplification77.0%
(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 55.4%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3277.0
Applied rewrites77.0%
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 55.4%
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.3
Applied rewrites4.3%
herbie shell --seed 2024254
(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))))