(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 (sqrt t_0)))
(if (<= g 1.95e-223)
(+ (* (cbrt (/ 0.5 a)) (cbrt (* -2.0 g))) (cbrt (* (/ -0.5 a) (+ g t_0))))
(+
(cbrt (* (/ 0.5 a) (- t_0 g)))
(* (cbrt (/ -0.5 a)) (cbrt (+ g (* t_1 t_1))))))))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 = sqrt(t_0);
double tmp;
if (g <= 1.95e-223) {
tmp = (cbrt((0.5 / a)) * cbrt((-2.0 * g))) + cbrt(((-0.5 / a) * (g + t_0)));
} else {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + (cbrt((-0.5 / a)) * cbrt((g + (t_1 * t_1))));
}
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.sqrt(t_0);
double tmp;
if (g <= 1.95e-223) {
tmp = (Math.cbrt((0.5 / a)) * Math.cbrt((-2.0 * g))) + Math.cbrt(((-0.5 / a) * (g + t_0)));
} else {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + (t_1 * t_1))));
}
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 = sqrt(t_0) tmp = 0.0 if (g <= 1.95e-223) tmp = Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(-2.0 * g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + t_0)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + Float64(t_1 * t_1))))); 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[Sqrt[t$95$0], $MachinePrecision]}, If[LessEqual[g, 1.95e-223], N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\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{t_0}\\
\mathbf{if}\;g \leq 1.95 \cdot 10^{-223}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{-2 \cdot g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + t_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + t_1 \cdot t_1}\\
\end{array}
Results
if g < 1.94999999999999981e-223Initial program 37.0
Simplified37.0
Applied egg-rr33.3
Taylor expanded in g around -inf 32.4
if 1.94999999999999981e-223 < g Initial program 36.5
Simplified36.5
Applied egg-rr32.9
Applied egg-rr32.9
Final simplification32.6
herbie shell --seed 2022203
(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))))))))