
(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 11 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
(*
(sin (* uy (* 2.0 PI)))
(cbrt
(pow
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))
(* ux (- (- (- 1.0 maxCos) maxCos) -1.0)))
1.5))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * cbrtf(powf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (ux * (((1.0f - maxCos) - maxCos) - -1.0f))), 1.5f));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * cbrt((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)))) ^ Float32(1.5)))) end
\begin{array}{l}
\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left({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)\right)}^{1.5}}
\end{array}
Initial program 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in ux around -inf 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
associate-*r*98.4%
mul-1-neg98.4%
sub-neg98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
sub-neg98.4%
mul-1-neg98.4%
unsub-neg98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
add-cbrt-cube98.3%
add-sqr-sqrt98.4%
pow198.4%
pow1/298.4%
pow-prod-up98.4%
Applied egg-rr98.4%
Final simplification98.4%
(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 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in ux around -inf 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
associate-*r*98.4%
mul-1-neg98.4%
sub-neg98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
sub-neg98.4%
mul-1-neg98.4%
unsub-neg98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in uy around inf 98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (sin (* PI (* uy 2.0)))))
(if (<= maxCos 9.999999747378752e-6)
(* (sqrt (* ux (- (- -2.0) ux))) t_0)
(* t_0 (sqrt (* ux (- 2.0 (* 2.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = sinf((((float) M_PI) * (uy * 2.0f)));
float tmp;
if (maxCos <= 9.999999747378752e-6f) {
tmp = sqrtf((ux * (-(-2.0f) - ux))) * t_0;
} else {
tmp = t_0 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = sin(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) tmp = Float32(0.0) if (maxCos <= Float32(9.999999747378752e-6)) tmp = Float32(sqrt(Float32(ux * Float32(Float32(-Float32(-2.0)) - ux))) * t_0); else tmp = Float32(t_0 * 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 = sin((single(pi) * (uy * single(2.0)))); tmp = single(0.0); if (maxCos <= single(9.999999747378752e-6)) tmp = sqrt((ux * (-single(-2.0) - ux))) * t_0; else tmp = t_0 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\pi \cdot \left(uy \cdot 2\right)\right)\\
\mathbf{if}\;maxCos \leq 9.999999747378752 \cdot 10^{-6}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(--2\right) - ux\right)} \cdot t_0\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 9.99999975e-6Initial program 57.1%
associate-*l*57.1%
sub-neg57.1%
+-commutative57.1%
distribute-rgt-neg-in57.1%
fma-def57.2%
Simplified57.2%
Taylor expanded in ux around -inf 98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
associate-*r*98.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%
associate-*r*98.3%
add-log-exp61.6%
associate-*r*61.6%
*-commutative61.6%
associate-*l*61.6%
Applied egg-rr61.6%
rem-log-exp98.3%
associate-*r*98.3%
*-commutative98.3%
log1p-expm1-u98.3%
associate-*r*98.3%
Applied egg-rr98.3%
Taylor expanded in maxCos around 0 97.9%
associate-*r*97.9%
*-commutative97.9%
*-commutative97.9%
*-commutative97.9%
sub-neg97.9%
mul-1-neg97.9%
distribute-neg-out97.9%
unpow297.9%
distribute-rgt-out98.0%
Simplified98.0%
if 9.99999975e-6 < maxCos Initial program 48.7%
Taylor expanded in ux around 0 84.6%
*-commutative84.6%
Simplified84.6%
Final simplification96.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00044999999227002263)
(* (sin (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (- 1.0 (- ux (* ux maxCos))) (+ -1.0 (* ux (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00044999999227002263f) {
tmp = sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((1.0f - (ux - (ux * maxCos))) * (-1.0f + (ux * (1.0f - maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00044999999227002263)) tmp = Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * 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(ux * maxCos))) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00044999999227002263)) tmp = sin((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((single(1.0) - (ux - (ux * maxCos))) * (single(-1.0) + (ux * (single(1.0) - maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00044999999227002263:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 4.49999992e-4Initial program 38.8%
associate-*l*38.8%
sub-neg38.8%
+-commutative38.8%
distribute-rgt-neg-in38.8%
fma-def38.8%
Simplified38.9%
Taylor expanded in maxCos around 0 38.1%
Taylor expanded in ux around 0 85.4%
if 4.49999992e-4 < ux Initial program 91.7%
associate-*l*91.7%
sub-neg91.7%
+-commutative91.7%
distribute-rgt-neg-in91.7%
fma-def91.9%
Simplified92.0%
Taylor expanded in uy around 0 76.9%
Simplified77.1%
Final simplification82.7%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* ux (- (- -2.0) ux))) (sin (* PI (* uy 2.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (-(-2.0f) - ux))) * sinf((((float) M_PI) * (uy * 2.0f)));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(ux * Float32(Float32(-Float32(-2.0)) - ux))) * sin(Float32(Float32(pi) * Float32(uy * Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (-single(-2.0) - ux))) * sin((single(pi) * (uy * single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(--2\right) - ux\right)} \cdot \sin \left(\pi \cdot \left(uy \cdot 2\right)\right)
\end{array}
Initial program 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in ux around -inf 98.4%
+-commutative98.4%
mul-1-neg98.4%
unsub-neg98.4%
associate-*r*98.4%
mul-1-neg98.4%
sub-neg98.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
sub-neg98.4%
mul-1-neg98.4%
unsub-neg98.4%
mul-1-neg98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
associate-*r*98.4%
add-log-exp61.7%
associate-*r*61.7%
*-commutative61.7%
associate-*l*61.7%
Applied egg-rr61.7%
rem-log-exp98.4%
associate-*r*98.4%
*-commutative98.4%
log1p-expm1-u98.4%
associate-*r*98.4%
Applied egg-rr98.4%
Taylor expanded in maxCos around 0 92.1%
associate-*r*92.1%
*-commutative92.1%
*-commutative92.1%
*-commutative92.1%
sub-neg92.1%
mul-1-neg92.1%
distribute-neg-out92.1%
unpow292.1%
distribute-rgt-out92.1%
Simplified92.1%
Final simplification92.1%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 9.40000027185306e-5)
(* 2.0 (* (* uy PI) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (- (+ 1.0 (* ux maxCos)) ux) (+ -1.0 (* ux (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.40000027185306e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos)))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + (((1.0f + (ux * maxCos)) - ux) * (-1.0f + (ux * (1.0f - maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.40000027185306e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - ux) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(9.40000027185306e-5)) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + (((single(1.0) + (ux * maxCos)) - ux) * (single(-1.0) + (ux * (single(1.0) - maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.40000027185306 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(\left(1 + ux \cdot maxCos\right) - ux\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 9.40000027e-5Initial program 35.7%
associate-*l*35.7%
sub-neg35.7%
+-commutative35.7%
distribute-rgt-neg-in35.7%
fma-def35.7%
Simplified35.8%
Taylor expanded in uy around 0 32.5%
Simplified32.6%
Taylor expanded in ux around 0 76.9%
Taylor expanded in maxCos around 0 77.0%
if 9.40000027e-5 < ux Initial program 89.1%
associate-*l*89.1%
sub-neg89.1%
+-commutative89.1%
distribute-rgt-neg-in89.1%
fma-def89.4%
Simplified89.4%
Taylor expanded in uy around 0 74.8%
Simplified75.0%
Taylor expanded in uy around 0 74.8%
Final simplification76.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 9.40000027185306e-5)
(* 2.0 (* (* uy PI) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (- 1.0 (- ux (* ux maxCos))) (+ -1.0 (* ux (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 9.40000027185306e-5f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos)))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((1.0f - (ux - (ux * maxCos))) * (-1.0f + (ux * (1.0f - maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(9.40000027185306e-5)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * 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(ux * maxCos))) * Float32(Float32(-1.0) + Float32(ux * Float32(Float32(1.0) - maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(9.40000027185306e-5)) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos))))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((single(1.0) - (ux - (ux * maxCos))) * (single(-1.0) + (ux * (single(1.0) - maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 9.40000027185306 \cdot 10^{-5}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(-1 + ux \cdot \left(1 - maxCos\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 9.40000027e-5Initial program 35.7%
associate-*l*35.7%
sub-neg35.7%
+-commutative35.7%
distribute-rgt-neg-in35.7%
fma-def35.7%
Simplified35.8%
Taylor expanded in uy around 0 32.5%
Simplified32.6%
Taylor expanded in ux around 0 76.9%
Taylor expanded in maxCos around 0 77.0%
if 9.40000027e-5 < ux Initial program 89.1%
associate-*l*89.1%
sub-neg89.1%
+-commutative89.1%
distribute-rgt-neg-in89.1%
fma-def89.4%
Simplified89.4%
Taylor expanded in uy around 0 74.8%
Simplified75.0%
Final simplification76.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00046999999904073775) (* 2.0 (* (* uy PI) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))))) (* 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 <= 0.00046999999904073775f) {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos)))));
} 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(0.00046999999904073775)) tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))))); 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(0.00046999999904073775)) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos))))); 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 0.00046999999904073775:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\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 < 4.69999999e-4Initial program 39.2%
associate-*l*39.2%
sub-neg39.2%
+-commutative39.2%
distribute-rgt-neg-in39.2%
fma-def39.2%
Simplified39.3%
Taylor expanded in uy around 0 35.3%
Simplified35.4%
Taylor expanded in ux around 0 75.6%
Taylor expanded in maxCos around 0 75.6%
if 4.69999999e-4 < ux Initial program 92.1%
associate-*l*92.1%
sub-neg92.1%
+-commutative92.1%
distribute-rgt-neg-in92.1%
fma-def92.3%
Simplified92.3%
Taylor expanded in uy around 0 77.1%
Simplified77.3%
Taylor expanded in maxCos around 0 75.4%
Final simplification75.5%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\right)
\end{array}
Initial program 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in uy around 0 48.5%
Simplified48.6%
Taylor expanded in ux around 0 66.3%
Taylor expanded in maxCos around 0 66.4%
Final simplification66.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 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in uy around 0 48.5%
Simplified48.6%
Taylor expanded in ux around 0 66.3%
Final simplification66.3%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf((2.0f * ux)));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(2.0) * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(2.0) * ux))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{2 \cdot ux}\right)
\end{array}
Initial program 55.9%
associate-*l*55.9%
sub-neg55.9%
+-commutative55.9%
distribute-rgt-neg-in55.9%
fma-def56.0%
Simplified56.1%
Taylor expanded in uy around 0 48.5%
Simplified48.6%
Taylor expanded in ux around 0 66.3%
Taylor expanded in maxCos around 0 62.8%
Final simplification62.8%
herbie shell --seed 2024020
(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)))))))