
(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 (+ (* (cbrt (fma 2.0 g h)) (cbrt (/ -0.5 a))) (cbrt (* (/ -0.5 a) (- g g)))))
double code(double g, double h, double a) {
return (cbrt(fma(2.0, g, h)) * cbrt((-0.5 / a))) + cbrt(((-0.5 / a) * (g - g)));
}
function code(g, h, a) return Float64(Float64(cbrt(fma(2.0, g, h)) * cbrt(Float64(-0.5 / a))) + cbrt(Float64(Float64(-0.5 / a) * Float64(g - g)))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(2.0 * g + h), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\mathsf{fma}\left(2, g, h\right)} \cdot \sqrt[3]{\frac{-0.5}{a}} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)}
\end{array}
Initial program 49.5%
Simplified49.5%
Applied egg-rr12.9%
+-commutative12.9%
+-commutative12.9%
associate-+l+12.9%
Simplified12.9%
Taylor expanded in g around -inf 20.2%
mul-1-neg20.2%
Simplified20.2%
add-cbrt-cube20.1%
sqrt-unprod20.1%
sqrt-prod20.1%
add-cube-cbrt20.2%
unpow220.2%
sqrt-prod1.0%
add-sqr-sqrt1.5%
Applied egg-rr95.0%
Final simplification95.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ -0.5 a) (- g g))) (/ (cbrt (* -0.5 (+ g (+ g h)))) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * (g - g))) + (cbrt((-0.5 * (g + (g + h)))) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * (g - g))) + (Math.cbrt((-0.5 * (g + (g + h)))) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-0.5 / a) * Float64(g - g))) + Float64(cbrt(Float64(-0.5 * Float64(g + Float64(g + h)))) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + N[(g + h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-0.5}{a} \cdot \left(g - g\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + \left(g + h\right)\right)}}{\sqrt[3]{a}}
\end{array}
Initial program 49.5%
Simplified49.5%
Applied egg-rr36.3%
Taylor expanded in g around -inf 95.0%
mul-1-neg20.2%
Simplified95.0%
Final simplification95.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (* h (/ 0.5 a))) (* (cbrt (/ -0.5 a)) (cbrt (+ g g)))))
double code(double g, double h, double a) {
return cbrt((h * (0.5 / a))) + (cbrt((-0.5 / a)) * cbrt((g + g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((h * (0.5 / a))) + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + g)));
}
function code(g, h, a) return Float64(cbrt(Float64(h * Float64(0.5 / a))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + g)))) end
code[g_, h_, a_] := N[(N[Power[N[(h * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{h \cdot \frac{0.5}{a}} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + g}
\end{array}
Initial program 49.5%
Simplified49.5%
fma-neg49.5%
distribute-rgt-neg-out49.5%
add-sqr-sqrt43.1%
add-sqr-sqrt27.9%
difference-of-squares27.9%
Applied egg-rr28.0%
difference-of-squares28.0%
rem-square-sqrt21.6%
rem-square-sqrt29.2%
unsub-neg29.2%
mul-1-neg29.2%
+-commutative29.2%
associate-+l+28.6%
mul-1-neg28.6%
sub-neg28.6%
+-inverses28.6%
+-rgt-identity28.6%
Simplified28.6%
Taylor expanded in g around inf 73.8%
*-commutative73.8%
cbrt-prod90.3%
Applied egg-rr90.3%
Final simplification90.3%
(FPCore (g h a) :precision binary64 (+ (cbrt (* h (/ 0.5 a))) (/ (cbrt (* -0.5 (+ g g))) (cbrt a))))
double code(double g, double h, double a) {
return cbrt((h * (0.5 / a))) + (cbrt((-0.5 * (g + g))) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((h * (0.5 / a))) + (Math.cbrt((-0.5 * (g + g))) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(h * Float64(0.5 / a))) + Float64(cbrt(Float64(-0.5 * Float64(g + g))) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(h * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(-0.5 * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{h \cdot \frac{0.5}{a}} + \frac{\sqrt[3]{-0.5 \cdot \left(g + g\right)}}{\sqrt[3]{a}}
\end{array}
Initial program 49.5%
Simplified49.5%
fma-neg49.5%
distribute-rgt-neg-out49.5%
add-sqr-sqrt43.1%
add-sqr-sqrt27.9%
difference-of-squares27.9%
Applied egg-rr28.0%
difference-of-squares28.0%
rem-square-sqrt21.6%
rem-square-sqrt29.2%
unsub-neg29.2%
mul-1-neg29.2%
+-commutative29.2%
associate-+l+28.6%
mul-1-neg28.6%
sub-neg28.6%
+-inverses28.6%
+-rgt-identity28.6%
Simplified28.6%
Taylor expanded in g around inf 73.8%
associate-*r/73.8%
cbrt-div90.3%
Applied egg-rr90.3%
Final simplification90.3%
(FPCore (g h a)
:precision binary64
(if (<= (* h h) 2e+176)
(+
(cbrt (* (/ 0.5 a) (- (- (/ 0.5 (/ g (* h h))) g) g)))
(cbrt (* (/ -0.5 a) (* 0.5 (/ h (/ g h))))))
(* (cbrt (/ g a)) (cbrt -1.0))))
double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 2e+176) {
tmp = cbrt(((0.5 / a) * (((0.5 / (g / (h * h))) - g) - g))) + cbrt(((-0.5 / a) * (0.5 * (h / (g / h)))));
} else {
tmp = cbrt((g / a)) * cbrt(-1.0);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 2e+176) {
tmp = Math.cbrt(((0.5 / a) * (((0.5 / (g / (h * h))) - g) - g))) + Math.cbrt(((-0.5 / a) * (0.5 * (h / (g / h)))));
} else {
tmp = Math.cbrt((g / a)) * Math.cbrt(-1.0);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (Float64(h * h) <= 2e+176) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(Float64(Float64(0.5 / Float64(g / Float64(h * h))) - g) - g))) + cbrt(Float64(Float64(-0.5 / a) * Float64(0.5 * Float64(h / Float64(g / h)))))); else tmp = Float64(cbrt(Float64(g / a)) * cbrt(-1.0)); end return tmp end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 2e+176], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[(N[(0.5 / N[(g / N[(h * h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - g), $MachinePrecision] - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(0.5 * N[(h / N[(g / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 2 \cdot 10^{+176}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(\left(\frac{0.5}{\frac{g}{h \cdot h}} - g\right) - g\right)} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(0.5 \cdot \frac{h}{\frac{g}{h}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{g}{a}} \cdot \sqrt[3]{-1}\\
\end{array}
\end{array}
if (*.f64 h h) < 2e176Initial program 54.7%
Simplified54.7%
Taylor expanded in g around -inf 30.8%
+-commutative30.8%
mul-1-neg30.8%
unsub-neg30.8%
associate-*r/30.8%
associate-/l*30.8%
unpow230.8%
Simplified30.8%
Taylor expanded in g around -inf 81.2%
unpow281.2%
associate-/l*81.6%
Simplified81.6%
if 2e176 < (*.f64 h h) Initial program 9.9%
Simplified9.9%
fma-neg9.9%
distribute-rgt-neg-out9.9%
add-sqr-sqrt9.9%
add-sqr-sqrt6.6%
difference-of-squares6.6%
Applied egg-rr7.2%
difference-of-squares7.2%
rem-square-sqrt7.2%
rem-square-sqrt7.4%
unsub-neg7.4%
mul-1-neg7.4%
+-commutative7.4%
associate-+l+6.3%
mul-1-neg6.3%
sub-neg6.3%
+-inverses6.3%
+-rgt-identity6.3%
Simplified6.3%
Taylor expanded in g around inf 48.3%
Taylor expanded in g around 0 48.3%
Taylor expanded in h around 0 27.9%
unpow1/355.2%
*-lft-identity55.2%
Simplified55.2%
Final simplification78.5%
(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 49.5%
Simplified49.5%
fma-neg49.5%
distribute-rgt-neg-out49.5%
add-sqr-sqrt43.1%
add-sqr-sqrt27.9%
difference-of-squares27.9%
Applied egg-rr28.0%
difference-of-squares28.0%
rem-square-sqrt21.6%
rem-square-sqrt29.2%
unsub-neg29.2%
mul-1-neg29.2%
+-commutative29.2%
associate-+l+28.6%
mul-1-neg28.6%
sub-neg28.6%
+-inverses28.6%
+-rgt-identity28.6%
Simplified28.6%
Taylor expanded in g around inf 73.8%
Taylor expanded in g around 0 73.8%
Taylor expanded in h around 0 40.8%
unpow1/376.8%
*-lft-identity76.8%
Simplified76.8%
Final simplification76.8%
herbie shell --seed 2023292
(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))))))))