
(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 (* (/ -0.5 a) (- g g)))))
double code(double g, double h, double a) {
return (cbrt(-g) / cbrt(a)) + cbrt(((-0.5 / a) * (g - g)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((-0.5 / a) * (g - g)));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g)))) end
code[g_, h_, a_] := N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}
\end{array}
Initial program 40.4%
Simplified40.4%
associate-*l/40.3%
cbrt-div44.6%
pow244.6%
pow244.6%
Applied egg-rr44.6%
Taylor expanded in g around -inf 36.7%
neg-mul-136.7%
Simplified36.7%
Taylor expanded in g around -inf 95.5%
mul-1-neg95.5%
Simplified95.5%
Taylor expanded in g around 0 95.9%
mul-1-neg95.9%
Simplified95.9%
Final simplification95.9%
(FPCore (g h a) :precision binary64 (if (or (<= a -2.7e-54) (not (<= a 9.4e-38))) (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a))) (+ (cbrt (- g)) (/ (cbrt (* 0.5 (- (- g) g))) (cbrt a)))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -2.7e-54) || !(a <= 9.4e-38)) {
tmp = cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
} else {
tmp = cbrt(-g) + (cbrt((0.5 * (-g - g))) / cbrt(a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -2.7e-54) || !(a <= 9.4e-38)) {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
} else {
tmp = Math.cbrt(-g) + (Math.cbrt((0.5 * (-g - g))) / Math.cbrt(a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -2.7e-54) || !(a <= 9.4e-38)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a))); else tmp = Float64(cbrt(Float64(-g)) + Float64(cbrt(Float64(0.5 * Float64(Float64(-g) - g))) / cbrt(a))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -2.7e-54], N[Not[LessEqual[a, 9.4e-38]], $MachinePrecision]], 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], N[(N[Power[(-g), 1/3], $MachinePrecision] + N[(N[Power[N[(0.5 * N[((-g) - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2.7 \cdot 10^{-54} \lor \neg \left(a \leq 9.4 \cdot 10^{-38}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-g} + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if a < -2.70000000000000026e-54 or 9.39999999999999996e-38 < a Initial program 43.5%
Simplified43.5%
Taylor expanded in g around inf 17.4%
Taylor expanded in g around inf 85.5%
Taylor expanded in g around 0 86.2%
if -2.70000000000000026e-54 < a < 9.39999999999999996e-38Initial program 35.7%
Simplified35.7%
associate-*l/35.7%
cbrt-div41.5%
pow241.5%
pow241.5%
Applied egg-rr41.5%
Taylor expanded in g around -inf 30.7%
neg-mul-130.7%
Simplified30.7%
Taylor expanded in g around inf 11.1%
Taylor expanded in g around 0 11.1%
Simplified96.5%
Final simplification90.3%
(FPCore (g h a) :precision binary64 (if (or (<= a -6e-86) (not (<= a 2.65e-42))) (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a))) (+ -1.0 (/ (cbrt (* 0.5 (- (- g) g))) (cbrt a)))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -6e-86) || !(a <= 2.65e-42)) {
tmp = cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
} else {
tmp = -1.0 + (cbrt((0.5 * (-g - g))) / cbrt(a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -6e-86) || !(a <= 2.65e-42)) {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
} else {
tmp = -1.0 + (Math.cbrt((0.5 * (-g - g))) / Math.cbrt(a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -6e-86) || !(a <= 2.65e-42)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a))); else tmp = Float64(-1.0 + Float64(cbrt(Float64(0.5 * Float64(Float64(-g) - g))) / cbrt(a))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -6e-86], N[Not[LessEqual[a, 2.65e-42]], $MachinePrecision]], 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], N[(-1.0 + N[(N[Power[N[(0.5 * N[((-g) - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -6 \cdot 10^{-86} \lor \neg \left(a \leq 2.65 \cdot 10^{-42}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}\\
\mathbf{else}:\\
\;\;\;\;-1 + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if a < -6.0000000000000002e-86 or 2.65e-42 < a Initial program 43.3%
Simplified43.3%
Taylor expanded in g around inf 18.6%
Taylor expanded in g around inf 85.6%
Taylor expanded in g around 0 86.2%
if -6.0000000000000002e-86 < a < 2.65e-42Initial program 35.4%
Simplified35.4%
associate-*l/35.3%
cbrt-div41.7%
pow241.7%
pow241.7%
Applied egg-rr41.7%
Taylor expanded in g around -inf 32.4%
neg-mul-132.4%
Simplified32.4%
Taylor expanded in g around inf 10.6%
cbrt-prod96.5%
Applied egg-rr0.0%
Simplified93.7%
Final simplification89.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (- g)) (cbrt (* (/ 0.5 a) (- g g)))))
double code(double g, double h, double a) {
return cbrt(-g) + cbrt(((0.5 / a) * (g - g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-g) + Math.cbrt(((0.5 / a) * (g - g)));
}
function code(g, h, a) return Float64(cbrt(Float64(-g)) + cbrt(Float64(Float64(0.5 / a) * Float64(g - g)))) end
code[g_, h_, a_] := 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}
\\
\sqrt[3]{-g} + \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}
\end{array}
Initial program 40.4%
Simplified40.4%
Taylor expanded in g around inf 17.4%
Taylor expanded in g around inf 70.2%
Taylor expanded in g around 0 70.6%
Simplified5.1%
Final simplification5.1%
(FPCore (g h a) :precision binary64 (+ -1.0 (/ (cbrt (* 0.5 (- (- g) g))) (cbrt a))))
double code(double g, double h, double a) {
return -1.0 + (cbrt((0.5 * (-g - g))) / cbrt(a));
}
public static double code(double g, double h, double a) {
return -1.0 + (Math.cbrt((0.5 * (-g - g))) / Math.cbrt(a));
}
function code(g, h, a) return Float64(-1.0 + Float64(cbrt(Float64(0.5 * Float64(Float64(-g) - g))) / cbrt(a))) end
code[g_, h_, a_] := N[(-1.0 + N[(N[Power[N[(0.5 * N[((-g) - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \frac{\sqrt[3]{0.5 \cdot \left(\left(-g\right) - g\right)}}{\sqrt[3]{a}}
\end{array}
Initial program 40.4%
Simplified40.4%
associate-*l/40.3%
cbrt-div44.6%
pow244.6%
pow244.6%
Applied egg-rr44.6%
Taylor expanded in g around -inf 36.7%
neg-mul-136.7%
Simplified36.7%
Taylor expanded in g around inf 19.8%
cbrt-prod95.6%
Applied egg-rr0.0%
Simplified62.6%
Final simplification62.6%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) -1.0))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + -1.0;
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + -1.0;
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + -1.0) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + -1
\end{array}
Initial program 40.4%
Simplified40.4%
Taylor expanded in g around inf 17.4%
Taylor expanded in g around inf 70.2%
cbrt-prod95.6%
Applied egg-rr0.0%
Simplified4.3%
Final simplification4.3%
herbie shell --seed 2023298
(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))))))))