
(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 (* (PI) u2)) (t_1 (* (sin t_0) (cos t_0))))
(if (<= (- 1.0 u1) 0.9998900294303894)
(* (* 2.0 t_1) (sqrt (- (log (- 1.0 u1)))))
(* (* (sqrt (- (- u1))) 2.0) t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot u2\\
t_1 := \sin t\_0 \cdot \cos t\_0\\
\mathbf{if}\;1 - u1 \leq 0.9998900294303894:\\
\;\;\;\;\left(2 \cdot t\_1\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot 2\right) \cdot t\_1\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999890029Initial program 88.5%
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-*.f3288.6
Applied rewrites88.6%
if 0.999890029 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.4
Applied rewrites92.4%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
associate-*r*N/A
lower-*.f32N/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-*.f3292.5
Applied rewrites92.5%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (PI) u2)))
(if (<= (- 1.0 u1) 0.9998900294303894)
(* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1)))))
(* (* (sqrt (- (- u1))) 2.0) (* (sin t_0) (cos t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9998900294303894:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(\sqrt{-\left(-u1\right)} \cdot 2\right) \cdot \left(\sin t\_0 \cdot \cos t\_0\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999890029Initial program 88.5%
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.f3288.1
Applied rewrites88.1%
lift-*.f32N/A
lift-pow.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3288.1
Applied rewrites88.1%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
associate-*r*N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
add-cube-cbrtN/A
lift-PI.f32N/A
Applied rewrites88.5%
if 0.999890029 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.4
Applied rewrites92.4%
lift-*.f32N/A
lift-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
sin-2N/A
associate-*r*N/A
lower-*.f32N/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-*.f3292.5
Applied rewrites92.5%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (- 1.0 u1) 0.9998900294303894) (* (sin (* (+ u2 u2) (PI))) (sqrt (- (log (- 1.0 u1))))) (* (sin (* (* 2.0 (PI)) u2)) (sqrt (* (/ -1.0 (- u1)) (* u1 u1))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;1 - u1 \leq 0.9998900294303894:\\
\;\;\;\;\sin \left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{\frac{-1}{-u1} \cdot \left(u1 \cdot u1\right)}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999890029Initial program 88.5%
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.f3288.1
Applied rewrites88.1%
lift-*.f32N/A
lift-pow.f32N/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3288.1
Applied rewrites88.1%
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
associate-*r*N/A
lift-cbrt.f32N/A
lift-PI.f32N/A
add-cube-cbrtN/A
lift-PI.f32N/A
Applied rewrites88.5%
if 0.999890029 < (-.f32 #s(literal 1 binary32) u1) Initial program 37.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3292.4
Applied rewrites92.4%
lift-neg.f32N/A
neg-sub0N/A
flip--N/A
div-invN/A
lower-*.f32N/A
Applied rewrites92.4%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3292.4
Applied rewrites92.4%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* 2.0 (PI)) u2)))
(if (<= (- 1.0 u1) 0.9996100068092346)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sin t_0) (sqrt (* (/ -1.0 (- u1)) (* u1 u1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9996100068092346:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin t\_0 \cdot \sqrt{\frac{-1}{-u1} \cdot \left(u1 \cdot u1\right)}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.999610007Initial program 90.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.6
Applied rewrites74.6%
if 0.999610007 < (-.f32 #s(literal 1 binary32) u1) Initial program 41.1%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3290.2
Applied rewrites90.2%
lift-neg.f32N/A
neg-sub0N/A
flip--N/A
div-invN/A
lower-*.f32N/A
Applied rewrites90.3%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3290.3
Applied rewrites90.3%
Final simplification84.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* 2.0 (PI)) u2)))
(if (<= (- 1.0 u1) 0.9996100068092346)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\\
\mathbf{if}\;1 - u1 \leq 0.9996100068092346:\\
\;\;\;\;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.999610007Initial program 90.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3274.6
Applied rewrites74.6%
if 0.999610007 < (-.f32 #s(literal 1 binary32) u1) Initial program 41.1%
Applied rewrites30.3%
Taylor expanded in u1 around 0
lower-sqrt.f3290.2
Applied rewrites90.2%
Final simplification84.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 60.1%
Applied rewrites25.7%
Taylor expanded in u1 around 0
lower-sqrt.f3275.1
Applied rewrites75.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* 2.0 (PI)) u2) (sqrt (- (- u1)))))
\begin{array}{l}
\\
\left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \cdot \sqrt{-\left(-u1\right)}
\end{array}
Initial program 60.1%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3275.1
Applied rewrites75.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3264.0
Applied rewrites64.0%
Final simplification64.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (fma u2 (PI) (* (PI) u2)) (- (sqrt u1))))
\begin{array}{l}
\\
\mathsf{fma}\left(u2, \mathsf{PI}\left(\right), \mathsf{PI}\left(\right) \cdot u2\right) \cdot \left(-\sqrt{u1}\right)
\end{array}
Initial program 60.1%
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.9
Applied rewrites4.9%
Applied rewrites5.0%
Final simplification5.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (+ u2 u2) (PI)) (- (sqrt u1))))
\begin{array}{l}
\\
\left(\left(u2 + u2\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \left(-\sqrt{u1}\right)
\end{array}
Initial program 60.1%
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.9
Applied rewrites4.9%
Applied rewrites4.9%
Final simplification4.9%
herbie shell --seed 2024270
(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))))