(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 (+ g t_0))
(t_2 (- t_0 g))
(t_3
(+
(cbrt (* (/ 1.0 (* 2.0 a)) t_2))
(cbrt (* t_1 (/ -1.0 (* 2.0 a))))))
(t_4
(+ (/ (cbrt (* 0.5 t_2)) (cbrt a)) (/ (cbrt (* t_1 -0.5)) (cbrt a)))))
(if (<= t_3 -5e-105)
t_4
(if (<= t_3 0.0)
(+ (cbrt (* t_2 (/ 0.5 a))) (* (cbrt (/ -0.5 a)) (cbrt (+ g g))))
t_4))))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 = g + t_0;
double t_2 = t_0 - g;
double t_3 = cbrt(((1.0 / (2.0 * a)) * t_2)) + cbrt((t_1 * (-1.0 / (2.0 * a))));
double t_4 = (cbrt((0.5 * t_2)) / cbrt(a)) + (cbrt((t_1 * -0.5)) / cbrt(a));
double tmp;
if (t_3 <= -5e-105) {
tmp = t_4;
} else if (t_3 <= 0.0) {
tmp = cbrt((t_2 * (0.5 / a))) + (cbrt((-0.5 / a)) * cbrt((g + g)));
} else {
tmp = t_4;
}
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 = g + t_0;
double t_2 = t_0 - g;
double t_3 = Math.cbrt(((1.0 / (2.0 * a)) * t_2)) + Math.cbrt((t_1 * (-1.0 / (2.0 * a))));
double t_4 = (Math.cbrt((0.5 * t_2)) / Math.cbrt(a)) + (Math.cbrt((t_1 * -0.5)) / Math.cbrt(a));
double tmp;
if (t_3 <= -5e-105) {
tmp = t_4;
} else if (t_3 <= 0.0) {
tmp = Math.cbrt((t_2 * (0.5 / a))) + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + g)));
} else {
tmp = t_4;
}
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(g + t_0) t_2 = Float64(t_0 - g) t_3 = Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * t_2)) + cbrt(Float64(t_1 * Float64(-1.0 / Float64(2.0 * a))))) t_4 = Float64(Float64(cbrt(Float64(0.5 * t_2)) / cbrt(a)) + Float64(cbrt(Float64(t_1 * -0.5)) / cbrt(a))) tmp = 0.0 if (t_3 <= -5e-105) tmp = t_4; elseif (t_3 <= 0.0) tmp = Float64(cbrt(Float64(t_2 * Float64(0.5 / a))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + g)))); else tmp = t_4; 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[(g + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 - g), $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * t$95$2), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$1 * N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[Power[N[(0.5 * t$95$2), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(t$95$1 * -0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -5e-105], t$95$4, If[LessEqual[t$95$3, 0.0], N[(N[Power[N[(t$95$2 * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$4]]]]]]]
\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 := g + t_0\\
t_2 := t_0 - g\\
t_3 := \sqrt[3]{\frac{1}{2 \cdot a} \cdot t_2} + \sqrt[3]{t_1 \cdot \frac{-1}{2 \cdot a}}\\
t_4 := \frac{\sqrt[3]{0.5 \cdot t_2}}{\sqrt[3]{a}} + \frac{\sqrt[3]{t_1 \cdot -0.5}}{\sqrt[3]{a}}\\
\mathbf{if}\;t_3 \leq -5 \cdot 10^{-105}:\\
\;\;\;\;t_4\\
\mathbf{elif}\;t_3 \leq 0:\\
\;\;\;\;\sqrt[3]{t_2 \cdot \frac{0.5}{a}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}\\
\mathbf{else}:\\
\;\;\;\;t_4\\
\end{array}
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.99999999999999963e-105 or -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))))))) Initial program 34.3
Simplified34.3
Applied egg-rr32.9
Applied egg-rr31.6
if -4.99999999999999963e-105 < (+.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 59.9
Simplified59.7
Applied egg-rr43.3
Taylor expanded in g around inf 7.8
Final simplification30.6
herbie shell --seed 2022206
(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))))))))