
(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 4 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) (* (cbrt -1.0) (pow 4.0 0.16666666666666666)))))
double code(double g, double h, double a) {
return cbrt((0.5 / a)) * (cbrt(g) * (cbrt(-1.0) * pow(4.0, 0.16666666666666666)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.5 / a)) * (Math.cbrt(g) * (Math.cbrt(-1.0) * Math.pow(4.0, 0.16666666666666666)));
}
function code(g, h, a) return Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(g) * Float64(cbrt(-1.0) * (4.0 ^ 0.16666666666666666)))) end
code[g_, h_, a_] := N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[g, 1/3], $MachinePrecision] * N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[4.0, 0.16666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{g} \cdot \left(\sqrt[3]{-1} \cdot {4}^{0.16666666666666666}\right)\right)
\end{array}
Initial program 46.7%
Applied rewrites13.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6496.1
Applied rewrites96.1%
Applied rewrites96.6%
(FPCore (g h a) :precision binary64 (if (<= (pow (* 2.0 a) -1.0) 2e+76) (* (cbrt (/ g a)) (cbrt -1.0)) (* (pow (* 2.0 a) -0.3333333333333333) (cbrt (* g -2.0)))))
double code(double g, double h, double a) {
double tmp;
if (pow((2.0 * a), -1.0) <= 2e+76) {
tmp = cbrt((g / a)) * cbrt(-1.0);
} else {
tmp = pow((2.0 * a), -0.3333333333333333) * cbrt((g * -2.0));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (Math.pow((2.0 * a), -1.0) <= 2e+76) {
tmp = Math.cbrt((g / a)) * Math.cbrt(-1.0);
} else {
tmp = Math.pow((2.0 * a), -0.3333333333333333) * Math.cbrt((g * -2.0));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((Float64(2.0 * a) ^ -1.0) <= 2e+76) tmp = Float64(cbrt(Float64(g / a)) * cbrt(-1.0)); else tmp = Float64((Float64(2.0 * a) ^ -0.3333333333333333) * cbrt(Float64(g * -2.0))); end return tmp end
code[g_, h_, a_] := If[LessEqual[N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision], 2e+76], N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(2.0 * a), $MachinePrecision], -0.3333333333333333], $MachinePrecision] * N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;{\left(2 \cdot a\right)}^{-1} \leq 2 \cdot 10^{+76}:\\
\;\;\;\;\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{-1}\\
\mathbf{else}:\\
\;\;\;\;{\left(2 \cdot a\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)) < 2.0000000000000001e76Initial program 51.5%
lift-cbrt.f64N/A
pow1/3N/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
pow1/3N/A
lift-cbrt.f64N/A
lower-fabs.f6437.5
lift-*.f64N/A
*-commutativeN/A
Applied rewrites14.1%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-neg.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
Applied rewrites8.9%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6486.9
Applied rewrites86.9%
if 2.0000000000000001e76 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) Initial program 24.0%
Applied rewrites8.2%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6497.0
Applied rewrites97.0%
Applied rewrites96.0%
lift-cbrt.f64N/A
pow1/3N/A
lift-/.f64N/A
metadata-evalN/A
associate-/r*N/A
lift-*.f64N/A
inv-powN/A
pow-powN/A
lower-pow.f64N/A
metadata-eval88.3
Applied rewrites88.3%
Final simplification87.2%
(FPCore (g h a) :precision binary64 (* (cbrt (/ 0.5 a)) (cbrt (* g -2.0))))
double code(double g, double h, double a) {
return cbrt((0.5 / a)) * cbrt((g * -2.0));
}
public static double code(double g, double h, double a) {
return Math.cbrt((0.5 / a)) * Math.cbrt((g * -2.0));
}
function code(g, h, a) return Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(g * -2.0))) end
code[g_, h_, a_] := N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g \cdot -2}
\end{array}
Initial program 46.7%
Applied rewrites13.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6496.1
Applied rewrites96.1%
Applied rewrites96.3%
(FPCore (g h a) :precision binary64 (* (cbrt (/ g a)) (cbrt -1.0)))
double code(double g, double h, double a) {
return cbrt((g / a)) * cbrt(-1.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt((g / a)) * Math.cbrt(-1.0);
}
function code(g, h, a) return Float64(cbrt(Float64(g / a)) * cbrt(-1.0)) end
code[g_, h_, a_] := N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{-1}
\end{array}
Initial program 46.7%
lift-cbrt.f64N/A
pow1/3N/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
pow1/3N/A
lift-cbrt.f64N/A
lower-fabs.f6435.1
lift-*.f64N/A
*-commutativeN/A
Applied rewrites12.6%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift--.f64N/A
lift-neg.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
Applied rewrites7.4%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6477.2
Applied rewrites77.2%
herbie shell --seed 2024339
(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))))))))