
(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 13 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 maxCos -2.0 2.0) ux) (* (* ux ux) (pow (+ maxCos -1.0) 2.0)))
1.5)
(pow (sin (* uy (* 2.0 PI))) 3.0))))
float code(float ux, float uy, float maxCos) {
return cbrtf((powf(((fmaf(maxCos, -2.0f, 2.0f) * ux) - ((ux * ux) * powf((maxCos + -1.0f), 2.0f))), 1.5f) * powf(sinf((uy * (2.0f * ((float) M_PI)))), 3.0f)));
}
function code(ux, uy, maxCos) return cbrt(Float32((Float32(Float32(fma(maxCos, Float32(-2.0), Float32(2.0)) * ux) - Float32(Float32(ux * ux) * (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0)))) ^ Float32(1.5)) * (sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) ^ Float32(3.0)))) end
\begin{array}{l}
\\
\sqrt[3]{{\left(\mathsf{fma}\left(maxCos, -2, 2\right) \cdot ux - \left(ux \cdot ux\right) \cdot {\left(maxCos + -1\right)}^{2}\right)}^{1.5} \cdot {\sin \left(uy \cdot \left(2 \cdot \pi\right)\right)}^{3}}
\end{array}
Initial program 55.6%
*-commutative55.6%
add-cbrt-cube55.6%
associate-*r*55.6%
add-cbrt-cube55.6%
cbrt-unprod55.6%
Applied egg-rr55.6%
Taylor expanded in ux around 0 98.5%
cancel-sign-sub-inv98.5%
metadata-eval98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
*-commutative98.5%
fma-def98.5%
*-commutative98.5%
unpow298.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* PI (* 2.0 uy)))
(sqrt
(*
ux
(+ (fma maxCos -2.0 2.0) (* ux (* (+ maxCos -1.0) (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
return sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (fmaf(maxCos, -2.0f, 2.0f) + (ux * ((maxCos + -1.0f) * (1.0f - maxCos))))));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(fma(maxCos, Float32(-2.0), Float32(2.0)) + Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))))))) end
\begin{array}{l}
\\
\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(\mathsf{fma}\left(maxCos, -2, 2\right) + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial 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.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.3%
+-commutative98.3%
fma-def98.3%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
distribute-neg-in98.4%
metadata-eval98.4%
+-commutative98.4%
sub-neg98.4%
sub-neg98.4%
metadata-eval98.4%
*-commutative98.4%
unpow298.4%
Simplified98.4%
Taylor expanded in uy around inf 98.3%
add-log-exp61.8%
associate-*r*61.8%
Applied egg-rr61.8%
Taylor expanded in uy around inf 98.3%
*-commutative98.3%
associate-*r*98.3%
*-commutative98.3%
*-commutative98.3%
fma-def98.4%
cancel-sign-sub-inv98.4%
metadata-eval98.4%
fma-def98.3%
associate-*r*98.3%
sub-neg98.3%
metadata-eval98.3%
unpow298.3%
associate-*r*98.3%
distribute-rgt-out98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* ux (- 1.0 ux))))
(*
(sin (* uy (* 2.0 PI)))
(sqrt (- (- (* 2.0 ux) (* ux ux)) (* maxCos (+ t_0 t_0)))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (1.0f - ux);
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf((((2.0f * ux) - (ux * ux)) - (maxCos * (t_0 + t_0))));
}
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(Float32(1.0) - ux)) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)) - Float32(maxCos * Float32(t_0 + t_0))))) end
function tmp = code(ux, uy, maxCos) t_0 = ux * (single(1.0) - ux); tmp = sin((uy * (single(2.0) * single(pi)))) * sqrt((((single(2.0) * ux) - (ux * ux)) - (maxCos * (t_0 + t_0)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(1 - ux\right)\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(2 \cdot ux - ux \cdot ux\right) - maxCos \cdot \left(t_0 + t_0\right)}
\end{array}
\end{array}
Initial 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.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 maxCos around 0 53.3%
Taylor expanded in ux around 0 97.8%
+-commutative97.8%
mul-1-neg97.8%
unsub-neg97.8%
unpow297.8%
Simplified97.8%
Final simplification97.8%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ ux (- -1.0 (* maxCos ux))))
(t_1 (* t_0 (+ -1.0 (- ux (* maxCos ux))))))
(if (<= ux 0.00039999998989515007)
(* (sin (* uy (* 2.0 PI))) (sqrt (+ ux ux)))
(*
2.0
(*
(sqrt
(/ (+ 1.0 (* (* t_0 (+ 1.0 (- (* maxCos ux) ux))) t_1)) (+ 1.0 t_1)))
(* uy PI))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux + (-1.0f - (maxCos * ux));
float t_1 = t_0 * (-1.0f + (ux - (maxCos * ux)));
float tmp;
if (ux <= 0.00039999998989515007f) {
tmp = sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux + ux));
} else {
tmp = 2.0f * (sqrtf(((1.0f + ((t_0 * (1.0f + ((maxCos * ux) - ux))) * t_1)) / (1.0f + t_1))) * (uy * ((float) M_PI)));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) t_1 = Float32(t_0 * Float32(Float32(-1.0) + Float32(ux - Float32(maxCos * ux)))) tmp = Float32(0.0) if (ux <= Float32(0.00039999998989515007)) tmp = Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux + ux))); else tmp = Float32(Float32(2.0) * Float32(sqrt(Float32(Float32(Float32(1.0) + Float32(Float32(t_0 * Float32(Float32(1.0) + Float32(Float32(maxCos * ux) - ux))) * t_1)) / Float32(Float32(1.0) + t_1))) * Float32(uy * Float32(pi)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux + (single(-1.0) - (maxCos * ux)); t_1 = t_0 * (single(-1.0) + (ux - (maxCos * ux))); tmp = single(0.0); if (ux <= single(0.00039999998989515007)) tmp = sin((uy * (single(2.0) * single(pi)))) * sqrt((ux + ux)); else tmp = single(2.0) * (sqrt(((single(1.0) + ((t_0 * (single(1.0) + ((maxCos * ux) - ux))) * t_1)) / (single(1.0) + t_1))) * (uy * single(pi))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux + \left(-1 - maxCos \cdot ux\right)\\
t_1 := t_0 \cdot \left(-1 + \left(ux - maxCos \cdot ux\right)\right)\\
\mathbf{if}\;ux \leq 0.00039999998989515007:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + ux}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{\frac{1 + \left(t_0 \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right) \cdot t_1}{1 + t_1}} \cdot \left(uy \cdot \pi\right)\right)\\
\end{array}
\end{array}
if ux < 3.9999999e-4Initial program 36.0%
associate-*l*36.0%
sub-neg36.0%
+-commutative36.0%
distribute-rgt-neg-in36.0%
fma-def36.0%
+-commutative36.0%
associate-+r-36.0%
fma-def36.0%
neg-sub036.0%
+-commutative36.0%
associate-+r-36.0%
associate--r-36.0%
neg-sub036.0%
+-commutative36.0%
sub-neg36.0%
fma-def36.0%
Simplified36.0%
Taylor expanded in ux around 0 91.9%
associate--l+91.9%
distribute-lft-in91.9%
*-rgt-identity91.9%
mul-1-neg91.9%
sub-neg91.9%
metadata-eval91.9%
distribute-neg-in91.9%
metadata-eval91.9%
+-commutative91.9%
sub-neg91.9%
Simplified91.9%
Taylor expanded in maxCos around 0 87.9%
if 3.9999999e-4 < ux Initial program 91.2%
associate-*l*91.2%
sub-neg91.2%
+-commutative91.2%
distribute-rgt-neg-in91.2%
fma-def91.2%
+-commutative91.2%
associate-+r-91.3%
fma-def91.3%
neg-sub091.3%
+-commutative91.3%
associate-+r-91.2%
associate--r-91.2%
neg-sub091.2%
+-commutative91.2%
sub-neg91.2%
fma-def91.2%
Simplified91.2%
Taylor expanded in uy around 0 77.3%
flip-+77.2%
Applied egg-rr77.5%
Final simplification84.2%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return sinf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - ux)));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sin((single(pi) * (single(2.0) * uy))) * sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\sin \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial 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.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.3%
+-commutative98.3%
fma-def98.3%
associate--l+98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
distribute-neg-in98.4%
metadata-eval98.4%
+-commutative98.4%
sub-neg98.4%
sub-neg98.4%
metadata-eval98.4%
*-commutative98.4%
unpow298.4%
Simplified98.4%
Taylor expanded in uy around inf 98.3%
add-log-exp61.8%
associate-*r*61.8%
Applied egg-rr61.8%
Taylor expanded in maxCos around 0 93.6%
associate-*r*93.6%
*-commutative93.6%
*-commutative93.6%
+-commutative93.6%
mul-1-neg93.6%
sub-neg93.6%
*-commutative93.6%
unpow293.6%
distribute-lft-out--93.7%
Simplified93.7%
Final simplification93.7%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ ux (- -1.0 (* maxCos ux))))
(t_1 (* t_0 (+ -1.0 (- ux (* maxCos ux))))))
(if (<= ux 7.999999797903001e-5)
(* 2.0 (* (* uy PI) (sqrt (+ ux (+ ux (* -2.0 (* maxCos ux)))))))
(*
2.0
(*
(sqrt
(/ (+ 1.0 (* (* t_0 (+ 1.0 (- (* maxCos ux) ux))) t_1)) (+ 1.0 t_1)))
(* uy PI))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux + (-1.0f - (maxCos * ux));
float t_1 = t_0 * (-1.0f + (ux - (maxCos * ux)));
float tmp;
if (ux <= 7.999999797903001e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux + (-2.0f * (maxCos * ux))))));
} else {
tmp = 2.0f * (sqrtf(((1.0f + ((t_0 * (1.0f + ((maxCos * ux) - ux))) * t_1)) / (1.0f + t_1))) * (uy * ((float) M_PI)));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) t_1 = Float32(t_0 * Float32(Float32(-1.0) + Float32(ux - Float32(maxCos * ux)))) tmp = Float32(0.0) if (ux <= Float32(7.999999797903001e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux))))))); else tmp = Float32(Float32(2.0) * Float32(sqrt(Float32(Float32(Float32(1.0) + Float32(Float32(t_0 * Float32(Float32(1.0) + Float32(Float32(maxCos * ux) - ux))) * t_1)) / Float32(Float32(1.0) + t_1))) * Float32(uy * Float32(pi)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux + (single(-1.0) - (maxCos * ux)); t_1 = t_0 * (single(-1.0) + (ux - (maxCos * ux))); tmp = single(0.0); if (ux <= single(7.999999797903001e-5)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux + (single(-2.0) * (maxCos * ux)))))); else tmp = single(2.0) * (sqrt(((single(1.0) + ((t_0 * (single(1.0) + ((maxCos * ux) - ux))) * t_1)) / (single(1.0) + t_1))) * (uy * single(pi))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux + \left(-1 - maxCos \cdot ux\right)\\
t_1 := t_0 \cdot \left(-1 + \left(ux - maxCos \cdot ux\right)\right)\\
\mathbf{if}\;ux \leq 7.999999797903001 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\sqrt{\frac{1 + \left(t_0 \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)\right) \cdot t_1}{1 + t_1}} \cdot \left(uy \cdot \pi\right)\right)\\
\end{array}
\end{array}
if ux < 7.9999998e-5Initial program 33.1%
associate-*l*33.1%
sub-neg33.1%
+-commutative33.1%
distribute-rgt-neg-in33.1%
fma-def33.0%
+-commutative33.0%
associate-+r-33.1%
fma-def33.1%
neg-sub033.1%
+-commutative33.1%
associate-+r-33.0%
associate--r-33.0%
neg-sub033.0%
+-commutative33.0%
sub-neg33.0%
fma-def33.0%
Simplified33.0%
Taylor expanded in ux around 0 93.6%
associate--l+93.6%
distribute-lft-in93.6%
*-rgt-identity93.6%
mul-1-neg93.6%
sub-neg93.6%
metadata-eval93.6%
distribute-neg-in93.6%
metadata-eval93.6%
+-commutative93.6%
sub-neg93.6%
Simplified93.6%
Taylor expanded in uy around 0 78.5%
Taylor expanded in maxCos around 0 78.5%
if 7.9999998e-5 < ux Initial program 89.1%
associate-*l*89.1%
sub-neg89.1%
+-commutative89.1%
distribute-rgt-neg-in89.1%
fma-def89.2%
+-commutative89.2%
associate-+r-89.2%
fma-def89.2%
neg-sub089.2%
+-commutative89.2%
associate-+r-89.2%
associate--r-89.2%
neg-sub089.2%
+-commutative89.2%
sub-neg89.2%
fma-def89.2%
Simplified89.2%
Taylor expanded in uy around 0 75.0%
flip-+75.0%
Applied egg-rr75.2%
Final simplification77.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (+ ux (- -1.0 (* maxCos ux)))))
(if (<= ux 9.999999747378752e-5)
(* 2.0 (* (* uy PI) (sqrt (+ ux (+ ux (* -2.0 (* maxCos ux)))))))
(* 2.0 (* (* uy PI) (sqrt (- 1.0 (* t_0 t_0))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux + (-1.0f - (maxCos * ux));
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux + (-2.0f * (maxCos * ux))))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f - (t_0 * t_0))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux))))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux + (single(-1.0) - (maxCos * ux)); tmp = single(0.0); if (ux <= single(9.999999747378752e-5)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux + (single(-2.0) * (maxCos * ux)))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) - (t_0 * t_0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux + \left(-1 - maxCos \cdot ux\right)\\
\mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}\right)\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.3%
+-commutative33.3%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in ux around 0 93.4%
associate--l+93.4%
distribute-lft-in93.5%
*-rgt-identity93.5%
mul-1-neg93.5%
sub-neg93.5%
metadata-eval93.5%
distribute-neg-in93.5%
metadata-eval93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in uy around 0 78.5%
Taylor expanded in maxCos around 0 78.5%
if 9.99999975e-5 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-def89.3%
+-commutative89.3%
associate-+r-89.4%
fma-def89.4%
neg-sub089.4%
+-commutative89.4%
associate-+r-89.3%
associate--r-89.3%
neg-sub089.3%
+-commutative89.3%
sub-neg89.3%
fma-def89.3%
Simplified89.3%
Taylor expanded in uy around 0 75.1%
Final simplification77.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 9.999999747378752e-5)
(* 2.0 (* (* uy PI) (sqrt (+ ux (+ ux (* -2.0 (* maxCos ux)))))))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (+ ux (- -1.0 (* maxCos ux))) (+ 1.0 (- (* maxCos ux) ux)))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux + (-2.0f * (maxCos * ux))))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((ux + (-1.0f - (maxCos * ux))) * (1.0f + ((maxCos * ux) - ux))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux))))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) + Float32(Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) * Float32(Float32(1.0) + Float32(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 = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux + (single(-2.0) * (maxCos * ux)))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((ux + (single(-1.0) - (maxCos * 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}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.3%
+-commutative33.3%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in ux around 0 93.4%
associate--l+93.4%
distribute-lft-in93.5%
*-rgt-identity93.5%
mul-1-neg93.5%
sub-neg93.5%
metadata-eval93.5%
distribute-neg-in93.5%
metadata-eval93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in uy around 0 78.5%
Taylor expanded in maxCos around 0 78.5%
if 9.99999975e-5 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-def89.3%
+-commutative89.3%
associate-+r-89.4%
fma-def89.4%
neg-sub089.4%
+-commutative89.4%
associate-+r-89.3%
associate--r-89.3%
neg-sub089.3%
+-commutative89.3%
sub-neg89.3%
fma-def89.3%
Simplified89.3%
Taylor expanded in uy around 0 75.1%
*-un-lft-identity75.1%
*-commutative75.1%
associate--l+75.2%
*-commutative75.2%
Applied egg-rr75.2%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 9.999999747378752e-5) (* 2.0 (* (* uy PI) (sqrt (+ ux (+ ux (* -2.0 (* maxCos ux))))))) (* 2.0 (* (* uy PI) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.999999747378752e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux + (-2.0f * (maxCos * ux))))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.999999747378752e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux))))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * 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(9.999999747378752e-5)) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux + (single(-2.0) * (maxCos * ux)))))); else tmp = single(2.0) * ((uy * single(pi)) * 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 9.999999747378752 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\right)\\
\end{array}
\end{array}
if ux < 9.99999975e-5Initial program 33.3%
associate-*l*33.3%
sub-neg33.3%
+-commutative33.3%
distribute-rgt-neg-in33.3%
fma-def33.3%
+-commutative33.3%
associate-+r-33.4%
fma-def33.4%
neg-sub033.4%
+-commutative33.4%
associate-+r-33.3%
associate--r-33.3%
neg-sub033.3%
+-commutative33.3%
sub-neg33.3%
fma-def33.3%
Simplified33.3%
Taylor expanded in ux around 0 93.4%
associate--l+93.4%
distribute-lft-in93.5%
*-rgt-identity93.5%
mul-1-neg93.5%
sub-neg93.5%
metadata-eval93.5%
distribute-neg-in93.5%
metadata-eval93.5%
+-commutative93.5%
sub-neg93.5%
Simplified93.5%
Taylor expanded in uy around 0 78.5%
Taylor expanded in maxCos around 0 78.5%
if 9.99999975e-5 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-def89.3%
+-commutative89.3%
associate-+r-89.4%
fma-def89.4%
neg-sub089.4%
+-commutative89.4%
associate-+r-89.3%
associate--r-89.3%
neg-sub089.3%
+-commutative89.3%
sub-neg89.3%
fma-def89.3%
Simplified89.3%
Taylor expanded in uy around 0 75.1%
Taylor expanded in maxCos around 0 71.9%
Final simplification75.9%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (+ ux (* ux (- 1.0 (* maxCos 2.0))))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux * (1.0f - (maxCos * 2.0f))))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - Float32(maxCos * Float32(2.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux * (single(1.0) - (maxCos * single(2.0))))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + ux \cdot \left(1 - maxCos \cdot 2\right)}\right)
\end{array}
Initial 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.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 76.8%
associate--l+76.8%
distribute-lft-in76.9%
*-rgt-identity76.9%
mul-1-neg76.9%
sub-neg76.9%
metadata-eval76.9%
distribute-neg-in76.9%
metadata-eval76.9%
+-commutative76.9%
sub-neg76.9%
Simplified76.9%
Taylor expanded in uy around 0 66.0%
Final simplification66.0%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (+ ux (+ ux (* -2.0 (* maxCos ux))))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + (ux + (-2.0f * (maxCos * ux))))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux))))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + (ux + (single(-2.0) * (maxCos * ux)))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)}\right)
\end{array}
Initial 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.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 76.8%
associate--l+76.8%
distribute-lft-in76.9%
*-rgt-identity76.9%
mul-1-neg76.9%
sub-neg76.9%
metadata-eval76.9%
distribute-neg-in76.9%
metadata-eval76.9%
+-commutative76.9%
sub-neg76.9%
Simplified76.9%
Taylor expanded in uy around 0 66.0%
Taylor expanded in maxCos around 0 66.0%
Final simplification66.0%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (+ ux ux)))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((ux + ux)));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(ux + ux)))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((ux + ux))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{ux + ux}\right)
\end{array}
Initial 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.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 76.8%
associate--l+76.8%
distribute-lft-in76.9%
*-rgt-identity76.9%
mul-1-neg76.9%
sub-neg76.9%
metadata-eval76.9%
distribute-neg-in76.9%
metadata-eval76.9%
+-commutative76.9%
sub-neg76.9%
Simplified76.9%
Taylor expanded in uy around 0 66.0%
Taylor expanded in maxCos around 0 64.0%
Final simplification64.0%
(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(Float32(uy * 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(\left(uy \cdot \pi\right) \cdot \sqrt{0}\right)
\end{array}
Initial 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.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 48.4%
Taylor expanded in ux around 0 7.1%
Final simplification7.1%
herbie shell --seed 2023255
(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)))))))