
(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 14 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 (* (sqrt (- (log1p (- u1)))) (sin (* (+ (PI) (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 58.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3258.6
Applied rewrites58.6%
lift--.f32N/A
lift-log.f32N/A
*-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f3298.4
Applied rewrites98.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))) (t_1 (* (* (PI) 2.0) u2)))
(if (<= t_0 -0.0052999998442828655)
(* (sqrt (- t_0)) t_1)
(* (sqrt (fma (* 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.0052999998442828655:\\
\;\;\;\;\sqrt{-t\_0} \cdot t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5 \cdot u1, u1, u1\right)} \cdot \sin t\_1\\
\end{array}
\end{array}
if (log.f32 (-.f32 #s(literal 1 binary32) u1)) < -0.00529999984Initial program 95.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3276.1
Applied rewrites76.1%
if -0.00529999984 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 47.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.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.4%
Applied rewrites98.4%
Taylor expanded in u1 around 0
Applied rewrites97.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.0052999998442828655)
(* (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.0052999998442828655:\\
\;\;\;\;\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.00529999984Initial program 95.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3276.1
Applied rewrites76.1%
if -0.00529999984 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 47.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3297.3
Applied rewrites97.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%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1)))
(*
(sqrt
(/
(- (* u1 u1) (* t_0 (* (* (fma 0.3333333333333333 u1 0.5) u1) u1)))
(- u1 t_0)))
(sin (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right) \cdot u1\right) \cdot u1\\
\sqrt{\frac{u1 \cdot u1 - t\_0 \cdot \left(\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right) \cdot u1\right) \cdot u1\right)}{u1 - t\_0}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
\end{array}
Initial program 58.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.f3294.0
Applied rewrites94.0%
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 rewrites94.0%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
flip-+N/A
lower-/.f32N/A
Applied rewrites93.9%
Taylor expanded in u1 around 0
Applied rewrites94.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(*
(sqrt
(/
(*
(fma
(- (* (- (* -0.3611111111111111 u1) 0.3333333333333333) u1) 0.25)
(* u1 u1)
1.0)
(* u1 u1))
(- u1 (* (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1))))
(sin (* (* 2.0 (PI)) u2))))\begin{array}{l}
\\
\sqrt{\frac{\mathsf{fma}\left(\left(-0.3611111111111111 \cdot u1 - 0.3333333333333333\right) \cdot u1 - 0.25, u1 \cdot u1, 1\right) \cdot \left(u1 \cdot u1\right)}{u1 - \left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right) \cdot u1\right) \cdot u1}} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 58.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.f3294.0
Applied rewrites94.0%
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 rewrites94.0%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
flip-+N/A
lower-/.f32N/A
Applied rewrites93.9%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f32N/A
pow2N/A
lift-*.f32N/A
pow2N/A
lift-*.f3294.1
Applied rewrites94.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma u1 1.0 (* u1 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1)))) (sin (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(u1, 1, u1 \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(0.25, u1, 0.3333333333333333\right), u1, 0.5\right) \cdot u1\right)\right)} \cdot \sin \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 58.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.f3294.0
Applied rewrites94.0%
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 rewrites94.0%
(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 58.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3258.6
Applied rewrites58.6%
lift--.f32N/A
lift-log.f32N/A
*-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f3298.4
Applied rewrites98.4%
Taylor expanded in u1 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.f32N/A
lift-fma.f3294.0
Applied rewrites94.0%
(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 58.6%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3258.6
Applied rewrites58.6%
lift--.f32N/A
lift-log.f32N/A
*-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f3298.4
Applied rewrites98.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3292.1
Applied rewrites92.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.0008999999845400453)
(*
(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.0008999999845400453:\\
\;\;\;\;\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.99999985e-4Initial program 58.9%
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.2
Applied rewrites94.2%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3293.3
Applied rewrites93.3%
if 8.99999985e-4 < u2 Initial program 58.0%
Taylor expanded in u1 around 0
Applied rewrites75.1%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3275.1
Applied rewrites75.1%
(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.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.f3294.0
Applied rewrites94.0%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.1
Applied rewrites79.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1)) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, 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.6%
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.f3275.1
Applied rewrites75.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3277.9
Applied rewrites77.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma u1 1.0 (* u1 (* 0.5 u1)))) (* (* (PI) 2.0) u2)))
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(u1, 1, u1 \cdot \left(0.5 \cdot u1\right)\right)} \cdot \left(\left(\mathsf{PI}\left(\right) \cdot 2\right) \cdot u2\right)
\end{array}
Initial program 58.6%
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.f3275.1
Applied rewrites75.1%
lift-*.f32N/A
lift-fma.f32N/A
*-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f3275.1
Applied rewrites75.1%
(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.6%
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.f3275.1
Applied rewrites75.1%
(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.6%
Taylor expanded in u1 around 0
Applied rewrites75.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3266.4
Applied rewrites66.4%
herbie shell --seed 2025073
(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))))