
(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 6 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.9%
Simplified44.2%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around -inf 74.6%
neg-mul-174.6%
Simplified74.6%
associate-*l/74.7%
cbrt-div96.1%
*-commutative96.1%
associate-*r*96.4%
metadata-eval96.4%
neg-mul-196.4%
Applied egg-rr96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (if (or (<= a -2.4e-126) (not (<= a 3.35e-112))) (+ (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ (- g) a))) (+ (/ (cbrt (- g)) (cbrt a)) (cbrt -2.0))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -2.4e-126) || !(a <= 3.35e-112)) {
tmp = cbrt(((g - g) * (-0.5 / a))) + cbrt((-g / a));
} else {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(-2.0);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -2.4e-126) || !(a <= 3.35e-112)) {
tmp = Math.cbrt(((g - g) * (-0.5 / a))) + Math.cbrt((-g / a));
} else {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(-2.0);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -2.4e-126) || !(a <= 3.35e-112)) tmp = Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) + cbrt(Float64(Float64(-g) / a))); else tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(-2.0)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -2.4e-126], N[Not[LessEqual[a, 3.35e-112]], $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[-2.0, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.4 \cdot 10^{-126} \lor \neg \left(a \leq 3.35 \cdot 10^{-112}\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]{-2}\\
\end{array}
\end{array}
if a < -2.40000000000000007e-126 or 3.3499999999999999e-112 < a Initial program 49.5%
Simplified50.1%
Taylor expanded in g around -inf 32.9%
*-commutative32.9%
Simplified32.9%
Taylor expanded in g around -inf 92.8%
neg-mul-192.8%
Simplified92.8%
associate-*l/92.9%
*-commutative92.9%
associate-*r*93.5%
metadata-eval93.5%
neg-mul-193.5%
Applied egg-rr93.5%
if -2.40000000000000007e-126 < a < 3.3499999999999999e-112Initial program 32.7%
Simplified32.7%
Taylor expanded in g around -inf 16.5%
*-commutative16.5%
Simplified16.5%
Taylor expanded in g around inf 10.0%
Taylor expanded in a around 0 10.0%
Simplified33.8%
add-sqr-sqrt16.3%
sqrt-unprod5.9%
swap-sqr3.6%
count-23.6%
count-23.6%
swap-sqr3.6%
metadata-eval3.6%
metadata-eval3.6%
swap-sqr3.6%
*-commutative3.6%
*-commutative3.6%
frac-times3.6%
metadata-eval3.6%
metadata-eval3.6%
frac-times3.6%
swap-sqr5.9%
*-commutative5.9%
*-commutative5.9%
sqrt-unprod16.3%
add-sqr-sqrt33.8%
Applied egg-rr90.9%
Final simplification92.6%
(FPCore (g h a) :precision binary64 (+ (* (cbrt (/ 0.5 a)) (cbrt (* g -2.0))) (cbrt 0.0)))
double code(double g, double h, double a) {
return (cbrt((0.5 / a)) * cbrt((g * -2.0))) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return (Math.cbrt((0.5 / a)) * Math.cbrt((g * -2.0))) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(g * -2.0))) + cbrt(0.0)) end
code[g_, h_, a_] := N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g \cdot -2} + \sqrt[3]{0}
\end{array}
Initial program 43.9%
Simplified44.2%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.4%
cbrt-prod16.9%
Applied egg-rr16.9%
add-sqr-sqrt8.1%
sqrt-unprod30.6%
sqr-neg30.6%
sqrt-unprod33.3%
add-sqr-sqrt96.1%
sub-neg96.1%
+-inverses96.1%
associate-*r/96.1%
metadata-eval96.1%
metadata-eval96.1%
associate-*r/96.1%
mul0-lft96.1%
Applied egg-rr96.1%
Final simplification96.1%
(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 43.9%
Simplified44.2%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around -inf 74.6%
neg-mul-174.6%
Simplified74.6%
associate-*l/74.7%
*-commutative74.7%
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 43.9%
Simplified44.2%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.4%
Taylor expanded in a around 0 15.4%
Simplified43.1%
Taylor expanded in g around 0 43.5%
associate-*r/43.5%
mul-1-neg43.5%
Simplified43.5%
Final simplification43.5%
(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 43.9%
Simplified44.2%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.4%
Taylor expanded in a around 0 15.4%
Simplified43.1%
Taylor expanded in g around 0 4.5%
Final simplification4.5%
herbie shell --seed 2024040
(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))))))))