
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1)))) end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1)))) end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)}
\end{array}
\end{array}
(FPCore (g h a) :precision binary64 (* (/ -1.0 (cbrt a)) (cbrt g)))
double code(double g, double h, double a) {
return (-1.0 / cbrt(a)) * cbrt(g);
}
public static double code(double g, double h, double a) {
return (-1.0 / Math.cbrt(a)) * Math.cbrt(g);
}
function code(g, h, a) return Float64(Float64(-1.0 / cbrt(a)) * cbrt(g)) end
code[g_, h_, a_] := N[(N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\sqrt[3]{a}} \cdot \sqrt[3]{g}
\end{array}
Initial program 46.3%
Simplified46.3%
Taylor expanded in g around inf 75.9%
pow1/338.4%
div-inv38.4%
unpow-prod-down23.0%
pow1/346.1%
Applied egg-rr46.1%
unpow1/395.6%
Simplified95.6%
Applied egg-rr96.1%
associate-/r/96.1%
Simplified96.1%
(FPCore (g h a) :precision binary64 (/ (cbrt g) (- (cbrt a))))
double code(double g, double h, double a) {
return cbrt(g) / -cbrt(a);
}
public static double code(double g, double h, double a) {
return Math.cbrt(g) / -Math.cbrt(a);
}
function code(g, h, a) return Float64(cbrt(g) / Float64(-cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] / (-N[Power[a, 1/3], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{g}}{-\sqrt[3]{a}}
\end{array}
Initial program 46.3%
Simplified46.3%
Taylor expanded in g around inf 75.9%
pow1/338.4%
div-inv38.4%
unpow-prod-down23.0%
pow1/346.1%
Applied egg-rr46.1%
unpow1/395.6%
Simplified95.6%
Applied egg-rr96.1%
associate-/r/96.1%
associate-*l/96.1%
neg-mul-196.1%
distribute-frac-neg96.1%
distribute-frac-neg296.1%
Simplified96.1%
(FPCore (g h a) :precision binary64 (if (<= a -1e-310) (cbrt g) (- (cbrt g))))
double code(double g, double h, double a) {
double tmp;
if (a <= -1e-310) {
tmp = cbrt(g);
} else {
tmp = -cbrt(g);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (a <= -1e-310) {
tmp = Math.cbrt(g);
} else {
tmp = -Math.cbrt(g);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (a <= -1e-310) tmp = cbrt(g); else tmp = Float64(-cbrt(g)); end return tmp end
code[g_, h_, a_] := If[LessEqual[a, -1e-310], N[Power[g, 1/3], $MachinePrecision], (-N[Power[g, 1/3], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\sqrt[3]{g}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt[3]{g}\\
\end{array}
\end{array}
if a < -9.999999999999969e-311Initial program 43.7%
Simplified43.7%
Taylor expanded in g around inf 76.6%
pow176.6%
cbrt-unprod77.3%
cbrt-unprod77.3%
metadata-eval77.3%
Applied egg-rr77.3%
unpow177.3%
*-commutative77.3%
neg-mul-177.3%
distribute-neg-frac277.3%
Simplified77.3%
Applied egg-rr0.0%
associate-*r/0.0%
*-commutative0.0%
associate-/l*0.0%
*-inverses8.0%
Simplified8.0%
Taylor expanded in g around 0 8.0%
if -9.999999999999969e-311 < a Initial program 48.9%
Simplified48.9%
Taylor expanded in g around inf 75.2%
pow175.2%
cbrt-unprod75.7%
cbrt-unprod75.7%
metadata-eval75.7%
Applied egg-rr75.7%
unpow175.7%
*-commutative75.7%
neg-mul-175.7%
distribute-neg-frac275.7%
Simplified75.7%
Applied egg-rr1.4%
associate-*r/1.4%
*-commutative1.4%
associate-/l*1.4%
*-inverses1.4%
Simplified1.4%
Applied egg-rr7.7%
neg-sub07.7%
Simplified7.7%
(FPCore (g h a) :precision binary64 (cbrt (/ g (- a))))
double code(double g, double h, double a) {
return cbrt((g / -a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((g / -a));
}
function code(g, h, a) return cbrt(Float64(g / Float64(-a))) end
code[g_, h_, a_] := N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{-a}}
\end{array}
Initial program 46.3%
Simplified46.3%
Taylor expanded in g around inf 75.9%
pow175.9%
cbrt-unprod76.5%
cbrt-unprod76.5%
metadata-eval76.5%
Applied egg-rr76.5%
unpow176.5%
*-commutative76.5%
neg-mul-176.5%
distribute-neg-frac276.5%
Simplified76.5%
(FPCore (g h a) :precision binary64 (cbrt g))
double code(double g, double h, double a) {
return cbrt(g);
}
public static double code(double g, double h, double a) {
return Math.cbrt(g);
}
function code(g, h, a) return cbrt(g) end
code[g_, h_, a_] := N[Power[g, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g}
\end{array}
Initial program 46.3%
Simplified46.3%
Taylor expanded in g around inf 75.9%
pow175.9%
cbrt-unprod76.5%
cbrt-unprod76.5%
metadata-eval76.5%
Applied egg-rr76.5%
unpow176.5%
*-commutative76.5%
neg-mul-176.5%
distribute-neg-frac276.5%
Simplified76.5%
Applied egg-rr0.7%
associate-*r/0.7%
*-commutative0.7%
associate-/l*0.7%
*-inverses4.6%
Simplified4.6%
Taylor expanded in g around 0 4.6%
herbie shell --seed 2024146
(FPCore (g h a)
:name "2-ancestry mixing, positive discriminant"
:precision binary64
(+ (cbrt (* (/ 1.0 (* 2.0 a)) (+ (- g) (sqrt (- (* g g) (* h h)))))) (cbrt (* (/ 1.0 (* 2.0 a)) (- (- g) (sqrt (- (* g g) (* h h))))))))