
(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 (log (+ 1.0 (expm1 (* uy (* 2.0 PI)))))) (sqrt (* ux (- (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf(logf((1.0f + expm1f((uy * (2.0f * ((float) M_PI))))))) * sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) - (2.0f * maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(log(Float32(Float32(1.0) + expm1(Float32(uy * Float32(Float32(2.0) * Float32(pi))))))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) - Float32(Float32(2.0) * maxCos))))) end
\begin{array}{l}
\\
\cos \log \left(1 + \mathsf{expm1}\left(uy \cdot \left(2 \cdot \pi\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 99.1%
associate-*r*99.1%
log1p-expm1-u99.1%
log1p-undefine99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 (+ (* 2.0 maxCos) (* ux (pow (+ -1.0 maxCos) 2.0))))))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ((2.0f * maxCos) + (ux * powf((-1.0f + maxCos), 2.0f))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(Float32(2.0) * maxCos) + Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ((single(2.0) * maxCos) + (ux * ((single(-1.0) + maxCos) ^ single(2.0))))))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - \left(2 \cdot maxCos + ux \cdot {\left(-1 + maxCos\right)}^{2}\right)\right)}
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 99.1%
associate--l+99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* ux (- (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* 2.0 maxCos)))) (cos (* PI (* uy 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) - (2.0f * maxCos)))) * 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) + maxCos) ^ Float32(2.0)))) - Float32(Float32(2.0) * maxCos)))) * 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)))) - (single(2.0) * maxCos)))) * cos((single(pi) * (uy * single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) - 2 \cdot maxCos\right)} \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (- (* ux (- 2.0 ux)) (* maxCos (* ux (- 2.0 (* 2.0 ux))))))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(((ux * (2.0f - ux)) - (maxCos * (ux * (2.0f - (2.0f * ux))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) - ux)) - Float32(maxCos * Float32(ux * Float32(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 * (single(2.0) - ux)) - (maxCos * (ux * (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(2 - ux\right) - maxCos \cdot \left(ux \cdot \left(2 - 2 \cdot ux\right)\right)}
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 99.1%
Taylor expanded in maxCos around 0 97.8%
Final simplification97.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= maxCos 1.2000000424450263e-6) (* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 ux)))) (sqrt (* ux (- (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 1.2000000424450263e-6f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(1.2000000424450263e-6)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) - Float32(Float32(2.0) * maxCos)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(1.2000000424450263e-6)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt((ux * ((single(2.0) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.2000000424450263 \cdot 10^{-6}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 1.2e-6Initial program 56.1%
Taylor expanded in ux around 0 99.1%
Taylor expanded in maxCos around 0 98.9%
neg-mul-198.9%
unsub-neg98.9%
Simplified98.9%
if 1.2e-6 < maxCos Initial program 47.3%
Taylor expanded in ux around 0 99.0%
Taylor expanded in uy around 0 85.4%
Final simplification96.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= maxCos 1.2000000424450263e-5) (* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 ux)))) (* (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (cos (* 2.0 (* uy PI))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 1.2000000424450263e-5f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos)))) * cosf((2.0f * (uy * ((float) M_PI))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(1.2000000424450263e-5)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = Float32(sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) * cos(Float32(Float32(2.0) * Float32(uy * Float32(pi))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(1.2000000424450263e-5)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))) * cos((single(2.0) * (uy * single(pi)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.2000000424450263 \cdot 10^{-5}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)\\
\end{array}
\end{array}
if maxCos < 1.20000004e-5Initial program 55.9%
Taylor expanded in ux around 0 99.1%
Taylor expanded in maxCos around 0 98.5%
neg-mul-198.5%
unsub-neg98.5%
Simplified98.5%
if 1.20000004e-5 < maxCos Initial program 46.7%
Taylor expanded in ux around 0 82.3%
Final simplification96.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 1.2000000424450263e-5)
(* (cos (* PI (* uy 2.0))) (sqrt (* ux (- 2.0 ux))))
(*
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(+ 1.0 (* -2.0 (* (* uy PI) (* uy PI)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 1.2000000424450263e-5f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos)))) * (1.0f + (-2.0f * ((uy * ((float) M_PI)) * (uy * ((float) M_PI)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(1.2000000424450263e-5)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = Float32(sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) * Float32(Float32(1.0) + Float32(Float32(-2.0) * Float32(Float32(uy * Float32(pi)) * Float32(uy * Float32(pi)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(1.2000000424450263e-5)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))) * (single(1.0) + (single(-2.0) * ((uy * single(pi)) * (uy * single(pi))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.2000000424450263 \cdot 10^{-5}:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \left(1 + -2 \cdot \left(\left(uy \cdot \pi\right) \cdot \left(uy \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if maxCos < 1.20000004e-5Initial program 55.9%
Taylor expanded in ux around 0 99.1%
Taylor expanded in maxCos around 0 98.5%
neg-mul-198.5%
unsub-neg98.5%
Simplified98.5%
if 1.20000004e-5 < maxCos Initial program 46.7%
Taylor expanded in ux around 0 82.3%
Taylor expanded in uy around 0 79.4%
unpow279.4%
unpow279.4%
swap-sqr79.4%
unpow279.4%
Simplified79.4%
unpow279.4%
Applied egg-rr79.4%
Final simplification96.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00015999999595806003)
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))
(sqrt
(+ 1.0 (* (- (+ 1.0 (* ux maxCos)) ux) (- -1.0 (* ux (+ -1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
} else {
tmp = sqrtf((1.0f + (((1.0f + (ux * maxCos)) - ux) * (-1.0f - (ux * (-1.0f + maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - 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 = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); else tmp = sqrt((single(1.0) + (((single(1.0) + (ux * maxCos)) - 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:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(\left(1 + ux \cdot maxCos\right) - ux\right) \cdot \left(-1 - ux \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 37.5%
associate-*l*37.5%
sub-neg37.5%
+-commutative37.5%
distribute-rgt-neg-in37.5%
fma-define37.4%
Simplified37.4%
Taylor expanded in maxCos around 0 37.0%
Taylor expanded in ux around 0 87.3%
if 1.59999996e-4 < ux Initial program 89.9%
associate-*l*89.9%
sub-neg89.9%
+-commutative89.9%
distribute-rgt-neg-in89.9%
fma-define90.3%
Simplified90.5%
Taylor expanded in uy around 0 76.3%
Final simplification83.7%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00015999999595806003)
(*
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(+ 1.0 (* -2.0 (* (* uy PI) (* uy PI)))))
(sqrt
(+ 1.0 (* (- (+ 1.0 (* ux maxCos)) 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)))) * (1.0f + (-2.0f * ((uy * ((float) M_PI)) * (uy * ((float) M_PI)))));
} else {
tmp = sqrtf((1.0f + (((1.0f + (ux * maxCos)) - ux) * (-1.0f - (ux * (-1.0f + maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = Float32(sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) * Float32(Float32(1.0) + Float32(Float32(-2.0) * Float32(Float32(uy * Float32(pi)) * Float32(uy * Float32(pi)))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - 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)))) * (single(1.0) + (single(-2.0) * ((uy * single(pi)) * (uy * single(pi))))); else tmp = sqrt((single(1.0) + (((single(1.0) + (ux * maxCos)) - 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)} \cdot \left(1 + -2 \cdot \left(\left(uy \cdot \pi\right) \cdot \left(uy \cdot \pi\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(\left(1 + ux \cdot maxCos\right) - ux\right) \cdot \left(-1 - ux \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 37.5%
Taylor expanded in ux around 0 92.8%
Taylor expanded in uy around 0 84.6%
unpow284.6%
unpow284.6%
swap-sqr84.6%
unpow284.6%
Simplified84.6%
unpow284.6%
Applied egg-rr84.6%
if 1.59999996e-4 < ux Initial program 89.9%
associate-*l*89.9%
sub-neg89.9%
+-commutative89.9%
distribute-rgt-neg-in89.9%
fma-define90.3%
Simplified90.5%
Taylor expanded in uy around 0 76.3%
Final simplification81.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00011999999696854502)
(sqrt (* maxCos (+ (* ux -2.0) (* 2.0 (/ ux maxCos)))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ -1.0 maxCos))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00011999999696854502f) {
tmp = sqrtf((maxCos * ((ux * -2.0f) + (2.0f * (ux / maxCos)))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (-1.0f + maxCos))) * (-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.00011999999696854502e0) then
tmp = sqrt((maxcos * ((ux * (-2.0e0)) + (2.0e0 * (ux / maxcos)))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * ((-1.0e0) + maxcos))) * ((-1.0e0) + (ux - (ux * maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00011999999696854502)) tmp = sqrt(Float32(maxCos * Float32(Float32(ux * Float32(-2.0)) + Float32(Float32(2.0) * Float32(ux / maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(Float32(-1.0) + maxCos))) * 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.00011999999696854502)) tmp = sqrt((maxCos * ((ux * single(-2.0)) + (single(2.0) * (ux / maxCos))))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (single(-1.0) + maxCos))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00011999999696854502:\\
\;\;\;\;\sqrt{maxCos \cdot \left(ux \cdot -2 + 2 \cdot \frac{ux}{maxCos}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(-1 + maxCos\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.19999997e-4Initial program 36.6%
Taylor expanded in ux around 0 93.3%
Taylor expanded in uy around 0 77.2%
Taylor expanded in maxCos around inf 77.2%
if 1.19999997e-4 < ux Initial program 89.2%
associate-*l*89.2%
sub-neg89.2%
+-commutative89.2%
distribute-rgt-neg-in89.2%
fma-define89.5%
Simplified89.6%
Taylor expanded in uy around 0 75.1%
mul-1-neg75.1%
unsub-neg75.1%
sub-neg75.1%
metadata-eval75.1%
distribute-lft-in75.1%
*-commutative75.1%
mul-1-neg75.1%
sub-neg75.1%
*-commutative75.1%
associate--l+75.0%
unpow275.0%
sub-neg75.0%
Simplified75.1%
Final simplification76.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00011999999696854502)
(sqrt (* maxCos (+ (* ux -2.0) (* 2.0 (/ ux maxCos)))))
(sqrt
(+ 1.0 (* (- (+ 1.0 (* ux maxCos)) ux) (- -1.0 (* ux (+ -1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00011999999696854502f) {
tmp = sqrtf((maxCos * ((ux * -2.0f) + (2.0f * (ux / maxCos)))));
} else {
tmp = sqrtf((1.0f + (((1.0f + (ux * maxCos)) - 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.00011999999696854502e0) then
tmp = sqrt((maxcos * ((ux * (-2.0e0)) + (2.0e0 * (ux / maxcos)))))
else
tmp = sqrt((1.0e0 + (((1.0e0 + (ux * maxcos)) - 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.00011999999696854502)) tmp = sqrt(Float32(maxCos * Float32(Float32(ux * Float32(-2.0)) + Float32(Float32(2.0) * Float32(ux / maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - 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.00011999999696854502)) tmp = sqrt((maxCos * ((ux * single(-2.0)) + (single(2.0) * (ux / maxCos))))); else tmp = sqrt((single(1.0) + (((single(1.0) + (ux * maxCos)) - 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.00011999999696854502:\\
\;\;\;\;\sqrt{maxCos \cdot \left(ux \cdot -2 + 2 \cdot \frac{ux}{maxCos}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(\left(1 + ux \cdot maxCos\right) - ux\right) \cdot \left(-1 - ux \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.19999997e-4Initial program 36.6%
Taylor expanded in ux around 0 93.3%
Taylor expanded in uy around 0 77.2%
Taylor expanded in maxCos around inf 77.2%
if 1.19999997e-4 < ux Initial program 89.2%
associate-*l*89.2%
sub-neg89.2%
+-commutative89.2%
distribute-rgt-neg-in89.2%
fma-define89.5%
Simplified89.6%
Taylor expanded in uy around 0 75.1%
Final simplification76.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0003499999875202775) (sqrt (* maxCos (+ (* ux -2.0) (* 2.0 (/ ux maxCos))))) (sqrt (+ 1.0 (* (+ 1.0 (- (* ux maxCos) ux)) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0003499999875202775f) {
tmp = sqrtf((maxCos * ((ux * -2.0f) + (2.0f * (ux / maxCos)))));
} else {
tmp = sqrtf((1.0f + ((1.0f + ((ux * maxCos) - 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.0003499999875202775e0) then
tmp = sqrt((maxcos * ((ux * (-2.0e0)) + (2.0e0 * (ux / maxcos)))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + ((ux * maxcos) - ux)) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0003499999875202775)) tmp = sqrt(Float32(maxCos * Float32(Float32(ux * Float32(-2.0)) + Float32(Float32(2.0) * Float32(ux / maxCos))))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(Float32(ux * maxCos) - 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.0003499999875202775)) tmp = sqrt((maxCos * ((ux * single(-2.0)) + (single(2.0) * (ux / maxCos))))); else tmp = sqrt((single(1.0) + ((single(1.0) + ((ux * maxCos) - ux)) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0003499999875202775:\\
\;\;\;\;\sqrt{maxCos \cdot \left(ux \cdot -2 + 2 \cdot \frac{ux}{maxCos}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + \left(ux \cdot maxCos - ux\right)\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 3.49999988e-4Initial program 38.7%
Taylor expanded in ux around 0 92.1%
Taylor expanded in uy around 0 76.3%
Taylor expanded in maxCos around inf 76.3%
if 3.49999988e-4 < ux Initial program 91.2%
associate-*l*91.2%
sub-neg91.2%
+-commutative91.2%
distribute-rgt-neg-in91.2%
fma-define91.4%
Simplified91.6%
Taylor expanded in uy around 0 76.4%
mul-1-neg76.4%
unsub-neg76.4%
sub-neg76.4%
metadata-eval76.4%
distribute-lft-in76.4%
*-commutative76.4%
mul-1-neg76.4%
sub-neg76.4%
*-commutative76.4%
associate--l+76.3%
unpow276.3%
sub-neg76.3%
Simplified76.4%
Taylor expanded in maxCos around 0 73.6%
neg-mul-173.6%
Simplified73.6%
Final simplification75.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0003499999875202775) (sqrt (* maxCos (+ (* ux -2.0) (* 2.0 (/ ux maxCos))))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0003499999875202775f) {
tmp = sqrtf((maxCos * ((ux * -2.0f) + (2.0f * (ux / 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.0003499999875202775e0) then
tmp = sqrt((maxcos * ((ux * (-2.0e0)) + (2.0e0 * (ux / 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.0003499999875202775)) tmp = sqrt(Float32(maxCos * Float32(Float32(ux * Float32(-2.0)) + Float32(Float32(2.0) * Float32(ux / 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.0003499999875202775)) tmp = sqrt((maxCos * ((ux * single(-2.0)) + (single(2.0) * (ux / 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.0003499999875202775:\\
\;\;\;\;\sqrt{maxCos \cdot \left(ux \cdot -2 + 2 \cdot \frac{ux}{maxCos}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 3.49999988e-4Initial program 38.7%
Taylor expanded in ux around 0 92.1%
Taylor expanded in uy around 0 76.3%
Taylor expanded in maxCos around inf 76.3%
if 3.49999988e-4 < ux Initial program 91.2%
associate-*l*91.2%
sub-neg91.2%
+-commutative91.2%
distribute-rgt-neg-in91.2%
fma-define91.4%
Simplified91.6%
Taylor expanded in uy around 0 76.4%
mul-1-neg76.4%
unsub-neg76.4%
sub-neg76.4%
metadata-eval76.4%
distribute-lft-in76.4%
*-commutative76.4%
mul-1-neg76.4%
sub-neg76.4%
*-commutative76.4%
associate--l+76.3%
unpow276.3%
sub-neg76.3%
Simplified76.4%
Taylor expanded in maxCos around 0 73.2%
Final simplification75.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* maxCos (+ (* ux -2.0) (* 2.0 (/ ux maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((maxCos * ((ux * -2.0f) + (2.0f * (ux / 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 * ((ux * (-2.0e0)) + (2.0e0 * (ux / maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(maxCos * Float32(Float32(ux * Float32(-2.0)) + Float32(Float32(2.0) * Float32(ux / maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((maxCos * ((ux * single(-2.0)) + (single(2.0) * (ux / maxCos))))); end
\begin{array}{l}
\\
\sqrt{maxCos \cdot \left(ux \cdot -2 + 2 \cdot \frac{ux}{maxCos}\right)}
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 79.1%
Taylor expanded in uy around 0 67.3%
Taylor expanded in maxCos around inf 67.3%
Final simplification67.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) + (-2.0f * (ux * 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(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}
\end{array}
Initial program 54.7%
Taylor expanded in ux around 0 79.1%
Taylor expanded in uy around 0 67.3%
Taylor expanded in maxCos around 0 67.3%
Final simplification67.3%
(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 54.7%
Taylor expanded in ux around 0 79.1%
Taylor expanded in uy around 0 67.3%
Final simplification67.3%
(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 54.7%
Taylor expanded in ux around 0 79.1%
Taylor expanded in uy around 0 67.3%
Taylor expanded in maxCos around 0 64.0%
Final simplification64.0%
herbie shell --seed 2024055
(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)))))))