
(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 15 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 (* 2.0 (* uy PI))) (sqrt (* (- 1.0 maxCos) (+ (* 2.0 ux) (* (+ maxCos -1.0) (pow ux 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((1.0f - maxCos) * ((2.0f * ux) + ((maxCos + -1.0f) * powf(ux, 2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) + Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) + ((maxCos + single(-1.0)) * (ux ^ single(2.0)))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux + \left(maxCos + -1\right) \cdot {ux}^{2}\right)}
\end{array}
Initial program 54.7%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in ux around inf 99.0%
fma-define99.0%
+-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-lft-in99.0%
metadata-eval99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
pow1/299.0%
pow-to-exp96.4%
count-296.4%
Applied egg-rr96.4%
Taylor expanded in uy around inf 99.0%
associate-*r*99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
associate-*r*99.0%
distribute-rgt-out99.0%
+-commutative99.0%
metadata-eval99.0%
sub-neg99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (* (- 1.0 maxCos) (- (* 2.0 ux) (pow ux 2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((1.0f - maxCos) * ((2.0f * ux) - powf(ux, 2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) - (ux ^ single(2.0))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux - {ux}^{2}\right)}
\end{array}
Initial program 54.7%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in ux around inf 99.0%
fma-define99.0%
+-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-lft-in99.0%
metadata-eval99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
pow1/299.0%
pow-to-exp96.4%
count-296.4%
Applied egg-rr96.4%
Taylor expanded in uy around inf 99.0%
associate-*r*99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
associate-*r*99.0%
distribute-rgt-out99.0%
+-commutative99.0%
metadata-eval99.0%
sub-neg99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in maxCos around 0 97.8%
mul-1-neg79.3%
Simplified97.8%
Final simplification97.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}
\end{array}
Initial program 54.7%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in ux around -inf 99.0%
Taylor expanded in maxCos around 0 93.6%
+-commutative93.6%
mul-1-neg93.6%
unsub-neg93.6%
*-commutative93.6%
Simplified93.6%
Final simplification93.6%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* PI (* 2.0 uy))))
(t_1
(+
1.0
(* (+ (- 1.0 ux) (* maxCos ux)) (- (+ ux -1.0) (* maxCos ux))))))
(if (<= t_1 0.00039999998989515007)
(* t_0 (sqrt (+ (* 2.0 ux) (* (* maxCos ux) -2.0))))
(* t_0 (sqrt t_1)))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf((((float) M_PI) * (2.0f * uy)));
float t_1 = 1.0f + (((1.0f - ux) + (maxCos * ux)) * ((ux + -1.0f) - (maxCos * ux)));
float tmp;
if (t_1 <= 0.00039999998989515007f) {
tmp = t_0 * sqrtf(((2.0f * ux) + ((maxCos * ux) * -2.0f)));
} else {
tmp = t_0 * sqrtf(t_1);
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) t_1 = Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) - ux) + Float32(maxCos * ux)) * Float32(Float32(ux + Float32(-1.0)) - Float32(maxCos * ux)))) tmp = Float32(0.0) if (t_1 <= Float32(0.00039999998989515007)) tmp = Float32(t_0 * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(maxCos * ux) * Float32(-2.0))))); else tmp = Float32(t_0 * sqrt(t_1)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos((single(pi) * (single(2.0) * uy))); t_1 = single(1.0) + (((single(1.0) - ux) + (maxCos * ux)) * ((ux + single(-1.0)) - (maxCos * ux))); tmp = single(0.0); if (t_1 <= single(0.00039999998989515007)) tmp = t_0 * sqrt(((single(2.0) * ux) + ((maxCos * ux) * single(-2.0)))); else tmp = t_0 * sqrt(t_1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
t_1 := 1 + \left(\left(1 - ux\right) + maxCos \cdot ux\right) \cdot \left(\left(ux + -1\right) - maxCos \cdot ux\right)\\
\mathbf{if}\;t\_1 \leq 0.00039999998989515007:\\
\;\;\;\;t\_0 \cdot \sqrt{2 \cdot ux + \left(maxCos \cdot ux\right) \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \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.9999999e-4Initial program 36.6%
Taylor expanded in ux around 0 93.1%
Taylor expanded in maxCos around 0 93.1%
if 3.9999999e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) Initial program 88.2%
Final simplification91.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.0012000000569969416) (sqrt (* (- 1.0 maxCos) (+ (* 2.0 ux) (* (+ maxCos -1.0) (pow ux 2.0))))) (* (cos (* PI (* 2.0 uy))) (sqrt (+ (* 2.0 ux) (* (* maxCos ux) -2.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0012000000569969416f) {
tmp = sqrtf(((1.0f - maxCos) * ((2.0f * ux) + ((maxCos + -1.0f) * powf(ux, 2.0f)))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf(((2.0f * ux) + ((maxCos * ux) * -2.0f)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0012000000569969416)) tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) + Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(maxCos * ux) * Float32(-2.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(0.0012000000569969416)) tmp = sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) + ((maxCos + single(-1.0)) * (ux ^ single(2.0)))))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt(((single(2.0) * ux) + ((maxCos * ux) * single(-2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0012000000569969416:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux + \left(maxCos + -1\right) \cdot {ux}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux + \left(maxCos \cdot ux\right) \cdot -2}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00120000006Initial program 54.0%
associate-*l*54.0%
sub-neg54.0%
+-commutative54.0%
distribute-rgt-neg-in54.0%
fma-define54.1%
Simplified54.2%
Taylor expanded in ux around inf 99.5%
fma-define99.5%
+-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
pow1/299.6%
pow-to-exp96.6%
count-296.6%
Applied egg-rr96.6%
Taylor expanded in uy around 0 98.0%
associate-*r*98.0%
*-commutative98.0%
sub-neg98.0%
metadata-eval98.0%
+-commutative98.0%
associate-*r*98.0%
distribute-rgt-out98.1%
+-commutative98.1%
metadata-eval98.1%
sub-neg98.1%
*-commutative98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
Simplified98.1%
if 0.00120000006 < (*.f32 uy 2) Initial program 56.0%
Taylor expanded in ux around 0 78.0%
Taylor expanded in maxCos around 0 78.1%
Final simplification91.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.0012000000569969416) (sqrt (* (- 1.0 maxCos) (+ (* 2.0 ux) (* (+ maxCos -1.0) (pow ux 2.0))))) (* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0012000000569969416f) {
tmp = sqrtf(((1.0f - maxCos) * ((2.0f * ux) + ((maxCos + -1.0f) * powf(ux, 2.0f)))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0012000000569969416)) tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) + Float32(Float32(maxCos + Float32(-1.0)) * (ux ^ Float32(2.0)))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * 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 ((single(2.0) * uy) <= single(0.0012000000569969416)) tmp = sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) + ((maxCos + single(-1.0)) * (ux ^ single(2.0)))))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0012000000569969416:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux + \left(maxCos + -1\right) \cdot {ux}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00120000006Initial program 54.0%
associate-*l*54.0%
sub-neg54.0%
+-commutative54.0%
distribute-rgt-neg-in54.0%
fma-define54.1%
Simplified54.2%
Taylor expanded in ux around inf 99.5%
fma-define99.5%
+-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
pow1/299.6%
pow-to-exp96.6%
count-296.6%
Applied egg-rr96.6%
Taylor expanded in uy around 0 98.0%
associate-*r*98.0%
*-commutative98.0%
sub-neg98.0%
metadata-eval98.0%
+-commutative98.0%
associate-*r*98.0%
distribute-rgt-out98.1%
+-commutative98.1%
metadata-eval98.1%
sub-neg98.1%
*-commutative98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
Simplified98.1%
if 0.00120000006 < (*.f32 uy 2) Initial program 56.0%
Taylor expanded in ux around 0 78.0%
Final simplification91.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.0012000000569969416) (sqrt (* (- 1.0 maxCos) (- (* 2.0 ux) (pow ux 2.0)))) (* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0012000000569969416f) {
tmp = sqrtf(((1.0f - maxCos) * ((2.0f * ux) - powf(ux, 2.0f))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0012000000569969416)) tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * 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 ((single(2.0) * uy) <= single(0.0012000000569969416)) tmp = sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) - (ux ^ single(2.0))))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0012000000569969416:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux - {ux}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00120000006Initial program 54.0%
associate-*l*54.0%
sub-neg54.0%
+-commutative54.0%
distribute-rgt-neg-in54.0%
fma-define54.1%
Simplified54.2%
Taylor expanded in ux around inf 99.5%
fma-define99.5%
+-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
pow1/299.6%
pow-to-exp96.6%
count-296.6%
Applied egg-rr96.6%
Taylor expanded in uy around 0 98.0%
associate-*r*98.0%
*-commutative98.0%
sub-neg98.0%
metadata-eval98.0%
+-commutative98.0%
associate-*r*98.0%
distribute-rgt-out98.1%
+-commutative98.1%
metadata-eval98.1%
sub-neg98.1%
*-commutative98.1%
sub-neg98.1%
metadata-eval98.1%
+-commutative98.1%
Simplified98.1%
Taylor expanded in maxCos around 0 97.1%
mul-1-neg97.1%
Simplified97.1%
if 0.00120000006 < (*.f32 uy 2) Initial program 56.0%
Taylor expanded in ux around 0 78.0%
Final simplification90.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.004000000189989805) (sqrt (* (- 1.0 maxCos) (- (* 2.0 ux) (pow ux 2.0)))) (* (cos (* PI (* 2.0 uy))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.004000000189989805f) {
tmp = sqrtf(((1.0f - maxCos) * ((2.0f * ux) - powf(ux, 2.0f))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.004000000189989805)) tmp = sqrt(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(0.004000000189989805)) tmp = sqrt(((single(1.0) - maxCos) * ((single(2.0) * ux) - (ux ^ single(2.0))))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.004000000189989805:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(2 \cdot ux - {ux}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00400000019Initial program 54.4%
associate-*l*54.4%
sub-neg54.4%
+-commutative54.4%
distribute-rgt-neg-in54.4%
fma-define54.5%
Simplified54.6%
Taylor expanded in ux around inf 99.4%
fma-define99.4%
+-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
distribute-lft-in99.4%
metadata-eval99.4%
associate--l+99.4%
mul-1-neg99.4%
sub-neg99.4%
*-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
Simplified99.4%
pow1/299.4%
pow-to-exp96.6%
count-296.6%
Applied egg-rr96.6%
Taylor expanded in uy around 0 95.8%
associate-*r*95.8%
*-commutative95.8%
sub-neg95.8%
metadata-eval95.8%
+-commutative95.8%
associate-*r*95.8%
distribute-rgt-out95.8%
+-commutative95.8%
metadata-eval95.8%
sub-neg95.8%
*-commutative95.8%
sub-neg95.8%
metadata-eval95.8%
+-commutative95.8%
Simplified95.8%
Taylor expanded in maxCos around 0 94.9%
mul-1-neg94.9%
Simplified94.9%
if 0.00400000019 < (*.f32 uy 2) Initial program 55.5%
Taylor expanded in ux around 0 78.0%
Taylor expanded in maxCos around 0 75.8%
*-commutative37.0%
Simplified75.8%
Final simplification89.7%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.0012000000569969416) (sqrt (- (* 2.0 ux) (pow ux 2.0))) (* (cos (* PI (* 2.0 uy))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0012000000569969416f) {
tmp = sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0012000000569969416)) tmp = sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(0.0012000000569969416)) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); else tmp = cos((single(pi) * (single(2.0) * uy))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0012000000569969416:\\
\;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00120000006Initial program 54.0%
associate-*l*54.0%
sub-neg54.0%
+-commutative54.0%
distribute-rgt-neg-in54.0%
fma-define54.1%
Simplified54.2%
Taylor expanded in ux around inf 99.5%
fma-define99.5%
+-commutative99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
distribute-lft-in99.5%
metadata-eval99.5%
associate--l+99.6%
mul-1-neg99.6%
sub-neg99.6%
*-commutative99.6%
sub-neg99.6%
metadata-eval99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in uy around 0 98.0%
Taylor expanded in maxCos around 0 93.0%
+-commutative93.0%
mul-1-neg93.0%
unsub-neg93.0%
Simplified93.0%
if 0.00120000006 < (*.f32 uy 2) Initial program 56.0%
Taylor expanded in ux around 0 78.0%
Taylor expanded in maxCos around 0 74.9%
*-commutative42.4%
Simplified74.9%
Final simplification86.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) - powf(ux, 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(((2.0e0 * ux) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - {ux}^{2}}
\end{array}
Initial program 54.7%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in ux around inf 99.0%
fma-define99.0%
+-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-lft-in99.0%
metadata-eval99.0%
associate--l+99.0%
mul-1-neg99.0%
sub-neg99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in uy around 0 79.9%
Taylor expanded in maxCos around 0 76.2%
+-commutative76.2%
mul-1-neg76.2%
unsub-neg76.2%
Simplified76.2%
Final simplification76.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* ux (+ maxCos -1.0))))
(if (<= ux 0.00015999999595806003)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt (+ 1.0 (* (+ 1.0 t_0) (- -1.0 t_0)))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (maxCos + -1.0f);
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + t_0) * (-1.0f - t_0))));
}
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) :: tmp
t_0 = ux * (maxcos + (-1.0e0))
if (ux <= 0.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + t_0) * ((-1.0e0) - t_0))))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(maxCos + Float32(-1.0))) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + t_0) * Float32(Float32(-1.0) - t_0)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux * (maxCos + single(-1.0)); tmp = single(0.0); if (ux <= single(0.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + t_0) * (single(-1.0) - t_0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(maxCos + -1\right)\\
\mathbf{if}\;ux \leq 0.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + t\_0\right) \cdot \left(-1 - t\_0\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 36.2%
associate-*l*36.2%
sub-neg36.2%
+-commutative36.2%
distribute-rgt-neg-in36.2%
fma-define36.3%
Simplified36.4%
Taylor expanded in uy around 0 33.2%
Simplified33.2%
Taylor expanded in ux around 0 77.6%
if 1.59999996e-4 < ux Initial program 87.7%
associate-*l*87.7%
sub-neg87.7%
+-commutative87.7%
distribute-rgt-neg-in87.7%
fma-define87.9%
Simplified87.9%
Taylor expanded in uy around 0 71.3%
Simplified71.3%
Taylor expanded in ux around -inf 71.4%
mul-1-neg71.4%
unsub-neg71.4%
mul-1-neg71.4%
sub-neg71.4%
Simplified71.4%
Final simplification75.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00015999999595806003) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (- -1.0 (* ux (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f - (ux * (maxCos + -1.0f))))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) - (ux * (maxcos + (-1.0e0)))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) - Float32(ux * Float32(maxCos + Float32(-1.0))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) - (ux * (maxCos + single(-1.0))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 - ux \cdot \left(maxCos + -1\right)\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 36.2%
associate-*l*36.2%
sub-neg36.2%
+-commutative36.2%
distribute-rgt-neg-in36.2%
fma-define36.3%
Simplified36.4%
Taylor expanded in uy around 0 33.2%
Simplified33.2%
Taylor expanded in ux around 0 77.6%
if 1.59999996e-4 < ux Initial program 87.7%
associate-*l*87.7%
sub-neg87.7%
+-commutative87.7%
distribute-rgt-neg-in87.7%
fma-define87.9%
Simplified87.9%
Taylor expanded in uy around 0 71.3%
Simplified71.3%
Taylor expanded in maxCos around 0 68.8%
Final simplification74.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00015999999595806003) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00015999999595806003f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.00015999999595806003e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00015999999595806003)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00015999999595806003)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00015999999595806003:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 1.59999996e-4Initial program 36.2%
associate-*l*36.2%
sub-neg36.2%
+-commutative36.2%
distribute-rgt-neg-in36.2%
fma-define36.3%
Simplified36.4%
Taylor expanded in uy around 0 33.2%
Simplified33.2%
Taylor expanded in ux around 0 77.6%
if 1.59999996e-4 < ux Initial program 87.7%
associate-*l*87.7%
sub-neg87.7%
+-commutative87.7%
distribute-rgt-neg-in87.7%
fma-define87.9%
Simplified87.9%
Taylor expanded in uy around 0 71.3%
Simplified71.3%
Taylor expanded in maxCos around 0 68.5%
neg-mul-168.5%
sub-neg68.5%
Simplified68.5%
Final simplification74.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%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in uy around 0 46.9%
Simplified46.9%
Taylor expanded in ux around 0 67.2%
Final simplification67.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 54.7%
associate-*l*54.7%
sub-neg54.7%
+-commutative54.7%
distribute-rgt-neg-in54.7%
fma-define54.8%
Simplified54.9%
Taylor expanded in uy around 0 46.9%
Simplified46.9%
Taylor expanded in ux around 0 67.2%
Taylor expanded in maxCos around 0 64.7%
*-commutative64.7%
Simplified64.7%
Final simplification64.7%
herbie shell --seed 2024053
(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)))))))