
(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 (/ 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 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around -inf 74.5%
mul-1-neg74.5%
Simplified74.5%
cbrt-prod96.2%
Applied egg-rr96.2%
Final simplification96.2%
(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 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around -inf 74.5%
mul-1-neg74.5%
Simplified74.5%
associate-*l/74.5%
*-commutative74.5%
associate-*r*74.5%
metadata-eval74.5%
neg-mul-174.5%
cbrt-div96.0%
Applied egg-rr96.0%
Final simplification96.0%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (- g g) (/ -0.5 a)))))
(if (<= a -1.7e-83)
(+ t_0 (cbrt (- (/ g a))))
(if (<= a 4.7e-58)
(+ (/ (cbrt (- g)) (cbrt a)) (cbrt -1.0))
(+ t_0 (cbrt (* (/ 0.5 a) (* g -2.0))))))))
double code(double g, double h, double a) {
double t_0 = cbrt(((g - g) * (-0.5 / a)));
double tmp;
if (a <= -1.7e-83) {
tmp = t_0 + cbrt(-(g / a));
} else if (a <= 4.7e-58) {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(-1.0);
} else {
tmp = t_0 + cbrt(((0.5 / a) * (g * -2.0)));
}
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 <= -1.7e-83) {
tmp = t_0 + Math.cbrt(-(g / a));
} else if (a <= 4.7e-58) {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(-1.0);
} else {
tmp = t_0 + Math.cbrt(((0.5 / a) * (g * -2.0)));
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) tmp = 0.0 if (a <= -1.7e-83) tmp = Float64(t_0 + cbrt(Float64(-Float64(g / a)))); elseif (a <= 4.7e-58) tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(-1.0)); else tmp = Float64(t_0 + cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0)))); 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, -1.7e-83], N[(t$95$0 + N[Power[(-N[(g / a), $MachinePrecision]), 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 4.7e-58], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $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 -1.7 \cdot 10^{-83}:\\
\;\;\;\;t_0 + \sqrt[3]{-\frac{g}{a}}\\
\mathbf{elif}\;a \leq 4.7 \cdot 10^{-58}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{-1}\\
\mathbf{else}:\\
\;\;\;\;t_0 + \sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)}\\
\end{array}
\end{array}
if a < -1.6999999999999999e-83Initial program 45.7%
Simplified45.7%
Taylor expanded in g around -inf 26.8%
*-commutative26.8%
Simplified26.8%
Taylor expanded in g around -inf 96.2%
mul-1-neg96.2%
Simplified96.2%
associate-*l/96.3%
*-commutative96.3%
associate-*r*96.3%
metadata-eval96.3%
neg-mul-196.3%
Applied egg-rr96.3%
if -1.6999999999999999e-83 < a < 4.69999999999999994e-58Initial program 34.9%
Simplified34.9%
Taylor expanded in g around -inf 27.0%
*-commutative27.0%
Simplified27.0%
Taylor expanded in g around inf 10.5%
Applied egg-rr0.0%
Simplified38.7%
add-sqr-sqrt21.1%
add-sqr-sqrt38.7%
add-sqr-sqrt14.5%
sqrt-unprod12.2%
count-212.2%
count-212.2%
swap-sqr12.2%
metadata-eval12.2%
metadata-eval12.2%
swap-sqr12.2%
*-commutative12.2%
*-commutative12.2%
sqrt-unprod0.6%
add-sqr-sqrt0.8%
add-sqr-sqrt0.4%
sqrt-unprod11.9%
frac-times11.9%
metadata-eval11.9%
metadata-eval11.9%
frac-times11.9%
sqrt-unprod20.1%
add-sqr-sqrt38.7%
Applied egg-rr91.5%
if 4.69999999999999994e-58 < a Initial program 43.6%
Simplified43.6%
Taylor expanded in g around -inf 29.4%
*-commutative29.4%
Simplified29.4%
Taylor expanded in g around -inf 95.1%
mul-1-neg95.1%
Simplified95.1%
Final simplification94.0%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* (/ -0.5 a) (+ g g)))))
(if (<= g -2.85e-5)
(+ (cbrt (- (/ g a))) (cbrt -1.0))
(if (<= g 7e+17) (+ (cbrt g) t_0) (+ (cbrt -1.0) t_0)))))
double code(double g, double h, double a) {
double t_0 = cbrt(((-0.5 / a) * (g + g)));
double tmp;
if (g <= -2.85e-5) {
tmp = cbrt(-(g / a)) + cbrt(-1.0);
} else if (g <= 7e+17) {
tmp = cbrt(g) + t_0;
} else {
tmp = cbrt(-1.0) + t_0;
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt(((-0.5 / a) * (g + g)));
double tmp;
if (g <= -2.85e-5) {
tmp = Math.cbrt(-(g / a)) + Math.cbrt(-1.0);
} else if (g <= 7e+17) {
tmp = Math.cbrt(g) + t_0;
} else {
tmp = Math.cbrt(-1.0) + t_0;
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(-0.5 / a) * Float64(g + g))) tmp = 0.0 if (g <= -2.85e-5) tmp = Float64(cbrt(Float64(-Float64(g / a))) + cbrt(-1.0)); elseif (g <= 7e+17) tmp = Float64(cbrt(g) + t_0); else tmp = Float64(cbrt(-1.0) + t_0); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[g, -2.85e-5], N[(N[Power[(-N[(g / a), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 7e+17], N[(N[Power[g, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision], N[(N[Power[-1.0, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\
\mathbf{if}\;g \leq -2.85 \cdot 10^{-5}:\\
\;\;\;\;\sqrt[3]{-\frac{g}{a}} + \sqrt[3]{-1}\\
\mathbf{elif}\;g \leq 7 \cdot 10^{+17}:\\
\;\;\;\;\sqrt[3]{g} + t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-1} + t_0\\
\end{array}
\end{array}
if g < -2.8500000000000002e-5Initial program 35.0%
Simplified35.0%
Taylor expanded in g around -inf 34.6%
*-commutative34.6%
Simplified34.6%
Taylor expanded in g around inf 15.1%
Applied egg-rr0.0%
Simplified41.9%
Taylor expanded in g around 0 42.0%
mul-1-neg42.0%
distribute-neg-frac42.0%
Simplified42.0%
if -2.8500000000000002e-5 < g < 7e17Initial program 84.0%
Simplified84.0%
Taylor expanded in g around -inf 62.2%
*-commutative62.2%
Simplified62.2%
Taylor expanded in g around inf 18.1%
Taylor expanded in a around 0 18.1%
Simplified56.1%
if 7e17 < g Initial program 28.0%
Simplified28.0%
Taylor expanded in g around -inf 7.7%
*-commutative7.7%
Simplified7.7%
Taylor expanded in g around inf 14.5%
Applied egg-rr0.0%
Simplified50.1%
Final simplification48.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 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around -inf 74.5%
mul-1-neg74.5%
Simplified74.5%
associate-*l/74.5%
*-commutative74.5%
associate-*r*74.5%
metadata-eval74.5%
neg-mul-174.5%
Applied egg-rr74.5%
Final simplification74.5%
(FPCore (g h a) :precision binary64 (+ (cbrt (- (/ g a))) (cbrt -1.0)))
double code(double g, double h, double a) {
return cbrt(-(g / a)) + cbrt(-1.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-(g / a)) + Math.cbrt(-1.0);
}
function code(g, h, a) return Float64(cbrt(Float64(-Float64(g / a))) + cbrt(-1.0)) end
code[g_, h_, a_] := N[(N[Power[(-N[(g / a), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-\frac{g}{a}} + \sqrt[3]{-1}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around inf 15.4%
Applied egg-rr0.0%
Simplified43.9%
Taylor expanded in g around 0 43.9%
mul-1-neg43.9%
distribute-neg-frac43.9%
Simplified43.9%
Final simplification43.9%
(FPCore (g h a) :precision binary64 (cbrt -1.0))
double code(double g, double h, double a) {
return cbrt(-1.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-1.0);
}
function code(g, h, a) return cbrt(-1.0) end
code[g_, h_, a_] := N[Power[-1.0, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-1}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around inf 15.4%
Applied egg-rr0.0%
Simplified43.9%
Taylor expanded in g around 0 4.4%
Final simplification4.4%
herbie shell --seed 2023326
(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))))))))