(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 (+ g (sqrt (- (* g g) (* h h))))) (t_1 (/ (* h h) g)))
(if (<= g 1.4710116353411875e-158)
(+
(/ (cbrt (- (- (* 0.5 t_1) g) g)) (cbrt (* 2.0 a)))
(cbrt (* (/ t_0 a) -0.5)))
(+
(/ (cbrt (/ (* t_1 -0.5) 2.0)) (cbrt a))
(/ (cbrt (* t_0 -0.5)) (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 = g + sqrt(((g * g) - (h * h)));
double t_1 = (h * h) / g;
double tmp;
if (g <= 1.4710116353411875e-158) {
tmp = (cbrt((((0.5 * t_1) - g) - g)) / cbrt((2.0 * a))) + cbrt(((t_0 / a) * -0.5));
} else {
tmp = (cbrt(((t_1 * -0.5) / 2.0)) / cbrt(a)) + (cbrt((t_0 * -0.5)) / 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 = g + Math.sqrt(((g * g) - (h * h)));
double t_1 = (h * h) / g;
double tmp;
if (g <= 1.4710116353411875e-158) {
tmp = (Math.cbrt((((0.5 * t_1) - g) - g)) / Math.cbrt((2.0 * a))) + Math.cbrt(((t_0 / a) * -0.5));
} else {
tmp = (Math.cbrt(((t_1 * -0.5) / 2.0)) / Math.cbrt(a)) + (Math.cbrt((t_0 * -0.5)) / 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 = Float64(g + sqrt(Float64(Float64(g * g) - Float64(h * h)))) t_1 = Float64(Float64(h * h) / g) tmp = 0.0 if (g <= 1.4710116353411875e-158) tmp = Float64(Float64(cbrt(Float64(Float64(Float64(0.5 * t_1) - g) - g)) / cbrt(Float64(2.0 * a))) + cbrt(Float64(Float64(t_0 / a) * -0.5))); else tmp = Float64(Float64(cbrt(Float64(Float64(t_1 * -0.5) / 2.0)) / cbrt(a)) + Float64(cbrt(Float64(t_0 * -0.5)) / 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[(g + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]}, If[LessEqual[g, 1.4710116353411875e-158], N[(N[(N[Power[N[(N[(N[(0.5 * t$95$1), $MachinePrecision] - g), $MachinePrecision] - g), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(2.0 * a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(t$95$0 / a), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(N[(t$95$1 * -0.5), $MachinePrecision] / 2.0), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(t$95$0 * -0.5), $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 := g + \sqrt{g \cdot g - h \cdot h}\\
t_1 := \frac{h \cdot h}{g}\\
\mathbf{if}\;g \leq 1.4710116353411875 \cdot 10^{-158}:\\
\;\;\;\;\frac{\sqrt[3]{\left(0.5 \cdot t_1 - g\right) - g}}{\sqrt[3]{2 \cdot a}} + \sqrt[3]{\frac{t_0}{a} \cdot -0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{\frac{t_1 \cdot -0.5}{2}}}{\sqrt[3]{a}} + \frac{\sqrt[3]{t_0 \cdot -0.5}}{\sqrt[3]{a}}\\
\end{array}



Bits error versus g



Bits error versus h



Bits error versus a
Results
if g < 1.4710116353411875e-158Initial program 38.0
Simplified38.0
Applied egg-rr34.4
Taylor expanded in g around -inf 33.1
Simplified33.1
if 1.4710116353411875e-158 < g Initial program 34.9
Simplified34.8
Applied egg-rr34.8
Applied egg-rr30.9
Taylor expanded in g around inf 30.4
Simplified30.4
Final simplification31.8
herbie shell --seed 2022144
(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))))))))