
(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 4 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 (* (/ -1.0 (/ -1.0 (cbrt g))) (cbrt (/ 0.5 a))))
double code(double g, double a) {
return (-1.0 / (-1.0 / cbrt(g))) * cbrt((0.5 / a));
}
public static double code(double g, double a) {
return (-1.0 / (-1.0 / Math.cbrt(g))) * Math.cbrt((0.5 / a));
}
function code(g, a) return Float64(Float64(-1.0 / Float64(-1.0 / cbrt(g))) * cbrt(Float64(0.5 / a))) end
code[g_, a_] := N[(N[(-1.0 / N[(-1.0 / N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\frac{-1}{\sqrt[3]{g}}} \cdot \sqrt[3]{\frac{0.5}{a}}
\end{array}
Initial program 75.0%
Applied rewrites98.6%
Applied rewrites98.7%
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
lower-/.f64N/A
lift-pow.f64N/A
unpow-1N/A
distribute-neg-fracN/A
metadata-evalN/A
lower-/.f6498.7
Applied rewrites98.7%
Final simplification98.7%
(FPCore (g a) :precision binary64 (if (<= (* 2.0 a) -2e-306) (* (cbrt (* -0.5 g)) (pow (- a) -0.3333333333333333)) (cbrt (* g (/ 0.5 a)))))
double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -2e-306) {
tmp = cbrt((-0.5 * g)) * pow(-a, -0.3333333333333333);
} else {
tmp = cbrt((g * (0.5 / a)));
}
return tmp;
}
public static double code(double g, double a) {
double tmp;
if ((2.0 * a) <= -2e-306) {
tmp = Math.cbrt((-0.5 * g)) * Math.pow(-a, -0.3333333333333333);
} else {
tmp = Math.cbrt((g * (0.5 / a)));
}
return tmp;
}
function code(g, a) tmp = 0.0 if (Float64(2.0 * a) <= -2e-306) tmp = Float64(cbrt(Float64(-0.5 * g)) * (Float64(-a) ^ -0.3333333333333333)); else tmp = cbrt(Float64(g * Float64(0.5 / a))); end return tmp end
code[g_, a_] := If[LessEqual[N[(2.0 * a), $MachinePrecision], -2e-306], N[(N[Power[N[(-0.5 * g), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[(-a), -0.3333333333333333], $MachinePrecision]), $MachinePrecision], N[Power[N[(g * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot a \leq -2 \cdot 10^{-306}:\\
\;\;\;\;\sqrt[3]{-0.5 \cdot g} \cdot {\left(-a\right)}^{-0.3333333333333333}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g \cdot \frac{0.5}{a}}\\
\end{array}
\end{array}
if (*.f64 #s(literal 2 binary64) a) < -2.00000000000000006e-306Initial program 78.1%
Applied rewrites98.6%
lift-cbrt.f64N/A
pow1/3N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
lower-neg.f64N/A
metadata-eval92.1
Applied rewrites92.1%
if -2.00000000000000006e-306 < (*.f64 #s(literal 2 binary64) a) Initial program 72.4%
Applied rewrites98.7%
lift-*.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
cbrt-unprodN/A
lift-/.f64N/A
associate-*l/N/A
neg-mul-1N/A
lift-*.f64N/A
distribute-rgt-neg-outN/A
lift-neg.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lift-cbrt.f6472.4
lift-*.f64N/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
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Final simplification81.6%
(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 75.0%
Applied rewrites98.6%
lift-*.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
cbrt-unprodN/A
lift-/.f64N/A
frac-2negN/A
associate-*l/N/A
cbrt-divN/A
metadata-evalN/A
*-lft-identityN/A
lift-*.f64N/A
metadata-evalN/A
associate-*r*N/A
neg-mul-1N/A
lift-neg.f64N/A
cbrt-divN/A
associate-*l/N/A
associate-/r/N/A
lift-neg.f64N/A
frac-2negN/A
associate-/r/N/A
cbrt-prodN/A
lower-*.f64N/A
Applied rewrites98.7%
Final simplification98.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 75.0%
Applied rewrites98.6%
lift-*.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
cbrt-unprodN/A
lift-/.f64N/A
associate-*l/N/A
neg-mul-1N/A
lift-*.f64N/A
distribute-rgt-neg-outN/A
lift-neg.f64N/A
associate-*l/N/A
lift-/.f64N/A
lift-*.f64N/A
lift-cbrt.f6475.0
lift-*.f64N/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
lower-*.f64N/A
lower-/.f6475.0
Applied rewrites75.0%
Final simplification75.0%
herbie shell --seed 2024254
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))