
(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 9 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 (/ 0.0 a)) (* (cbrt (/ -0.5 a)) (cbrt (+ g g)))))
double code(double g, double h, double a) {
return cbrt((0.0 / a)) + (cbrt((-0.5 / a)) * cbrt((g + g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.0 / a)) + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + g)));
}
function code(g, h, a) return Float64(cbrt(Float64(0.0 / a)) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + g)))) end
code[g_, h_, a_] := N[(N[Power[N[(0.0 / a), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0}{a}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}
\end{array}
Initial program 45.8%
Simplified45.8%
*-commutative45.8%
cbrt-prod48.1%
pow248.1%
pow248.1%
Applied egg-rr48.1%
Taylor expanded in g around inf 32.5%
pow1/232.5%
difference-of-squares32.6%
unpow-prod-down35.2%
Applied egg-rr35.2%
unpow1/235.2%
unpow1/235.2%
+-commutative35.2%
Simplified35.2%
Taylor expanded in g around inf 96.4%
associate-*r/96.4%
distribute-rgt1-in96.4%
metadata-eval96.4%
mul0-lft96.4%
metadata-eval96.4%
Simplified96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (if (or (<= a -6e-127) (not (<= a 6.8e-50))) (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt (* (/ -0.5 a) (- g g)))) (+ (cbrt -2.0) (/ (cbrt (- g)) (cbrt a)))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -6e-127) || !(a <= 6.8e-50)) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = cbrt(-2.0) + (cbrt(-g) / cbrt(a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -6e-127) || !(a <= 6.8e-50)) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((-0.5 / a) * (g - g)));
} else {
tmp = Math.cbrt(-2.0) + (Math.cbrt(-g) / Math.cbrt(a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -6e-127) || !(a <= 6.8e-50)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g)))); else tmp = Float64(cbrt(-2.0) + Float64(cbrt(Float64(-g)) / cbrt(a))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -6e-127], N[Not[LessEqual[a, 6.8e-50]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -6 \cdot 10^{-127} \lor \neg \left(a \leq 6.8 \cdot 10^{-50}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-2} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if a < -6.00000000000000017e-127 or 6.80000000000000029e-50 < a Initial program 48.6%
Simplified48.6%
Taylor expanded in g around -inf 28.8%
*-commutative28.8%
Simplified28.8%
Taylor expanded in g around -inf 91.9%
neg-mul-191.9%
Simplified91.9%
if -6.00000000000000017e-127 < a < 6.80000000000000029e-50Initial program 41.0%
Simplified41.0%
Taylor expanded in g around -inf 24.9%
*-commutative24.9%
Simplified24.9%
Taylor expanded in g around inf 11.3%
add-sqr-sqrt5.0%
sqrt-unprod3.3%
swap-sqr3.4%
frac-times3.4%
metadata-eval3.4%
metadata-eval3.4%
frac-times3.4%
*-commutative3.4%
*-commutative3.4%
swap-sqr3.4%
metadata-eval3.4%
metadata-eval3.4%
swap-sqr3.4%
count-23.4%
count-23.4%
swap-sqr3.3%
*-commutative3.3%
*-commutative3.3%
sqrt-unprod5.0%
add-sqr-sqrt11.3%
expm1-log1p-u5.4%
Applied egg-rr0.0%
Simplified46.5%
add-sqr-sqrt21.0%
sqrt-unprod7.6%
*-commutative7.6%
*-commutative7.6%
swap-sqr4.2%
frac-times4.2%
metadata-eval4.2%
metadata-eval4.2%
frac-times4.2%
count-24.2%
count-24.2%
swap-sqr4.2%
metadata-eval4.2%
metadata-eval4.2%
swap-sqr4.2%
*-commutative4.2%
*-commutative4.2%
swap-sqr7.6%
Applied egg-rr94.2%
Final simplification92.8%
(FPCore (g h a) :precision binary64 (if (or (<= a -5.6e-34) (not (<= a 1.3e-59))) (+ (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 ((a <= -5.6e-34) || !(a <= 1.3e-59)) {
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 ((a <= -5.6e-34) || !(a <= 1.3e-59)) {
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 ((a <= -5.6e-34) || !(a <= 1.3e-59)) 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[a, -5.6e-34], N[Not[LessEqual[a, 1.3e-59]], $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}\;a \leq -5.6 \cdot 10^{-34} \lor \neg \left(a \leq 1.3 \cdot 10^{-59}\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 a < -5.59999999999999994e-34 or 1.29999999999999999e-59 < a Initial program 47.6%
Simplified47.6%
Taylor expanded in g around -inf 26.5%
*-commutative26.5%
Simplified26.5%
Taylor expanded in g around inf 18.0%
expm1-log1p-u22.7%
expm1-udef22.7%
Applied egg-rr0.0%
Simplified75.8%
if -5.59999999999999994e-34 < a < 1.29999999999999999e-59Initial program 43.6%
Simplified43.6%
Taylor expanded in g around -inf 28.4%
*-commutative28.4%
Simplified28.4%
Taylor expanded in g around inf 12.6%
Taylor expanded in a around 0 12.6%
Simplified56.0%
Final simplification66.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt (* (/ -0.5 a) (- g g)))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((-0.5 / a) * (g - g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((-0.5 / a) * (g - g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - 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[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}
\end{array}
Initial program 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around -inf 75.8%
neg-mul-175.8%
Simplified75.8%
Final simplification75.8%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ -0.5 a) (- g g))) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * (g - g))) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * (g - g))) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around -inf 75.8%
neg-mul-175.8%
Simplified75.8%
associate-*l/75.7%
*-commutative75.7%
associate-*r*75.7%
metadata-eval75.7%
neg-mul-175.7%
Applied egg-rr75.7%
Final simplification75.7%
(FPCore (g h a) :precision binary64 (+ (cbrt -2.0) (cbrt (* (/ -0.5 a) (+ g g)))))
double code(double g, double h, double a) {
return cbrt(-2.0) + cbrt(((-0.5 / a) * (g + g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-2.0) + Math.cbrt(((-0.5 / a) * (g + g)));
}
function code(g, h, a) return Float64(cbrt(-2.0) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))) end
code[g_, h_, a_] := N[(N[Power[-2.0, 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-2} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}
\end{array}
Initial program 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt7.2%
sqrt-unprod14.5%
swap-sqr18.2%
frac-times18.5%
metadata-eval18.5%
metadata-eval18.5%
frac-times18.2%
*-commutative18.2%
*-commutative18.2%
swap-sqr18.2%
metadata-eval18.2%
metadata-eval18.2%
swap-sqr18.2%
count-218.2%
count-218.2%
swap-sqr14.5%
*-commutative14.5%
*-commutative14.5%
sqrt-unprod7.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.0%
Applied egg-rr0.0%
Simplified48.0%
Final simplification48.0%
(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 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt7.2%
sqrt-unprod14.5%
swap-sqr18.2%
frac-times18.5%
metadata-eval18.5%
metadata-eval18.5%
frac-times18.2%
*-commutative18.2%
*-commutative18.2%
swap-sqr18.2%
metadata-eval18.2%
metadata-eval18.2%
swap-sqr18.2%
count-218.2%
count-218.2%
swap-sqr14.5%
*-commutative14.5%
*-commutative14.5%
sqrt-unprod7.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.0%
Applied egg-rr0.0%
Simplified48.0%
Taylor expanded in g around 0 48.0%
associate-*r/48.0%
mul-1-neg48.0%
Simplified48.0%
Final simplification48.0%
(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 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt7.2%
sqrt-unprod14.5%
swap-sqr18.2%
frac-times18.5%
metadata-eval18.5%
metadata-eval18.5%
frac-times18.2%
*-commutative18.2%
*-commutative18.2%
swap-sqr18.2%
metadata-eval18.2%
metadata-eval18.2%
swap-sqr18.2%
count-218.2%
count-218.2%
swap-sqr14.5%
*-commutative14.5%
*-commutative14.5%
sqrt-unprod7.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.0%
Applied egg-rr0.0%
Simplified48.0%
expm1-log1p-u20.9%
expm1-udef20.9%
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 45.8%
Simplified45.8%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt7.2%
sqrt-unprod14.5%
swap-sqr18.2%
frac-times18.5%
metadata-eval18.5%
metadata-eval18.5%
frac-times18.2%
*-commutative18.2%
*-commutative18.2%
swap-sqr18.2%
metadata-eval18.2%
metadata-eval18.2%
swap-sqr18.2%
count-218.2%
count-218.2%
swap-sqr14.5%
*-commutative14.5%
*-commutative14.5%
sqrt-unprod7.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.0%
Applied egg-rr0.0%
Simplified48.0%
Taylor expanded in g around 0 4.7%
Final simplification4.7%
herbie shell --seed 2024013
(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))))))))