
(FPCore (g a) :precision binary64 (cbrt (/ g (* 2.0 a))))
double code(double g, double a) {
return cbrt((g / (2.0 * a)));
}
public static double code(double g, double a) {
return Math.cbrt((g / (2.0 * a)));
}
function code(g, a) return cbrt(Float64(g / Float64(2.0 * a))) end
code[g_, a_] := N[Power[N[(g / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{2 \cdot a}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g a) :precision binary64 (cbrt (/ g (* 2.0 a))))
double code(double g, double a) {
return cbrt((g / (2.0 * a)));
}
public static double code(double g, double a) {
return Math.cbrt((g / (2.0 * a)));
}
function code(g, a) return cbrt(Float64(g / Float64(2.0 * a))) end
code[g_, a_] := N[Power[N[(g / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{2 \cdot a}}
\end{array}
(FPCore (g a) :precision binary64 (* (cbrt (/ -1.0 a)) (cbrt (* g -0.5))))
double code(double g, double a) {
return cbrt((-1.0 / a)) * cbrt((g * -0.5));
}
public static double code(double g, double a) {
return Math.cbrt((-1.0 / a)) * Math.cbrt((g * -0.5));
}
function code(g, a) return Float64(cbrt(Float64(-1.0 / a)) * cbrt(Float64(g * -0.5))) end
code[g_, a_] := N[(N[Power[N[(-1.0 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g * -0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-1}{a}} \cdot \sqrt[3]{g \cdot -0.5}
\end{array}
Initial program 72.3%
remove-double-divN/A
inv-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow2N/A
remove-double-negN/A
remove-double-negN/A
sqr-negN/A
pow-prod-downN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
clear-numN/A
/-rgt-identityN/A
neg-sub0N/A
Applied rewrites45.6%
lift-cbrt.f64N/A
lift-/.f64N/A
frac-2negN/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
lower-/.f64N/A
metadata-eval98.7
Applied rewrites98.7%
lift-/.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
cbrt-undivN/A
lift-neg.f64N/A
neg-mul-1N/A
lift-*.f64N/A
times-fracN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
associate-*l*N/A
lft-mult-inverseN/A
metadata-evalN/A
lower-cbrt.f64N/A
metadata-evalN/A
lft-mult-inverseN/A
*-commutativeN/A
Applied rewrites98.8%
(FPCore (g a) :precision binary64 (if (<= (* a 2.0) -4e-306) (* (pow (* a -2.0) -0.3333333333333333) (cbrt (- g))) (* (pow a -0.3333333333333333) (cbrt (* g 0.5)))))
double code(double g, double a) {
double tmp;
if ((a * 2.0) <= -4e-306) {
tmp = pow((a * -2.0), -0.3333333333333333) * cbrt(-g);
} else {
tmp = pow(a, -0.3333333333333333) * cbrt((g * 0.5));
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((a * 2.0) <= -4e-306) {
tmp = Math.pow((a * -2.0), -0.3333333333333333) * Math.cbrt(-g);
} else {
tmp = Math.pow(a, -0.3333333333333333) * Math.cbrt((g * 0.5));
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(a * 2.0) <= -4e-306) tmp = Float64((Float64(a * -2.0) ^ -0.3333333333333333) * cbrt(Float64(-g))); else tmp = Float64((a ^ -0.3333333333333333) * cbrt(Float64(g * 0.5))); end return tmp end
code[g_, a_] := If[LessEqual[N[(a * 2.0), $MachinePrecision], -4e-306], N[(N[Power[N[(a * -2.0), $MachinePrecision], -0.3333333333333333], $MachinePrecision] * N[Power[(-g), 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[a, -0.3333333333333333], $MachinePrecision] * N[Power[N[(g * 0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot 2 \leq -4 \cdot 10^{-306}:\\
\;\;\;\;{\left(a \cdot -2\right)}^{-0.3333333333333333} \cdot \sqrt[3]{-g}\\
\mathbf{else}:\\
\;\;\;\;{a}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot 0.5}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -4.00000000000000011e-306Initial program 77.4%
remove-double-divN/A
inv-powN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow2N/A
remove-double-negN/A
remove-double-negN/A
sqr-negN/A
pow-prod-downN/A
pow-prod-upN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
inv-powN/A
clear-numN/A
/-rgt-identityN/A
neg-sub0N/A
Applied rewrites48.0%
lift-cbrt.f64N/A
lift-/.f64N/A
frac-2negN/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-neg-fracN/A
lower-/.f64N/A
metadata-eval98.6
Applied rewrites98.6%
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
*-commutativeN/A
lower-*.f6498.6
Applied rewrites92.2%
if -4.00000000000000011e-306 < (*.f64 #s(literal 2 binary64) a) Initial program 77.2%
lift-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
div-invN/A
cbrt-prodN/A
pow1/3N/A
*-commutativeN/A
lower-*.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-evalN/A
lower-cbrt.f64N/A
div-invN/A
lower-*.f64N/A
metadata-eval91.7
Applied rewrites91.7%
Final simplification91.9%
herbie shell --seed 2024227
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))