(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 (/ 1.0 (* 2.0 a)))
(t_1 (sqrt (- (* g g) (* h h))))
(t_2 (cbrt (* (+ g t_1) (/ -1.0 (* 2.0 a)))))
(t_3 (cbrt (* t_0 (- t_1 g)))))
(if (<= (+ t_3 t_2) 3.7663600711920855e+98)
(+ t_3 (cbrt (* t_0 (fma -1.0 g (- t_1)))))
(+
t_2
(*
(exp
(*
0.3333333333333333
(- (log (- (sqrt (- (pow g 2.0) (pow h 2.0))) g)) (log a))))
(cbrt 0.5))))))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 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
double t_2 = cbrt(((g + t_1) * (-1.0 / (2.0 * a))));
double t_3 = cbrt((t_0 * (t_1 - g)));
double tmp;
if ((t_3 + t_2) <= 3.7663600711920855e+98) {
tmp = t_3 + cbrt((t_0 * fma(-1.0, g, -t_1)));
} else {
tmp = t_2 + (exp((0.3333333333333333 * (log((sqrt((pow(g, 2.0) - pow(h, 2.0))) - g)) - log(a)))) * cbrt(0.5));
}
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(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_2 = cbrt(Float64(Float64(g + t_1) * Float64(-1.0 / Float64(2.0 * a)))) t_3 = cbrt(Float64(t_0 * Float64(t_1 - g))) tmp = 0.0 if (Float64(t_3 + t_2) <= 3.7663600711920855e+98) tmp = Float64(t_3 + cbrt(Float64(t_0 * fma(-1.0, g, Float64(-t_1))))); else tmp = Float64(t_2 + Float64(exp(Float64(0.3333333333333333 * Float64(log(Float64(sqrt(Float64((g ^ 2.0) - (h ^ 2.0))) - g)) - log(a)))) * cbrt(0.5))); 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[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(N[(g + t$95$1), $MachinePrecision] * N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[(t$95$0 * N[(t$95$1 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(t$95$3 + t$95$2), $MachinePrecision], 3.7663600711920855e+98], N[(t$95$3 + N[Power[N[(t$95$0 * N[(-1.0 * g + (-t$95$1)), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$2 + N[(N[Exp[N[(0.3333333333333333 * N[(N[Log[N[(N[Sqrt[N[(N[Power[g, 2.0], $MachinePrecision] - N[Power[h, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - g), $MachinePrecision]], $MachinePrecision] - N[Log[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Power[0.5, 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 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
t_2 := \sqrt[3]{\left(g + t_1\right) \cdot \frac{-1}{2 \cdot a}}\\
t_3 := \sqrt[3]{t_0 \cdot \left(t_1 - g\right)}\\
\mathbf{if}\;t_3 + t_2 \leq 3.7663600711920855 \cdot 10^{+98}:\\
\;\;\;\;t_3 + \sqrt[3]{t_0 \cdot \mathsf{fma}\left(-1, g, -t_1\right)}\\
\mathbf{else}:\\
\;\;\;\;t_2 + e^{0.3333333333333333 \cdot \left(\log \left(\sqrt{{g}^{2} - {h}^{2}} - g\right) - \log a\right)} \cdot \sqrt[3]{0.5}\\
\end{array}



Bits error versus g



Bits error versus h



Bits error versus a
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))))))) < 3.76636007119208554e98Initial program 12.1
Applied egg-rr18.5
Applied egg-rr12.1
if 3.76636007119208554e98 < (+.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 63.5
Taylor expanded in a around 0 62.2
Final simplification35.8
herbie shell --seed 2022140
(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))))))))