
(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 (* (- g g) (/ -0.5 a)))))
double code(double g, double h, double a) {
return (cbrt(-g) / cbrt(a)) + cbrt(((g - g) * (-0.5 / a)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((g - g) * (-0.5 / a)));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(g - g) * Float64(-0.5 / a)))) end
code[g_, h_, a_] := N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Initial program 47.1%
Simplified47.1%
Taylor expanded in g around -inf 29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in g around -inf 75.1%
neg-mul-175.1%
Simplified75.1%
associate-*l/75.1%
cbrt-div97.6%
*-commutative97.6%
associate-*r*97.6%
metadata-eval97.6%
neg-mul-197.6%
Applied egg-rr97.6%
Final simplification97.6%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (- g g) (/ -0.5 a)))))
(if (<= a -1.25e-47)
(- t_0 (cbrt (/ g a)))
(if (<= a 2.2e-33)
(+ (/ (cbrt (- g)) (cbrt a)) (cbrt -2.0))
(+ t_0 (cbrt (/ -1.0 (/ a g))))))))
double code(double g, double h, double a) {
double t_0 = cbrt(((g - g) * (-0.5 / a)));
double tmp;
if (a <= -1.25e-47) {
tmp = t_0 - cbrt((g / a));
} else if (a <= 2.2e-33) {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(-2.0);
} else {
tmp = t_0 + cbrt((-1.0 / (a / g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt(((g - g) * (-0.5 / a)));
double tmp;
if (a <= -1.25e-47) {
tmp = t_0 - Math.cbrt((g / a));
} else if (a <= 2.2e-33) {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(-2.0);
} else {
tmp = t_0 + Math.cbrt((-1.0 / (a / g)));
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) tmp = 0.0 if (a <= -1.25e-47) tmp = Float64(t_0 - cbrt(Float64(g / a))); elseif (a <= 2.2e-33) tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(-2.0)); else tmp = Float64(t_0 + cbrt(Float64(-1.0 / Float64(a / g)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[a, -1.25e-47], N[(t$95$0 - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 2.2e-33], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[-2.0, 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[Power[N[(-1.0 / N[(a / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}\\
\mathbf{if}\;a \leq -1.25 \cdot 10^{-47}:\\
\;\;\;\;t\_0 - \sqrt[3]{\frac{g}{a}}\\
\mathbf{elif}\;a \leq 2.2 \cdot 10^{-33}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{-2}\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \sqrt[3]{\frac{-1}{\frac{a}{g}}}\\
\end{array}
\end{array}
if a < -1.25000000000000003e-47Initial program 50.2%
Simplified50.2%
Taylor expanded in g around -inf 33.0%
*-commutative33.0%
Simplified33.0%
Taylor expanded in g around -inf 94.3%
neg-mul-194.3%
Simplified94.3%
Taylor expanded in g around -inf 94.3%
mul-1-neg94.3%
Simplified94.3%
if -1.25000000000000003e-47 < a < 2.20000000000000005e-33Initial program 39.1%
Simplified39.1%
Taylor expanded in g around -inf 23.4%
*-commutative23.4%
Simplified23.4%
Taylor expanded in g around inf 11.5%
add-sqr-sqrt6.4%
sqrt-unprod3.9%
swap-sqr7.0%
frac-times7.1%
metadata-eval7.1%
metadata-eval7.1%
frac-times7.0%
*-commutative7.0%
*-commutative7.0%
swap-sqr7.0%
metadata-eval7.0%
metadata-eval7.0%
swap-sqr7.0%
count-27.0%
count-27.0%
swap-sqr3.9%
*-commutative3.9%
*-commutative3.9%
sqrt-unprod6.4%
add-sqr-sqrt11.5%
associate-*r/11.5%
Applied egg-rr0.0%
Simplified42.9%
Applied egg-rr89.7%
if 2.20000000000000005e-33 < a Initial program 55.8%
Simplified55.8%
Taylor expanded in g around -inf 33.4%
*-commutative33.4%
Simplified33.4%
Taylor expanded in g around -inf 91.2%
neg-mul-191.2%
Simplified91.2%
associate-*l/91.3%
clear-num91.3%
*-commutative91.3%
associate-*r*91.3%
metadata-eval91.3%
neg-mul-191.3%
Applied egg-rr91.3%
Final simplification91.6%
(FPCore (g h a) :precision binary64 (if (or (<= g -40.0) (not (<= g 1.5e+65))) (+ (cbrt -2.0) (cbrt (/ g (- a)))) (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt g))))
double code(double g, double h, double a) {
double tmp;
if ((g <= -40.0) || !(g <= 1.5e+65)) {
tmp = cbrt(-2.0) + cbrt((g / -a));
} else {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + cbrt(g);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((g <= -40.0) || !(g <= 1.5e+65)) {
tmp = Math.cbrt(-2.0) + Math.cbrt((g / -a));
} else {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(g);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((g <= -40.0) || !(g <= 1.5e+65)) tmp = Float64(cbrt(-2.0) + cbrt(Float64(g / Float64(-a)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(g)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[g, -40.0], N[Not[LessEqual[g, 1.5e+65]], $MachinePrecision]], N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -40 \lor \neg \left(g \leq 1.5 \cdot 10^{+65}\right):\\
\;\;\;\;\sqrt[3]{-2} + \sqrt[3]{\frac{g}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{g}\\
\end{array}
\end{array}
if g < -40 or 1.5000000000000001e65 < g Initial program 33.0%
Simplified33.0%
Taylor expanded in g around -inf 24.7%
*-commutative24.7%
Simplified24.7%
Taylor expanded in g around inf 14.3%
add-sqr-sqrt6.9%
sqrt-unprod8.0%
swap-sqr14.0%
frac-times14.0%
metadata-eval14.0%
metadata-eval14.0%
frac-times14.0%
*-commutative14.0%
*-commutative14.0%
swap-sqr14.0%
metadata-eval14.0%
metadata-eval14.0%
swap-sqr14.0%
count-214.0%
count-214.0%
swap-sqr8.0%
*-commutative8.0%
*-commutative8.0%
sqrt-unprod6.9%
add-sqr-sqrt14.3%
associate-*r/14.3%
Applied egg-rr0.0%
Simplified46.1%
Taylor expanded in g around 0 46.1%
neg-mul-146.1%
distribute-neg-frac246.1%
Simplified46.1%
if -40 < g < 1.5000000000000001e65Initial program 76.4%
Simplified76.4%
Taylor expanded in g around -inf 38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in g around inf 17.4%
Taylor expanded in g around 0 17.4%
Simplified38.7%
Final simplification43.7%
(FPCore (g h a) :precision binary64 (- (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt(((g - g) * (-0.5 / a))) - cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - g) * (-0.5 / a))) - Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) - cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 47.1%
Simplified47.1%
Taylor expanded in g around -inf 29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in g around -inf 75.1%
neg-mul-175.1%
Simplified75.1%
Taylor expanded in g around -inf 75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification75.1%
(FPCore (g h a) :precision binary64 (+ (cbrt -2.0) (cbrt (/ g (- a)))))
double code(double g, double h, double a) {
return cbrt(-2.0) + cbrt((g / -a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0) + Math.cbrt((g / -a));
}
function code(g, h, a) return Float64(cbrt(-2.0) + cbrt(Float64(g / Float64(-a)))) end
code[g_, h_, a_] := N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2} + \sqrt[3]{\frac{g}{-a}}
\end{array}
Initial program 47.1%
Simplified47.1%
Taylor expanded in g around -inf 29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in g around inf 15.3%
add-sqr-sqrt8.0%
sqrt-unprod17.3%
swap-sqr23.0%
frac-times23.3%
metadata-eval23.3%
metadata-eval23.3%
frac-times23.0%
*-commutative23.0%
*-commutative23.0%
swap-sqr23.0%
metadata-eval23.0%
metadata-eval23.0%
swap-sqr23.0%
count-223.0%
count-223.0%
swap-sqr17.3%
*-commutative17.3%
*-commutative17.3%
sqrt-unprod8.0%
add-sqr-sqrt15.3%
associate-*r/15.3%
Applied egg-rr0.0%
Simplified39.6%
Taylor expanded in g around 0 39.7%
neg-mul-139.7%
distribute-neg-frac239.7%
Simplified39.7%
Final simplification39.7%
(FPCore (g h a) :precision binary64 (+ (cbrt -2.0) (cbrt 0.0)))
double code(double g, double h, double a) {
return cbrt(-2.0) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(cbrt(-2.0) + cbrt(0.0)) end
code[g_, h_, a_] := N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2} + \sqrt[3]{0}
\end{array}
Initial program 47.1%
Simplified47.1%
Taylor expanded in g around -inf 29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in g around inf 15.3%
add-sqr-sqrt8.0%
sqrt-unprod17.3%
swap-sqr23.0%
frac-times23.3%
metadata-eval23.3%
metadata-eval23.3%
frac-times23.0%
*-commutative23.0%
*-commutative23.0%
swap-sqr23.0%
metadata-eval23.0%
metadata-eval23.0%
swap-sqr23.0%
count-223.0%
count-223.0%
swap-sqr17.3%
*-commutative17.3%
*-commutative17.3%
sqrt-unprod8.0%
add-sqr-sqrt15.3%
associate-*r/15.3%
Applied egg-rr0.0%
Simplified39.6%
add-log-exp4.4%
*-commutative4.4%
exp-prod4.5%
add-sqr-sqrt3.5%
sqrt-unprod4.3%
sqr-neg4.3%
sqrt-unprod3.3%
add-sqr-sqrt4.4%
sub-neg4.4%
+-inverses4.4%
metadata-eval4.4%
metadata-eval4.4%
Applied egg-rr4.4%
Final simplification4.4%
(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 47.1%
Simplified47.1%
Taylor expanded in g around -inf 29.1%
*-commutative29.1%
Simplified29.1%
Taylor expanded in g around inf 15.3%
add-sqr-sqrt8.0%
sqrt-unprod17.3%
swap-sqr23.0%
frac-times23.3%
metadata-eval23.3%
metadata-eval23.3%
frac-times23.0%
*-commutative23.0%
*-commutative23.0%
swap-sqr23.0%
metadata-eval23.0%
metadata-eval23.0%
swap-sqr23.0%
count-223.0%
count-223.0%
swap-sqr17.3%
*-commutative17.3%
*-commutative17.3%
sqrt-unprod8.0%
add-sqr-sqrt15.3%
associate-*r/15.3%
Applied egg-rr0.0%
Simplified39.6%
Taylor expanded in g around 0 39.7%
Simplified4.7%
Final simplification4.7%
herbie shell --seed 2024115
(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))))))))