
(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 14 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 (* (cos (* (* u2 (PI)) 2.0)) (sqrt (- (log1p (- u1))))))
\begin{array}{l}
\\
\cos \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
Initial program 59.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.3
Applied rewrites93.3%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3293.4
Applied rewrites93.4%
Taylor expanded in u2 around inf
associate-*l*N/A
*-commutativeN/A
sqrt-prodN/A
lower-*.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.f32N/A
*-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
mul-1-negN/A
lower-log1p.f32N/A
Applied rewrites98.9%
sin-+PI/2-revN/A
associate-*l*N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
lower-cos.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f32N/A
lower-PI.f32N/A
lower-sqrt.f32N/A
Applied rewrites98.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 (PI)) u2))))
(if (<= (* (sqrt (- (log (- 1.0 u1)))) t_0) 0.3149999976158142)
(*
(sqrt
(fma
u1
1.0
(* u1 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1))))
t_0)
(sqrt (- (log1p (- u1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0 \leq 0.3149999976158142:\\
\;\;\;\;\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 t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) < 0.314999998Initial program 54.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%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3298.4
Applied rewrites98.4%
if 0.314999998 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) Initial program 98.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.f3255.6
Applied rewrites55.6%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3255.6
Applied rewrites55.6%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3288.8
Applied rewrites88.8%
Final simplification97.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<=
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2)))
0.3149999976158142)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
(cos (* (+ (PI) (PI)) u2)))
(sqrt (- (log1p (- u1))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \leq 0.3149999976158142:\\
\;\;\;\;\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)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) < 0.314999998Initial program 54.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%
count-2-revN/A
lower-+.f32N/A
lower-PI.f32N/A
lower-PI.f3298.3
Applied rewrites98.3%
if 0.314999998 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) Initial program 98.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.f3255.6
Applied rewrites55.6%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3255.6
Applied rewrites55.6%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3288.8
Applied rewrites88.8%
Final simplification97.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 (PI)) u2))))
(if (<= (* (sqrt (- (log (- 1.0 u1)))) t_0) 0.17499999701976776)
(* (sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1)) t_0)
(sqrt (- (log1p (- u1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0 \leq 0.17499999701976776:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) < 0.174999997Initial program 52.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3298.0
Applied rewrites98.0%
if 0.174999997 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) Initial program 98.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.f3264.8
Applied rewrites64.8%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3264.8
Applied rewrites64.8%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3286.9
Applied rewrites86.9%
Final simplification96.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* (* 2.0 (PI)) u2))))
(if (<= (* (sqrt (- (log (- 1.0 u1)))) t_0) 0.10000000149011612)
(* (sqrt (fma u1 1.0 (* u1 (* 0.5 u1)))) t_0)
(sqrt (- (log1p (- u1)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0 \leq 0.10000000149011612:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(u1, 1, u1 \cdot \left(0.5 \cdot u1\right)\right)} \cdot t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) < 0.100000001Initial program 49.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3296.6
Applied rewrites96.6%
*-commutativeN/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f3296.8
Applied rewrites96.8%
if 0.100000001 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) Initial program 96.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.f3273.0
Applied rewrites73.0%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3273.1
Applied rewrites73.1%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3286.5
Applied rewrites86.5%
Final simplification94.6%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<=
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2)))
0.10000000149011612)
(* (sqrt (* (fma 0.5 u1 1.0) u1)) (cos (* (+ (PI) (PI)) u2)))
(sqrt (- (log1p (- u1))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right) \leq 0.10000000149011612:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) < 0.100000001Initial program 49.5%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3296.6
Applied rewrites96.6%
count-2-revN/A
lower-+.f32N/A
lower-PI.f32N/A
lower-PI.f3296.6
Applied rewrites96.6%
if 0.100000001 < (*.f32 (sqrt.f32 (neg.f32 (log.f32 (-.f32 #s(literal 1 binary32) u1)))) (cos.f32 (*.f32 (*.f32 #s(literal 2 binary32) (PI.f32)) u2))) Initial program 96.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.f3273.0
Applied rewrites73.0%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3273.1
Applied rewrites73.1%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3286.5
Applied rewrites86.5%
Final simplification94.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= u1 0.03400000184774399)
(*
(sqrt
(fma u1 1.0 (* u1 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1))))
(cos (* (* 2.0 (PI)) u2)))
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (+ (PI) (PI)) u2)))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u1 \leq 0.03400000184774399:\\
\;\;\;\;\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 \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u1 < 0.0340000018Initial program 52.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.f3298.7
Applied rewrites98.7%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3298.8
Applied rewrites98.8%
if 0.0340000018 < u1 Initial program 98.3%
count-2-revN/A
lower-+.f32N/A
lower-PI.f32N/A
lower-PI.f3298.3
Applied rewrites98.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 0.0020000000949949026) (sqrt (- (log1p (- u1)))) (* (sqrt u1) (cos (* (* 2.0 (PI)) u2)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.0020000000949949026:\\
\;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \cos \left(\left(2 \cdot \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\end{array}
\end{array}
if u2 < 0.00200000009Initial program 60.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.f3292.4
Applied rewrites92.4%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3292.6
Applied rewrites92.6%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3295.8
Applied rewrites95.8%
if 0.00200000009 < u2 Initial program 57.1%
Taylor expanded in u1 around 0
Applied rewrites77.7%
Final simplification90.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (- (log1p (- u1)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(-log1pf(-u1));
}
function code(cosTheta_i, u1, u2) return sqrt(Float32(-log1p(Float32(-u1)))) end
\begin{array}{l}
\\
\sqrt{-\mathsf{log1p}\left(-u1\right)}
\end{array}
Initial program 59.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.3
Applied rewrites93.3%
+-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
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3293.4
Applied rewrites93.4%
Taylor expanded in u2 around 0
sqrt-prodN/A
lower-sqrt.f32N/A
*-commutativeN/A
lower-*.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.f3278.7
Applied rewrites78.7%
Final simplification78.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (fma (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1) u1 u1)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(fmaf((fmaf(fmaf(0.25f, u1, 0.3333333333333333f), u1, 0.5f) * u1), u1, u1));
}
function code(cosTheta_i, u1, u2) return sqrt(fma(Float32(fma(fma(Float32(0.25), u1, Float32(0.3333333333333333)), u1, Float32(0.5)) * u1), u1, u1)) end
\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)}
\end{array}
Initial program 59.5%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lower-log.f32N/A
lower--.f3251.1
Applied rewrites51.1%
Taylor expanded in u1 around 0
Applied rewrites63.7%
Taylor expanded in u1 around 0
distribute-lft-inN/A
*-rgt-identityN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f3274.5
Applied rewrites74.5%
Final simplification74.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1)))
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));
}
function code(cosTheta_i, u1, u2) return sqrt(Float32(fma(fma(fma(Float32(0.25), u1, Float32(0.3333333333333333)), u1, Float32(0.5)), u1, Float32(1.0)) * u1)) 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}
\end{array}
Initial program 59.5%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lower-log.f32N/A
lower--.f3251.1
Applied rewrites51.1%
Taylor expanded in u1 around 0
*-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
+-commutativeN/A
lower-*.f32N/A
lower-fma.f32N/A
lower-fma.f32N/A
lower-fma.f3274.3
Applied rewrites74.3%
Final simplification74.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (fma (fma 0.3333333333333333 u1 0.5) u1 1.0) u1)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((fmaf(fmaf(0.3333333333333333f, u1, 0.5f), u1, 1.0f) * u1));
}
function code(cosTheta_i, u1, u2) return sqrt(Float32(fma(fma(Float32(0.3333333333333333), u1, Float32(0.5)), u1, Float32(1.0)) * u1)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(0.3333333333333333, u1, 0.5\right), u1, 1\right) \cdot u1}
\end{array}
Initial program 59.5%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lower-log.f32N/A
lower--.f3251.1
Applied rewrites51.1%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3273.2
Applied rewrites73.2%
Final simplification73.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (fma 0.5 u1 1.0) u1)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((fmaf(0.5f, u1, 1.0f) * u1));
}
function code(cosTheta_i, u1, u2) return sqrt(Float32(fma(Float32(0.5), u1, Float32(1.0)) * u1)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(0.5, u1, 1\right) \cdot u1}
\end{array}
Initial program 59.5%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lower-log.f32N/A
lower--.f3251.1
Applied rewrites51.1%
Taylor expanded in u1 around 0
+-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
lower-fma.f3270.7
Applied rewrites70.7%
Final simplification70.7%
(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(u1) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(u1); end
\begin{array}{l}
\\
\sqrt{u1}
\end{array}
Initial program 59.5%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lower-log.f32N/A
lower--.f3251.1
Applied rewrites51.1%
Taylor expanded in u1 around 0
Applied rewrites63.7%
Final simplification63.7%
herbie shell --seed 2025043
(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))))