
(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 7 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 0.5)) (cbrt a)))
double code(double g, double a) {
return cbrt((g * 0.5)) / cbrt(a);
}
public static double code(double g, double a) {
return Math.cbrt((g * 0.5)) / Math.cbrt(a);
}
function code(g, a) return Float64(cbrt(Float64(g * 0.5)) / cbrt(a)) end
code[g_, a_] := N[(N[Power[N[(g * 0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g \cdot 0.5}}{\sqrt[3]{a}}
\end{array}
Initial program 75.6%
lift-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
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%
(FPCore (g a) :precision binary64 (if (<= (* a 2.0) 2e-303) (/ 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-303) {
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-303) {
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-303) 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-303], 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^{-303}:\\
\;\;\;\;\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.99999999999999986e-303Initial program 72.8%
lift-cbrt.f64N/A
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-eval73.9
Applied rewrites73.9%
if 1.99999999999999986e-303 < (*.f64 #s(literal 2 binary64) a) Initial program 78.2%
lift-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
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%
Final simplification83.3%
(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 75.6%
lift-cbrt.f64N/A
lift-/.f64N/A
cbrt-divN/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.7
Applied rewrites98.7%
Final simplification98.7%
(FPCore (g a)
:precision binary64
(let* ((t_0 (/ g (* a 2.0))) (t_1 (/ 1.0 (cbrt (/ a (* g 0.5))))))
(if (<= t_0 -1e-282)
t_1
(if (<= t_0 5e-318)
(/ (* g 0.5) (cbrt (* a (* (* g 0.5) (* g 0.5)))))
t_1))))
double code(double g, double a) {
double t_0 = g / (a * 2.0);
double t_1 = 1.0 / cbrt((a / (g * 0.5)));
double tmp;
if (t_0 <= -1e-282) {
tmp = t_1;
} else if (t_0 <= 5e-318) {
tmp = (g * 0.5) / cbrt((a * ((g * 0.5) * (g * 0.5))));
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double g, double a) {
double t_0 = g / (a * 2.0);
double t_1 = 1.0 / Math.cbrt((a / (g * 0.5)));
double tmp;
if (t_0 <= -1e-282) {
tmp = t_1;
} else if (t_0 <= 5e-318) {
tmp = (g * 0.5) / Math.cbrt((a * ((g * 0.5) * (g * 0.5))));
} else {
tmp = t_1;
}
return tmp;
}
function code(g, a) t_0 = Float64(g / Float64(a * 2.0)) t_1 = Float64(1.0 / cbrt(Float64(a / Float64(g * 0.5)))) tmp = 0.0 if (t_0 <= -1e-282) tmp = t_1; elseif (t_0 <= 5e-318) tmp = Float64(Float64(g * 0.5) / cbrt(Float64(a * Float64(Float64(g * 0.5) * Float64(g * 0.5))))); 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[(1.0 / N[Power[N[(a / N[(g * 0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -1e-282], t$95$1, If[LessEqual[t$95$0, 5e-318], 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], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{g}{a \cdot 2}\\
t_1 := \frac{1}{\sqrt[3]{\frac{a}{g \cdot 0.5}}}\\
\mathbf{if}\;t\_0 \leq -1 \cdot 10^{-282}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{-318}:\\
\;\;\;\;\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}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (/.f64 g (*.f64 #s(literal 2 binary64) a)) < -1e-282 or 4.9999987e-318 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) Initial program 85.4%
lift-cbrt.f64N/A
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-eval86.7
Applied rewrites86.7%
if -1e-282 < (/.f64 g (*.f64 #s(literal 2 binary64) a)) < 4.9999987e-318Initial program 11.6%
lift-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
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.5
Applied rewrites98.5%
Applied rewrites42.0%
Final simplification80.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 75.6%
lift-cbrt.f64N/A
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.5
Applied rewrites76.5%
(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 75.6%
Final simplification75.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 75.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-eval75.6
Applied rewrites75.6%
Final simplification75.6%
herbie shell --seed 2024238
(FPCore (g a)
:name "2-ancestry mixing, zero discriminant"
:precision binary64
(cbrt (/ g (* 2.0 a))))