
(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 8 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 (* 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.7%
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 (if (<= (* 2.0 a) -1e-304) (* (cbrt (* g -0.5)) (pow (- a) -0.3333333333333333)) (* (pow a -0.3333333333333333) (cbrt (* g 0.5)))))
double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -1e-304) {
tmp = cbrt((g * -0.5)) * pow(-a, -0.3333333333333333);
} 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) <= -1e-304) {
tmp = Math.cbrt((g * -0.5)) * Math.pow(-a, -0.3333333333333333);
} 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) <= -1e-304) tmp = Float64(cbrt(Float64(g * -0.5)) * (Float64(-a) ^ -0.3333333333333333)); 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], -1e-304], N[(N[Power[N[(g * -0.5), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[(-a), -0.3333333333333333], $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 -1 \cdot 10^{-304}:\\
\;\;\;\;\sqrt[3]{g \cdot -0.5} \cdot {\left(-a\right)}^{-0.3333333333333333}\\
\mathbf{else}:\\
\;\;\;\;{a}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot 0.5}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -9.99999999999999971e-305Initial program 74.2%
lift-*.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
cbrt-undivN/A
lift-*.f64N/A
associate-/r*N/A
cbrt-divN/A
div-invN/A
metadata-evalN/A
lift-*.f64N/A
cbrt-divN/A
frac-2negN/A
div-invN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lift-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
pow1/3N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
lower-pow.f64N/A
lower-neg.f6491.8
Applied rewrites91.8%
if -9.99999999999999971e-305 < (*.f64 #s(literal 2 binary64) a) Initial program 79.7%
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.1
Applied rewrites92.1%
(FPCore (g a) :precision binary64 (if (<= (* 2.0 a) -1e-304) (cbrt (/ (/ g a) (* (/ 0.5 a) (* a 4.0)))) (* (pow a -0.3333333333333333) (cbrt (* g 0.5)))))
double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -1e-304) {
tmp = cbrt(((g / a) / ((0.5 / a) * (a * 4.0))));
} 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) <= -1e-304) {
tmp = Math.cbrt(((g / a) / ((0.5 / a) * (a * 4.0))));
} 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) <= -1e-304) tmp = cbrt(Float64(Float64(g / a) / Float64(Float64(0.5 / a) * Float64(a * 4.0)))); 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], -1e-304], N[Power[N[(N[(g / a), $MachinePrecision] / N[(N[(0.5 / a), $MachinePrecision] * N[(a * 4.0), $MachinePrecision]), $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 -1 \cdot 10^{-304}:\\
\;\;\;\;\sqrt[3]{\frac{\frac{g}{a}}{\frac{0.5}{a} \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;{a}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot 0.5}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -9.99999999999999971e-305Initial program 74.2%
lift-*.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-eval74.1
Applied rewrites74.1%
associate-*l/N/A
*-commutativeN/A
associate-*l/N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
pow-divN/A
unpow1N/A
unpow1N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
lift-*.f64N/A
times-fracN/A
associate-/r*N/A
*-commutativeN/A
associate-/l*N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
metadata-evalN/A
associate-/r/N/A
lift-/.f64N/A
frac-timesN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites74.2%
if -9.99999999999999971e-305 < (*.f64 #s(literal 2 binary64) a) Initial program 79.7%
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.1
Applied rewrites92.1%
(FPCore (g a) :precision binary64 (* (cbrt g) (cbrt (/ 0.5 a))))
double code(double g, double a) {
return cbrt(g) * cbrt((0.5 / a));
}
public static double code(double g, double a) {
return Math.cbrt(g) * Math.cbrt((0.5 / a));
}
function code(g, a) return Float64(cbrt(g) * cbrt(Float64(0.5 / a))) end
code[g_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g} \cdot \sqrt[3]{\frac{0.5}{a}}
\end{array}
Initial program 76.7%
associate-/r*N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
lower-cbrt.f6498.8
Applied rewrites98.8%
lift-*.f64N/A
cbrt-undivN/A
pow1/3N/A
lift-*.f64N/A
associate-/l*N/A
unpow-prod-downN/A
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-cbrt.f64N/A
lower-/.f64N/A
pow1/3N/A
lower-cbrt.f6498.7
Applied rewrites98.7%
Final simplification98.7%
(FPCore (g a) :precision binary64 (/ 1.0 (cbrt (/ a (* g 0.5)))))
double code(double g, double a) {
return 1.0 / cbrt((a / (g * 0.5)));
}
public static double code(double g, double a) {
return 1.0 / Math.cbrt((a / (g * 0.5)));
}
function code(g, a) return Float64(1.0 / cbrt(Float64(a / Float64(g * 0.5)))) end
code[g_, a_] := N[(1.0 / N[Power[N[(a / N[(g * 0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt[3]{\frac{a}{g \cdot 0.5}}}
\end{array}
Initial program 76.7%
lift-*.f64N/A
clear-numN/A
cbrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lower-cbrt.f64N/A
clear-numN/A
lift-*.f64N/A
associate-/r*N/A
clear-numN/A
lower-/.f64N/A
div-invN/A
lower-*.f64N/A
metadata-eval76.9
Applied rewrites76.9%
(FPCore (g a) :precision binary64 (/ 1.0 (cbrt (* a (/ 2.0 g)))))
double code(double g, double a) {
return 1.0 / cbrt((a * (2.0 / g)));
}
public static double code(double g, double a) {
return 1.0 / Math.cbrt((a * (2.0 / g)));
}
function code(g, a) return Float64(1.0 / cbrt(Float64(a * Float64(2.0 / g)))) end
code[g_, a_] := N[(1.0 / N[Power[N[(a * N[(2.0 / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt[3]{a \cdot \frac{2}{g}}}
\end{array}
Initial program 76.7%
lift-*.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.8
Applied rewrites98.8%
Applied rewrites76.5%
associate-*l*N/A
metadata-evalN/A
lift-*.f64N/A
*-rgt-identityN/A
lift-*.f64N/A
associate-/r/N/A
clear-numN/A
lift-*.f64N/A
*-rgt-identityN/A
lift-*.f64N/A
associate-/l*N/A
metadata-evalN/A
associate-/r*N/A
associate-/r/N/A
lift-/.f64N/A
*-inversesN/A
associate-/r*N/A
*-commutativeN/A
lift-*.f64N/A
associate-/l/N/A
lift-/.f64N/A
associate-*l/N/A
associate-/r/N/A
lower-*.f64N/A
Applied rewrites76.8%
Final simplification76.8%
(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}
Initial program 76.7%
(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.7%
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.7
Applied rewrites76.7%
Final simplification76.7%
herbie shell --seed 2024209
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))