
(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 13 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 (* (pow a -1.0) 2.0)) (cbrt g)) (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((pow(a, -1.0) * 2.0)) * cbrt(g)), cbrt(-0.5), ((cbrt(((h / g) * h)) / cbrt(a)) * (cbrt(0.5) * cbrt(-0.5))));
}
function code(g, h, a) return fma(Float64(cbrt(Float64((a ^ -1.0) * 2.0)) * cbrt(g)), 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[Power[N[(N[Power[a, -1.0], $MachinePrecision] * 2.0), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[g, 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(\sqrt[3]{{a}^{-1} \cdot 2} \cdot \sqrt[3]{g}, \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 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites97.0%
(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)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0)))))
(t_2
(* (- g) (* (cbrt 0.5) (+ (cbrt 0.0) (cbrt (/ 2.0 (* a (* g g))))))))
(t_3 (cbrt (/ (- g) a))))
(if (<= t_1 -4e+89)
t_2
(if (<= t_1 2e+98)
(fma (cbrt (/ h a)) (cbrt (* -0.25 (/ h g))) t_3)
(if (<= t_1 INFINITY)
t_2
(fma (cbrt (/ (* (/ h g) h) a)) (cbrt -0.25) t_3))))))
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))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double t_2 = -g * (cbrt(0.5) * (cbrt(0.0) + cbrt((2.0 / (a * (g * g))))));
double t_3 = cbrt((-g / a));
double tmp;
if (t_1 <= -4e+89) {
tmp = t_2;
} else if (t_1 <= 2e+98) {
tmp = fma(cbrt((h / a)), cbrt((-0.25 * (h / g))), t_3);
} else if (t_1 <= ((double) INFINITY)) {
tmp = t_2;
} else {
tmp = fma(cbrt((((h / g) * h) / a)), cbrt(-0.25), t_3);
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = Float64(cbrt(Float64((Float64(2.0 * a) ^ -1.0) * Float64(Float64(-g) + t_0))) + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) t_2 = Float64(Float64(-g) * Float64(cbrt(0.5) * Float64(cbrt(0.0) + cbrt(Float64(2.0 / Float64(a * Float64(g * g))))))) t_3 = cbrt(Float64(Float64(-g) / a)) tmp = 0.0 if (t_1 <= -4e+89) tmp = t_2; elseif (t_1 <= 2e+98) tmp = fma(cbrt(Float64(h / a)), cbrt(Float64(-0.25 * Float64(h / g))), t_3); elseif (t_1 <= Inf) tmp = t_2; else tmp = fma(cbrt(Float64(Float64(Float64(h / g) * h) / a)), cbrt(-0.25), t_3); 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[(N[Power[N[(N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision] * N[((-g) + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(-1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * N[(g + t$95$0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[((-g) * N[(N[Power[0.5, 1/3], $MachinePrecision] * N[(N[Power[0.0, 1/3], $MachinePrecision] + N[Power[N[(2.0 / N[(a * N[(g * g), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[t$95$1, -4e+89], t$95$2, If[LessEqual[t$95$1, 2e+98], N[(N[Power[N[(h / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-0.25 * N[(h / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + t$95$3), $MachinePrecision], If[LessEqual[t$95$1, Infinity], t$95$2, N[(N[Power[N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.25, 1/3], $MachinePrecision] + t$95$3), $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)} + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)}\\
t_2 := \left(-g\right) \cdot \left(\sqrt[3]{0.5} \cdot \left(\sqrt[3]{0} + \sqrt[3]{\frac{2}{a \cdot \left(g \cdot g\right)}}\right)\right)\\
t_3 := \sqrt[3]{\frac{-g}{a}}\\
\mathbf{if}\;t\_1 \leq -4 \cdot 10^{+89}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+98}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{h}{a}}, \sqrt[3]{-0.25 \cdot \frac{h}{g}}, t\_3\right)\\
\mathbf{elif}\;t\_1 \leq \infty:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{\frac{h}{g} \cdot h}{a}}, \sqrt[3]{-0.25}, t\_3\right)\\
\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))))))) < -3.99999999999999998e89 or 2e98 < (+.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))))))) < +inf.0Initial program 9.8%
lift-+.f64N/A
+-commutativeN/A
Applied rewrites9.8%
Taylor expanded in g around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-+.f64N/A
Applied rewrites99.1%
if -3.99999999999999998e89 < (+.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))))))) < 2e98Initial program 79.3%
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 rewrites89.1%
Applied rewrites95.1%
Applied rewrites95.7%
Applied rewrites90.3%
if +inf.0 < (+.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 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 rewrites60.0%
Applied rewrites91.8%
Applied rewrites96.9%
Applied rewrites60.8%
Final simplification78.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (* (- g h) (+ h g))))
(t_1 (pow (* 2.0 a) -1.0))
(t_2 (* (cbrt (/ 0.5 a)) (+ (cbrt (- t_0 g)) (cbrt (- (- g) t_0))))))
(if (<= t_1 -2e+130)
t_2
(if (<= t_1 -2e+100)
(/
(fma
(cbrt (* (* a a) (/ (* h h) g)))
(cbrt -0.25)
(* (cbrt (* (* a a) g)) (cbrt -1.0)))
a)
(if (<= t_1 5e+218)
(fma
(cbrt (* (* (/ h g) h) -0.25))
(pow (cbrt a) -1.0)
(cbrt (/ (- g) a)))
t_2)))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g - h) * (h + g)));
double t_1 = pow((2.0 * a), -1.0);
double t_2 = cbrt((0.5 / a)) * (cbrt((t_0 - g)) + cbrt((-g - t_0)));
double tmp;
if (t_1 <= -2e+130) {
tmp = t_2;
} else if (t_1 <= -2e+100) {
tmp = fma(cbrt(((a * a) * ((h * h) / g))), cbrt(-0.25), (cbrt(((a * a) * g)) * cbrt(-1.0))) / a;
} else if (t_1 <= 5e+218) {
tmp = fma(cbrt((((h / g) * h) * -0.25)), pow(cbrt(a), -1.0), cbrt((-g / a)));
} else {
tmp = t_2;
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g - h) * Float64(h + g))) t_1 = Float64(2.0 * a) ^ -1.0 t_2 = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(t_0 - g)) + cbrt(Float64(Float64(-g) - t_0)))) tmp = 0.0 if (t_1 <= -2e+130) tmp = t_2; elseif (t_1 <= -2e+100) tmp = Float64(fma(cbrt(Float64(Float64(a * a) * Float64(Float64(h * h) / g))), cbrt(-0.25), Float64(cbrt(Float64(Float64(a * a) * g)) * cbrt(-1.0))) / a); elseif (t_1 <= 5e+218) tmp = fma(cbrt(Float64(Float64(Float64(h / g) * h) * -0.25)), (cbrt(a) ^ -1.0), cbrt(Float64(Float64(-g) / a))); else tmp = t_2; end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g - h), $MachinePrecision] * N[(h + g), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[N[(t$95$0 - g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) - t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+130], t$95$2, If[LessEqual[t$95$1, -2e+100], N[(N[(N[Power[N[(N[(a * a), $MachinePrecision] * N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.25, 1/3], $MachinePrecision] + N[(N[Power[N[(N[(a * a), $MachinePrecision] * g), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[t$95$1, 5e+218], N[(N[Power[N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[Power[a, 1/3], $MachinePrecision], -1.0], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(g - h\right) \cdot \left(h + g\right)}\\
t_1 := {\left(2 \cdot a\right)}^{-1}\\
t_2 := \sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{t\_0 - g} + \sqrt[3]{\left(-g\right) - t\_0}\right)\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{+130}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq -2 \cdot 10^{+100}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\sqrt[3]{\left(a \cdot a\right) \cdot \frac{h \cdot h}{g}}, \sqrt[3]{-0.25}, \sqrt[3]{\left(a \cdot a\right) \cdot g} \cdot \sqrt[3]{-1}\right)}{a}\\
\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\left(\frac{h}{g} \cdot h\right) \cdot -0.25}, {\left(\sqrt[3]{a}\right)}^{-1}, \sqrt[3]{\frac{-g}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < -2.0000000000000001e130 or 4.99999999999999983e218 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) Initial program 28.6%
lift-+.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
Applied rewrites52.8%
if -2.0000000000000001e130 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < -2.00000000000000003e100Initial program 26.9%
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 rewrites29.6%
Applied rewrites30.2%
Taylor expanded in a around 0
Applied rewrites90.5%
if -2.00000000000000003e100 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < 4.99999999999999983e218Initial program 45.9%
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 rewrites85.6%
Applied rewrites95.6%
Applied rewrites96.6%
Applied rewrites87.0%
Final simplification78.8%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (* (- g h) (+ h g)))))
(if (<= (pow (* 2.0 a) -1.0) 5e+218)
(fma
(cbrt (* (* (/ h g) h) -0.25))
(pow (cbrt a) -1.0)
(cbrt (/ (- g) a)))
(* (cbrt (/ 0.5 a)) (+ (cbrt (- t_0 g)) (cbrt (- (- g) t_0)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g - h) * (h + g)));
double tmp;
if (pow((2.0 * a), -1.0) <= 5e+218) {
tmp = fma(cbrt((((h / g) * h) * -0.25)), pow(cbrt(a), -1.0), cbrt((-g / a)));
} else {
tmp = cbrt((0.5 / a)) * (cbrt((t_0 - g)) + cbrt((-g - t_0)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g - h) * Float64(h + g))) tmp = 0.0 if ((Float64(2.0 * a) ^ -1.0) <= 5e+218) tmp = fma(cbrt(Float64(Float64(Float64(h / g) * h) * -0.25)), (cbrt(a) ^ -1.0), cbrt(Float64(Float64(-g) / a))); else tmp = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(t_0 - g)) + cbrt(Float64(Float64(-g) - t_0)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g - h), $MachinePrecision] * N[(h + g), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision], 5e+218], N[(N[Power[N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[Power[a, 1/3], $MachinePrecision], -1.0], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[N[(t$95$0 - g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) - t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(g - h\right) \cdot \left(h + g\right)}\\
\mathbf{if}\;{\left(2 \cdot a\right)}^{-1} \leq 5 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\left(\frac{h}{g} \cdot h\right) \cdot -0.25}, {\left(\sqrt[3]{a}\right)}^{-1}, \sqrt[3]{\frac{-g}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{t\_0 - g} + \sqrt[3]{\left(-g\right) - t\_0}\right)\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < 4.99999999999999983e218Initial 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 rewrites76.6%
Applied rewrites94.6%
Applied rewrites96.2%
Applied rewrites77.8%
if 4.99999999999999983e218 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) Initial program 20.7%
lift-+.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
Applied rewrites56.4%
Final simplification75.4%
(FPCore (g h a) :precision binary64 (fma (* (cbrt -0.5) (cbrt g)) (cbrt (* (pow a -1.0) 2.0)) (cbrt (* -0.25 (/ (* (/ h g) h) a)))))
double code(double g, double h, double a) {
return fma((cbrt(-0.5) * cbrt(g)), cbrt((pow(a, -1.0) * 2.0)), cbrt((-0.25 * (((h / g) * h) / a))));
}
function code(g, h, a) return fma(Float64(cbrt(-0.5) * cbrt(g)), cbrt(Float64((a ^ -1.0) * 2.0)), cbrt(Float64(-0.25 * Float64(Float64(Float64(h / g) * h) / a)))) end
code[g_, h_, a_] := N[(N[(N[Power[-0.5, 1/3], $MachinePrecision] * N[Power[g, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[N[(N[Power[a, -1.0], $MachinePrecision] * 2.0), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt[3]{-0.5} \cdot \sqrt[3]{g}, \sqrt[3]{{a}^{-1} \cdot 2}, \sqrt[3]{-0.25 \cdot \frac{\frac{h}{g} \cdot h}{a}}\right)
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites95.3%
(FPCore (g h a) :precision binary64 (fma (cbrt g) (* (cbrt (* (pow a -1.0) 2.0)) (cbrt -0.5)) (cbrt (* -0.25 (/ (* (/ h g) h) a)))))
double code(double g, double h, double a) {
return fma(cbrt(g), (cbrt((pow(a, -1.0) * 2.0)) * cbrt(-0.5)), cbrt((-0.25 * (((h / g) * h) / a))));
}
function code(g, h, a) return fma(cbrt(g), Float64(cbrt(Float64((a ^ -1.0) * 2.0)) * cbrt(-0.5)), cbrt(Float64(-0.25 * Float64(Float64(Float64(h / g) * h) / a)))) end
code[g_, h_, a_] := N[(N[Power[g, 1/3], $MachinePrecision] * N[(N[Power[N[(N[Power[a, -1.0], $MachinePrecision] * 2.0), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt[3]{g}, \sqrt[3]{{a}^{-1} \cdot 2} \cdot \sqrt[3]{-0.5}, \sqrt[3]{-0.25 \cdot \frac{\frac{h}{g} \cdot h}{a}}\right)
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites95.2%
(FPCore (g h a) :precision binary64 (fma (pow (cbrt a) -1.0) (* (cbrt g) (cbrt -1.0)) (cbrt (* -0.25 (/ (* (/ h g) h) a)))))
double code(double g, double h, double a) {
return fma(pow(cbrt(a), -1.0), (cbrt(g) * cbrt(-1.0)), cbrt((-0.25 * (((h / g) * h) / a))));
}
function code(g, h, a) return fma((cbrt(a) ^ -1.0), Float64(cbrt(g) * cbrt(-1.0)), cbrt(Float64(-0.25 * Float64(Float64(Float64(h / g) * h) / a)))) end
code[g_, h_, a_] := N[(N[Power[N[Power[a, 1/3], $MachinePrecision], -1.0], $MachinePrecision] * N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left({\left(\sqrt[3]{a}\right)}^{-1}, \sqrt[3]{g} \cdot \sqrt[3]{-1}, \sqrt[3]{-0.25 \cdot \frac{\frac{h}{g} \cdot h}{a}}\right)
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites95.1%
(FPCore (g h a) :precision binary64 (fma (pow (cbrt a) -1.0) (* (cbrt g) (cbrt -1.0)) (cbrt (* -0.25 (* (/ h a) (/ h g))))))
double code(double g, double h, double a) {
return fma(pow(cbrt(a), -1.0), (cbrt(g) * cbrt(-1.0)), cbrt((-0.25 * ((h / a) * (h / g)))));
}
function code(g, h, a) return fma((cbrt(a) ^ -1.0), Float64(cbrt(g) * cbrt(-1.0)), cbrt(Float64(-0.25 * Float64(Float64(h / a) * Float64(h / g))))) end
code[g_, h_, a_] := N[(N[Power[N[Power[a, 1/3], $MachinePrecision], -1.0], $MachinePrecision] * N[(N[Power[g, 1/3], $MachinePrecision] * N[Power[-1.0, 1/3], $MachinePrecision]), $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({\left(\sqrt[3]{a}\right)}^{-1}, \sqrt[3]{g} \cdot \sqrt[3]{-1}, \sqrt[3]{-0.25 \cdot \left(\frac{h}{a} \cdot \frac{h}{g}\right)}\right)
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites94.0%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (* (- g h) (+ h g)))))
(if (<= (pow (* 2.0 a) -1.0) 5e+218)
(fma (cbrt (/ h a)) (cbrt (* -0.25 (/ h g))) (cbrt (/ (- g) a)))
(* (cbrt (/ 0.5 a)) (+ (cbrt (- t_0 g)) (cbrt (- (- g) t_0)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g - h) * (h + g)));
double tmp;
if (pow((2.0 * a), -1.0) <= 5e+218) {
tmp = fma(cbrt((h / a)), cbrt((-0.25 * (h / g))), cbrt((-g / a)));
} else {
tmp = cbrt((0.5 / a)) * (cbrt((t_0 - g)) + cbrt((-g - t_0)));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g - h) * Float64(h + g))) tmp = 0.0 if ((Float64(2.0 * a) ^ -1.0) <= 5e+218) tmp = fma(cbrt(Float64(h / a)), cbrt(Float64(-0.25 * Float64(h / g))), cbrt(Float64(Float64(-g) / a))); else tmp = Float64(cbrt(Float64(0.5 / a)) * Float64(cbrt(Float64(t_0 - g)) + cbrt(Float64(Float64(-g) - t_0)))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[Sqrt[N[(N[(g - h), $MachinePrecision] * N[(h + g), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision], 5e+218], N[(N[Power[N[(h / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-0.25 * N[(h / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[(N[Power[N[(t$95$0 - g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) - t$95$0), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(g - h\right) \cdot \left(h + g\right)}\\
\mathbf{if}\;{\left(2 \cdot a\right)}^{-1} \leq 5 \cdot 10^{+218}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{h}{a}}, \sqrt[3]{-0.25 \cdot \frac{h}{g}}, \sqrt[3]{\frac{-g}{a}}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{0.5}{a}} \cdot \left(\sqrt[3]{t\_0 - g} + \sqrt[3]{\left(-g\right) - t\_0}\right)\\
\end{array}
\end{array}
if (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) < 4.99999999999999983e218Initial 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 rewrites76.6%
Applied rewrites94.6%
Applied rewrites96.2%
Applied rewrites77.7%
if 4.99999999999999983e218 < (/.f64 #s(literal 1 binary64) (*.f64 #s(literal 2 binary64) a)) Initial program 20.7%
lift-+.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
pow1/3N/A
Applied rewrites56.4%
Final simplification75.3%
(FPCore (g h a) :precision binary64 (fma (cbrt (/ h a)) (cbrt (* -0.25 (/ h g))) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return fma(cbrt((h / a)), cbrt((-0.25 * (h / g))), cbrt((-g / a)));
}
function code(g, h, a) return fma(cbrt(Float64(h / a)), cbrt(Float64(-0.25 * Float64(h / g))), cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(h / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(-0.25 * N[(h / g), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt[3]{\frac{h}{a}}, \sqrt[3]{-0.25 \cdot \frac{h}{g}}, \sqrt[3]{\frac{-g}{a}}\right)
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites72.4%
(FPCore (g h a) :precision binary64 (+ (cbrt (/ (- g) a)) (cbrt (* -0.25 (/ (* (/ h g) h) a)))))
double code(double g, double h, double a) {
return cbrt((-g / a)) + cbrt((-0.25 * (((h / g) * h) / a)));
}
public static double code(double g, double h, double a) {
return Math.cbrt((-g / a)) + Math.cbrt((-0.25 * (((h / g) * h) / a)));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(-g) / a)) + cbrt(Float64(-0.25 * Float64(Float64(Float64(h / g) * h) / a)))) end
code[g_, h_, a_] := N[(N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(-0.25 * N[(N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{-g}{a}} + \sqrt[3]{-0.25 \cdot \frac{\frac{h}{g} \cdot h}{a}}
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites93.5%
Applied rewrites96.4%
Applied rewrites72.3%
(FPCore (g h a) :precision binary64 (* (cbrt -1.0) (cbrt (/ g a))))
double code(double g, double h, double a) {
return cbrt(-1.0) * cbrt((g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt(-1.0) * Math.cbrt((g / a));
}
function code(g, h, a) return Float64(cbrt(-1.0) * cbrt(Float64(g / a))) end
code[g_, h_, a_] := N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{-1} \cdot \sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 40.9%
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 rewrites71.4%
Applied rewrites72.4%
Taylor expanded in g around inf
Applied rewrites70.7%
(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 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 40.9%
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 rewrites45.5%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-*.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
unpow2N/A
rem-square-sqrtN/A
lower-cbrt.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
lower-/.f64N/A
lower-cbrt.f642.9
Applied rewrites2.9%
Applied rewrites2.9%
herbie shell --seed 2024318
(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))))))))