
(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 3 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.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.3%
Simplified40.3%
Taylor expanded in g around -inf 26.3%
*-commutative26.3%
Simplified26.3%
Taylor expanded in g around inf 14.9%
Applied egg-rr70.3%
associate-*r/70.4%
cbrt-div94.4%
count-294.4%
Applied egg-rr94.4%
*-commutative94.4%
associate-*r*94.4%
metadata-eval94.4%
neg-mul-194.4%
Simplified94.4%
Final simplification94.4%
(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(g / Float64(-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.3%
Simplified40.3%
Taylor expanded in g around -inf 26.3%
*-commutative26.3%
Simplified26.3%
Taylor expanded in g around inf 14.9%
Applied egg-rr70.3%
Taylor expanded in g around 0 70.4%
associate-*r/70.4%
metadata-eval70.4%
associate-*r*70.4%
associate-*l/70.3%
*-commutative70.3%
rem-cube-cbrt70.2%
*-lft-identity70.2%
cube-prod70.2%
metadata-eval70.2%
metadata-eval70.2%
rem-cube-cbrt70.3%
associate-*r/70.4%
times-frac70.4%
neg-mul-170.4%
distribute-rgt-neg-in70.4%
*-commutative70.4%
metadata-eval70.4%
associate-*l*70.4%
metadata-eval70.4%
*-rgt-identity70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification70.4%
(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.3%
Simplified40.3%
Taylor expanded in g around -inf 26.3%
*-commutative26.3%
Simplified26.3%
Taylor expanded in g around inf 14.9%
Applied egg-rr70.3%
*-commutative70.3%
clear-num70.3%
flip-+0.0%
frac-times0.0%
*-un-lft-identity0.0%
pow20.0%
pow20.0%
div-inv0.0%
metadata-eval0.0%
*-un-lft-identity0.0%
fma-neg0.0%
add-sqr-sqrt0.4%
sqrt-unprod0.8%
sqr-neg0.8%
sqrt-prod0.7%
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 2024021
(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))))))))