
(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 5 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 (/ 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.4%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.5
Applied egg-rr98.5%
*-commutativeN/A
associate-/l*N/A
div-invN/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
pow-prod-downN/A
metadata-evalN/A
associate-/r/N/A
metadata-evalN/A
pow-powN/A
inv-powN/A
associate-/r/N/A
metadata-evalN/A
div-invN/A
pow1/3N/A
cbrt-divN/A
unpow1/3N/A
frac-2negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
Applied egg-rr98.4%
sub0-negN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
cbrt-undivN/A
clear-numN/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
+-rgt-identityN/A
cbrt-lowering-cbrt.f64N/A
+-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
/-lowering-/.f6498.7
Applied egg-rr98.7%
sub0-negN/A
neg-lowering-neg.f64N/A
cbrt-lowering-cbrt.f6498.7
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (g a)
:precision binary64
(let* ((t_0 (/ g (* a 2.0)))
(t_1 (fma g (* 0.25 (* g a)) 0.0))
(t_2 (/ (fma g 0.5 0.0) (cbrt t_1))))
(if (<= t_0 (- INFINITY))
(* (fma g 0.5 0.0) (/ 1.0 (/ 1.0 (cbrt (/ 1.0 t_1)))))
(if (<= t_0 -4e-318)
(cbrt (* g (/ 0.5 a)))
(if (<= t_0 2e-309)
t_2
(if (<= t_0 4e+307) (/ 1.0 (cbrt (/ a (fma g 0.5 0.0)))) t_2))))))
double code(double g, double a) {
double t_0 = g / (a * 2.0);
double t_1 = fma(g, (0.25 * (g * a)), 0.0);
double t_2 = fma(g, 0.5, 0.0) / cbrt(t_1);
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = fma(g, 0.5, 0.0) * (1.0 / (1.0 / cbrt((1.0 / t_1))));
} else if (t_0 <= -4e-318) {
tmp = cbrt((g * (0.5 / a)));
} else if (t_0 <= 2e-309) {
tmp = t_2;
} else if (t_0 <= 4e+307) {
tmp = 1.0 / cbrt((a / fma(g, 0.5, 0.0)));
} else {
tmp = t_2;
}
return tmp;
}
function code(g, a) t_0 = Float64(g / Float64(a * 2.0)) t_1 = fma(g, Float64(0.25 * Float64(g * a)), 0.0) t_2 = Float64(fma(g, 0.5, 0.0) / cbrt(t_1)) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = Float64(fma(g, 0.5, 0.0) * Float64(1.0 / Float64(1.0 / cbrt(Float64(1.0 / t_1))))); elseif (t_0 <= -4e-318) tmp = cbrt(Float64(g * Float64(0.5 / a))); elseif (t_0 <= 2e-309) tmp = t_2; elseif (t_0 <= 4e+307) tmp = Float64(1.0 / cbrt(Float64(a / fma(g, 0.5, 0.0)))); else tmp = t_2; end return tmp end
code[g_, a_] := Block[{t$95$0 = N[(g / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(g * N[(0.25 * N[(g * a), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(g * 0.5 + 0.0), $MachinePrecision] / N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], N[(N[(g * 0.5 + 0.0), $MachinePrecision] * N[(1.0 / N[(1.0 / N[Power[N[(1.0 / t$95$1), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -4e-318], N[Power[N[(g * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], If[LessEqual[t$95$0, 2e-309], t$95$2, If[LessEqual[t$95$0, 4e+307], N[(1.0 / N[Power[N[(a / N[(g * 0.5 + 0.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{g}{a \cdot 2}\\
t_1 := \mathsf{fma}\left(g, 0.25 \cdot \left(g \cdot a\right), 0\right)\\
t_2 := \frac{\mathsf{fma}\left(g, 0.5, 0\right)}{\sqrt[3]{t\_1}}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(g, 0.5, 0\right) \cdot \frac{1}{\frac{1}{\sqrt[3]{\frac{1}{t\_1}}}}\\
\mathbf{elif}\;t\_0 \leq -4 \cdot 10^{-318}:\\
\;\;\;\;\sqrt[3]{g \cdot \frac{0.5}{a}}\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-309}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+307}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\frac{a}{\mathsf{fma}\left(g, 0.5, 0\right)}}}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -inf.0Initial program 4.6%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6497.8
Applied egg-rr97.8%
Applied egg-rr19.1%
+-rgt-identityN/A
*-commutativeN/A
associate-*r*N/A
associate-*l*N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6464.6
Applied egg-rr64.6%
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
associate-*l*N/A
+-rgt-identityN/A
+-rgt-identityN/A
flip-+N/A
clear-numN/A
cbrt-divN/A
metadata-evalN/A
--rgt-identityN/A
Applied egg-rr65.0%
if -inf.0 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -3.9999999e-318Initial program 98.7%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
associate-/r*N/A
/-lowering-/.f64N/A
metadata-eval98.7
Applied egg-rr98.7%
if -3.9999999e-318 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < 1.9999999999999988e-309 or 3.99999999999999994e307 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) Initial program 6.5%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.4
Applied egg-rr98.4%
*-commutativeN/A
associate-/l*N/A
div-invN/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
pow-prod-downN/A
metadata-evalN/A
associate-/r/N/A
metadata-evalN/A
pow-powN/A
inv-powN/A
associate-/r/N/A
metadata-evalN/A
div-invN/A
pow1/3N/A
cbrt-divN/A
unpow1/3N/A
frac-2negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
Applied egg-rr98.2%
sub0-negN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
cbrt-undivN/A
clear-numN/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
+-rgt-identityN/A
cbrt-lowering-cbrt.f64N/A
+-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
/-lowering-/.f6498.4
Applied egg-rr98.4%
Applied egg-rr71.8%
if 1.9999999999999988e-309 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < 3.99999999999999994e307Initial program 99.0%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.6
Applied egg-rr98.6%
Applied egg-rr92.6%
Applied egg-rr99.2%
Final simplification91.9%
(FPCore (g a)
:precision binary64
(let* ((t_0 (/ g (* a 2.0)))
(t_1 (/ (fma g 0.5 0.0) (cbrt (fma g (* 0.25 (* g a)) 0.0)))))
(if (<= t_0 (- INFINITY))
t_1
(if (<= t_0 -4e-318)
(cbrt (* g (/ 0.5 a)))
(if (<= t_0 2e-309)
t_1
(if (<= t_0 4e+307) (/ 1.0 (cbrt (/ a (fma g 0.5 0.0)))) t_1))))))
double code(double g, double a) {
double t_0 = g / (a * 2.0);
double t_1 = fma(g, 0.5, 0.0) / cbrt(fma(g, (0.25 * (g * a)), 0.0));
double tmp;
if (t_0 <= -((double) INFINITY)) {
tmp = t_1;
} else if (t_0 <= -4e-318) {
tmp = cbrt((g * (0.5 / a)));
} else if (t_0 <= 2e-309) {
tmp = t_1;
} else if (t_0 <= 4e+307) {
tmp = 1.0 / cbrt((a / fma(g, 0.5, 0.0)));
} else {
tmp = t_1;
}
return tmp;
}
function code(g, a) t_0 = Float64(g / Float64(a * 2.0)) t_1 = Float64(fma(g, 0.5, 0.0) / cbrt(fma(g, Float64(0.25 * Float64(g * a)), 0.0))) tmp = 0.0 if (t_0 <= Float64(-Inf)) tmp = t_1; elseif (t_0 <= -4e-318) tmp = cbrt(Float64(g * Float64(0.5 / a))); elseif (t_0 <= 2e-309) tmp = t_1; elseif (t_0 <= 4e+307) tmp = Float64(1.0 / cbrt(Float64(a / fma(g, 0.5, 0.0)))); else tmp = t_1; end return tmp end
code[g_, a_] := Block[{t$95$0 = N[(g / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(g * 0.5 + 0.0), $MachinePrecision] / N[Power[N[(g * N[(0.25 * N[(g * a), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, (-Infinity)], t$95$1, If[LessEqual[t$95$0, -4e-318], N[Power[N[(g * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], If[LessEqual[t$95$0, 2e-309], t$95$1, If[LessEqual[t$95$0, 4e+307], N[(1.0 / N[Power[N[(a / N[(g * 0.5 + 0.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{g}{a \cdot 2}\\
t_1 := \frac{\mathsf{fma}\left(g, 0.5, 0\right)}{\sqrt[3]{\mathsf{fma}\left(g, 0.25 \cdot \left(g \cdot a\right), 0\right)}}\\
\mathbf{if}\;t\_0 \leq -\infty:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq -4 \cdot 10^{-318}:\\
\;\;\;\;\sqrt[3]{g \cdot \frac{0.5}{a}}\\
\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{-309}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 4 \cdot 10^{+307}:\\
\;\;\;\;\frac{1}{\sqrt[3]{\frac{a}{\mathsf{fma}\left(g, 0.5, 0\right)}}}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -inf.0 or -3.9999999e-318 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < 1.9999999999999988e-309 or 3.99999999999999994e307 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) Initial program 6.0%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.2
Applied egg-rr98.2%
*-commutativeN/A
associate-/l*N/A
div-invN/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
pow-prod-downN/A
metadata-evalN/A
associate-/r/N/A
metadata-evalN/A
pow-powN/A
inv-powN/A
associate-/r/N/A
metadata-evalN/A
div-invN/A
pow1/3N/A
cbrt-divN/A
unpow1/3N/A
frac-2negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
Applied egg-rr98.1%
sub0-negN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
cbrt-undivN/A
clear-numN/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
+-rgt-identityN/A
cbrt-lowering-cbrt.f64N/A
+-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
/-lowering-/.f6498.5
Applied egg-rr98.5%
Applied egg-rr69.9%
if -inf.0 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -3.9999999e-318Initial program 98.7%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
associate-/r*N/A
/-lowering-/.f64N/A
metadata-eval98.7
Applied egg-rr98.7%
if 1.9999999999999988e-309 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < 3.99999999999999994e307Initial program 99.0%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.6
Applied egg-rr98.6%
Applied egg-rr92.6%
Applied egg-rr99.2%
Final simplification91.9%
(FPCore (g a) :precision binary64 (/ (cbrt g) (cbrt (* a 2.0))))
double code(double g, double a) {
return cbrt(g) / cbrt((a * 2.0));
}
public static double code(double g, double a) {
return Math.cbrt(g) / Math.cbrt((a * 2.0));
}
function code(g, a) return Float64(cbrt(g) / cbrt(Float64(a * 2.0))) end
code[g_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[N[(a * 2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g}}{\sqrt[3]{a \cdot 2}}
\end{array}
Initial program 76.4%
clear-numN/A
associate-/r/N/A
cbrt-prodN/A
cbrt-divN/A
metadata-evalN/A
cbrt-prodN/A
associate-/r*N/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
metadata-evalN/A
associate-*l/N/A
/-lowering-/.f64N/A
*-lowering-*.f64N/A
pow-lowering-pow.f64N/A
metadata-evalN/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f6498.5
Applied egg-rr98.5%
*-commutativeN/A
associate-/l*N/A
div-invN/A
pow1/3N/A
pow-flipN/A
metadata-evalN/A
pow-prod-downN/A
metadata-evalN/A
associate-/r/N/A
metadata-evalN/A
pow-powN/A
inv-powN/A
associate-/r/N/A
metadata-evalN/A
div-invN/A
pow1/3N/A
cbrt-divN/A
unpow1/3N/A
frac-2negN/A
associate-/l*N/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
Applied egg-rr98.4%
sub0-negN/A
distribute-frac-neg2N/A
neg-lowering-neg.f64N/A
cbrt-undivN/A
clear-numN/A
div-invN/A
metadata-evalN/A
*-commutativeN/A
+-rgt-identityN/A
cbrt-lowering-cbrt.f64N/A
+-rgt-identityN/A
*-commutativeN/A
metadata-evalN/A
div-invN/A
clear-numN/A
/-lowering-/.f6498.7
Applied egg-rr98.7%
distribute-rgt-neg-outN/A
distribute-lft-neg-inN/A
clear-numN/A
cbrt-divN/A
metadata-evalN/A
un-div-invN/A
sub0-negN/A
remove-double-negN/A
/-lowering-/.f64N/A
cbrt-lowering-cbrt.f64N/A
cbrt-lowering-cbrt.f64N/A
div-invN/A
metadata-evalN/A
*-lowering-*.f6498.7
Applied egg-rr98.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.4%
clear-numN/A
associate-/r/N/A
*-lowering-*.f64N/A
associate-/r*N/A
/-lowering-/.f64N/A
metadata-eval76.4
Applied egg-rr76.4%
Final simplification76.4%
herbie shell --seed 2024197
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))