
(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 48.4%
Simplified48.4%
Taylor expanded in g around -inf 28.7%
*-commutative28.7%
Simplified28.7%
Taylor expanded in g around -inf 76.6%
neg-mul-176.6%
Simplified76.6%
cbrt-prod96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (* g -2.0))))
(if (or (<= a -4.4e-37) (not (<= a 7.5e-21)))
(+
(cbrt (* (/ 0.5 a) (* g -2.0)))
(cbrt (* (/ -0.5 a) (+ g (* g (- -1.0 (* -0.5 (* (/ h g) (/ h g)))))))))
(+ (* (cbrt (/ 0.5 a)) t_0) t_0))))
double code(double g, double h, double a) {
double t_0 = cbrt((g * -2.0));
double tmp;
if ((a <= -4.4e-37) || !(a <= 7.5e-21)) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((-0.5 / a) * (g + (g * (-1.0 - (-0.5 * ((h / g) * (h / g))))))));
} else {
tmp = (cbrt((0.5 / a)) * t_0) + t_0;
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt((g * -2.0));
double tmp;
if ((a <= -4.4e-37) || !(a <= 7.5e-21)) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((-0.5 / a) * (g + (g * (-1.0 - (-0.5 * ((h / g) * (h / g))))))));
} else {
tmp = (Math.cbrt((0.5 / a)) * t_0) + t_0;
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(g * -2.0)) tmp = 0.0 if ((a <= -4.4e-37) || !(a <= 7.5e-21)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + Float64(g * Float64(-1.0 - Float64(-0.5 * Float64(Float64(h / g) * Float64(h / g))))))))); else tmp = Float64(Float64(cbrt(Float64(0.5 / a)) * t_0) + t_0); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]}, If[Or[LessEqual[a, -4.4e-37], N[Not[LessEqual[a, 7.5e-21]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + N[(g * N[(-1.0 - N[(-0.5 * N[(N[(h / g), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * t$95$0), $MachinePrecision] + t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{g \cdot -2}\\
\mathbf{if}\;a \leq -4.4 \cdot 10^{-37} \lor \neg \left(a \leq 7.5 \cdot 10^{-21}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g \cdot \left(-1 - -0.5 \cdot \left(\frac{h}{g} \cdot \frac{h}{g}\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot t\_0 + t\_0\\
\end{array}
\end{array}
if a < -4.40000000000000004e-37 or 7.50000000000000072e-21 < a Initial program 48.4%
Simplified48.4%
Taylor expanded in g around -inf 29.8%
*-commutative29.8%
Simplified29.8%
Taylor expanded in g around -inf 87.1%
associate-*r*87.1%
neg-mul-187.1%
Simplified87.1%
pow287.1%
pow287.1%
times-frac92.2%
Applied egg-rr92.2%
if -4.40000000000000004e-37 < a < 7.50000000000000072e-21Initial program 48.5%
Simplified48.5%
Taylor expanded in g around -inf 27.4%
*-commutative27.4%
Simplified27.4%
Taylor expanded in g around inf 12.8%
cbrt-prod97.6%
Applied egg-rr12.8%
Taylor expanded in g around 0 12.8%
Simplified96.6%
Final simplification94.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 48.4%
Simplified48.4%
Taylor expanded in g around -inf 28.7%
*-commutative28.7%
Simplified28.7%
Taylor expanded in g around -inf 76.6%
neg-mul-176.6%
Simplified76.6%
associate-*l/76.6%
cbrt-div96.4%
*-commutative96.4%
associate-*r*96.4%
metadata-eval96.4%
neg-mul-196.4%
Applied egg-rr96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt (* (/ -0.5 a) (+ g (* g (- -1.0 (* -0.5 (* (/ h g) (/ h g))))))))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((-0.5 / a) * (g + (g * (-1.0 - (-0.5 * ((h / g) * (h / g))))))));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((-0.5 / a) * (g + (g * (-1.0 - (-0.5 * ((h / g) * (h / g))))))));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + Float64(g * Float64(-1.0 - Float64(-0.5 * Float64(Float64(h / g) * Float64(h / g))))))))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + N[(g * N[(-1.0 - N[(-0.5 * N[(N[(h / g), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g \cdot \left(-1 - -0.5 \cdot \left(\frac{h}{g} \cdot \frac{h}{g}\right)\right)\right)}
\end{array}
Initial program 48.4%
Simplified48.4%
Taylor expanded in g around -inf 28.7%
*-commutative28.7%
Simplified28.7%
Taylor expanded in g around -inf 72.4%
associate-*r*72.4%
neg-mul-172.4%
Simplified72.4%
pow272.4%
pow272.4%
times-frac76.9%
Applied egg-rr76.9%
Final simplification76.9%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (/ g a))))
(if (or (<= a -0.065) (not (<= a 0.5)))
(- (- t_0) t_0)
(- (cbrt (* g -2.0)) t_0))))
double code(double g, double h, double a) {
double t_0 = cbrt((g / a));
double tmp;
if ((a <= -0.065) || !(a <= 0.5)) {
tmp = -t_0 - t_0;
} else {
tmp = cbrt((g * -2.0)) - t_0;
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt((g / a));
double tmp;
if ((a <= -0.065) || !(a <= 0.5)) {
tmp = -t_0 - t_0;
} else {
tmp = Math.cbrt((g * -2.0)) - t_0;
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(g / a)) tmp = 0.0 if ((a <= -0.065) || !(a <= 0.5)) tmp = Float64(Float64(-t_0) - t_0); else tmp = Float64(cbrt(Float64(g * -2.0)) - t_0); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]}, If[Or[LessEqual[a, -0.065], N[Not[LessEqual[a, 0.5]], $MachinePrecision]], N[((-t$95$0) - t$95$0), $MachinePrecision], N[(N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision] - t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{a}}\\
\mathbf{if}\;a \leq -0.065 \lor \neg \left(a \leq 0.5\right):\\
\;\;\;\;\left(-t\_0\right) - t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g \cdot -2} - t\_0\\
\end{array}
\end{array}
if a < -0.065000000000000002 or 0.5 < a Initial program 48.7%
Simplified48.7%
Taylor expanded in g around -inf 30.3%
*-commutative30.3%
Simplified30.3%
Taylor expanded in g around inf 18.0%
Taylor expanded in g around -inf 18.0%
mul-1-neg18.0%
Simplified18.0%
Taylor expanded in g around -inf 18.0%
mul-1-neg18.0%
Simplified18.0%
if -0.065000000000000002 < a < 0.5Initial program 48.1%
Simplified48.1%
Taylor expanded in g around -inf 27.1%
*-commutative27.1%
Simplified27.1%
Taylor expanded in g around inf 13.1%
Taylor expanded in g around -inf 13.1%
mul-1-neg13.1%
Simplified13.1%
Taylor expanded in g around 0 13.1%
Simplified57.7%
Final simplification37.2%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt (* (/ -0.5 a) 0.0))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((-0.5 / a) * 0.0));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((-0.5 / a) * 0.0));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(-0.5 / a) * 0.0))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * 0.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot 0}
\end{array}
Initial program 48.4%
Simplified48.4%
Taylor expanded in g around -inf 28.7%
*-commutative28.7%
Simplified28.7%
Taylor expanded in g around -inf 72.4%
associate-*r*72.4%
neg-mul-172.4%
Simplified72.4%
Taylor expanded in h around 0 76.6%
distribute-rgt1-in76.6%
metadata-eval76.6%
mul0-lft76.6%
Simplified76.6%
Final simplification76.6%
(FPCore (g h a) :precision binary64 (- (cbrt (* g -2.0)) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt((g * -2.0)) - cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((g * -2.0)) - Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(g * -2.0)) - cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{g \cdot -2} - \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 48.4%
Simplified48.4%
Taylor expanded in g around -inf 28.7%
*-commutative28.7%
Simplified28.7%
Taylor expanded in g around inf 15.6%
Taylor expanded in g around -inf 15.6%
mul-1-neg15.6%
Simplified15.6%
Taylor expanded in g around 0 15.6%
Simplified30.3%
Final simplification30.3%
herbie shell --seed 2024092
(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))))))))