
(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 (/ 1.0 a)))))
double code(double g, double h, double a) {
return cbrt(g) * -cbrt((1.0 / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(g) * -Math.cbrt((1.0 / a));
}
function code(g, h, a) return Float64(cbrt(g) * Float64(-cbrt(Float64(1.0 / a)))) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] * (-N[Power[N[(1.0 / a), $MachinePrecision], 1/3], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g} \cdot \left(-\sqrt[3]{\frac{1}{a}}\right)
\end{array}
Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.4%
pow1/332.8%
div-inv32.8%
unpow-prod-down18.8%
pow1/343.1%
Applied egg-rr43.1%
unpow1/394.0%
Simplified94.0%
*-un-lft-identity94.0%
metadata-eval94.0%
metadata-eval94.0%
metadata-eval94.0%
metadata-eval94.0%
cbrt-unprod94.0%
cbrt-unprod94.5%
rem-3cbrt-lft94.5%
metadata-eval94.5%
Applied egg-rr94.5%
Final simplification94.5%
(FPCore (g h a) :precision binary64 (/ -1.0 (/ (cbrt a) (cbrt g))))
double code(double g, double h, double a) {
return -1.0 / (cbrt(a) / cbrt(g));
}
public static double code(double g, double h, double a) {
return -1.0 / (Math.cbrt(a) / Math.cbrt(g));
}
function code(g, h, a) return Float64(-1.0 / Float64(cbrt(a) / cbrt(g))) end
code[g_, h_, a_] := N[(-1.0 / N[(N[Power[a, 1/3], $MachinePrecision] / N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-1}{\frac{\sqrt[3]{a}}{\sqrt[3]{g}}}
\end{array}
Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.4%
pow1/332.8%
div-inv32.8%
unpow-prod-down18.8%
pow1/343.1%
Applied egg-rr43.1%
unpow1/394.0%
Simplified94.0%
Applied egg-rr94.3%
(FPCore (g h a) :precision binary64 (/ (- (cbrt g)) (cbrt a)))
double code(double g, double h, double a) {
return -cbrt(g) / cbrt(a);
}
public static double code(double g, double h, double a) {
return -Math.cbrt(g) / Math.cbrt(a);
}
function code(g, h, a) return Float64(Float64(-cbrt(g)) / cbrt(a)) end
code[g_, h_, a_] := N[((-N[Power[g, 1/3], $MachinePrecision]) / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\sqrt[3]{g}}{\sqrt[3]{a}}
\end{array}
Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.4%
pow1/332.8%
div-inv32.8%
unpow-prod-down18.8%
pow1/343.1%
Applied egg-rr43.1%
unpow1/394.0%
Simplified94.0%
Applied egg-rr94.3%
associate-/r/94.3%
associate-*l/94.3%
neg-mul-194.3%
Simplified94.3%
(FPCore (g h a) :precision binary64 (if (<= a -2e-310) (cbrt g) (- (cbrt g))))
double code(double g, double h, double a) {
double tmp;
if (a <= -2e-310) {
tmp = cbrt(g);
} else {
tmp = -cbrt(g);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (a <= -2e-310) {
tmp = Math.cbrt(g);
} else {
tmp = -Math.cbrt(g);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (a <= -2e-310) tmp = cbrt(g); else tmp = Float64(-cbrt(g)); end return tmp end
code[g_, h_, a_] := If[LessEqual[a, -2e-310], N[Power[g, 1/3], $MachinePrecision], (-N[Power[g, 1/3], $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\sqrt[3]{g}\\
\mathbf{else}:\\
\;\;\;\;-\sqrt[3]{g}\\
\end{array}
\end{array}
if a < -1.999999999999994e-310Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.9%
pow171.9%
cbrt-unprod72.4%
cbrt-unprod72.4%
metadata-eval72.4%
Applied egg-rr72.4%
unpow172.4%
*-commutative72.4%
neg-mul-172.4%
distribute-neg-frac272.4%
Simplified72.4%
Applied egg-rr0.0%
*-commutative0.0%
associate-*l/0.0%
associate-/l*0.0%
*-inverses7.9%
*-rgt-identity7.9%
Simplified7.9%
if -1.999999999999994e-310 < a Initial program 46.9%
Simplified46.9%
Taylor expanded in g around inf 70.9%
pow170.9%
cbrt-unprod71.5%
cbrt-unprod71.5%
metadata-eval71.5%
Applied egg-rr71.5%
unpow171.5%
*-commutative71.5%
neg-mul-171.5%
distribute-neg-frac271.5%
Simplified71.5%
Applied egg-rr1.2%
*-commutative1.2%
associate-*l/1.2%
associate-/l*1.3%
*-inverses1.3%
*-rgt-identity1.3%
Simplified1.3%
Applied egg-rr8.0%
*-commutative8.0%
neg-mul-18.0%
Simplified8.0%
(FPCore (g h a) :precision binary64 (cbrt (/ g (- a))))
double code(double g, double h, double a) {
return cbrt((g / -a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((g / -a));
}
function code(g, h, a) return cbrt(Float64(g / Float64(-a))) end
code[g_, h_, a_] := N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{-a}}
\end{array}
Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.4%
pow171.4%
cbrt-unprod71.9%
cbrt-unprod71.9%
metadata-eval71.9%
Applied egg-rr71.9%
unpow171.9%
*-commutative71.9%
neg-mul-171.9%
distribute-neg-frac271.9%
Simplified71.9%
(FPCore (g h a) :precision binary64 (cbrt g))
double code(double g, double h, double a) {
return cbrt(g);
}
public static double code(double g, double h, double a) {
return Math.cbrt(g);
}
function code(g, h, a) return cbrt(g) end
code[g_, h_, a_] := N[Power[g, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g}
\end{array}
Initial program 47.0%
Simplified47.0%
Taylor expanded in g around inf 71.4%
pow171.4%
cbrt-unprod71.9%
cbrt-unprod71.9%
metadata-eval71.9%
Applied egg-rr71.9%
unpow171.9%
*-commutative71.9%
neg-mul-171.9%
distribute-neg-frac271.9%
Simplified71.9%
Applied egg-rr0.6%
*-commutative0.6%
associate-*l/0.6%
associate-/l*0.6%
*-inverses4.7%
*-rgt-identity4.7%
Simplified4.7%
herbie shell --seed 2024184
(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))))))))