
(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 6 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
(if (<= g -2e-298)
(+ (/ (cbrt (* -0.25 (* (/ h g) h))) (cbrt a)) (cbrt (/ (- g) a)))
(+
(/ (cbrt (- (fma (sqrt (+ h g)) (sqrt (- g h)) g))) (cbrt (* a 2.0)))
(cbrt (* (/ (* 0.0 h) a) 0.25)))))
double code(double g, double h, double a) {
double tmp;
if (g <= -2e-298) {
tmp = (cbrt((-0.25 * ((h / g) * h))) / cbrt(a)) + cbrt((-g / a));
} else {
tmp = (cbrt(-fma(sqrt((h + g)), sqrt((g - h)), g)) / cbrt((a * 2.0))) + cbrt((((0.0 * h) / a) * 0.25));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -2e-298) tmp = Float64(Float64(cbrt(Float64(-0.25 * Float64(Float64(h / g) * h))) / cbrt(a)) + cbrt(Float64(Float64(-g) / a))); else tmp = Float64(Float64(cbrt(Float64(-fma(sqrt(Float64(h + g)), sqrt(Float64(g - h)), g))) / cbrt(Float64(a * 2.0))) + cbrt(Float64(Float64(Float64(0.0 * h) / a) * 0.25))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, -2e-298], N[(N[(N[Power[N[(-0.25 * N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[(-N[(N[Sqrt[N[(h + g), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(g - h), $MachinePrecision]], $MachinePrecision] + g), $MachinePrecision]), 1/3], $MachinePrecision] / N[Power[N[(a * 2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(N[(0.0 * h), $MachinePrecision] / a), $MachinePrecision] * 0.25), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -2 \cdot 10^{-298}:\\
\;\;\;\;\frac{\sqrt[3]{-0.25 \cdot \left(\frac{h}{g} \cdot h\right)}}{\sqrt[3]{a}} + \sqrt[3]{\frac{-g}{a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{-\mathsf{fma}\left(\sqrt{h + g}, \sqrt{g - h}, g\right)}}{\sqrt[3]{a \cdot 2}} + \sqrt[3]{\frac{0 \cdot h}{a} \cdot 0.25}\\
\end{array}
\end{array}
if g < -1.99999999999999982e-298Initial program 43.4%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6411.1
Applied rewrites11.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.f6479.4
Applied rewrites79.4%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6479.4
Applied rewrites79.4%
Applied rewrites79.4%
if -1.99999999999999982e-298 < g Initial program 38.9%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6438.9
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6438.9
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
Applied rewrites38.9%
Applied rewrites47.9%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-*.f6495.6
Applied rewrites95.6%
Final simplification87.7%
(FPCore (g h a) :precision binary64 (+ (/ (cbrt (* -0.25 (* (/ h g) h))) (cbrt a)) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return (cbrt((-0.25 * ((h / g) * h))) / cbrt(a)) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return (Math.cbrt((-0.25 * ((h / g) * h))) / Math.cbrt(a)) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-0.25 * Float64(Float64(h / g) * h))) / cbrt(a)) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(-0.25 * N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-0.25 \cdot \left(\frac{h}{g} \cdot h\right)}}{\sqrt[3]{a}} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 41.1%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6425.1
Applied rewrites25.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.f6475.3
Applied rewrites75.3%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6475.3
Applied rewrites75.3%
Applied rewrites75.4%
Final simplification75.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (/ -1.0 (/ a g)))))
double code(double g, double h, double a) {
return cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((-1.0 / (a / g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((-1.0 / (a / g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64(-1.0 / Float64(a / 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[(-1.0 / N[(a / 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]{\frac{-1}{\frac{a}{g}}}
\end{array}
Initial program 41.1%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6425.1
Applied rewrites25.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.f6475.3
Applied rewrites75.3%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6475.3
Applied rewrites75.3%
Applied rewrites75.3%
Final simplification75.3%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64(Float64(-g) / a))) 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[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 41.1%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6425.1
Applied rewrites25.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.f6475.3
Applied rewrites75.3%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6475.3
Applied rewrites75.3%
Final simplification75.3%
(FPCore (g h a) :precision binary64 (* (cbrt -1.0) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt(-1.0) * cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-1.0) * Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(-1.0) * cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-1} \cdot \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 41.1%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6441.1
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6441.1
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f6441.1
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
Applied rewrites41.1%
Applied rewrites24.7%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6473.9
Applied rewrites73.9%
Final simplification73.9%
(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 41.1%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
*-commutativeN/A
times-fracN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-cbrt.f64N/A
div-invN/A
metadata-evalN/A
Applied rewrites42.9%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
lower-cbrt.f642.9
Applied rewrites2.9%
Taylor expanded in a around 0
Applied rewrites2.9%
herbie shell --seed 2024253
(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))))))))