
(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 13 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
(*
(cos (cbrt (* (pow (* uy 2.0) 3.0) (pow PI 3.0))))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(* ux (+ (- 1.0 maxCos) (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf(cbrtf((powf((uy * 2.0f), 3.0f) * powf(((float) M_PI), 3.0f)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux * ((1.0f - maxCos) + (1.0f - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(cbrt(Float32((Float32(uy * Float32(2.0)) ^ Float32(3.0)) * (Float32(pi) ^ Float32(3.0))))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux * Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)))))) end
\begin{array}{l}
\\
\cos \left(\sqrt[3]{{\left(uy \cdot 2\right)}^{3} \cdot {\pi}^{3}}\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux \cdot \left(\left(1 - maxCos\right) + \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.1%
pow399.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (fma (fma maxCos -2.0 2.0) ux (* (* ux ux) (- (pow (- 1.0 maxCos) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(fmaf(maxCos, -2.0f, 2.0f), ux, ((ux * ux) * -powf((1.0f - maxCos), 2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(fma(maxCos, Float32(-2.0), Float32(2.0)), ux, Float32(Float32(ux * ux) * Float32(-(Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
+-commutative58.8%
associate-+r-58.7%
fma-def58.7%
+-commutative58.7%
associate-+r-58.6%
fma-def58.6%
Simplified58.6%
Taylor expanded in ux around -inf 99.0%
metadata-eval99.0%
cancel-sign-sub-inv99.0%
*-commutative99.0%
fma-def99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
fma-def99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(* ux (+ (- 1.0 maxCos) (- 1.0 maxCos)))))
(cos (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux * ((1.0f - maxCos) + (1.0f - maxCos))))) * cosf((uy * (2.0f * ((float) M_PI))));
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux * Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos))))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux \cdot \left(\left(1 - maxCos\right) + \left(1 - maxCos\right)\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (* (- 1.0 maxCos) (+ (* (+ maxCos -1.0) (* ux ux)) (* 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((1.0f - maxCos) * (((maxCos + -1.0f) * (ux * ux)) + (2.0f * ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)) + Float32(Float32(2.0) * ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(1.0) - maxCos) * (((maxCos + single(-1.0)) * (ux * ux)) + (single(2.0) * ux)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(ux \cdot ux\right) + 2 \cdot ux\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around inf 99.0%
*-commutative99.0%
associate-*r*99.0%
*-commutative99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
metadata-eval99.0%
metadata-eval99.0%
distribute-lft-neg-in99.0%
distribute-rgt-neg-in99.0%
distribute-lft-in99.0%
sub-neg99.0%
*-commutative99.0%
associate-*r*99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (* (- 1.0 maxCos) (* ux (+ 2.0 (* (+ maxCos -1.0) ux)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((1.0f - maxCos) * (ux * (2.0f + ((maxCos + -1.0f) * ux)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos + Float32(-1.0)) * ux)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((single(1.0) - maxCos) * (ux * (single(2.0) + ((maxCos + single(-1.0)) * ux))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(2 + \left(maxCos + -1\right) \cdot ux\right)\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.1%
pow399.1%
Applied egg-rr99.1%
Taylor expanded in uy around inf 99.0%
Simplified99.0%
Taylor expanded in uy around inf 99.0%
+-commutative99.0%
unpow299.0%
associate-*r*99.0%
distribute-rgt-out99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 58.8%
associate-*l*58.8%
+-commutative58.8%
associate-+r-58.7%
fma-def58.7%
+-commutative58.7%
associate-+r-58.6%
fma-def58.6%
Simplified58.6%
Taylor expanded in ux around -inf 99.0%
metadata-eval99.0%
cancel-sign-sub-inv99.0%
*-commutative99.0%
fma-def99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
fma-def99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.0%
*-commutative94.0%
associate-*r*94.0%
*-commutative94.0%
+-commutative94.0%
mul-1-neg94.0%
unsub-neg94.0%
unpow294.0%
Simplified94.0%
Final simplification94.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.003000000026077032)
(sqrt
(fma
ux
(- (+ 1.0 (- 1.0 maxCos)) maxCos)
(* (* ux ux) (* (+ maxCos -1.0) (- 1.0 maxCos)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.003000000026077032f) {
tmp = sqrtf(fmaf(ux, ((1.0f + (1.0f - maxCos)) - maxCos), ((ux * ux) * ((maxCos + -1.0f) * (1.0f - 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.003000000026077032)) tmp = sqrt(fma(ux, Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos), Float32(Float32(ux * ux) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - 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.003000000026077032:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, \left(1 + \left(1 - maxCos\right)\right) - maxCos, \left(ux \cdot ux\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\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 < 0.00300000003Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.5%
+-commutative58.5%
associate-+r-58.5%
fma-def58.5%
neg-sub058.5%
+-commutative58.5%
associate-+r-58.3%
associate--r-58.3%
neg-sub058.3%
+-commutative58.3%
sub-neg58.3%
fma-def58.3%
Simplified58.3%
Taylor expanded in uy around 0 56.8%
Taylor expanded in ux around 0 95.3%
+-commutative95.3%
fma-def95.4%
mul-1-neg95.4%
sub-neg95.4%
metadata-eval95.4%
distribute-neg-in95.4%
metadata-eval95.4%
+-commutative95.4%
sub-neg95.4%
associate-*r*95.4%
sub-neg95.4%
metadata-eval95.4%
unpow295.4%
Simplified95.4%
if 0.00300000003 < uy Initial program 60.6%
associate-*l*60.6%
+-commutative60.6%
associate-+r-60.5%
fma-def60.5%
+-commutative60.5%
associate-+r-60.4%
fma-def60.4%
Simplified60.4%
Taylor expanded in ux around 0 45.0%
Taylor expanded in maxCos around 0 71.0%
Final simplification89.2%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.1%
pow399.1%
Applied egg-rr99.1%
Taylor expanded in uy around inf 99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.0%
+-commutative94.0%
neg-mul-194.0%
sub-neg94.0%
unpow294.0%
distribute-rgt-out--93.9%
Simplified93.9%
Final simplification93.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma ux (- (+ 1.0 (- 1.0 maxCos)) maxCos) (* (* ux ux) (* (+ maxCos -1.0) (- 1.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(ux, ((1.0f + (1.0f - maxCos)) - maxCos), ((ux * ux) * ((maxCos + -1.0f) * (1.0f - maxCos)))));
}
function code(ux, uy, maxCos) return sqrt(fma(ux, Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos), Float32(Float32(ux * ux) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(ux, \left(1 + \left(1 - maxCos\right)\right) - maxCos, \left(ux \cdot ux\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in uy around 0 50.3%
Taylor expanded in ux around 0 80.8%
+-commutative80.8%
fma-def80.8%
mul-1-neg80.8%
sub-neg80.8%
metadata-eval80.8%
distribute-neg-in80.8%
metadata-eval80.8%
+-commutative80.8%
sub-neg80.8%
associate-*r*80.8%
sub-neg80.8%
metadata-eval80.8%
unpow280.8%
Simplified80.8%
Final simplification80.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* (- 1.0 maxCos) (* ux (+ 2.0 (* (+ maxCos -1.0) ux))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((1.0f - maxCos) * (ux * (2.0f + ((maxCos + -1.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(((1.0e0 - maxcos) * (ux * (2.0e0 + ((maxcos + (-1.0e0)) * ux)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos + Float32(-1.0)) * ux))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(1.0) - maxCos) * (ux * (single(2.0) + ((maxCos + single(-1.0)) * ux))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(2 + \left(maxCos + -1\right) \cdot ux\right)\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.1%
pow399.1%
Applied egg-rr99.1%
Taylor expanded in uy around inf 99.0%
Simplified99.0%
Taylor expanded in uy around 0 80.7%
+-commutative80.7%
unpow280.7%
associate-*r*80.7%
distribute-rgt-out80.8%
*-commutative80.8%
sub-neg80.8%
metadata-eval80.8%
+-commutative80.8%
Simplified80.8%
Final simplification80.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) - (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 * (2.0e0 - (2.0e0 * maxcos))) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - ux \cdot ux}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
+-commutative99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
mul-1-neg99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in uy around 0 80.8%
Taylor expanded in maxCos around 0 80.4%
mul-1-neg80.4%
unpow280.4%
distribute-rgt-neg-in80.4%
Simplified80.4%
Final simplification80.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (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((ux * (2.0e0 - ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in uy around 0 50.3%
Taylor expanded in maxCos around 0 49.2%
*-commutative49.2%
fma-def49.2%
associate-*r*49.2%
distribute-rgt-out49.2%
mul-1-neg49.2%
sub-neg49.2%
metadata-eval49.2%
+-commutative49.2%
fma-def49.6%
sub-neg49.6%
metadata-eval49.6%
Simplified49.6%
Taylor expanded in ux around 0 80.7%
+-commutative80.7%
mul-1-neg80.7%
unsub-neg80.7%
unpow280.7%
Simplified80.7%
Taylor expanded in maxCos around 0 77.4%
unpow277.4%
distribute-rgt-out--77.5%
Simplified77.5%
Final simplification77.5%
(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 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def59.1%
+-commutative59.1%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in uy around 0 50.3%
Taylor expanded in maxCos around 0 49.2%
*-commutative49.2%
fma-def49.2%
associate-*r*49.2%
distribute-rgt-out49.2%
mul-1-neg49.2%
sub-neg49.2%
metadata-eval49.2%
+-commutative49.2%
fma-def49.6%
sub-neg49.6%
metadata-eval49.6%
Simplified49.6%
Taylor expanded in ux around 0 65.8%
Taylor expanded in maxCos around 0 63.5%
Final simplification63.5%
herbie shell --seed 2023252
(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)))))))