
(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 46.5%
Simplified46.5%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around -inf 76.5%
neg-mul-176.5%
Simplified76.5%
associate-*l/76.5%
cbrt-div95.8%
*-commutative95.8%
associate-*r*96.2%
metadata-eval96.2%
neg-mul-196.2%
Applied egg-rr96.2%
Final simplification96.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (- g g) (/ -0.5 a)))))
(if (<= a -6.2e-69)
(+ t_0 (cbrt (* (/ 0.5 a) (* g -2.0))))
(if (<= a 3.9e-36)
(+ (/ (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 <= -6.2e-69) {
tmp = t_0 + cbrt(((0.5 / a) * (g * -2.0)));
} else if (a <= 3.9e-36) {
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 <= -6.2e-69) {
tmp = t_0 + Math.cbrt(((0.5 / a) * (g * -2.0)));
} else if (a <= 3.9e-36) {
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 <= -6.2e-69) tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0)))); elseif (a <= 3.9e-36) tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(-2.0)); else tmp = Float64(t_0 + cbrt(Float64(1.0 / Float64(a / Float64(-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, -6.2e-69], N[(t$95$0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 3.9e-36], 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 -6.2 \cdot 10^{-69}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)}\\
\mathbf{elif}\;a \leq 3.9 \cdot 10^{-36}:\\
\;\;\;\;\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 < -6.1999999999999999e-69Initial program 45.8%
Simplified45.8%
Taylor expanded in g around -inf 24.2%
*-commutative24.2%
Simplified24.2%
Taylor expanded in g around -inf 89.6%
neg-mul-189.6%
Simplified89.6%
if -6.1999999999999999e-69 < a < 3.9000000000000001e-36Initial program 41.0%
Simplified41.0%
Taylor expanded in g around -inf 27.9%
*-commutative27.9%
Simplified27.9%
Taylor expanded in g around inf 11.5%
associate-*l/11.5%
associate-/l*11.5%
add-sqr-sqrt6.5%
sqrt-unprod11.1%
*-commutative11.1%
*-commutative11.1%
swap-sqr11.1%
metadata-eval11.1%
metadata-eval11.1%
swap-sqr11.1%
count-211.1%
count-211.1%
sqrt-unprod0.9%
add-sqr-sqrt1.9%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified44.7%
add-sqr-sqrt18.2%
sqrt-unprod6.4%
swap-sqr3.0%
count-23.0%
count-23.0%
swap-sqr3.0%
metadata-eval3.0%
metadata-eval3.0%
swap-sqr3.0%
*-commutative3.0%
*-commutative3.0%
frac-times3.0%
metadata-eval3.0%
metadata-eval3.0%
frac-times3.0%
swap-sqr6.4%
*-commutative6.4%
*-commutative6.4%
sqrt-unprod18.2%
add-sqr-sqrt44.7%
Applied egg-rr91.6%
if 3.9000000000000001e-36 < a Initial program 52.7%
Simplified52.7%
Taylor expanded in g around -inf 32.8%
*-commutative32.8%
Simplified32.8%
Taylor expanded in g around -inf 89.9%
neg-mul-189.9%
Simplified89.9%
associate-*l/90.0%
clear-num90.0%
*-commutative90.0%
associate-*r*91.2%
metadata-eval91.2%
neg-mul-191.2%
Applied egg-rr91.2%
Final simplification90.8%
(FPCore (g h a) :precision binary64 (if (or (<= g -1.8e+19) (not (<= g 1350000000.0))) (+ (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 <= -1.8e+19) || !(g <= 1350000000.0)) {
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 <= -1.8e+19) || !(g <= 1350000000.0)) {
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 <= -1.8e+19) || !(g <= 1350000000.0)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + Float64(-2.0 / cbrt(a))); else tmp = Float64(cbrt(Float64(-g)) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[g, -1.8e+19], N[Not[LessEqual[g, 1350000000.0]], $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 -1.8 \cdot 10^{+19} \lor \neg \left(g \leq 1350000000\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 < -1.8e19 or 1.35e9 < g Initial program 37.6%
Simplified37.6%
Taylor expanded in g around -inf 21.3%
*-commutative21.3%
Simplified21.3%
Taylor expanded in g around inf 15.3%
Applied egg-rr0.0%
Simplified71.5%
if -1.8e19 < g < 1.35e9Initial program 69.0%
Simplified69.0%
Taylor expanded in g around -inf 45.7%
*-commutative45.7%
Simplified45.7%
Taylor expanded in g around inf 16.6%
Taylor expanded in a around 0 16.6%
Simplified38.8%
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(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 46.5%
Simplified46.5%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around -inf 76.5%
neg-mul-176.5%
Simplified76.5%
associate-*l/76.5%
*-commutative76.5%
associate-*r*76.8%
metadata-eval76.8%
neg-mul-176.8%
Applied egg-rr76.8%
Final simplification76.8%
(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(Float64(-g) / 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 46.5%
Simplified46.5%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around inf 15.7%
associate-*l/15.7%
associate-/l*15.7%
add-sqr-sqrt7.9%
sqrt-unprod9.9%
*-commutative9.9%
*-commutative9.9%
swap-sqr9.9%
metadata-eval9.9%
metadata-eval9.9%
swap-sqr9.9%
count-29.9%
count-29.9%
sqrt-unprod1.8%
add-sqr-sqrt3.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified40.3%
Taylor expanded in g around 0 40.6%
neg-mul-140.6%
distribute-neg-frac40.6%
Simplified40.6%
Final simplification40.6%
(FPCore (g h a) :precision binary64 (+ (cbrt -2.0) (/ -2.0 (cbrt a))))
double code(double g, double h, double a) {
return cbrt(-2.0) + (-2.0 / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0) + (-2.0 / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(-2.0) + Float64(-2.0 / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[(-2.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2} + \frac{-2}{\sqrt[3]{a}}
\end{array}
Initial program 46.5%
Simplified46.5%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around inf 15.7%
associate-*l/15.7%
associate-/l*15.7%
add-sqr-sqrt7.9%
sqrt-unprod9.9%
*-commutative9.9%
*-commutative9.9%
swap-sqr9.9%
metadata-eval9.9%
metadata-eval9.9%
swap-sqr9.9%
count-29.9%
count-29.9%
sqrt-unprod1.8%
add-sqr-sqrt3.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified40.3%
Applied egg-rr0.0%
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 46.5%
Simplified46.5%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around inf 15.7%
associate-*l/15.7%
associate-/l*15.7%
add-sqr-sqrt7.9%
sqrt-unprod9.9%
*-commutative9.9%
*-commutative9.9%
swap-sqr9.9%
metadata-eval9.9%
metadata-eval9.9%
swap-sqr9.9%
count-29.9%
count-29.9%
sqrt-unprod1.8%
add-sqr-sqrt3.3%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified40.3%
Taylor expanded in g around 0 4.7%
Final simplification4.7%
herbie shell --seed 2024024
(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))))))))