
(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 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g h a) :precision binary64 (let* ((t_0 (/ 1.0 (* 2.0 a))) (t_1 (sqrt (- (* g g) (* h h))))) (+ (cbrt (* t_0 (+ (- g) t_1))) (cbrt (* t_0 (- (- g) t_1))))))
double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = sqrt(((g * g) - (h * h)));
return cbrt((t_0 * (-g + t_1))) + cbrt((t_0 * (-g - t_1)));
}
public static double code(double g, double h, double a) {
double t_0 = 1.0 / (2.0 * a);
double t_1 = Math.sqrt(((g * g) - (h * h)));
return Math.cbrt((t_0 * (-g + t_1))) + Math.cbrt((t_0 * (-g - t_1)));
}
function code(g, h, a) t_0 = Float64(1.0 / Float64(2.0 * a)) t_1 = sqrt(Float64(Float64(g * g) - Float64(h * h))) return Float64(cbrt(Float64(t_0 * Float64(Float64(-g) + t_1))) + cbrt(Float64(t_0 * Float64(Float64(-g) - t_1)))) end
code[g_, h_, a_] := Block[{t$95$0 = N[(1.0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(g * g), $MachinePrecision] - N[(h * h), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(t$95$0 * N[((-g) + t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * N[((-g) - t$95$1), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{2 \cdot a}\\
t_1 := \sqrt{g \cdot g - h \cdot h}\\
\sqrt[3]{t\_0 \cdot \left(\left(-g\right) + t\_1\right)} + \sqrt[3]{t\_0 \cdot \left(\left(-g\right) - t\_1\right)}
\end{array}
\end{array}
(FPCore (g h a) :precision binary64 (+ (/ (cbrt (- g)) (cbrt a)) (cbrt (* (* -0.5 (* (/ h g) h)) (/ 1.0 (* a 2.0))))))
double code(double g, double h, double a) {
return (cbrt(-g) / cbrt(a)) + cbrt(((-0.5 * ((h / g) * h)) * (1.0 / (a * 2.0))));
}
public static double code(double g, double h, double a) {
return (Math.cbrt(-g) / Math.cbrt(a)) + Math.cbrt(((-0.5 * ((h / g) * h)) * (1.0 / (a * 2.0))));
}
function code(g, h, a) return Float64(Float64(cbrt(Float64(-g)) / cbrt(a)) + cbrt(Float64(Float64(-0.5 * Float64(Float64(h / g) * h)) * Float64(1.0 / Float64(a * 2.0))))) end
code[g_, h_, a_] := N[(N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(N[(-0.5 * N[(N[(h / g), $MachinePrecision] * h), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{-g}}{\sqrt[3]{a}} + \sqrt[3]{\left(-0.5 \cdot \left(\frac{h}{g} \cdot h\right)\right) \cdot \frac{1}{a \cdot 2}}
\end{array}
Initial program 38.6%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6421.3
Applied rewrites21.3%
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 rewrites25.3%
Taylor expanded in g around inf
mul-1-negN/A
lower-neg.f6489.3
Applied rewrites89.3%
Applied rewrites95.6%
Final simplification95.6%
(FPCore (g h a)
:precision binary64
(let* ((t_0 (/ (cbrt (- g)) (cbrt a))))
(if (<= (* h h) 5e-247)
(+ (pow (/ (* a 2.0) (* (/ (* h h) g) -0.5)) -0.3333333333333333) t_0)
(if (<= (* h h) 4e+306)
(+ (cbrt (/ (* -0.25 (* h h)) (* g a))) t_0)
(+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (/ (- g) a)))))))
double code(double g, double h, double a) {
double t_0 = cbrt(-g) / cbrt(a);
double tmp;
if ((h * h) <= 5e-247) {
tmp = pow(((a * 2.0) / (((h * h) / g) * -0.5)), -0.3333333333333333) + t_0;
} else if ((h * h) <= 4e+306) {
tmp = cbrt(((-0.25 * (h * h)) / (g * a))) + t_0;
} else {
tmp = cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((-g / a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double t_0 = Math.cbrt(-g) / Math.cbrt(a);
double tmp;
if ((h * h) <= 5e-247) {
tmp = Math.pow(((a * 2.0) / (((h * h) / g) * -0.5)), -0.3333333333333333) + t_0;
} else if ((h * h) <= 4e+306) {
tmp = Math.cbrt(((-0.25 * (h * h)) / (g * a))) + t_0;
} else {
tmp = Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((-g / a));
}
return tmp;
}
function code(g, h, a) t_0 = Float64(cbrt(Float64(-g)) / cbrt(a)) tmp = 0.0 if (Float64(h * h) <= 5e-247) tmp = Float64((Float64(Float64(a * 2.0) / Float64(Float64(Float64(h * h) / g) * -0.5)) ^ -0.3333333333333333) + t_0); elseif (Float64(h * h) <= 4e+306) tmp = Float64(cbrt(Float64(Float64(-0.25 * Float64(h * h)) / Float64(g * a))) + t_0); else tmp = Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64(Float64(-g) / a))); end return tmp end
code[g_, h_, a_] := Block[{t$95$0 = N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(h * h), $MachinePrecision], 5e-247], N[(N[Power[N[(N[(a * 2.0), $MachinePrecision] / N[(N[(N[(h * h), $MachinePrecision] / g), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], -0.3333333333333333], $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[N[(h * h), $MachinePrecision], 4e+306], N[(N[Power[N[(N[(-0.25 * N[(h * h), $MachinePrecision]), $MachinePrecision] / N[(g * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + t$95$0), $MachinePrecision], N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}\\
\mathbf{if}\;h \cdot h \leq 5 \cdot 10^{-247}:\\
\;\;\;\;{\left(\frac{a \cdot 2}{\frac{h \cdot h}{g} \cdot -0.5}\right)}^{-0.3333333333333333} + t\_0\\
\mathbf{elif}\;h \cdot h \leq 4 \cdot 10^{+306}:\\
\;\;\;\;\sqrt[3]{\frac{-0.25 \cdot \left(h \cdot h\right)}{g \cdot a}} + t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}\\
\end{array}
\end{array}
if (*.f64 h h) < 4.99999999999999978e-247Initial program 47.8%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6428.8
Applied rewrites28.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.9%
Taylor expanded in g around inf
mul-1-negN/A
lower-neg.f6498.0
Applied rewrites98.0%
lift-cbrt.f64N/A
pow1/3N/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
Applied rewrites98.0%
if 4.99999999999999978e-247 < (*.f64 h h) < 4.00000000000000007e306Initial program 36.2%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6417.1
Applied rewrites17.1%
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 rewrites17.9%
Taylor expanded in g around inf
mul-1-negN/A
lower-neg.f6497.4
Applied rewrites97.4%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6497.0
Applied rewrites97.0%
if 4.00000000000000007e306 < (*.f64 h h) Initial program 0.0%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f640.0
Applied rewrites0.0%
Taylor expanded in g around inf
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.f6445.7
Applied rewrites45.7%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6445.7
Applied rewrites45.7%
Final simplification92.9%
(FPCore (g h a) :precision binary64 (if (<= (* h h) 4e+306) (+ (cbrt (/ (* -0.25 (* h h)) (* g a))) (/ (cbrt (- g)) (cbrt a))) (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (/ (- g) a)))))
double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 4e+306) {
tmp = cbrt(((-0.25 * (h * h)) / (g * a))) + (cbrt(-g) / cbrt(a));
} else {
tmp = cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((-g / a));
}
return tmp;
}
public static double code(double g, double h, double a) {
double tmp;
if ((h * h) <= 4e+306) {
tmp = Math.cbrt(((-0.25 * (h * h)) / (g * a))) + (Math.cbrt(-g) / Math.cbrt(a));
} else {
tmp = Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((-g / a));
}
return tmp;
}
function code(g, h, a) tmp = 0.0 if (Float64(h * h) <= 4e+306) tmp = Float64(cbrt(Float64(Float64(-0.25 * Float64(h * h)) / Float64(g * a))) + Float64(cbrt(Float64(-g)) / cbrt(a))); else tmp = Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64(Float64(-g) / a))); end return tmp end
code[g_, h_, a_] := If[LessEqual[N[(h * h), $MachinePrecision], 4e+306], N[(N[Power[N[(N[(-0.25 * N[(h * h), $MachinePrecision]), $MachinePrecision] / N[(g * a), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[(-g), 1/3], $MachinePrecision] / N[Power[a, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;h \cdot h \leq 4 \cdot 10^{+306}:\\
\;\;\;\;\sqrt[3]{\frac{-0.25 \cdot \left(h \cdot h\right)}{g \cdot a}} + \frac{\sqrt[3]{-g}}{\sqrt[3]{a}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}\\
\end{array}
\end{array}
if (*.f64 h h) < 4.00000000000000007e306Initial program 42.4%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6423.4
Applied rewrites23.4%
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 rewrites27.6%
Taylor expanded in g around inf
mul-1-negN/A
lower-neg.f6497.7
Applied rewrites97.7%
Taylor expanded in g around inf
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-*.f6493.1
Applied rewrites93.1%
if 4.00000000000000007e306 < (*.f64 h h) Initial program 0.0%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f640.0
Applied rewrites0.0%
Taylor expanded in g around inf
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.f6445.7
Applied rewrites45.7%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6445.7
Applied rewrites45.7%
Final simplification88.9%
(FPCore (g h a) :precision binary64 (+ (cbrt (* (* (/ h a) (/ h g)) -0.25)) (cbrt (/ (- g) a))))
double code(double g, double h, double a) {
return cbrt((((h / a) * (h / g)) * -0.25)) + cbrt((-g / a));
}
public static double code(double g, double h, double a) {
return Math.cbrt((((h / a) * (h / g)) * -0.25)) + Math.cbrt((-g / a));
}
function code(g, h, a) return Float64(cbrt(Float64(Float64(Float64(h / a) * Float64(h / g)) * -0.25)) + cbrt(Float64(Float64(-g) / a))) end
code[g_, h_, a_] := N[(N[Power[N[(N[(N[(h / a), $MachinePrecision] * N[(h / g), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[((-g) / a), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\left(\frac{h}{a} \cdot \frac{h}{g}\right) \cdot -0.25} + \sqrt[3]{\frac{-g}{a}}
\end{array}
Initial program 38.6%
Taylor expanded in g around inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6423.7
Applied rewrites23.7%
Taylor expanded in g around inf
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.f6473.9
Applied rewrites73.9%
lift-+.f64N/A
+-commutativeN/A
lower-+.f6473.9
Applied rewrites73.9%
Final simplification73.9%
(FPCore (g h a) :precision binary64 (- (cbrt (/ g a))))
double code(double g, double h, double a) {
return -cbrt((g / a));
}
public static double code(double g, double h, double a) {
return -Math.cbrt((g / a));
}
function code(g, h, a) return Float64(-cbrt(Float64(g / a))) end
code[g_, h_, a_] := (-N[Power[N[(g / a), $MachinePrecision], 1/3], $MachinePrecision])
\begin{array}{l}
\\
-\sqrt[3]{\frac{g}{a}}
\end{array}
Initial program 38.6%
Taylor expanded in g around inf
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6421.3
Applied rewrites21.3%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
clear-numN/A
cbrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lower-cbrt.f64N/A
Applied rewrites21.3%
Taylor expanded in g around -inf
mul-1-negN/A
lower-neg.f64N/A
lower-cbrt.f64N/A
lower-/.f6472.5
Applied rewrites72.5%
(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 38.6%
lift-cbrt.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
lift-*.f64N/A
*-commutativeN/A
times-fracN/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
inv-powN/A
lower-pow.f64N/A
lower-cbrt.f64N/A
div-invN/A
metadata-evalN/A
Applied rewrites42.7%
Taylor expanded in g around -inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-cbrt.f64N/A
*-commutativeN/A
+-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
metadata-evalN/A
mul0-lftN/A
mul0-lftN/A
metadata-evalN/A
distribute-rgt1-inN/A
lower-cbrt.f64N/A
distribute-rgt1-inN/A
metadata-evalN/A
mul0-lftN/A
Applied rewrites2.9%
Applied rewrites2.9%
herbie shell --seed 2024296
(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))))))))