
(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}
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}
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}
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}
(FPCore (g h a) :precision binary64 (/ (+ (cbrt (* (/ (- (+ g 0.0) g) (+ a a)) (* a -2.0))) (cbrt (+ (+ g 0.0) g))) (cbrt (* a -2.0))))
double code(double g, double h, double a) {
return (cbrt(((((g + 0.0) - g) / (a + a)) * (a * -2.0))) + cbrt(((g + 0.0) + g))) / cbrt((a * -2.0));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(((((g + 0.0) - g) / (a + a)) * (a * -2.0))) + Math.cbrt(((g + 0.0) + g))) / Math.cbrt((a * -2.0));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(Float64(Float64(Float64(g + 0.0) - g) / Float64(a + a)) * Float64(a * -2.0))) + cbrt(Float64(Float64(g + 0.0) + g))) / cbrt(Float64(a * -2.0))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(N[(N[(N[(g + 0.0), $MachinePrecision] - g), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision] * N[(a * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(g + 0.0), $MachinePrecision] + g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[N[(a * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\frac{\sqrt[3]{\frac{\left(g + 0\right) - g}{a + a} \cdot \left(a \cdot -2\right)} + \sqrt[3]{\left(g + 0\right) + g}}{\sqrt[3]{a \cdot -2}}
Initial program 43.3%
Applied rewrites46.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6432.2%
Applied rewrites32.2%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6495.9%
Applied rewrites95.9%
lift-cbrt.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
associate-/l/N/A
distribute-rgt-neg-inN/A
count-2-revN/A
lift-+.f64N/A
cbrt-divN/A
metadata-evalN/A
cbrt-neg-revN/A
lower-/.f64N/A
cbrt-neg-revN/A
lower-cbrt.f64N/A
lift-+.f64N/A
count-2-revN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval95.7%
Applied rewrites95.7%
Applied rewrites95.7%
(FPCore (g h a) :precision binary64 (fma (/ 1.0 (cbrt (* -2.0 a))) (cbrt (+ (+ g 0.0) g)) (cbrt (/ (- (+ g 0.0) g) (+ a a)))))
double code(double g, double h, double a) {
return fma((1.0 / cbrt((-2.0 * a))), cbrt(((g + 0.0) + g)), cbrt((((g + 0.0) - g) / (a + a))));
}
function code(g, h, a) return fma(Float64(1.0 / cbrt(Float64(-2.0 * a))), cbrt(Float64(Float64(g + 0.0) + g)), cbrt(Float64(Float64(Float64(g + 0.0) - g) / Float64(a + a)))) end
code[g_, h_, a_] := N[(N[(1.0 / N[Power[N[(-2.0 * a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[(g + 0.0), $MachinePrecision] + g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(N[(g + 0.0), $MachinePrecision] - g), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\frac{1}{\sqrt[3]{-2 \cdot a}}, \sqrt[3]{\left(g + 0\right) + g}, \sqrt[3]{\frac{\left(g + 0\right) - g}{a + a}}\right)
Initial program 43.3%
Applied rewrites46.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6432.2%
Applied rewrites32.2%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6495.9%
Applied rewrites95.9%
lift-cbrt.f64N/A
lift-/.f64N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
associate-/l/N/A
distribute-rgt-neg-inN/A
count-2-revN/A
lift-+.f64N/A
cbrt-divN/A
metadata-evalN/A
cbrt-neg-revN/A
lower-/.f64N/A
cbrt-neg-revN/A
lower-cbrt.f64N/A
lift-+.f64N/A
count-2-revN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-eval95.7%
Applied rewrites95.7%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lift-*.f64N/A
lift-+.f64N/A
lower-+.f6495.7%
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lft95.7%
Applied rewrites95.7%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lift-*.f64N/A
lift-+.f64N/A
lower-+.f6495.7%
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lft95.7%
Applied rewrites95.7%
(FPCore (g h a) :precision binary64 (fma (cbrt (/ -0.5 a)) (cbrt (+ (+ g 0.0) g)) (cbrt (/ (- (+ g 0.0) g) (+ a a)))))
double code(double g, double h, double a) {
return fma(cbrt((-0.5 / a)), cbrt(((g + 0.0) + g)), cbrt((((g + 0.0) - g) / (a + a))));
}
function code(g, h, a) return fma(cbrt(Float64(-0.5 / a)), cbrt(Float64(Float64(g + 0.0) + g)), cbrt(Float64(Float64(Float64(g + 0.0) - g) / Float64(a + a)))) end
code[g_, h_, a_] := N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[(g + 0.0), $MachinePrecision] + g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(N[(g + 0.0), $MachinePrecision] - g), $MachinePrecision] / N[(a + a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\mathsf{fma}\left(\sqrt[3]{\frac{-0.5}{a}}, \sqrt[3]{\left(g + 0\right) + g}, \sqrt[3]{\frac{\left(g + 0\right) - g}{a + a}}\right)
Initial program 43.3%
Applied rewrites46.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6432.2%
Applied rewrites32.2%
Taylor expanded in g around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6495.9%
Applied rewrites95.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lift-*.f64N/A
lift-+.f64N/A
lower-+.f6495.9%
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lft95.9%
Applied rewrites95.9%
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
sum-to-mult-revN/A
*-commutativeN/A
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lift-*.f64N/A
lift-+.f64N/A
lower-+.f6495.9%
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lft95.9%
Applied rewrites95.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 1.0 (* 2.0 a)) (* -0.5 (* h (/ h g))))) (cbrt (* -1.0 (/ g a)))))
double code(double g, double h, double a) {
return cbrt(((1.0 / (2.0 * a)) * (-0.5 * (h * (h / g))))) + cbrt((-1.0 * (g / a)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((1.0 / (2.0 * a)) * (-0.5 * (h * (h / g))))) + Math.cbrt((-1.0 * (g / a)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(-0.5 * Float64(h * Float64(h / g))))) + cbrt(Float64(-1.0 * Float64(g / a)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(-0.5 * N[(h * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-1.0 * N[(g / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(-0.5 \cdot \left(h \cdot \frac{h}{g}\right)\right)} + \sqrt[3]{-1 \cdot \frac{g}{a}}
Initial program 43.3%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f6426.8%
Applied rewrites26.8%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
lower-pow.f6470.2%
Applied rewrites70.2%
lift-/.f64N/A
lift-pow.f64N/A
pow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.0%
Applied rewrites74.0%
(FPCore (g h a) :precision binary64 (- (cbrt (/ (- g) a)) (cbrt (/ 0.0 a))))
double code(double g, double h, double a) {
return cbrt((-g / a)) - cbrt((0.0 / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) - Math.cbrt((0.0 / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) - cbrt(Float64(0.0 / a))) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(0.0 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\sqrt[3]{\frac{-g}{a}} - \sqrt[3]{\frac{0}{a}}
Initial program 43.3%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f6426.8%
Applied rewrites26.8%
Applied rewrites26.9%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
lower-+.f64N/A
lower-*.f6472.5%
Applied rewrites72.5%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
associate-*l/N/A
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lift-*.f64N/A
lift-+.f64N/A
lift-/.f6472.5%
lift-+.f64N/A
lift-*.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lft72.5%
Applied rewrites72.5%
herbie shell --seed 2025214
(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))))))))