
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 17 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \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) (fma -2.0 u2 0.5)))))
\begin{array}{l}
\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)
\end{array}
Initial program 54.9%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3298.9
Applied rewrites98.9%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3299.0
Applied rewrites99.0%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3299.1
Applied rewrites99.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 (PI)) u2))))
(if (<= t_0 0.998199999332428)
(* (sqrt u1) t_0)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.998199999332428:\\
\;\;\;\;\sqrt{u1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\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 \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)) < 0.998199999Initial program 61.8%
lift-neg.f32N/A
lift-log.f32N/A
neg-logN/A
lower-log.f32N/A
lower-/.f3258.6
Applied rewrites58.6%
Taylor expanded in u1 around 0
lower-sqrt.f3274.3
Applied rewrites74.3%
if 0.998199999 < (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2)) Initial program 53.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.f3295.4
Applied rewrites95.4%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3295.3
Applied rewrites95.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (- (log1p (- u1)))) (cos (* (+ (PI) (PI)) u2))))
\begin{array}{l}
\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 54.9%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3298.9
Applied rewrites98.9%
lift-*.f32N/A
count-2-revN/A
lower-+.f3298.9
Applied rewrites98.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1)))
(*
(sqrt
(*
(/ (- 1.0 (* t_0 (* (fma 0.3333333333333333 u1 0.5) u1))) (- 1.0 t_0))
u1))
(sin (fma -2.0 (* u2 (PI)) (/ (PI) 2.0))))))\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{1 - t\_0 \cdot \left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right) \cdot u1\right)}{1 - t\_0} \cdot u1} \cdot \sin \left(\mathsf{fma}\left(-2, u2 \cdot \mathsf{PI}\left(\right), \frac{\mathsf{PI}\left(\right)}{2}\right)\right)
\end{array}
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3294.5
Applied rewrites94.5%
Applied rewrites94.5%
Taylor expanded in u1 around 0
Applied rewrites95.2%
Final simplification95.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.006000000052154064)
(* (sqrt (- (log1p (- u1)))) (fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0))
(*
(sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1))
(sin (* (PI) (fma -2.0 u2 0.5))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.006000000052154064:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)\\
\end{array}
\end{array}
if u2 < 0.00600000005Initial program 53.4%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3299.4
Applied rewrites99.4%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3299.3
Applied rewrites99.3%
if 0.00600000005 < u2 Initial program 59.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.f3291.9
Applied rewrites91.9%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3292.2
Applied rewrites92.2%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3292.5
Applied rewrites92.5%
Taylor expanded in u1 around 0
Applied rewrites90.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 u1)) (sin (* (PI) (fma -2.0 u2 0.5)))))
\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(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3294.5
Applied rewrites94.5%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3294.6
Applied rewrites94.6%
Applied rewrites94.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.006000000052154064)
(* (sqrt (- (log1p (- u1)))) (fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0))
(*
(sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1))
(cos (* (* 2.0 (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.006000000052154064:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 0.00600000005Initial program 53.4%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3299.4
Applied rewrites99.4%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3299.3
Applied rewrites99.3%
if 0.00600000005 < u2 Initial program 59.7%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3290.2
Applied rewrites90.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 u1)) (cos (* (* 2.0 (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 \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
Applied rewrites94.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 0.006000000052154064) (* (sqrt (- (log1p (- u1)))) (fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0)) (* (sqrt (* (fma 0.5 u1 1.0) u1)) (sin (* (PI) (fma -2.0 u2 0.5))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.006000000052154064:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)\\
\end{array}
\end{array}
if u2 < 0.00600000005Initial program 53.4%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3299.4
Applied rewrites99.4%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3299.3
Applied rewrites99.3%
if 0.00600000005 < u2 Initial program 59.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.f3291.9
Applied rewrites91.9%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3292.2
Applied rewrites92.2%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3292.5
Applied rewrites92.5%
Taylor expanded in u1 around 0
Applied rewrites87.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (cos (* (+ (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 \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
lift-*.f32N/A
count-2-revN/A
lower-+.f3294.5
Applied rewrites94.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 7.000000186963007e-5) (sqrt (- (log1p (- u1)))) (* (sqrt (* (fma 0.5 u1 1.0) u1)) (sin (* (PI) (fma -2.0 u2 0.5))))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 7.000000186963007 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)\\
\end{array}
\end{array}
if u2 < 7.00000019e-5Initial program 52.1%
lift-neg.f32N/A
lift-log.f32N/A
neg-logN/A
lower-log.f32N/A
lower-/.f3249.9
Applied rewrites49.9%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
log-recN/A
lower-neg.f32N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f3299.6
Applied rewrites99.6%
if 7.00000019e-5 < u2 Initial program 58.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.6
Applied rewrites93.6%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3293.8
Applied rewrites93.8%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3294.0
Applied rewrites94.0%
Taylor expanded in u1 around 0
Applied rewrites89.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 7.000000186963007e-5) (sqrt (- (log1p (- u1)))) (* (sqrt (* (fma 0.5 u1 1.0) u1)) (cos (* (* 2.0 (PI)) u2)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 7.000000186963007 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 7.00000019e-5Initial program 52.1%
lift-neg.f32N/A
lift-log.f32N/A
neg-logN/A
lower-log.f32N/A
lower-/.f3249.9
Applied rewrites49.9%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
log-recN/A
lower-neg.f32N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f3299.6
Applied rewrites99.6%
if 7.00000019e-5 < u2 Initial program 58.4%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3288.9
Applied rewrites88.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u2 0.009499999694526196)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0))
(* (sqrt (- (- u1))) (sin (* (PI) (fma -2.0 u2 0.5))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.009499999694526196:\\
\;\;\;\;\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 \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\left(-u1\right)} \cdot \sin \left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2, u2, 0.5\right)\right)\\
\end{array}
\end{array}
if u2 < 0.00949999969Initial program 53.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.f3295.4
Applied rewrites95.4%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3295.3
Applied rewrites95.3%
if 0.00949999969 < u2 Initial program 61.8%
lift-log.f32N/A
lift--.f32N/A
*-lft-identityN/A
fp-cancel-sub-sign-invN/A
distribute-lft-neg-inN/A
*-lft-identityN/A
lower-log1p.f32N/A
lower-neg.f3297.0
Applied rewrites97.0%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3297.4
Applied rewrites97.4%
Taylor expanded in u2 around 0
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
lower-PI.f32N/A
lower-fma.f3298.0
Applied rewrites98.0%
Taylor expanded in u1 around 0
mul-1-negN/A
lower-neg.f3274.4
Applied rewrites74.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (- (* (fma (* (* (PI) u2) (PI)) -2.0 0.0) u2) -1.0)))
\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(\left(\mathsf{PI}\left(\right) \cdot u2\right) \cdot \mathsf{PI}\left(\right), -2, 0\right) \cdot u2 - -1\right)
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3294.5
Applied rewrites94.5%
lift-sin.f32N/A
lift-fma.f32N/A
sin-sumN/A
sin-+PI/2N/A
lift-PI.f32N/A
lift-/.f32N/A
lift-fma.f32N/A
lift-sin.f32N/A
lift-/.f32N/A
lift-PI.f32N/A
sin-PI/2N/A
fp-cancel-sign-sub-invN/A
Applied rewrites94.4%
Taylor expanded in u2 around 0
Applied rewrites84.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) (fma (* -2.0 (* u2 u2)) (* (PI) (PI)) 1.0)))
\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 \mathsf{fma}\left(-2 \cdot \left(u2 \cdot u2\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 1\right)
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
Taylor expanded in u2 around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-PI.f3284.9
Applied rewrites84.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)) 1.0))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((fmaf(fmaf(fmaf(0.25f, u1, 0.3333333333333333f), u1, 0.5f), u1, 1.0f) * u1)) * 1.0f;
}
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(fma(fma(fma(Float32(0.25), u1, Float32(0.3333333333333333)), u1, Float32(0.5)), u1, Float32(1.0)) * u1)) * Float32(1.0)) end
\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 1
\end{array}
Initial program 54.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.5
Applied rewrites94.5%
lift-cos.f32N/A
cos-neg-revN/A
sin-+PI/2-revN/A
lower-sin.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-PI.f32N/A
lift-PI.f32N/A
associate-*l*N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lift-PI.f32N/A
lower-/.f3294.5
Applied rewrites94.5%
lift-sin.f32N/A
lift-fma.f32N/A
sin-sumN/A
sin-+PI/2N/A
lift-PI.f32N/A
lift-/.f32N/A
lift-fma.f32N/A
lift-sin.f32N/A
lift-/.f32N/A
lift-PI.f32N/A
sin-PI/2N/A
fp-cancel-sign-sub-invN/A
Applied rewrites94.4%
Taylor expanded in u2 around 0
cos-PIN/A
metadata-eval77.2
Applied rewrites77.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (- (- u1))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(-(-u1));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(4) function code(costheta_i, u1, u2)
use fmin_fmax_functions
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt(-(-u1))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(-Float32(-u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(-(-u1)); end
\begin{array}{l}
\\
\sqrt{-\left(-u1\right)}
\end{array}
Initial program 54.9%
Taylor expanded in u2 around 0
lower-*.f32N/A
lower-sqrt.f32N/A
*-lft-identityN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
lower-neg.f32N/A
lower-sqrt.f32-0.0
Applied rewrites-0.0%
Taylor expanded in u1 around 0
Applied rewrites-0.0%
Applied rewrites67.0%
Applied rewrites67.0%
Final simplification67.0%
herbie shell --seed 2024351
(FPCore (cosTheta_i u1 u2)
:name "Beckmann Sample, near normal, slope_x"
: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)))) (cos (* (* 2.0 (PI)) u2))))