
(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.5 a) (- g g))) (* (cbrt g) (cbrt (/ 1.0 a)))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) - (cbrt(g) * cbrt((1.0 / a)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) - (Math.cbrt(g) * Math.cbrt((1.0 / a)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) - Float64(cbrt(g) * cbrt(Float64(1.0 / a)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] - N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[N[(1.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} - \sqrt[3]{g} \cdot \sqrt[3]{\frac{1}{a}}
\end{array}
Initial program 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
Taylor expanded in g around 0 71.6%
Simplified71.6%
pow1/334.0%
div-inv34.0%
unpow-prod-down20.6%
pow1/344.3%
Applied egg-rr44.3%
unpow1/396.5%
Simplified96.5%
Final simplification96.5%
(FPCore (g h a) :precision binary64 (- (cbrt (* (/ 0.5 a) (- g g))) (/ (cbrt g) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) - (cbrt(g) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) - (Math.cbrt(g) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) - Float64(cbrt(g) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $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]{\frac{0.5}{a} \cdot \left(g - g\right)} - \frac{\sqrt[3]{g}}{\sqrt[3]{a}}
\end{array}
Initial program 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
Taylor expanded in g around 0 71.6%
Simplified71.6%
cbrt-div96.5%
div-inv96.4%
Applied egg-rr96.4%
associate-*r/96.5%
*-rgt-identity96.5%
Simplified96.5%
Final simplification96.5%
(FPCore (g h a) :precision binary64 (let* ((t_0 (cbrt (* (/ 0.5 a) (- g g))))) (if (<= a 9e-309) (+ t_0 (cbrt (/ -1.0 a))) (+ t_0 (cbrt (- g))))))
double code(double g, double h, double a) {
double t_0 = cbrt(((0.5 / a) * (g - g)));
double tmp;
if (a <= 9e-309) {
tmp = t_0 + cbrt((-1.0 / a));
} else {
tmp = t_0 + cbrt(-g);
}
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 (a <= 9e-309) {
tmp = t_0 + Math.cbrt((-1.0 / a));
} else {
tmp = t_0 + Math.cbrt(-g);
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) tmp = 0.0 if (a <= 9e-309) tmp = Float64(t_0 + cbrt(Float64(-1.0 / a))); else tmp = Float64(t_0 + cbrt(Float64(-g))); 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[a, 9e-309], N[(t$95$0 + N[Power[N[(-1.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[Power[(-g), 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{if}\;a \leq 9 \cdot 10^{-309}:\\
\;\;\;\;t\_0 + \sqrt[3]{\frac{-1}{a}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \sqrt[3]{-g}\\
\end{array}
\end{array}
if a < 9.0000000000000021e-309Initial program 44.0%
Simplified44.0%
Taylor expanded in g around inf 22.1%
Taylor expanded in g around inf 72.8%
add-sqr-sqrt34.1%
pow234.1%
Applied egg-rr0.0%
Simplified0.0%
unpow20.0%
div-inv0.0%
metadata-eval0.0%
sqrt-div0.0%
associate-*l*0.0%
add-sqr-sqrt0.0%
sqrt-prod0.0%
frac-times0.0%
metadata-eval0.0%
add-sqr-sqrt0.0%
add-sqr-sqrt4.6%
Applied egg-rr4.6%
associate-*r/4.6%
metadata-eval4.6%
Simplified4.6%
if 9.0000000000000021e-309 < a Initial program 36.2%
Simplified36.2%
Taylor expanded in g around inf 23.2%
Taylor expanded in g around inf 70.2%
*-commutative70.2%
distribute-lft-in70.2%
Applied egg-rr70.2%
Simplified8.0%
Final simplification6.3%
(FPCore (g h a) :precision binary64 (let* ((t_0 (cbrt (* (/ 0.5 a) (- g g))))) (if (<= g -5e-300) (+ t_0 (cbrt (/ 1.0 a))) (+ t_0 (cbrt (/ -1.0 a))))))
double code(double g, double h, double a) {
double t_0 = cbrt(((0.5 / a) * (g - g)));
double tmp;
if (g <= -5e-300) {
tmp = t_0 + cbrt((1.0 / a));
} else {
tmp = t_0 + cbrt((-1.0 / a));
}
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 <= -5e-300) {
tmp = t_0 + Math.cbrt((1.0 / a));
} else {
tmp = t_0 + Math.cbrt((-1.0 / a));
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) tmp = 0.0 if (g <= -5e-300) tmp = Float64(t_0 + cbrt(Float64(1.0 / a))); else tmp = Float64(t_0 + cbrt(Float64(-1.0 / a))); 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, -5e-300], N[(t$95$0 + N[Power[N[(1.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[Power[N[(-1.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)}\\
\mathbf{if}\;g \leq -5 \cdot 10^{-300}:\\
\;\;\;\;t\_0 + \sqrt[3]{\frac{1}{a}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 + \sqrt[3]{\frac{-1}{a}}\\
\end{array}
\end{array}
if g < -4.99999999999999996e-300Initial program 38.3%
Simplified38.3%
Taylor expanded in g around inf 2.6%
Taylor expanded in g around inf 73.7%
add-sqr-sqrt34.7%
pow234.7%
Applied egg-rr0.0%
Simplified3.8%
Taylor expanded in a around 0 7.9%
if -4.99999999999999996e-300 < g Initial program 42.3%
Simplified42.3%
Taylor expanded in g around inf 43.6%
Taylor expanded in g around inf 69.3%
add-sqr-sqrt36.0%
pow236.0%
Applied egg-rr0.0%
Simplified0.7%
unpow20.7%
div-inv0.7%
metadata-eval0.7%
sqrt-div0.7%
associate-*l*0.7%
add-sqr-sqrt0.0%
sqrt-prod3.7%
frac-times3.7%
metadata-eval3.7%
add-sqr-sqrt3.7%
add-sqr-sqrt7.8%
Applied egg-rr7.8%
associate-*r/7.8%
metadata-eval7.8%
Simplified7.8%
Final simplification7.8%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) (/ -1.0 (cbrt (/ a g)))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + (-1.0 / cbrt((a / g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + (-1.0 / Math.cbrt((a / g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(-1.0 / cbrt(Float64(a / g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(-1.0 / N[Power[N[(a / g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \frac{-1}{\sqrt[3]{\frac{a}{g}}}
\end{array}
Initial program 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
Taylor expanded in g around 0 71.6%
Simplified71.6%
clear-num71.5%
cbrt-div72.8%
metadata-eval72.8%
Applied egg-rr72.8%
Final simplification72.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(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 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
Taylor expanded in g around 0 71.6%
Simplified71.6%
Final simplification71.6%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (- g))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + cbrt(-g);
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt(-g);
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(-g))) end
code[g_, h_, a_] := 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}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{-g}
\end{array}
Initial program 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
*-commutative71.5%
distribute-lft-in71.5%
Applied egg-rr71.5%
Simplified4.6%
Final simplification4.6%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt 0.5)))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + cbrt(0.5);
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt(0.5);
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(0.5)) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{0.5}
\end{array}
Initial program 40.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
frac-2neg71.5%
metadata-eval71.5%
associate-*r/71.6%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
Applied egg-rr0.0%
Simplified4.4%
Final simplification4.4%
(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.2%
Simplified40.2%
Taylor expanded in g around inf 22.6%
Taylor expanded in g around inf 71.5%
cbrt-prod96.5%
Applied egg-rr0.0%
Simplified4.2%
Final simplification4.2%
herbie shell --seed 2024054
(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))))))))