
(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 5 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 44.0%
Simplified44.0%
Taylor expanded in g around -inf 25.4%
*-commutative25.4%
Simplified25.4%
Taylor expanded in g around -inf 76.5%
neg-mul-176.5%
Simplified76.5%
associate-*l/76.6%
cbrt-div96.1%
*-commutative96.1%
associate-*r*96.1%
metadata-eval96.1%
neg-mul-196.1%
Applied egg-rr96.1%
Final simplification96.1%
(FPCore (g h a) :precision binary64 (if (or (<= a -1.25e-60) (not (<= a 8.6e-32))) (+ (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ (- g) a))) (+ (/ (cbrt (- g)) (cbrt a)) (cbrt -0.5))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -1.25e-60) || !(a <= 8.6e-32)) {
tmp = cbrt(((g - g) * (-0.5 / a))) + cbrt((-g / a));
} else {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(-0.5);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -1.25e-60) || !(a <= 8.6e-32)) {
tmp = Math.cbrt(((g - g) * (-0.5 / a))) + Math.cbrt((-g / a));
} else {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(-0.5);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -1.25e-60) || !(a <= 8.6e-32)) 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(-0.5)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -1.25e-60], N[Not[LessEqual[a, 8.6e-32]], $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[-0.5, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.25 \cdot 10^{-60} \lor \neg \left(a \leq 8.6 \cdot 10^{-32}\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]{-0.5}\\
\end{array}
\end{array}
if a < -1.25e-60 or 8.5999999999999998e-32 < a Initial program 43.4%
Simplified43.4%
Taylor expanded in g around -inf 22.7%
*-commutative22.7%
Simplified22.7%
Taylor expanded in g around -inf 90.5%
neg-mul-190.5%
Simplified90.5%
associate-*l/90.6%
*-commutative90.6%
associate-*r*90.6%
metadata-eval90.6%
neg-mul-190.6%
Applied egg-rr90.6%
if -1.25e-60 < a < 8.5999999999999998e-32Initial program 44.9%
Simplified44.9%
Taylor expanded in g around -inf 29.7%
*-commutative29.7%
Simplified29.7%
Taylor expanded in g around inf 12.7%
add-sqr-sqrt5.3%
sqrt-unprod4.0%
*-commutative4.0%
*-commutative4.0%
swap-sqr7.1%
*-commutative7.1%
*-commutative7.1%
swap-sqr7.1%
metadata-eval7.1%
metadata-eval7.1%
swap-sqr7.1%
count-27.1%
count-27.1%
frac-times7.1%
metadata-eval7.1%
metadata-eval7.1%
frac-times7.1%
swap-sqr4.0%
sqrt-unprod5.3%
add-sqr-sqrt12.7%
associate-*r/12.7%
Applied egg-rr0.0%
Simplified50.5%
add-sqr-sqrt22.7%
sqrt-unprod6.2%
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-sqr6.2%
*-commutative6.2%
*-commutative6.2%
sqrt-unprod22.7%
Applied egg-rr90.5%
Final simplification90.6%
(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.0%
Simplified44.0%
Taylor expanded in g around -inf 25.4%
*-commutative25.4%
Simplified25.4%
Taylor expanded in g around -inf 76.5%
neg-mul-176.5%
Simplified76.5%
associate-*l/76.6%
*-commutative76.6%
associate-*r*76.6%
metadata-eval76.6%
neg-mul-176.6%
Applied egg-rr76.6%
Final simplification76.6%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g) a)) (cbrt -0.5)))
double code(double g, double h, double a) {
return cbrt((-g / a)) + cbrt(-0.5);
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) + Math.cbrt(-0.5);
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(-0.5)) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[-0.5, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{-0.5}
\end{array}
Initial program 44.0%
Simplified44.0%
Taylor expanded in g around -inf 25.4%
*-commutative25.4%
Simplified25.4%
Taylor expanded in g around inf 15.7%
add-sqr-sqrt7.0%
sqrt-unprod16.3%
*-commutative16.3%
*-commutative16.3%
swap-sqr19.6%
*-commutative19.6%
*-commutative19.6%
swap-sqr19.6%
metadata-eval19.6%
metadata-eval19.6%
swap-sqr19.6%
count-219.6%
count-219.6%
frac-times20.2%
metadata-eval20.2%
metadata-eval20.2%
frac-times19.6%
swap-sqr16.3%
sqrt-unprod7.0%
add-sqr-sqrt15.7%
associate-*r/15.7%
Applied egg-rr0.0%
Simplified46.8%
+-commutative46.8%
*-un-lft-identity46.8%
fma-def46.8%
count-246.8%
Applied egg-rr46.8%
fma-udef46.8%
*-lft-identity46.8%
associate-*r/46.8%
*-commutative46.8%
associate-*l*46.8%
metadata-eval46.8%
*-commutative46.8%
mul-1-neg46.8%
Simplified46.8%
Final simplification46.8%
(FPCore (g h a) :precision binary64 (cbrt -0.5))
double code(double g, double h, double a) {
return cbrt(-0.5);
}
public static double code(double g, double h, double a) {
return Math.cbrt(-0.5);
}
function code(g, h, a) return cbrt(-0.5) end
code[g_, h_, a_] := N[Power[-0.5, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-0.5}
\end{array}
Initial program 44.0%
Simplified44.0%
Taylor expanded in g around -inf 25.4%
*-commutative25.4%
Simplified25.4%
Taylor expanded in g around inf 15.7%
add-sqr-sqrt7.0%
sqrt-unprod16.3%
*-commutative16.3%
*-commutative16.3%
swap-sqr19.6%
*-commutative19.6%
*-commutative19.6%
swap-sqr19.6%
metadata-eval19.6%
metadata-eval19.6%
swap-sqr19.6%
count-219.6%
count-219.6%
frac-times20.2%
metadata-eval20.2%
metadata-eval20.2%
frac-times19.6%
swap-sqr16.3%
sqrt-unprod7.0%
add-sqr-sqrt15.7%
associate-*r/15.7%
Applied egg-rr0.0%
Simplified46.8%
Taylor expanded in g around 0 4.8%
Final simplification4.8%
herbie shell --seed 2023306
(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))))))))