
(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 6 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 g) (cbrt (/ 4.0 (/ 2.0 a)))))
double code(double g, double a) {
return cbrt(g) / cbrt((4.0 / (2.0 / a)));
}
public static double code(double g, double a) {
return Math.cbrt(g) / Math.cbrt((4.0 / (2.0 / a)));
}
function code(g, a) return Float64(cbrt(g) / cbrt(Float64(4.0 / Float64(2.0 / a)))) end
code[g_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[N[(4.0 / N[(2.0 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g}}{\sqrt[3]{\frac{4}{\frac{2}{a}}}}
\end{array}
Initial program 76.0%
lift-cbrt.f64N/A
lift-/.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
metadata-evalN/A
associate-/r/N/A
div-invN/A
associate-/r*N/A
metadata-evalN/A
metadata-evalN/A
associate-/r*N/A
div-invN/A
lower-/.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
(FPCore (g a) :precision binary64 (if (<= (* 2.0 a) -4e-307) (* (pow (- a) -0.3333333333333333) (cbrt (* g -0.5))) (* (pow a -0.3333333333333333) (cbrt (* g 0.5)))))
double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -4e-307) {
tmp = pow(-a, -0.3333333333333333) * cbrt((g * -0.5));
} else {
tmp = pow(a, -0.3333333333333333) * cbrt((g * 0.5));
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -4e-307) {
tmp = Math.pow(-a, -0.3333333333333333) * Math.cbrt((g * -0.5));
} else {
tmp = Math.pow(a, -0.3333333333333333) * Math.cbrt((g * 0.5));
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(2.0 * a) <= -4e-307) tmp = Float64((Float64(-a) ^ -0.3333333333333333) * cbrt(Float64(g * -0.5))); else tmp = Float64((a ^ -0.3333333333333333) * cbrt(Float64(g * 0.5))); end return tmp end
code[g_, a_] := If[LessEqual[N[(2.0 * a), $MachinePrecision], -4e-307], N[(N[Power[(-a), -0.3333333333333333], $MachinePrecision] * N[Power[N[(g * -0.5), $MachinePrecision], 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}\;2 \cdot a \leq -4 \cdot 10^{-307}:\\
\;\;\;\;{\left(-a\right)}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;{a}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot 0.5}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -3.99999999999999964e-307Initial program 79.1%
lift-cbrt.f64N/A
lift-/.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.8
Applied rewrites98.8%
lift-/.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
*-rgt-identityN/A
*-inversesN/A
associate-/l*N/A
lift-*.f64N/A
cbrt-prodN/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
clear-numN/A
lift-/.f64N/A
lift-/.f64N/A
cbrt-divN/A
Applied rewrites98.8%
lift-*.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
cbrt-unprodN/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
metadata-evalN/A
div-invN/A
associate-*l/N/A
frac-2negN/A
associate-*l/N/A
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
lower-*.f64N/A
Applied rewrites92.4%
if -3.99999999999999964e-307 < (*.f64 #s(literal 2 binary64) a) Initial program 72.4%
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-eval92.2
Applied rewrites92.2%
Final simplification92.3%
(FPCore (g a) :precision binary64 (if (<= (* 2.0 a) -4e-307) (cbrt (/ (/ 1.0 a) (/ 2.0 g))) (* (pow a -0.3333333333333333) (cbrt (* g 0.5)))))
double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -4e-307) {
tmp = cbrt(((1.0 / a) / (2.0 / g)));
} else {
tmp = pow(a, -0.3333333333333333) * cbrt((g * 0.5));
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -4e-307) {
tmp = Math.cbrt(((1.0 / a) / (2.0 / g)));
} else {
tmp = Math.pow(a, -0.3333333333333333) * Math.cbrt((g * 0.5));
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(2.0 * a) <= -4e-307) tmp = cbrt(Float64(Float64(1.0 / a) / Float64(2.0 / g))); else tmp = Float64((a ^ -0.3333333333333333) * cbrt(Float64(g * 0.5))); end return tmp end
code[g_, a_] := If[LessEqual[N[(2.0 * a), $MachinePrecision], -4e-307], N[Power[N[(N[(1.0 / a), $MachinePrecision] / N[(2.0 / g), $MachinePrecision]), $MachinePrecision], 1/3], $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}\;2 \cdot a \leq -4 \cdot 10^{-307}:\\
\;\;\;\;\sqrt[3]{\frac{\frac{1}{a}}{\frac{2}{g}}}\\
\mathbf{else}:\\
\;\;\;\;{a}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot 0.5}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -3.99999999999999964e-307Initial program 79.1%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6479.1
Applied rewrites79.1%
if -3.99999999999999964e-307 < (*.f64 #s(literal 2 binary64) a) Initial program 72.4%
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-eval92.2
Applied rewrites92.2%
(FPCore (g a) :precision binary64 (/ (cbrt g) (cbrt (* 2.0 a))))
double code(double g, double a) {
return cbrt(g) / cbrt((2.0 * a));
}
public static double code(double g, double a) {
return Math.cbrt(g) / Math.cbrt((2.0 * a));
}
function code(g, a) return Float64(cbrt(g) / cbrt(Float64(2.0 * a))) end
code[g_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[N[(2.0 * a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g}}{\sqrt[3]{2 \cdot a}}
\end{array}
Initial program 76.0%
lift-cbrt.f64N/A
lift-/.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.8
Applied rewrites98.8%
(FPCore (g a) :precision binary64 (cbrt (/ (/ 1.0 a) (/ 2.0 g))))
double code(double g, double a) {
return cbrt(((1.0 / a) / (2.0 / g)));
}
public static double code(double g, double a) {
return Math.cbrt(((1.0 / a) / (2.0 / g)));
}
function code(g, a) return cbrt(Float64(Float64(1.0 / a) / Float64(2.0 / g))) end
code[g_, a_] := N[Power[N[(N[(1.0 / a), $MachinePrecision] / N[(2.0 / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{\frac{1}{a}}{\frac{2}{g}}}
\end{array}
Initial program 76.0%
lift-/.f64N/A
clear-numN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6476.0
Applied rewrites76.0%
(FPCore (g a) :precision binary64 (cbrt (* g (/ 0.5 a))))
double code(double g, double a) {
return cbrt((g * (0.5 / a)));
}
public static double code(double g, double a) {
return Math.cbrt((g * (0.5 / a)));
}
function code(g, a) return cbrt(Float64(g * Float64(0.5 / a))) end
code[g_, a_] := N[Power[N[(g * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g \cdot \frac{0.5}{a}}
\end{array}
Initial program 76.0%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-eval76.0
Applied rewrites76.0%
Final simplification76.0%
herbie shell --seed 2024234
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))