
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1)))) end
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]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t_0 \cdot \left(\left(-g\right) + t_1\right)} + \sqrt[3]{t_0 \cdot \left(\left(-g\right) - t_1\right)}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1)))) end
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]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t_0 \cdot \left(\left(-g\right) + t_1\right)} + \sqrt[3]{t_0 \cdot \left(\left(-g\right) - t_1\right)}
\end{array}
\end{array}
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (cbrt (* (+ g t_0) (/ -0.5 a)))))
(if (<= (* h h) 0.0)
(+ (/ (cbrt (* 0.5 (- (hypot g (sqrt (* h (- h)))) g))) (cbrt a)) t_1)
(+ t_1 (cbrt (* (/ 0.5 a) (- t_0 g)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if ((h * h) <= 0.0) {
tmp = (cbrt((0.5 * (hypot(g, sqrt((h * -h))) - g))) / cbrt(a)) + t_1;
} else {
tmp = t_1 + cbrt(((0.5 / a) * (t_0 - g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if ((h * h) <= 0.0) {
tmp = (Math.cbrt((0.5 * (Math.hypot(g, Math.sqrt((h * -h))) - g))) / Math.cbrt(a)) + t_1;
} else {
tmp = t_1 + Math.cbrt(((0.5 / a) * (t_0 - g)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) tmp = 0.0 if (Float64(h * h) <= 0.0) tmp = Float64(Float64(cbrt(Float64(0.5 * Float64(hypot(g, sqrt(Float64(h * Float64(-h)))) - g))) / cbrt(a)) + t_1); else tmp = Float64(t_1 + cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g)))); end return tmp end
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[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(N[(N[Power[N[(0.5 * N[(N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision], N[(t$95$1 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;\frac{\sqrt[3]{0.5 \cdot \left(\mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right) - g\right)}}{\sqrt[3]{a}} + t_1\\
\mathbf{else}:\\
\;\;\;\;t_1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 46.7%
Simplified46.7%
associate-*l/46.7%
cbrt-div53.4%
sub-neg53.4%
add-sqr-sqrt53.4%
hypot-def54.3%
distribute-rgt-neg-in54.3%
Applied egg-rr54.3%
if 0.0 < (*.f64 h h) Initial program 31.1%
Simplified31.1%
Final simplification40.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (cbrt (* (/ 0.5 a) (- t_0 g)))))
(if (<= (* h h) 0.0)
(+ t_1 (/ (cbrt (* -0.5 (+ g (hypot g (sqrt (* h (- h))))))) (cbrt a)))
(+ (cbrt (* (+ g t_0) (/ -0.5 a))) t_1))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = cbrt(((0.5 / a) * (t_0 - g)));
double tmp;
if ((h * h) <= 0.0) {
tmp = t_1 + (cbrt((-0.5 * (g + hypot(g, sqrt((h * -h)))))) / cbrt(a));
} else {
tmp = cbrt(((g + t_0) * (-0.5 / a))) + t_1;
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.cbrt(((0.5 / a) * (t_0 - g)));
double tmp;
if ((h * h) <= 0.0) {
tmp = t_1 + (Math.cbrt((-0.5 * (g + Math.hypot(g, Math.sqrt((h * -h)))))) / Math.cbrt(a));
} else {
tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + t_1;
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) tmp = 0.0 if (Float64(h * h) <= 0.0) tmp = Float64(t_1 + Float64(cbrt(Float64(-0.5 * Float64(g + hypot(g, sqrt(Float64(h * Float64(-h))))))) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + t_1); end return tmp end
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[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(t$95$1 + N[(N[Power[N[(-0.5 * N[(g + N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + t$95$1), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;t_1 + \frac{\sqrt[3]{-0.5 \cdot \left(g + \mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right)\right)}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + t_1\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 46.7%
Simplified46.7%
associate-*r/46.7%
cbrt-div50.3%
sub-neg50.3%
add-sqr-sqrt50.3%
hypot-def52.9%
distribute-rgt-neg-in52.9%
Applied egg-rr52.9%
if 0.0 < (*.f64 h h) Initial program 31.1%
Simplified31.1%
Final simplification39.8%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (cbrt (* (+ g t_0) (/ -0.5 a)))))
(if (<= (* h h) 0.0)
(+ t_1 (* (cbrt (/ 0.5 a)) (cbrt (- (hypot g (sqrt (* h (- h)))) g))))
(+ t_1 (cbrt (* (/ 0.5 a) (- t_0 g)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if ((h * h) <= 0.0) {
tmp = t_1 + (cbrt((0.5 / a)) * cbrt((hypot(g, sqrt((h * -h))) - g)));
} else {
tmp = t_1 + cbrt(((0.5 / a) * (t_0 - g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.cbrt(((g + t_0) * (-0.5 / a)));
double tmp;
if ((h * h) <= 0.0) {
tmp = t_1 + (Math.cbrt((0.5 / a)) * Math.cbrt((Math.hypot(g, Math.sqrt((h * -h))) - g)));
} else {
tmp = t_1 + Math.cbrt(((0.5 / a) * (t_0 - g)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) tmp = 0.0 if (Float64(h * h) <= 0.0) tmp = Float64(t_1 + Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(hypot(g, sqrt(Float64(h * Float64(-h)))) - g)))); else tmp = Float64(t_1 + cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g)))); end return tmp end
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[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 0.0], N[(t$95$1 + N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[Sqrt[g ^ 2 + N[Sqrt[N[(h * (-h)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] - g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;h \cdot h \leq 0:\\
\;\;\;\;t_1 + \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, \sqrt{h \cdot \left(-h\right)}\right) - g}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)}\\
\end{array}
\end{array}
if (*.f64 h h) < 0.0Initial program 46.7%
Simplified46.7%
cbrt-prod53.4%
sub-neg53.4%
add-sqr-sqrt53.4%
hypot-def54.2%
distribute-rgt-neg-in54.2%
Applied egg-rr54.2%
if 0.0 < (*.f64 h h) Initial program 31.1%
Simplified31.1%
Final simplification40.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= g 4e-300)
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ -0.5 a) (- g g))))
(+
(cbrt (* (+ g t_0) (/ -0.5 a)))
(cbrt (* (/ 0.5 a) (/ (* (* h h) -0.5) g)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 4e-300) {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = cbrt(((g + t_0) * (-0.5 / a))) + cbrt(((0.5 / a) * (((h * h) * -0.5) / g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 4e-300) {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (((h * h) * -0.5) / g)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (g <= 4e-300) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g)))); else tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(Float64(Float64(h * h) * -0.5) / g)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[g, 4e-300], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(N[(h * h), $MachinePrecision] * -0.5), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq 4 \cdot 10^{-300}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \frac{\left(h \cdot h\right) \cdot -0.5}{g}}\\
\end{array}
\end{array}
if g < 4.0000000000000001e-300Initial program 36.2%
Simplified36.2%
Taylor expanded in g around -inf 37.6%
neg-mul-137.6%
Simplified37.6%
if 4.0000000000000001e-300 < g Initial program 38.5%
Simplified38.5%
Taylor expanded in g around inf 41.3%
associate-*r/41.3%
unpow241.3%
Simplified41.3%
Final simplification39.4%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -0.5 a)))))
(if (<= g -1.6e-162)
(+ t_0 (cbrt (* (/ 0.5 a) (* g -2.0))))
(+ t_0 (cbrt (* (/ 0.5 a) (- g g)))))))
double code(double g, double h, double a) {
double t_0 = cbrt(((g + sqrt(((g * g) - (h * h)))) * (-0.5 / a)));
double tmp;
if (g <= -1.6e-162) {
tmp = t_0 + cbrt(((0.5 / a) * (g * -2.0)));
} else {
tmp = t_0 + cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt(((g + Math.sqrt(((g * g) - (h * h)))) * (-0.5 / a)));
double tmp;
if (g <= -1.6e-162) {
tmp = t_0 + Math.cbrt(((0.5 / a) * (g * -2.0)));
} else {
tmp = t_0 + Math.cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(g + sqrt(Float64(Float64(g * g) - Float64(h * h)))) * Float64(-0.5 / a))) tmp = 0.0 if (g <= -1.6e-162) tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0)))); else tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(N[(g + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[g, -1.6e-162], N[(t$95$0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;g \leq -1.6 \cdot 10^{-162}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\end{array}
\end{array}
if g < -1.59999999999999988e-162Initial program 37.3%
Simplified37.3%
Taylor expanded in g around -inf 37.4%
*-commutative37.4%
Simplified37.4%
if -1.59999999999999988e-162 < g Initial program 37.3%
Simplified37.3%
Taylor expanded in g around inf 38.9%
Final simplification38.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= g 1e-175)
(+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (/ -0.5 a) (- g g))))
(+ (cbrt (* (+ g t_0) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (- g g)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 1e-175) {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = cbrt(((g + t_0) * (-0.5 / a))) + cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 1e-175) {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (g <= 1e-175) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g)))); else tmp = Float64(cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[g, 1e-175], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq 10^{-175}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\end{array}
\end{array}
if g < 1e-175Initial program 35.6%
Simplified35.6%
Taylor expanded in g around -inf 37.0%
neg-mul-137.0%
Simplified37.0%
if 1e-175 < g Initial program 39.3%
Simplified39.3%
Taylor expanded in g around inf 41.0%
Final simplification38.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (* g -2.0)))))
double code(double g, double h, double a) {
return cbrt(((g + sqrt(((g * g) - (h * h)))) * (-0.5 / a))) + cbrt(((0.5 / a) * (g * -2.0)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g + Math.sqrt(((g * g) - (h * h)))) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (g * -2.0)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g + sqrt(Float64(Float64(g * g) - Float64(h * h)))) * Float64(-0.5 / a))) + cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(g + \sqrt{g \cdot g - h \cdot h}\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)}
\end{array}
Initial program 37.3%
Simplified37.3%
Taylor expanded in g around -inf 23.7%
*-commutative23.7%
Simplified23.7%
Final simplification23.7%
herbie shell --seed 2023285
(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))))))))