
(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 12 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))
(* (pow ux 2.0) (* (+ maxCos -1.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)), (powf(ux, 2.0f) * ((maxCos + -1.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((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.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), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 56.2%
associate-*l*56.2%
cancel-sign-sub-inv56.2%
+-commutative56.2%
*-commutative56.2%
fma-def56.1%
Simplified56.0%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
+-commutative98.8%
associate--l+98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
distribute-lft-in98.8%
metadata-eval98.8%
mul-1-neg98.8%
sub-neg98.8%
*-commutative98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(-
(* ux (- 2.0 (* 2.0 maxCos)))
(* (pow ux 2.0) (* (+ maxCos -1.0) (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((ux * (2.0f - (2.0f * maxCos))) - (powf(ux, 2.0f) * ((maxCos + -1.0f) * (maxCos + -1.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - ((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (maxCos + single(-1.0)))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)}
\end{array}
Initial program 56.2%
associate-*l*56.2%
cancel-sign-sub-inv56.2%
+-commutative56.2%
*-commutative56.2%
fma-def56.1%
Simplified56.0%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
+-commutative98.8%
associate--l+98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
distribute-lft-in98.8%
metadata-eval98.8%
mul-1-neg98.8%
sub-neg98.8%
*-commutative98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in uy around inf 98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.00011999999696854502)
(sqrt
(fma
ux
(+ (- 1.0 maxCos) (- 1.0 maxCos))
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.00011999999696854502f) {
tmp = sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), (powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos)))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.00011999999696854502)) tmp = sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.00011999999696854502:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.19999997e-4Initial program 52.3%
associate-*l*52.3%
cancel-sign-sub-inv52.3%
+-commutative52.3%
*-commutative52.3%
fma-def52.3%
Simplified52.1%
Taylor expanded in ux around 0 99.4%
fma-def99.5%
+-commutative99.5%
associate--l+99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
mul-1-neg99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in uy around 0 99.6%
if 1.19999997e-4 < (*.f32 uy 2) Initial program 60.5%
associate-*l*60.5%
cancel-sign-sub-inv60.5%
+-commutative60.5%
*-commutative60.5%
fma-def60.4%
Simplified60.3%
Taylor expanded in ux around 0 98.1%
fma-def98.0%
+-commutative98.0%
associate--l+98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
distribute-lft-in98.1%
metadata-eval98.1%
mul-1-neg98.1%
sub-neg98.1%
*-commutative98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in maxCos around 0 92.8%
Final simplification96.4%
(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.00034050000249408185)
(* 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.00034050000249408185f) {
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.00034050000249408185)) 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.00034050000249408185)) 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.00034050000249408185:\\
\;\;\;\;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)))) < 3.40500002e-4Initial program 37.7%
Taylor expanded in ux around 0 91.5%
if 3.40500002e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) Initial program 88.5%
Final simplification90.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.002199999988079071)
(sqrt
(fma
ux
(+ (- 1.0 maxCos) (- 1.0 maxCos))
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))))
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.002199999988079071f) {
tmp = sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), (powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos)))));
} else {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.002199999988079071)) tmp = sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.002199999988079071:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.0022Initial program 54.0%
associate-*l*54.0%
cancel-sign-sub-inv54.0%
+-commutative54.0%
*-commutative54.0%
fma-def54.1%
Simplified53.9%
Taylor expanded in ux around 0 99.4%
fma-def99.4%
+-commutative99.4%
associate--l+99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
mul-1-neg99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in uy around 0 97.2%
if 0.0022 < (*.f32 uy 2) Initial program 60.5%
Taylor expanded in ux around 0 74.1%
Final simplification89.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* ux (- 2.0 (* 2.0 maxCos)))))
(if (<= (* uy 2.0) 0.002199999988079071)
(sqrt (- t_0 (* (pow ux 2.0) (* (+ maxCos -1.0) (+ maxCos -1.0)))))
(* (cos (* PI (* uy 2.0))) (sqrt t_0)))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (2.0f - (2.0f * maxCos));
float tmp;
if ((uy * 2.0f) <= 0.002199999988079071f) {
tmp = sqrtf((t_0 - (powf(ux, 2.0f) * ((maxCos + -1.0f) * (maxCos + -1.0f)))));
} else {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(t_0);
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.002199999988079071)) tmp = sqrt(Float32(t_0 - Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(t_0)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux * (single(2.0) - (single(2.0) * maxCos)); tmp = single(0.0); if ((uy * single(2.0)) <= single(0.002199999988079071)) tmp = sqrt((t_0 - ((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (maxCos + single(-1.0)))))); else tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt(t_0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(2 - 2 \cdot maxCos\right)\\
\mathbf{if}\;uy \cdot 2 \leq 0.002199999988079071:\\
\;\;\;\;\sqrt{t_0 - {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{t_0}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.0022Initial program 54.0%
associate-*l*54.0%
cancel-sign-sub-inv54.0%
+-commutative54.0%
*-commutative54.0%
fma-def54.1%
Simplified53.9%
Taylor expanded in ux around 0 99.4%
fma-def99.4%
+-commutative99.4%
associate--l+99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
mul-1-neg99.5%
sub-neg99.5%
*-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in uy around 0 97.1%
if 0.0022 < (*.f32 uy 2) Initial program 60.5%
Taylor expanded in ux around 0 74.1%
Final simplification89.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (* (pow ux 2.0) (* (+ maxCos -1.0) (+ maxCos -1.0))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) - (powf(ux, 2.0f) * ((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 - (2.0e0 * maxcos))) - ((ux ** 2.0e0) * ((maxcos + (-1.0e0)) * (maxcos + (-1.0e0))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - ((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (maxCos + single(-1.0)))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)}
\end{array}
Initial program 56.2%
associate-*l*56.2%
cancel-sign-sub-inv56.2%
+-commutative56.2%
*-commutative56.2%
fma-def56.1%
Simplified56.0%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
+-commutative98.8%
associate--l+98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
distribute-lft-in98.8%
metadata-eval98.8%
mul-1-neg98.8%
sub-neg98.8%
*-commutative98.8%
sub-neg98.8%
metadata-eval98.8%
+-commutative98.8%
Simplified98.8%
Taylor expanded in uy around 0 78.3%
Final simplification78.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00023999999393709004)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt
(+ 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ -1.0 (* ux (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00023999999393709004f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + (((1.0f - ux) + (ux * maxCos)) * (-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.00023999999393709004e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + (((1.0e0 - ux) + (ux * maxcos)) * ((-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.00023999999393709004)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) * 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.00023999999393709004)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + (((single(1.0) - ux) + (ux * maxCos)) * (single(-1.0) + (ux * (single(1.0) - maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00023999999393709004:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 2.39999994e-4Initial program 38.7%
associate-*l*38.7%
cancel-sign-sub-inv38.7%
+-commutative38.7%
*-commutative38.7%
fma-def38.7%
Simplified38.5%
Taylor expanded in uy around 0 34.1%
Taylor expanded in ux around 0 75.2%
if 2.39999994e-4 < ux Initial program 89.0%
associate-*l*89.0%
cancel-sign-sub-inv89.0%
+-commutative89.0%
*-commutative89.0%
fma-def89.0%
Simplified89.0%
Taylor expanded in uy around 0 70.1%
+-commutative70.1%
associate--l+70.1%
*-commutative70.1%
Applied egg-rr70.1%
Final simplification73.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00023999999393709004) (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.00023999999393709004f) {
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.00023999999393709004e0) 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.00023999999393709004)) 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.00023999999393709004)) 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.00023999999393709004:\\
\;\;\;\;\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 < 2.39999994e-4Initial program 38.7%
associate-*l*38.7%
cancel-sign-sub-inv38.7%
+-commutative38.7%
*-commutative38.7%
fma-def38.7%
Simplified38.5%
Taylor expanded in uy around 0 34.1%
Taylor expanded in ux around 0 75.2%
if 2.39999994e-4 < ux Initial program 89.0%
associate-*l*89.0%
cancel-sign-sub-inv89.0%
+-commutative89.0%
*-commutative89.0%
fma-def89.0%
Simplified89.0%
Taylor expanded in uy around 0 70.1%
Taylor expanded in maxCos around 0 67.8%
Final simplification72.6%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00023999999393709004) (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.00023999999393709004f) {
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.00023999999393709004e0) 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.00023999999393709004)) 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.00023999999393709004)) 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.00023999999393709004:\\
\;\;\;\;\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 < 2.39999994e-4Initial program 38.7%
associate-*l*38.7%
cancel-sign-sub-inv38.7%
+-commutative38.7%
*-commutative38.7%
fma-def38.7%
Simplified38.5%
Taylor expanded in uy around 0 34.1%
Taylor expanded in ux around 0 75.2%
if 2.39999994e-4 < ux Initial program 89.0%
associate-*l*89.0%
cancel-sign-sub-inv89.0%
+-commutative89.0%
*-commutative89.0%
fma-def89.0%
Simplified89.0%
Taylor expanded in uy around 0 70.1%
Taylor expanded in maxCos around 0 67.7%
Final simplification72.6%
(FPCore (ux uy maxCos) :precision binary32 (* (+ maxCos -1.0) (* ux (sqrt -1.0))))
float code(float ux, float uy, float maxCos) {
return (maxCos + -1.0f) * (ux * sqrtf(-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 = (maxcos + (-1.0e0)) * (ux * sqrt((-1.0e0)))
end function
function code(ux, uy, maxCos) return Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * sqrt(Float32(-1.0)))) end
function tmp = code(ux, uy, maxCos) tmp = (maxCos + single(-1.0)) * (ux * sqrt(single(-1.0))); end
\begin{array}{l}
\\
\left(maxCos + -1\right) \cdot \left(ux \cdot \sqrt{-1}\right)
\end{array}
Initial program 56.2%
associate-*l*56.2%
cancel-sign-sub-inv56.2%
+-commutative56.2%
*-commutative56.2%
fma-def56.1%
Simplified56.0%
Taylor expanded in uy around 0 46.6%
Taylor expanded in ux around inf -0.0%
Simplified-0.0%
Final simplification-0.0%
(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 56.2%
associate-*l*56.2%
cancel-sign-sub-inv56.2%
+-commutative56.2%
*-commutative56.2%
fma-def56.1%
Simplified56.0%
Taylor expanded in uy around 0 46.6%
Taylor expanded in ux around 0 65.1%
Final simplification65.1%
herbie shell --seed 2023301
(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)))))))