
(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}
NOTE: h should be positive before calling this function
(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 1.55e-162)
(+ t_1 (/ (cbrt (* (+ g (hypot g (sqrt (- (* h h))))) -0.5)) (cbrt a)))
(+ t_1 (cbrt (* (+ g t_0) (/ -0.5 a)))))))h = abs(h);
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 <= 1.55e-162) {
tmp = t_1 + (cbrt(((g + hypot(g, sqrt(-(h * h)))) * -0.5)) / cbrt(a));
} else {
tmp = t_1 + cbrt(((g + t_0) * (-0.5 / a)));
}
return tmp;
}
h = Math.abs(h);
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 <= 1.55e-162) {
tmp = t_1 + (Math.cbrt(((g + Math.hypot(g, Math.sqrt(-(h * h)))) * -0.5)) / Math.cbrt(a));
} else {
tmp = t_1 + Math.cbrt(((g + t_0) * (-0.5 / a)));
}
return tmp;
}
h = abs(h) 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 (h <= 1.55e-162) tmp = Float64(t_1 + Float64(cbrt(Float64(Float64(g + hypot(g, sqrt(Float64(-Float64(h * h))))) * -0.5)) / cbrt(a))); else tmp = Float64(t_1 + cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a)))); end return tmp end
NOTE: h should be positive before calling this function
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[h, 1.55e-162], N[(t$95$1 + N[(N[Power[N[(N[(g + N[Sqrt[g ^ 2 + N[Sqrt[(-N[(h * h), $MachinePrecision])], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
h = |h|\\
\\
\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 \leq 1.55 \cdot 10^{-162}:\\
\;\;\;\;t_1 + \frac{\sqrt[3]{\left(g + \mathsf{hypot}\left(g, \sqrt{-h \cdot h}\right)\right) \cdot -0.5}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\end{array}
\end{array}
if h < 1.5499999999999999e-162Initial program 44.0%
Simplified44.0%
associate-*r/44.0%
cbrt-div47.5%
sub-neg47.5%
add-sqr-sqrt34.8%
hypot-def36.5%
distribute-rgt-neg-in36.5%
Applied egg-rr36.5%
if 1.5499999999999999e-162 < h Initial program 39.9%
Simplified39.9%
Final simplification37.5%
NOTE: h should be positive before calling this function
(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 1.55e-162)
(+ t_1 (* (cbrt (/ -0.5 a)) (cbrt (+ g (hypot g (sqrt (- (* h h))))))))
(+ t_1 (cbrt (* (+ g t_0) (/ -0.5 a)))))))h = abs(h);
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 <= 1.55e-162) {
tmp = t_1 + (cbrt((-0.5 / a)) * cbrt((g + hypot(g, sqrt(-(h * h))))));
} else {
tmp = t_1 + cbrt(((g + t_0) * (-0.5 / a)));
}
return tmp;
}
h = Math.abs(h);
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 <= 1.55e-162) {
tmp = t_1 + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + Math.hypot(g, Math.sqrt(-(h * h))))));
} else {
tmp = t_1 + Math.cbrt(((g + t_0) * (-0.5 / a)));
}
return tmp;
}
h = abs(h) 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 (h <= 1.55e-162) tmp = Float64(t_1 + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + hypot(g, sqrt(Float64(-Float64(h * h)))))))); else tmp = Float64(t_1 + cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a)))); end return tmp end
NOTE: h should be positive before calling this function
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[h, 1.55e-162], N[(t$95$1 + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + N[Sqrt[g ^ 2 + N[Sqrt[(-N[(h * h), $MachinePrecision])], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
h = |h|\\
\\
\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 \leq 1.55 \cdot 10^{-162}:\\
\;\;\;\;t_1 + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + \mathsf{hypot}\left(g, \sqrt{-h \cdot h}\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1 + \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}\\
\end{array}
\end{array}
if h < 1.5499999999999999e-162Initial program 44.0%
Simplified44.0%
cbrt-prod47.5%
*-commutative47.5%
sub-neg47.5%
add-sqr-sqrt34.8%
hypot-def36.4%
distribute-rgt-neg-in36.4%
Applied egg-rr36.4%
if 1.5499999999999999e-162 < h Initial program 39.9%
Simplified39.9%
Final simplification37.5%
NOTE: h should be positive before calling this function (FPCore (g h a) :precision binary64 (let* ((t_0 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* (/ 0.5 a) (- t_0 g))) (cbrt (* (+ g t_0) (/ -0.5 a))))))
h = abs(h);
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
return cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((g + t_0) * (-0.5 / a)));
}
h = Math.abs(h);
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((g + t_0) * (-0.5 / a)));
}
h = abs(h) function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(g + t_0) * Float64(-0.5 / a)))) end
NOTE: h should be positive before calling this function
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(t$95$0 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(g + t$95$0), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
h = |h|\\
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\left(g + t_0\right) \cdot \frac{-0.5}{a}}
\end{array}
\end{array}
Initial program 42.7%
Simplified42.7%
Final simplification42.7%
NOTE: h should be positive before calling this function
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h)))))
(if (<= g 1e-173)
(+
(cbrt (* (/ 0.5 a) (- t_0 g)))
(cbrt (* (/ -0.5 a) (* 0.5 (/ h (/ g h))))))
(+ (cbrt (* (+ g t_0) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (- g g)))))))h = abs(h);
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 1e-173) {
tmp = cbrt(((0.5 / a) * (t_0 - g))) + cbrt(((-0.5 / a) * (0.5 * (h / (g / h)))));
} else {
tmp = cbrt(((g + t_0) * (-0.5 / a))) + cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
h = Math.abs(h);
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double tmp;
if (g <= 1e-173) {
tmp = Math.cbrt(((0.5 / a) * (t_0 - g))) + Math.cbrt(((-0.5 / a) * (0.5 * (h / (g / h)))));
} else {
tmp = Math.cbrt(((g + t_0) * (-0.5 / a))) + Math.cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
h = abs(h) function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) tmp = 0.0 if (g <= 1e-173) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(t_0 - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(0.5 * Float64(h / Float64(g / h)))))); 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
NOTE: h should be positive before calling this function
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-173], 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[(0.5 * N[(h / N[(g / h), $MachinePrecision]), $MachinePrecision]), $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}
h = |h|\\
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
\mathbf{if}\;g \leq 10^{-173}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(t_0 - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(0.5 \cdot \frac{h}{\frac{g}{h}}\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-173Initial program 42.8%
Simplified42.8%
Taylor expanded in g around -inf 44.3%
unpow244.3%
associate-/l*44.3%
Simplified44.3%
if 1e-173 < g Initial program 42.7%
Simplified42.7%
Taylor expanded in g around inf 43.7%
Final simplification44.0%
NOTE: h should be positive before calling this function
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -0.5 a)))))
(if (<= g -1.55e-162)
(+ t_0 (cbrt (* (/ 0.5 a) (- (- g) g))))
(+ t_0 (cbrt (* (/ 0.5 a) (- g g)))))))h = abs(h);
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.55e-162) {
tmp = t_0 + cbrt(((0.5 / a) * (-g - g)));
} else {
tmp = t_0 + cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
h = Math.abs(h);
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.55e-162) {
tmp = t_0 + Math.cbrt(((0.5 / a) * (-g - g)));
} else {
tmp = t_0 + Math.cbrt(((0.5 / a) * (g - g)));
}
return tmp;
}
h = abs(h) 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.55e-162) tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(Float64(-g) - g)))); else tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))); end return tmp end
NOTE: h should be positive before calling this function
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.55e-162], N[(t$95$0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[((-g) - g), $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}
h = |h|\\
\\
\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.55 \cdot 10^{-162}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left(-g\right) - g\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\end{array}
\end{array}
if g < -1.5499999999999999e-162Initial program 44.6%
Simplified44.6%
Taylor expanded in g around -inf 44.0%
mul-1-neg44.0%
Simplified44.0%
if -1.5499999999999999e-162 < g Initial program 40.9%
Simplified40.9%
Taylor expanded in g around inf 42.0%
Final simplification43.0%
NOTE: h should be positive before calling this function (FPCore (g h a) :precision binary64 (+ (cbrt (* (+ g (sqrt (- (* g g) (* h h)))) (/ -0.5 a))) (cbrt (* (/ 0.5 a) (- g g)))))
h = abs(h);
double code(double g, double h, double a) {
return cbrt(((g + sqrt(((g * g) - (h * h)))) * (-0.5 / a))) + cbrt(((0.5 / a) * (g - g)));
}
h = Math.abs(h);
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 - g)));
}
h = abs(h) 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 - g)))) end
NOTE: h should be positive before calling this function 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 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
h = |h|\\
\\
\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 - g\right)}
\end{array}
Initial program 42.7%
Simplified42.7%
Taylor expanded in g around inf 22.1%
Final simplification22.1%
NOTE: h should be positive before calling this function (FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- (sqrt (- (* g g) (* h h))) g))) (cbrt (* (/ -0.5 a) (+ g g)))))
h = abs(h);
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (sqrt(((g * g) - (h * h))) - g))) + cbrt(((-0.5 / a) * (g + g)));
}
h = Math.abs(h);
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (Math.sqrt(((g * g) - (h * h))) - g))) + Math.cbrt(((-0.5 / a) * (g + g)));
}
h = abs(h) function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(sqrt(Float64(Float64(g * g) - Float64(h * h))) - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))) end
NOTE: h should be positive before calling this function code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - g), $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}
h = |h|\\
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(\sqrt{g \cdot g - h \cdot h} - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}
\end{array}
Initial program 42.7%
Simplified42.7%
Taylor expanded in g around inf 25.6%
Final simplification25.6%
herbie shell --seed 2023287
(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))))))))