
(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 14 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 (cbrt (* (pow (* uy 2.0) 3.0) (pow PI 3.0)))) (sqrt (fma (fma maxCos -2.0 2.0) ux (* (* ux ux) (- (pow (- 1.0 maxCos) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf(cbrtf((powf((uy * 2.0f), 3.0f) * powf(((float) M_PI), 3.0f)))) * sqrtf(fmaf(fmaf(maxCos, -2.0f, 2.0f), ux, ((ux * ux) * -powf((1.0f - maxCos), 2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(cbrt(Float32((Float32(uy * Float32(2.0)) ^ Float32(3.0)) * (Float32(pi) ^ Float32(3.0))))) * sqrt(fma(fma(maxCos, Float32(-2.0), Float32(2.0)), ux, Float32(Float32(ux * ux) * Float32(-(Float32(Float32(1.0) - maxCos) ^ Float32(2.0))))))) end
\begin{array}{l}
\\
\cos \left(\sqrt[3]{{\left(uy \cdot 2\right)}^{3} \cdot {\pi}^{3}}\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)}
\end{array}
Initial program 55.7%
associate-*l*55.7%
+-commutative55.7%
associate-+r-55.8%
fma-def55.8%
+-commutative55.8%
associate-+r-55.7%
fma-def55.7%
Simplified55.7%
Taylor expanded in ux around -inf 99.0%
metadata-eval99.0%
cancel-sign-sub-inv99.0%
*-commutative99.0%
fma-def99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
fma-def99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
associate-*r*99.0%
add-cbrt-cube99.0%
add-cbrt-cube99.0%
cbrt-unprod99.0%
pow399.1%
pow399.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (fma (fma maxCos -2.0 2.0) ux (* (* ux ux) (- (pow (- 1.0 maxCos) 2.0))))) (cos (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(fmaf(maxCos, -2.0f, 2.0f), ux, ((ux * ux) * -powf((1.0f - maxCos), 2.0f)))) * cosf((uy * (2.0f * ((float) M_PI))));
}
function code(ux, uy, maxCos) return Float32(sqrt(fma(fma(maxCos, Float32(-2.0), Float32(2.0)), ux, Float32(Float32(ux * ux) * Float32(-(Float32(Float32(1.0) - maxCos) ^ Float32(2.0)))))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi))))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(\mathsf{fma}\left(maxCos, -2, 2\right), ux, \left(ux \cdot ux\right) \cdot \left(-{\left(1 - maxCos\right)}^{2}\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Initial program 55.7%
associate-*l*55.7%
+-commutative55.7%
associate-+r-55.8%
fma-def55.8%
+-commutative55.8%
associate-+r-55.7%
fma-def55.7%
Simplified55.7%
Taylor expanded in ux around -inf 99.0%
metadata-eval99.0%
cancel-sign-sub-inv99.0%
*-commutative99.0%
fma-def99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
fma-def99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(* (- 1.0 maxCos) (* 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), ((1.0f - maxCos) * (2.0f * ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos + Float32(-1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(2.0) * ux))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos + -1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), \left(1 - maxCos\right) \cdot \left(2 \cdot ux\right)\right)}
\end{array}
Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.7%
+-commutative55.7%
associate-+r-55.7%
fma-def55.7%
neg-sub055.7%
+-commutative55.7%
associate-+r-55.6%
associate--r-55.6%
neg-sub055.6%
+-commutative55.6%
sub-neg55.6%
fma-def55.6%
Simplified55.6%
Taylor expanded in ux around 0 98.9%
fma-def98.9%
sub-neg98.9%
metadata-eval98.9%
*-commutative98.9%
unpow298.9%
+-commutative98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
distribute-neg-in98.9%
metadata-eval98.9%
+-commutative98.9%
mul-1-neg98.9%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
pow199.0%
count-299.0%
Applied egg-rr99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0015999999595806003)
(sqrt
(-
(* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
(* ux (- (* 2.0 maxCos) 2.0))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0015999999595806003f) {
tmp = sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 2.0f))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * 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.0015999999595806003)) tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.0015999999595806003)) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0015999999595806003:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00159999996Initial program 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def55.9%
+-commutative55.9%
associate-+r-55.9%
fma-def55.9%
neg-sub055.9%
+-commutative55.9%
associate-+r-55.8%
associate--r-55.8%
neg-sub055.8%
+-commutative55.8%
sub-neg55.8%
fma-def55.8%
Simplified55.8%
Taylor expanded in uy around 0 55.3%
Taylor expanded in ux around 0 58.3%
associate--l+58.0%
associate-*r*58.0%
*-commutative58.0%
sub-neg58.0%
metadata-eval58.0%
unpow258.0%
fma-neg58.0%
associate--l+58.1%
mul-1-neg58.1%
sub-neg58.1%
metadata-eval58.1%
distribute-neg-in58.1%
metadata-eval58.1%
+-commutative58.1%
sub-neg58.1%
metadata-eval58.1%
Simplified58.1%
Taylor expanded in ux around 0 97.8%
if 0.00159999996 < (*.f32 uy 2) Initial program 55.3%
associate-*l*55.3%
+-commutative55.3%
associate-+r-55.4%
fma-def55.4%
+-commutative55.4%
associate-+r-55.3%
fma-def55.3%
Simplified55.3%
Taylor expanded in ux around 0 78.7%
Final simplification91.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0016499999910593033)
(sqrt
(-
(* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0)))
(* ux (- (* 2.0 maxCos) 2.0))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0016499999910593033f) {
tmp = sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 2.0f))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0016499999910593033)) tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.0016499999910593033)) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0016499999910593033:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00165Initial program 55.6%
associate-*l*55.6%
sub-neg55.6%
+-commutative55.6%
distribute-rgt-neg-in55.6%
fma-def55.6%
+-commutative55.6%
associate-+r-55.6%
fma-def55.6%
neg-sub055.6%
+-commutative55.6%
associate-+r-55.5%
associate--r-55.5%
neg-sub055.5%
+-commutative55.5%
sub-neg55.5%
fma-def55.5%
Simplified55.5%
Taylor expanded in uy around 0 55.0%
Taylor expanded in ux around 0 58.0%
associate--l+57.7%
associate-*r*57.7%
*-commutative57.7%
sub-neg57.7%
metadata-eval57.7%
unpow257.7%
fma-neg57.7%
associate--l+57.8%
mul-1-neg57.8%
sub-neg57.8%
metadata-eval57.8%
distribute-neg-in57.8%
metadata-eval57.8%
+-commutative57.8%
sub-neg57.8%
metadata-eval57.8%
Simplified57.8%
Taylor expanded in ux around 0 97.7%
if 0.00165 < (*.f32 uy 2) Initial program 55.8%
associate-*l*55.8%
+-commutative55.8%
associate-+r-56.0%
fma-def56.0%
+-commutative56.0%
associate-+r-55.9%
fma-def55.9%
Simplified55.9%
Taylor expanded in ux around 0 44.3%
Taylor expanded in maxCos around 0 76.0%
Final simplification90.4%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 55.7%
associate-*l*55.7%
+-commutative55.7%
associate-+r-55.8%
fma-def55.8%
+-commutative55.8%
associate-+r-55.7%
fma-def55.7%
Simplified55.7%
Taylor expanded in ux around -inf 99.0%
metadata-eval99.0%
cancel-sign-sub-inv99.0%
*-commutative99.0%
fma-def99.0%
cancel-sign-sub-inv99.0%
metadata-eval99.0%
+-commutative99.0%
*-commutative99.0%
fma-def99.0%
mul-1-neg99.0%
distribute-rgt-neg-in99.0%
unpow299.0%
mul-1-neg99.0%
sub-neg99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 94.3%
+-commutative94.3%
mul-1-neg94.3%
unsub-neg94.3%
unpow294.3%
Simplified94.3%
Final simplification94.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* (- 1.0 maxCos) (* (+ maxCos -1.0) (pow ux 2.0))) (* ux (- (* 2.0 maxCos) 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - maxCos) * ((maxCos + -1.0f) * powf(ux, 2.0f))) - (ux * ((2.0f * maxCos) - 2.0f))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((((1.0e0 - maxcos) * ((maxcos + (-1.0e0)) * (ux ** 2.0e0))) - (ux * ((2.0e0 * maxcos) - 2.0e0))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))) - Float32(ux * Float32(Float32(Float32(2.0) * maxCos) - Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - maxCos) * ((maxCos + single(-1.0)) * (ux ^ single(2.0)))) - (ux * ((single(2.0) * maxCos) - single(2.0))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left(\left(maxCos + -1\right) \cdot {ux}^{2}\right) - ux \cdot \left(2 \cdot maxCos - 2\right)}
\end{array}
Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.7%
+-commutative55.7%
associate-+r-55.7%
fma-def55.7%
neg-sub055.7%
+-commutative55.7%
associate-+r-55.6%
associate--r-55.6%
neg-sub055.6%
+-commutative55.6%
sub-neg55.6%
fma-def55.6%
Simplified55.6%
Taylor expanded in uy around 0 46.9%
Taylor expanded in ux around 0 49.2%
associate--l+49.0%
associate-*r*49.0%
*-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
unpow249.0%
fma-neg49.0%
associate--l+49.0%
mul-1-neg49.0%
sub-neg49.0%
metadata-eval49.0%
distribute-neg-in49.0%
metadata-eval49.0%
+-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
Simplified49.0%
Taylor expanded in ux around 0 79.2%
Final simplification79.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma 2.0 ux (* ux (- ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf(2.0f, ux, (ux * -ux)));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(2.0), ux, Float32(ux * Float32(-ux)))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(2, ux, ux \cdot \left(-ux\right)\right)}
\end{array}
Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.7%
+-commutative55.7%
associate-+r-55.7%
fma-def55.7%
neg-sub055.7%
+-commutative55.7%
associate-+r-55.6%
associate--r-55.6%
neg-sub055.6%
+-commutative55.6%
sub-neg55.6%
fma-def55.6%
Simplified55.6%
Taylor expanded in uy around 0 46.9%
Taylor expanded in ux around 0 49.2%
associate--l+49.0%
associate-*r*49.0%
*-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
unpow249.0%
fma-neg49.0%
associate--l+49.0%
mul-1-neg49.0%
sub-neg49.0%
metadata-eval49.0%
distribute-neg-in49.0%
metadata-eval49.0%
+-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
Simplified49.0%
Taylor expanded in maxCos around 0 75.8%
+-commutative75.8%
fma-def75.8%
mul-1-neg75.8%
unpow275.8%
distribute-rgt-neg-in75.8%
Simplified75.8%
Final simplification75.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ -1.0 (- ux (* maxCos ux))))
(t_1 (* (+ ux (- -1.0 (* maxCos ux))) t_0)))
(if (<= ux 7.999999797903001e-5)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt
(/ (+ 1.0 (* (* (- (+ 1.0 (* maxCos ux)) ux) t_0) t_1)) (+ 1.0 t_1))))))
float code(float ux, float uy, float maxCos) {
float t_0 = -1.0f + (ux - (maxCos * ux));
float t_1 = (ux + (-1.0f - (maxCos * ux))) * t_0;
float tmp;
if (ux <= 7.999999797903001e-5f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf(((1.0f + ((((1.0f + (maxCos * ux)) - ux) * t_0) * t_1)) / (1.0f + t_1)));
}
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) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = (-1.0e0) + (ux - (maxcos * ux))
t_1 = (ux + ((-1.0e0) - (maxcos * ux))) * t_0
if (ux <= 7.999999797903001e-5) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt(((1.0e0 + ((((1.0e0 + (maxcos * ux)) - ux) * t_0) * t_1)) / (1.0e0 + t_1)))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(Float32(-1.0) + Float32(ux - Float32(maxCos * ux))) t_1 = Float32(Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) * t_0) tmp = Float32(0.0) if (ux <= Float32(7.999999797903001e-5)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux) * t_0) * t_1)) / Float32(Float32(1.0) + t_1))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = single(-1.0) + (ux - (maxCos * ux)); t_1 = (ux + (single(-1.0) - (maxCos * ux))) * t_0; tmp = single(0.0); if (ux <= single(7.999999797903001e-5)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt(((single(1.0) + ((((single(1.0) + (maxCos * ux)) - ux) * t_0) * t_1)) / (single(1.0) + t_1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -1 + \left(ux - maxCos \cdot ux\right)\\
t_1 := \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot t_0\\
\mathbf{if}\;ux \leq 7.999999797903001 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1 + \left(\left(\left(1 + maxCos \cdot ux\right) - ux\right) \cdot t_0\right) \cdot t_1}{1 + t_1}}\\
\end{array}
\end{array}
if ux < 7.9999998e-5Initial program 32.8%
associate-*l*32.8%
sub-neg32.8%
+-commutative32.8%
distribute-rgt-neg-in32.8%
fma-def32.8%
+-commutative32.8%
associate-+r-32.9%
fma-def32.9%
neg-sub032.9%
+-commutative32.9%
associate-+r-32.8%
associate--r-32.8%
neg-sub032.8%
+-commutative32.8%
sub-neg32.8%
fma-def32.8%
Simplified32.8%
Taylor expanded in uy around 0 29.6%
Taylor expanded in ux around 0 32.6%
associate--l+32.6%
associate-*r*32.6%
*-commutative32.6%
sub-neg32.6%
metadata-eval32.6%
unpow232.6%
fma-neg32.6%
associate--l+32.6%
mul-1-neg32.6%
sub-neg32.6%
metadata-eval32.6%
distribute-neg-in32.6%
metadata-eval32.6%
+-commutative32.6%
sub-neg32.6%
metadata-eval32.6%
Simplified32.6%
Taylor expanded in ux around 0 76.6%
if 7.9999998e-5 < ux Initial program 89.6%
associate-*l*89.6%
sub-neg89.6%
+-commutative89.6%
distribute-rgt-neg-in89.6%
fma-def89.6%
+-commutative89.6%
associate-+r-89.7%
fma-def89.7%
neg-sub089.7%
+-commutative89.7%
associate-+r-89.6%
associate--r-89.6%
neg-sub089.6%
+-commutative89.6%
sub-neg89.6%
fma-def89.6%
Simplified89.6%
Taylor expanded in uy around 0 72.6%
flip-+72.6%
metadata-eval72.6%
associate--l+72.6%
associate--l+72.8%
associate--l+72.8%
Applied egg-rr72.8%
Final simplification75.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 9.999999747378752e-5)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt
(- 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (- (+ 1.0 (* maxCos ux)) ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f - ((1.0f + (ux * (maxCos + -1.0f))) * ((1.0f + (maxCos * ux)) - 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 <= 9.999999747378752e-5) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 - ((1.0e0 + (ux * (maxcos + (-1.0e0)))) * ((1.0e0 + (maxcos * ux)) - ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-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(Float32(1.0) + Float32(maxCos * ux)) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(9.999999747378752e-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) + (maxCos * ux)) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \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(\left(1 + maxCos \cdot ux\right) - ux\right)}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.1%
associate-*l*33.1%
sub-neg33.1%
+-commutative33.1%
distribute-rgt-neg-in33.1%
fma-def33.1%
+-commutative33.1%
associate-+r-33.1%
fma-def33.1%
neg-sub033.1%
+-commutative33.1%
associate-+r-33.1%
associate--r-33.1%
neg-sub033.1%
+-commutative33.1%
sub-neg33.1%
fma-def33.1%
Simplified33.1%
Taylor expanded in uy around 0 29.8%
Taylor expanded in ux around 0 32.8%
associate--l+32.8%
associate-*r*32.8%
*-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
unpow232.8%
fma-neg32.8%
associate--l+32.8%
mul-1-neg32.8%
sub-neg32.8%
metadata-eval32.8%
distribute-neg-in32.8%
metadata-eval32.8%
+-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
Simplified32.8%
Taylor expanded in ux around 0 76.6%
if 9.99999975e-5 < ux Initial program 89.8%
associate-*l*89.8%
sub-neg89.8%
+-commutative89.8%
distribute-rgt-neg-in89.8%
fma-def89.8%
+-commutative89.8%
associate-+r-89.8%
fma-def89.8%
neg-sub089.8%
+-commutative89.8%
associate-+r-89.7%
associate--r-89.7%
neg-sub089.7%
+-commutative89.7%
sub-neg89.7%
fma-def89.7%
Simplified89.7%
Taylor expanded in uy around 0 72.6%
Taylor expanded in ux around -inf 72.8%
mul-1-neg72.8%
unsub-neg72.8%
mul-1-neg72.8%
sub-neg72.8%
Simplified72.8%
Final simplification75.1%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 9.999999747378752e-5) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (- 1.0 (* (- 1.0 ux) (- (+ 1.0 (* maxCos ux)) ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f - ((1.0f - ux) * ((1.0f + (maxCos * ux)) - 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 <= 9.999999747378752e-5) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 - ((1.0e0 - ux) * ((1.0e0 + (maxcos * ux)) - ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-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) - ux) * Float32(Float32(Float32(1.0) + Float32(maxCos * ux)) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(9.999999747378752e-5)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) - ((single(1.0) - ux) * ((single(1.0) + (maxCos * ux)) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(\left(1 + maxCos \cdot ux\right) - ux\right)}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.1%
associate-*l*33.1%
sub-neg33.1%
+-commutative33.1%
distribute-rgt-neg-in33.1%
fma-def33.1%
+-commutative33.1%
associate-+r-33.1%
fma-def33.1%
neg-sub033.1%
+-commutative33.1%
associate-+r-33.1%
associate--r-33.1%
neg-sub033.1%
+-commutative33.1%
sub-neg33.1%
fma-def33.1%
Simplified33.1%
Taylor expanded in uy around 0 29.8%
Taylor expanded in ux around 0 32.8%
associate--l+32.8%
associate-*r*32.8%
*-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
unpow232.8%
fma-neg32.8%
associate--l+32.8%
mul-1-neg32.8%
sub-neg32.8%
metadata-eval32.8%
distribute-neg-in32.8%
metadata-eval32.8%
+-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
Simplified32.8%
Taylor expanded in ux around 0 76.6%
if 9.99999975e-5 < ux Initial program 89.8%
associate-*l*89.8%
sub-neg89.8%
+-commutative89.8%
distribute-rgt-neg-in89.8%
fma-def89.8%
+-commutative89.8%
associate-+r-89.8%
fma-def89.8%
neg-sub089.8%
+-commutative89.8%
associate-+r-89.7%
associate--r-89.7%
neg-sub089.7%
+-commutative89.7%
sub-neg89.7%
fma-def89.7%
Simplified89.7%
Taylor expanded in uy around 0 72.6%
Taylor expanded in maxCos around 0 69.8%
Final simplification73.9%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 9.999999747378752e-5) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (- 1.0 (* (+ ux -1.0) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f - ((ux + -1.0f) * (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 <= 9.999999747378752e-5) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 - ((ux + (-1.0e0)) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-5)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) - Float32(Float32(ux + Float32(-1.0)) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(9.999999747378752e-5)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) - ((ux + single(-1.0)) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(ux + -1\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.1%
associate-*l*33.1%
sub-neg33.1%
+-commutative33.1%
distribute-rgt-neg-in33.1%
fma-def33.1%
+-commutative33.1%
associate-+r-33.1%
fma-def33.1%
neg-sub033.1%
+-commutative33.1%
associate-+r-33.1%
associate--r-33.1%
neg-sub033.1%
+-commutative33.1%
sub-neg33.1%
fma-def33.1%
Simplified33.1%
Taylor expanded in uy around 0 29.8%
Taylor expanded in ux around 0 32.8%
associate--l+32.8%
associate-*r*32.8%
*-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
unpow232.8%
fma-neg32.8%
associate--l+32.8%
mul-1-neg32.8%
sub-neg32.8%
metadata-eval32.8%
distribute-neg-in32.8%
metadata-eval32.8%
+-commutative32.8%
sub-neg32.8%
metadata-eval32.8%
Simplified32.8%
Taylor expanded in ux around 0 76.6%
if 9.99999975e-5 < ux Initial program 89.8%
associate-*l*89.8%
sub-neg89.8%
+-commutative89.8%
distribute-rgt-neg-in89.8%
fma-def89.8%
+-commutative89.8%
associate-+r-89.8%
fma-def89.8%
neg-sub089.8%
+-commutative89.8%
associate-+r-89.7%
associate--r-89.7%
neg-sub089.7%
+-commutative89.7%
sub-neg89.7%
fma-def89.7%
Simplified89.7%
Taylor expanded in uy around 0 72.6%
Taylor expanded in maxCos around 0 69.5%
Final simplification73.8%
(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 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.7%
+-commutative55.7%
associate-+r-55.7%
fma-def55.7%
neg-sub055.7%
+-commutative55.7%
associate-+r-55.6%
associate--r-55.6%
neg-sub055.6%
+-commutative55.6%
sub-neg55.6%
fma-def55.6%
Simplified55.6%
Taylor expanded in uy around 0 46.9%
Taylor expanded in ux around 0 49.2%
associate--l+49.0%
associate-*r*49.0%
*-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
unpow249.0%
fma-neg49.0%
associate--l+49.0%
mul-1-neg49.0%
sub-neg49.0%
metadata-eval49.0%
distribute-neg-in49.0%
metadata-eval49.0%
+-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
Simplified49.0%
Taylor expanded in ux around 0 64.2%
Final simplification64.2%
(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 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-def55.7%
+-commutative55.7%
associate-+r-55.7%
fma-def55.7%
neg-sub055.7%
+-commutative55.7%
associate-+r-55.6%
associate--r-55.6%
neg-sub055.6%
+-commutative55.6%
sub-neg55.6%
fma-def55.6%
Simplified55.6%
Taylor expanded in uy around 0 46.9%
Taylor expanded in ux around 0 49.2%
associate--l+49.0%
associate-*r*49.0%
*-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
unpow249.0%
fma-neg49.0%
associate--l+49.0%
mul-1-neg49.0%
sub-neg49.0%
metadata-eval49.0%
distribute-neg-in49.0%
metadata-eval49.0%
+-commutative49.0%
sub-neg49.0%
metadata-eval49.0%
Simplified49.0%
Taylor expanded in ux around 0 64.2%
Taylor expanded in maxCos around 0 62.3%
*-commutative62.3%
Simplified62.3%
Final simplification62.3%
herbie shell --seed 2023255
(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)))))))