
(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 (* (sqrt (- (log1p (- u1)))) (cos (* (* u2 (PI)) 2.0))))
\begin{array}{l}
\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\right)
\end{array}
Initial program 56.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.f3294.2
Applied rewrites94.2%
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%
Taylor expanded in u2 around inf
count-2-revN/A
associate-*l*N/A
*-commutativeN/A
sqrt-prodN/A
lower-*.f32N/A
Applied rewrites99.2%
Applied rewrites99.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.1599999964237213)
(* (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.1599999964237213:\\
\;\;\;\;\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.159999996Initial program 49.4%
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.159999996 < (*.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 97.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.f3266.1
Applied rewrites66.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 rewrites66.1%
Taylor expanded in u2 around 0
count-2-revN/A
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.f3284.0
Applied rewrites84.0%
Final simplification96.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<=
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2)))
0.07500000298023224)
(* (sqrt (fma (* 0.5 u1) u1 u1)) (cos (* (* u2 (PI)) 2.0)))
(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.07500000298023224:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(0.5 \cdot u1, u1, u1\right)} \cdot \cos \left(\left(u2 \cdot \mathsf{PI}\left(\right)\right) \cdot 2\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.075000003Initial program 44.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.f3299.1
Applied rewrites99.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 rewrites99.1%
Taylor expanded in u1 around 0
Applied rewrites97.7%
lift-fma.f32N/A
*-rgt-identityN/A
+-commutativeN/A
lift-*.f32N/A
*-commutativeN/A
lower-fma.f3297.7
lower-fma.f32N/A
lower-fma.f32N/A
lower-fma.f32N/A
lower-fma.f32N/A
lower-fma.f32N/A
Applied rewrites97.7%
if 0.075000003 < (*.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 95.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.f3277.2
Applied rewrites77.2%
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 rewrites77.2%
Taylor expanded in u2 around 0
count-2-revN/A
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.f3283.5
Applied rewrites83.5%
Final simplification94.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<=
(* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 (PI)) u2)))
0.07500000298023224)
(* (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.07500000298023224:\\
\;\;\;\;\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.075000003Initial program 44.8%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3297.7
Applied rewrites97.7%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.7
Applied rewrites97.7%
if 0.075000003 < (*.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 95.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.f3277.2
Applied rewrites77.2%
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 rewrites77.2%
Taylor expanded in u2 around 0
count-2-revN/A
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.f3283.5
Applied rewrites83.5%
Final simplification94.5%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* (+ (PI) (PI)) u2))))
(if (<= u1 0.02500000037252903)
(*
(sqrt (* (fma (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1 1.0) u1))
t_0)
(* (sqrt (- (log (- 1.0 u1)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(\mathsf{PI}\left(\right) + \mathsf{PI}\left(\right)\right) \cdot u2\right)\\
\mathbf{if}\;u1 \leq 0.02500000037252903:\\
\;\;\;\;\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 t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-\log \left(1 - u1\right)} \cdot t\_0\\
\end{array}
\end{array}
if u1 < 0.0250000004Initial program 48.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.f3299.2
Applied rewrites99.2%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3299.2
Applied rewrites99.2%
if 0.0250000004 < u1 Initial program 97.5%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lower-+.f32N/A
lift-PI.f32N/A
lift-PI.f3297.5
Applied rewrites97.5%
(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 56.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.f3294.2
Applied rewrites94.2%
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
*-rgt-identityN/A
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.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)) (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 56.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.f3294.2
Applied rewrites94.2%
lift-PI.f32N/A
lift-*.f32N/A
count-2-revN/A
lift-+.f32N/A
lift-PI.f32N/A
lift-PI.f3294.2
Applied rewrites94.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 0.001500000013038516) (sqrt (- (log1p (- u1)))) (* (sqrt u1) (cos (* (* 2.0 (PI)) u2)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.001500000013038516:\\
\;\;\;\;\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.00150000001Initial program 56.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.f3295.1
Applied rewrites95.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 rewrites95.1%
Taylor expanded in u2 around 0
count-2-revN/A
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.f3296.9
Applied rewrites96.9%
if 0.00150000001 < u2 Initial program 54.8%
Taylor expanded in u1 around 0
Applied rewrites75.6%
Final simplification90.9%
(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 56.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.f3294.2
Applied rewrites94.2%
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%
Taylor expanded in u2 around 0
count-2-revN/A
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.f3280.9
Applied rewrites80.9%
Final simplification80.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (fma u1 1.0 (* u1 (* (fma (fma 0.25 u1 0.3333333333333333) u1 0.5) u1)))) 1.0))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(fmaf(u1, 1.0f, (u1 * (fmaf(fmaf(0.25f, u1, 0.3333333333333333f), u1, 0.5f) * u1)))) * 1.0f;
}
function code(cosTheta_i, u1, u2) return Float32(sqrt(fma(u1, Float32(1.0), Float32(u1 * Float32(fma(fma(Float32(0.25), u1, Float32(0.3333333333333333)), u1, Float32(0.5)) * u1)))) * Float32(1.0)) end
\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 1
\end{array}
Initial program 56.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.f3294.2
Applied rewrites94.2%
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%
Taylor expanded in u2 around 0
count-2-rev78.0
Applied rewrites78.0%
(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 56.0%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lift-log.f32N/A
lift--.f3248.6
Applied rewrites48.6%
Taylor expanded in u1 around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-*.f3278.0
Applied rewrites78.0%
Final simplification78.0%
(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 56.0%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lift-log.f32N/A
lift--.f3248.6
Applied rewrites48.6%
Taylor expanded in u1 around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3276.9
Applied rewrites76.9%
Final simplification76.9%
(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 56.0%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lift-log.f32N/A
lift--.f3248.6
Applied rewrites48.6%
Taylor expanded in u1 around 0
+-commutativeN/A
*-commutativeN/A
lift-fma.f32N/A
lift-*.f3274.2
Applied rewrites74.2%
Final simplification74.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(u1) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(u1); end
\begin{array}{l}
\\
\sqrt{u1}
\end{array}
Initial program 56.0%
Taylor expanded in u2 around 0
sqrt-unprodN/A
lower-sqrt.f32N/A
lower-*.f32N/A
lift-log.f32N/A
lift--.f3248.6
Applied rewrites48.6%
Taylor expanded in u1 around 0
Applied rewrites65.8%
Final simplification65.8%
herbie shell --seed 2025037
(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))))