
(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 (fma (/ (* (cbrt g) (pow 2.0 0.3333333333333333)) (cbrt a)) (cbrt -0.5) (* (/ (cbrt (* (/ h g) h)) (cbrt a)) (* (cbrt 0.5) (cbrt -0.5)))))
double code(double g, double h, double a) {
return fma(((cbrt(g) * pow(2.0, 0.3333333333333333)) / cbrt(a)), cbrt(-0.5), ((cbrt(((h / g) * h)) / cbrt(a)) * (cbrt(0.5) * cbrt(-0.5))));
}
function code(g, h, a) return fma(Float64(Float64(cbrt(g) * (2.0 ^ 0.3333333333333333)) / cbrt(a)), cbrt(-0.5), Float64(Float64(cbrt(Float64(Float64(h / g) * h)) / cbrt(a)) * Float64(cbrt(0.5) * cbrt(-0.5)))) end
code[g_, h_, a_] := N[(N[(N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[2.0, 0.3333333333333333], $MachinePrecision]), $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision] + N[(N[(N[Power[N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $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 {2}^{0.3333333333333333}}{\sqrt[3]{a}}, \sqrt[3]{-0.5}, \frac{\sqrt[3]{\frac{h}{g} \cdot h}}{\sqrt[3]{a}} \cdot \left(\sqrt[3]{0.5} \cdot \sqrt[3]{-0.5}\right)\right)
\end{array}
Initial program 44.8%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites73.1%
Applied rewrites92.5%
Applied rewrites96.3%
Applied rewrites96.9%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (cbrt (* (pow (* 2.0 a) -1.0) (+ (- g) t_0))))
(t_2 (+ t_1 (cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0))))))
(if (or (<= t_2 -2e-104) (not (<= t_2 2e-104)))
(+ (cbrt (* (* (/ g a) 2.0) -0.5)) (cbrt (* -0.25 (* (/ h a) (/ h g)))))
(+ t_1 (/ (cbrt (* (* -2.0 g) 0.5)) (cbrt a))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = cbrt((pow((2.0 * a), -1.0) * (-g + t_0)));
double t_2 = t_1 + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double tmp;
if ((t_2 <= -2e-104) || !(t_2 <= 2e-104)) {
tmp = cbrt((((g / a) * 2.0) * -0.5)) + cbrt((-0.25 * ((h / a) * (h / g))));
} else {
tmp = t_1 + (cbrt(((-2.0 * g) * 0.5)) / cbrt(a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.sqrt(((g * g) - (h * h)));
double t_1 = Math.cbrt((Math.pow((2.0 * a), -1.0) * (-g + t_0)));
double t_2 = t_1 + Math.cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double tmp;
if ((t_2 <= -2e-104) || !(t_2 <= 2e-104)) {
tmp = Math.cbrt((((g / a) * 2.0) * -0.5)) + Math.cbrt((-0.25 * ((h / a) * (h / g))));
} else {
tmp = t_1 + (Math.cbrt(((-2.0 * g) * 0.5)) / Math.cbrt(a));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + t_0))) t_2 = Float64(t_1 + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) tmp = 0.0 if ((t_2 <= -2e-104) || !(t_2 <= 2e-104)) tmp = Float64(cbrt(Float64(Float64(Float64(g / a) * 2.0) * -0.5)) + cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))); else tmp = Float64(t_1 + Float64(cbrt(Float64(Float64(-2.0 * g) * 0.5)) / cbrt(a))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 + N[Power[N[(N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(g + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$2, -2e-104], N[Not[LessEqual[t$95$2, 2e-104]], $MachinePrecision]], N[(N[Power[N[(N[(N[(g / a), $MachinePrecision] * 2.0), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(N[Power[N[(N[(-2.0 * g), $MachinePrecision] * 0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \sqrt[3]{{\left(2 \cdot a\right)}^{-1} \cdot \left(\left(-g\right) + t\_0\right)}\\
t_2 := t\_1 + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)}\\
\mathbf{if}\;t\_2 \leq -2 \cdot 10^{-104} \lor \neg \left(t\_2 \leq 2 \cdot 10^{-104}\right):\\
\;\;\;\;\sqrt[3]{\left(\frac{g}{a} \cdot 2\right) \cdot -0.5} + \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_1 + \frac{\sqrt[3]{\left(-2 \cdot g\right) \cdot 0.5}}{\sqrt[3]{a}}\\
\end{array}
\end{array}
if (+.f64 (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < -1.99999999999999985e-104 or 1.99999999999999985e-104 < (+.f64 (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) Initial program 46.1%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites75.9%
Applied rewrites92.8%
Applied rewrites76.7%
if -1.99999999999999985e-104 < (+.f64 (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (+.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h)))))) (cbrt.f64 (*.f64 (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) (-.f64 (neg.f64 g) (sqrt.f64 (-.f64 (*.f64 g g) (*.f64 h h))))))) < 1.99999999999999985e-104Initial program 16.8%
lift-cbrt.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
associate-*r/N/A
cbrt-divN/A
lower-/.f64N/A
Applied rewrites35.7%
Taylor expanded in g around inf
metadata-evalN/A
metadata-evalN/A
rem-square-sqrtN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
metadata-eval87.1
Applied rewrites87.1%
Final simplification77.2%
(FPCore (g h a) :precision binary64 (/ (fma (cbrt -0.25) (cbrt (* (/ h g) h)) (cbrt (* (* 2.0 g) -0.5))) (cbrt a)))
double code(double g, double h, double a) {
return fma(cbrt(-0.25), cbrt(((h / g) * h)), cbrt(((2.0 * g) * -0.5))) / cbrt(a);
}
function code(g, h, a) return Float64(fma(cbrt(-0.25), cbrt(Float64(Float64(h / g) * h)), cbrt(Float64(Float64(2.0 * g) * -0.5))) / cbrt(a)) end
code[g_, h_, a_] := N[(N[(N[Power[-0.25, 1/3], $MachinePrecision] * N[Power[N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(2.0 * g), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\sqrt[3]{-0.25}, \sqrt[3]{\frac{h}{g} \cdot h}, \sqrt[3]{\left(2 \cdot g\right) \cdot -0.5}\right)}{\sqrt[3]{a}}
\end{array}
Initial program 44.8%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites73.1%
Applied rewrites92.5%
Applied rewrites96.3%
Applied rewrites96.8%
(FPCore (g h a)
:precision binary64
(if (<= g -1.35e+154)
(+ (cbrt (* (* (/ g a) 2.0) -0.5)) (cbrt (* -0.25 (* (/ h a) (/ h g)))))
(if (<= g -1e-307)
(+
(/ (cbrt (- (sqrt (fma (- h) h (* g g))) g)) (cbrt (* 2.0 a)))
(cbrt (* (/ -0.25 a) (/ (* h h) g))))
(*
(cbrt (/ 0.5 a))
(+
(cbrt (- (fma (sqrt (+ h g)) (sqrt (- g h)) g)))
(cbrt (* (* (/ h g) h) -0.5)))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -1.35e+154) {
tmp = cbrt((((g / a) * 2.0) * -0.5)) + cbrt((-0.25 * ((h / a) * (h / g))));
} else if (g <= -1e-307) {
tmp = (cbrt((sqrt(fma(-h, h, (g * g))) - g)) / cbrt((2.0 * a))) + cbrt(((-0.25 / a) * ((h * h) / g)));
} else {
tmp = cbrt((0.5 / a)) * (cbrt(-fma(sqrt((h + g)), sqrt((g - h)), g)) + cbrt((((h / g) * h) * -0.5)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -1.35e+154) tmp = Float64(cbrt(Float64(Float64(Float64(g / a) * 2.0) * -0.5)) + cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))); elseif (g <= -1e-307) tmp = Float64(Float64(cbrt(Float64(sqrt(fma(Float64(-h), h, Float64(g * g))) - g)) / cbrt(Float64(2.0 * a))) + cbrt(Float64(Float64(-0.25 / a) * Float64(Float64(h * h) / g)))); else tmp = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(-fma(sqrt(Float64(h + g)), sqrt(Float64(g - h)), g))) + cbrt(Float64(Float64(Float64(h / g) * h) * -0.5)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, -1.35e+154], N[(N[Power[N[(N[(N[(g / a), $MachinePrecision] * 2.0), $MachinePrecision] * -0.5), $MachinePrecision], 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, -1e-307], N[(N[(N[Power[N[(N[Sqrt[N[((-h) * h + N[(g * g), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - g), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(2.0 * a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(-0.25 / a), $MachinePrecision] * N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[(-N[(N[Sqrt[N[(h + g), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(g - h), $MachinePrecision]], $MachinePrecision] + g), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\left(\frac{g}{a} \cdot 2\right) \cdot -0.5} + \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\\
\mathbf{elif}\;g \leq -1 \cdot 10^{-307}:\\
\;\;\;\;\frac{\sqrt[3]{\sqrt{\mathsf{fma}\left(-h, h, g \cdot g\right)} - g}}{\sqrt[3]{2 \cdot a}} + \sqrt[3]{\frac{-0.25}{a} \cdot \frac{h \cdot h}{g}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{-\mathsf{fma}\left(\sqrt{h + g}, \sqrt{g - h}, g\right)} + \sqrt[3]{\left(\frac{h}{g} \cdot h\right) \cdot -0.5}\right)\\
\end{array}
\end{array}
if g < -1.35000000000000003e154Initial program 0.0%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites57.5%
Applied rewrites92.6%
Applied rewrites58.1%
if -1.35000000000000003e154 < g < -9.99999999999999909e-308Initial program 73.0%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6416.0
Applied rewrites16.0%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites0.0%
Taylor expanded in g around -inf
associate-*r/N/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f640.0
Applied rewrites0.0%
lift-neg.f64N/A
lift-fma.f64N/A
lift-sqrt.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-+.f64N/A
lift--.f64N/A
sqrt-prodN/A
lift-*.f64N/A
lift-sqrt.f64N/A
lower-+.f64N/A
Applied rewrites86.9%
if -9.99999999999999909e-308 < g Initial program 46.1%
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
sqr-neg-revN/A
lift-neg.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower--.f640.0
Applied rewrites0.0%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f640.0
Applied rewrites0.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-squares-revN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
difference-of-squaresN/A
+-commutativeN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-unprodN/A
Applied rewrites76.0%
Applied rewrites97.3%
Final simplification86.0%
(FPCore (g h a)
:precision binary64
(if (<= g -1e-307)
(+ (cbrt (* (* (/ g a) 2.0) -0.5)) (cbrt (* -0.25 (* (/ h a) (/ h g)))))
(*
(cbrt (/ 0.5 a))
(+
(cbrt (- (fma (sqrt (+ h g)) (sqrt (- g h)) g)))
(cbrt (* (* (/ h g) h) -0.5))))))
double code(double g, double h, double a) {
double tmp;
if (g <= -1e-307) {
tmp = cbrt((((g / a) * 2.0) * -0.5)) + cbrt((-0.25 * ((h / a) * (h / g))));
} else {
tmp = cbrt((0.5 / a)) * (cbrt(-fma(sqrt((h + g)), sqrt((g - h)), g)) + cbrt((((h / g) * h) * -0.5)));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (g <= -1e-307) tmp = Float64(cbrt(Float64(Float64(Float64(g / a) * 2.0) * -0.5)) + cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))); else tmp = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(-fma(sqrt(Float64(h + g)), sqrt(Float64(g - h)), g))) + cbrt(Float64(Float64(Float64(h / g) * h) * -0.5)))); end return tmp end
code[g_, h_, a_] := If[LessEqual[g, -1e-307], N[(N[Power[N[(N[(N[(g / a), $MachinePrecision] * 2.0), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[(-N[(N[Sqrt[N[(h + g), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(g - h), $MachinePrecision]], $MachinePrecision] + g), $MachinePrecision]), 1/3], $MachinePrecision] + N[Power[N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] * -0.5), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;g \leq -1 \cdot 10^{-307}:\\
\;\;\;\;\sqrt[3]{\left(\frac{g}{a} \cdot 2\right) \cdot -0.5} + \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{-\mathsf{fma}\left(\sqrt{h + g}, \sqrt{g - h}, g\right)} + \sqrt[3]{\left(\frac{h}{g} \cdot h\right) \cdot -0.5}\right)\\
\end{array}
\end{array}
if g < -9.99999999999999909e-308Initial program 43.5%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites70.0%
Applied rewrites94.4%
Applied rewrites70.6%
if -9.99999999999999909e-308 < g Initial program 46.1%
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
sqr-neg-revN/A
lift-neg.f64N/A
lift-neg.f64N/A
lift-*.f64N/A
difference-of-squaresN/A
sqrt-prodN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower--.f640.0
Applied rewrites0.0%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f640.0
Applied rewrites0.0%
lift--.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
*-commutativeN/A
lift-+.f64N/A
lift--.f64N/A
difference-of-squares-revN/A
lift-neg.f64N/A
lift-neg.f64N/A
sqr-neg-revN/A
difference-of-squaresN/A
+-commutativeN/A
lift-+.f64N/A
lift--.f64N/A
*-commutativeN/A
sqrt-unprodN/A
Applied rewrites76.0%
Applied rewrites97.3%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ g a) 2.0) -0.5)) (cbrt (* -0.25 (* (/ h a) (/ h g))))))
double code(double g, double h, double a) {
return cbrt((((g / a) * 2.0) * -0.5)) + cbrt((-0.25 * ((h / a) * (h / g))));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((g / a) * 2.0) * -0.5)) + Math.cbrt((-0.25 * ((h / a) * (h / g))));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(g / a) * 2.0) * -0.5)) + cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(N[(g / a), $MachinePrecision] * 2.0), $MachinePrecision] * -0.5), $MachinePrecision], 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}
\\
\sqrt[3]{\left(\frac{g}{a} \cdot 2\right) \cdot -0.5} + \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}
\end{array}
Initial program 44.8%
Taylor expanded in h around 0
*-commutativeN/A
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
Applied rewrites73.1%
Applied rewrites92.5%
Applied rewrites73.9%
(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(Float64(-g) + Float64(-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(\left(-g\right) + \left(-g\right)\right)} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 44.8%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6427.9
Applied rewrites27.9%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f6415.2
Applied rewrites15.2%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6415.2
Applied rewrites15.2%
(FPCore (g h a) :precision binary64 (- 0.0))
double code(double g, double h, double a) {
return -0.0;
}
real(8) function code(g, h, a)
real(8), intent (in) :: g
real(8), intent (in) :: h
real(8), intent (in) :: a
code = -0.0d0
end function
public static double code(double g, double h, double a) {
return -0.0;
}
def code(g, h, a): return -0.0
function code(g, h, a) return Float64(-0.0) end
function tmp = code(g, h, a) tmp = -0.0; end
code[g_, h_, a_] := (-0.0)
\begin{array}{l}
\\
-0
\end{array}
Initial program 44.8%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6427.9
Applied rewrites27.9%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites18.6%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
Applied rewrites3.0%
Taylor expanded in g around 0
Applied rewrites3.0%
herbie shell --seed 2024333
(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))))))))