
(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 12 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
(cbrt
(*
(pow
(fma
ux
(* 2.0 (- 1.0 maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0))))
1.5)
(pow (sin (* 2.0 (* uy PI))) 3.0))))
float code(float ux, float uy, float maxCos) {
return cbrtf((powf(fmaf(ux, (2.0f * (1.0f - maxCos)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))), 1.5f) * powf(sinf((2.0f * (uy * ((float) M_PI)))), 3.0f)));
}
function code(ux, uy, maxCos) return cbrt(Float32((fma(ux, Float32(Float32(2.0) * Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))) ^ Float32(1.5)) * (sin(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) ^ Float32(3.0)))) end
\begin{array}{l}
\\
\sqrt[3]{{\left(\mathsf{fma}\left(ux, 2 \cdot \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)\right)}^{1.5} \cdot {\sin \left(2 \cdot \left(uy \cdot \pi\right)\right)}^{3}}
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in ux around 0 98.3%
fma-def98.4%
+-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
*-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
*-commutative98.4%
add-cbrt-cube98.4%
associate-*r*98.4%
*-commutative98.4%
associate-*r*98.4%
add-cbrt-cube98.3%
unpow398.4%
cbrt-unprod98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* uy (* 2.0 PI)))
(sqrt
(fma
ux
(+ (- 1.0 maxCos) (- 1.0 maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))))) end
\begin{array}{l}
\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in ux around 0 98.3%
fma-def98.4%
+-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
*-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 0.00026780000189319253)
(*
2.0
(*
(* uy PI)
(sqrt
(fma
ux
(+ 2.0 (* maxCos -2.0))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))))))
(* (sqrt (- (* ux 2.0) (pow ux 2.0))) (sin (* PI (* 2.0 uy))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.00026780000189319253f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(fmaf(ux, (2.0f + (maxCos * -2.0f)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f))))));
} else {
tmp = sqrtf(((ux * 2.0f) - powf(ux, 2.0f))) * sinf((((float) M_PI) * (2.0f * uy)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.00026780000189319253)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(fma(ux, Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0)))))))); else tmp = Float32(sqrt(Float32(Float32(ux * Float32(2.0)) - (ux ^ Float32(2.0)))) * sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.00026780000189319253:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot 2 - {ux}^{2}} \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if (*.f32 uy 2) < 2.67800002e-4Initial program 59.6%
associate-*l*59.6%
sub-neg59.6%
+-commutative59.6%
distribute-rgt-neg-in59.6%
fma-def59.5%
Simplified59.6%
Taylor expanded in ux around 0 98.4%
fma-def98.4%
+-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
*-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in uy around 0 98.3%
fma-def98.3%
cancel-sign-sub-inv98.3%
metadata-eval98.3%
*-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
if 2.67800002e-4 < (*.f32 uy 2) Initial program 63.2%
associate-*l*63.2%
sub-neg63.2%
+-commutative63.2%
distribute-rgt-neg-in63.2%
fma-def63.6%
Simplified63.1%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
+-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
distribute-lft-in98.3%
metadata-eval98.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
*-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in maxCos around 0 95.0%
associate-*r*95.0%
+-commutative95.0%
mul-1-neg95.0%
unsub-neg95.0%
Simplified95.0%
Final simplification97.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* 2.0 (* uy PI)))
(sqrt
(+
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))
(* 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) * ((1.0f - maxCos) * (maxCos + -1.0f))) + (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(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0)))) + 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)) * ((single(1.0) - maxCos) * (maxCos + single(-1.0)))) + (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(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in ux around 0 98.3%
fma-def98.4%
+-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
*-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in uy around inf 98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 0.00026780000189319253)
(*
2.0
(*
(* uy PI)
(sqrt
(+
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
(* (sqrt (- (* ux 2.0) (pow ux 2.0))) (sin (* PI (* 2.0 uy))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.00026780000189319253f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f))) + (ux * (2.0f - (2.0f * maxCos))))));
} else {
tmp = sqrtf(((ux * 2.0f) - powf(ux, 2.0f))) * sinf((((float) M_PI) * (2.0f * uy)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.00026780000189319253)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))))); else tmp = Float32(sqrt(Float32(Float32(ux * Float32(2.0)) - (ux ^ Float32(2.0)))) * sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(0.00026780000189319253)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (maxCos + single(-1.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos)))))); else tmp = sqrt(((ux * single(2.0)) - (ux ^ single(2.0)))) * sin((single(pi) * (single(2.0) * uy))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.00026780000189319253:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot 2 - {ux}^{2}} \cdot \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\end{array}
\end{array}
if (*.f32 uy 2) < 2.67800002e-4Initial program 59.6%
associate-*l*59.6%
sub-neg59.6%
+-commutative59.6%
distribute-rgt-neg-in59.6%
fma-def59.5%
Simplified59.6%
Taylor expanded in ux around 0 98.4%
fma-def98.4%
+-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
*-commutative98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in uy around 0 98.3%
if 2.67800002e-4 < (*.f32 uy 2) Initial program 63.2%
associate-*l*63.2%
sub-neg63.2%
+-commutative63.2%
distribute-rgt-neg-in63.2%
fma-def63.6%
Simplified63.1%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
+-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
distribute-lft-in98.3%
metadata-eval98.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
*-commutative98.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in maxCos around 0 95.0%
associate-*r*95.0%
+-commutative95.0%
mul-1-neg95.0%
unsub-neg95.0%
Simplified95.0%
Final simplification97.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ (- 1.0 ux) (* ux maxCos))) (t_1 (sin (* PI (* 2.0 uy)))))
(if (<= t_0 0.9998850226402283)
(* t_1 (sqrt (+ 1.0 (* t_0 (- (+ ux -1.0) (* ux maxCos))))))
(* t_1 (sqrt (* ux (- 2.0 (* 2.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
float t_1 = sinf((((float) M_PI) * (2.0f * uy)));
float tmp;
if (t_0 <= 0.9998850226402283f) {
tmp = t_1 * sqrtf((1.0f + (t_0 * ((ux + -1.0f) - (ux * maxCos)))));
} else {
tmp = t_1 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) t_1 = sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) tmp = Float32(0.0) if (t_0 <= Float32(0.9998850226402283)) 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(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); t_1 = sin((single(pi) * (single(2.0) * uy))); tmp = single(0.0); if (t_0 <= single(0.9998850226402283)) tmp = t_1 * sqrt((single(1.0) + (t_0 * ((ux + single(-1.0)) - (ux * maxCos))))); else tmp = t_1 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
t_1 := \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;t_0 \leq 0.9998850226402283:\\
\;\;\;\;t_1 \cdot \sqrt{1 + t_0 \cdot \left(\left(ux + -1\right) - ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) < 0.999885023Initial program 90.4%
if 0.999885023 < (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) Initial program 38.5%
Taylor expanded in ux around 0 92.1%
*-commutative92.1%
Simplified92.1%
Final simplification91.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= (* 2.0 uy) 0.002899999963119626) (* 2.0 (* (* uy PI) (sqrt (* ux (- (- -2.0) ux))))) (* (sin (* 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.002899999963119626f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux * (-(-2.0f) - ux))));
} else {
tmp = sinf((((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.002899999963119626)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux * Float32(Float32(-Float32(-2.0)) - ux))))); else tmp = Float32(sin(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.002899999963119626)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux * (-single(-2.0) - ux)))); else tmp = sin((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.002899999963119626:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(--2\right) - ux\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \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.00289999996Initial program 59.4%
associate-*l*59.4%
sub-neg59.4%
+-commutative59.4%
distribute-rgt-neg-in59.4%
fma-def59.5%
Simplified59.5%
Taylor expanded in uy around 0 59.2%
Taylor expanded in ux around -inf 61.9%
Taylor expanded in maxCos around 0 59.3%
distribute-lft-in59.3%
metadata-eval59.3%
associate-+r+91.3%
metadata-eval91.3%
mul-1-neg91.3%
+-commutative91.3%
unpow291.3%
distribute-rgt-out91.4%
Simplified91.4%
if 0.00289999996 < (*.f32 uy 2) Initial program 65.1%
Taylor expanded in ux around 0 72.3%
*-commutative72.3%
Simplified72.3%
Final simplification86.1%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00011500000255182385) (* (sin (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 (* 2.0 maxCos))))) (* (sin (* uy (* 2.0 PI))) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00011500000255182385f) {
tmp = sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sinf((uy * (2.0f * ((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.00011500000255182385)) 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(uy * Float32(Float32(2.0) * 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.00011500000255182385)) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sin((uy * (single(2.0) * 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.00011500000255182385:\\
\;\;\;\;\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.15000003e-4Initial program 38.5%
Taylor expanded in ux around 0 92.1%
*-commutative92.1%
Simplified92.1%
if 1.15000003e-4 < ux Initial program 90.4%
associate-*l*90.4%
sub-neg90.4%
+-commutative90.4%
distribute-rgt-neg-in90.4%
fma-def90.5%
Simplified90.5%
Taylor expanded in maxCos around 0 85.5%
Final simplification89.2%
(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(uy * Float32(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(uy \cdot \left(\pi \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\right)\right)
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in uy around inf 60.9%
Taylor expanded in uy around 0 53.8%
Simplified53.9%
Taylor expanded in ux around 0 66.2%
Final simplification66.2%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* uy (* PI (sqrt (* ux (- (- -2.0) ux)))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * (uy * (((float) M_PI) * sqrtf((ux * (-(-2.0f) - ux)))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(uy * Float32(Float32(pi) * sqrt(Float32(ux * Float32(Float32(-Float32(-2.0)) - ux)))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * (uy * (single(pi) * sqrt((ux * (-single(-2.0) - ux))))); end
\begin{array}{l}
\\
2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{ux \cdot \left(\left(--2\right) - ux\right)}\right)\right)
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in uy around 0 53.8%
Taylor expanded in ux around -inf 56.0%
Taylor expanded in maxCos around 0 54.1%
associate-*l*54.1%
distribute-lft-in54.1%
metadata-eval54.1%
associate-+r+79.1%
metadata-eval79.1%
mul-1-neg79.1%
+-commutative79.1%
unpow279.1%
distribute-rgt-out79.2%
Simplified79.2%
Final simplification79.2%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (* ux (- (- -2.0) ux))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux * (-(-2.0f) - ux))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux * Float32(Float32(-Float32(-2.0)) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux * (-single(-2.0) - ux)))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(--2\right) - ux\right)}\right)
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in uy around 0 53.8%
Taylor expanded in ux around -inf 56.0%
Taylor expanded in maxCos around 0 54.1%
distribute-lft-in54.1%
metadata-eval54.1%
associate-+r+79.2%
metadata-eval79.2%
mul-1-neg79.2%
+-commutative79.2%
unpow279.2%
distribute-rgt-out79.2%
Simplified79.2%
Final simplification79.2%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* uy (* PI (sqrt 0.0)))))
float code(float ux, float uy, float maxCos) {
return 2.0f * (uy * (((float) M_PI) * sqrtf(0.0f)));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(uy * Float32(Float32(pi) * sqrt(Float32(0.0))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * (uy * (single(pi) * sqrt(single(0.0)))); end
\begin{array}{l}
\\
2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{0}\right)\right)
\end{array}
Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.1%
Simplified61.0%
Taylor expanded in uy around inf 60.9%
Taylor expanded in uy around 0 53.8%
Simplified53.9%
Taylor expanded in ux around 0 7.1%
Final simplification7.1%
herbie shell --seed 2023340
(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)))))))