
(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 16 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) - Float32(maxCos + 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 - \left(maxCos + -1\right)\right) - maxCos\right)\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
associate-*r*98.9%
add-cbrt-cube98.9%
add-cbrt-cube98.9%
cbrt-unprod98.9%
pow398.9%
pow398.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
ux
(- (- 2.0 maxCos) maxCos)
(* (* ux ux) (- (pow (+ maxCos -1.0) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, ((2.0f - maxCos) - maxCos), ((ux * ux) * -powf((maxCos + -1.0f), 2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(Float32(2.0) - maxCos) - maxCos), Float32(Float32(ux * ux) * Float32(-(Float32(maxCos + Float32(-1.0)) ^ Float32(2.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(2 - maxCos\right) - maxCos, \left(ux \cdot ux\right) \cdot \left(-{\left(maxCos + -1\right)}^{2}\right)\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
*-un-lft-identity98.9%
unsub-neg98.9%
Applied egg-rr98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(fma
ux
(- 1.0 (+ maxCos maxCos))
(+ ux (* (+ maxCos -1.0) (* (* ux ux) (- 1.0 maxCos))))))
(cos (* PI (* uy 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(ux, (1.0f - (maxCos + maxCos)), (ux + ((maxCos + -1.0f) * ((ux * ux) * (1.0f - maxCos)))))) * cosf((((float) M_PI) * (uy * 2.0f)));
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(ux, Float32(Float32(1.0) - Float32(maxCos + maxCos)), Float32(ux + Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)))))) * cos(Float32(Float32(pi) * Float32(uy * Float32(2.0))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(ux, 1 - \left(maxCos + maxCos\right), ux + \left(maxCos + -1\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(1 - maxCos\right)\right)\right)} \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
associate--l+98.8%
distribute-rgt-in98.8%
*-lft-identity98.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
distribute-neg-in98.8%
metadata-eval98.8%
+-commutative98.8%
sub-neg98.8%
Simplified98.8%
Taylor expanded in uy around inf 98.8%
*-commutative98.8%
fma-def98.8%
count-298.8%
sub-neg98.8%
metadata-eval98.8%
unpow298.8%
associate-*r*98.8%
Simplified98.8%
Final simplification98.8%
(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) - Float32(maxCos + 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 - \left(maxCos + -1\right)\right) - maxCos\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
(- 1.0 maxCos)
(* (+ maxCos -1.0) (* ux ux))
(* ux (- (- 2.0 maxCos) maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((1.0f - maxCos), ((maxCos + -1.0f) * (ux * ux)), (ux * ((2.0f - maxCos) - maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)), Float32(ux * Float32(Float32(Float32(2.0) - maxCos) - maxCos))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(1 - maxCos, \left(maxCos + -1\right) \cdot \left(ux \cdot ux\right), ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
associate-*r*98.9%
add-cbrt-cube98.9%
add-cbrt-cube98.9%
cbrt-unprod98.9%
pow398.9%
pow398.9%
Applied egg-rr98.9%
pow198.9%
Applied egg-rr98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.0009500000160187483)
(sqrt
(+
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))
(* ux (- (- 1.0 (+ maxCos -1.0)) 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.0009500000160187483f) {
tmp = sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f - (maxCos + -1.0f)) - 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.0009500000160187483)) tmp = sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(Float32(1.0) - Float32(maxCos + Float32(-1.0))) - 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
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.0009500000160187483)) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) - (maxCos + single(-1.0))) - maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.0009500000160187483:\\
\;\;\;\;\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 - \left(maxCos + -1\right)\right) - maxCos\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.50000016e-4Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.1%
+-commutative59.1%
associate-+r-59.2%
fma-def59.2%
neg-sub059.2%
+-commutative59.2%
associate-+r-59.0%
associate--r-59.0%
neg-sub059.0%
+-commutative59.0%
sub-neg59.0%
fma-def59.0%
Simplified59.0%
Taylor expanded in uy around 0 58.5%
Taylor expanded in ux around inf 97.7%
if 9.50000016e-4 < uy Initial program 52.6%
associate-*l*52.6%
+-commutative52.6%
associate-+r-52.6%
fma-def52.6%
+-commutative52.6%
associate-+r-52.5%
fma-def52.5%
Simplified52.5%
Taylor expanded in ux around 0 81.2%
Final simplification92.1%
(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 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in maxCos around 0 94.5%
+-commutative94.5%
mul-1-neg94.5%
unsub-neg94.5%
*-commutative94.5%
unpow294.5%
Simplified94.5%
Final simplification94.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.00139999995008111)
(sqrt
(+
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))
(* ux (- (- 1.0 (+ maxCos -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.00139999995008111f) {
tmp = sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f - (maxCos + -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.00139999995008111)) tmp = sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(Float32(1.0) - Float32(maxCos + 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
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.00139999995008111)) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) - (maxCos + single(-1.0))) - maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.00139999995008111:\\
\;\;\;\;\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 - \left(maxCos + -1\right)\right) - maxCos\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.00139999995Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.1%
+-commutative59.1%
associate-+r-59.2%
fma-def59.2%
neg-sub059.2%
+-commutative59.2%
associate-+r-59.0%
associate--r-59.0%
neg-sub059.0%
+-commutative59.0%
sub-neg59.0%
fma-def59.0%
Simplified59.0%
Taylor expanded in uy around 0 58.5%
Taylor expanded in ux around inf 97.5%
if 0.00139999995 < uy Initial program 52.4%
associate-*l*52.4%
+-commutative52.4%
associate-+r-52.4%
fma-def52.4%
+-commutative52.4%
associate-+r-52.3%
fma-def52.3%
Simplified52.3%
Taylor expanded in ux around 0 44.1%
Taylor expanded in maxCos around 0 78.7%
*-commutative78.7%
Simplified78.7%
Final simplification91.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0))) (* ux (- (- 1.0 (+ maxCos -1.0)) maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f - (maxCos + -1.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((((maxcos + (-1.0e0)) * ((1.0e0 - maxcos) * (ux ** 2.0e0))) + (ux * ((1.0e0 - (maxcos + (-1.0e0))) - maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * (ux ^ Float32(2.0)))) + Float32(ux * Float32(Float32(Float32(1.0) - Float32(maxCos + Float32(-1.0))) - maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) - (maxCos + single(-1.0))) - maxCos)))); end
\begin{array}{l}
\\
\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 - \left(maxCos + -1\right)\right) - maxCos\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in uy around 0 49.2%
Taylor expanded in ux around inf 78.1%
Final simplification78.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma ux (- 1.0 (+ maxCos maxCos)) (+ ux (* (+ maxCos -1.0) (* (* ux ux) (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(ux, (1.0f - (maxCos + maxCos)), (ux + ((maxCos + -1.0f) * ((ux * ux) * (1.0f - maxCos))))));
}
function code(ux, uy, maxCos) return sqrt(fma(ux, Float32(Float32(1.0) - Float32(maxCos + maxCos)), Float32(ux + Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(ux, 1 - \left(maxCos + maxCos\right), ux + \left(maxCos + -1\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
associate--l+98.8%
distribute-rgt-in98.8%
*-lft-identity98.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
distribute-neg-in98.8%
metadata-eval98.8%
+-commutative98.8%
sub-neg98.8%
Simplified98.8%
Taylor expanded in uy around 0 78.1%
fma-def78.1%
count-278.1%
sub-neg78.1%
metadata-eval78.1%
unpow278.1%
Simplified78.1%
Final simplification78.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (+ maxCos -1.0) (* (* ux ux) (- 1.0 maxCos))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((maxCos + -1.0f) * ((ux * ux) * (1.0f - maxCos))) + (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((((maxcos + (-1.0e0)) * ((ux * ux) * (1.0e0 - maxcos))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((maxCos + single(-1.0)) * ((ux * ux) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{\left(maxCos + -1\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in uy around 0 78.1%
Taylor expanded in maxCos around 0 78.1%
distribute-rgt-out78.1%
metadata-eval78.1%
sub-neg78.1%
*-commutative78.1%
sub-neg78.1%
metadata-eval78.1%
unpow278.1%
Simplified78.1%
Final simplification78.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 2.0 (* 2.0 maxCos))) (* (* ux ux) (+ -1.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) + ((ux * ux) * (-1.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))) + ((ux * ux) * ((-1.0e0) + (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) + Float32(Float32(ux * ux) * Float32(Float32(-1.0) + Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) + ((ux * ux) * (single(-1.0) + (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \left(ux \cdot ux\right) \cdot \left(-1 + 2 \cdot maxCos\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in uy around 0 78.1%
Taylor expanded in maxCos around 0 77.8%
associate-*r*77.8%
distribute-rgt-out77.8%
unpow277.8%
*-commutative77.8%
Simplified77.8%
Final simplification77.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 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in uy around 0 78.1%
Taylor expanded in maxCos around 0 77.6%
mul-1-neg77.6%
unpow277.6%
distribute-rgt-neg-in77.6%
Simplified77.6%
Final simplification77.6%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (- 2.0 maxCos) maxCos))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f - maxCos) - 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 - maxcos) - maxcos)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) - maxCos) - maxCos))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) - maxCos) - maxCos))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}
\end{array}
Initial program 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in uy around 0 49.2%
Taylor expanded in ux around 0 63.2%
mul-1-neg63.2%
sub-neg63.2%
sub-neg63.2%
metadata-eval63.2%
+-commutative63.2%
associate--r+63.2%
metadata-eval63.2%
Simplified63.2%
Final simplification63.2%
(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 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Taylor expanded in uy around 0 78.1%
Taylor expanded in maxCos around 0 75.5%
+-commutative75.5%
mul-1-neg75.5%
unsub-neg75.5%
*-commutative75.5%
unpow275.5%
Simplified75.5%
Final simplification75.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 56.7%
associate-*l*56.7%
sub-neg56.7%
+-commutative56.7%
distribute-rgt-neg-in56.7%
fma-def56.9%
+-commutative56.9%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in uy around 0 49.2%
Taylor expanded in ux around 0 63.2%
mul-1-neg63.2%
sub-neg63.2%
sub-neg63.2%
metadata-eval63.2%
+-commutative63.2%
associate--r+63.2%
metadata-eval63.2%
Simplified63.2%
Taylor expanded in maxCos around 0 61.6%
Final simplification61.6%
herbie shell --seed 2023240
(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)))))))