
(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 8 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 (* h (- h))) (t_1 (sqrt (fma g g t_0))))
(if (<= (* h h) 0.0)
(+
(cbrt (* (- g (sqrt (* (+ h g) (- g h)))) (/ -0.5 a)))
(/ (cbrt (* -0.5 (+ g (hypot g (sqrt t_0))))) (cbrt a)))
(+ (cbrt (* (/ 0.5 a) (- t_1 g))) (cbrt (/ (+ g t_1) (/ a -0.5)))))))
double code(double g, double h, double a) {
double t_0 = h * -h;
double t_1 = sqrt(fma(g, g, t_0));
double tmp;
if ((h * h) <= 0.0) {
tmp = cbrt(((g - sqrt(((h + g) * (g - h)))) * (-0.5 / a))) + (cbrt((-0.5 * (g + hypot(g, sqrt(t_0))))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (t_1 - g))) + cbrt(((g + t_1) / (a / -0.5)));
}
return tmp;
}
function code(g, h, a) t_0 = Float64(h * Float64(-h)) t_1 = sqrt(fma(g, g, t_0)) 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(-0.5 * Float64(g + hypot(g, sqrt(t_0))))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_1 - g))) + cbrt(Float64(Float64(g + t_1) / Float64(a / -0.5)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[(h * (-h)), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(g * g + t$95$0), $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[(-0.5 * N[(g + N[Sqrt[g ^ 2 + N[Sqrt[t$95$0], $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$1 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(g + t$95$1), $MachinePrecision] / N[(a / -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := h \cdot \left(-h\right)\\
t_1 := \sqrt{\mathsf{fma}\left(g, g, t_0\right)}\\
\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]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{t_0}\right)\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_1 - g\right)} + \sqrt[3]{\frac{g + t_1}{\frac{a}{-0.5}}}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 48.1%
Simplified48.1%
associate-*r/48.1%
cbrt-div52.7%
difference-of-squares52.7%
sub-neg52.7%
add-sqr-sqrt52.7%
hypot-def57.7%
distribute-rgt-neg-in57.7%
Applied egg-rr57.7%
if 0.0 < (*.f64 h h) Initial program 33.2%
associate-/r*33.2%
metadata-eval33.2%
+-commutative33.2%
unsub-neg33.2%
fma-neg33.2%
sub-neg33.2%
distribute-neg-out33.2%
neg-mul-133.2%
associate-*r*33.2%
Simplified33.2%
Final simplification44.0%
(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 (/ -0.5 a)) (cbrt (+ g (hypot g (sqrt (* h (- h))))))))
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (+ g t_0) (/ (- 0.5) a)))))))
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((-0.5 / a)) * cbrt((g + hypot(g, sqrt((h * -h))))));
} else {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((g + t_0) * (-0.5 / a)));
}
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((-0.5 / a)) * Math.cbrt((g + Math.hypot(g, Math.sqrt((h * -h))))));
} else {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((g + t_0) * (-0.5 / a)));
}
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(-0.5 / a)) * cbrt(Float64(g + hypot(g, sqrt(Float64(h * Float64(-h)))))))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(g + t_0) * Float64(Float64(-0.5) / a)))); 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[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $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[(g + t$95$0), $MachinePrecision] * N[((-0.5) / a), $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}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 48.1%
Simplified48.1%
cbrt-prod52.7%
difference-of-squares52.7%
fma-neg52.7%
fma-neg52.7%
difference-of-squares52.7%
difference-of-squares52.7%
sub-neg52.7%
add-sqr-sqrt52.7%
hypot-def57.7%
distribute-rgt-neg-in57.7%
Applied egg-rr57.7%
*-commutative57.7%
Simplified57.7%
if 0.0 < (*.f64 h h) Initial program 33.2%
associate-/r*33.2%
metadata-eval33.2%
+-commutative33.2%
unsub-neg33.2%
associate-/r*33.2%
metadata-eval33.2%
Simplified33.2%
Final simplification44.0%
(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 (* -0.5 (+ g (hypot g (sqrt (* h (- h))))))) (cbrt a)))
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (+ g t_0) (/ (- 0.5) a)))))))
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((-0.5 * (g + hypot(g, sqrt((h * -h)))))) / cbrt(a));
} else {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((g + t_0) * (-0.5 / a)));
}
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((-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(((g + t_0) * (-0.5 / a)));
}
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(-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(g + t_0) * Float64(Float64(-0.5) / a)))); 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[(-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[(g + t$95$0), $MachinePrecision] * N[((-0.5) / a), $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]{-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]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 48.1%
Simplified48.1%
associate-*r/48.1%
cbrt-div52.7%
difference-of-squares52.7%
sub-neg52.7%
add-sqr-sqrt52.7%
hypot-def57.7%
distribute-rgt-neg-in57.7%
Applied egg-rr57.7%
if 0.0 < (*.f64 h h) Initial program 33.2%
associate-/r*33.2%
metadata-eval33.2%
+-commutative33.2%
unsub-neg33.2%
associate-/r*33.2%
metadata-eval33.2%
Simplified33.2%
Final simplification44.0%
(FPCore (g h a)
:precision binary64
(if (<= g -2e-176)
(+
(cbrt (* (/ 0.5 a) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (/ 0.5 a) (* -0.5 (/ (* h h) g)))))
(+
(cbrt (* (/ -0.5 a) (- g g)))
(cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h)))))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -2e-176) {
tmp = cbrt(((0.5 / a) * (sqrt(((g * g) - (h * h))) - g))) + cbrt(((0.5 / a) * (-0.5 * ((h * h) / g))));
} else {
tmp = cbrt(((-0.5 / a) * (g - g))) + 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-176) {
tmp = Math.cbrt(((0.5 / a) * (Math.sqrt(((g * g) - (h * h))) - g))) + Math.cbrt(((0.5 / a) * (-0.5 * ((h * h) / g))));
} else {
tmp = Math.cbrt(((-0.5 / a) * (g - g))) + 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-176) 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(-0.5 * Float64(Float64(h * h) / g))))); else tmp = Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))) + 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-176], 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[(-0.5 * N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $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^{-176}:\\
\;\;\;\;\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(-0.5 \cdot \frac{h \cdot h}{g}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \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 < -2e-176Initial program 43.2%
associate-/r*43.2%
metadata-eval43.2%
+-commutative43.2%
unsub-neg43.2%
associate-/r*43.2%
metadata-eval43.2%
Simplified43.2%
Taylor expanded in g around -inf 46.4%
unpow246.4%
Simplified46.4%
if -2e-176 < g Initial program 36.9%
Simplified36.9%
Taylor expanded in g around inf 38.2%
Final simplification42.0%
(FPCore (g h a)
:precision binary64
(if (<= g -8.5e-182)
(+
(cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ (- 0.5) a)))
(cbrt (* (/ 0.5 a) (- (- g) g))))
(+
(cbrt (* (/ -0.5 a) (- g g)))
(cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h)))))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -8.5e-182) {
tmp = cbrt(((g + sqrt(((g * g) - (h * h)))) * (-0.5 / a))) + cbrt(((0.5 / a) * (-g - g)));
} else {
tmp = cbrt(((-0.5 / a) * (g - g))) + 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 <= -8.5e-182) {
tmp = Math.cbrt(((g + Math.sqrt(((g * g) - (h * h)))) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (-g - g)));
} else {
tmp = Math.cbrt(((-0.5 / a) * (g - g))) + Math.cbrt(((-0.5 / a) * (g + Math.sqrt(((h + g) * (g - h))))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -8.5e-182) tmp = Float64(cbrt(Float64(Float64(g + sqrt(Float64(Float64(g * g) - Float64(h * h)))) * Float64(Float64(-0.5) / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - g)))); else tmp = Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))) + 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, -8.5e-182], N[(N[Power[N[(N[(g + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * 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], N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $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 -8.5 \cdot 10^{-182}:\\
\;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \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 < -8.5000000000000001e-182Initial program 42.9%
associate-/r*42.9%
metadata-eval42.9%
+-commutative42.9%
unsub-neg42.9%
associate-/r*42.9%
metadata-eval42.9%
Simplified42.9%
Taylor expanded in g around -inf 43.1%
neg-mul-143.1%
Simplified43.1%
if -8.5000000000000001e-182 < g Initial program 37.1%
Simplified37.1%
Taylor expanded in g around inf 38.4%
Final simplification40.6%
(FPCore (g h a)
:precision binary64
(if (<= g -2e-155)
(+
(cbrt (* (/ 0.5 a) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (/ 0.5 a) (- g g))))
(+
(cbrt (* (/ -0.5 a) (- g g)))
(cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h)))))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -2e-155) {
tmp = cbrt(((0.5 / a) * (sqrt(((g * g) - (h * h))) - g))) + cbrt(((0.5 / a) * (g - g)));
} else {
tmp = cbrt(((-0.5 / a) * (g - g))) + 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-155) {
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.5 / a) * (g - g))) + 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-155) 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(Float64(-0.5 / a) * Float64(g - g))) + 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-155], 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[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $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^{-155}:\\
\;\;\;\;\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]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \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 < -2.00000000000000003e-155Initial program 43.4%
associate-/r*43.4%
metadata-eval43.4%
+-commutative43.4%
unsub-neg43.4%
associate-/r*43.4%
metadata-eval43.4%
Simplified43.4%
Taylor expanded in g around -inf 45.1%
neg-mul-143.5%
Simplified45.1%
if -2.00000000000000003e-155 < g Initial program 36.8%
Simplified36.8%
Taylor expanded in g around inf 38.1%
Final simplification41.3%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ -0.5 a) (- g g))) (cbrt (* (/ -0.5 a) (+ g (sqrt (* (+ h g) (- g h))))))))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * (g - g))) + cbrt(((-0.5 / a) * (g + sqrt(((h + g) * (g - h))))));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * (g - g))) + Math.cbrt(((-0.5 / a) * (g + Math.sqrt(((h + g) * (g - h))))));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))) + 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[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $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]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\right)}
\end{array}
Initial program 39.8%
Simplified39.8%
Taylor expanded in g around inf 21.6%
Final simplification21.6%
(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 39.8%
Simplified39.8%
Taylor expanded in g around inf 24.7%
Final simplification24.7%
herbie shell --seed 2023258
(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))))))))