
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \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 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \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
(expm1
(log1p
(cbrt
(*
(pow (sin (* 2.0 (* uy PI))) 3.0)
(pow
(-
(* (* (pow ux 2.0) (- 1.0 maxCos)) (+ maxCos -1.0))
(* ux (+ -2.0 (* 2.0 maxCos))))
1.5))))))
float code(float ux, float uy, float maxCos) {
return expm1f(log1pf(cbrtf((powf(sinf((2.0f * (uy * ((float) M_PI)))), 3.0f) * powf((((powf(ux, 2.0f) * (1.0f - maxCos)) * (maxCos + -1.0f)) - (ux * (-2.0f + (2.0f * maxCos)))), 1.5f)))));
}
function code(ux, uy, maxCos) return expm1(log1p(cbrt(Float32((sin(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) ^ Float32(3.0)) * (Float32(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(1.0) - maxCos)) * Float32(maxCos + Float32(-1.0))) - Float32(ux * Float32(Float32(-2.0) + Float32(Float32(2.0) * maxCos)))) ^ Float32(1.5)))))) end
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{3} \cdot {\left(\left({ux}^{2} \cdot \left(1 - maxCos\right)\right) \cdot \left(maxCos + -1\right) - ux \cdot \left(-2 + 2 \cdot maxCos\right)\right)}^{1.5}}\right)\right)
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-def56.5%
Simplified56.6%
Taylor expanded in ux around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
*-commutative98.3%
mul-1-neg98.3%
sub-neg98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
sub-neg98.3%
mul-1-neg98.3%
unsub-neg98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
expm1-log1p-u98.3%
associate-*r*98.3%
*-commutative98.3%
+-commutative98.3%
metadata-eval98.3%
sub-neg98.3%
*-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
+-commutative98.3%
associate--r-98.3%
Applied egg-rr98.3%
Applied egg-rr98.3%
Simplified98.3%
Final simplification98.3%
(FPCore (ux uy maxCos)
:precision binary32
(expm1
(log1p
(*
(sqrt
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))
(* ux (- (- (- 1.0 maxCos) maxCos) -1.0))))
(sin (* PI (* 2.0 uy)))))))
float code(float ux, float uy, float maxCos) {
return expm1f(log1pf((sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (ux * (((1.0f - maxCos) - maxCos) - -1.0f)))) * sinf((((float) M_PI) * (2.0f * uy))))));
}
function code(ux, uy, maxCos) return expm1(log1p(Float32(sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(Float32(Float32(1.0) - maxCos) - maxCos) - Float32(-1.0))))) * sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy)))))) end
\begin{array}{l}
\\
\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(\left(\left(1 - maxCos\right) - maxCos\right) - -1\right)} \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\right)\right)
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-def56.5%
Simplified56.6%
Taylor expanded in ux around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
*-commutative98.3%
mul-1-neg98.3%
sub-neg98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
sub-neg98.3%
mul-1-neg98.3%
unsub-neg98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
expm1-log1p-u98.3%
associate-*r*98.3%
*-commutative98.3%
+-commutative98.3%
metadata-eval98.3%
sub-neg98.3%
*-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
+-commutative98.3%
associate--r-98.3%
Applied egg-rr98.3%
Final simplification98.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* 2.0 (* uy PI)))
(sqrt
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sinf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = sin((single(2.0) * (uy * single(pi)))) * sqrt((((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + 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-def56.5%
Simplified56.6%
Taylor expanded in ux around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
*-commutative98.3%
mul-1-neg98.3%
sub-neg98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
sub-neg98.3%
mul-1-neg98.3%
unsub-neg98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
Taylor expanded in uy around inf 98.3%
Final simplification98.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (sin (* PI (* 2.0 uy)))))
(if (<= maxCos 2.499999936844688e-5)
(* (sqrt (- (* 2.0 ux) (pow ux 2.0))) t_0)
(* t_0 (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = sinf((((float) M_PI) * (2.0f * uy)));
float tmp;
if (maxCos <= 2.499999936844688e-5f) {
tmp = sqrtf(((2.0f * ux) - powf(ux, 2.0f))) * t_0;
} else {
tmp = t_0 * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) tmp = Float32(0.0) if (maxCos <= Float32(2.499999936844688e-5)) tmp = Float32(sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) * t_0); else tmp = Float32(t_0 * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = sin((single(pi) * (single(2.0) * uy))); tmp = single(0.0); if (maxCos <= single(2.499999936844688e-5)) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))) * t_0; else tmp = t_0 * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;maxCos \leq 2.499999936844688 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 2.49999994e-5Initial program 58.2%
associate-*l*58.2%
sub-neg58.2%
+-commutative58.2%
distribute-rgt-neg-in58.2%
fma-def58.3%
Simplified58.4%
Taylor expanded in ux around -inf 98.2%
+-commutative98.2%
mul-1-neg98.2%
unsub-neg98.2%
*-commutative98.2%
mul-1-neg98.2%
sub-neg98.2%
sub-neg98.2%
metadata-eval98.2%
+-commutative98.2%
sub-neg98.2%
mul-1-neg98.2%
unsub-neg98.2%
mul-1-neg98.2%
sub-neg98.2%
metadata-eval98.2%
Simplified98.2%
Taylor expanded in maxCos around 0 97.6%
associate-*r*97.6%
*-commutative97.6%
*-commutative97.6%
*-commutative97.6%
cancel-sign-sub-inv97.6%
metadata-eval97.6%
mul-1-neg97.6%
Simplified97.6%
expm1-log1p-u97.5%
expm1-udef82.1%
+-commutative82.1%
fma-def82.1%
Applied egg-rr82.1%
expm1-def97.5%
expm1-log1p97.6%
fma-neg97.6%
Simplified97.6%
if 2.49999994e-5 < maxCos Initial program 47.4%
Taylor expanded in ux around 0 40.1%
Taylor expanded in maxCos around 0 83.3%
Final simplification95.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (* ux maxCos) (- 1.0 ux))) (t_1 (sin (* PI (* 2.0 uy)))))
(if (<= t_0 0.9998049736022949)
(* t_1 (sqrt (+ 1.0 (* t_0 (- (+ ux -1.0) (* ux maxCos))))))
(* t_1 (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (ux * maxCos) + (1.0f - ux);
float t_1 = sinf((((float) M_PI) * (2.0f * uy)));
float tmp;
if (t_0 <= 0.9998049736022949f) {
tmp = t_1 * sqrtf((1.0f + (t_0 * ((ux + -1.0f) - (ux * maxCos)))));
} else {
tmp = t_1 * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(ux * maxCos) + Float32(Float32(1.0) - ux)) t_1 = sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) tmp = Float32(0.0) if (t_0 <= Float32(0.9998049736022949)) tmp = Float32(t_1 * sqrt(Float32(Float32(1.0) + Float32(t_0 * Float32(Float32(ux + Float32(-1.0)) - Float32(ux * maxCos)))))); else tmp = Float32(t_1 * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (ux * maxCos) + (single(1.0) - ux); t_1 = sin((single(pi) * (single(2.0) * uy))); tmp = single(0.0); if (t_0 <= single(0.9998049736022949)) tmp = t_1 * sqrt((single(1.0) + (t_0 * ((ux + single(-1.0)) - (ux * maxCos))))); else tmp = t_1 * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot maxCos + \left(1 - ux\right)\\
t_1 := \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;t_0 \leq 0.9998049736022949:\\
\;\;\;\;t_1 \cdot \sqrt{1 + t_0 \cdot \left(\left(ux + -1\right) - ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\end{array}
\end{array}
if (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) < 0.999804974Initial program 89.2%
if 0.999804974 < (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) Initial program 36.5%
Taylor expanded in ux around 0 39.8%
Taylor expanded in maxCos around 0 91.7%
Final simplification90.7%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 0.0020000000949949026)
(*
2.0
(*
(* uy PI)
(sqrt
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
(* (sin (* PI (* 2.0 uy))) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0020000000949949026f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (ux * (2.0f - (2.0f * maxCos))))));
} else {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0020000000949949026)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))))); else tmp = Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(0.0020000000949949026)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos)))))); else tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0020000000949949026:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00200000009Initial program 58.7%
associate-*l*58.7%
sub-neg58.7%
+-commutative58.7%
distribute-rgt-neg-in58.7%
fma-def58.7%
Simplified58.8%
Taylor expanded in ux around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
*-commutative98.6%
mul-1-neg98.6%
sub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
sub-neg98.6%
mul-1-neg98.6%
unsub-neg98.6%
mul-1-neg98.6%
sub-neg98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in uy around 0 97.5%
if 0.00200000009 < (*.f32 uy 2) Initial program 50.9%
Taylor expanded in ux around 0 41.7%
Taylor expanded in maxCos around 0 79.0%
Final simplification92.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019500000053085387) (* (sin (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 (* 2.0 maxCos))))) (* (sin (* 2.0 (* uy PI))) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sinf((2.0f * (uy * ((float) M_PI)))) * sqrtf((1.0f - ((1.0f - ux) * (1.0f - ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(sin(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(1.0) - ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sin((single(2.0) * (uy * single(pi)))) * sqrt((single(1.0) - ((single(1.0) - ux) * (single(1.0) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.3%
Taylor expanded in ux around 0 91.8%
*-commutative91.8%
Simplified91.8%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.2%
Simplified89.4%
Taylor expanded in uy around inf 89.0%
Taylor expanded in maxCos around 0 83.9%
mul-1-neg83.9%
unsub-neg83.9%
mul-1-neg83.9%
sub-neg83.9%
Simplified83.9%
Final simplification88.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019500000053085387) (* (sin (* PI (* 2.0 uy))) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))) (* (sin (* 2.0 (* uy PI))) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sinf((2.0f * (uy * ((float) M_PI)))) * sqrtf((1.0f - ((1.0f - ux) * (1.0f - ux))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos))))); else tmp = Float32(sin(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(1.0) - ux))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sin((single(2.0) * (uy * single(pi)))) * sqrt((single(1.0) - ((single(1.0) - ux) * (single(1.0) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.3%
Taylor expanded in ux around 0 39.6%
Taylor expanded in maxCos around 0 91.8%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.2%
Simplified89.4%
Taylor expanded in uy around inf 89.0%
Taylor expanded in maxCos around 0 83.9%
mul-1-neg83.9%
unsub-neg83.9%
mul-1-neg83.9%
sub-neg83.9%
Simplified83.9%
Final simplification88.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.0012000000569969416) (* (sqrt (- (* 2.0 ux) (pow ux 2.0))) (* uy (* 2.0 PI))) (* (sin (* 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))) * (uy * (2.0f * ((float) M_PI)));
} else {
tmp = sinf((((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 = Float32(sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) * Float32(uy * Float32(Float32(2.0) * Float32(pi)))); else tmp = Float32(sin(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)))) * (uy * (single(2.0) * single(pi))); else tmp = sin((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}} \cdot \left(uy \cdot \left(2 \cdot \pi\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \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 58.7%
associate-*l*58.7%
sub-neg58.7%
+-commutative58.7%
distribute-rgt-neg-in58.7%
fma-def58.8%
Simplified58.9%
Taylor expanded in ux around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
*-commutative98.6%
mul-1-neg98.6%
sub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
sub-neg98.6%
mul-1-neg98.6%
unsub-neg98.6%
mul-1-neg98.6%
sub-neg98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in maxCos around 0 91.7%
associate-*r*91.7%
*-commutative91.7%
*-commutative91.7%
*-commutative91.7%
cancel-sign-sub-inv91.7%
metadata-eval91.7%
mul-1-neg91.7%
Simplified91.7%
Taylor expanded in uy around 0 91.1%
associate-*r*91.1%
*-commutative91.1%
associate-*l*91.1%
Simplified91.1%
if 0.00120000006 < (*.f32 uy 2) Initial program 51.3%
Taylor expanded in ux around 0 42.2%
Taylor expanded in maxCos around 0 72.4%
Final simplification85.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 2.8000000384054147e-5) (* (sin (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 (* 2.0 maxCos))))) (* (sqrt (- (* 2.0 ux) (pow ux 2.0))) (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 2.8000000384054147e-5f) {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf(((2.0f * ux) - powf(ux, 2.0f))) * (uy * (2.0f * ((float) M_PI)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(2.8000000384054147e-5)) tmp = Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) * Float32(uy * Float32(Float32(2.0) * Float32(pi)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(2.8000000384054147e-5)) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))) * (uy * (single(2.0) * single(pi))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 2.8000000384054147 \cdot 10^{-5}:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot \left(uy \cdot \left(2 \cdot \pi\right)\right)\\
\end{array}
\end{array}
if ux < 2.80000004e-5Initial program 30.1%
Taylor expanded in ux around 0 94.7%
*-commutative94.7%
Simplified94.7%
if 2.80000004e-5 < ux Initial program 85.0%
associate-*l*85.0%
sub-neg85.0%
+-commutative85.0%
distribute-rgt-neg-in85.0%
fma-def85.1%
Simplified85.3%
Taylor expanded in ux around -inf 98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
*-commutative98.5%
mul-1-neg98.5%
sub-neg98.5%
sub-neg98.5%
metadata-eval98.5%
+-commutative98.5%
sub-neg98.5%
mul-1-neg98.5%
unsub-neg98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 92.0%
associate-*r*92.0%
*-commutative92.0%
*-commutative92.0%
*-commutative92.0%
cancel-sign-sub-inv92.0%
metadata-eval92.0%
mul-1-neg92.0%
Simplified92.0%
Taylor expanded in uy around 0 81.2%
associate-*r*81.2%
*-commutative81.2%
associate-*l*81.2%
Simplified81.2%
Final simplification88.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019500000053085387)
(* (sin (* PI (* 2.0 uy))) (sqrt (* 2.0 ux)))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (+ 1.0 (* ux (+ maxCos -1.0))) (+ ux (- -1.0 (* ux maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((2.0f * ux));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (ux + (-1.0f - (ux * maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(2.0) * ux))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(ux + Float32(Float32(-1.0) - Float32(ux * maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt((single(2.0) * ux)); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (ux + (single(-1.0) - (ux * maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux + \left(-1 - ux \cdot maxCos\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.3%
Taylor expanded in ux around 0 39.6%
Taylor expanded in maxCos around 0 84.6%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.2%
Simplified89.4%
Taylor expanded in uy around 0 78.2%
Final simplification82.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019500000053085387)
(* 2.0 (* (* uy PI) (sqrt (- (* ux (- -2.0)) (* ux (* 2.0 maxCos))))))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (+ 1.0 (* ux (+ maxCos -1.0))) (+ ux (- -1.0 (* ux maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((ux * -(-2.0f)) - (ux * (2.0f * maxCos)))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (ux + (-1.0f - (ux * maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(ux * Float32(Float32(2.0) * maxCos)))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * Float32(ux + Float32(Float32(-1.0) - Float32(ux * maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((ux * -single(-2.0)) - (ux * (single(2.0) * maxCos))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (ux + (single(-1.0) - (ux * maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(--2\right) - ux \cdot \left(2 \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(ux + \left(-1 - ux \cdot maxCos\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.3%
associate-*l*36.3%
sub-neg36.3%
+-commutative36.3%
distribute-rgt-neg-in36.3%
fma-def36.3%
Simplified36.3%
Taylor expanded in uy around 0 33.8%
Taylor expanded in ux around 0 75.2%
sub-neg75.2%
metadata-eval75.2%
+-commutative75.2%
distribute-lft-in75.2%
Applied egg-rr75.2%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.2%
Simplified89.4%
Taylor expanded in uy around 0 78.2%
Final simplification76.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019500000053085387) (* 2.0 (* (* uy PI) (sqrt (- (* ux (- -2.0)) (* ux (* 2.0 maxCos)))))) (* 2.0 (* (* uy PI) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((ux * -(-2.0f)) - (ux * (2.0f * maxCos)))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f - ((1.0f - ux) * (1.0f - ux)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(ux * Float32(Float32(2.0) * maxCos)))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(1.0) - ux)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((ux * -single(-2.0)) - (ux * (single(2.0) * maxCos))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) - ((single(1.0) - ux) * (single(1.0) - ux))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(--2\right) - ux \cdot \left(2 \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\right)\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.3%
associate-*l*36.3%
sub-neg36.3%
+-commutative36.3%
distribute-rgt-neg-in36.3%
fma-def36.3%
Simplified36.3%
Taylor expanded in uy around 0 33.8%
Taylor expanded in ux around 0 75.2%
sub-neg75.2%
metadata-eval75.2%
+-commutative75.2%
distribute-lft-in75.2%
Applied egg-rr75.2%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.2%
Simplified89.4%
Taylor expanded in uy around 0 78.2%
Taylor expanded in maxCos around 0 74.3%
Final simplification74.8%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (- (* ux (- -2.0)) (* ux (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf(((ux * -(-2.0f)) - (ux * (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(ux * Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((ux * -single(-2.0)) - (ux * (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(--2\right) - ux \cdot \left(2 \cdot maxCos\right)}\right)
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-def56.5%
Simplified56.6%
Taylor expanded in uy around 0 50.8%
Taylor expanded in ux around 0 65.4%
sub-neg65.4%
metadata-eval65.4%
+-commutative65.4%
distribute-lft-in65.4%
Applied egg-rr65.4%
Final simplification65.4%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\right)
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-def56.5%
Simplified56.6%
Taylor expanded in uy around 0 50.8%
Taylor expanded in ux around 0 65.4%
Final simplification65.4%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (* ux (- -2.0))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux * -(-2.0f))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux * Float32(-Float32(-2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux * -single(-2.0)))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(--2\right)}\right)
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-def56.5%
Simplified56.6%
Taylor expanded in uy around 0 50.8%
Taylor expanded in ux around 0 65.4%
Taylor expanded in maxCos around 0 61.8%
*-commutative61.8%
Simplified61.8%
Final simplification61.8%
herbie shell --seed 2023333
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
: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)))
(* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))