
(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
(if (<= (* h h) 1e+187)
(+
(/ (cbrt (- g)) (cbrt a))
(cbrt (* (* 0.5 (/ (pow h 2.0) g)) (/ -0.5 a))))
(*
h
(+
(cbrt (/ -0.25 (* g (* h a))))
(* (* (cbrt g) (cbrt (/ 1.0 a))) (/ (* (cbrt -0.5) (cbrt 2.0)) h))))))
double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 1e+187) {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(((0.5 * (pow(h, 2.0) / g)) * (-0.5 / a)));
} else {
tmp = h * (cbrt((-0.25 / (g * (h * a)))) + ((cbrt(g) * cbrt((1.0 / a))) * ((cbrt(-0.5) * cbrt(2.0)) / h)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 1e+187) {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((0.5 * (Math.pow(h, 2.0) / g)) * (-0.5 / a)));
} else {
tmp = h * (Math.cbrt((-0.25 / (g * (h * a)))) + ((Math.cbrt(g) * Math.cbrt((1.0 / a))) * ((Math.cbrt(-0.5) * Math.cbrt(2.0)) / h)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (Float64(h * h) <= 1e+187) tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(0.5 * Float64((h ^ 2.0) / g)) * Float64(-0.5 / a)))); else tmp = Float64(h * Float64(cbrt(Float64(-0.25 / Float64(g * Float64(h * a)))) + Float64(Float64(cbrt(g) * cbrt(Float64(1.0 / a))) * Float64(Float64(cbrt(-0.5) * cbrt(2.0)) / h)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 1e+187], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(h * N[(N[Power[N[(-0.25 / N[(g * N[(h * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[N[(1.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 10^{+187}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(0.5 \cdot \frac{{h}^{2}}{g}\right) \cdot \frac{-0.5}{a}}\\
\mathbf{else}:\\
\;\;\;\;h \cdot \left(\sqrt[3]{\frac{-0.25}{g \cdot \left(h \cdot a\right)}} + \left(\sqrt[3]{g} \cdot \sqrt[3]{\frac{1}{a}}\right) \cdot \frac{\sqrt[3]{-0.5} \cdot \sqrt[3]{2}}{h}\right)\\
\end{array}
\end{array}
if (*.f64 h h) < 9.99999999999999907e186Initial program 43.1%
Simplified43.1%
Taylor expanded in g around -inf 27.3%
mul-1-neg27.3%
distribute-neg-frac227.3%
Simplified27.3%
frac-2neg27.3%
cbrt-div32.1%
Applied egg-rr32.1%
remove-double-neg32.1%
Simplified32.1%
Taylor expanded in g around -inf 98.4%
if 9.99999999999999907e186 < (*.f64 h h) Initial program 2.2%
Simplified2.2%
Taylor expanded in h around 0 11.9%
Taylor expanded in h around inf 35.5%
add-cbrt-cube35.5%
pow1/332.5%
pow332.5%
unpow-prod-down32.5%
pow332.5%
add-cube-cbrt32.5%
associate-*r*31.9%
*-commutative31.9%
cbrt-unprod31.9%
metadata-eval31.9%
Applied egg-rr31.9%
unpow1/335.5%
associate-*l/35.5%
rem-cube-cbrt35.5%
metadata-eval35.5%
associate-*l*35.5%
Simplified35.5%
pow1/316.3%
div-inv16.3%
unpow-prod-down31.1%
pow1/339.9%
Applied egg-rr39.9%
unpow1/394.5%
Simplified94.5%
Final simplification97.9%
(FPCore (g h a)
:precision binary64
(if (<= h 3.8e+117)
(+
(/ (cbrt (- g)) (cbrt a))
(cbrt (* (* 0.5 (/ (pow h 2.0) g)) (/ -0.5 a))))
(*
h
(+
(cbrt (/ -0.25 (* g (* h a))))
(* (/ (* (cbrt -0.5) (cbrt 2.0)) h) (/ (cbrt g) (cbrt a)))))))
double code(double g, double h, double a) {
double tmp;
if (h <= 3.8e+117) {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(((0.5 * (pow(h, 2.0) / g)) * (-0.5 / a)));
} else {
tmp = h * (cbrt((-0.25 / (g * (h * a)))) + (((cbrt(-0.5) * cbrt(2.0)) / h) * (cbrt(g) / cbrt(a))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (h <= 3.8e+117) {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((0.5 * (Math.pow(h, 2.0) / g)) * (-0.5 / a)));
} else {
tmp = h * (Math.cbrt((-0.25 / (g * (h * a)))) + (((Math.cbrt(-0.5) * Math.cbrt(2.0)) / h) * (Math.cbrt(g) / Math.cbrt(a))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (h <= 3.8e+117) tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(0.5 * Float64((h ^ 2.0) / g)) * Float64(-0.5 / a)))); else tmp = Float64(h * Float64(cbrt(Float64(-0.25 / Float64(g * Float64(h * a)))) + Float64(Float64(Float64(cbrt(-0.5) * cbrt(2.0)) / h) * Float64(cbrt(g) / cbrt(a))))); end return tmp end
code[g_, h_, a_] := If[LessEqual[h, 3.8e+117], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(h * N[(N[Power[N[(-0.25 / N[(g * N[(h * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] / h), $MachinePrecision] * N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \leq 3.8 \cdot 10^{+117}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(0.5 \cdot \frac{{h}^{2}}{g}\right) \cdot \frac{-0.5}{a}}\\
\mathbf{else}:\\
\;\;\;\;h \cdot \left(\sqrt[3]{\frac{-0.25}{g \cdot \left(h \cdot a\right)}} + \frac{\sqrt[3]{-0.5} \cdot \sqrt[3]{2}}{h} \cdot \frac{\sqrt[3]{g}}{\sqrt[3]{a}}\right)\\
\end{array}
\end{array}
if h < 3.8000000000000002e117Initial program 40.1%
Simplified40.1%
Taylor expanded in g around -inf 25.4%
mul-1-neg25.4%
distribute-neg-frac225.4%
Simplified25.4%
frac-2neg25.4%
cbrt-div29.9%
Applied egg-rr29.9%
remove-double-neg29.9%
Simplified29.9%
Taylor expanded in g around -inf 94.9%
if 3.8000000000000002e117 < h Initial program 0.3%
Simplified0.3%
Taylor expanded in h around 0 8.9%
Taylor expanded in h around inf 47.7%
add-cbrt-cube47.7%
pow1/347.3%
pow347.3%
unpow-prod-down47.3%
pow347.3%
add-cube-cbrt47.3%
associate-*r*47.0%
*-commutative47.0%
cbrt-unprod47.0%
metadata-eval47.0%
Applied egg-rr47.0%
unpow1/347.7%
associate-*l/47.7%
rem-cube-cbrt47.7%
metadata-eval47.7%
associate-*l*47.7%
Simplified47.7%
cbrt-div96.8%
Applied egg-rr96.8%
Final simplification95.0%
(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(Float64(-g)) / 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 37.8%
Simplified37.8%
Taylor expanded in g around -inf 24.0%
mul-1-neg24.0%
distribute-neg-frac224.0%
Simplified24.0%
frac-2neg24.0%
cbrt-div28.2%
Applied egg-rr28.2%
remove-double-neg28.2%
Simplified28.2%
Taylor expanded in g around -inf 96.0%
neg-mul-196.0%
Simplified96.0%
Taylor expanded in g around 0 96.0%
Final simplification96.0%
(FPCore (g h a) :precision binary64 (* (cbrt (/ g a)) -2.0))
double code(double g, double h, double a) {
return cbrt((g / a)) * -2.0;
}
public static double code(double g, double h, double a) {
return Math.cbrt((g / a)) * -2.0;
}
function code(g, h, a) return Float64(cbrt(Float64(g / a)) * -2.0) end
code[g_, h_, a_] := N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{a}} \cdot -2
\end{array}
Initial program 37.8%
Simplified37.8%
Taylor expanded in g around -inf 24.0%
mul-1-neg24.0%
distribute-neg-frac224.0%
Simplified24.0%
Taylor expanded in g around inf 14.6%
Taylor expanded in g around -inf 14.6%
*-commutative14.6%
Simplified14.6%
(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 37.8%
Simplified37.8%
Taylor expanded in g around -inf 24.0%
mul-1-neg24.0%
distribute-neg-frac224.0%
Simplified24.0%
frac-2neg24.0%
cbrt-div28.2%
Applied egg-rr28.2%
remove-double-neg28.2%
Simplified28.2%
Taylor expanded in g around -inf 96.0%
neg-mul-196.0%
Simplified96.0%
*-un-lft-identity96.0%
+-commutative96.0%
unsub-neg96.0%
cbrt-undiv69.8%
Applied egg-rr69.8%
*-lft-identity69.8%
+-commutative69.8%
distribute-frac-neg69.8%
distribute-neg-frac269.8%
+-inverses69.8%
mul0-lft69.8%
metadata-eval69.8%
+-inverses69.8%
rem-cbrt-cube69.8%
+-inverses69.8%
Simplified69.8%
Final simplification69.8%
herbie shell --seed 2024114
(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))))))))