
(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 5 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) (* -0.5 (* h (/ h g))))) (/ (cbrt (* -0.5 (+ g g))) (cbrt a))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (-0.5 * (h * (h / g))))) + (cbrt((-0.5 * (g + g))) / cbrt(a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (-0.5 * (h * (h / g))))) + (Math.cbrt((-0.5 * (g + g))) / Math.cbrt(a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(-0.5 * Float64(h * Float64(h / g))))) + Float64(cbrt(Float64(-0.5 * Float64(g + g))) / cbrt(a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(-0.5 * N[(h * N[(h / g), $MachinePrecision]), $MachinePrecision]), $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]{\frac{0.5}{a} \cdot \left(-0.5 \cdot \left(h \cdot \frac{h}{g}\right)\right)} + \frac{\sqrt[3]{-0.5 \cdot \left(g + g\right)}}{\sqrt[3]{a}}
\end{array}
Initial program 37.8%
Simplified37.8%
associate-*r/37.8%
cbrt-div42.8%
pow242.8%
pow242.8%
Applied egg-rr42.8%
Taylor expanded in g around inf 25.8%
Taylor expanded in g around inf 91.7%
unpow291.7%
*-un-lft-identity91.7%
times-frac95.6%
Applied egg-rr95.6%
Final simplification95.6%
(FPCore (g h a) :precision binary64 (if (<= g 7.3e-240) (+ -1.0 (cbrt (* (/ 0.5 a) (- (fabs g) g)))) (+ (cbrt (* (/ 0.5 a) (- g g))) (/ -1.0 (cbrt a)))))
double code(double g, double h, double a) {
double tmp;
if (g <= 7.3e-240) {
tmp = -1.0 + cbrt(((0.5 / a) * (fabs(g) - g)));
} else {
tmp = cbrt(((0.5 / a) * (g - g))) + (-1.0 / cbrt(a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if (g <= 7.3e-240) {
tmp = -1.0 + Math.cbrt(((0.5 / a) * (Math.abs(g) - g)));
} else {
tmp = Math.cbrt(((0.5 / a) * (g - g))) + (-1.0 / Math.cbrt(a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= 7.3e-240) tmp = Float64(-1.0 + cbrt(Float64(Float64(0.5 / a) * Float64(abs(g) - g)))); else tmp = Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + Float64(-1.0 / cbrt(a))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, 7.3e-240], N[(-1.0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[Abs[g], $MachinePrecision] - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(-1.0 / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq 7.3 \cdot 10^{-240}:\\
\;\;\;\;-1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left|g\right| - g\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \frac{-1}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if g < 7.30000000000000004e-240Initial program 38.8%
Simplified38.8%
Taylor expanded in g around inf 2.6%
Taylor expanded in g around inf 66.1%
cbrt-prod93.0%
Applied egg-rr0.0%
Simplified4.7%
add-sqr-sqrt0.1%
sqrt-prod21.8%
rem-sqrt-square40.9%
Applied egg-rr40.9%
if 7.30000000000000004e-240 < g Initial program 36.8%
Simplified36.8%
Taylor expanded in g around inf 38.3%
Taylor expanded in g around inf 69.0%
expm1-log1p-u46.3%
expm1-udef27.4%
Applied egg-rr0.0%
Simplified7.5%
Final simplification24.6%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 37.8%
Simplified37.8%
Taylor expanded in g around inf 20.0%
Taylor expanded in g around inf 67.5%
Taylor expanded in g around 0 67.6%
Final simplification67.6%
(FPCore (g h a) :precision binary64 (+ -1.0 (cbrt (* (/ 0.5 a) (- (fabs g) g)))))
double code(double g, double h, double a) {
return -1.0 + cbrt(((0.5 / a) * (fabs(g) - g)));
}
public static double code(double g, double h, double a) {
return -1.0 + Math.cbrt(((0.5 / a) * (Math.abs(g) - g)));
}
function code(g, h, a) return Float64(-1.0 + cbrt(Float64(Float64(0.5 / a) * Float64(abs(g) - g)))) end
code[g_, h_, a_] := N[(-1.0 + N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(N[Abs[g], $MachinePrecision] - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-1 + \sqrt[3]{\frac{0.5}{a} \cdot \left(\left|g\right| - g\right)}
\end{array}
Initial program 37.8%
Simplified37.8%
Taylor expanded in g around inf 20.0%
Taylor expanded in g around inf 67.5%
cbrt-prod95.0%
Applied egg-rr0.0%
Simplified4.4%
add-sqr-sqrt2.2%
sqrt-prod12.2%
rem-sqrt-square22.9%
Applied egg-rr22.9%
Final simplification22.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (/ 0.5 a) (- g g))) -1.0))
double code(double g, double h, double a) {
return cbrt(((0.5 / a) * (g - g))) + -1.0;
}
public static double code(double g, double h, double a) {
return Math.cbrt(((0.5 / a) * (g - g))) + -1.0;
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(0.5 / a) * Float64(g - g))) + -1.0) end
code[g_, h_, a_] := N[(N[Power[N[(N[(0.5 / a), $MachinePrecision] * N[(g - g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + -1.0), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.5}{a} \cdot \left(g - g\right)} + -1
\end{array}
Initial program 37.8%
Simplified37.8%
Taylor expanded in g around inf 20.0%
Taylor expanded in g around inf 67.5%
cbrt-prod95.0%
Applied egg-rr0.0%
Simplified4.4%
Final simplification4.4%
herbie shell --seed 2024075
(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))))))))