
(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
(let* ((t_0 (sqrt (- (* g g) (* h h)))) (t_1 (sqrt (* (+ h g) (- g h)))))
(if (<=
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) t_0)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0))))
-5e+46)
(* (cbrt (/ 0.5 a)) (+ (cbrt (- t_1 g)) (cbrt (- (- g) t_1))))
(+ (* (cbrt (/ h a)) (cbrt (* (/ h g) -0.25))) (cbrt (/ (- g) a))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = sqrt(((h + g) * (g - h)));
double tmp;
if ((cbrt((pow((2.0 * a), -1.0) * (-g + t_0))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)))) <= -5e+46) {
tmp = cbrt((0.5 / a)) * (cbrt((t_1 - g)) + cbrt((-g - t_1)));
} else {
tmp = (cbrt((h / a)) * cbrt(((h / g) * -0.25))) + cbrt((-g / a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.sqrt(((h + g) * (g - h)));
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)))) <= -5e+46) {
tmp = Math.cbrt((0.5 / a)) * (Math.cbrt((t_1 - g)) + Math.cbrt((-g - t_1)));
} else {
tmp = (Math.cbrt((h / a)) * Math.cbrt(((h / g) * -0.25))) + Math.cbrt((-g / a));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = sqrt(Float64(Float64(h + g) * Float64(g - h))) 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)))) <= -5e+46) tmp = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(t_1 - g)) + cbrt(Float64(Float64(-g) - t_1)))); else tmp = Float64(Float64(cbrt(Float64(h / a)) * cbrt(Float64(Float64(h / g) * -0.25))) + cbrt(Float64(Float64(-g) / a))); 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[Sqrt[N[(N[(h + g), $MachinePrecision] * N[(g - h), $MachinePrecision]), $MachinePrecision]], $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], -5e+46], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[N[(t$95$1 - g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) - t$95$1), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(h / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[(h / g), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt{\left(h + g\right) \cdot \left(g - h\right)}\\
\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 -5 \cdot 10^{+46}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{t\_1 - g} + \sqrt[3]{\left(-g\right) - t\_1}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{h}{a}} \cdot \sqrt[3]{\frac{h}{g} \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}\\
\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))))))) < -5.0000000000000002e46Initial program 68.4%
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.f6487.2
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6487.2
Applied rewrites87.2%
lift-+.f64N/A
lift-*.f64N/A
lift-cbrt.f64N/A
lift-/.f64N/A
metadata-evalN/A
associate-/r*N/A
lift-*.f64N/A
lift-/.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
Applied rewrites96.8%
if -5.0000000000000002e46 < (+.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 41.8%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6424.7
Applied rewrites24.7%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6474.7
Applied rewrites74.7%
Applied rewrites74.8%
Final simplification76.5%
(FPCore (g h a) :precision binary64 (+ (* (cbrt (/ h a)) (cbrt (* (/ h g) -0.25))) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return (cbrt((h / a)) * cbrt(((h / g) * -0.25))) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return (Math.cbrt((h / a)) * Math.cbrt(((h / g) * -0.25))) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(h / a)) * cbrt(Float64(Float64(h / g) * -0.25))) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(h / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[(h / g), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{h}{a}} \cdot \sqrt[3]{\frac{h}{g} \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 43.9%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6426.1
Applied rewrites26.1%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6474.1
Applied rewrites74.1%
Applied rewrites74.1%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g) a)) (cbrt (* -0.25 (* (/ h g) (/ h a))))))
double code(double g, double h, double a) {
return cbrt((-g / a)) + cbrt((-0.25 * ((h / g) * (h / a))));
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) + Math.cbrt((-0.25 * ((h / g) * (h / a))));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(Float64(-0.25 * Float64(Float64(h / g) * Float64(h / a))))) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / g), $MachinePrecision] * N[(h / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{-0.25 \cdot \left(\frac{h}{g} \cdot \frac{h}{a}\right)}
\end{array}
Initial program 43.9%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6426.1
Applied rewrites26.1%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6474.1
Applied rewrites74.1%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6474.1
Applied rewrites74.1%
(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 43.9%
lift-*.f64N/A
lift--.f64N/A
distribute-rgt-out--N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
associate-*r/N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
associate-*r/N/A
sub-divN/A
lower-/.f64N/A
Applied rewrites43.9%
lift-cbrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-+.f64N/A
+-commutativeN/A
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
+-commutativeN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
lift-*.f64N/A
lift-neg.f64N/A
sub-negN/A
lift--.f64N/A
lift-/.f64N/A
clear-numN/A
Applied rewrites46.5%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6471.0
Applied rewrites71.0%
(FPCore (g h a) :precision binary64 0.0)
double code(double g, double h, double a) {
return 0.0;
}
real(8) function code(g, h, a)
real(8), intent (in) :: g
real(8), intent (in) :: h
real(8), intent (in) :: a
code = 0.0d0
end function
public static double code(double g, double h, double a) {
return 0.0;
}
def code(g, h, a): return 0.0
function code(g, h, a) return 0.0 end
function tmp = code(g, h, a) tmp = 0.0; end
code[g_, h_, a_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 43.9%
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.f6446.5
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6446.5
Applied rewrites46.5%
Taylor expanded in g around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
unpow2N/A
rem-square-sqrtN/A
lower-cbrt.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
lower-/.f64N/A
lower-cbrt.f643.0
Applied rewrites3.0%
Applied rewrites3.0%
herbie shell --seed 2024311
(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))))))))