
(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 15 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 (* uy (* 2.0 PI)))
(sqrt
(fma
ux
(+ 1.0 (- (- 1.0 maxCos) maxCos))
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (* ux ux)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, (1.0f + ((1.0f - maxCos) - maxCos)), ((maxCos + -1.0f) * ((1.0f - maxCos) * (ux * ux)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) - maxCos)), Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * ux)))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(ux \cdot ux\right)\right)\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
fma-def98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* (- 1.0 maxCos) (* 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((((1.0f - maxCos) * (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(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(2.0) * ux)) - Float32(Float32(ux * ux) * (Float32(Float32(1.0) - maxCos) ^ Float32(2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((((single(1.0) - maxCos) * (single(2.0) * ux)) - ((ux * ux) * ((single(1.0) - maxCos) ^ single(2.0))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux\right) - \left(ux \cdot ux\right) \cdot {\left(1 - maxCos\right)}^{2}}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around -inf 98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
associate-*r*98.9%
mul-1-neg98.9%
sub-neg98.9%
*-commutative98.9%
unpow298.9%
mul-1-neg98.9%
sub-neg98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(*
ux
(- (+ 2.0 (* maxCos -2.0)) (* ux (* (+ maxCos -1.0) (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * ((2.0f + (maxCos * -2.0f)) - (ux * ((maxCos + -1.0f) * (maxCos + -1.0f))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))) - Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * ((single(2.0) + (maxCos * single(-2.0))) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.0))))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + maxCos \cdot -2\right) - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
fma-def98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
Simplified99.0%
expm1-log1p-u98.9%
associate--l-99.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(*
ux
(+ 2.0 (+ (* maxCos -2.0) (* (- 1.0 maxCos) (* ux (+ maxCos -1.0)))))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f + ((maxCos * -2.0f) + ((1.0f - maxCos) * (ux * (maxCos + -1.0f)))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) + Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(maxCos + Float32(-1.0))))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) + ((single(1.0) - maxCos) * (ux * (maxCos + single(-1.0)))))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 + \left(1 - maxCos\right) \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
fma-def98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
Simplified99.0%
expm1-log1p-u98.9%
associate--l-99.0%
Applied egg-rr99.0%
Taylor expanded in uy around inf 98.9%
Simplified98.9%
pow198.9%
associate-+l+98.9%
associate-*r*98.9%
Applied egg-rr98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.00022000000171829015)
(sqrt
(+
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))
(* (cos (* 2.0 (* uy PI))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00022000000171829015f) {
tmp = sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
} else {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * 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.00022000000171829015)) 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(Float32(1.0) - maxCos)) - maxCos)))); else tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.00022000000171829015)) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)))); else tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00022000000171829015:\\
\;\;\;\;\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 2.20000002e-4Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.2%
+-commutative57.2%
associate-+r-57.3%
fma-def57.3%
neg-sub057.3%
+-commutative57.3%
associate-+r-57.0%
associate--r-57.0%
neg-sub057.0%
+-commutative57.0%
sub-neg57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in uy around 0 56.9%
Taylor expanded in ux around inf 99.4%
if 2.20000002e-4 < (*.f32 uy 2) Initial program 51.9%
associate-*l*51.9%
sub-neg51.9%
+-commutative51.9%
distribute-rgt-neg-in51.9%
fma-def52.1%
+-commutative52.1%
associate-+r-52.1%
fma-def52.1%
neg-sub052.1%
+-commutative52.1%
associate-+r-52.0%
associate--r-52.0%
neg-sub052.0%
+-commutative52.0%
sub-neg52.0%
fma-def52.0%
Simplified52.0%
Taylor expanded in ux around 0 98.0%
+-commutative98.0%
fma-def98.0%
associate--l+98.0%
mul-1-neg98.0%
sub-neg98.0%
metadata-eval98.0%
distribute-neg-in98.0%
metadata-eval98.0%
+-commutative98.0%
sub-neg98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
unpow298.0%
Simplified98.0%
Taylor expanded in maxCos around 0 94.2%
+-commutative94.2%
mul-1-neg94.2%
sub-neg94.2%
unpow294.2%
Simplified94.2%
Final simplification97.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.00011000000085914508)
(sqrt
(+
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))
(* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.00011000000085914508f) {
tmp = sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
} else {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.00011000000085914508)) 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(Float32(1.0) - maxCos)) - maxCos)))); else tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.00011000000085914508)) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)))); else tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.00011000000085914508:\\
\;\;\;\;\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if uy < 1.10000001e-4Initial program 57.0%
associate-*l*57.0%
sub-neg57.0%
+-commutative57.0%
distribute-rgt-neg-in57.0%
fma-def57.2%
+-commutative57.2%
associate-+r-57.3%
fma-def57.3%
neg-sub057.3%
+-commutative57.3%
associate-+r-57.0%
associate--r-57.0%
neg-sub057.0%
+-commutative57.0%
sub-neg57.0%
fma-def57.0%
Simplified57.0%
Taylor expanded in uy around 0 56.9%
Taylor expanded in ux around inf 99.4%
if 1.10000001e-4 < uy Initial program 51.9%
associate-*l*51.9%
sub-neg51.9%
+-commutative51.9%
distribute-rgt-neg-in51.9%
fma-def52.1%
+-commutative52.1%
associate-+r-52.1%
fma-def52.1%
neg-sub052.1%
+-commutative52.1%
associate-+r-52.0%
associate--r-52.0%
neg-sub052.0%
+-commutative52.0%
sub-neg52.0%
fma-def52.0%
Simplified52.0%
Taylor expanded in ux around 0 98.0%
+-commutative98.0%
fma-def98.0%
associate--l+98.0%
mul-1-neg98.0%
sub-neg98.0%
metadata-eval98.0%
distribute-neg-in98.0%
metadata-eval98.0%
+-commutative98.0%
sub-neg98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
unpow298.0%
Simplified98.0%
Taylor expanded in maxCos around 0 94.2%
+-commutative94.2%
mul-1-neg94.2%
sub-neg94.2%
unpow294.2%
distribute-rgt-out--94.1%
Simplified94.1%
Final simplification97.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.0004600000102072954)
(sqrt
(+
(* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0)))
(* ux (- (+ 1.0 (- 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.0004600000102072954f) {
tmp = sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f + (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.0004600000102072954)) 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(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
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.0004600000102072954)) tmp = sqrt((((maxCos + single(-1.0)) * ((single(1.0) - maxCos) * (ux ^ single(2.0)))) + (ux * ((single(1.0) + (single(1.0) - maxCos)) - 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.0004600000102072954:\\
\;\;\;\;\sqrt{\left(maxCos + -1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + \left(1 - maxCos\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 < 4.6000001e-4Initial program 56.9%
associate-*l*56.9%
sub-neg56.9%
+-commutative56.9%
distribute-rgt-neg-in56.9%
fma-def57.1%
+-commutative57.1%
associate-+r-57.2%
fma-def57.2%
neg-sub057.2%
+-commutative57.2%
associate-+r-56.9%
associate--r-56.9%
neg-sub056.9%
+-commutative56.9%
sub-neg56.9%
fma-def56.9%
Simplified56.9%
Taylor expanded in uy around 0 56.5%
Taylor expanded in ux around inf 98.0%
if 4.6000001e-4 < uy Initial program 50.9%
associate-*l*50.9%
+-commutative50.9%
associate-+r-50.9%
fma-def50.9%
+-commutative50.9%
associate-+r-50.9%
fma-def50.9%
Simplified50.9%
Taylor expanded in ux around 0 42.0%
Taylor expanded in maxCos around 0 77.0%
Final simplification91.7%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (+ maxCos -1.0) (* (- 1.0 maxCos) (pow ux 2.0))) (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((maxCos + -1.0f) * ((1.0f - maxCos) * powf(ux, 2.0f))) + (ux * ((1.0f + (1.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((((maxcos + (-1.0e0)) * ((1.0e0 - maxcos) * (ux ** 2.0e0))) + (ux * ((1.0e0 + (1.0e0 - maxcos)) - 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(Float32(1.0) - maxCos)) - 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) + (single(1.0) - maxCos)) - 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(1 - maxCos\right)\right) - maxCos\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in uy around 0 49.1%
Taylor expanded in ux around inf 82.8%
Final simplification82.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (+ 2.0 (* maxCos -2.0)) ux (* (- 1.0 maxCos) (* ux (* ux (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((2.0f + (maxCos * -2.0f)), ux, ((1.0f - maxCos) * (ux * (ux * (maxCos + -1.0f))))));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))), ux, Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(ux * Float32(maxCos + Float32(-1.0))))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(2 + maxCos \cdot -2, ux, \left(1 - maxCos\right) \cdot \left(ux \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
fma-def98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
Simplified99.0%
expm1-log1p-u98.9%
associate--l-99.0%
Applied egg-rr99.0%
Taylor expanded in uy around 0 82.8%
fma-def82.8%
cancel-sign-sub-inv82.8%
metadata-eval82.8%
*-commutative82.8%
associate-*r*82.8%
unpow282.8%
associate-*l*82.8%
sub-neg82.8%
metadata-eval82.8%
Simplified82.8%
Final simplification82.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (+ 2.0 (* maxCos -2.0)) (* ux (* (+ maxCos -1.0) (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f + (maxCos * -2.0f)) - (ux * ((maxCos + -1.0f) * (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 * ((2.0e0 + (maxcos * (-2.0e0))) - (ux * ((maxcos + (-1.0e0)) * (maxcos + (-1.0e0)))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))) - Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) + (maxCos * single(-2.0))) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.0))))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 + maxCos \cdot -2\right) - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 98.9%
+-commutative98.9%
fma-def98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
distribute-neg-in99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
*-commutative99.0%
unpow299.0%
Simplified99.0%
expm1-log1p-u98.9%
associate--l-99.0%
Applied egg-rr99.0%
Taylor expanded in uy around 0 82.8%
associate-*r*82.8%
*-commutative82.8%
sub-neg82.8%
metadata-eval82.8%
unpow282.8%
associate-*r*82.8%
distribute-rgt-out82.8%
sub-neg82.8%
*-commutative82.8%
distribute-rgt-neg-in82.8%
metadata-eval82.8%
*-commutative82.8%
metadata-eval82.8%
sub-neg82.8%
*-commutative82.8%
sub-neg82.8%
metadata-eval82.8%
Simplified82.8%
Final simplification82.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0001340000017080456) (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))) (sqrt (+ 1.0 (* (+ ux (- -1.0 (* ux maxCos))) (- 1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0001340000017080456f) {
tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
} else {
tmp = sqrtf((1.0f + ((ux + (-1.0f - (ux * maxCos))) * (1.0f - ux))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.0001340000017080456e0) then
tmp = sqrt((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)))
else
tmp = sqrt((1.0e0 + ((ux + ((-1.0e0) - (ux * maxcos))) * (1.0e0 - ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0001340000017080456)) tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(ux + Float32(Float32(-1.0) - Float32(ux * maxCos))) * Float32(Float32(1.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0001340000017080456)) tmp = sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos))); else tmp = sqrt((single(1.0) + ((ux + (single(-1.0) - (ux * maxCos))) * (single(1.0) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001340000017080456:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(ux + \left(-1 - ux \cdot maxCos\right)\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.34000002e-4Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.4%
+-commutative33.4%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in uy around 0 31.2%
Taylor expanded in ux around 0 78.7%
if 1.34000002e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.4%
+-commutative89.4%
associate-+r-89.5%
fma-def89.5%
neg-sub089.5%
+-commutative89.5%
associate-+r-89.1%
associate--r-89.1%
neg-sub089.1%
+-commutative89.1%
sub-neg89.1%
fma-def89.1%
Simplified89.1%
Taylor expanded in uy around 0 76.9%
Taylor expanded in maxCos around 0 75.1%
Final simplification77.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0001340000017080456) (sqrt (* ux (+ 2.0 (* maxCos -2.0)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0001340000017080456f) {
tmp = sqrtf((ux * (2.0f + (maxCos * -2.0f))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.0001340000017080456e0) then
tmp = sqrt((ux * (2.0e0 + (maxcos * (-2.0e0)))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0001340000017080456)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0001340000017080456)) tmp = sqrt((ux * (single(2.0) + (maxCos * single(-2.0))))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001340000017080456:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 1.34000002e-4Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.4%
+-commutative33.4%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in ux around 0 93.4%
associate--l+93.4%
distribute-lft-in93.4%
*-rgt-identity93.4%
mul-1-neg93.4%
sub-neg93.4%
metadata-eval93.4%
distribute-neg-in93.4%
metadata-eval93.4%
+-commutative93.4%
sub-neg93.4%
Simplified93.4%
log1p-expm1-u93.3%
Applied egg-rr93.3%
Taylor expanded in uy around 0 78.6%
*-commutative78.6%
distribute-lft1-in78.7%
count-278.7%
associate--l-78.7%
+-commutative78.7%
associate--l-78.7%
count-278.7%
associate-+r-78.7%
metadata-eval78.7%
sub-neg78.7%
*-commutative78.7%
distribute-rgt-neg-in78.7%
metadata-eval78.7%
Simplified78.7%
if 1.34000002e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.4%
+-commutative89.4%
associate-+r-89.5%
fma-def89.5%
neg-sub089.5%
+-commutative89.5%
associate-+r-89.1%
associate--r-89.1%
neg-sub089.1%
+-commutative89.1%
sub-neg89.1%
fma-def89.1%
Simplified89.1%
Taylor expanded in uy around 0 76.9%
Taylor expanded in maxCos around 0 74.8%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0001340000017080456) (sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0001340000017080456f) {
tmp = sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.0001340000017080456e0) then
tmp = sqrt((ux * ((1.0e0 + (1.0e0 - maxcos)) - maxcos)))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0001340000017080456)) tmp = sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0001340000017080456)) tmp = sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001340000017080456:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 1.34000002e-4Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.4%
+-commutative33.4%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in uy around 0 31.2%
Taylor expanded in ux around 0 78.7%
if 1.34000002e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.4%
+-commutative89.4%
associate-+r-89.5%
fma-def89.5%
neg-sub089.5%
+-commutative89.5%
associate-+r-89.1%
associate--r-89.1%
neg-sub089.1%
+-commutative89.1%
sub-neg89.1%
fma-def89.1%
Simplified89.1%
Taylor expanded in uy around 0 76.9%
Taylor expanded in maxCos around 0 74.8%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (* maxCos -2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + (maxCos * -2.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 * (2.0e0 + (maxcos * (-2.0e0)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + (maxCos * single(-2.0))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right)}
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in ux around 0 77.5%
associate--l+77.5%
distribute-lft-in77.4%
*-rgt-identity77.4%
mul-1-neg77.4%
sub-neg77.4%
metadata-eval77.4%
distribute-neg-in77.4%
metadata-eval77.4%
+-commutative77.4%
sub-neg77.4%
Simplified77.4%
log1p-expm1-u77.4%
Applied egg-rr77.4%
Taylor expanded in uy around 0 66.8%
*-commutative66.8%
distribute-lft1-in66.8%
count-266.8%
associate--l-66.8%
+-commutative66.8%
associate--l-66.8%
count-266.8%
associate-+r-66.8%
metadata-eval66.8%
sub-neg66.8%
*-commutative66.8%
distribute-rgt-neg-in66.8%
metadata-eval66.8%
Simplified66.8%
Final simplification66.8%
(FPCore (ux uy maxCos) :precision binary32 1.0)
float code(float ux, float uy, float maxCos) {
return 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 = 1.0e0
end function
function code(ux, uy, maxCos) return Float32(1.0) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0); end
\begin{array}{l}
\\
1
\end{array}
Initial program 55.1%
associate-*l*55.1%
sub-neg55.1%
+-commutative55.1%
distribute-rgt-neg-in55.1%
fma-def55.3%
+-commutative55.3%
associate-+r-55.3%
fma-def55.3%
neg-sub055.3%
+-commutative55.3%
associate-+r-55.1%
associate--r-55.1%
neg-sub055.1%
+-commutative55.1%
sub-neg55.1%
fma-def55.1%
Simplified55.1%
Taylor expanded in uy around 0 49.1%
Taylor expanded in ux around inf 19.6%
Taylor expanded in ux around 0 19.8%
Final simplification19.8%
herbie shell --seed 2023195
(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)))))))