
(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 (/ 0.0 a)) (* (cbrt (* 0.5 g)) (cbrt (/ -2.0 a)))))
double code(double g, double h, double a) {
return cbrt((0.0 / a)) + (cbrt((0.5 * g)) * cbrt((-2.0 / a)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.0 / a)) + (Math.cbrt((0.5 * g)) * Math.cbrt((-2.0 / a)));
}
function code(g, h, a) return Float64(cbrt(Float64(0.0 / a)) + Float64(cbrt(Float64(0.5 * g)) * cbrt(Float64(-2.0 / a)))) end
code[g_, h_, a_] := N[(N[Power[N[(0.0 / a), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(0.5 * g), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-2.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0}{a}} + \sqrt[3]{0.5 \cdot g} \cdot \sqrt[3]{\frac{-2}{a}}
\end{array}
Initial program 41.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.3
Simplified25.3%
difference-of-squaresN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6423.9
Applied egg-rr23.9%
Taylor expanded in g around inf
associate-*r/N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
lower-/.f6471.4
Simplified71.4%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
times-fracN/A
metadata-evalN/A
lift-*.f64N/A
associate-/l*N/A
associate-*r*N/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f6494.8
Applied egg-rr94.8%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (/ 1.0 (* a 2.0))))
(if (<= t_0 2e+112)
(+ (cbrt (* t_0 (* (* -0.5 h) (/ h g)))) (cbrt (* t_0 (* g -2.0))))
(+
(cbrt (/ 0.0 a))
(* (pow (* a 2.0) -0.3333333333333333) (cbrt (* g -2.0)))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (a * 2.0);
double tmp;
if (t_0 <= 2e+112) {
tmp = cbrt((t_0 * ((-0.5 * h) * (h / g)))) + cbrt((t_0 * (g * -2.0)));
} else {
tmp = cbrt((0.0 / a)) + (pow((a * 2.0), -0.3333333333333333) * cbrt((g * -2.0)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (a * 2.0);
double tmp;
if (t_0 <= 2e+112) {
tmp = Math.cbrt((t_0 * ((-0.5 * h) * (h / g)))) + Math.cbrt((t_0 * (g * -2.0)));
} else {
tmp = Math.cbrt((0.0 / a)) + (Math.pow((a * 2.0), -0.3333333333333333) * Math.cbrt((g * -2.0)));
}
return tmp;
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(a * 2.0)) tmp = 0.0 if (t_0 <= 2e+112) tmp = Float64(cbrt(Float64(t_0 * Float64(Float64(-0.5 * h) * Float64(h / g)))) + cbrt(Float64(t_0 * Float64(g * -2.0)))); else tmp = Float64(cbrt(Float64(0.0 / a)) + Float64((Float64(a * 2.0) ^ -0.3333333333333333) * cbrt(Float64(g * -2.0)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+112], N[(N[Power[N[(t$95$0 * N[(N[(-0.5 * h), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.0 / a), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(a * 2.0), $MachinePrecision], -0.3333333333333333], $MachinePrecision] * N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{a \cdot 2}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+112}:\\
\;\;\;\;\sqrt[3]{t\_0 \cdot \left(\left(-0.5 \cdot h\right) \cdot \frac{h}{g}\right)} + \sqrt[3]{t\_0 \cdot \left(g \cdot -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0}{a}} + {\left(a \cdot 2\right)}^{-0.3333333333333333} \cdot \sqrt[3]{g \cdot -2}\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < 1.9999999999999999e112Initial program 42.9%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6426.7
Simplified26.7%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.6
Simplified73.6%
associate-*r*N/A
associate-/l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6478.5
Applied egg-rr78.5%
if 1.9999999999999999e112 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) Initial program 30.3%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6415.9
Simplified15.9%
difference-of-squaresN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f646.2
Applied egg-rr6.2%
Taylor expanded in g around inf
associate-*r/N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
lower-/.f6438.9
Simplified38.9%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
lift-cbrt.f64N/A
lower-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
lift-pow.f6487.8
Applied egg-rr87.8%
Final simplification79.7%
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* a 2.0)))) (+ (cbrt (* t_0 (* (* -0.5 h) (/ h g)))) (cbrt (* t_0 (* g -2.0))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (a * 2.0);
return cbrt((t_0 * ((-0.5 * h) * (h / g)))) + cbrt((t_0 * (g * -2.0)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (a * 2.0);
return Math.cbrt((t_0 * ((-0.5 * h) * (h / g)))) + Math.cbrt((t_0 * (g * -2.0)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(a * 2.0)) return Float64(cbrt(Float64(t_0 * Float64(Float64(-0.5 * h) * Float64(h / g)))) + cbrt(Float64(t_0 * Float64(g * -2.0)))) end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[(N[(-0.5 * h), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{a \cdot 2}\\
\sqrt[3]{t\_0 \cdot \left(\left(-0.5 \cdot h\right) \cdot \frac{h}{g}\right)} + \sqrt[3]{t\_0 \cdot \left(g \cdot -2\right)}
\end{array}
\end{array}
Initial program 41.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.3
Simplified25.3%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6469.2
Simplified69.2%
associate-*r*N/A
associate-/l*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-/.f6473.5
Applied egg-rr73.5%
Final simplification73.5%
(FPCore (g h a) :precision binary64 (- (cbrt (/ 0.0 a)) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt((0.0 / a)) - cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.0 / a)) - Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(0.0 / a)) - cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[N[(0.0 / a), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0}{a}} - \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 41.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.3
Simplified25.3%
difference-of-squaresN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6423.9
Applied egg-rr23.9%
Taylor expanded in g around inf
associate-*r/N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
lower-/.f6471.4
Simplified71.4%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6471.4
Simplified71.4%
Final simplification71.4%
(FPCore (g h a) :precision binary64 (cbrt (* (/ 1.0 (* a 2.0)) (* g -2.0))))
double code(double g, double h, double a) {
return cbrt(((1.0 / (a * 2.0)) * (g * -2.0)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((1.0 / (a * 2.0)) * (g * -2.0)));
}
function code(g, h, a) return cbrt(Float64(Float64(1.0 / Float64(a * 2.0)) * Float64(g * -2.0))) end
code[g_, h_, a_] := N[Power[N[(N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{1}{a \cdot 2} \cdot \left(g \cdot -2\right)}
\end{array}
Initial program 41.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.3
Simplified25.3%
difference-of-squaresN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6423.9
Applied egg-rr23.9%
Taylor expanded in g around inf
associate-*r/N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
lower-/.f6471.4
Simplified71.4%
lift-/.f64N/A
pow1/3N/A
lift-/.f64N/A
div0N/A
metadata-eval71.4
Applied egg-rr71.4%
Final simplification71.4%
herbie shell --seed 2024219
(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))))))))