
(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 9 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 (- g)) (cbrt a)) (cbrt (* (- g g) (/ -0.5 a)))))
double code(double g, double h, double a) {
return (cbrt(-g) / cbrt(a)) + cbrt(((g - g) * (-0.5 / a)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((g - g) * (-0.5 / a)));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(g - g) * Float64(-0.5 / a)))) end
code[g_, h_, a_] := N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}}
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
associate-*l/75.1%
cbrt-div94.3%
*-commutative94.3%
associate-*r*94.3%
metadata-eval94.3%
neg-mul-194.3%
Applied egg-rr94.3%
Final simplification94.3%
(FPCore (g h a) :precision binary64 (if (or (<= a -5.2e-11) (not (<= a 1.15e-74))) (+ (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ g (- a)))) (+ (/ (cbrt (- g)) (cbrt a)) (cbrt -1.0))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -5.2e-11) || !(a <= 1.15e-74)) {
tmp = cbrt(((g - g) * (-0.5 / a))) + cbrt((g / -a));
} else {
tmp = (cbrt(-g) / cbrt(a)) + cbrt(-1.0);
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -5.2e-11) || !(a <= 1.15e-74)) {
tmp = Math.cbrt(((g - g) * (-0.5 / a))) + Math.cbrt((g / -a));
} else {
tmp = (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(-1.0);
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -5.2e-11) || !(a <= 1.15e-74)) tmp = Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) + cbrt(Float64(g / Float64(-a)))); else tmp = Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(-1.0)); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -5.2e-11], N[Not[LessEqual[a, 1.15e-74]], $MachinePrecision]], N[(N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.2 \cdot 10^{-11} \lor \neg \left(a \leq 1.15 \cdot 10^{-74}\right):\\
\;\;\;\;\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{g}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{-1}\\
\end{array}
\end{array}
if a < -5.2000000000000001e-11 or 1.1499999999999999e-74 < a Initial program 45.1%
Simplified45.1%
Taylor expanded in g around -inf 29.8%
*-commutative29.8%
Simplified29.8%
Taylor expanded in g around -inf 87.8%
neg-mul-187.8%
Simplified87.8%
*-un-lft-identity87.8%
associate-*l/87.9%
*-commutative87.9%
associate-*r*87.9%
metadata-eval87.9%
neg-mul-187.9%
Applied egg-rr87.9%
*-lft-identity87.9%
Simplified87.9%
if -5.2000000000000001e-11 < a < 1.1499999999999999e-74Initial program 44.4%
Simplified44.4%
Taylor expanded in g around -inf 22.5%
*-commutative22.5%
Simplified22.5%
Taylor expanded in g around inf 12.7%
add-sqr-sqrt7.0%
sqrt-unprod4.4%
*-commutative4.4%
*-commutative4.4%
swap-sqr5.1%
*-commutative5.1%
*-commutative5.1%
swap-sqr5.1%
metadata-eval5.1%
metadata-eval5.1%
swap-sqr5.1%
count-25.1%
count-25.1%
frac-times5.2%
metadata-eval5.2%
metadata-eval5.2%
frac-times5.1%
swap-sqr4.4%
sqrt-unprod7.0%
add-sqr-sqrt12.7%
expm1-log1p-u7.1%
Applied egg-rr0.0%
Simplified53.0%
add-sqr-sqrt27.7%
sqrt-unprod9.8%
swap-sqr7.4%
count-27.4%
count-27.4%
swap-sqr7.4%
metadata-eval7.4%
metadata-eval7.4%
swap-sqr7.4%
*-commutative7.4%
*-commutative7.4%
frac-times7.4%
metadata-eval7.4%
metadata-eval7.4%
frac-times7.4%
swap-sqr9.8%
*-commutative9.8%
*-commutative9.8%
Applied egg-rr90.8%
Final simplification89.1%
(FPCore (g h a) :precision binary64 (+ (* (cbrt (/ 0.5 a)) (cbrt (* g -2.0))) (cbrt 0.0)))
double code(double g, double h, double a) {
return (cbrt((0.5 / a)) * cbrt((g * -2.0))) + cbrt(0.0);
}
public static double code(double g, double h, double a) {
return (Math.cbrt((0.5 / a)) * Math.cbrt((g * -2.0))) + Math.cbrt(0.0);
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(g * -2.0))) + cbrt(0.0)) 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[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{g \cdot -2} + \sqrt[3]{0}
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around inf 15.6%
cbrt-prod18.6%
Applied egg-rr18.6%
Applied egg-rr94.3%
Final simplification94.3%
(FPCore (g h a) :precision binary64 (if (or (<= a -1.25e-43) (not (<= a 1.25e-8))) (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (/ -1.0 (cbrt a))) (+ (cbrt g) (cbrt (* (/ -0.5 a) (+ g g))))))
double code(double g, double h, double a) {
double tmp;
if ((a <= -1.25e-43) || !(a <= 1.25e-8)) {
tmp = cbrt(((0.5 / a) * (g * -2.0))) + (-1.0 / cbrt(a));
} else {
tmp = cbrt(g) + cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((a <= -1.25e-43) || !(a <= 1.25e-8)) {
tmp = Math.cbrt(((0.5 / a) * (g * -2.0))) + (-1.0 / Math.cbrt(a));
} else {
tmp = Math.cbrt(g) + Math.cbrt(((-0.5 / a) * (g + g)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if ((a <= -1.25e-43) || !(a <= 1.25e-8)) tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + Float64(-1.0 / cbrt(a))); else tmp = Float64(cbrt(g) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))); end return tmp end
code[g_, h_, a_] := If[Or[LessEqual[a, -1.25e-43], N[Not[LessEqual[a, 1.25e-8]], $MachinePrecision]], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[g, 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.25 \cdot 10^{-43} \lor \neg \left(a \leq 1.25 \cdot 10^{-8}\right):\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \frac{-1}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{g} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}\\
\end{array}
\end{array}
if a < -1.25000000000000005e-43 or 1.2499999999999999e-8 < a Initial program 40.9%
Simplified40.9%
Taylor expanded in g around -inf 25.5%
*-commutative25.5%
Simplified25.5%
Taylor expanded in g around inf 17.5%
*-un-lft-identity44.9%
*-commutative44.9%
Applied egg-rr0.0%
Simplified74.6%
if -1.25000000000000005e-43 < a < 1.2499999999999999e-8Initial program 49.4%
Simplified49.4%
Taylor expanded in g around -inf 28.1%
*-commutative28.1%
Simplified28.1%
Taylor expanded in g around inf 13.3%
Taylor expanded in a around 0 13.3%
Simplified59.0%
Final simplification67.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (- g g) (/ -0.5 a))) (cbrt (/ g (- a)))))
double code(double g, double h, double a) {
return cbrt(((g - g) * (-0.5 / a))) + cbrt((g / -a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - g) * (-0.5 / a))) + Math.cbrt((g / -a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - g) * Float64(-0.5 / a))) + cbrt(Float64(g / Float64(-a)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - g), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(g / (-a)), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(g - g\right) \cdot \frac{-0.5}{a}} + \sqrt[3]{\frac{g}{-a}}
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around -inf 75.0%
neg-mul-175.0%
Simplified75.0%
*-un-lft-identity75.0%
associate-*l/75.1%
*-commutative75.1%
associate-*r*75.1%
metadata-eval75.1%
neg-mul-175.1%
Applied egg-rr75.1%
*-lft-identity75.1%
Simplified75.1%
Final simplification75.1%
(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 / Float64(-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}} + \sqrt[3]{-1}
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt8.2%
sqrt-unprod12.7%
*-commutative12.7%
*-commutative12.7%
swap-sqr14.8%
*-commutative14.8%
*-commutative14.8%
swap-sqr14.8%
metadata-eval14.8%
metadata-eval14.8%
swap-sqr14.8%
count-214.8%
count-214.8%
frac-times15.8%
metadata-eval15.8%
metadata-eval15.8%
frac-times14.8%
swap-sqr12.7%
sqrt-unprod8.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.6%
Applied egg-rr0.0%
Simplified48.8%
Taylor expanded in g around 0 48.9%
associate-*r/48.9%
neg-mul-148.9%
Simplified48.9%
Final simplification48.9%
(FPCore (g h a) :precision binary64 (+ (cbrt -1.0) (/ -1.0 (cbrt a))))
double code(double g, double h, double a) {
return cbrt(-1.0) + (-1.0 / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-1.0) + (-1.0 / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(-1.0) + Float64(-1.0 / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[-1.0, 1/3], $MachinePrecision] + N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-1} + \frac{-1}{\sqrt[3]{a}}
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt8.2%
sqrt-unprod12.7%
*-commutative12.7%
*-commutative12.7%
swap-sqr14.8%
*-commutative14.8%
*-commutative14.8%
swap-sqr14.8%
metadata-eval14.8%
metadata-eval14.8%
swap-sqr14.8%
count-214.8%
count-214.8%
frac-times15.8%
metadata-eval15.8%
metadata-eval15.8%
frac-times14.8%
swap-sqr12.7%
sqrt-unprod8.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.6%
Applied egg-rr0.0%
Simplified48.8%
*-un-lft-identity48.8%
*-commutative48.8%
Applied egg-rr0.0%
Simplified4.9%
Final simplification4.9%
(FPCore (g h a) :precision binary64 -1.0)
double code(double g, double h, double a) {
return -1.0;
}
real(8) function code(g, h, a)
real(8), intent (in) :: g
real(8), intent (in) :: h
real(8), intent (in) :: a
code = -1.0d0
end function
public static double code(double g, double h, double a) {
return -1.0;
}
def code(g, h, a): return -1.0
function code(g, h, a) return -1.0 end
function tmp = code(g, h, a) tmp = -1.0; end
code[g_, h_, a_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt8.2%
sqrt-unprod12.7%
*-commutative12.7%
*-commutative12.7%
swap-sqr14.8%
*-commutative14.8%
*-commutative14.8%
swap-sqr14.8%
metadata-eval14.8%
metadata-eval14.8%
swap-sqr14.8%
count-214.8%
count-214.8%
frac-times15.8%
metadata-eval15.8%
metadata-eval15.8%
frac-times14.8%
swap-sqr12.7%
sqrt-unprod8.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.6%
Applied egg-rr0.0%
Simplified48.8%
Applied egg-rr4.4%
Final simplification4.4%
(FPCore (g h a) :precision binary64 1.0)
double code(double g, double h, double a) {
return 1.0;
}
real(8) function code(g, h, a)
real(8), intent (in) :: g
real(8), intent (in) :: h
real(8), intent (in) :: a
code = 1.0d0
end function
public static double code(double g, double h, double a) {
return 1.0;
}
def code(g, h, a): return 1.0
function code(g, h, a) return 1.0 end
function tmp = code(g, h, a) tmp = 1.0; end
code[g_, h_, a_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 44.8%
Simplified44.8%
Taylor expanded in g around -inf 26.7%
*-commutative26.7%
Simplified26.7%
Taylor expanded in g around inf 15.6%
add-sqr-sqrt8.2%
sqrt-unprod12.7%
*-commutative12.7%
*-commutative12.7%
swap-sqr14.8%
*-commutative14.8%
*-commutative14.8%
swap-sqr14.8%
metadata-eval14.8%
metadata-eval14.8%
swap-sqr14.8%
count-214.8%
count-214.8%
frac-times15.8%
metadata-eval15.8%
metadata-eval15.8%
frac-times14.8%
swap-sqr12.7%
sqrt-unprod8.2%
add-sqr-sqrt15.6%
expm1-log1p-u10.6%
Applied egg-rr0.0%
Simplified48.8%
Applied egg-rr4.5%
Final simplification4.5%
herbie shell --seed 2024046
(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))))))))