(FPCore (g h a) :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))))))))
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (cbrt (* (/ 0.5 a) (- t_0 g))))
(t_2 (+ t_1 (cbrt (* (+ g t_0) (/ -0.5 a))))))
(if (<= h -1.85e-171)
t_2
(if (<= h 1.05e-162)
(+ t_1 (/ (cbrt (* -0.5 (+ g (hypot g (sqrt (* h (- h))))))) (cbrt a)))
t_2))))double code(double g, double h, double a) {
return cbrt(((1.0 / (2.0 * a)) * (-g + sqrt(((g * g) - (h * h)))))) + cbrt(((1.0 / (2.0 * a)) * (-g - sqrt(((g * g) - (h * h))))));
}
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = cbrt(((0.5 / a) * (t_0 - g)));
double t_2 = t_1 + cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if (h <= -1.85e-171) {
tmp = t_2;
} else if (h <= 1.05e-162) {
tmp = t_1 + (cbrt((-0.5 * (g + hypot(g, sqrt((h * -h)))))) / cbrt(a));
} else {
tmp = t_2;
}
return tmp;
}
public static double code(double g, double h, double a) {
return Math.cbrt(((1.0 / (2.0 * a)) * (-g + Math.sqrt(((g * g) - (h * h)))))) + Math.cbrt(((1.0 / (2.0 * a)) * (-g - Math.sqrt(((g * g) - (h * h))))));
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.cbrt(((0.5 / a) * (t_0 - g)));
double t_2 = t_1 + Math.cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if (h <= -1.85e-171) {
tmp = t_2;
} else if (h <= 1.05e-162) {
tmp = t_1 + (Math.cbrt((-0.5 * (g + Math.hypot(g, Math.sqrt((h * -h)))))) / Math.cbrt(a));
} else {
tmp = t_2;
}
return tmp;
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(Float64(-g) - sqrt(Float64(Float64(g * g) - Float64(h * h))))))) end
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) t_2 = Float64(t_1 + cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a)))) tmp = 0.0 if (h <= -1.85e-171) tmp = t_2; elseif (h <= 1.05e-162) tmp = Float64(t_1 + Float64(cbrt(Float64(-0.5 * Float64(g + hypot(g, sqrt(Float64(h * Float64(-h))))))) / cbrt(a))); else tmp = t_2; end return tmp end
code[g_, h_, a_] := N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $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[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[((-g) - N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[h, -1.85e-171], t$95$2, If[LessEqual[h, 1.05e-162], N[(t$95$1 + 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], t$95$2]]]]]
\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\left(-g\right) - \sqrt{g \cdot g - h \cdot h}\right)}
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\
t_2 := t_1 + \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;h \leq -1.85 \cdot 10^{-171}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;h \leq 1.05 \cdot 10^{-162}:\\
\;\;\;\;t_1 + \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}:\\
\;\;\;\;t_2\\
\end{array}
Results
if h < -1.85000000000000006e-171 or 1.05e-162 < h Initial program 39.5
Simplified39.5
if -1.85000000000000006e-171 < h < 1.05e-162Initial program 30.8
Simplified30.7
Applied egg-rr34.9
Applied egg-rr27.3
Final simplification34.4
herbie shell --seed 2022209
(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))))))))