
(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 10 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 2.0)) (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 * 2.0)) / 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(cbrt(Float64(g * 2.0)) / 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[Power[N[(g * 2.0), $MachinePrecision], 1/3], $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}}{\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 51.4%
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 rewrites80.6%
Applied rewrites96.2%
Applied rewrites97.7%
Applied rewrites98.0%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (/ (- g) a))
(t_2 (pow (* 2.0 a) -1.0))
(t_3
(+
(cbrt (* t_2 (+ (- g) t_0)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0)))))
(t_4 (/ (* h h) g)))
(if (<= t_3 -5e-99)
(+ (cbrt (* t_2 (* t_4 -0.5))) (cbrt (fma (/ 0.25 a) t_4 t_1)))
(if (<= t_3 0.0)
(+ (/ (cbrt (- (- g) g)) (cbrt (* 2.0 a))) (cbrt t_1))
(* (cbrt -1.0) (cbrt (/ g a)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = -g / a;
double t_2 = pow((2.0 * a), -1.0);
double t_3 = cbrt((t_2 * (-g + t_0))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double t_4 = (h * h) / g;
double tmp;
if (t_3 <= -5e-99) {
tmp = cbrt((t_2 * (t_4 * -0.5))) + cbrt(fma((0.25 / a), t_4, t_1));
} else if (t_3 <= 0.0) {
tmp = (cbrt((-g - g)) / cbrt((2.0 * a))) + cbrt(t_1);
} else {
tmp = cbrt(-1.0) * cbrt((g / a));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = Float64(Float64(-g) / a) t_2 = Float64(2.0 * a) ^ -1.0 t_3 = Float64(cbrt(Float64(t_2 * Float64(Float64(-g) + t_0))) + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) t_4 = Float64(Float64(h * h) / g) tmp = 0.0 if (t_3 <= -5e-99) tmp = Float64(cbrt(Float64(t_2 * Float64(t_4 * -0.5))) + cbrt(fma(Float64(0.25 / a), t_4, t_1))); elseif (t_3 <= 0.0) tmp = Float64(Float64(cbrt(Float64(Float64(-g) - g)) / cbrt(Float64(2.0 * a))) + cbrt(t_1)); else tmp = Float64(cbrt(-1.0) * cbrt(Float64(g / 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[((-g) / a), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[(t$95$2 * 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$4 = N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]}, If[LessEqual[t$95$3, -5e-99], N[(N[Power[N[(t$95$2 * N[(t$95$4 * -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.25 / a), $MachinePrecision] * t$95$4 + t$95$1), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(N[(N[Power[N[((-g) - g), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(2.0 * a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \frac{-g}{a}\\
t_2 := {\left(2 \cdot a\right)}^{-1}\\
t_3 := \sqrt[3]{t\_2 \cdot \left(\left(-g\right) + t\_0\right)} + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)}\\
t_4 := \frac{h \cdot h}{g}\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{-99}:\\
\;\;\;\;\sqrt[3]{t\_2 \cdot \left(t\_4 \cdot -0.5\right)} + \sqrt[3]{\mathsf{fma}\left(\frac{0.25}{a}, t\_4, t\_1\right)}\\
\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;\frac{\sqrt[3]{\left(-g\right) - g}}{\sqrt[3]{2 \cdot a}} + \sqrt[3]{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-1} \cdot \sqrt[3]{\frac{g}{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))))))) < -4.99999999999999969e-99Initial program 85.0%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6448.2
Applied rewrites48.2%
Taylor expanded in h around 0
+-commutativeN/A
associate-*r/N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
if -4.99999999999999969e-99 < (+.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))))))) < 0.0Initial program 4.4%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
*-lft-identityN/A
lower-/.f64N/A
Applied rewrites85.9%
if 0.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 37.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 rewrites77.4%
Applied rewrites78.3%
Taylor expanded in g around inf
Applied rewrites77.4%
Final simplification83.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (/ (- g) a))
(t_2 (pow (* 2.0 a) -1.0))
(t_3
(+
(cbrt (* t_2 (+ (- g) t_0)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0)))))
(t_4 (/ (* h h) g)))
(if (<= t_3 -5e-99)
(+ (cbrt (* t_2 (* t_4 -0.5))) (cbrt (fma (/ 0.25 a) t_4 t_1)))
(if (<= t_3 0.0)
(+ (/ (cbrt (* (- (- g) g) 0.5)) (cbrt a)) (cbrt t_1))
(* (cbrt -1.0) (cbrt (/ g a)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = -g / a;
double t_2 = pow((2.0 * a), -1.0);
double t_3 = cbrt((t_2 * (-g + t_0))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double t_4 = (h * h) / g;
double tmp;
if (t_3 <= -5e-99) {
tmp = cbrt((t_2 * (t_4 * -0.5))) + cbrt(fma((0.25 / a), t_4, t_1));
} else if (t_3 <= 0.0) {
tmp = (cbrt(((-g - g) * 0.5)) / cbrt(a)) + cbrt(t_1);
} else {
tmp = cbrt(-1.0) * cbrt((g / a));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = Float64(Float64(-g) / a) t_2 = Float64(2.0 * a) ^ -1.0 t_3 = Float64(cbrt(Float64(t_2 * Float64(Float64(-g) + t_0))) + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) t_4 = Float64(Float64(h * h) / g) tmp = 0.0 if (t_3 <= -5e-99) tmp = Float64(cbrt(Float64(t_2 * Float64(t_4 * -0.5))) + cbrt(fma(Float64(0.25 / a), t_4, t_1))); elseif (t_3 <= 0.0) tmp = Float64(Float64(cbrt(Float64(Float64(Float64(-g) - g) * 0.5)) / cbrt(a)) + cbrt(t_1)); else tmp = Float64(cbrt(-1.0) * cbrt(Float64(g / 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[((-g) / a), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[(t$95$2 * 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$4 = N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]}, If[LessEqual[t$95$3, -5e-99], N[(N[Power[N[(t$95$2 * N[(t$95$4 * -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.25 / a), $MachinePrecision] * t$95$4 + t$95$1), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(N[(N[Power[N[(N[((-g) - g), $MachinePrecision] * 0.5), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \frac{-g}{a}\\
t_2 := {\left(2 \cdot a\right)}^{-1}\\
t_3 := \sqrt[3]{t\_2 \cdot \left(\left(-g\right) + t\_0\right)} + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)}\\
t_4 := \frac{h \cdot h}{g}\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{-99}:\\
\;\;\;\;\sqrt[3]{t\_2 \cdot \left(t\_4 \cdot -0.5\right)} + \sqrt[3]{\mathsf{fma}\left(\frac{0.25}{a}, t\_4, t\_1\right)}\\
\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;\frac{\sqrt[3]{\left(\left(-g\right) - g\right) \cdot 0.5}}{\sqrt[3]{a}} + \sqrt[3]{t\_1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-1} \cdot \sqrt[3]{\frac{g}{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))))))) < -4.99999999999999969e-99Initial program 85.0%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6448.2
Applied rewrites48.2%
Taylor expanded in h around 0
+-commutativeN/A
associate-*r/N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
if -4.99999999999999969e-99 < (+.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))))))) < 0.0Initial program 4.4%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
lift-/.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lift-/.f644.4
Applied rewrites4.4%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
cbrt-divN/A
lift-cbrt.f64N/A
lower-/.f64N/A
Applied rewrites85.9%
if 0.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 37.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 rewrites77.4%
Applied rewrites78.3%
Taylor expanded in g around inf
Applied rewrites77.4%
Final simplification83.3%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (sqrt (- (* g g) (* h h))))
(t_1 (/ (- g) a))
(t_2 (pow (* 2.0 a) -1.0))
(t_3
(+
(cbrt (* t_2 (+ (- g) t_0)))
(cbrt (* (/ -1.0 (* 2.0 a)) (+ g t_0)))))
(t_4 (/ (* h h) g)))
(if (<= t_3 -5e-99)
(+ (cbrt (* t_2 (* t_4 -0.5))) (cbrt (fma (/ 0.25 a) t_4 t_1)))
(if (<= t_3 0.0)
(fma (cbrt (/ 0.5 a)) (cbrt (- (- g) g)) (cbrt t_1))
(* (cbrt -1.0) (cbrt (/ g a)))))))
double code(double g, double h, double a) {
double t_0 = sqrt(((g * g) - (h * h)));
double t_1 = -g / a;
double t_2 = pow((2.0 * a), -1.0);
double t_3 = cbrt((t_2 * (-g + t_0))) + cbrt(((-1.0 / (2.0 * a)) * (g + t_0)));
double t_4 = (h * h) / g;
double tmp;
if (t_3 <= -5e-99) {
tmp = cbrt((t_2 * (t_4 * -0.5))) + cbrt(fma((0.25 / a), t_4, t_1));
} else if (t_3 <= 0.0) {
tmp = fma(cbrt((0.5 / a)), cbrt((-g - g)), cbrt(t_1));
} else {
tmp = cbrt(-1.0) * cbrt((g / a));
}
return tmp;
}
function code(g, h, a) t_0 = sqrt(Float64(Float64(g * g) - Float64(h * h))) t_1 = Float64(Float64(-g) / a) t_2 = Float64(2.0 * a) ^ -1.0 t_3 = Float64(cbrt(Float64(t_2 * Float64(Float64(-g) + t_0))) + cbrt(Float64(Float64(-1.0 / Float64(2.0 * a)) * Float64(g + t_0)))) t_4 = Float64(Float64(h * h) / g) tmp = 0.0 if (t_3 <= -5e-99) tmp = Float64(cbrt(Float64(t_2 * Float64(t_4 * -0.5))) + cbrt(fma(Float64(0.25 / a), t_4, t_1))); elseif (t_3 <= 0.0) tmp = fma(cbrt(Float64(0.5 / a)), cbrt(Float64(Float64(-g) - g)), cbrt(t_1)); else tmp = Float64(cbrt(-1.0) * cbrt(Float64(g / 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[((-g) / a), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[(2.0 * a), $MachinePrecision], -1.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[N[(t$95$2 * 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$4 = N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision]}, If[LessEqual[t$95$3, -5e-99], N[(N[Power[N[(t$95$2 * N[(t$95$4 * -0.5), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(N[(0.25 / a), $MachinePrecision] * t$95$4 + t$95$1), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.0], N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[((-g) - g), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[t$95$1, 1/3], $MachinePrecision]), $MachinePrecision], N[(N[Power[-1.0, 1/3], $MachinePrecision] * N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{g \cdot g - h \cdot h}\\
t_1 := \frac{-g}{a}\\
t_2 := {\left(2 \cdot a\right)}^{-1}\\
t_3 := \sqrt[3]{t\_2 \cdot \left(\left(-g\right) + t\_0\right)} + \sqrt[3]{\frac{-1}{2 \cdot a} \cdot \left(g + t\_0\right)}\\
t_4 := \frac{h \cdot h}{g}\\
\mathbf{if}\;t\_3 \leq -5 \cdot 10^{-99}:\\
\;\;\;\;\sqrt[3]{t\_2 \cdot \left(t\_4 \cdot -0.5\right)} + \sqrt[3]{\mathsf{fma}\left(\frac{0.25}{a}, t\_4, t\_1\right)}\\
\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;\mathsf{fma}\left(\sqrt[3]{\frac{0.5}{a}}, \sqrt[3]{\left(-g\right) - g}, \sqrt[3]{t\_1}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{-1} \cdot \sqrt[3]{\frac{g}{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))))))) < -4.99999999999999969e-99Initial program 85.0%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6448.2
Applied rewrites48.2%
Taylor expanded in h around 0
+-commutativeN/A
associate-*r/N/A
times-fracN/A
lower-fma.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6495.8
Applied rewrites95.8%
if -4.99999999999999969e-99 < (+.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))))))) < 0.0Initial program 4.4%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
lift-+.f64N/A
lift-cbrt.f64N/A
lift-*.f64N/A
cbrt-prodN/A
lower-fma.f64N/A
Applied rewrites85.6%
if 0.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 37.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 rewrites77.4%
Applied rewrites78.3%
Taylor expanded in g around inf
Applied rewrites77.4%
Final simplification83.3%
(FPCore (g h a) :precision binary64 (fma (* (/ (cbrt g) (cbrt a)) (cbrt 2.0)) (cbrt -0.5) (* (/ (cbrt (* (/ h g) h)) (cbrt a)) (cbrt -0.25))))
double code(double g, double h, double a) {
return fma(((cbrt(g) / cbrt(a)) * cbrt(2.0)), cbrt(-0.5), ((cbrt(((h / g) * h)) / cbrt(a)) * cbrt(-0.25)));
}
function code(g, h, a) return fma(Float64(Float64(cbrt(g) / cbrt(a)) * cbrt(2.0)), cbrt(-0.5), Float64(Float64(cbrt(Float64(Float64(h / g) * h)) / cbrt(a)) * cbrt(-0.25))) end
code[g_, h_, a_] := N[(N[(N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[2.0, 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[Power[-0.25, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \sqrt[3]{2}, \sqrt[3]{-0.5}, \frac{\sqrt[3]{\frac{h}{g} \cdot h}}{\sqrt[3]{a}} \cdot \sqrt[3]{-0.25}\right)
\end{array}
Initial program 51.4%
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 rewrites80.6%
Applied rewrites96.2%
Applied rewrites97.7%
Applied rewrites97.7%
(FPCore (g h a) :precision binary64 (fma (/ (cbrt (* g 2.0)) (cbrt a)) (cbrt -0.5) (* (cbrt (* (/ h g) (/ h a))) (* (cbrt 0.5) (cbrt -0.5)))))
double code(double g, double h, double a) {
return fma((cbrt((g * 2.0)) / cbrt(a)), cbrt(-0.5), (cbrt(((h / g) * (h / a))) * (cbrt(0.5) * cbrt(-0.5))));
}
function code(g, h, a) return fma(Float64(cbrt(Float64(g * 2.0)) / cbrt(a)), cbrt(-0.5), 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 * 2.0), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[-0.5, 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 2}}{\sqrt[3]{a}}, \sqrt[3]{-0.5}, \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 51.4%
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 rewrites80.6%
Applied rewrites96.2%
Applied rewrites96.6%
(FPCore (g h a) :precision binary64 (fma (* (/ (cbrt g) (cbrt a)) (cbrt 2.0)) (cbrt -0.5) (* (cbrt (* (/ h g) (/ h a))) (cbrt -0.25))))
double code(double g, double h, double a) {
return fma(((cbrt(g) / cbrt(a)) * cbrt(2.0)), cbrt(-0.5), (cbrt(((h / g) * (h / a))) * cbrt(-0.25)));
}
function code(g, h, a) return fma(Float64(Float64(cbrt(g) / cbrt(a)) * cbrt(2.0)), cbrt(-0.5), Float64(cbrt(Float64(Float64(h / g) * Float64(h / a))) * cbrt(-0.25))) end
code[g_, h_, a_] := N[(N[(N[(N[Power[g, 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[2.0, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[-0.5, 1/3], $MachinePrecision] + N[(N[Power[N[(N[(h / g), $MachinePrecision] * N[(h / a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[-0.25, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{\sqrt[3]{g}}{\sqrt[3]{a}} \cdot \sqrt[3]{2}, \sqrt[3]{-0.5}, \sqrt[3]{\frac{h}{g} \cdot \frac{h}{a}} \cdot \sqrt[3]{-0.25}\right)
\end{array}
Initial program 51.4%
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 rewrites80.6%
Applied rewrites96.2%
Applied rewrites96.2%
(FPCore (g h a) :precision binary64 (fma (cbrt (* (/ h a) -0.25)) (cbrt (/ h g)) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return fma(cbrt(((h / a) * -0.25)), cbrt((h / g)), cbrt((-g / a)));
}
function code(g, h, a) return fma(cbrt(Float64(Float64(h / a) * -0.25)), cbrt(Float64(h / g)), cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(h / a), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[(h / g), $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} \cdot -0.25}, \sqrt[3]{\frac{h}{g}}, \sqrt[3]{\frac{-g}{a}}\right)
\end{array}
Initial program 51.4%
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 rewrites80.6%
Applied rewrites96.2%
Applied rewrites97.7%
Applied rewrites81.6%
(FPCore (g h a) :precision binary64 (fma (cbrt (/ 0.5 a)) (cbrt (- (- g) (* g 1.0))) (cbrt 0.0)))
double code(double g, double h, double a) {
return fma(cbrt((0.5 / a)), cbrt((-g - (g * 1.0))), cbrt(0.0));
}
function code(g, h, a) return fma(cbrt(Float64(0.5 / a)), cbrt(Float64(Float64(-g) - Float64(g * 1.0))), cbrt(0.0)) end
code[g_, h_, a_] := N[(N[Power[N[(0.5 / a), $MachinePrecision], 1/3], $MachinePrecision] * N[Power[N[((-g) - N[(g * 1.0), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[0.0, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sqrt[3]{\frac{0.5}{a}}, \sqrt[3]{\left(-g\right) - g \cdot 1}, \sqrt[3]{0}\right)
\end{array}
Initial program 51.4%
Applied rewrites14.4%
Taylor expanded in g around inf
lower-*.f64N/A
lower-/.f64N/A
distribute-rgt1-inN/A
rem-square-sqrtN/A
unpow2N/A
+-commutativeN/A
lower-*.f64N/A
unpow2N/A
rem-square-sqrtN/A
metadata-eval30.6
Applied rewrites30.6%
Taylor expanded in g around -inf
associate-*r*N/A
unpow2N/A
rem-square-sqrtN/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f6496.0
Applied rewrites96.0%
Final simplification96.0%
(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 51.4%
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 rewrites80.6%
Applied rewrites81.6%
Taylor expanded in g around inf
Applied rewrites79.8%
herbie shell --seed 2024342
(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))))))))