
(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 8 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 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around -inf 72.0%
neg-mul-172.0%
Simplified72.0%
associate-*l/72.1%
cbrt-div96.1%
*-commutative96.1%
associate-*r*96.1%
metadata-eval96.1%
neg-mul-196.1%
Applied egg-rr96.1%
Final simplification96.1%
(FPCore (g h a) :precision binary64 (if (or (<= a -2.5e-90) (not (<= a 3.8e-16))) (- (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ g a))) (+ (/ (cbrt (- g)) (cbrt a)) (cbrt g))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -2.5e-90) || !(a <= 3.8e-16)) {
tmp = cbrt(((g - g) * (-0.5 / a))) - cbrt((g / a));
} else {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(g);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -2.5e-90) || !(a <= 3.8e-16)) {
tmp = Math.cbrt(((g - g) * (-0.5 / a))) - Math.cbrt((g / a));
} else {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(g);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -2.5e-90) || !(a <= 3.8e-16)) tmp = Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) - cbrt(Float64(g / a))); else tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(g)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -2.5e-90], N[Not[LessEqual[a, 3.8e-16]], $MachinePrecision]], 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], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.5 \cdot 10^{-90} \lor \neg \left(a \leq 3.8 \cdot 10^{-16}\right):\\
\;\;\;\;\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} - \sqrt[3]{\frac{g}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{g}\\
\end{array}
\end{array}
if a < -2.5000000000000001e-90 or 3.80000000000000012e-16 < a Initial program 42.0%
Simplified42.0%
Taylor expanded in g around -inf 27.3%
*-commutative27.3%
Simplified27.3%
Taylor expanded in g around -inf 87.5%
neg-mul-187.5%
Simplified87.5%
Taylor expanded in g around -inf 87.6%
mul-1-neg87.6%
Simplified87.6%
if -2.5000000000000001e-90 < a < 3.80000000000000012e-16Initial program 44.7%
Simplified44.7%
Taylor expanded in g around -inf 22.0%
*-commutative22.0%
Simplified22.0%
Taylor expanded in g around inf 11.5%
Taylor expanded in a around 0 11.5%
Simplified49.0%
add-sqr-sqrt26.1%
sqrt-unprod11.9%
swap-sqr4.9%
count-24.9%
count-24.9%
swap-sqr4.9%
metadata-eval4.9%
metadata-eval4.9%
swap-sqr4.9%
*-commutative4.9%
*-commutative4.9%
frac-times4.9%
metadata-eval4.9%
metadata-eval4.9%
frac-times4.9%
swap-sqr11.9%
*-commutative11.9%
*-commutative11.9%
sqrt-unprod26.1%
add-sqr-sqrt49.0%
Applied egg-rr95.4%
Final simplification90.7%
(FPCore (g h a) :precision binary64 (if (or (<= a -1.22e-27) (not (<= a 1e-29))) (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (/ -1.0 (cbrt a))) (+ (cbrt g) (cbrt (/ (- g) a)))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -1.22e-27) || !(a <= 1e-29)) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + (-1.0 / cbrt(a));
} else {
tmp = cbrt(g) + cbrt((-g / a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -1.22e-27) || !(a <= 1e-29)) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + (-1.0 / Math.cbrt(a));
} else {
tmp = Math.cbrt(g) + Math.cbrt((-g / a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -1.22e-27) || !(a <= 1e-29)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + Float64(-1.0 / cbrt(a))); else tmp = Float64(cbrt(g) + cbrt(Float64(Float64(-g) / a))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -1.22e-27], N[Not[LessEqual[a, 1e-29]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.22 \cdot 10^{-27} \lor \neg \left(a \leq 10^{-29}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \frac{-1}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-g}{a}}\\
\end{array}
\end{array}
if a < -1.22e-27 or 9.99999999999999943e-30 < a Initial program 39.8%
Simplified39.8%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around inf 17.1%
*-un-lft-identity5.8%
*-commutative5.8%
Applied egg-rr0.0%
Simplified68.9%
if -1.22e-27 < a < 9.99999999999999943e-30Initial program 47.1%
Simplified47.1%
Taylor expanded in g around -inf 24.8%
*-commutative24.8%
Simplified24.8%
Taylor expanded in g around inf 12.4%
Taylor expanded in a around 0 12.4%
Simplified54.3%
Taylor expanded in g around 0 54.3%
associate-*r/54.3%
mul-1-neg54.3%
Simplified54.3%
Final simplification62.3%
(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 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around -inf 72.0%
neg-mul-172.0%
Simplified72.0%
Taylor expanded in g around -inf 72.1%
mul-1-neg72.1%
Simplified72.1%
Final simplification72.1%
(FPCore (g h a) :precision binary64 (- (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt g)))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g * -2.0))) - cbrt(g);
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g * -2.0))) - Math.cbrt(g);
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) - cbrt(g)) end
code[g_, h_, a_] := 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}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} - \sqrt[3]{g}
\end{array}
Initial program 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around inf 15.0%
Taylor expanded in g around 0 15.0%
Simplified27.9%
Final simplification27.9%
(FPCore (g h a) :precision binary64 (+ (cbrt g) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(g) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(g) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(g) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around inf 15.0%
Taylor expanded in a around 0 15.0%
Simplified27.6%
Taylor expanded in g around 0 27.6%
associate-*r/27.6%
mul-1-neg27.6%
Simplified27.6%
Final simplification27.6%
(FPCore (g h a) :precision binary64 (+ (cbrt g) (/ -1.0 (cbrt a))))
double code(double g, double h, double a) {
return cbrt(g) + (-1.0 / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(g) + (-1.0 / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(g) + Float64(-1.0 / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] + N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g} + \frac{-1}{\sqrt[3]{a}}
\end{array}
Initial program 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around inf 15.0%
Taylor expanded in a around 0 15.0%
Simplified27.6%
*-un-lft-identity27.6%
*-commutative27.6%
Applied egg-rr0.0%
Simplified4.9%
Final simplification4.9%
(FPCore (g h a) :precision binary64 (+ (cbrt g) (cbrt 0.0)))
double code(double g, double h, double a) {
return cbrt(g) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(g) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(cbrt(g) + cbrt(0.0)) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g} + \sqrt[3]{0}
\end{array}
Initial program 43.0%
Simplified43.0%
Taylor expanded in g around -inf 25.2%
*-commutative25.2%
Simplified25.2%
Taylor expanded in g around inf 15.0%
Taylor expanded in a around 0 15.0%
Simplified27.6%
add-log-exp4.3%
*-commutative4.3%
exp-prod4.2%
add-sqr-sqrt3.3%
sqrt-unprod3.9%
sqr-neg3.9%
sqrt-unprod3.0%
add-sqr-sqrt4.5%
sub-neg4.5%
+-inverses4.5%
metadata-eval4.5%
metadata-eval4.5%
Applied egg-rr4.5%
Final simplification4.5%
herbie shell --seed 2024066
(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))))))))