
(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 13 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 (log (- 1.0 u1))) (t_1 (sin (* (+ (PI) (PI)) u2))))
(if (<= t_0 -0.029999999329447746)
(* (sqrt (- t_0)) t_1)
(*
(sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 u1))
t_1))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
t_1 := \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq -0.029999999329447746:\\
\;\;\;\;\sqrt{-t\_0} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right) \cdot u1, u1, u1\right)} \cdot t\_1\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.0299999993Initial program 97.3%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.3
Applied rewrites97.3%
if -0.0299999993 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 47.3%
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-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites98.3%
Applied rewrites98.3%
lift-PI.f32N/A
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3298.3
Applied rewrites98.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))) (t_1 (* (* (PI) 2.0) u2)))
(if (<= t_0 -0.0494999997317791)
(* (sqrt (- t_0)) t_1)
(* (sqrt (fma (* (fma 0.3333333333333333 u1 0.5) u1) u1 u1)) (sin t_1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
t_1 := \left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\\
\mathbf{if}\;t\_0 \leq -0.0494999997317791:\\
\;\;\;\;\sqrt{-t\_0} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right) \cdot u1, u1, u1\right)} \cdot \sin t\_1\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.0494999997Initial program 97.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3281.7
Applied rewrites81.7%
if -0.0494999997 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 48.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.f3298.1
Applied rewrites98.1%
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites98.1%
Applied rewrites98.1%
Taylor expanded in u1 around 0
Applied rewrites97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.0494999997317791)
(* (sqrt (- t_0)) (* (* (PI) 2.0) u2))
(*
(sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1))
(sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq -0.0494999997317791:\\
\;\;\;\;\sqrt{-t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.0494999997Initial program 97.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3281.7
Applied rewrites81.7%
if -0.0494999997 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 48.8%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3297.1
Applied rewrites97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.010999999940395355)
(* (sqrt (- t_0)) (* (* (PI) 2.0) u2))
(* (sqrt (fma (* 0.5 u1) u1 u1)) (sin (* (* 2.0 (PI)) u2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \log \left(1 - u1\right)\\
\mathbf{if}\;t\_0 \leq -0.010999999940395355:\\
\;\;\;\;\sqrt{-t\_0} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5 \cdot u1, u1, u1\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.0109999999Initial program 95.5%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.6
Applied rewrites79.6%
if -0.0109999999 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 44.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3296.6
Applied rewrites96.6%
lift-*.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f3296.7
Applied rewrites96.7%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-*.f3296.7
Applied rewrites96.7%
(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 (* (* 2.0 (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(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
\end{array}
Initial program 54.5%
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-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.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 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) \cdot u1, u1, u1\right)} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 54.5%
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-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
Applied rewrites93.7%
Applied rewrites93.7%
lift-PI.f32N/A
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3293.7
Applied rewrites93.7%
(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 54.5%
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 (if (<= u1 0.010999999940395355) (* (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.010999999940395355:\\
\;\;\;\;\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.0109999999Initial program 44.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3296.6
Applied rewrites96.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3296.6
Applied rewrites96.6%
if 0.0109999999 < u1 Initial program 95.5%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.6
Applied rewrites79.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.0008200000156648457)
(*
(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.0008200000156648457:\\
\;\;\;\;\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 < 8.20000016e-4Initial program 56.2%
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.4
Applied rewrites94.4%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3293.4
Applied rewrites93.4%
if 8.20000016e-4 < u2 Initial program 51.2%
Taylor expanded in u1 around 0
Applied rewrites78.9%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3278.9
Applied rewrites78.9%
(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 54.5%
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.f3278.1
Applied rewrites78.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (+ u1 (* (* 0.5 u1) u1))) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{u1 + \left(0.5 \cdot u1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 54.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.2
Applied rewrites88.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3274.0
Applied rewrites74.0%
lift-*.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
*-commutativeN/A
*-rgt-identityN/A
lower-+.f32N/A
lower-*.f32N/A
lower-*.f3274.1
Applied rewrites74.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma 0.5 u1 1.0) u1)) (* (+ (PI) (PI)) u2)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 54.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.2
Applied rewrites88.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3274.0
Applied rewrites74.0%
lift-PI.f32N/A
lift-*.f32N/A
*-commutativeN/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3274.0
Applied rewrites74.0%
(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 54.5%
Taylor expanded in u1 around 0
Applied rewrites77.8%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3266.6
Applied rewrites66.6%
herbie shell --seed 2025046
(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))))