
(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 (/ 0.5 a)) (cbrt (* g -2.0))) (cbrt (* (- g g) (/ -0.5 a)))))
double code(double g, double h, double a) {
return (cbrt((0.5 / a)) * cbrt((g * -2.0))) + cbrt(((g - g) * (-0.5 / a)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt((0.5 / a)) * Math.cbrt((g * -2.0))) + Math.cbrt(((g - g) * (-0.5 / a)));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(g * -2.0))) + cbrt(Float64(Float64(g - g) * Float64(-0.5 / a)))) 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[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g \cdot -2} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Initial program 44.5%
Simplified44.5%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
cbrt-prod96.8%
Applied egg-rr96.8%
Final simplification96.8%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (- g g) (/ -0.5 a))) (/ (cbrt (- g)) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(((g - g) * (-0.5 / a))) + (cbrt(-g) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - g) * (-0.5 / a))) + (Math.cbrt(-g) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) + Float64(cbrt(Float64(-g)) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}
\end{array}
Initial program 44.5%
Simplified44.5%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
associate-*l/75.0%
cbrt-div96.7%
*-commutative96.7%
associate-*r*96.7%
metadata-eval96.7%
neg-mul-196.7%
Applied egg-rr96.7%
Final simplification96.7%
(FPCore (g h a) :precision binary64 (if (or (<= a -3.5e-19) (not (<= a 1.4e-44))) (+ (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 <= -3.5e-19) || !(a <= 1.4e-44)) {
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 <= -3.5e-19) || !(a <= 1.4e-44)) {
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 <= -3.5e-19) || !(a <= 1.4e-44)) 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, -3.5e-19], N[Not[LessEqual[a, 1.4e-44]], $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 -3.5 \cdot 10^{-19} \lor \neg \left(a \leq 1.4 \cdot 10^{-44}\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 < -3.50000000000000015e-19 or 1.4e-44 < a Initial program 47.4%
Simplified47.4%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around -inf 89.3%
neg-mul-189.3%
Simplified89.3%
associate-*l/89.4%
*-commutative89.4%
associate-*r*89.4%
metadata-eval89.4%
neg-mul-189.4%
Applied egg-rr89.4%
if -3.50000000000000015e-19 < a < 1.4e-44Initial program 40.4%
Simplified40.4%
Taylor expanded in g around -inf 21.8%
*-commutative21.8%
Simplified21.8%
Taylor expanded in g around inf 12.2%
Applied egg-rr0.0%
Simplified47.3%
add-sqr-sqrt22.5%
sqrt-unprod10.0%
*-commutative10.0%
*-commutative10.0%
swap-sqr6.9%
frac-times6.9%
metadata-eval6.9%
metadata-eval6.9%
frac-times6.9%
count-26.9%
count-26.9%
swap-sqr6.9%
metadata-eval6.9%
metadata-eval6.9%
swap-sqr6.9%
*-commutative6.9%
*-commutative6.9%
swap-sqr10.0%
sqrt-unprod22.5%
add-sqr-sqrt47.3%
Applied egg-rr90.1%
Final simplification89.7%
(FPCore (g h a) :precision binary64 (if (or (<= g -2.7) (not (<= g 0.37))) (+ (cbrt (- (/ g a))) (cbrt -2.0)) (+ (cbrt (- g)) (cbrt (* (/ -0.5 a) (+ g g))))))
double code(double g, double h, double a) {
double tmp;
if ((g <= -2.7) || !(g <= 0.37)) {
tmp = cbrt(-(g / a)) + cbrt(-2.0);
} 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 <= -2.7) || !(g <= 0.37)) {
tmp = Math.cbrt(-(g / a)) + Math.cbrt(-2.0);
} else {
tmp = Math.cbrt(-g) + Math.cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((g <= -2.7) || !(g <= 0.37)) tmp = Float64(cbrt(Float64(-Float64(g / a))) + cbrt(-2.0)); 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, -2.7], N[Not[LessEqual[g, 0.37]], $MachinePrecision]], N[(N[Power[(-N[(g / a), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[-2.0, 1/3], $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 -2.7 \lor \neg \left(g \leq 0.37\right):\\
\;\;\;\;\sqrt[3]{-\frac{g}{a}} + \sqrt[3]{-2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\
\end{array}
\end{array}
if g < -2.7000000000000002 or 0.37 < g Initial program 37.8%
Simplified37.8%
Taylor expanded in g around -inf 20.7%
*-commutative20.7%
Simplified20.7%
Taylor expanded in g around inf 15.1%
Applied egg-rr0.0%
Simplified49.9%
Taylor expanded in g around 0 49.9%
if -2.7000000000000002 < g < 0.37Initial program 63.5%
Simplified63.5%
Taylor expanded in g around -inf 39.2%
*-commutative39.2%
Simplified39.2%
Taylor expanded in g around inf 16.2%
Taylor expanded in a around 0 16.2%
Simplified38.8%
Final simplification47.0%
(FPCore (g h a) :precision binary64 (if (or (<= g -1.75) (not (<= g 4.3e+17))) (+ (cbrt (- (/ g a))) (cbrt -2.0)) (+ (cbrt (* (/ -0.5 a) (+ g g))) (cbrt g))))
double code(double g, double h, double a) {
double tmp;
if ((g <= -1.75) || !(g <= 4.3e+17)) {
tmp = cbrt(-(g / a)) + cbrt(-2.0);
} else {
tmp = cbrt(((-0.5 / a) * (g + g))) + cbrt(g);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((g <= -1.75) || !(g <= 4.3e+17)) {
tmp = Math.cbrt(-(g / a)) + Math.cbrt(-2.0);
} else {
tmp = Math.cbrt(((-0.5 / a) * (g + g))) + Math.cbrt(g);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((g <= -1.75) || !(g <= 4.3e+17)) tmp = Float64(cbrt(Float64(-Float64(g / a))) + cbrt(-2.0)); else tmp = Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g + g))) + cbrt(g)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[g, -1.75], N[Not[LessEqual[g, 4.3e+17]], $MachinePrecision]], N[(N[Power[(-N[(g / a), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[-2.0, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -1.75 \lor \neg \left(g \leq 4.3 \cdot 10^{+17}\right):\\
\;\;\;\;\sqrt[3]{-\frac{g}{a}} + \sqrt[3]{-2}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)} + \sqrt[3]{g}\\
\end{array}
\end{array}
if g < -1.75 or 4.3e17 < g Initial program 36.5%
Simplified36.5%
Taylor expanded in g around -inf 20.7%
*-commutative20.7%
Simplified20.7%
Taylor expanded in g around inf 15.0%
Applied egg-rr0.0%
Simplified50.0%
Taylor expanded in g around 0 50.0%
if -1.75 < g < 4.3e17Initial program 65.5%
Simplified65.5%
Taylor expanded in g around -inf 38.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in g around inf 16.3%
associate-*l/16.3%
clear-num17.6%
*-commutative17.6%
associate-*r*17.6%
metadata-eval17.6%
neg-mul-117.6%
Applied egg-rr17.6%
Simplified39.2%
Final simplification47.0%
(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 44.5%
Simplified44.5%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
associate-*l/75.0%
*-commutative75.0%
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 44.5%
Simplified44.5%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around inf 15.4%
Applied egg-rr0.0%
Simplified43.7%
Taylor expanded in g around 0 43.7%
Final simplification43.7%
(FPCore (g h a) :precision binary64 -8.0)
double code(double g, double h, double a) {
return -8.0;
}
real(8) function code(g, h, a)
real(8), intent (in) :: g
real(8), intent (in) :: h
real(8), intent (in) :: a
code = -8.0d0
end function
public static double code(double g, double h, double a) {
return -8.0;
}
def code(g, h, a): return -8.0
function code(g, h, a) return -8.0 end
function tmp = code(g, h, a) tmp = -8.0; end
code[g_, h_, a_] := -8.0
\begin{array}{l}
\\
-8
\end{array}
Initial program 44.5%
Simplified44.5%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around inf 15.4%
Applied egg-rr0.0%
Simplified43.7%
Taylor expanded in g around 0 4.5%
Simplified4.5%
Final simplification4.5%
herbie shell --seed 2023322
(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))))))))