
(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+295)
(+
(cbrt (* (/ 0.5 a) (* -0.5 (/ (pow h 2.0) g))))
(/ (cbrt (* -0.5 (+ g g))) (cbrt a)))
(+
(cbrt (* (/ 0.5 a) (- g g)))
(* (/ 1.0 (/ (cbrt a) (cbrt g))) (* (cbrt -0.5) (cbrt 2.0))))))
double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 1e+295) {
tmp = cbrt(((0.5 / a) * (-0.5 * (pow(h, 2.0) / g)))) + (cbrt((-0.5 * (g + g))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (g - g))) + ((1.0 / (cbrt(a) / cbrt(g))) * (cbrt(-0.5) * cbrt(2.0)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 1e+295) {
tmp = Math.cbrt(((0.5 / a) * (-0.5 * (Math.pow(h, 2.0) / g)))) + (Math.cbrt((-0.5 * (g + g))) / Math.cbrt(a));
} else {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + ((1.0 / (Math.cbrt(a) / Math.cbrt(g))) * (Math.cbrt(-0.5) * Math.cbrt(2.0)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (Float64(h * h) <= 1e+295) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(-0.5 * Float64((h ^ 2.0) / g)))) + Float64(cbrt(Float64(-0.5 * Float64(g + g))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(Float64(1.0 / Float64(cbrt(a) / cbrt(g))) * Float64(cbrt(-0.5) * cbrt(2.0)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 1e+295], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(1.0 / N[(N[Power[a, 1/3], $MachinePrecision] / N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 10^{+295}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(-0.5 \cdot \frac{{h}^{2}}{g}\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + g\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \frac{1}{\frac{\sqrt[3]{a}}{\sqrt[3]{g}}} \cdot \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right)\\
\end{array}
\end{array}
if (*.f64 h h) < 9.9999999999999998e294Initial program 48.3%
Simplified48.3%
associate-*r/48.3%
cbrt-div53.1%
pow253.1%
pow253.1%
Applied egg-rr53.1%
Taylor expanded in g around inf 33.3%
Taylor expanded in g around inf 97.4%
if 9.9999999999999998e294 < (*.f64 h h) Initial program 0.0%
Simplified0.0%
Taylor expanded in g around inf 0.0%
Taylor expanded in h around 0 29.1%
unpow1/345.8%
*-lft-identity45.8%
Simplified45.8%
cbrt-div82.8%
clear-num82.8%
Applied egg-rr82.8%
Final simplification96.4%
(FPCore (g h a)
:precision binary64
(if (<= h 1.1e+150)
(+
(cbrt (* (/ 0.5 a) (* -0.5 (/ (pow h 2.0) g))))
(/ (cbrt (* -0.5 (+ g g))) (cbrt a)))
(+
(cbrt (* (/ 0.5 a) (- g g)))
(* (* (cbrt -0.5) (cbrt 2.0)) (/ (cbrt g) (cbrt a))))))
double code(double g, double h, double a) {
double tmp;
if (h <= 1.1e+150) {
tmp = cbrt(((0.5 / a) * (-0.5 * (pow(h, 2.0) / g)))) + (cbrt((-0.5 * (g + g))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (g - g))) + ((cbrt(-0.5) * cbrt(2.0)) * (cbrt(g) / cbrt(a)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (h <= 1.1e+150) {
tmp = Math.cbrt(((0.5 / a) * (-0.5 * (Math.pow(h, 2.0) / g)))) + (Math.cbrt((-0.5 * (g + g))) / Math.cbrt(a));
} else {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + ((Math.cbrt(-0.5) * Math.cbrt(2.0)) * (Math.cbrt(g) / Math.cbrt(a)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (h <= 1.1e+150) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(-0.5 * Float64((h ^ 2.0) / g)))) + Float64(cbrt(Float64(-0.5 * Float64(g + g))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(Float64(cbrt(-0.5) * cbrt(2.0)) * Float64(cbrt(g) / cbrt(a)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[h, 1.1e+150], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] * N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \leq 1.1 \cdot 10^{+150}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(-0.5 \cdot \frac{{h}^{2}}{g}\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + g\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) \cdot \frac{\sqrt[3]{g}}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if h < 1.1e150Initial program 46.9%
Simplified46.9%
associate-*r/46.9%
cbrt-div51.6%
pow251.6%
pow251.6%
Applied egg-rr51.6%
Taylor expanded in g around inf 32.4%
Taylor expanded in g around inf 94.7%
if 1.1e150 < h Initial program 0.0%
Simplified0.0%
Taylor expanded in g around inf 0.0%
Taylor expanded in h around 0 39.5%
unpow1/350.9%
*-lft-identity50.9%
Simplified50.9%
cbrt-div84.2%
div-inv84.3%
Applied egg-rr84.3%
associate-*r/84.2%
*-rgt-identity84.2%
Simplified84.2%
Final simplification94.3%
(FPCore (g h a)
:precision binary64
(if (<= h 1.35e+154)
(+
(cbrt (* (/ 0.5 a) (* -0.5 (/ (pow h 2.0) g))))
(/ (cbrt (* -0.5 (+ g g))) (cbrt a)))
(+
(cbrt (* (/ 0.5 a) (- g g)))
(* (* (cbrt -0.5) (cbrt 2.0)) (/ 1.0 (cbrt (/ a g)))))))
double code(double g, double h, double a) {
double tmp;
if (h <= 1.35e+154) {
tmp = cbrt(((0.5 / a) * (-0.5 * (pow(h, 2.0) / g)))) + (cbrt((-0.5 * (g + g))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (g - g))) + ((cbrt(-0.5) * cbrt(2.0)) * (1.0 / cbrt((a / g))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (h <= 1.35e+154) {
tmp = Math.cbrt(((0.5 / a) * (-0.5 * (Math.pow(h, 2.0) / g)))) + (Math.cbrt((-0.5 * (g + g))) / Math.cbrt(a));
} else {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + ((Math.cbrt(-0.5) * Math.cbrt(2.0)) * (1.0 / Math.cbrt((a / g))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (h <= 1.35e+154) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(-0.5 * Float64((h ^ 2.0) / g)))) + Float64(cbrt(Float64(-0.5 * Float64(g + g))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(Float64(cbrt(-0.5) * cbrt(2.0)) * Float64(1.0 / cbrt(Float64(a / g))))); end return tmp end
code[g_, h_, a_] := If[LessEqual[h, 1.35e+154], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[(a / g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(-0.5 \cdot \frac{{h}^{2}}{g}\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + g\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) \cdot \frac{1}{\sqrt[3]{\frac{a}{g}}}\\
\end{array}
\end{array}
if h < 1.35000000000000003e154Initial program 46.9%
Simplified46.9%
associate-*r/46.9%
cbrt-div51.6%
pow251.6%
pow251.6%
Applied egg-rr51.6%
Taylor expanded in g around inf 32.4%
Taylor expanded in g around inf 94.7%
if 1.35000000000000003e154 < h Initial program 0.0%
Simplified0.0%
Taylor expanded in g around inf 0.0%
Taylor expanded in h around 0 39.5%
unpow1/350.9%
*-lft-identity50.9%
Simplified50.9%
clear-num50.9%
cbrt-div67.3%
metadata-eval67.3%
Applied egg-rr67.3%
Final simplification93.7%
(FPCore (g h a)
:precision binary64
(if (<= h 7.4e+146)
(+
(cbrt (* (/ 0.5 a) (* g -2.0)))
(cbrt (* (/ (* 0.5 (pow h 2.0)) g) (/ -0.5 a))))
(+
(cbrt (* (/ 0.5 a) (- g g)))
(* (* (cbrt -0.5) (cbrt 2.0)) (/ 1.0 (cbrt (/ a g)))))))
double code(double g, double h, double a) {
double tmp;
if (h <= 7.4e+146) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + cbrt((((0.5 * pow(h, 2.0)) / g) * (-0.5 / a)));
} else {
tmp = cbrt(((0.5 / a) * (g - g))) + ((cbrt(-0.5) * cbrt(2.0)) * (1.0 / cbrt((a / g))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (h <= 7.4e+146) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt((((0.5 * Math.pow(h, 2.0)) / g) * (-0.5 / a)));
} else {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + ((Math.cbrt(-0.5) * Math.cbrt(2.0)) * (1.0 / Math.cbrt((a / g))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (h <= 7.4e+146) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(Float64(0.5 * (h ^ 2.0)) / g) * Float64(-0.5 / a)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(Float64(cbrt(-0.5) * cbrt(2.0)) * Float64(1.0 / cbrt(Float64(a / g))))); end return tmp end
code[g_, h_, a_] := If[LessEqual[h, 7.4e+146], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(N[(0.5 * N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision] / g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Power[N[(a / g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \leq 7.4 \cdot 10^{+146}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{0.5 \cdot {h}^{2}}{g} \cdot \frac{-0.5}{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \left(\sqrt[3]{-0.5} \cdot \sqrt[3]{2}\right) \cdot \frac{1}{\sqrt[3]{\frac{a}{g}}}\\
\end{array}
\end{array}
if h < 7.40000000000000009e146Initial program 47.3%
Simplified47.3%
Taylor expanded in g around -inf 26.1%
associate-*r/26.1%
Simplified26.1%
Taylor expanded in g around -inf 74.0%
*-commutative74.0%
Simplified74.0%
if 7.40000000000000009e146 < h Initial program 0.0%
Simplified0.0%
Taylor expanded in g around inf 0.1%
Taylor expanded in h around 0 33.3%
unpow1/343.2%
*-lft-identity43.2%
Simplified43.2%
clear-num43.2%
cbrt-div56.9%
metadata-eval56.9%
Applied egg-rr56.9%
Final simplification73.2%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 45.1%
Simplified45.1%
Taylor expanded in g around inf 25.5%
Taylor expanded in g around inf 72.2%
associate-*r/72.2%
neg-mul-172.2%
Simplified72.2%
Final simplification72.2%
herbie shell --seed 2023337
(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))))))))