
(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}
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 (/ (cbrt (* 0.5 g)) (cbrt a)))
double code(double g, double a) {
return cbrt((0.5 * g)) / cbrt(a);
}
public static double code(double g, double a) {
return Math.cbrt((0.5 * g)) / Math.cbrt(a);
}
function code(g, a) return Float64(cbrt(Float64(0.5 * g)) / cbrt(a)) end
code[g_, a_] := N[(N[Power[N[(0.5 * g), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{0.5 \cdot g}}{\sqrt[3]{a}}
\end{array}
Initial program 76.9%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-/r*N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6498.7
Applied rewrites98.7%
Taylor expanded in g around 0
lower-*.f6498.7
Applied rewrites98.7%
(FPCore (g a) :precision binary64 (/ (cbrt g) (cbrt (+ a a))))
double code(double g, double a) {
return cbrt(g) / cbrt((a + a));
}
public static double code(double g, double a) {
return Math.cbrt(g) / Math.cbrt((a + a));
}
function code(g, a) return Float64(cbrt(g) / cbrt(Float64(a + a))) end
code[g_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[N[(a + a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g}}{\sqrt[3]{a + a}}
\end{array}
Initial program 76.9%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
count-2-revN/A
lower-+.f6498.7
Applied rewrites98.7%
(FPCore (g a)
:precision binary64
(let* ((t_0
(exp
(* (+ (- (log (/ -1.0 g))) (log (/ -0.5 a))) 0.3333333333333333)))
(t_1 (cbrt (/ g (* 2.0 a))))
(t_2 (cbrt (/ g (+ a a)))))
(if (<= t_1 -1e-106)
t_2
(if (<= t_1 0.0) t_0 (if (<= t_1 1e+97) t_2 t_0)))))
double code(double g, double a) {
double t_0 = exp(((-log((-1.0 / g)) + log((-0.5 / a))) * 0.3333333333333333));
double t_1 = cbrt((g / (2.0 * a)));
double t_2 = cbrt((g / (a + a)));
double tmp;
if (t_1 <= -1e-106) {
tmp = t_2;
} else if (t_1 <= 0.0) {
tmp = t_0;
} else if (t_1 <= 1e+97) {
tmp = t_2;
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double g, double a) {
double t_0 = Math.exp(((-Math.log((-1.0 / g)) + Math.log((-0.5 / a))) * 0.3333333333333333));
double t_1 = Math.cbrt((g / (2.0 * a)));
double t_2 = Math.cbrt((g / (a + a)));
double tmp;
if (t_1 <= -1e-106) {
tmp = t_2;
} else if (t_1 <= 0.0) {
tmp = t_0;
} else if (t_1 <= 1e+97) {
tmp = t_2;
} else {
tmp = t_0;
}
return tmp;
}
function code(g, a) t_0 = exp(Float64(Float64(Float64(-log(Float64(-1.0 / g))) + log(Float64(-0.5 / a))) * 0.3333333333333333)) t_1 = cbrt(Float64(g / Float64(2.0 * a))) t_2 = cbrt(Float64(g / Float64(a + a))) tmp = 0.0 if (t_1 <= -1e-106) tmp = t_2; elseif (t_1 <= 0.0) tmp = t_0; elseif (t_1 <= 1e+97) tmp = t_2; else tmp = t_0; end return tmp end
code[g_, a_] := Block[{t$95$0 = N[Exp[N[(N[((-N[Log[N[(-1.0 / g), $MachinePrecision]], $MachinePrecision]) + N[Log[N[(-0.5 / a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(g / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(g / N[(a + a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[t$95$1, -1e-106], t$95$2, If[LessEqual[t$95$1, 0.0], t$95$0, If[LessEqual[t$95$1, 1e+97], t$95$2, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\left(\left(-\log \left(\frac{-1}{g}\right)\right) + \log \left(\frac{-0.5}{a}\right)\right) \cdot 0.3333333333333333}\\
t_1 := \sqrt[3]{\frac{g}{2 \cdot a}}\\
t_2 := \sqrt[3]{\frac{g}{a + a}}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-106}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq 10^{+97}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) < -9.99999999999999941e-107 or -0.0 < (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) < 1.0000000000000001e97Initial program 76.9%
lift-*.f64N/A
count-2-revN/A
lower-+.f6476.9
Applied rewrites76.9%
if -9.99999999999999941e-107 < (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) < -0.0 or 1.0000000000000001e97 < (cbrt.f64 (/.f64 g (*.f64 #s(literal 2 binary64) a))) Initial program 76.9%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
pow1/3N/A
pow-to-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-log.f64N/A
lift-/.f64N/A
count-2-revN/A
lower-+.f6436.5
Applied rewrites36.5%
Taylor expanded in g around -inf
+-commutativeN/A
lower-+.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower-log.f64N/A
lower-/.f64N/A
lower-log.f64N/A
lower-/.f6422.3
Applied rewrites22.3%
(FPCore (g a) :precision binary64 (cbrt (/ g (+ a a))))
double code(double g, double a) {
return cbrt((g / (a + a)));
}
public static double code(double g, double a) {
return Math.cbrt((g / (a + a)));
}
function code(g, a) return cbrt(Float64(g / Float64(a + a))) end
code[g_, a_] := N[Power[N[(g / N[(a + a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{a + a}}
\end{array}
Initial program 76.9%
lift-*.f64N/A
count-2-revN/A
lower-+.f6476.9
Applied rewrites76.9%
herbie shell --seed 2025134
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))