
(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 (sin (* u2 (* (PI) 2.0)))))
(if (<= u1 0.00015999999595806003)
(* t_0 (pow (* u1 u1) 0.25))
(* (sqrt (- (log (- 1.0 u1)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 0.00015999999595806003:\\
\;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 1.59999996e-4Initial program 43.2%
Applied rewrites32.5%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3290.6
Applied rewrites90.6%
if 1.59999996e-4 < u1 Initial program 89.9%
Final simplification90.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (PI))) (t_1 (sin (* u2 (* (PI) 2.0)))))
(if (<= u1 4.4999998749517545e-7)
(* t_1 (pow (* u1 u1) 0.25))
(if (<= u1 0.0038399999029934406)
(*
(sqrt
(-
(* (/ (- 1.0 (* 0.25 (* u1 u1))) (- 1.0 (* -0.5 u1))) u1)
(log1p (* (- u1) u1))))
t_1)
(* (* (* (sin t_0) (cos t_0)) 2.0) (sqrt (- (log (- 1.0 u1)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \mathsf{PI}\left(\right)\\
t_1 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
\;\;\;\;t\_1 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
\mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
\;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\sin t\_0 \cdot \cos t\_0\right) \cdot 2\right) \cdot \sqrt{-\log \left(1 - u1\right)}\\
\end{array}
\end{array}
if u1 < 4.49999987e-7Initial program 21.5%
Applied rewrites37.7%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3298.5
Applied rewrites98.5%
if 4.49999987e-7 < u1 < 0.0038399999Initial program 66.2%
Applied rewrites33.9%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3216.3
Applied rewrites16.6%
Applied rewrites58.2%
if 0.0038399999 < u1 Initial program 94.7%
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-*.f3294.7
Applied rewrites94.7%
Final simplification68.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* u2 (* (PI) 2.0)))))
(if (<= u1 4.4999998749517545e-7)
(* t_0 (pow (* u1 u1) 0.25))
(if (<= u1 0.0038399999029934406)
(*
(sqrt
(-
(* (/ (- 1.0 (* 0.25 (* u1 u1))) (- 1.0 (* -0.5 u1))) u1)
(log1p (* (- u1) u1))))
t_0)
(* (sqrt (- (log (- 1.0 u1)))) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
\;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
\mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
\;\;\;\;\sqrt{\frac{1 - 0.25 \cdot \left(u1 \cdot u1\right)}{1 - -0.5 \cdot u1} \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 4.49999987e-7Initial program 21.5%
Applied rewrites35.1%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3298.5
Applied rewrites98.5%
if 4.49999987e-7 < u1 < 0.0038399999Initial program 66.2%
Applied rewrites35.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3216.6
Applied rewrites16.1%
Applied rewrites59.4%
if 0.0038399999 < u1 Initial program 94.7%
Final simplification68.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sin (* u2 (* (PI) 2.0)))))
(if (<= u1 4.4999998749517545e-7)
(* t_0 (pow (* u1 u1) 0.25))
(if (<= u1 0.0038399999029934406)
(* (sqrt (- (* (+ (* -0.5 u1) 1.0) u1) (log1p (* (- u1) u1)))) t_0)
(* (sqrt (- (log (- 1.0 u1)))) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)\\
\mathbf{if}\;u1 \leq 4.4999998749517545 \cdot 10^{-7}:\\
\;\;\;\;t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
\mathbf{elif}\;u1 \leq 0.0038399999029934406:\\
\;\;\;\;\sqrt{\left(-0.5 \cdot u1 + 1\right) \cdot u1 - \mathsf{log1p}\left(\left(-u1\right) \cdot u1\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 4.49999987e-7Initial program 21.5%
Applied rewrites36.4%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3298.5
Applied rewrites98.5%
if 4.49999987e-7 < u1 < 0.0038399999Initial program 66.2%
Applied rewrites35.2%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3217.9
Applied rewrites13.7%
Applied rewrites51.2%
if 0.0038399999 < u1 Initial program 94.7%
Final simplification68.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (* (PI) 2.0))))
(if (<= (- 1.0 u1) 0.9993000030517578)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sin t_0) (pow (* u1 u1) 0.25)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\
\;\;\;\;t\_0 \cdot \sqrt{-\log \left(1 - u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin t\_0 \cdot {\left(u1 \cdot u1\right)}^{0.25}\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) u1) < 0.9993Initial program 92.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.1
Applied rewrites80.1%
if 0.9993 < (-.f32 #s(literal 1 binary32) u1) Initial program 45.7%
Applied rewrites31.1%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3289.0
Applied rewrites89.0%
Final simplification85.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u2 (* (PI) 2.0))))
(if (<= (- 1.0 u1) 0.9993000030517578)
(* t_0 (sqrt (- (log (- 1.0 u1)))))
(* (sqrt u1) (sin t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\\
\mathbf{if}\;1 - u1 \leq 0.9993000030517578:\\
\;\;\;\;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.9993Initial program 92.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3280.1
Applied rewrites80.1%
if 0.9993 < (-.f32 #s(literal 1 binary32) u1) Initial program 45.7%
Applied rewrites32.3%
Taylor expanded in u1 around 0
lower-sqrt.f3288.9
Applied rewrites88.9%
Final simplification85.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (sin (* u2 (* (PI) 2.0)))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \sin \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)
\end{array}
Initial program 62.5%
Applied rewrites26.2%
Taylor expanded in u1 around 0
lower-sqrt.f3274.3
Applied rewrites74.3%
Final simplification74.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* (* u2 (PI)) 2.0) (pow (* u1 u1) 0.25)))
\begin{array}{l}
\\
\left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot {\left(u1 \cdot u1\right)}^{0.25}
\end{array}
Initial program 62.5%
Applied rewrites26.7%
Taylor expanded in u1 around 0
unpow2N/A
lower-*.f3274.3
Applied rewrites74.3%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.6
Applied rewrites65.6%
Final simplification65.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (* u2 (* (PI) 2.0))))
\begin{array}{l}
\\
\sqrt{u1} \cdot \left(u2 \cdot \left(\mathsf{PI}\left(\right) \cdot 2\right)\right)
\end{array}
Initial program 62.5%
Applied rewrites27.1%
Taylor expanded in u1 around 0
lower-sqrt.f3274.3
Applied rewrites74.3%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-PI.f3265.6
Applied rewrites65.6%
Final simplification65.6%
herbie shell --seed 2024268
(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))))