
(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 76.6%
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-eval42.5
Applied egg-rr42.5%
Taylor expanded in a around 0
lower-cbrt.f64N/A
lower-/.f6498.8
Simplified98.8%
(FPCore (g a) :precision binary64 (if (<= (* a 2.0) -5e-301) (* (pow (* a -2.0) -0.3333333333333333) (cbrt (- g))) (* (cbrt g) (pow (* a 2.0) -0.3333333333333333))))
double code(double g, double a) {
double tmp;
if ((a * 2.0) <= -5e-301) {
tmp = pow((a * -2.0), -0.3333333333333333) * cbrt(-g);
} else {
tmp = cbrt(g) * pow((a * 2.0), -0.3333333333333333);
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((a * 2.0) <= -5e-301) {
tmp = Math.pow((a * -2.0), -0.3333333333333333) * Math.cbrt(-g);
} else {
tmp = Math.cbrt(g) * Math.pow((a * 2.0), -0.3333333333333333);
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(a * 2.0) <= -5e-301) tmp = Float64((Float64(a * -2.0) ^ -0.3333333333333333) * cbrt(Float64(-g))); else tmp = Float64(cbrt(g) * (Float64(a * 2.0) ^ -0.3333333333333333)); end return tmp end
code[g_, a_] := If[LessEqual[N[(a * 2.0), $MachinePrecision], -5e-301], N[(N[Power[N[(a * -2.0), $MachinePrecision], -0.3333333333333333], $MachinePrecision] * N[Power[(-g), 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[N[(a * 2.0), $MachinePrecision], -0.3333333333333333], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot 2 \leq -5 \cdot 10^{-301}:\\
\;\;\;\;{\left(a \cdot -2\right)}^{-0.3333333333333333} \cdot \sqrt[3]{-g}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} \cdot {\left(a \cdot 2\right)}^{-0.3333333333333333}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -5.00000000000000013e-301Initial program 73.9%
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-eval0.0
Applied egg-rr0.0%
Taylor expanded in a around 0
lower-cbrt.f64N/A
lower-/.f6498.8
Simplified98.8%
lift-/.f64N/A
lift-*.f64N/A
cbrt-unprodN/A
pow1/3N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
associate-*l/N/A
unpow-prod-downN/A
Applied egg-rr98.8%
lift-/.f64N/A
lift-cbrt.f64N/A
lift-neg.f64N/A
lift-cbrt.f64N/A
lift-*.f6498.8
lift-cbrt.f64N/A
pow1/3N/A
lift-/.f64N/A
clear-numN/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
div-invN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval91.9
Applied egg-rr91.9%
if -5.00000000000000013e-301 < (*.f64 #s(literal 2 binary64) a) Initial program 79.7%
lift-*.f64N/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.f6492.2
Applied egg-rr92.2%
Final simplification92.1%
(FPCore (g a) :precision binary64 (if (<= (* a 2.0) 2e-299) (/ 1.0 (cbrt (/ a (* g 0.5)))) (* (cbrt g) (pow (* a 2.0) -0.3333333333333333))))
double code(double g, double a) {
double tmp;
if ((a * 2.0) <= 2e-299) {
tmp = 1.0 / cbrt((a / (g * 0.5)));
} else {
tmp = cbrt(g) * pow((a * 2.0), -0.3333333333333333);
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((a * 2.0) <= 2e-299) {
tmp = 1.0 / Math.cbrt((a / (g * 0.5)));
} else {
tmp = Math.cbrt(g) * Math.pow((a * 2.0), -0.3333333333333333);
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(a * 2.0) <= 2e-299) tmp = Float64(1.0 / cbrt(Float64(a / Float64(g * 0.5)))); else tmp = Float64(cbrt(g) * (Float64(a * 2.0) ^ -0.3333333333333333)); end return tmp end
code[g_, a_] := If[LessEqual[N[(a * 2.0), $MachinePrecision], 2e-299], N[(1.0 / N[Power[N[(a / N[(g * 0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[N[(a * 2.0), $MachinePrecision], -0.3333333333333333], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot 2 \leq 2 \cdot 10^{-299}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\frac{a}{g \cdot 0.5}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} \cdot {\left(a \cdot 2\right)}^{-0.3333333333333333}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < 1.99999999999999998e-299Initial program 74.1%
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-eval74.9
Applied egg-rr74.9%
if 1.99999999999999998e-299 < (*.f64 #s(literal 2 binary64) a) Initial program 79.5%
lift-*.f64N/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.f6492.3
Applied egg-rr92.3%
Final simplification82.8%
(FPCore (g a) :precision binary64 (if (<= (* a 2.0) 2e-299) (/ 1.0 (cbrt (/ a (* g 0.5)))) (* (cbrt (* g 0.5)) (pow a -0.3333333333333333))))
double code(double g, double a) {
double tmp;
if ((a * 2.0) <= 2e-299) {
tmp = 1.0 / cbrt((a / (g * 0.5)));
} else {
tmp = cbrt((g * 0.5)) * pow(a, -0.3333333333333333);
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((a * 2.0) <= 2e-299) {
tmp = 1.0 / Math.cbrt((a / (g * 0.5)));
} else {
tmp = Math.cbrt((g * 0.5)) * Math.pow(a, -0.3333333333333333);
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(a * 2.0) <= 2e-299) tmp = Float64(1.0 / cbrt(Float64(a / Float64(g * 0.5)))); else tmp = Float64(cbrt(Float64(g * 0.5)) * (a ^ -0.3333333333333333)); end return tmp end
code[g_, a_] := If[LessEqual[N[(a * 2.0), $MachinePrecision], 2e-299], N[(1.0 / N[Power[N[(a / N[(g * 0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(g * 0.5), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[a, -0.3333333333333333], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \cdot 2 \leq 2 \cdot 10^{-299}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\frac{a}{g \cdot 0.5}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g \cdot 0.5} \cdot {a}^{-0.3333333333333333}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < 1.99999999999999998e-299Initial program 74.1%
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-eval74.9
Applied egg-rr74.9%
if 1.99999999999999998e-299 < (*.f64 #s(literal 2 binary64) a) Initial program 79.5%
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 egg-rr92.2%
Final simplification82.8%
(FPCore (g a) :precision binary64 (* (cbrt (/ 0.5 a)) (cbrt g)))
double code(double g, double a) {
return cbrt((0.5 / a)) * cbrt(g);
}
public static double code(double g, double a) {
return Math.cbrt((0.5 / a)) * Math.cbrt(g);
}
function code(g, a) return Float64(cbrt(Float64(0.5 / a)) * cbrt(g)) end
code[g_, a_] := N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g}
\end{array}
Initial program 76.6%
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-eval42.5
Applied egg-rr42.5%
Taylor expanded in a around 0
lower-cbrt.f64N/A
lower-/.f6498.8
Simplified98.8%
lift-/.f64N/A
lift-*.f64N/A
cbrt-unprodN/A
pow1/3N/A
*-commutativeN/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
associate-*r/N/A
metadata-evalN/A
associate-/r*N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
associate-*l/N/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
associate-*l/N/A
unpow-prod-downN/A
Applied egg-rr98.8%
lift-/.f64N/A
lift-neg.f64N/A
cbrt-unprodN/A
pow1/3N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
associate-/r/N/A
lift-neg.f64N/A
frac-2negN/A
associate-/r/N/A
unpow-prod-downN/A
lower-*.f64N/A
Applied egg-rr98.8%
(FPCore (g a)
:precision binary64
(let* ((t_0 (/ g (* a 2.0))))
(if (<= t_0 -5e-324)
(/ 1.0 (cbrt (/ a (* g 0.5))))
(if (<= t_0 0.0)
(/ (* g 0.5) (cbrt (* a (* (* g 0.5) (* g 0.5)))))
(cbrt (/ (/ 1.0 a) (/ 2.0 g)))))))
double code(double g, double a) {
double t_0 = g / (a * 2.0);
double tmp;
if (t_0 <= -5e-324) {
tmp = 1.0 / cbrt((a / (g * 0.5)));
} else if (t_0 <= 0.0) {
tmp = (g * 0.5) / cbrt((a * ((g * 0.5) * (g * 0.5))));
} else {
tmp = cbrt(((1.0 / a) / (2.0 / g)));
}
return tmp;
}
public static double code(double g, double a) {
double t_0 = g / (a * 2.0);
double tmp;
if (t_0 <= -5e-324) {
tmp = 1.0 / Math.cbrt((a / (g * 0.5)));
} else if (t_0 <= 0.0) {
tmp = (g * 0.5) / Math.cbrt((a * ((g * 0.5) * (g * 0.5))));
} else {
tmp = Math.cbrt(((1.0 / a) / (2.0 / g)));
}
return tmp;
}
function code(g, a) t_0 = Float64(g / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= -5e-324) tmp = Float64(1.0 / cbrt(Float64(a / Float64(g * 0.5)))); elseif (t_0 <= 0.0) tmp = Float64(Float64(g * 0.5) / cbrt(Float64(a * Float64(Float64(g * 0.5) * Float64(g * 0.5))))); else tmp = cbrt(Float64(Float64(1.0 / a) / Float64(2.0 / g))); end return tmp end
code[g_, a_] := Block[{t$95$0 = N[(g / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -5e-324], N[(1.0 / N[Power[N[(a / N[(g * 0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 0.0], N[(N[(g * 0.5), $MachinePrecision] / N[Power[N[(a * N[(N[(g * 0.5), $MachinePrecision] * N[(g * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[Power[N[(N[(1.0 / a), $MachinePrecision] / N[(2.0 / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{g}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq -5 \cdot 10^{-324}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\frac{a}{g \cdot 0.5}}}\\
\mathbf{elif}\;t\_0 \leq 0:\\
\;\;\;\;\frac{g \cdot 0.5}{\sqrt[3]{a \cdot \left(\left(g \cdot 0.5\right) \cdot \left(g \cdot 0.5\right)\right)}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{\frac{1}{a}}{\frac{2}{g}}}\\
\end{array}
\end{array}
if (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -4.94066e-324Initial program 84.2%
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-eval84.4
Applied egg-rr84.4%
if -4.94066e-324 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -0.0Initial program 4.6%
lift-*.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.7
Applied egg-rr98.7%
Applied egg-rr31.7%
if -0.0 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) Initial program 88.3%
associate-/r*N/A
clear-numN/A
associate-/r*N/A
associate-/l/N/A
lower-/.f64N/A
lower-/.f64N/A
lower-/.f6488.4
Applied egg-rr88.4%
Final simplification79.9%
(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.6%
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.7
Applied egg-rr76.7%
(FPCore (g a) :precision binary64 (cbrt (/ g (* a 2.0))))
double code(double g, double a) {
return cbrt((g / (a * 2.0)));
}
public static double code(double g, double a) {
return Math.cbrt((g / (a * 2.0)));
}
function code(g, a) return cbrt(Float64(g / Float64(a * 2.0))) end
code[g_, a_] := N[Power[N[(g / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{a \cdot 2}}
\end{array}
Initial program 76.6%
Final simplification76.6%
(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.6%
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.6
Applied egg-rr76.6%
Final simplification76.6%
herbie shell --seed 2024210
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))