
(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 8 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 (- (hypot g h) g))) (* (cbrt (/ -0.5 a)) (cbrt (+ g (hypot g h))))))
double code(double g, double h, double a) {
return (cbrt((0.5 / a)) * cbrt((hypot(g, h) - g))) + (cbrt((-0.5 / a)) * cbrt((g + hypot(g, h))));
}
public static double code(double g, double h, double a) {
return (Math.cbrt((0.5 / a)) * Math.cbrt((Math.hypot(g, h) - g))) + (Math.cbrt((-0.5 / a)) * Math.cbrt((g + Math.hypot(g, h))));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(0.5 / a)) * cbrt(Float64(hypot(g, h) - g))) + Float64(cbrt(Float64(-0.5 / a)) * cbrt(Float64(g + hypot(g, h))))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(N[Sqrt[g ^ 2 + h ^ 2], $MachinePrecision] - g), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(-0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(g + N[Sqrt[g ^ 2 + h ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a}} \cdot \sqrt[3]{\mathsf{hypot}\left(g, h\right) - g} + \sqrt[3]{\frac{-0.5}{a}} \cdot \sqrt[3]{g + \mathsf{hypot}\left(g, h\right)}
\end{array}
Initial program 49.8%
associate-/r*49.8%
metadata-eval49.8%
+-commutative49.8%
unsub-neg49.8%
fma-neg49.8%
sub-neg49.8%
distribute-neg-out49.8%
neg-mul-149.8%
associate-*r*49.8%
Simplified49.8%
expm1-log1p-u43.3%
expm1-udef33.0%
Applied egg-rr27.7%
expm1-def27.2%
expm1-log1p27.3%
Simplified27.3%
div-inv27.3%
clear-num27.3%
cbrt-prod30.0%
Applied egg-rr51.8%
*-commutative51.8%
Simplified51.8%
add-sqr-sqrt51.5%
sqrt-unprod69.7%
cbrt-unprod61.6%
swap-sqr39.6%
frac-times39.6%
metadata-eval39.6%
metadata-eval39.6%
frac-times39.6%
swap-sqr61.6%
expm1-log1p-u61.2%
expm1-log1p-u61.1%
cbrt-unprod69.0%
Applied egg-rr96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (+ (* (cbrt 0.5) (/ (cbrt (* g -2.0)) (cbrt a))) (cbrt (/ (- g g) (/ a -0.5)))))
double code(double g, double h, double a) {
return (cbrt(0.5) * (cbrt((g * -2.0)) / cbrt(a))) + cbrt(((g - g) / (a / -0.5)));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(0.5) * (Math.cbrt((g * -2.0)) / Math.cbrt(a))) + Math.cbrt(((g - g) / (a / -0.5)));
}
function code(g, h, a) return Float64(Float64(cbrt(0.5) * Float64(cbrt(Float64(g * -2.0)) / cbrt(a))) + cbrt(Float64(Float64(g - g) / Float64(a / -0.5)))) end
code[g_, h_, a_] := N[(N[(N[Power[0.5, 1/3], $MachinePrecision] * N[(N[Power[N[(g * -2.0), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(g - g), $MachinePrecision] / N[(a / -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{0.5} \cdot \frac{\sqrt[3]{g \cdot -2}}{\sqrt[3]{a}} + \sqrt[3]{\frac{g - g}{\frac{a}{-0.5}}}
\end{array}
Initial program 49.8%
associate-/r*49.8%
metadata-eval49.8%
+-commutative49.8%
unsub-neg49.8%
fma-neg49.8%
sub-neg49.8%
distribute-neg-out49.8%
neg-mul-149.8%
associate-*r*49.8%
Simplified49.8%
associate-*l/49.8%
cbrt-div54.4%
Applied egg-rr54.8%
Taylor expanded in g around -inf 37.5%
*-commutative37.5%
Simplified37.5%
Taylor expanded in g around -inf 96.4%
neg-mul-196.4%
Simplified96.4%
cbrt-prod96.4%
*-un-lft-identity96.4%
times-frac96.4%
Applied egg-rr96.4%
/-rgt-identity96.4%
Simplified96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g g) (/ a -0.5))) (/ (cbrt (- g)) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(((g - g) / (a / -0.5))) + (cbrt(-g) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - g) / (a / -0.5))) + (Math.cbrt(-g) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - g) / Float64(a / -0.5))) + Float64(cbrt(Float64(-g)) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - g), $MachinePrecision] / N[(a / -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g - g}{\frac{a}{-0.5}}} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}
\end{array}
Initial program 49.8%
associate-/r*49.8%
metadata-eval49.8%
+-commutative49.8%
unsub-neg49.8%
fma-neg49.8%
sub-neg49.8%
distribute-neg-out49.8%
neg-mul-149.8%
associate-*r*49.8%
Simplified49.8%
associate-*l/49.8%
cbrt-div54.4%
Applied egg-rr54.8%
Taylor expanded in g around -inf 37.5%
*-commutative37.5%
Simplified37.5%
Taylor expanded in g around -inf 96.4%
neg-mul-196.4%
Simplified96.4%
expm1-log1p-u60.4%
expm1-udef38.8%
Applied egg-rr38.8%
expm1-def60.4%
expm1-log1p96.4%
*-commutative96.4%
associate-*l*96.4%
metadata-eval96.4%
*-commutative96.4%
neg-mul-196.4%
Simplified96.4%
Final simplification96.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (* g -2.0))) (cbrt (/ (* 0.5 (/ h (/ g h))) (/ a -0.5)))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g * -2.0))) + cbrt(((0.5 * (h / (g / h))) / (a / -0.5)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g * -2.0))) + Math.cbrt(((0.5 * (h / (g / h))) / (a / -0.5)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g * -2.0))) + cbrt(Float64(Float64(0.5 * Float64(h / Float64(g / h))) / Float64(a / -0.5)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g * -2.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.5 * N[(h / N[(g / h), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a / -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g \cdot -2\right)} + \sqrt[3]{\frac{0.5 \cdot \frac{h}{\frac{g}{h}}}{\frac{a}{-0.5}}}
\end{array}
Initial program 49.8%
associate-/r*49.8%
metadata-eval49.8%
+-commutative49.8%
unsub-neg49.8%
fma-neg49.8%
sub-neg49.8%
distribute-neg-out49.8%
neg-mul-149.8%
associate-*r*49.8%
Simplified49.8%
Taylor expanded in g around -inf 30.1%
*-commutative30.1%
Simplified30.1%
Taylor expanded in g around -inf 72.9%
unpow272.9%
associate-/l*77.0%
Simplified77.0%
Final simplification77.0%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g g) (/ a -0.5))) (/ 1.0 (cbrt (/ a (- g))))))
double code(double g, double h, double a) {
return cbrt(((g - g) / (a / -0.5))) + (1.0 / cbrt((a / -g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((g - g) / (a / -0.5))) + (1.0 / Math.cbrt((a / -g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(g - g) / Float64(a / -0.5))) + Float64(1.0 / cbrt(Float64(a / Float64(-g))))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(g - g), $MachinePrecision] / N[(a / -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(1.0 / N[Power[N[(a / (-g)), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{g - g}{\frac{a}{-0.5}}} + \frac{1}{\sqrt[3]{\frac{a}{-g}}}
\end{array}
Initial program 49.8%
associate-/r*49.8%
metadata-eval49.8%
+-commutative49.8%
unsub-neg49.8%
fma-neg49.8%
sub-neg49.8%
distribute-neg-out49.8%
neg-mul-149.8%
associate-*r*49.8%
Simplified49.8%
associate-*l/49.8%
cbrt-div54.4%
Applied egg-rr54.8%
Taylor expanded in g around -inf 37.5%
*-commutative37.5%
Simplified37.5%
Taylor expanded in g around -inf 96.4%
neg-mul-196.4%
Simplified96.4%
clear-num96.3%
inv-pow96.3%
cbrt-undiv76.5%
Applied egg-rr76.5%
unpow-176.5%
*-commutative76.5%
associate-*l*76.5%
metadata-eval76.5%
*-commutative76.5%
neg-mul-176.5%
Simplified76.5%
Final simplification76.5%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ -0.5 a) 0.0)) (cbrt (* (/ -0.5 a) (+ g g)))))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * 0.0)) + cbrt(((-0.5 / a) * (g + g)));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * 0.0)) + Math.cbrt(((-0.5 / a) * (g + g)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-0.5 / a) * 0.0)) + cbrt(Float64(Float64(-0.5 / a) * Float64(g + g)))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * 0.0), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-0.5 / a), $MachinePrecision] * N[(g + g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-0.5}{a} \cdot 0} + \sqrt[3]{\frac{-0.5}{a} \cdot \left(g + g\right)}
\end{array}
Initial program 49.8%
Simplified49.8%
Taylor expanded in g around inf 28.4%
distribute-rgt1-in28.4%
metadata-eval28.4%
mul0-lft28.4%
metadata-eval28.4%
Simplified28.4%
Taylor expanded in g around inf 75.3%
Final simplification75.3%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ -0.5 a) 0.0)) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * 0.0)) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * 0.0)) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-0.5 / a) * 0.0)) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(-0.5 / a), $MachinePrecision] * 0.0), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-0.5}{a} \cdot 0} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 49.8%
Simplified49.8%
Taylor expanded in g around inf 28.4%
distribute-rgt1-in28.4%
metadata-eval28.4%
mul0-lft28.4%
metadata-eval28.4%
Simplified28.4%
Taylor expanded in g around inf 75.3%
associate-*r/75.3%
neg-mul-175.3%
Simplified75.3%
Final simplification75.3%
(FPCore (g h a) :precision binary64 (cbrt (* (/ -0.5 a) 0.0)))
double code(double g, double h, double a) {
return cbrt(((-0.5 / a) * 0.0));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((-0.5 / a) * 0.0));
}
function code(g, h, a) return cbrt(Float64(Float64(-0.5 / a) * 0.0)) end
code[g_, h_, a_] := N[Power[N[(N[(-0.5 / a), $MachinePrecision] * 0.0), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-0.5}{a} \cdot 0}
\end{array}
Initial program 49.8%
Simplified49.8%
Taylor expanded in g around inf 28.4%
distribute-rgt1-in28.4%
metadata-eval28.4%
mul0-lft28.4%
metadata-eval28.4%
Simplified28.4%
Taylor expanded in g around inf 75.3%
add-sqr-sqrt34.8%
sqrt-unprod35.5%
cbrt-unprod17.9%
swap-sqr9.2%
count-29.2%
count-29.2%
swap-sqr9.2%
metadata-eval9.2%
metadata-eval9.2%
swap-sqr9.2%
*-commutative9.2%
*-commutative9.2%
frac-times9.2%
metadata-eval9.2%
metadata-eval9.2%
frac-times9.2%
swap-sqr17.9%
*-commutative17.9%
associate-*l/17.9%
*-commutative17.9%
associate-*l/17.9%
frac-times9.2%
Applied egg-rr3.0%
Final simplification3.0%
herbie shell --seed 2023178
(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))))))))