
(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 9 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
(let* ((t_0 (sin (* PI (* 2.0 uy))))
(t_1
(-
(fma ux (fma -2.0 maxCos 1.0) ux)
(* (+ maxCos -1.0) (* (+ maxCos -1.0) (* ux ux))))))
(cbrt (* (* t_0 (sqrt t_1)) (* t_1 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = sinf((((float) M_PI) * (2.0f * uy)));
float t_1 = fmaf(ux, fmaf(-2.0f, maxCos, 1.0f), ux) - ((maxCos + -1.0f) * ((maxCos + -1.0f) * (ux * ux)));
return cbrtf(((t_0 * sqrtf(t_1)) * (t_1 * (t_0 * t_0))));
}
function code(ux, uy, maxCos) t_0 = sin(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) t_1 = Float32(fma(ux, fma(Float32(-2.0), maxCos, Float32(1.0)), ux) - Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)))) return cbrt(Float32(Float32(t_0 * sqrt(t_1)) * Float32(t_1 * Float32(t_0 * t_0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
t_1 := \mathsf{fma}\left(ux, \mathsf{fma}\left(-2, maxCos, 1\right), ux\right) - \left(maxCos + -1\right) \cdot \left(\left(maxCos + -1\right) \cdot \left(ux \cdot ux\right)\right)\\
\sqrt[3]{\left(t_0 \cdot \sqrt{t_1}\right) \cdot \left(t_1 \cdot \left(t_0 \cdot t_0\right)\right)}
\end{array}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
add-exp-log90.3%
distribute-rgt-in90.3%
*-un-lft-identity90.3%
distribute-neg-in90.3%
metadata-eval90.3%
Applied egg-rr90.3%
Taylor expanded in uy around inf 98.3%
add-cbrt-cube98.3%
Applied egg-rr98.3%
Simplified98.4%
Final simplification98.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(+
(* ux (- 1.0 (* 2.0 maxCos)))
(+ ux (* (+ maxCos -1.0) (* (pow ux 2.0) (- 1.0 maxCos))))))
(sin (* 2.0 (* PI uy)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (1.0f - (2.0f * maxCos))) + (ux + ((maxCos + -1.0f) * (powf(ux, 2.0f) * (1.0f - maxCos)))))) * sinf((2.0f * (((float) M_PI) * uy)));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32(ux + Float32(Float32(maxCos + Float32(-1.0)) * Float32((ux ^ Float32(2.0)) * Float32(Float32(1.0) - maxCos)))))) * sin(Float32(Float32(2.0) * Float32(Float32(pi) * uy)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(1.0) - (single(2.0) * maxCos))) + (ux + ((maxCos + single(-1.0)) * ((ux ^ single(2.0)) * (single(1.0) - maxCos)))))) * sin((single(2.0) * (single(pi) * uy))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 - 2 \cdot maxCos\right) + \left(ux + \left(maxCos + -1\right) \cdot \left({ux}^{2} \cdot \left(1 - maxCos\right)\right)\right)} \cdot \sin \left(2 \cdot \left(\pi \cdot uy\right)\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
add-exp-log90.3%
distribute-rgt-in90.3%
*-un-lft-identity90.3%
distribute-neg-in90.3%
metadata-eval90.3%
Applied egg-rr90.3%
Taylor expanded in uy around inf 98.3%
Final simplification98.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* 2.0 (* PI uy)))
(sqrt
(+
(* (+ maxCos -1.0) (* (pow ux 2.0) (- 1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sinf((2.0f * (((float) M_PI) * uy))) * sqrtf((((maxCos + -1.0f) * (powf(ux, 2.0f) * (1.0f - maxCos))) + (ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(Float32(2.0) * Float32(Float32(pi) * uy))) * sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32((ux ^ Float32(2.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) * (single(pi) * uy))) * sqrt((((maxCos + single(-1.0)) * ((ux ^ single(2.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sin \left(2 \cdot \left(\pi \cdot uy\right)\right) \cdot \sqrt{\left(maxCos + -1\right) \cdot \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.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 (* ux (+ -1.0 ux))))
(*
(sin (* uy (* PI 2.0)))
(sqrt (+ (* maxCos (+ t_0 t_0)) (- (* 2.0 ux) (* ux ux)))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (-1.0f + ux);
return sinf((uy * (((float) M_PI) * 2.0f))) * sqrtf(((maxCos * (t_0 + t_0)) + ((2.0f * ux) - (ux * ux))));
}
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(Float32(-1.0) + ux)) return Float32(sin(Float32(uy * Float32(Float32(pi) * Float32(2.0)))) * sqrt(Float32(Float32(maxCos * Float32(t_0 + t_0)) + Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))))) end
function tmp = code(ux, uy, maxCos) t_0 = ux * (single(-1.0) + ux); tmp = sin((uy * (single(pi) * single(2.0)))) * sqrt(((maxCos * (t_0 + t_0)) + ((single(2.0) * ux) - (ux * ux)))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(-1 + ux\right)\\
\sin \left(uy \cdot \left(\pi \cdot 2\right)\right) \cdot \sqrt{maxCos \cdot \left(t_0 + t_0\right) + \left(2 \cdot ux - ux \cdot ux\right)}
\end{array}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in maxCos around 0 51.5%
Taylor expanded in ux around 0 97.5%
+-commutative97.5%
neg-mul-197.5%
unsub-neg97.5%
unpow297.5%
Simplified97.5%
Final simplification97.5%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 1.500000053056283e-6)
(* (sin (* uy (* PI 2.0))) (sqrt (- (* 2.0 ux) (* ux ux))))
(*
2.0
(*
(* PI uy)
(sqrt
(+
(+ ux (* ux (+ 1.0 (* maxCos -2.0))))
(* (+ maxCos -1.0) (* ux (* ux (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 1.500000053056283e-6f) {
tmp = sinf((uy * (((float) M_PI) * 2.0f))) * sqrtf(((2.0f * ux) - (ux * ux)));
} else {
tmp = 2.0f * ((((float) M_PI) * uy) * sqrtf(((ux + (ux * (1.0f + (maxCos * -2.0f)))) + ((maxCos + -1.0f) * (ux * (ux * (1.0f - maxCos)))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(1.500000053056283e-6)) tmp = Float32(sin(Float32(uy * Float32(Float32(pi) * Float32(2.0)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); else tmp = Float32(Float32(2.0) * Float32(Float32(Float32(pi) * uy) * sqrt(Float32(Float32(ux + Float32(ux * Float32(Float32(1.0) + Float32(maxCos * Float32(-2.0))))) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(ux * Float32(Float32(1.0) - maxCos)))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(1.500000053056283e-6)) tmp = sin((uy * (single(pi) * single(2.0)))) * sqrt(((single(2.0) * ux) - (ux * ux))); else tmp = single(2.0) * ((single(pi) * uy) * sqrt(((ux + (ux * (single(1.0) + (maxCos * single(-2.0))))) + ((maxCos + single(-1.0)) * (ux * (ux * (single(1.0) - maxCos))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 1.500000053056283 \cdot 10^{-6}:\\
\;\;\;\;\sin \left(uy \cdot \left(\pi \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(\pi \cdot uy\right) \cdot \sqrt{\left(ux + ux \cdot \left(1 + maxCos \cdot -2\right)\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)}\right)\\
\end{array}
\end{array}
if maxCos < 1.50000005e-6Initial program 54.3%
associate-*l*54.3%
sub-neg54.3%
+-commutative54.3%
distribute-rgt-neg-in54.3%
fma-def54.6%
+-commutative54.6%
associate-+r-54.6%
fma-def54.6%
neg-sub054.6%
+-commutative54.6%
associate-+r-54.6%
associate--r-54.6%
neg-sub054.6%
+-commutative54.6%
sub-neg54.6%
fma-def54.6%
Simplified54.6%
Taylor expanded in ux around 0 98.2%
fma-def98.2%
sub-neg98.2%
metadata-eval98.2%
*-commutative98.2%
unpow298.2%
associate--l+98.2%
mul-1-neg98.2%
sub-neg98.2%
metadata-eval98.2%
Simplified98.2%
Taylor expanded in maxCos around 0 98.1%
+-commutative98.1%
neg-mul-198.1%
unsub-neg98.1%
unpow298.1%
Simplified98.1%
if 1.50000005e-6 < maxCos Initial program 51.5%
associate-*l*51.5%
sub-neg51.5%
+-commutative51.5%
distribute-rgt-neg-in51.5%
fma-def51.4%
+-commutative51.4%
associate-+r-51.0%
fma-def51.0%
neg-sub051.0%
+-commutative51.0%
associate-+r-50.2%
associate--r-50.2%
neg-sub050.2%
+-commutative50.2%
sub-neg50.2%
fma-def50.2%
Simplified50.2%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
associate--l+98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
add-exp-log91.5%
distribute-rgt-in91.5%
*-un-lft-identity91.5%
distribute-neg-in91.5%
metadata-eval91.5%
Applied egg-rr91.5%
Taylor expanded in uy around 0 86.0%
fma-def86.0%
cancel-sign-sub-inv86.0%
metadata-eval86.0%
*-commutative86.0%
*-commutative86.0%
unpow286.0%
sub-neg86.0%
metadata-eval86.0%
+-commutative86.0%
Simplified86.0%
fma-udef86.0%
*-commutative86.0%
metadata-eval86.0%
cancel-sign-sub-inv86.0%
*-commutative86.0%
+-commutative86.0%
metadata-eval86.0%
sub-neg86.0%
pow286.0%
associate-+r+86.2%
cancel-sign-sub-inv86.2%
metadata-eval86.2%
*-commutative86.2%
pow286.2%
Applied egg-rr86.2%
Final simplification96.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
2.0
(*
(* PI uy)
(sqrt
(+
(* ux (+ 1.0 (* maxCos -2.0)))
(+ ux (* (+ maxCos -1.0) (* ux (* ux (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((((float) M_PI) * uy) * sqrtf(((ux * (1.0f + (maxCos * -2.0f))) + (ux + ((maxCos + -1.0f) * (ux * (ux * (1.0f - maxCos))))))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(Float32(pi) * uy) * sqrt(Float32(Float32(ux * Float32(Float32(1.0) + Float32(maxCos * Float32(-2.0)))) + Float32(ux + Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(ux * Float32(Float32(1.0) - maxCos))))))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((single(pi) * uy) * sqrt(((ux * (single(1.0) + (maxCos * single(-2.0)))) + (ux + ((maxCos + single(-1.0)) * (ux * (ux * (single(1.0) - maxCos)))))))); end
\begin{array}{l}
\\
2 \cdot \left(\left(\pi \cdot uy\right) \cdot \sqrt{ux \cdot \left(1 + maxCos \cdot -2\right) + \left(ux + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)\right)}\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
add-exp-log90.3%
distribute-rgt-in90.3%
*-un-lft-identity90.3%
distribute-neg-in90.3%
metadata-eval90.3%
Applied egg-rr90.3%
Taylor expanded in uy around 0 81.4%
fma-def81.3%
cancel-sign-sub-inv81.3%
metadata-eval81.3%
*-commutative81.3%
*-commutative81.3%
unpow281.3%
sub-neg81.3%
metadata-eval81.3%
+-commutative81.3%
Simplified81.3%
fma-udef81.4%
*-commutative81.4%
metadata-eval81.4%
cancel-sign-sub-inv81.4%
*-commutative81.4%
+-commutative81.4%
metadata-eval81.4%
sub-neg81.4%
pow281.4%
+-commutative81.4%
Applied egg-rr81.4%
Final simplification81.4%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* uy (* PI (sqrt (* ux (+ 2.0 (* maxCos -2.0))))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * (uy * (((float) M_PI) * sqrtf((ux * (2.0f + (maxCos * -2.0f))))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(uy * Float32(Float32(pi) * sqrt(Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * (uy * (single(pi) * sqrt((ux * (single(2.0) + (maxCos * single(-2.0))))))); end
\begin{array}{l}
\\
2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{ux \cdot \left(2 + maxCos \cdot -2\right)}\right)\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in maxCos around 0 51.5%
Taylor expanded in uy around 0 45.3%
associate-*l*45.3%
fma-def45.3%
+-commutative45.3%
mul-1-neg45.3%
unsub-neg45.3%
sub-neg45.3%
metadata-eval45.3%
*-commutative45.3%
*-commutative45.3%
Simplified45.3%
Taylor expanded in ux around 0 67.8%
Final simplification67.8%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* PI uy) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((((float) M_PI) * uy) * sqrtf(((2.0f * ux) - (ux * ux))));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(Float32(pi) * uy) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((single(pi) * uy) * sqrt(((single(2.0) * ux) - (ux * ux)))); end
\begin{array}{l}
\\
2 \cdot \left(\left(\pi \cdot uy\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
add-exp-log90.3%
distribute-rgt-in90.3%
*-un-lft-identity90.3%
distribute-neg-in90.3%
metadata-eval90.3%
Applied egg-rr90.3%
Taylor expanded in uy around 0 81.4%
fma-def81.3%
cancel-sign-sub-inv81.3%
metadata-eval81.3%
*-commutative81.3%
*-commutative81.3%
unpow281.3%
sub-neg81.3%
metadata-eval81.3%
+-commutative81.3%
Simplified81.3%
Taylor expanded in maxCos around 0 76.5%
+-commutative76.5%
mul-1-neg76.5%
unsub-neg76.5%
*-commutative76.5%
unpow276.5%
Simplified76.5%
Final simplification76.5%
(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(uy * Float32(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(uy \cdot \left(\pi \cdot \sqrt{2 \cdot ux}\right)\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.9%
associate--r-53.9%
neg-sub053.9%
+-commutative53.9%
sub-neg53.9%
fma-def53.9%
Simplified53.9%
Taylor expanded in maxCos around 0 51.5%
Taylor expanded in uy around 0 45.3%
associate-*l*45.3%
fma-def45.3%
+-commutative45.3%
mul-1-neg45.3%
unsub-neg45.3%
sub-neg45.3%
metadata-eval45.3%
*-commutative45.3%
*-commutative45.3%
Simplified45.3%
Taylor expanded in ux around 0 67.8%
Taylor expanded in maxCos around 0 64.7%
*-commutative64.7%
Simplified64.7%
Final simplification64.7%
herbie shell --seed 2023222
(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)))))))