
(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
(let* ((t_0 (* u2 (PI))) (t_1 (- (log (- 1.0 u1)))) (t_2 (cbrt (PI))))
(if (<= t_1 0.00015999999595806003)
(* (* (sqrt (- (- u1))) (* (sin t_0) 2.0)) (cos t_0))
(* (sqrt t_1) (sin (* (pow t_2 2.0) (* (* t_2 u2) 2.0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := -\log \left(1 - u1\right)\\
t_2 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot \left(\sin t\_0 \cdot 2\right)\right) \cdot \cos t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left({t\_2}^{2} \cdot \left(\left(t\_2 \cdot u2\right) \cdot 2\right)\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.5
Applied rewrites91.5%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites91.7%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
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.f3290.8
Applied rewrites90.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))) (t_1 (- (log (- 1.0 u1)))) (t_2 (cbrt (PI))))
(if (<= t_1 0.00015999999595806003)
(* (* (sqrt (- (- u1))) (* (sin t_0) 2.0)) (cos t_0))
(* (sqrt t_1) (sin (* (* (* u2 2.0) (pow t_2 2.0)) t_2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := -\log \left(1 - u1\right)\\
t_2 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot \left(\sin t\_0 \cdot 2\right)\right) \cdot \cos t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left(\left(\left(u2 \cdot 2\right) \cdot {t\_2}^{2}\right) \cdot t\_2\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.5
Applied rewrites91.5%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites91.7%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lift-PI.f32N/A
add-cube-cbrtN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
pow2N/A
lower-pow.f32N/A
lift-PI.f32N/A
lower-cbrt.f32N/A
lift-PI.f32N/A
lower-cbrt.f3290.8
Applied rewrites90.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00015999999595806003)
(* (* (sqrt (- (- u1))) (* (sin t_0) 2.0)) (cos t_0))
(* (sqrt t_1) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot \left(\sin t\_0 \cdot 2\right)\right) \cdot \cos t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.5
Applied rewrites91.5%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
associate-*r*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites91.7%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00015999999595806003)
(* (* (sqrt (- (- u1))) (* 2.0 (cos t_0))) (sin t_0))
(* (sqrt t_1) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot \left(2 \cdot \cos t\_0\right)\right) \cdot \sin t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3291.5
Applied rewrites91.5%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f32N/A
sin-2N/A
lift-sin.f32N/A
lift-cos.f32N/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites91.7%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))) (t_1 (* (PI) u2)))
(if (<= t_0 0.00015999999595806003)
(* (* (* (cos t_1) (sin t_1)) 2.0) (sqrt u1))
(* (sqrt t_0) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
t_1 := \mathsf{PI}\left(\right) \cdot u2\\
\mathbf{if}\;t\_0 \leq 0.00015999999595806003:\\
\;\;\;\;\left(\left(\cos t\_1 \cdot \sin t\_1\right) \cdot 2\right) \cdot \sqrt{u1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_0} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Applied rewrites17.5%
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.f3291.5
Applied rewrites91.5%
Applied rewrites91.6%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998400211334229) (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 (PI)) u2))) (* (sin (* (* (PI) 2.0) u2)) (sqrt u1))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998400211334229:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999840021Initial program 90.5%
if 0.999840021 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.1%
Applied rewrites17.3%
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.f3291.7
Applied rewrites91.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9993000030517578) (* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) u2) 2.0)) (* (sin (* (* (PI) 2.0) u2)) (sqrt u1))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.9993Initial program 93.3%
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-*.f3293.3
Applied rewrites93.3%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites14.7%
Taylor expanded in u2 around 0
Applied rewrites81.5%
if 0.9993 < (-.f32 #s(literal 1 binary32) u1) Initial program 40.7%
Applied rewrites16.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.f3289.5
Applied rewrites89.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sin (* (* (PI) 2.0) u2)) (sqrt u1)))
\begin{array}{l}
\\
\sin \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right) \cdot \sqrt{u1}
\end{array}
Initial program 58.0%
Applied rewrites13.5%
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.f3275.7
Applied rewrites75.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* (PI) u2) 2.0) (sqrt u1)))
\begin{array}{l}
\\
\left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right) \cdot \sqrt{u1}
\end{array}
Initial program 58.0%
Applied rewrites13.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.f3275.7
Applied rewrites75.7%
Taylor expanded in u2 around 0
Applied rewrites66.9%
herbie shell --seed 2024307
(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))))