
(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 (* (+ (PI) (PI)) u2))))
(if (<= u1 0.02500000037252903)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
t_0)
(* (sqrt (- (log (- 1.0 u1)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;u1 \leq 0.02500000037252903:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right), u1, 1\right) \cdot u1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 0.0250000004Initial program 48.7%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3298.5
Applied rewrites98.5%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3298.5
Applied rewrites98.5%
if 0.0250000004 < u1 Initial program 97.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.6
Applied rewrites97.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.006000000052154064)
(* (sqrt (- t_0)) (* (* (PI) 2.0) u2))
(* (sqrt (* (fma 0.5 u1 1.0) u1)) (sin (* (+ (PI) (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq -0.006000000052154064:\\
\;\;\;\;\sqrt{-t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.00600000005Initial program 95.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.0
Applied rewrites79.0%
if -0.00600000005 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 44.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3297.6
Applied rewrites97.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.6
Applied rewrites97.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1)))
(*
(sqrt
(*
(/ (- (* t_0 (* (fma 0.3333333333333333 u1 0.5) u1)) 1.0) (- t_0 1.0))
u1))
(sin (* (+ (PI) (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right) \cdot u1\\
\sqrt{\frac{t\_0 \cdot \left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right) \cdot u1\right) - 1}{t\_0 - 1} \cdot u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3293.7
Applied rewrites93.7%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3293.7
Applied rewrites93.7%
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
flip-+N/A
lower-/.f32N/A
Applied rewrites93.5%
Taylor expanded in u1 around 0
Applied rewrites94.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (sin (* (+ (PI) (PI)) u2))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3293.7
Applied rewrites93.7%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3293.7
Applied rewrites93.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1)) (sin (* (+ (PI) (PI)) u2))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3293.7
Applied rewrites93.7%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3293.7
Applied rewrites93.7%
Taylor expanded in u1 around 0
Applied rewrites92.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.0006799999973736703)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(* (* (PI) 2.0) u2))
(* (sqrt u1) (sin (* (+ (PI) (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.0006799999973736703:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 6.79999997e-4Initial program 57.0%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3294.7
Applied rewrites94.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3293.8
Applied rewrites93.8%
if 6.79999997e-4 < u2 Initial program 54.9%
Taylor expanded in u1 around 0
Applied rewrites75.2%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3275.2
Applied rewrites75.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3293.7
Applied rewrites93.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.3
Applied rewrites79.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma 0.5 u1 1.0) u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.4
Applied rewrites88.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3275.7
Applied rewrites75.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt u1) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 56.4%
Taylor expanded in u1 around 0
Applied rewrites76.8%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3267.3
Applied rewrites67.3%
herbie shell --seed 2025037
(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))))