
(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.5) (cbrt 0.5)) (pow (cbrt (/ a (* (/ h g) h))) -1.0)) (* (cbrt (/ 0.5 a)) (cbrt (* -2.0 g)))))
double code(double g, double h, double a) {
return ((cbrt(-0.5) * cbrt(0.5)) * pow(cbrt((a / ((h / g) * h))), -1.0)) + (cbrt((0.5 / a)) * cbrt((-2.0 * g)));
}
public static double code(double g, double h, double a) {
return ((Math.cbrt(-0.5) * Math.cbrt(0.5)) * Math.pow(Math.cbrt((a / ((h / g) * h))), -1.0)) + (Math.cbrt((0.5 / a)) * Math.cbrt((-2.0 * g)));
}
function code(g, h, a) return Float64(Float64(Float64(cbrt(-0.5) * cbrt(0.5)) * (cbrt(Float64(a / Float64(Float64(h / g) * h))) ^ -1.0)) + Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(-2.0 * g)))) end
code[g_, h_, a_] := N[(N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[N[Power[N[(a / N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sqrt[3]{-0.5} \cdot \sqrt[3]{0.5}\right) \cdot {\left(\sqrt[3]{\frac{a}{\frac{h}{g} \cdot h}}\right)}^{-1} + \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{-2 \cdot g}
\end{array}
Initial program 41.8%
Taylor expanded in g around inf
lower-*.f6427.1
Applied rewrites27.1%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
lift-cbrt.f64N/A
pow1/3N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/3N/A
lower-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
pow1/3N/A
lower-cbrt.f6494.5
Applied rewrites94.5%
Applied rewrites96.3%
Final simplification96.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (* (/ 0.5 a) (* -2.0 g)))
(t_2 (cbrt t_1)))
(if (<=
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) t_0)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0))))
-1e-100)
(+ t_2 t_2)
(+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (pow t_1 0.3333333333333333)))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = (0.5 / a) * (-2.0 * g);
double t_2 = cbrt(t_1);
double tmp;
if ((cbrt((pow((2.0 * a), -1.0) * (-g + t_0))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)))) <= -1e-100) {
tmp = t_2 + t_2;
} else {
tmp = cbrt((((h / a) * (h / g)) * -0.25)) + pow(t_1, 0.3333333333333333);
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = (0.5 / a) * (-2.0 * g);
double t_2 = Math.cbrt(t_1);
double tmp;
if ((Math.cbrt((Math.pow((2.0 * a), -1.0) * (-g + t_0))) + Math.cbrt(((-1.0 / (2.0 * a)) * (g + t_0)))) <= -1e-100) {
tmp = t_2 + t_2;
} else {
tmp = Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.pow(t_1, 0.3333333333333333);
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = Float64(Float64(0.5 / a) * Float64(-2.0 * g)) t_2 = cbrt(t_1) tmp = 0.0 if (Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + t_0))) + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) <= -1e-100) tmp = Float64(t_2 + t_2); else tmp = Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + (t_1 ^ 0.3333333333333333)); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * g), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 1/3], $MachinePrecision]}, If[LessEqual[N[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(g + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], -1e-100], N[(t$95$2 + t$95$2), $MachinePrecision], N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[t$95$1, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \frac{0.5}{a} \cdot \left(-2 \cdot g\right)\\
t_2 := \sqrt[3]{t\_1}\\
\mathbf{if}\;\sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + t\_0\right)} + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)} \leq -1 \cdot 10^{-100}:\\
\;\;\;\;t\_2 + t\_2\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + {t\_1}^{0.3333333333333333}\\
\end{array}
\end{array}
if (+.f64 (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < -1e-100Initial program 83.8%
Taylor expanded in g around inf
lower-*.f6454.9
Applied rewrites54.9%
Taylor expanded in g around -inf
lower-*.f6417.4
Applied rewrites17.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6417.4
Applied rewrites17.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lift-/.f6417.4
Applied rewrites17.4%
if -1e-100 < (+.f64 (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) Initial program 25.1%
Taylor expanded in g around inf
lower-*.f6416.0
Applied rewrites16.0%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6467.0
Applied rewrites67.0%
lift-cbrt.f64N/A
pow1/3N/A
lower-pow.f6446.3
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6446.3
Applied rewrites46.3%
Applied rewrites46.3%
Final simplification38.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (* (cbrt (/ 0.5 a)) (cbrt (* -2.0 g)))))
double code(double g, double h, double a) {
return cbrt((((h / a) * (h / g)) * -0.25)) + (cbrt((0.5 / a)) * cbrt((-2.0 * g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h / a) * (h / g)) * -0.25)) + (Math.cbrt((0.5 / a)) * Math.cbrt((-2.0 * g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(-2.0 * g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-2.0 * g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{-2 \cdot g}
\end{array}
Initial program 41.8%
Taylor expanded in g around inf
lower-*.f6427.1
Applied rewrites27.1%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
lift-cbrt.f64N/A
pow1/3N/A
lift-*.f64N/A
unpow-prod-downN/A
lower-*.f64N/A
pow1/3N/A
lower-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
pow1/3N/A
lower-cbrt.f6494.5
Applied rewrites94.5%
Applied rewrites94.5%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (* (pow (* 2.0 a) -1.0) (* -2.0 g)))))
double code(double g, double h, double a) {
return cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((pow((2.0 * a), -1.0) * (-2.0 * g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((Math.pow((2.0 * a), -1.0) * (-2.0 * g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(-2.0 * g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[(-2.0 * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(-2 \cdot g\right)}
\end{array}
Initial program 41.8%
Taylor expanded in g around inf
lower-*.f6427.1
Applied rewrites27.1%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6473.3
Applied rewrites73.3%
Applied rewrites73.3%
Final simplification73.3%
(FPCore (g h a) :precision binary64 (let* ((t_0 (cbrt (* (/ 0.5 a) (* -2.0 g))))) (+ t_0 t_0)))
double code(double g, double h, double a) {
double t_0 = cbrt(((0.5 / a) * (-2.0 * g)));
return t_0 + t_0;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt(((0.5 / a) * (-2.0 * g)));
return t_0 + t_0;
}
function code(g, h, a) t_0 = cbrt(Float64(Float64(0.5 / a) * Float64(-2.0 * g))) return Float64(t_0 + t_0) end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-2.0 * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, N[(t$95$0 + t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{0.5}{a} \cdot \left(-2 \cdot g\right)}\\
t\_0 + t\_0
\end{array}
\end{array}
Initial program 41.8%
Taylor expanded in g around inf
lower-*.f6427.1
Applied rewrites27.1%
Taylor expanded in g around -inf
lower-*.f6414.9
Applied rewrites14.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6414.9
Applied rewrites14.9%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lift-/.f6414.9
Applied rewrites14.9%
herbie shell --seed 2024298
(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))))))))