
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos)
:precision binary32
(*
(+ 1.0 (+ (cos (* uy (* 2.0 PI))) -1.0))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))))
float code(float ux, float uy, float maxCos) {
return (1.0f + (cosf((uy * (2.0f * ((float) M_PI)))) + -1.0f)) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) + Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) + Float32(-1.0))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos)))))) end
\begin{array}{l}
\\
\left(1 + \left(\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) + -1\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
expm1-log1p-u98.8%
Applied egg-rr98.8%
expm1-udef98.8%
log1p-udef98.7%
add-exp-log98.7%
Applied egg-rr98.7%
associate--l+99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos)))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+
(* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) + (ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in uy around inf 99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.00012700000661425292)
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))
(* (cos (* PI (* uy 2.0))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00012700000661425292f) {
tmp = sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
} else {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00012700000661425292)) tmp = sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00012700000661425292:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.27000007e-4Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def53.8%
+-commutative53.8%
associate-+r-53.8%
fma-def53.8%
neg-sub053.8%
+-commutative53.8%
associate-+r-53.7%
associate--r-53.7%
neg-sub053.7%
+-commutative53.7%
sub-neg53.7%
fma-def53.7%
Simplified53.7%
Taylor expanded in ux around 0 99.5%
fma-def99.5%
sub-neg99.5%
metadata-eval99.5%
*-commutative99.5%
unpow299.5%
associate--l+99.5%
distribute-rgt-in99.6%
*-lft-identity99.6%
mul-1-neg99.6%
sub-neg99.6%
metadata-eval99.6%
distribute-neg-in99.6%
metadata-eval99.6%
+-commutative99.6%
sub-neg99.6%
Simplified99.6%
expm1-log1p-u99.7%
Applied egg-rr99.7%
Taylor expanded in uy around 0 99.7%
if 1.27000007e-4 < (*.f32 uy 2) Initial program 54.0%
associate-*l*54.0%
sub-neg54.0%
+-commutative54.0%
distribute-rgt-neg-in54.0%
fma-def54.3%
+-commutative54.3%
associate-+r-54.4%
fma-def54.4%
neg-sub054.4%
+-commutative54.4%
associate-+r-54.2%
associate--r-54.2%
neg-sub054.2%
+-commutative54.2%
sub-neg54.2%
fma-def54.2%
Simplified54.2%
Taylor expanded in ux around 0 98.4%
fma-def98.4%
sub-neg98.4%
metadata-eval98.4%
*-commutative98.4%
unpow298.4%
associate--l+98.4%
distribute-rgt-in98.5%
*-lft-identity98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
distribute-neg-in98.5%
metadata-eval98.5%
+-commutative98.5%
sub-neg98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 94.1%
associate-*r*94.1%
+-commutative94.1%
mul-1-neg94.1%
unsub-neg94.1%
*-commutative94.1%
unpow294.1%
Simplified94.1%
Final simplification97.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.0009399999980814755)
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.0009399999980814755f) {
tmp = sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.0009399999980814755)) tmp = sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.0009399999980814755:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if uy < 9.39999998e-4Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.5%
+-commutative55.5%
associate-+r-55.5%
fma-def55.5%
neg-sub055.5%
+-commutative55.5%
associate-+r-55.4%
associate--r-55.4%
neg-sub055.4%
+-commutative55.4%
sub-neg55.4%
fma-def55.4%
Simplified55.4%
Taylor expanded in ux around 0 99.3%
fma-def99.4%
sub-neg99.4%
metadata-eval99.4%
*-commutative99.4%
unpow299.4%
associate--l+99.4%
distribute-rgt-in99.5%
*-lft-identity99.5%
mul-1-neg99.5%
sub-neg99.5%
metadata-eval99.5%
distribute-neg-in99.5%
metadata-eval99.5%
+-commutative99.5%
sub-neg99.5%
Simplified99.5%
expm1-log1p-u99.3%
Applied egg-rr99.3%
Taylor expanded in uy around 0 96.4%
if 9.39999998e-4 < uy Initial program 50.1%
associate-*l*50.1%
+-commutative50.1%
associate-+r-50.3%
fma-def50.3%
+-commutative50.3%
associate-+r-50.1%
fma-def50.1%
Simplified50.1%
Taylor expanded in ux around 0 81.4%
Final simplification92.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.0009399999980814755)
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(+ ux (* ux (- (- 1.0 maxCos) maxCos)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.0009399999980814755f) {
tmp = sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.0009399999980814755)) tmp = sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.0009399999980814755:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 9.39999998e-4Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.5%
+-commutative55.5%
associate-+r-55.5%
fma-def55.5%
neg-sub055.5%
+-commutative55.5%
associate-+r-55.4%
associate--r-55.4%
neg-sub055.4%
+-commutative55.4%
sub-neg55.4%
fma-def55.4%
Simplified55.4%
Taylor expanded in ux around 0 99.3%
fma-def99.4%
sub-neg99.4%
metadata-eval99.4%
*-commutative99.4%
unpow299.4%
associate--l+99.4%
distribute-rgt-in99.5%
*-lft-identity99.5%
mul-1-neg99.5%
sub-neg99.5%
metadata-eval99.5%
distribute-neg-in99.5%
metadata-eval99.5%
+-commutative99.5%
sub-neg99.5%
Simplified99.5%
expm1-log1p-u99.3%
Applied egg-rr99.3%
Taylor expanded in uy around 0 96.4%
if 9.39999998e-4 < uy Initial program 50.1%
associate-*l*50.1%
+-commutative50.1%
associate-+r-50.3%
fma-def50.3%
+-commutative50.3%
associate-+r-50.1%
fma-def50.1%
Simplified50.1%
Taylor expanded in ux around 0 41.8%
Taylor expanded in maxCos around 0 78.5%
*-commutative78.5%
Simplified78.5%
Final simplification91.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma ux (+ 1.0 (* maxCos -2.0)) (+ ux (* (- 1.0 maxCos) (* (+ maxCos -1.0) (* ux ux)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(ux, (1.0f + (maxCos * -2.0f)), (ux + ((1.0f - maxCos) * ((maxCos + -1.0f) * (ux * ux))))));
}
function code(ux, uy, maxCos) return sqrt(fma(ux, Float32(Float32(1.0) + Float32(maxCos * Float32(-2.0))), Float32(ux + Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(ux, 1 + maxCos \cdot -2, ux + \left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(ux \cdot ux\right)\right)\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
fma-def79.1%
cancel-sign-sub-inv79.1%
metadata-eval79.1%
sub-neg79.1%
metadata-eval79.1%
pow279.1%
Applied egg-rr79.1%
Final simplification79.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (+ maxCos -1.0) (* (* ux ux) (- 1.0 maxCos)) (+ ux (* ux (- (- 1.0 maxCos) maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux + (ux * ((1.0f - maxCos) - maxCos)))));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) - maxCos))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux + ux \cdot \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
expm1-log1p-u98.8%
Applied egg-rr98.8%
Taylor expanded in uy around 0 79.1%
Final simplification79.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) + (ux * (2.0f - (2.0f * maxCos)))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((((1.0e0 - maxcos) * ((maxcos + (-1.0e0)) * (ux ** 2.0e0))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in ux around 0 79.1%
Final simplification79.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 1.0 (* 2.0 maxCos))) (+ ux (* (* ux ux) (+ maxCos (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (1.0f - (2.0f * maxCos))) + (ux + ((ux * ux) * (maxCos + (maxCos + -1.0f))))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt(((ux * (1.0e0 - (2.0e0 * maxcos))) + (ux + ((ux * ux) * (maxcos + (maxcos + (-1.0e0)))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32(ux + Float32(Float32(ux * ux) * Float32(maxCos + Float32(maxCos + Float32(-1.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(1.0) - (single(2.0) * maxCos))) + (ux + ((ux * ux) * (maxCos + (maxCos + single(-1.0))))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 - 2 \cdot maxCos\right) + \left(ux + \left(ux \cdot ux\right) \cdot \left(maxCos + \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in maxCos around 0 79.0%
associate-*r*79.0%
distribute-rgt-out79.0%
unpow279.0%
count-279.0%
associate-+l+79.0%
+-commutative79.0%
associate-+l+79.0%
+-commutative79.0%
Simplified79.0%
Final simplification79.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 1.0 (* 2.0 maxCos))) (- ux (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (1.0f - (2.0f * maxCos))) + (ux - (ux * ux))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt(((ux * (1.0e0 - (2.0e0 * maxcos))) + (ux - (ux * ux))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32(ux - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(1.0) - (single(2.0) * maxCos))) + (ux - (ux * ux)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 - 2 \cdot maxCos\right) + \left(ux - ux \cdot ux\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in maxCos around 0 78.7%
mul-1-neg78.7%
unpow278.7%
distribute-rgt-neg-in78.7%
Simplified78.7%
Final simplification78.7%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in ux around 0 65.0%
Final simplification65.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) - (ux * ux)));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt(((2.0e0 * ux) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in maxCos around 0 74.9%
+-commutative74.9%
mul-1-neg74.9%
unsub-neg74.9%
*-commutative74.9%
unpow274.9%
Simplified74.9%
Final simplification74.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((2.0f * ux));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((2.0e0 * ux))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(2.0) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux}
\end{array}
Initial program 54.1%
associate-*l*54.1%
sub-neg54.1%
+-commutative54.1%
distribute-rgt-neg-in54.1%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
associate--l+99.0%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.1%
Taylor expanded in ux around 0 65.0%
Taylor expanded in maxCos around 0 62.1%
Final simplification62.1%
herbie shell --seed 2023242
(FPCore (ux uy maxCos)
:name "UniformSampleCone, x"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))