
(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 4 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 (/ 0.5 a)) (cbrt (* g -2.0))) (cbrt (* (- g g) (/ -0.5 a)))))
double code(double g, double h, double a) {
return (cbrt((0.5 / a)) * cbrt((g * -2.0))) + cbrt(((g - g) * (-0.5 / a)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt((0.5 / a)) * Math.cbrt((g * -2.0))) + Math.cbrt(((g - g) * (-0.5 / a)));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(g * -2.0))) + cbrt(Float64(Float64(g - g) * Float64(-0.5 / a)))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g \cdot -2} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around -inf 74.5%
neg-mul-174.5%
Simplified74.5%
cbrt-prod96.2%
Applied egg-rr96.2%
Final simplification96.2%
(FPCore (g h a) :precision binary64 (+ (cbrt 0.0) (/ (cbrt (- g)) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(0.0) + (cbrt(-g) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(0.0) + (Math.cbrt(-g) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(0.0) + Float64(cbrt(Float64(-g)) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[0.0, 1/3], $MachinePrecision] + N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around inf 15.4%
add-log-exp27.4%
*-commutative27.4%
exp-prod18.3%
add-sqr-sqrt12.5%
sqrt-unprod16.8%
*-commutative16.8%
*-commutative16.8%
swap-sqr16.8%
metadata-eval16.8%
metadata-eval16.8%
swap-sqr16.8%
count-216.8%
count-216.8%
sqrt-unprod4.3%
add-sqr-sqrt15.6%
add-sqr-sqrt14.7%
sqrt-unprod38.1%
frac-times40.4%
metadata-eval40.4%
metadata-eval40.4%
frac-times38.1%
sqrt-unprod16.3%
add-sqr-sqrt18.3%
Applied egg-rr74.5%
associate-*r/74.5%
cbrt-div96.0%
count-296.0%
Applied egg-rr96.0%
*-commutative96.0%
associate-*r*96.0%
metadata-eval96.0%
mul-1-neg96.0%
Simplified96.0%
Final simplification96.0%
(FPCore (g h a) :precision binary64 (+ (cbrt 0.0) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(0.0) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(0.0) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(0.0) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[0.0, 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around inf 15.4%
add-log-exp27.4%
*-commutative27.4%
exp-prod18.3%
add-sqr-sqrt12.5%
sqrt-unprod16.8%
*-commutative16.8%
*-commutative16.8%
swap-sqr16.8%
metadata-eval16.8%
metadata-eval16.8%
swap-sqr16.8%
count-216.8%
count-216.8%
sqrt-unprod4.3%
add-sqr-sqrt15.6%
add-sqr-sqrt14.7%
sqrt-unprod38.1%
frac-times40.4%
metadata-eval40.4%
metadata-eval40.4%
frac-times38.1%
sqrt-unprod16.3%
add-sqr-sqrt18.3%
Applied egg-rr74.5%
Taylor expanded in g around 0 74.5%
associate-*r/74.5%
mul-1-neg74.5%
Simplified74.5%
Final simplification74.5%
(FPCore (g h a) :precision binary64 (+ (cbrt 0.0) (cbrt 0.0)))
double code(double g, double h, double a) {
return cbrt(0.0) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return Math.cbrt(0.0) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(cbrt(0.0) + cbrt(0.0)) end
code[g_, h_, a_] := N[(N[Power[0.0, 1/3], $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0} + \sqrt[3]{0}
\end{array}
Initial program 40.7%
Simplified40.7%
Taylor expanded in g around -inf 27.7%
*-commutative27.7%
Simplified27.7%
Taylor expanded in g around inf 15.4%
add-log-exp27.4%
*-commutative27.4%
exp-prod18.3%
add-sqr-sqrt12.5%
sqrt-unprod16.8%
*-commutative16.8%
*-commutative16.8%
swap-sqr16.8%
metadata-eval16.8%
metadata-eval16.8%
swap-sqr16.8%
count-216.8%
count-216.8%
sqrt-unprod4.3%
add-sqr-sqrt15.6%
add-sqr-sqrt14.7%
sqrt-unprod38.1%
frac-times40.4%
metadata-eval40.4%
metadata-eval40.4%
frac-times38.1%
sqrt-unprod16.3%
add-sqr-sqrt18.3%
Applied egg-rr74.5%
*-commutative74.5%
clear-num74.5%
flip-+0.0%
frac-times0.0%
*-un-lft-identity0.0%
pow20.0%
pow20.0%
*-un-lft-identity0.0%
fma-neg0.0%
add-sqr-sqrt0.4%
sqrt-unprod0.6%
sqr-neg0.6%
sqrt-unprod0.6%
add-sqr-sqrt1.4%
fma-def1.4%
*-un-lft-identity1.4%
count-21.4%
Applied egg-rr1.4%
div-sub1.3%
+-inverses2.9%
Simplified2.9%
Final simplification2.9%
herbie shell --seed 2023326
(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))))))))