
(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 17 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 maxCos) (- 1.0 maxCos))
(* (+ maxCos -1.0) (* (pow ux 2.0) (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), ((maxCos + -1.0f) * (powf(ux, 2.0f) * (1.0f - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32(Float32(maxCos + Float32(-1.0)) * Float32((ux ^ Float32(2.0)) * Float32(Float32(1.0) - maxCos)))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), \left(maxCos + -1\right) \cdot \left({ux}^{2} \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-define58.4%
Simplified58.4%
Taylor expanded in ux around inf 98.9%
fma-define98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-lft-in98.9%
metadata-eval98.9%
+-commutative98.9%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
associate-*r*98.9%
sub-neg98.9%
mul-1-neg98.9%
*-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.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 (- (* (+ maxCos -1.0) (* ux -2.0)) (pow (* ux (+ maxCos -1.0)) 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((((maxCos + -1.0f) * (ux * -2.0f)) - powf((ux * (maxCos + -1.0f)), 2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(-2.0))) - (Float32(ux * Float32(maxCos + Float32(-1.0))) ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((((maxCos + single(-1.0)) * (ux * single(-2.0))) - ((ux * (maxCos + single(-1.0))) ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(maxCos + -1\right) \cdot \left(ux \cdot -2\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-define58.4%
Simplified58.4%
expm1-log1p-u58.4%
expm1-undefine58.2%
Applied egg-rr58.2%
Simplified57.8%
Taylor expanded in ux around -inf 98.9%
mul-1-neg98.9%
unsub-neg98.9%
associate-*r*98.9%
*-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
unpow298.9%
unpow298.9%
swap-sqr98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
unpow198.9%
pow-plus98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-define58.4%
Simplified58.4%
Taylor expanded in ux around -inf 98.9%
Taylor expanded in maxCos around 0 94.7%
+-commutative94.7%
neg-mul-194.7%
unsub-neg94.7%
*-commutative94.7%
Simplified94.7%
Final simplification94.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))
(t_1 (- 1.0 (* t_0 t_0)))
(t_2 (cos (* PI (* uy 2.0)))))
(if (<= t_1 0.0004199999966658652)
(* t_2 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(* t_2 (sqrt t_1)))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
float t_1 = 1.0f - (t_0 * t_0);
float t_2 = cosf((((float) M_PI) * (uy * 2.0f)));
float tmp;
if (t_1 <= 0.0004199999966658652f) {
tmp = t_2 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = t_2 * sqrtf(t_1);
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) t_1 = Float32(Float32(1.0) - Float32(t_0 * t_0)) t_2 = cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) tmp = Float32(0.0) if (t_1 <= Float32(0.0004199999966658652)) tmp = Float32(t_2 * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(t_2 * sqrt(t_1)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); t_1 = single(1.0) - (t_0 * t_0); t_2 = cos((single(pi) * (uy * single(2.0)))); tmp = single(0.0); if (t_1 <= single(0.0004199999966658652)) tmp = t_2 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = t_2 * sqrt(t_1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := 1 - t\_0 \cdot t\_0\\
t_2 := \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
\mathbf{if}\;t\_1 \leq 0.0004199999966658652:\\
\;\;\;\;t\_2 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_2 \cdot \sqrt{t\_1}\\
\end{array}
\end{array}
if (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) < 4.19999997e-4Initial program 38.5%
Taylor expanded in ux around 0 91.7%
if 4.19999997e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) Initial program 90.2%
Final simplification91.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))))
(if (<= (- 1.0 (* t_0 t_0)) 0.0004199999966658652)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(+
1.0
(* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
float tmp;
if ((1.0f - (t_0 * t_0)) <= 0.0004199999966658652f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) tmp = Float32(0.0) if (Float32(Float32(1.0) - Float32(t_0 * t_0)) <= Float32(0.0004199999966658652)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = single(0.0); if ((single(1.0) - (t_0 * t_0)) <= single(0.0004199999966658652)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\mathbf{if}\;1 - t\_0 \cdot t\_0 \leq 0.0004199999966658652:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) < 4.19999997e-4Initial program 38.5%
Taylor expanded in ux around 0 91.7%
if 4.19999997e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-define90.3%
Simplified90.4%
Taylor expanded in uy around inf 90.1%
Simplified90.3%
Final simplification91.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00011999999696854502)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(*
(cos (* uy (* 2.0 PI)))
(sqrt (+ 1.0 (+ (+ ux -1.0) (* (- 1.0 ux) (- ux (* ux maxCos)))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00011999999696854502f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((1.0f + ((ux + -1.0f) + ((1.0f - ux) * (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00011999999696854502)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(1.0) + Float32(Float32(ux + Float32(-1.0)) + Float32(Float32(Float32(1.0) - ux) * Float32(ux - Float32(ux * maxCos))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00011999999696854502)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(1.0) + ((ux + single(-1.0)) + ((single(1.0) - ux) * (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00011999999696854502:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 + \left(\left(ux + -1\right) + \left(1 - ux\right) \cdot \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.19999997e-4Initial program 37.2%
Taylor expanded in ux around 0 92.5%
if 1.19999997e-4 < ux Initial program 89.1%
associate-*l*89.1%
sub-neg89.1%
+-commutative89.1%
distribute-rgt-neg-in89.1%
fma-define89.3%
Simplified89.4%
Taylor expanded in uy around inf 88.9%
Simplified89.2%
Taylor expanded in maxCos around 0 87.2%
mul-1-neg87.2%
Simplified87.2%
distribute-rgt-in88.5%
*-un-lft-identity88.5%
unsub-neg88.5%
unsub-neg88.5%
Applied egg-rr88.5%
Final simplification90.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0002099999983329326)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(*
(cos (* 2.0 (* uy PI)))
(sqrt (+ 1.0 (* (- 1.0 ux) (- ux (+ 1.0 (* ux maxCos)))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0002099999983329326f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((1.0f + ((1.0f - ux) * (ux - (1.0f + (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0002099999983329326)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux - Float32(Float32(1.0) + Float32(ux * maxCos))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0002099999983329326)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((single(1.0) + ((single(1.0) - ux) * (ux - (single(1.0) + (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002099999983329326:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{1 + \left(1 - ux\right) \cdot \left(ux - \left(1 + ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 2.09999998e-4Initial program 38.5%
Taylor expanded in ux around 0 91.7%
if 2.09999998e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-define90.3%
Simplified90.4%
Taylor expanded in uy around inf 90.1%
Simplified90.3%
Taylor expanded in maxCos around 0 88.2%
mul-1-neg88.2%
Simplified88.2%
Taylor expanded in uy around inf 88.2%
Final simplification90.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0002099999983329326)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(*
(cos (* uy (* 2.0 PI)))
(sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 (- ux (* ux maxCos)))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0002099999983329326f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((1.0f + ((1.0f - ux) * (-1.0f + (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0002099999983329326)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0002099999983329326)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002099999983329326:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 2.09999998e-4Initial program 38.5%
Taylor expanded in ux around 0 91.7%
if 2.09999998e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-define90.3%
Simplified90.4%
Taylor expanded in uy around inf 90.1%
Simplified90.3%
Taylor expanded in maxCos around 0 88.2%
mul-1-neg88.2%
Simplified88.2%
unsub-neg88.2%
unsub-neg88.2%
Applied egg-rr88.2%
Final simplification90.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0002099999983329326) (* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos))))) (* (cos (* uy (* 2.0 PI))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0002099999983329326f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0002099999983329326)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * 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.0002099999983329326)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * 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.0002099999983329326:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 2.09999998e-4Initial program 38.5%
Taylor expanded in ux around 0 91.7%
if 2.09999998e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-define90.3%
Simplified90.4%
Taylor expanded in uy around inf 90.1%
Simplified90.3%
Taylor expanded in maxCos around 0 87.8%
Final simplification90.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0007999999797903001)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0007999999797903001f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0007999999797903001)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0007999999797903001)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0007999999797903001:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 7.9999998e-4Initial program 41.3%
Taylor expanded in ux around 0 89.9%
if 7.9999998e-4 < ux Initial program 92.6%
associate-*l*92.6%
sub-neg92.6%
+-commutative92.6%
distribute-rgt-neg-in92.6%
fma-define92.4%
Simplified92.5%
Taylor expanded in uy around 0 72.6%
Simplified72.8%
Final simplification84.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0007999999797903001)
(* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 maxCos))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0007999999797903001f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - maxCos)));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0007999999797903001)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0007999999797903001)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - maxCos))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0007999999797903001:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 7.9999998e-4Initial program 41.3%
associate-*l*41.3%
sub-neg41.3%
+-commutative41.3%
distribute-rgt-neg-in41.3%
fma-define41.5%
Simplified41.5%
Taylor expanded in uy around inf 41.3%
Simplified41.3%
Taylor expanded in maxCos around 0 41.0%
mul-1-neg41.0%
Simplified41.0%
Taylor expanded in ux around 0 86.6%
if 7.9999998e-4 < ux Initial program 92.6%
associate-*l*92.6%
sub-neg92.6%
+-commutative92.6%
distribute-rgt-neg-in92.6%
fma-define92.4%
Simplified92.5%
Taylor expanded in uy around 0 72.6%
Simplified72.8%
Final simplification82.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0001500000071246177)
(cbrt (pow (* ux (- 2.0 (* 2.0 maxCos))) 1.5))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0001500000071246177f) {
tmp = cbrtf(powf((ux * (2.0f - (2.0f * maxCos))), 1.5f));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0001500000071246177)) tmp = cbrt((Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) ^ Float32(1.5))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos)))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001500000071246177:\\
\;\;\;\;\sqrt[3]{{\left(ux \cdot \left(2 - 2 \cdot maxCos\right)\right)}^{1.5}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.50000007e-4Initial program 37.4%
associate-*l*37.4%
sub-neg37.4%
+-commutative37.4%
distribute-rgt-neg-in37.4%
fma-define37.4%
Simplified37.5%
Taylor expanded in uy around 0 33.6%
Simplified33.6%
Taylor expanded in ux around 0 74.0%
*-commutative74.0%
Simplified74.0%
add-cbrt-cube74.0%
add-sqr-sqrt74.0%
pow174.0%
pow1/274.0%
pow-prod-up74.0%
*-commutative74.0%
metadata-eval74.0%
Applied egg-rr74.0%
if 1.50000007e-4 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-define89.5%
Simplified89.5%
Taylor expanded in uy around 0 69.4%
Simplified69.7%
Final simplification72.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0001500000071246177)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0001500000071246177f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-1.0f + (ux - (ux * maxCos))))));
}
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.0001500000071246177e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * (maxcos + (-1.0e0)))) * ((-1.0e0) + (ux - (ux * maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0001500000071246177)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0001500000071246177)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0001500000071246177:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.50000007e-4Initial program 37.4%
associate-*l*37.4%
sub-neg37.4%
+-commutative37.4%
distribute-rgt-neg-in37.4%
fma-define37.4%
Simplified37.5%
Taylor expanded in uy around 0 33.6%
Simplified33.6%
Taylor expanded in ux around 0 74.0%
*-commutative74.0%
Simplified74.0%
if 1.50000007e-4 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-define89.5%
Simplified89.5%
Taylor expanded in uy around 0 69.4%
Simplified69.7%
Final simplification72.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00015999999595806003) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 (* ux (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f + (ux * (1.0f - maxCos))))));
}
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.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) + (ux * (1.0e0 - maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + (ux * (single(1.0) - maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 37.7%
associate-*l*37.7%
sub-neg37.7%
+-commutative37.7%
distribute-rgt-neg-in37.7%
fma-define37.7%
Simplified37.7%
Taylor expanded in uy around 0 33.8%
Simplified33.8%
Taylor expanded in ux around 0 74.0%
*-commutative74.0%
Simplified74.0%
if 1.59999996e-4 < ux Initial program 89.5%
associate-*l*89.5%
sub-neg89.5%
+-commutative89.5%
distribute-rgt-neg-in89.5%
fma-define89.7%
Simplified89.7%
Taylor expanded in uy around inf 89.3%
Simplified89.5%
Taylor expanded in maxCos around 0 87.5%
mul-1-neg87.5%
Simplified87.5%
Taylor expanded in uy around 0 68.2%
associate--l+68.3%
sub-neg68.3%
neg-mul-168.3%
distribute-rgt-in68.3%
Simplified68.3%
Final simplification71.7%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00015999999595806003) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * 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.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * 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.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * 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.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * 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.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 37.7%
associate-*l*37.7%
sub-neg37.7%
+-commutative37.7%
distribute-rgt-neg-in37.7%
fma-define37.7%
Simplified37.7%
Taylor expanded in uy around 0 33.8%
Simplified33.8%
Taylor expanded in ux around 0 74.0%
*-commutative74.0%
Simplified74.0%
if 1.59999996e-4 < ux Initial program 89.5%
associate-*l*89.5%
sub-neg89.5%
+-commutative89.5%
distribute-rgt-neg-in89.5%
fma-define89.7%
Simplified89.7%
Taylor expanded in uy around 0 69.4%
Simplified69.6%
Taylor expanded in maxCos around 0 68.0%
Final simplification71.6%
(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 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-define58.4%
Simplified58.4%
Taylor expanded in uy around 0 48.0%
Simplified48.1%
Taylor expanded in ux around 0 62.1%
*-commutative62.1%
Simplified62.1%
Final simplification62.1%
(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.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-define58.4%
Simplified58.4%
Taylor expanded in uy around 0 48.0%
Simplified48.1%
Taylor expanded in ux around 0 62.1%
*-commutative62.1%
Simplified62.1%
Taylor expanded in maxCos around 0 60.9%
*-commutative60.9%
Simplified60.9%
Final simplification60.9%
herbie shell --seed 2024046
(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)))))))