(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 (- t_0 g)))
(if (<= g -1e-170)
(+
(/ (cbrt (* 0.5 t_1)) (cbrt a))
(/ (cbrt (* (* (* h h) (/ 0.5 g)) -0.5)) (cbrt a)))
(if (<= g 1e-153)
(+ (cbrt (* t_1 (/ 0.5 a))) (/ (cbrt (* -0.5 (* g 2.0))) (cbrt a)))
(+
(/ (cbrt (* 0.5 (* -0.5 (/ (pow h 2.0) g)))) (cbrt a))
(/ (cbrt (* -0.5 (+ g t_0))) (cbrt a)))))))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 = t_0 - g;
double tmp;
if (g <= -1e-170) {
tmp = (cbrt((0.5 * t_1)) / cbrt(a)) + (cbrt((((h * h) * (0.5 / g)) * -0.5)) / cbrt(a));
} else if (g <= 1e-153) {
tmp = cbrt((t_1 * (0.5 / a))) + (cbrt((-0.5 * (g * 2.0))) / cbrt(a));
} else {
tmp = (cbrt((0.5 * (-0.5 * (pow(h, 2.0) / g)))) / cbrt(a)) + (cbrt((-0.5 * (g + t_0))) / cbrt(a));
}
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 = t_0 - g;
double tmp;
if (g <= -1e-170) {
tmp = (Math.cbrt((0.5 * t_1)) / Math.cbrt(a)) + (Math.cbrt((((h * h) * (0.5 / g)) * -0.5)) / Math.cbrt(a));
} else if (g <= 1e-153) {
tmp = Math.cbrt((t_1 * (0.5 / a))) + (Math.cbrt((-0.5 * (g * 2.0))) / Math.cbrt(a));
} else {
tmp = (Math.cbrt((0.5 * (-0.5 * (Math.pow(h, 2.0) / g)))) / Math.cbrt(a)) + (Math.cbrt((-0.5 * (g + t_0))) / Math.cbrt(a));
}
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 = Float64(t_0 - g) tmp = 0.0 if (g <= -1e-170) tmp = Float64(Float64(cbrt(Float64(0.5 * t_1)) / cbrt(a)) + Float64(cbrt(Float64(Float64(Float64(h * h) * Float64(0.5 / g)) * -0.5)) / cbrt(a))); elseif (g <= 1e-153) tmp = Float64(cbrt(Float64(t_1 * Float64(0.5 / a))) + Float64(cbrt(Float64(-0.5 * Float64(g * 2.0))) / cbrt(a))); else tmp = Float64(Float64(cbrt(Float64(0.5 * Float64(-0.5 * Float64((h ^ 2.0) / g)))) / cbrt(a)) + Float64(cbrt(Float64(-0.5 * Float64(g + t_0))) / cbrt(a))); 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[(t$95$0 - g), $MachinePrecision]}, If[LessEqual[g, -1e-170], N[(N[(N[Power[N[(0.5 * t$95$1), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(N[(N[(h * h), $MachinePrecision] * N[(0.5 / g), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 1e-153], N[(N[Power[N[(t$95$1 * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g * 2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(0.5 * N[(-0.5 * N[(N[Power[h, 2.0], $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 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 := t_0 - g\\
\mathbf{if}\;g \leq -1 \cdot 10^{-170}:\\
\;\;\;\;\frac{\sqrt[3]{0.5 \cdot t_1}}{\sqrt[3]{a}} + \frac{\sqrt[3]{\left(\left(h \cdot h\right) \cdot \frac{0.5}{g}\right) \cdot -0.5}}{\sqrt[3]{a}}\\
\mathbf{elif}\;g \leq 10^{-153}:\\
\;\;\;\;\sqrt[3]{t_1 \cdot \frac{0.5}{a}} + \frac{\sqrt[3]{-0.5 \cdot \left(g \cdot 2\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{0.5 \cdot \left(-0.5 \cdot \frac{{h}^{2}}{g}\right)}}{\sqrt[3]{a}} + \frac{\sqrt[3]{-0.5 \cdot \left(g + t_0\right)}}{\sqrt[3]{a}}\\
\end{array}
Results
if g < -9.99999999999999983e-171Initial program 35.1
Simplified35.1
Applied egg-rr35.0
Applied egg-rr31.3
Taylor expanded in g around -inf 30.7
Simplified30.7
if -9.99999999999999983e-171 < g < 1.00000000000000004e-153Initial program 53.7
Simplified53.7
Applied egg-rr50.3
Taylor expanded in g around inf 37.9
if 1.00000000000000004e-153 < g Initial program 35.4
Simplified35.4
Applied egg-rr31.7
Applied egg-rr31.6
Taylor expanded in g around inf 31.2
Final simplification31.3
herbie shell --seed 2022197
(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))))))))