
(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 7 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
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= (* h h) 0.0)
(+
(cbrt (* (- g (sqrt (* (+ h g) (- g h)))) (/ -0.5 a)))
(/ (cbrt (+ g (hypot g (sqrt (* h (- h)))))) (cbrt (* a -2.0))))
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ 0.5 a) (- (- g) t_0)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if ((h * h) <= 0.0) {
tmp = cbrt(((g - sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + (cbrt((g + hypot(g, sqrt((h * -h))))) / cbrt((a * -2.0)));
} else {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((0.5 / a) * (-g - t_0)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if ((h * h) <= 0.0) {
tmp = Math.cbrt(((g - Math.sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + (Math.cbrt((g + Math.hypot(g, Math.sqrt((h * -h))))) / Math.cbrt((a * -2.0)));
} else {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((0.5 / a) * (-g - t_0)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (Float64(h * h) <= 0.0) tmp = Float64(cbrt(Float64(Float64(g - sqrt(Float64(Float64(h + g) * Float64(g - h)))) * Float64(-0.5 / a))) + Float64(cbrt(Float64(g + hypot(g, sqrt(Float64(h * Float64(-h)))))) / cbrt(Float64(a * -2.0)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - t_0)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(N[Power[N[(N[(g - N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(g + N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(a * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[((-g) - t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;\sqrt[3]{\left(g - \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right) \cdot \frac{-0.5}{a}} + \frac{\sqrt[3]{g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)}}{\sqrt[3]{a \cdot -2}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - t_0\right)}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 52.9%
Simplified52.9%
difference-of-squares52.9%
fma-neg52.9%
clear-num52.9%
div-inv52.9%
cbrt-div56.3%
Applied egg-rr59.6%
if 0.0 < (*.f64 h h) Initial program 32.0%
associate-/r*32.0%
metadata-eval32.0%
+-commutative32.0%
unsub-neg32.0%
associate-/r*32.0%
metadata-eval32.0%
Simplified32.0%
Final simplification43.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= h 6e-163)
(+
(cbrt (* (- g (sqrt (* (+ h g) (- g h)))) (/ -0.5 a)))
(/ (cbrt (* -0.5 (+ g (hypot g (sqrt (* h (- h))))))) (cbrt a)))
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ 0.5 a) (- (- g) t_0)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if (h <= 6e-163) {
tmp = cbrt(((g - sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + (cbrt((-0.5 * (g + hypot(g, sqrt((h * -h)))))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((0.5 / a) * (-g - t_0)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if (h <= 6e-163) {
tmp = Math.cbrt(((g - Math.sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + (Math.cbrt((-0.5 * (g + Math.hypot(g, Math.sqrt((h * -h)))))) / Math.cbrt(a));
} else {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((0.5 / a) * (-g - t_0)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (h <= 6e-163) tmp = Float64(cbrt(Float64(Float64(g - sqrt(Float64(Float64(h + g) * Float64(g - h)))) * Float64(-0.5 / a))) + Float64(cbrt(Float64(-0.5 * Float64(g + hypot(g, sqrt(Float64(h * Float64(-h))))))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - t_0)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[h, 6e-163], N[(N[Power[N[(N[(g - N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[((-g) - t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;h \leq 6 \cdot 10^{-163}:\\
\;\;\;\;\sqrt[3]{\left(g - \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right) \cdot \frac{-0.5}{a}} + \frac{\sqrt[3]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - t_0\right)}\\
\end{array}
\end{array}
if h < 6.0000000000000005e-163Initial program 47.3%
Simplified47.3%
associate-*r/47.3%
cbrt-div50.5%
difference-of-squares50.5%
sub-neg50.5%
add-sqr-sqrt34.1%
hypot-def36.1%
distribute-rgt-neg-in36.1%
Applied egg-rr36.1%
if 6.0000000000000005e-163 < h Initial program 27.2%
associate-/r*27.2%
metadata-eval27.2%
+-commutative27.2%
unsub-neg27.2%
associate-/r*27.2%
metadata-eval27.2%
Simplified27.2%
Final simplification33.1%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= g -2e-162)
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ 0.5 a) (- g g))))
(+
(cbrt (* (/ 0.5 a) (- (- g) t_0)))
(cbrt (* (/ 0.5 a) (* -0.5 (/ (* h h) g))))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if (g <= -2e-162) {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((0.5 / a) * (g - g)));
} else {
tmp = cbrt(((0.5 / a) * (-g - t_0))) + cbrt(((0.5 / a) * (-0.5 * ((h * h) / g))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if (g <= -2e-162) {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((0.5 / a) * (g - g)));
} else {
tmp = Math.cbrt(((0.5 / a) * (-g - t_0))) + Math.cbrt(((0.5 / a) * (-0.5 * ((h * h) / g))));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (g <= -2e-162) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - t_0))) + cbrt(Float64(Float64(0.5 / a) * Float64(-0.5 * Float64(Float64(h * h) / g))))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[g, -2e-162], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[((-g) - t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-0.5 * N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq -2 \cdot 10^{-162}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - t_0\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(-0.5 \cdot \frac{h \cdot h}{g}\right)}\\
\end{array}
\end{array}
if g < -1.99999999999999991e-162Initial program 42.2%
associate-/r*42.2%
metadata-eval42.2%
+-commutative42.2%
unsub-neg42.2%
associate-/r*42.2%
metadata-eval42.2%
Simplified42.2%
Taylor expanded in g around -inf 43.8%
neg-mul-143.8%
Simplified43.8%
if -1.99999999999999991e-162 < g Initial program 39.0%
associate-/r*39.0%
metadata-eval39.0%
+-commutative39.0%
unsub-neg39.0%
associate-/r*39.0%
metadata-eval39.0%
Simplified39.0%
Taylor expanded in g around inf 41.4%
unpow241.4%
Simplified41.4%
Final simplification42.5%
(FPCore (g h a)
:precision binary64
(if (<= g -1.6e-162)
(+
(cbrt (* (/ 0.5 a) (- (- g) (sqrt (- (* g g) (* h h))))))
(cbrt (* (/ 0.5 a) (* g -2.0))))
(+
(cbrt (* 0.0 (/ -0.5 a)))
(cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h)))))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -1.6e-162) {
tmp = cbrt(((0.5 / a) * (-g - sqrt(((g * g) - (h * h)))))) + cbrt(((0.5 / a) * (g * -2.0)));
} else {
tmp = cbrt((0.0 * (-0.5 / a))) + cbrt(((-0.5 / a) * (g + sqrt(((h + g) * (g - h))))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (g <= -1.6e-162) {
tmp = Math.cbrt(((0.5 / a) * (-g - Math.sqrt(((g * g) - (h * h)))))) + Math.cbrt(((0.5 / a) * (g * -2.0)));
} else {
tmp = Math.cbrt((0.0 * (-0.5 / a))) + Math.cbrt(((-0.5 / a) * (g + Math.sqrt(((h + g) * (g - h))))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -1.6e-162) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0)))); else tmp = Float64(cbrt(Float64(0.0 * Float64(-0.5 / a))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + sqrt(Float64(Float64(h + g) * Float64(g - h))))))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, -1.6e-162], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[((-g) - N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.0 * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -1.6 \cdot 10^{-162}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{0 \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right)}\\
\end{array}
\end{array}
if g < -1.59999999999999988e-162Initial program 42.2%
associate-/r*42.2%
metadata-eval42.2%
+-commutative42.2%
unsub-neg42.2%
associate-/r*42.2%
metadata-eval42.2%
Simplified42.2%
Taylor expanded in g around -inf 41.9%
*-commutative41.9%
Simplified41.9%
if -1.59999999999999988e-162 < g Initial program 39.0%
Simplified39.0%
Taylor expanded in g around inf 40.3%
distribute-rgt1-in40.3%
metadata-eval40.3%
mul0-lft40.3%
metadata-eval40.3%
Simplified40.3%
Final simplification41.0%
(FPCore (g h a)
:precision binary64
(if (<= g -2e-162)
(+
(cbrt (* (/ 0.5 a) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (/ 0.5 a) (- g g))))
(+
(cbrt (* 0.0 (/ -0.5 a)))
(cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h)))))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -2e-162) {
tmp = cbrt(((0.5 / a) * (sqrt(((g * g) - (h * h))) - g))) + cbrt(((0.5 / a) * (g - g)));
} else {
tmp = cbrt((0.0 * (-0.5 / a))) + cbrt(((-0.5 / a) * (g + sqrt(((h + g) * (g - h))))));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (g <= -2e-162) {
tmp = Math.cbrt(((0.5 / a) * (Math.sqrt(((g * g) - (h * h))) - g))) + Math.cbrt(((0.5 / a) * (g - g)));
} else {
tmp = Math.cbrt((0.0 * (-0.5 / a))) + Math.cbrt(((-0.5 / a) * (g + Math.sqrt(((h + g) * (g - h))))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -2e-162) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(sqrt(Float64(Float64(g * g) - Float64(h * h))) - g))) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))); else tmp = Float64(cbrt(Float64(0.0 * Float64(-0.5 / a))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + sqrt(Float64(Float64(h + g) * Float64(g - h))))))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, -2e-162], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.0 * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -2 \cdot 10^{-162}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{0 \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right)}\\
\end{array}
\end{array}
if g < -1.99999999999999991e-162Initial program 42.2%
associate-/r*42.2%
metadata-eval42.2%
+-commutative42.2%
unsub-neg42.2%
associate-/r*42.2%
metadata-eval42.2%
Simplified42.2%
Taylor expanded in g around -inf 43.8%
neg-mul-143.8%
Simplified43.8%
if -1.99999999999999991e-162 < g Initial program 39.0%
Simplified39.0%
Taylor expanded in g around inf 40.3%
distribute-rgt1-in40.3%
metadata-eval40.3%
mul0-lft40.3%
metadata-eval40.3%
Simplified40.3%
Final simplification41.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (- g (sqrt (* (+ h g) (- g h)))) (/ -0.5 a))) (cbrt (* (/ -0.5 a) (+ g g)))))
double code(double g, double h, double a) {
return cbrt(((g - sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + cbrt(((-0.5 / a) * (g + g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - Math.sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + Math.cbrt(((-0.5 / a) * (g + g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - sqrt(Float64(Float64(h + g) * Float64(g - h)))) * Float64(-0.5 / a))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(g - \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}
\end{array}
Initial program 40.5%
Simplified40.5%
Taylor expanded in g around inf 26.2%
Final simplification26.2%
(FPCore (g h a) :precision binary64 (+ (cbrt (* 0.0 (/ -0.5 a))) (cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h))))))))
double code(double g, double h, double a) {
return cbrt((0.0 * (-0.5 / a))) + cbrt(((-0.5 / a) * (g + sqrt(((h + g) * (g - h))))));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.0 * (-0.5 / a))) + Math.cbrt(((-0.5 / a) * (g + Math.sqrt(((h + g) * (g - h))))));
}
function code(g, h, a) return Float64(cbrt(Float64(0.0 * Float64(-0.5 / a))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + sqrt(Float64(Float64(h + g) * Float64(g - h))))))) end
code[g_, h_, a_] := N[(N[Power[N[(0.0 * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + N[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0 \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right)}
\end{array}
Initial program 40.5%
Simplified40.5%
Taylor expanded in g around inf 23.0%
distribute-rgt1-in23.0%
metadata-eval23.0%
mul0-lft23.0%
metadata-eval23.0%
Simplified23.0%
Final simplification23.0%
herbie shell --seed 2023257
(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))))))))