
(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 (exp (log (* uy (* 2.0 PI)))))
(sqrt
(*
ux
(+ (+ 2.0 (* ux (+ -1.0 (* maxCos (- 2.0 maxCos))))) (* maxCos -2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf(expf(logf((uy * (2.0f * ((float) M_PI)))))) * sqrtf((ux * ((2.0f + (ux * (-1.0f + (maxCos * (2.0f - maxCos))))) + (maxCos * -2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(exp(log(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(ux * Float32(Float32(-1.0) + Float32(maxCos * Float32(Float32(2.0) - maxCos))))) + Float32(maxCos * Float32(-2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(exp(log((uy * (single(2.0) * single(pi)))))) * sqrt((ux * ((single(2.0) + (ux * (single(-1.0) + (maxCos * (single(2.0) - maxCos))))) + (maxCos * single(-2.0))))); end
\begin{array}{l}
\\
\cos \left(e^{\log \left(uy \cdot \left(2 \cdot \pi\right)\right)}\right) \cdot \sqrt{ux \cdot \left(\left(2 + ux \cdot \left(-1 + maxCos \cdot \left(2 - maxCos\right)\right)\right) + maxCos \cdot -2\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
metadata-eval99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 99.0%
add-exp-log99.0%
associate-*l*99.0%
Applied egg-rr99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(*
ux
(+ (+ 2.0 (* ux (+ -1.0 (* maxCos (- 2.0 maxCos))))) (* maxCos -2.0))))
(cos (* PI (* uy 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f + (ux * (-1.0f + (maxCos * (2.0f - maxCos))))) + (maxCos * -2.0f)))) * cosf((((float) M_PI) * (uy * 2.0f)));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(ux * Float32(Float32(-1.0) + Float32(maxCos * Float32(Float32(2.0) - maxCos))))) + Float32(maxCos * Float32(-2.0))))) * cos(Float32(Float32(pi) * Float32(uy * Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) + (ux * (single(-1.0) + (maxCos * (single(2.0) - maxCos))))) + (maxCos * single(-2.0))))) * cos((single(pi) * (uy * single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 + ux \cdot \left(-1 + maxCos \cdot \left(2 - maxCos\right)\right)\right) + maxCos \cdot -2\right)} \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
metadata-eval99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (- (* maxCos (* ux (- (- 2.0) (* ux -2.0)))) (* ux (+ ux -2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(((maxCos * (ux * (-2.0f - (ux * -2.0f)))) - (ux * (ux + -2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(maxCos * Float32(ux * Float32(Float32(-Float32(2.0)) - Float32(ux * Float32(-2.0))))) - Float32(ux * Float32(ux + Float32(-2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt(((maxCos * (ux * (-single(2.0) - (ux * single(-2.0))))) - (ux * (ux + single(-2.0))))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{maxCos \cdot \left(ux \cdot \left(\left(-2\right) - ux \cdot -2\right)\right) - ux \cdot \left(ux + -2\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 59.5%
Taylor expanded in maxCos around 0 98.6%
associate-*r*98.6%
mul-1-neg98.6%
*-commutative98.6%
sub-neg98.6%
metadata-eval98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0001900000061141327)
(sqrt
(*
ux
(+ 2.0 (+ (* ux (+ -1.0 (* maxCos (- 2.0 maxCos)))) (* maxCos -2.0)))))
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0001900000061141327f) {
tmp = sqrtf((ux * (2.0f + ((ux * (-1.0f + (maxCos * (2.0f - maxCos)))) + (maxCos * -2.0f)))));
} else {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0001900000061141327)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) + Float32(maxCos * Float32(Float32(2.0) - maxCos)))) + Float32(maxCos * Float32(-2.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * 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(2.0)) <= single(0.0001900000061141327)) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) + (maxCos * (single(2.0) - maxCos)))) + (maxCos * single(-2.0)))))); else tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0001900000061141327:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 + maxCos \cdot \left(2 - maxCos\right)\right) + maxCos \cdot -2\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 1.90000006e-4Initial program 55.1%
Taylor expanded in ux around 0 99.5%
cancel-sign-sub-inv99.5%
associate-*r*99.5%
mul-1-neg99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
metadata-eval99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in maxCos around 0 99.5%
Taylor expanded in uy around 0 99.5%
if 1.90000006e-4 < (*.f32 uy #s(literal 2 binary32)) Initial program 58.4%
Taylor expanded in ux around 0 98.4%
cancel-sign-sub-inv98.4%
associate-*r*98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
metadata-eval98.4%
*-commutative98.4%
Simplified98.4%
Taylor expanded in maxCos around 0 92.2%
neg-mul-192.2%
unsub-neg92.2%
Simplified92.2%
Final simplification96.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0013000000035390258)
(sqrt
(*
ux
(+ 2.0 (+ (* ux (+ -1.0 (* maxCos (- 2.0 maxCos)))) (* maxCos -2.0)))))
(* (cos (* PI (* uy 2.0))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0013000000035390258f) {
tmp = sqrtf((ux * (2.0f + ((ux * (-1.0f + (maxCos * (2.0f - maxCos)))) + (maxCos * -2.0f)))));
} else {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0013000000035390258)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) + Float32(maxCos * Float32(Float32(2.0) - maxCos)))) + Float32(maxCos * Float32(-2.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.0013000000035390258)) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) + (maxCos * (single(2.0) - maxCos)))) + (maxCos * single(-2.0)))))); else tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0013000000035390258:\\
\;\;\;\;\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 + maxCos \cdot \left(2 - maxCos\right)\right) + maxCos \cdot -2\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 0.0013Initial program 56.0%
Taylor expanded in ux around 0 99.5%
cancel-sign-sub-inv99.5%
associate-*r*99.5%
mul-1-neg99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
metadata-eval99.5%
*-commutative99.5%
Simplified99.5%
Taylor expanded in maxCos around 0 99.5%
Taylor expanded in uy around 0 98.5%
if 0.0013 < (*.f32 uy #s(literal 2 binary32)) Initial program 57.3%
Taylor expanded in ux around 0 49.6%
Taylor expanded in maxCos around 0 75.3%
Final simplification90.2%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (* ux (+ (* maxCos -2.0) (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * ((maxCos * -2.0f) + (2.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(maxCos * Float32(-2.0)) + Float32(Float32(2.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * ((maxCos * single(-2.0)) + (single(2.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(maxCos \cdot -2 + \left(2 - ux\right)\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
metadata-eval99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 97.4%
Final simplification97.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 7.200000254670158e-5)
(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 <= 7.200000254670158e-5f) {
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 <= 7.200000254670158e-5) 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(7.200000254670158e-5)) 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(7.200000254670158e-5)) 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 7.200000254670158 \cdot 10^{-5}:\\
\;\;\;\;\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.20000025e-5Initial program 34.2%
associate-*l*34.2%
sub-neg34.2%
+-commutative34.2%
distribute-rgt-neg-in34.2%
fma-define34.2%
Simplified34.2%
Taylor expanded in uy around 0 30.3%
Simplified30.2%
Taylor expanded in ux around 0 75.5%
if 7.20000025e-5 < ux Initial program 86.6%
associate-*l*86.6%
sub-neg86.6%
+-commutative86.6%
distribute-rgt-neg-in86.6%
fma-define86.5%
Simplified86.8%
Taylor expanded in uy around 0 72.0%
Simplified72.1%
Final simplification74.0%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0001500000071246177) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (- 1.0 (* (- 1.0 (- ux (* ux maxCos))) (- 1.0 ux))))))
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 - (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.0001500000071246177e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 - ((1.0e0 - (ux - (ux * maxcos))) * (1.0e0 - ux))))
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(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.0001500000071246177)) 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)))); 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 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.50000007e-4Initial program 35.7%
associate-*l*35.7%
sub-neg35.7%
+-commutative35.7%
distribute-rgt-neg-in35.7%
fma-define35.7%
Simplified35.8%
Taylor expanded in uy around 0 31.6%
Simplified31.4%
Taylor expanded in ux around 0 74.6%
if 1.50000007e-4 < ux Initial program 87.8%
associate-*l*87.8%
sub-neg87.8%
+-commutative87.8%
distribute-rgt-neg-in87.8%
fma-define87.8%
Simplified88.0%
Taylor expanded in uy around 0 73.0%
Simplified73.1%
Taylor expanded in maxCos around 0 70.7%
neg-mul-170.7%
Simplified70.7%
Final simplification73.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (+ (* ux (+ -1.0 (* maxCos (- 2.0 maxCos)))) (* maxCos -2.0))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + ((ux * (-1.0f + (maxCos * (2.0f - maxCos)))) + (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 + ((ux * ((-1.0e0) + (maxcos * (2.0e0 - maxcos)))) + (maxcos * (-2.0e0))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(ux * Float32(Float32(-1.0) + Float32(maxCos * Float32(Float32(2.0) - maxCos)))) + Float32(maxCos * Float32(-2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + ((ux * (single(-1.0) + (maxCos * (single(2.0) - maxCos)))) + (maxCos * single(-2.0)))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + \left(ux \cdot \left(-1 + maxCos \cdot \left(2 - maxCos\right)\right) + maxCos \cdot -2\right)\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.0%
cancel-sign-sub-inv99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
metadata-eval99.0%
*-commutative99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 99.0%
Taylor expanded in uy around 0 78.9%
Final simplification78.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00023799999326001853) (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.00023799999326001853f) {
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.00023799999326001853e0) 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.00023799999326001853)) 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.00023799999326001853)) 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.00023799999326001853:\\
\;\;\;\;\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.37999993e-4Initial program 37.1%
associate-*l*37.1%
sub-neg37.1%
+-commutative37.1%
distribute-rgt-neg-in37.1%
fma-define37.2%
Simplified37.3%
Taylor expanded in uy around 0 33.2%
Simplified33.0%
Taylor expanded in ux around 0 74.5%
if 2.37999993e-4 < ux Initial program 88.7%
associate-*l*88.7%
sub-neg88.7%
+-commutative88.7%
distribute-rgt-neg-in88.7%
fma-define88.6%
Simplified88.8%
Taylor expanded in uy around 0 72.9%
Simplified73.1%
Taylor expanded in maxCos around 0 70.1%
Final simplification72.9%
(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.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.6%
Taylor expanded in uy around 0 48.1%
Simplified48.0%
Taylor expanded in ux around 0 64.5%
Final simplification64.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.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.6%
Taylor expanded in uy around 0 48.1%
Simplified48.0%
Taylor expanded in ux around 0 64.5%
Taylor expanded in maxCos around 0 61.8%
*-commutative61.8%
Simplified61.8%
Final simplification61.8%
herbie shell --seed 2024095
(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)))))))