
(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 11 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.03999999910593033)
(*
(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.03999999910593033:\\
\;\;\;\;\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.0399999991Initial program 52.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.f3298.3
Applied rewrites98.3%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3298.3
Applied rewrites98.3%
if 0.0399999991 < u1 Initial program 97.9%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.9
Applied rewrites97.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u1 0.07999999821186066)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(sin (* (+ (PI) (PI)) u2)))
(* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) 2.0) u2))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u1 \leq 0.07999999821186066:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0799999982Initial program 53.8%
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.f3297.9
Applied rewrites97.9%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.9
Applied rewrites97.9%
if 0.0799999982 < u1 Initial program 98.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3286.7
Applied rewrites86.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u1 0.02500000037252903)
(*
(sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1))
(sin (* (+ (PI) (PI)) u2)))
(* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) 2.0) u2))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u1 \leq 0.02500000037252903:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0250000004Initial program 51.6%
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.3
Applied rewrites98.3%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3298.3
Applied rewrites98.3%
Taylor expanded in u1 around 0
Applied rewrites97.9%
if 0.0250000004 < u1 Initial program 97.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3285.4
Applied rewrites85.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u1 0.017999999225139618) (* (sqrt (* (fma 0.5 u1 1.0) u1)) (sin (* (+ (PI) (PI)) u2))) (* (sqrt (- (log (- 1.0 u1)))) (* (* (PI) 2.0) u2))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u1 \leq 0.017999999225139618:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0179999992Initial program 50.6%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3295.8
Applied rewrites95.8%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3295.8
Applied rewrites95.8%
if 0.0179999992 < u1 Initial program 97.3%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3284.9
Applied rewrites84.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.029999999329447746)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(*
(fma
(* -1.3333333333333333 (* u2 u2))
(* (* (PI) (PI)) (PI))
(* (PI) 2.0))
u2))
(* (sqrt u1) (sin (* (+ (PI) (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.029999999329447746:\\
\;\;\;\;\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(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), \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 < 0.0299999993Initial program 60.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.f3292.9
Applied rewrites92.9%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3292.4
Applied rewrites92.4%
lift-PI.f32N/A
lift-pow.f32N/A
unpow3N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-PI.f3292.4
Applied rewrites92.4%
if 0.0299999993 < u2 Initial program 49.6%
Taylor expanded in u1 around 0
Applied rewrites83.8%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3283.8
Applied rewrites83.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (* (fma (* -1.3333333333333333 (* u2 u2)) (* (* (PI) (PI)) (PI)) (* (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(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), \mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 58.8%
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.4
Applied rewrites93.4%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3283.5
Applied rewrites83.5%
lift-PI.f32N/A
lift-pow.f32N/A
unpow3N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-PI.f3283.5
Applied rewrites83.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (PI) 2.0)))
(if (<= u2 0.0017999999690800905)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(* t_0 u2))
(*
(sqrt u1)
(*
(fma (* -1.3333333333333333 (* u2 u2)) (* (* (PI) (PI)) (PI)) t_0)
u2)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 2\\
\mathbf{if}\;u2 \leq 0.0017999999690800905:\\
\;\;\;\;\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(t\_0 \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \left(\mathsf{fma}\left(-1.3333333333333333 \cdot \left(u2 \cdot u2\right), \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), t\_0\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 0.00179999997Initial program 60.6%
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.0
Applied rewrites93.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3291.6
Applied rewrites91.6%
if 0.00179999997 < u2 Initial program 55.1%
Taylor expanded in u1 around 0
Applied rewrites79.2%
Taylor expanded in u2 around 0
*-commutativeN/A
lower-*.f32N/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-pow.f32N/A
lift-PI.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3255.7
Applied rewrites55.7%
lift-PI.f32N/A
lift-pow.f32N/A
unpow3N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
lift-PI.f3255.7
Applied rewrites55.7%
(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 58.8%
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.4
Applied rewrites93.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3275.8
Applied rewrites75.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma u1 1.0 (* u1 (* 0.5 u1)))) (* 2.0 (* (PI) u2))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(u1, 1, u1 \cdot \left(0.5 \cdot u1\right)\right)} \cdot \left(2 \cdot \left(\mathsf{PI}\left(\right) \cdot u2\right)\right)
\end{array}
Initial program 58.8%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.1
Applied rewrites88.1%
lift-sin.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
sin-2N/A
lower-*.f32N/A
lower-*.f32N/A
lower-sin.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3288.0
Applied rewrites88.0%
Taylor expanded in u2 around 0
*-commutativeN/A
lift-*.f32N/A
lift-PI.f3271.8
Applied rewrites71.8%
lift-*.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f3271.9
Applied rewrites71.9%
(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 58.8%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.1
Applied rewrites88.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3271.8
Applied rewrites71.8%
(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 58.8%
Taylor expanded in u1 around 0
Applied rewrites76.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3263.8
Applied rewrites63.8%
herbie shell --seed 2025051
(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))))