
(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.03500000014901161)
(*
(sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 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.03500000014901161:\\
\;\;\;\;\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\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 0.0350000001Initial program 50.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-*.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%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.f3298.4
Applied rewrites98.4%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3298.4
Applied rewrites98.4%
if 0.0350000001 < u1 Initial program 97.7%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.7
Applied rewrites97.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.04500000178813934)
(* (sqrt (- t_0)) (* (* (PI) 2.0) u2))
(*
(sqrt (fma (* (fma 0.3333333333333333 u1 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.04500000178813934:\\
\;\;\;\;\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) \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.0450000018Initial 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.f3284.7
Applied rewrites84.7%
if -0.0450000018 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 51.1%
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%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.f3298.4
Applied rewrites98.4%
Taylor expanded in u1 around 0
Applied rewrites97.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.04500000178813934)
(* (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.04500000178813934:\\
\;\;\;\;\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.0450000018Initial 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.f3284.7
Applied rewrites84.7%
if -0.0450000018 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 51.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3297.6
Applied rewrites97.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (log (- 1.0 u1))))
(if (<= t_0 -0.007499999832361937)
(* (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.007499999832361937:\\
\;\;\;\;\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.00749999983Initial program 95.6%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3283.5
Applied rewrites83.5%
if -0.00749999983 < (log.f32 (-.f32 #s(literal 1 binary32) u1)) Initial program 47.0%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3297.1
Applied rewrites97.1%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.1
Applied rewrites97.1%
(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 57.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.f3294.1
Applied rewrites94.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 rewrites94.2%
lift-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
*-rgt-identityN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.f3294.2
Applied rewrites94.2%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3294.2
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 57.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.f3294.1
Applied rewrites94.1%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3294.1
Applied rewrites94.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.003000000026077032)
(*
(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.003000000026077032:\\
\;\;\;\;\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 < 0.00300000003Initial program 57.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.9
Applied rewrites93.9%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3291.3
Applied rewrites91.3%
if 0.00300000003 < u2 Initial program 55.7%
Taylor expanded in u1 around 0
Applied rewrites78.8%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3278.8
Applied rewrites78.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (PI) 2.0)))
(if (<= u2 0.003000000026077032)
(*
(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.003000000026077032:\\
\;\;\;\;\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.00300000003Initial program 57.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.9
Applied rewrites93.9%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3291.3
Applied rewrites91.3%
if 0.00300000003 < u2 Initial program 55.7%
Taylor expanded in u1 around 0
Applied rewrites78.8%
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.f3256.5
Applied rewrites56.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.f3256.5
Applied rewrites56.5%
(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 57.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.f3294.1
Applied rewrites94.1%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3279.2
Applied rewrites79.2%
(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 57.3%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.7
Applied rewrites88.7%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3275.3
Applied rewrites75.3%
(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 57.3%
Taylor expanded in u1 around 0
Applied rewrites77.5%
Taylor expanded in u2 around 0
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f3267.7
Applied rewrites67.7%
herbie shell --seed 2025027
(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))))