
(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 (fma (/ (cbrt (* g -0.5)) (cbrt a)) (pow 2.0 0.3333333333333333) (* (cbrt (* (/ h g) (/ h a))) (* (cbrt 0.5) (cbrt -0.5)))))
double code(double g, double h, double a) {
return fma((cbrt((g * -0.5)) / cbrt(a)), pow(2.0, 0.3333333333333333), (cbrt(((h / g) * (h / a))) * (cbrt(0.5) * cbrt(-0.5))));
}
function code(g, h, a) return fma(Float64(cbrt(Float64(g * -0.5)) / cbrt(a)), (2.0 ^ 0.3333333333333333), Float64(cbrt(Float64(Float64(h / g) * Float64(h / a))) * Float64(cbrt(0.5) * cbrt(-0.5)))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(g * -0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[2.0, 0.3333333333333333], $MachinePrecision] + N[(N[Power[N[(N[(h / g), $MachinePrecision] * N[(h / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[0.5, 1/3], $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\sqrt[3]{g \cdot -0.5}}{\sqrt[3]{a}}, {2}^{0.3333333333333333}, \sqrt[3]{\frac{h}{g} \cdot \frac{h}{a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)
\end{array}
Initial program 43.7%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.9
Applied rewrites71.9%
Applied rewrites89.7%
Applied rewrites90.4%
Applied rewrites90.6%
(FPCore (g h a) :precision binary64 (fma (/ (cbrt (* g -0.5)) (cbrt a)) (cbrt 2.0) (* (cbrt (* (/ h g) (/ h a))) (* (cbrt 0.5) (cbrt -0.5)))))
double code(double g, double h, double a) {
return fma((cbrt((g * -0.5)) / cbrt(a)), cbrt(2.0), (cbrt(((h / g) * (h / a))) * (cbrt(0.5) * cbrt(-0.5))));
}
function code(g, h, a) return fma(Float64(cbrt(Float64(g * -0.5)) / cbrt(a)), cbrt(2.0), Float64(cbrt(Float64(Float64(h / g) * Float64(h / a))) * Float64(cbrt(0.5) * cbrt(-0.5)))) end
code[g_, h_, a_] := N[(N[(N[Power[N[(g * -0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision] + N[(N[Power[N[(N[(h / g), $MachinePrecision] * N[(h / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[0.5, 1/3], $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\sqrt[3]{g \cdot -0.5}}{\sqrt[3]{a}}, \sqrt[3]{2}, \sqrt[3]{\frac{h}{g} \cdot \frac{h}{a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)
\end{array}
Initial program 43.7%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.9
Applied rewrites71.9%
Applied rewrites89.7%
Applied rewrites89.9%
(FPCore (g h a)
:precision binary64
(if (<= g 9.5e-198)
(fma (cbrt (/ g a)) (cbrt -1.0) (* (cbrt (* (/ h a) (/ h g))) (cbrt -0.25)))
(if (<= g 1.65e+148)
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) (sqrt (- (* g g) (* h h))))))
(/ (- (cbrt (* g 2.0))) (cbrt (* a 2.0))))
(fma
(cbrt (* (/ g a) -0.5))
(pow 2.0 0.3333333333333333)
(* (cbrt (* (/ h g) (/ h a))) (* (cbrt 0.5) (cbrt -0.5)))))))
double code(double g, double h, double a) {
double tmp;
if (g <= 9.5e-198) {
tmp = fma(cbrt((g / a)), cbrt(-1.0), (cbrt(((h / a) * (h / g))) * cbrt(-0.25)));
} else if (g <= 1.65e+148) {
tmp = cbrt((pow((2.0 * a), -1.0) * (-g + sqrt(((g * g) - (h * h)))))) + (-cbrt((g * 2.0)) / cbrt((a * 2.0)));
} else {
tmp = fma(cbrt(((g / a) * -0.5)), pow(2.0, 0.3333333333333333), (cbrt(((h / g) * (h / a))) * (cbrt(0.5) * cbrt(-0.5))));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= 9.5e-198) tmp = fma(cbrt(Float64(g / a)), cbrt(-1.0), Float64(cbrt(Float64(Float64(h / a) * Float64(h / g))) * cbrt(-0.25))); elseif (g <= 1.65e+148) tmp = Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + Float64(Float64(-cbrt(Float64(g * 2.0))) / cbrt(Float64(a * 2.0)))); else tmp = fma(cbrt(Float64(Float64(g / a) * -0.5)), (2.0 ^ 0.3333333333333333), Float64(cbrt(Float64(Float64(h / g) * Float64(h / a))) * Float64(cbrt(0.5) * cbrt(-0.5)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, 9.5e-198], N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision] + N[(N[Power[N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.25, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 1.65e+148], N[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[((-N[Power[N[(g * 2.0), $MachinePrecision], 1/3], $MachinePrecision]) / N[Power[N[(a * 2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(g / a), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[2.0, 0.3333333333333333], $MachinePrecision] + N[(N[Power[N[(N[(h / g), $MachinePrecision] * N[(h / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[0.5, 1/3], $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq 9.5 \cdot 10^{-198}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-1}, \sqrt[3]{\frac{h}{a} \cdot \frac{h}{g}} \cdot \sqrt[3]{-0.25}\right)\\
\mathbf{elif}\;g \leq 1.65 \cdot 10^{+148}:\\
\;\;\;\;\sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \frac{-\sqrt[3]{g \cdot 2}}{\sqrt[3]{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{g}{a} \cdot -0.5}, {2}^{0.3333333333333333}, \sqrt[3]{\frac{h}{g} \cdot \frac{h}{a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)\\
\end{array}
\end{array}
if g < 9.4999999999999997e-198Initial program 41.9%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.3
Applied rewrites71.3%
Applied rewrites72.0%
if 9.4999999999999997e-198 < g < 1.65000000000000005e148Initial program 82.6%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites95.7%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
lower-cbrt.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
if 1.65000000000000005e148 < g Initial program 3.8%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6462.2
Applied rewrites62.2%
Applied rewrites86.9%
Applied rewrites87.6%
Applied rewrites62.7%
Final simplification76.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (/ g a))))
(if (<= g 9.5e-198)
(fma t_0 (cbrt -1.0) (* (cbrt (* (/ h a) (/ h g))) (cbrt -0.25)))
(if (<= g 1.65e+148)
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) (sqrt (- (* g g) (* h h))))))
(/ (- (cbrt (* g 2.0))) (cbrt (* a 2.0))))
(* t_0 (cbrt -1.0))))))
double code(double g, double h, double a) {
double t_0 = cbrt((g / a));
double tmp;
if (g <= 9.5e-198) {
tmp = fma(t_0, cbrt(-1.0), (cbrt(((h / a) * (h / g))) * cbrt(-0.25)));
} else if (g <= 1.65e+148) {
tmp = cbrt((pow((2.0 * a), -1.0) * (-g + sqrt(((g * g) - (h * h)))))) + (-cbrt((g * 2.0)) / cbrt((a * 2.0)));
} else {
tmp = t_0 * cbrt(-1.0);
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(g / a)) tmp = 0.0 if (g <= 9.5e-198) tmp = fma(t_0, cbrt(-1.0), Float64(cbrt(Float64(Float64(h / a) * Float64(h / g))) * cbrt(-0.25))); elseif (g <= 1.65e+148) tmp = Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + Float64(Float64(-cbrt(Float64(g * 2.0))) / cbrt(Float64(a * 2.0)))); else tmp = Float64(t_0 * cbrt(-1.0)); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[g, 9.5e-198], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision] + N[(N[Power[N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.25, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 1.65e+148], N[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[((-N[Power[N[(g * 2.0), $MachinePrecision], 1/3], $MachinePrecision]) / N[Power[N[(a * 2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{a}}\\
\mathbf{if}\;g \leq 9.5 \cdot 10^{-198}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \sqrt[3]{-1}, \sqrt[3]{\frac{h}{a} \cdot \frac{h}{g}} \cdot \sqrt[3]{-0.25}\right)\\
\mathbf{elif}\;g \leq 1.65 \cdot 10^{+148}:\\
\;\;\;\;\sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \frac{-\sqrt[3]{g \cdot 2}}{\sqrt[3]{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt[3]{-1}\\
\end{array}
\end{array}
if g < 9.4999999999999997e-198Initial program 41.9%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.3
Applied rewrites71.3%
Applied rewrites72.0%
if 9.4999999999999997e-198 < g < 1.65000000000000005e148Initial program 82.6%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites95.7%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
lower-cbrt.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
if 1.65000000000000005e148 < g Initial program 3.8%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites3.8%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6462.6
Applied rewrites62.6%
Final simplification76.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (/ g a))))
(if (<= g 9.5e-198)
(fma t_0 (cbrt -1.0) (cbrt (* -0.25 (* (/ h a) (/ h g)))))
(if (<= g 1.65e+148)
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) (sqrt (- (* g g) (* h h))))))
(/ (- (cbrt (* g 2.0))) (cbrt (* a 2.0))))
(* t_0 (cbrt -1.0))))))
double code(double g, double h, double a) {
double t_0 = cbrt((g / a));
double tmp;
if (g <= 9.5e-198) {
tmp = fma(t_0, cbrt(-1.0), cbrt((-0.25 * ((h / a) * (h / g)))));
} else if (g <= 1.65e+148) {
tmp = cbrt((pow((2.0 * a), -1.0) * (-g + sqrt(((g * g) - (h * h)))))) + (-cbrt((g * 2.0)) / cbrt((a * 2.0)));
} else {
tmp = t_0 * cbrt(-1.0);
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(g / a)) tmp = 0.0 if (g <= 9.5e-198) tmp = fma(t_0, cbrt(-1.0), cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))); elseif (g <= 1.65e+148) tmp = Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + Float64(Float64(-cbrt(Float64(g * 2.0))) / cbrt(Float64(a * 2.0)))); else tmp = Float64(t_0 * cbrt(-1.0)); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[g, 9.5e-198], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 1.65e+148], N[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[((-N[Power[N[(g * 2.0), $MachinePrecision], 1/3], $MachinePrecision]) / N[Power[N[(a * 2.0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{a}}\\
\mathbf{if}\;g \leq 9.5 \cdot 10^{-198}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \sqrt[3]{-1}, \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\right)\\
\mathbf{elif}\;g \leq 1.65 \cdot 10^{+148}:\\
\;\;\;\;\sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \frac{-\sqrt[3]{g \cdot 2}}{\sqrt[3]{a \cdot 2}}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt[3]{-1}\\
\end{array}
\end{array}
if g < 9.4999999999999997e-198Initial program 41.9%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.3
Applied rewrites71.3%
Applied rewrites72.0%
if 9.4999999999999997e-198 < g < 1.65000000000000005e148Initial program 82.6%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites95.7%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
lower-cbrt.f64N/A
lower-*.f6498.1
Applied rewrites98.1%
if 1.65000000000000005e148 < g Initial program 3.8%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites3.8%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6462.6
Applied rewrites62.6%
Final simplification76.2%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (cbrt (/ g a))))
(if (<= g 9.5e-198)
(fma t_0 (cbrt -1.0) (cbrt (* -0.25 (* (/ h a) (/ h g)))))
(if (<= g 3.4e+145)
(+
(cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) (sqrt (- (* g g) (* h h))))))
(* (cbrt (/ 0.5 a)) (- (cbrt (* g 2.0)))))
(* t_0 (cbrt -1.0))))))
double code(double g, double h, double a) {
double t_0 = cbrt((g / a));
double tmp;
if (g <= 9.5e-198) {
tmp = fma(t_0, cbrt(-1.0), cbrt((-0.25 * ((h / a) * (h / g)))));
} else if (g <= 3.4e+145) {
tmp = cbrt((pow((2.0 * a), -1.0) * (-g + sqrt(((g * g) - (h * h)))))) + (cbrt((0.5 / a)) * -cbrt((g * 2.0)));
} else {
tmp = t_0 * cbrt(-1.0);
}
return tmp;
}
function code(g, h, a) t_0 = cbrt(Float64(g / a)) tmp = 0.0 if (g <= 9.5e-198) tmp = fma(t_0, cbrt(-1.0), cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))); elseif (g <= 3.4e+145) tmp = Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + sqrt(Float64(Float64(g * g) - Float64(h * h)))))) + Float64(cbrt(Float64(0.5 / a)) * Float64(-cbrt(Float64(g * 2.0))))); else tmp = Float64(t_0 * cbrt(-1.0)); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[g, 9.5e-198], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[g, 3.4e+145], N[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * (-N[Power[N[(g * 2.0), $MachinePrecision], 1/3], $MachinePrecision])), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{g}{a}}\\
\mathbf{if}\;g \leq 9.5 \cdot 10^{-198}:\\
\;\;\;\;\mathsf{fma}\left(t\_0, \sqrt[3]{-1}, \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\right)\\
\mathbf{elif}\;g \leq 3.4 \cdot 10^{+145}:\\
\;\;\;\;\sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + \sqrt{g \cdot g - h \cdot h}\right)} + \sqrt[3]{\frac{0.5}{a}} \cdot \left(-\sqrt[3]{g \cdot 2}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot \sqrt[3]{-1}\\
\end{array}
\end{array}
if g < 9.4999999999999997e-198Initial program 41.9%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.3
Applied rewrites71.3%
Applied rewrites72.0%
if 9.4999999999999997e-198 < g < 3.3999999999999999e145Initial program 82.0%
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
lower-*.f64N/A
pow1/3N/A
lower-cbrt.f64N/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f64N/A
lower-cbrt.f6495.4
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
Applied rewrites95.4%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
lower-cbrt.f64N/A
lower-*.f6497.9
Applied rewrites97.9%
if 3.3999999999999999e145 < g Initial program 7.3%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites7.3%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6464.0
Applied rewrites64.0%
Final simplification76.2%
(FPCore (g h a) :precision binary64 (fma (cbrt (/ g a)) (cbrt -1.0) (cbrt (* -0.25 (* (/ h a) (/ h g))))))
double code(double g, double h, double a) {
return fma(cbrt((g / a)), cbrt(-1.0), cbrt((-0.25 * ((h / a) * (h / g)))));
}
function code(g, h, a) return fma(cbrt(Float64(g / a)), cbrt(-1.0), cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))) end
code[g_, h_, a_] := N[(N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt[3]{\frac{g}{a}}, \sqrt[3]{-1}, \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\right)
\end{array}
Initial program 43.7%
Taylor expanded in h around 0
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
unpow2N/A
*-commutativeN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6471.9
Applied rewrites71.9%
Applied rewrites72.6%
(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 / 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}} \cdot \sqrt[3]{-1}
\end{array}
Initial program 43.7%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites46.9%
Taylor expanded in g around inf
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-cbrt.f6471.5
Applied rewrites71.5%
(FPCore (g h a) :precision binary64 (- (cbrt (* (/ (* (sqrt -1.0) h) a) -0.5))))
double code(double g, double h, double a) {
return -cbrt((((sqrt(-1.0) * h) / a) * -0.5));
}
public static double code(double g, double h, double a) {
return -Math.cbrt((((Math.sqrt(-1.0) * h) / a) * -0.5));
}
function code(g, h, a) return Float64(-cbrt(Float64(Float64(Float64(sqrt(-1.0) * h) / a) * -0.5))) end
code[g_, h_, a_] := (-N[Power[N[(N[(N[(N[Sqrt[-1.0], $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision])
\begin{array}{l}
\\
-\sqrt[3]{\frac{\sqrt{-1} \cdot h}{a} \cdot -0.5}
\end{array}
Initial program 43.7%
lift-cbrt.f64N/A
pow1/3N/A
sqr-powN/A
fabs-sqrN/A
sqr-powN/A
pow1/3N/A
lift-cbrt.f64N/A
lower-fabs.f6434.8
lift-*.f64N/A
*-commutativeN/A
Applied rewrites10.6%
Taylor expanded in h around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-/.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-cbrt.f640.0
Applied rewrites0.0%
Applied rewrites0.0%
herbie shell --seed 2024346
(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))))))))