
(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 (cbrt (PI))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00015999999595806003)
(/
(- (sin (* (* u2 (PI)) 2.0)))
(/
(- (* (* (- -0.041666666666666664) (sqrt u1)) (* u1 u1)) (sqrt u1))
u1))
(* (sqrt t_1) (sin (* (pow t_0 2.0) (* (* t_0 u2) 2.0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\frac{-\sin \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}{\frac{\left(\left(--0.041666666666666664\right) \cdot \sqrt{u1}\right) \cdot \left(u1 \cdot u1\right) - \sqrt{u1}}{u1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left({t\_0}^{2} \cdot \left(\left(t\_0 \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%
Applied rewrites17.6%
Applied rewrites38.9%
Taylor expanded in u1 around 0
lower-/.f32N/A
Applied rewrites91.8%
Taylor expanded in u1 around -inf
Applied rewrites91.8%
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%
Final simplification91.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cbrt (PI))) (t_1 (- (log (- 1.0 u1)))))
(if (<= t_1 0.00015999999595806003)
(/
(- (sin (* (* u2 (PI)) 2.0)))
(/
(- (* (* (- -0.041666666666666664) (sqrt u1)) (* u1 u1)) (sqrt u1))
u1))
(* (sqrt t_1) (sin (* (* (* u2 2.0) (pow t_0 2.0)) t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\mathsf{PI}\left(\right)}\\
t_1 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_1 \leq 0.00015999999595806003:\\
\;\;\;\;\frac{-\sin \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}{\frac{\left(\left(--0.041666666666666664\right) \cdot \sqrt{u1}\right) \cdot \left(u1 \cdot u1\right) - \sqrt{u1}}{u1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_1} \cdot \sin \left(\left(\left(u2 \cdot 2\right) \cdot {t\_0}^{2}\right) \cdot t\_0\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 1.59999996e-4Initial program 37.3%
Applied rewrites18.9%
Applied rewrites37.0%
Taylor expanded in u1 around 0
lower-/.f32N/A
Applied rewrites91.8%
Taylor expanded in u1 around -inf
Applied rewrites91.8%
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%
Final simplification91.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))))
(if (<= t_0 0.00015999999595806003)
(/
(- (sin (* (* u2 (PI)) 2.0)))
(/
(- (* (* (- -0.041666666666666664) (sqrt u1)) (* u1 u1)) (sqrt u1))
u1))
(* (sqrt t_0) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq 0.00015999999595806003:\\
\;\;\;\;\frac{-\sin \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}{\frac{\left(\left(--0.041666666666666664\right) \cdot \sqrt{u1}\right) \cdot \left(u1 \cdot u1\right) - \sqrt{u1}}{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.6%
Applied rewrites38.3%
Taylor expanded in u1 around 0
lower-/.f32N/A
Applied rewrites91.8%
Taylor expanded in u1 around -inf
Applied rewrites91.8%
if 1.59999996e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial program 90.8%
Final simplification91.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (- (log (- 1.0 u1)))))
(if (<= t_0 0.000699999975040555)
(/
(- (sin (* (* u2 (PI)) 2.0)))
(/
(- (* (* (- -0.041666666666666664) (sqrt u1)) (* u1 u1)) (sqrt u1))
u1))
(* (sqrt t_0) (* (* (PI) u2) 2.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := -\log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq 0.000699999975040555:\\
\;\;\;\;\frac{-\sin \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}{\frac{\left(\left(--0.041666666666666664\right) \cdot \sqrt{u1}\right) \cdot \left(u1 \cdot u1\right) - \sqrt{u1}}{u1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot 2\right)\\
\end{array}
\end{array}
if (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) < 6.99999975e-4Initial program 40.7%
Applied rewrites16.7%
Applied rewrites37.4%
Taylor expanded in u1 around 0
lower-/.f32N/A
Applied rewrites89.7%
Taylor expanded in u1 around -inf
Applied rewrites89.7%
if 6.99999975e-4 < (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1))) Initial 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%
Final simplification87.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9993000030517578) (* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) u2) 2.0)) (/ (- (sin (* (* u2 (PI)) 2.0))) (- (sqrt (/ 1.0 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}:\\
\;\;\;\;\frac{-\sin \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)}{-\sqrt{\frac{1}{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.9%
Taylor expanded in u2 around 0
Applied rewrites81.5%
if 0.9993 < (-.f32 #s(literal 1 binary32) u1) Initial program 40.7%
Applied rewrites15.8%
Applied rewrites37.2%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f32N/A
lower-sqrt.f32N/A
lower-/.f3289.6
Applied rewrites89.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9993000030517578) (* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) u2) 2.0)) (* (sin (* (PI) (+ u2 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(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\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.8%
Taylor expanded in u2 around 0
Applied rewrites81.5%
if 0.9993 < (-.f32 #s(literal 1 binary32) u1) Initial program 40.7%
Applied rewrites16.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.f3289.5
Applied rewrites89.5%
Applied rewrites89.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sin (* (PI) (+ u2 u2))) (sqrt u1)))
\begin{array}{l}
\\
\sin \left(\mathsf{PI}\left(\right) \cdot \left(u2 + u2\right)\right) \cdot \sqrt{u1}
\end{array}
Initial program 58.0%
Applied rewrites15.7%
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%
Applied rewrites75.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(/
(* -2.0 (* (PI) u2))
(/
(-
(*
(fma -0.25 (sqrt (/ 1.0 u1)) (* 0.041666666666666664 (sqrt u1)))
(* u1 u1))
(sqrt u1))
u1)))\begin{array}{l}
\\
\frac{-2 \cdot \left(\mathsf{PI}\left(\right) \cdot u2\right)}{\frac{\mathsf{fma}\left(-0.25, \sqrt{\frac{1}{u1}}, 0.041666666666666664 \cdot \sqrt{u1}\right) \cdot \left(u1 \cdot u1\right) - \sqrt{u1}}{u1}}
\end{array}
Initial program 58.0%
Applied rewrites13.7%
Applied rewrites35.0%
Taylor expanded in u1 around 0
lower-/.f32N/A
Applied rewrites75.9%
Taylor expanded in u2 around 0
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3267.0
Applied rewrites67.0%
(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))))