
(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 (+ (/ (cbrt (- g)) (cbrt a)) (cbrt 0.0)))
double code(double g, double h, double a) {
return (cbrt(-g) / cbrt(a)) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(0.0)) end
code[g_, h_, a_] := N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{0}
\end{array}
Initial program 48.3%
Simplified48.3%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around inf 15.5%
associate-*l/15.5%
cbrt-div16.3%
*-commutative16.3%
associate-*r*16.3%
metadata-eval16.3%
neg-mul-116.3%
Applied egg-rr16.3%
add-log-exp34.2%
*-commutative34.2%
exp-prod47.1%
add-sqr-sqrt23.1%
sqrt-unprod46.1%
frac-times46.1%
metadata-eval46.1%
metadata-eval46.1%
frac-times46.1%
sqrt-unprod23.0%
add-sqr-sqrt45.3%
add-sqr-sqrt44.4%
sqrt-unprod59.2%
sqr-neg59.2%
sqrt-unprod58.1%
add-sqr-sqrt95.5%
sub-neg95.5%
+-inverses95.5%
metadata-eval95.5%
Applied egg-rr95.5%
Final simplification95.5%
(FPCore (g h a) :precision binary64 (if (or (<= g -3.4e+25) (not (<= g 3e-17))) (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (/ -2.0 (cbrt a))) (+ (cbrt g) (cbrt (* (/ -0.5 a) (+ g g))))))
double code(double g, double h, double a) {
double tmp;
if ((g <= -3.4e+25) || !(g <= 3e-17)) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + (-2.0 / cbrt(a));
} else {
tmp = cbrt(g) + cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((g <= -3.4e+25) || !(g <= 3e-17)) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + (-2.0 / Math.cbrt(a));
} else {
tmp = Math.cbrt(g) + Math.cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((g <= -3.4e+25) || !(g <= 3e-17)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + Float64(-2.0 / cbrt(a))); else tmp = Float64(cbrt(g) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[g, -3.4e+25], N[Not[LessEqual[g, 3e-17]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(-2.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 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}
\mathbf{if}\;g \leq -3.4 \cdot 10^{+25} \lor \neg \left(g \leq 3 \cdot 10^{-17}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \frac{-2}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\
\end{array}
\end{array}
if g < -3.39999999999999984e25 or 3.00000000000000006e-17 < g Initial program 35.4%
Simplified35.4%
Taylor expanded in g around -inf 17.8%
*-commutative17.8%
Simplified17.8%
Taylor expanded in g around inf 14.5%
Applied egg-rr0.0%
Simplified65.0%
if -3.39999999999999984e25 < g < 3.00000000000000006e-17Initial program 82.6%
Simplified82.6%
Taylor expanded in g around -inf 60.0%
*-commutative60.0%
Simplified60.0%
Taylor expanded in g around inf 18.1%
Taylor expanded in a around 0 18.1%
Simplified54.8%
Final simplification62.3%
(FPCore (g h a) :precision binary64 (if (or (<= g -3.85) (not (<= g 2.45e-12))) (+ (cbrt (/ (- g) a)) (cbrt -2.0)) (+ (cbrt g) (cbrt (* (/ -0.5 a) (+ g g))))))
double code(double g, double h, double a) {
double tmp;
if ((g <= -3.85) || !(g <= 2.45e-12)) {
tmp = cbrt((-g / a)) + cbrt(-2.0);
} else {
tmp = cbrt(g) + cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((g <= -3.85) || !(g <= 2.45e-12)) {
tmp = Math.cbrt((-g / a)) + Math.cbrt(-2.0);
} else {
tmp = Math.cbrt(g) + Math.cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((g <= -3.85) || !(g <= 2.45e-12)) tmp = Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(-2.0)); else tmp = Float64(cbrt(g) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[g, -3.85], N[Not[LessEqual[g, 2.45e-12]], $MachinePrecision]], N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[-2.0, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 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}
\mathbf{if}\;g \leq -3.85 \lor \neg \left(g \leq 2.45 \cdot 10^{-12}\right):\\
\;\;\;\;\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{-2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\
\end{array}
\end{array}
if g < -3.85000000000000009 or 2.44999999999999986e-12 < g Initial program 37.1%
Simplified37.1%
Taylor expanded in g around -inf 20.4%
*-commutative20.4%
Simplified20.4%
Taylor expanded in g around inf 14.6%
add-sqr-sqrt7.0%
sqrt-unprod10.4%
*-commutative10.4%
*-commutative10.4%
swap-sqr15.4%
*-commutative15.4%
*-commutative15.4%
swap-sqr15.4%
metadata-eval15.4%
metadata-eval15.4%
swap-sqr15.4%
count-215.4%
count-215.4%
frac-times16.3%
metadata-eval16.3%
metadata-eval16.3%
frac-times15.4%
swap-sqr10.4%
sqrt-unprod7.0%
add-sqr-sqrt14.6%
expm1-log1p-u10.0%
Applied egg-rr0.0%
Simplified41.7%
Taylor expanded in g around 0 41.7%
associate-*r/41.7%
mul-1-neg41.7%
Simplified41.7%
if -3.85000000000000009 < g < 2.44999999999999986e-12Initial program 81.3%
Simplified81.3%
Taylor expanded in g around -inf 55.8%
*-commutative55.8%
Simplified55.8%
Taylor expanded in g around inf 18.1%
Taylor expanded in a around 0 18.1%
Simplified53.7%
Final simplification44.7%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g) a)) (cbrt (* (- g g) (/ -0.5 a)))))
double code(double g, double h, double a) {
return cbrt((-g / a)) + cbrt(((g - g) * (-0.5 / a)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) + Math.cbrt(((g - g) * (-0.5 / a)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(Float64(Float64(g - g) * Float64(-0.5 / a)))) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Initial program 48.3%
Simplified48.3%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
associate-*l/75.0%
*-commutative75.0%
associate-*r*75.0%
metadata-eval75.0%
neg-mul-175.0%
Applied egg-rr75.0%
Final simplification75.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g) a)) (cbrt -2.0)))
double code(double g, double h, double a) {
return cbrt((-g / a)) + cbrt(-2.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) + Math.cbrt(-2.0);
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(-2.0)) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[-2.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{-2}
\end{array}
Initial program 48.3%
Simplified48.3%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around inf 15.5%
add-sqr-sqrt7.0%
sqrt-unprod14.6%
*-commutative14.6%
*-commutative14.6%
swap-sqr18.5%
*-commutative18.5%
*-commutative18.5%
swap-sqr18.5%
metadata-eval18.5%
metadata-eval18.5%
swap-sqr18.5%
count-218.5%
count-218.5%
frac-times19.1%
metadata-eval19.1%
metadata-eval19.1%
frac-times18.5%
swap-sqr14.6%
sqrt-unprod7.0%
add-sqr-sqrt15.5%
expm1-log1p-u10.7%
Applied egg-rr0.0%
Simplified41.6%
Taylor expanded in g around 0 41.6%
associate-*r/41.6%
mul-1-neg41.6%
Simplified41.6%
Final simplification41.6%
(FPCore (g h a) :precision binary64 (- (cbrt -2.0) (cbrt g)))
double code(double g, double h, double a) {
return cbrt(-2.0) - cbrt(g);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0) - Math.cbrt(g);
}
function code(g, h, a) return Float64(cbrt(-2.0) - cbrt(g)) end
code[g_, h_, a_] := N[(N[Power[-2.0, 1/3], $MachinePrecision] - N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2} - \sqrt[3]{g}
\end{array}
Initial program 48.3%
Simplified48.3%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around inf 15.5%
add-sqr-sqrt7.0%
sqrt-unprod14.6%
*-commutative14.6%
*-commutative14.6%
swap-sqr18.5%
*-commutative18.5%
*-commutative18.5%
swap-sqr18.5%
metadata-eval18.5%
metadata-eval18.5%
swap-sqr18.5%
count-218.5%
count-218.5%
frac-times19.1%
metadata-eval19.1%
metadata-eval19.1%
frac-times18.5%
swap-sqr14.6%
sqrt-unprod7.0%
add-sqr-sqrt15.5%
expm1-log1p-u10.7%
Applied egg-rr0.0%
Simplified41.6%
add-sqr-sqrt19.1%
sqrt-unprod8.7%
swap-sqr6.2%
count-26.2%
count-26.2%
swap-sqr6.2%
metadata-eval6.2%
metadata-eval6.2%
swap-sqr6.2%
*-commutative6.2%
*-commutative6.2%
frac-times6.1%
metadata-eval6.1%
metadata-eval6.1%
frac-times6.2%
swap-sqr8.7%
*-commutative8.7%
*-commutative8.7%
sqrt-unprod19.1%
Applied egg-rr41.1%
Simplified4.9%
Final simplification4.9%
(FPCore (g h a) :precision binary64 (cbrt -2.0))
double code(double g, double h, double a) {
return cbrt(-2.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0);
}
function code(g, h, a) return cbrt(-2.0) end
code[g_, h_, a_] := N[Power[-2.0, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2}
\end{array}
Initial program 48.3%
Simplified48.3%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around inf 15.5%
add-sqr-sqrt7.0%
sqrt-unprod14.6%
*-commutative14.6%
*-commutative14.6%
swap-sqr18.5%
*-commutative18.5%
*-commutative18.5%
swap-sqr18.5%
metadata-eval18.5%
metadata-eval18.5%
swap-sqr18.5%
count-218.5%
count-218.5%
frac-times19.1%
metadata-eval19.1%
metadata-eval19.1%
frac-times18.5%
swap-sqr14.6%
sqrt-unprod7.0%
add-sqr-sqrt15.5%
expm1-log1p-u10.7%
Applied egg-rr0.0%
Simplified41.6%
Taylor expanded in g around 0 4.8%
Final simplification4.8%
herbie shell --seed 2024020
(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))))))))