
(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
(let* ((t_0 (/ 1.0 (* 2.0 a)))
(t_1 (sqrt (- (* g g) (* h h))))
(t_2 (cbrt (* (+ g t_1) (/ -1.0 (* 2.0 a))))))
(if (<= (+ (cbrt (* t_0 (- t_1 g))) t_2) (- INFINITY))
(+
t_2
(*
g
(fma
0.16666666666666666
(/
(* (cbrt (/ 1.0 (* a (pow g 8.0)))) (* (* h h) (cbrt 0.5)))
(pow (cbrt -2.0) 2.0))
(* (cbrt (/ 1.0 (* a (* g g)))) (* (cbrt 0.5) (cbrt -2.0))))))
(+ (cbrt (* t_0 (/ (* (* h h) -0.5) g))) (cbrt (* t_0 (* g -2.0)))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
double t_2 = cbrt(((g + t_1) * (-1.0 / (2.0 * a))));
double tmp;
if ((cbrt((t_0 * (t_1 - g))) + t_2) <= -((double) INFINITY)) {
tmp = t_2 + (g * fma(0.16666666666666666, ((cbrt((1.0 / (a * pow(g, 8.0)))) * ((h * h) * cbrt(0.5))) / pow(cbrt(-2.0), 2.0)), (cbrt((1.0 / (a * (g * g)))) * (cbrt(0.5) * cbrt(-2.0)))));
} else {
tmp = cbrt((t_0 * (((h * h) * -0.5) / g))) + cbrt((t_0 * (g * -2.0)));
}
return tmp;
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_2 = cbrt(Float64(Float64(g + t_1) * Float64(-1.0 / Float64(2.0 * a)))) tmp = 0.0 if (Float64(cbrt(Float64(t_0 * Float64(t_1 - g))) + t_2) <= Float64(-Inf)) tmp = Float64(t_2 + Float64(g * fma(0.16666666666666666, Float64(Float64(cbrt(Float64(1.0 / Float64(a * (g ^ 8.0)))) * Float64(Float64(h * h) * cbrt(0.5))) / (cbrt(-2.0) ^ 2.0)), Float64(cbrt(Float64(1.0 / Float64(a * Float64(g * g)))) * Float64(cbrt(0.5) * cbrt(-2.0)))))); else tmp = Float64(cbrt(Float64(t_0 * Float64(Float64(Float64(h * h) * -0.5) / g))) + cbrt(Float64(t_0 * Float64(g * -2.0)))); end return tmp 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]}, Block[{t$95$2 = N[Power[N[(N[(g + t$95$1), $MachinePrecision] * N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(N[Power[N[(t$95$0 * N[(t$95$1 - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + t$95$2), $MachinePrecision], (-Infinity)], N[(t$95$2 + N[(g * N[(0.16666666666666666 * N[(N[(N[Power[N[(1.0 / N[(a * N[Power[g, 8.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[(h * h), $MachinePrecision] * N[Power[0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[Power[-2.0, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(1.0 / N[(a * N[(g * g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[0.5, 1/3], $MachinePrecision] * N[Power[-2.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(t$95$0 * N[(N[(N[(h * h), $MachinePrecision] * -0.5), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[(g * -2.0), $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}\\
t_2 := \sqrt[3]{\left(g + t\_1\right) \cdot \frac{-1}{2 \cdot a}}\\
\mathbf{if}\;\sqrt[3]{t\_0 \cdot \left(t\_1 - g\right)} + t\_2 \leq -\infty:\\
\;\;\;\;t\_2 + g \cdot \mathsf{fma}\left(0.16666666666666666, \frac{\sqrt[3]{\frac{1}{a \cdot {g}^{8}}} \cdot \left(\left(h \cdot h\right) \cdot \sqrt[3]{0.5}\right)}{{\left(\sqrt[3]{-2}\right)}^{2}}, \sqrt[3]{\frac{1}{a \cdot \left(g \cdot g\right)}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-2}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{t\_0 \cdot \frac{\left(h \cdot h\right) \cdot -0.5}{g}} + \sqrt[3]{t\_0 \cdot \left(g \cdot -2\right)}\\
\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))))))) < -inf.0Initial program 4.4%
Taylor expanded in g around -inf
mul-1-negN/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-neg.f644.4
Simplified4.4%
Taylor expanded in g around inf
lower-*.f64N/A
lower-fma.f64N/A
Simplified97.8%
if -inf.0 < (+.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 42.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.5
Simplified25.5%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6472.3
Simplified72.3%
Final simplification72.8%
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a)))) (+ (cbrt (* t_0 (/ (* (* h h) -0.5) g))) (cbrt (* t_0 (* g -2.0))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
return cbrt((t_0 * (((h * h) * -0.5) / g))) + cbrt((t_0 * (g * -2.0)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
return Math.cbrt((t_0 * (((h * h) * -0.5) / g))) + Math.cbrt((t_0 * (g * -2.0)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) return Float64(cbrt(Float64(t_0 * Float64(Float64(Float64(h * h) * -0.5) / g))) + cbrt(Float64(t_0 * Float64(g * -2.0)))) end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[(N[(N[(h * h), $MachinePrecision] * -0.5), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
\sqrt[3]{t\_0 \cdot \frac{\left(h \cdot h\right) \cdot -0.5}{g}} + \sqrt[3]{t\_0 \cdot \left(g \cdot -2\right)}
\end{array}
\end{array}
Initial program 41.5%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.0
Simplified25.0%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6471.0
Simplified71.0%
Final simplification71.0%
(FPCore (g h a) :precision binary64 (- (cbrt (* (/ 1.0 (* 2.0 a)) (/ (* (* h h) -0.5) g))) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt(((1.0 / (2.0 * a)) * (((h * h) * -0.5) / g))) - cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((1.0 / (2.0 * a)) * (((h * h) * -0.5) / g))) - Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(Float64(Float64(h * h) * -0.5) / g))) - cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(N[(N[(h * h), $MachinePrecision] * -0.5), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{1}{2 \cdot a} \cdot \frac{\left(h \cdot h\right) \cdot -0.5}{g}} - \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 41.5%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.0
Simplified25.0%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6471.0
Simplified71.0%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6471.0
Simplified71.0%
Final simplification71.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 1.0 (* 2.0 a)) (* g -2.0))) (cbrt (/ (* (* h h) -0.25) (* a g)))))
double code(double g, double h, double a) {
return cbrt(((1.0 / (2.0 * a)) * (g * -2.0))) + cbrt((((h * h) * -0.25) / (a * g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((1.0 / (2.0 * a)) * (g * -2.0))) + Math.cbrt((((h * h) * -0.25) / (a * g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(1.0 / Float64(2.0 * a)) * Float64(g * -2.0))) + cbrt(Float64(Float64(Float64(h * h) * -0.25) / Float64(a * g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(N[(h * h), $MachinePrecision] * -0.25), $MachinePrecision] / N[(a * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{1}{2 \cdot a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{\left(h \cdot h\right) \cdot -0.25}{a \cdot g}}
\end{array}
Initial program 41.5%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.0
Simplified25.0%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6471.0
Simplified71.0%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6466.9
Simplified66.9%
Final simplification66.9%
(FPCore (g h a) :precision binary64 (- (cbrt (/ (* (* h h) -0.25) (* a g))) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt((((h * h) * -0.25) / (a * g))) - cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h * h) * -0.25) / (a * g))) - Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h * h) * -0.25) / Float64(a * g))) - cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(N[(h * h), $MachinePrecision] * -0.25), $MachinePrecision] / N[(a * g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{\left(h \cdot h\right) \cdot -0.25}{a \cdot g}} - \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 41.5%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.0
Simplified25.0%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6471.0
Simplified71.0%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6471.0
Simplified71.0%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6466.9
Simplified66.9%
Final simplification66.9%
(FPCore (g h a) :precision binary64 (let* ((t_0 (cbrt (/ g a)))) (- (- t_0) t_0)))
double code(double g, double h, double a) {
double t_0 = cbrt((g / a));
return -t_0 - t_0;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt((g / a));
return -t_0 - t_0;
}
function code(g, h, a) t_0 = cbrt(Float64(g / a)) return Float64(Float64(-t_0) - t_0) end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]}, N[((-t$95$0) - t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{a}}\\
\left(-t\_0\right) - t\_0
\end{array}
\end{array}
Initial program 41.5%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f6425.0
Simplified25.0%
Taylor expanded in g around -inf
*-commutativeN/A
lower-*.f6415.2
Simplified15.2%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6415.2
Simplified15.2%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6415.2
Simplified15.2%
Final simplification15.2%
herbie shell --seed 2024215
(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))))))))