\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}
\mathbf{if}\;g \le -8.03023201021905877 \cdot 10^{-161}:\\
\;\;\;\;\sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\left(-g\right) + \left|\sqrt[3]{g \cdot g - h \cdot h}\right| \cdot \sqrt{\sqrt[3]{g \cdot g - h \cdot h}}} + \sqrt[3]{\frac{1}{2 \cdot a}} \cdot \sqrt[3]{\left(-g\right) - \sqrt{g \cdot g - h \cdot h}}\\
\mathbf{else}:\\
\;\;\;\;\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 \sqrt[3]{\left(-g\right) - g}\\
\end{array}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 temp;
if ((g <= -8.030232010219059e-161)) {
temp = ((cbrt((1.0 / (2.0 * a))) * cbrt((-g + (fabs(cbrt(((g * g) - (h * h)))) * sqrt(cbrt(((g * g) - (h * h)))))))) + (cbrt((1.0 / (2.0 * a))) * cbrt((-g - sqrt(((g * g) - (h * h)))))));
} else {
temp = (cbrt(((1.0 / (2.0 * a)) * (-g + sqrt(((g * g) - (h * h)))))) + (cbrt((1.0 / (2.0 * a))) * cbrt((-g - g))));
}
return temp;
}



Bits error versus g



Bits error versus h



Bits error versus a
Results
if g < -8.030232010219059e-161Initial program 34.4
rmApplied cbrt-prod34.4
rmApplied cbrt-prod31.0
rmApplied add-cube-cbrt31.1
Applied sqrt-prod31.1
Simplified31.1
if -8.030232010219059e-161 < g Initial program 37.4
rmApplied cbrt-prod33.3
Taylor expanded around inf 32.1
Final simplification31.6
herbie shell --seed 2020057 +o rules:numerics
(FPCore (g h a)
:name "2-ancestry mixing, positive discriminant"
:precision binary64
(+ (cbrt (* (/ 1 (* 2 a)) (+ (- g) (sqrt (- (* g g) (* h h)))))) (cbrt (* (/ 1 (* 2 a)) (- (- g) (sqrt (- (* g g) (* h h))))))))