\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}\;\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-1}{2 \cdot a}} \leq -4.012135255503389 \cdot 10^{-107}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g} + \frac{\sqrt[3]{\left(-g\right) - \sqrt{g \cdot g - h \cdot h}}}{\sqrt[3]{2 \cdot a}}\\
\mathbf{elif}\;\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-1}{2 \cdot a}} \leq 0:\\
\;\;\;\;\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-1}{2 \cdot a}} + \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\left(-g\right) - g}\\
\mathbf{elif}\;\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-1}{2 \cdot a}} \leq \infty:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\sqrt{g \cdot g - h \cdot h} - g} + \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\left(-g\right) - \sqrt{g \cdot g - h \cdot h}}\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}(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
(if (<=
(+
(cbrt (* (/ 1.0 (* 2.0 a)) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -1.0 (* 2.0 a)))))
-4.012135255503389e-107)
(+
(* (cbrt (/ 0.5 a)) (cbrt (- (sqrt (- (* g g) (* h h))) g)))
(/ (cbrt (- (- g) (sqrt (- (* g g) (* h h))))) (cbrt (* 2.0 a))))
(if (<=
(+
(cbrt (* (/ 1.0 (* 2.0 a)) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -1.0 (* 2.0 a)))))
0.0)
(+
(cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -1.0 (* 2.0 a))))
(* (cbrt (/ 0.5 a)) (cbrt (- (- g) g))))
(if (<=
(+
(cbrt (* (/ 1.0 (* 2.0 a)) (- (sqrt (- (* g g) (* h h))) g)))
(cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -1.0 (* 2.0 a)))))
INFINITY)
(+
(* (cbrt (/ 0.5 a)) (cbrt (- (sqrt (- (* g g) (* h h))) g)))
(* (cbrt (/ 0.5 a)) (cbrt (- (- g) (sqrt (- (* g g) (* h h)))))))
-1.0))))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 tmp;
if ((cbrt((1.0 / (2.0 * a)) * (sqrt((g * g) - (h * h)) - g)) + cbrt((g + sqrt((g * g) - (h * h))) * (-1.0 / (2.0 * a)))) <= -4.012135255503389e-107) {
tmp = (cbrt(0.5 / a) * cbrt(sqrt((g * g) - (h * h)) - g)) + (cbrt(-g - sqrt((g * g) - (h * h))) / cbrt(2.0 * a));
} else if ((cbrt((1.0 / (2.0 * a)) * (sqrt((g * g) - (h * h)) - g)) + cbrt((g + sqrt((g * g) - (h * h))) * (-1.0 / (2.0 * a)))) <= 0.0) {
tmp = cbrt((g + sqrt((g * g) - (h * h))) * (-1.0 / (2.0 * a))) + (cbrt(0.5 / a) * cbrt(-g - g));
} else if ((cbrt((1.0 / (2.0 * a)) * (sqrt((g * g) - (h * h)) - g)) + cbrt((g + sqrt((g * g) - (h * h))) * (-1.0 / (2.0 * a)))) <= ((double) INFINITY)) {
tmp = (cbrt(0.5 / a) * cbrt(sqrt((g * g) - (h * h)) - g)) + (cbrt(0.5 / a) * cbrt(-g - sqrt((g * g) - (h * h))));
} else {
tmp = -1.0;
}
return tmp;
}



Bits error versus g



Bits error versus h



Bits error versus a
Results
if (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < -4.01213525550338899e-107Initial program 11.0
rmApplied cbrt-prod_binary64_65888.7
Simplified8.7
Simplified8.7
rmApplied associate-*l/_binary64_65008.7
Applied cbrt-div_binary64_65896.1
if -4.01213525550338899e-107 < (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < 0.0Initial program 60.6
rmApplied cbrt-prod_binary64_658841.7
Simplified41.5
Simplified41.5
Taylor expanded around -inf 7.5
if 0.0 < (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < +inf.0Initial program 10.5
rmApplied cbrt-prod_binary64_65887.9
Simplified7.9
Simplified7.9
rmApplied cbrt-prod_binary64_65886.0
Simplified6.0
rmApplied *-un-lft-identity_binary64_65576.0
Applied sqrt-prod_binary64_65736.0
Simplified6.0
if +inf.0 < (+.f64 (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 1 (*.f64 2 a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) Initial program 61.3
Final simplification30.5
herbie shell --seed 2021084
(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))))))))