
(FPCore (x) :precision binary64 (- (cbrt (+ x 1.0)) (cbrt x)))
double code(double x) {
return cbrt((x + 1.0)) - cbrt(x);
}
public static double code(double x) {
return Math.cbrt((x + 1.0)) - Math.cbrt(x);
}
function code(x) return Float64(cbrt(Float64(x + 1.0)) - cbrt(x)) end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{x + 1} - \sqrt[3]{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (cbrt (+ x 1.0)) (cbrt x)))
double code(double x) {
return cbrt((x + 1.0)) - cbrt(x);
}
public static double code(double x) {
return Math.cbrt((x + 1.0)) - Math.cbrt(x);
}
function code(x) return Float64(cbrt(Float64(x + 1.0)) - cbrt(x)) end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{x + 1} - \sqrt[3]{x}
\end{array}
(FPCore (x) :precision binary64 (+ (* -0.1111111111111111 (cbrt (/ 1.0 (pow x 5.0)))) (/ (/ 0.3333333333333333 (cbrt x)) (cbrt x))))
double code(double x) {
return (-0.1111111111111111 * cbrt((1.0 / pow(x, 5.0)))) + ((0.3333333333333333 / cbrt(x)) / cbrt(x));
}
public static double code(double x) {
return (-0.1111111111111111 * Math.cbrt((1.0 / Math.pow(x, 5.0)))) + ((0.3333333333333333 / Math.cbrt(x)) / Math.cbrt(x));
}
function code(x) return Float64(Float64(-0.1111111111111111 * cbrt(Float64(1.0 / (x ^ 5.0)))) + Float64(Float64(0.3333333333333333 / cbrt(x)) / cbrt(x))) end
code[x_] := N[(N[(-0.1111111111111111 * N[Power[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[(0.3333333333333333 / N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] / N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{x}^{5}}} + \frac{\frac{0.3333333333333333}{\sqrt[3]{x}}}{\sqrt[3]{x}}
\end{array}
Initial program 7.2%
Taylor expanded in x around inf 24.9%
Taylor expanded in x around inf 52.6%
cbrt-div52.8%
metadata-eval52.8%
unpow252.8%
cbrt-prod97.1%
add-sqr-sqrt97.1%
sqrt-div97.1%
metadata-eval97.1%
sqrt-unprod97.0%
add-sqr-sqrt97.1%
sqrt-div97.0%
metadata-eval97.0%
sqrt-unprod96.9%
add-sqr-sqrt97.0%
Applied egg-rr97.0%
associate-*l/97.1%
*-lft-identity97.1%
associate-/r*97.1%
unpow297.1%
Simplified97.1%
un-div-inv97.1%
unpow297.1%
associate-/r*97.1%
Applied egg-rr97.1%
(FPCore (x) :precision binary64 (+ (* -0.1111111111111111 (cbrt (/ 1.0 (pow x 5.0)))) (* 0.3333333333333333 (pow (cbrt x) -2.0))))
double code(double x) {
return (-0.1111111111111111 * cbrt((1.0 / pow(x, 5.0)))) + (0.3333333333333333 * pow(cbrt(x), -2.0));
}
public static double code(double x) {
return (-0.1111111111111111 * Math.cbrt((1.0 / Math.pow(x, 5.0)))) + (0.3333333333333333 * Math.pow(Math.cbrt(x), -2.0));
}
function code(x) return Float64(Float64(-0.1111111111111111 * cbrt(Float64(1.0 / (x ^ 5.0)))) + Float64(0.3333333333333333 * (cbrt(x) ^ -2.0))) end
code[x_] := N[(N[(-0.1111111111111111 * N[Power[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{x}^{5}}} + 0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}
\end{array}
Initial program 7.2%
Taylor expanded in x around inf 24.9%
Taylor expanded in x around inf 52.6%
cbrt-div52.8%
metadata-eval52.8%
unpow252.8%
cbrt-prod97.1%
add-sqr-sqrt97.1%
sqrt-div97.1%
metadata-eval97.1%
sqrt-unprod97.0%
add-sqr-sqrt97.1%
sqrt-div97.0%
metadata-eval97.0%
sqrt-unprod96.9%
add-sqr-sqrt97.0%
Applied egg-rr97.0%
associate-*l/97.1%
*-lft-identity97.1%
associate-/r*97.1%
unpow297.1%
Simplified97.1%
un-div-inv97.1%
Applied egg-rr97.1%
metadata-eval97.1%
associate-*l/97.1%
unpow-197.1%
*-commutative97.1%
exp-to-pow90.8%
*-commutative90.8%
exp-prod90.8%
*-commutative90.8%
associate-*r*90.8%
metadata-eval90.8%
*-commutative90.8%
exp-to-pow97.1%
Simplified97.1%
(FPCore (x)
:precision binary64
(if (<= x 1.35e+154)
(+
(* -0.1111111111111111 (pow x -1.6666666666666667))
(* 0.3333333333333333 (cbrt (/ 1.0 (pow x 2.0)))))
(+
(* -0.1111111111111111 (cbrt (/ 1.0 (pow x 5.0))))
(* 0.3333333333333333 (pow x -0.6666666666666666)))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = (-0.1111111111111111 * pow(x, -1.6666666666666667)) + (0.3333333333333333 * cbrt((1.0 / pow(x, 2.0))));
} else {
tmp = (-0.1111111111111111 * cbrt((1.0 / pow(x, 5.0)))) + (0.3333333333333333 * pow(x, -0.6666666666666666));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = (-0.1111111111111111 * Math.pow(x, -1.6666666666666667)) + (0.3333333333333333 * Math.cbrt((1.0 / Math.pow(x, 2.0))));
} else {
tmp = (-0.1111111111111111 * Math.cbrt((1.0 / Math.pow(x, 5.0)))) + (0.3333333333333333 * Math.pow(x, -0.6666666666666666));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = Float64(Float64(-0.1111111111111111 * (x ^ -1.6666666666666667)) + Float64(0.3333333333333333 * cbrt(Float64(1.0 / (x ^ 2.0))))); else tmp = Float64(Float64(-0.1111111111111111 * cbrt(Float64(1.0 / (x ^ 5.0)))) + Float64(0.3333333333333333 * (x ^ -0.6666666666666666))); end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[(N[(-0.1111111111111111 * N[Power[x, -1.6666666666666667], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.1111111111111111 * N[Power[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;-0.1111111111111111 \cdot {x}^{-1.6666666666666667} + 0.3333333333333333 \cdot \sqrt[3]{\frac{1}{{x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{x}^{5}}} + 0.3333333333333333 \cdot {x}^{-0.6666666666666666}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.5%
Taylor expanded in x around inf 47.5%
Taylor expanded in x around inf 96.3%
pow1/395.9%
pow-flip95.9%
pow-pow95.9%
metadata-eval95.9%
metadata-eval95.9%
Applied egg-rr96.3%
if 1.35000000000000003e154 < x Initial program 4.8%
Taylor expanded in x around inf 0.0%
Taylor expanded in x around inf 4.8%
pow1/34.8%
pow-flip6.2%
pow-pow89.1%
metadata-eval89.1%
metadata-eval89.1%
Applied egg-rr89.1%
(FPCore (x)
:precision binary64
(if (<= x 3.55e+155)
(+
(* -0.1111111111111111 (pow x -1.6666666666666667))
(* 0.3333333333333333 (cbrt (* (/ 1.0 x) (/ 1.0 x)))))
(+
(* -0.1111111111111111 (cbrt (/ 1.0 (pow x 5.0))))
(* 0.3333333333333333 (pow x -0.6666666666666666)))))
double code(double x) {
double tmp;
if (x <= 3.55e+155) {
tmp = (-0.1111111111111111 * pow(x, -1.6666666666666667)) + (0.3333333333333333 * cbrt(((1.0 / x) * (1.0 / x))));
} else {
tmp = (-0.1111111111111111 * cbrt((1.0 / pow(x, 5.0)))) + (0.3333333333333333 * pow(x, -0.6666666666666666));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 3.55e+155) {
tmp = (-0.1111111111111111 * Math.pow(x, -1.6666666666666667)) + (0.3333333333333333 * Math.cbrt(((1.0 / x) * (1.0 / x))));
} else {
tmp = (-0.1111111111111111 * Math.cbrt((1.0 / Math.pow(x, 5.0)))) + (0.3333333333333333 * Math.pow(x, -0.6666666666666666));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 3.55e+155) tmp = Float64(Float64(-0.1111111111111111 * (x ^ -1.6666666666666667)) + Float64(0.3333333333333333 * cbrt(Float64(Float64(1.0 / x) * Float64(1.0 / x))))); else tmp = Float64(Float64(-0.1111111111111111 * cbrt(Float64(1.0 / (x ^ 5.0)))) + Float64(0.3333333333333333 * (x ^ -0.6666666666666666))); end return tmp end
code[x_] := If[LessEqual[x, 3.55e+155], N[(N[(-0.1111111111111111 * N[Power[x, -1.6666666666666667], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-0.1111111111111111 * N[Power[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.55 \cdot 10^{+155}:\\
\;\;\;\;-0.1111111111111111 \cdot {x}^{-1.6666666666666667} + 0.3333333333333333 \cdot \sqrt[3]{\frac{1}{x} \cdot \frac{1}{x}}\\
\mathbf{else}:\\
\;\;\;\;-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{x}^{5}}} + 0.3333333333333333 \cdot {x}^{-0.6666666666666666}\\
\end{array}
\end{array}
if x < 3.54999999999999996e155Initial program 9.5%
Taylor expanded in x around inf 47.5%
Taylor expanded in x around inf 96.3%
add-sqr-sqrt96.2%
sqrt-div96.2%
metadata-eval96.2%
sqrt-pow196.2%
metadata-eval96.2%
pow196.2%
sqrt-div96.2%
metadata-eval96.2%
sqrt-pow196.2%
metadata-eval96.2%
pow196.2%
Applied egg-rr96.2%
pow1/395.9%
pow-flip95.9%
pow-pow95.9%
metadata-eval95.9%
metadata-eval95.9%
Applied egg-rr96.2%
if 3.54999999999999996e155 < x Initial program 4.8%
Taylor expanded in x around inf 0.0%
Taylor expanded in x around inf 4.8%
pow1/34.8%
pow-flip6.2%
pow-pow89.1%
metadata-eval89.1%
metadata-eval89.1%
Applied egg-rr89.1%
(FPCore (x) :precision binary64 (+ (* -0.1111111111111111 (pow x -1.6666666666666667)) (* 0.3333333333333333 (/ 1.0 (pow (cbrt x) 2.0)))))
double code(double x) {
return (-0.1111111111111111 * pow(x, -1.6666666666666667)) + (0.3333333333333333 * (1.0 / pow(cbrt(x), 2.0)));
}
public static double code(double x) {
return (-0.1111111111111111 * Math.pow(x, -1.6666666666666667)) + (0.3333333333333333 * (1.0 / Math.pow(Math.cbrt(x), 2.0)));
}
function code(x) return Float64(Float64(-0.1111111111111111 * (x ^ -1.6666666666666667)) + Float64(0.3333333333333333 * Float64(1.0 / (cbrt(x) ^ 2.0)))) end
code[x_] := N[(N[(-0.1111111111111111 * N[Power[x, -1.6666666666666667], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[(1.0 / N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.1111111111111111 \cdot {x}^{-1.6666666666666667} + 0.3333333333333333 \cdot \frac{1}{{\left(\sqrt[3]{x}\right)}^{2}}
\end{array}
Initial program 7.2%
Taylor expanded in x around inf 24.9%
Taylor expanded in x around inf 52.6%
cbrt-div52.8%
metadata-eval52.8%
unpow252.8%
cbrt-prod97.1%
add-sqr-sqrt97.1%
sqrt-div97.1%
metadata-eval97.1%
sqrt-unprod97.0%
add-sqr-sqrt97.1%
sqrt-div97.0%
metadata-eval97.0%
sqrt-unprod96.9%
add-sqr-sqrt97.0%
Applied egg-rr97.0%
associate-*l/97.1%
*-lft-identity97.1%
associate-/r*97.1%
unpow297.1%
Simplified97.1%
pow1/397.1%
pow-flip97.1%
pow-pow97.1%
metadata-eval97.1%
metadata-eval97.1%
Applied egg-rr97.1%
(FPCore (x) :precision binary64 (+ (* -0.1111111111111111 (pow x -1.6666666666666667)) (* 0.3333333333333333 (cbrt (* (/ 1.0 x) (/ 1.0 x))))))
double code(double x) {
return (-0.1111111111111111 * pow(x, -1.6666666666666667)) + (0.3333333333333333 * cbrt(((1.0 / x) * (1.0 / x))));
}
public static double code(double x) {
return (-0.1111111111111111 * Math.pow(x, -1.6666666666666667)) + (0.3333333333333333 * Math.cbrt(((1.0 / x) * (1.0 / x))));
}
function code(x) return Float64(Float64(-0.1111111111111111 * (x ^ -1.6666666666666667)) + Float64(0.3333333333333333 * cbrt(Float64(Float64(1.0 / x) * Float64(1.0 / x))))) end
code[x_] := N[(N[(-0.1111111111111111 * N[Power[x, -1.6666666666666667], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 * N[Power[N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-0.1111111111111111 \cdot {x}^{-1.6666666666666667} + 0.3333333333333333 \cdot \sqrt[3]{\frac{1}{x} \cdot \frac{1}{x}}
\end{array}
Initial program 7.2%
Taylor expanded in x around inf 24.9%
Taylor expanded in x around inf 52.6%
add-sqr-sqrt52.6%
sqrt-div52.6%
metadata-eval52.6%
sqrt-pow152.6%
metadata-eval52.6%
pow152.6%
sqrt-div52.6%
metadata-eval52.6%
sqrt-pow153.3%
metadata-eval53.3%
pow153.3%
Applied egg-rr53.3%
pow1/397.1%
pow-flip97.1%
pow-pow97.1%
metadata-eval97.1%
metadata-eval97.1%
Applied egg-rr53.3%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (cbrt (pow x -2.0))))
double code(double x) {
return 0.3333333333333333 * cbrt(pow(x, -2.0));
}
public static double code(double x) {
return 0.3333333333333333 * Math.cbrt(Math.pow(x, -2.0));
}
function code(x) return Float64(0.3333333333333333 * cbrt((x ^ -2.0))) end
code[x_] := N[(0.3333333333333333 * N[Power[N[Power[x, -2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \sqrt[3]{{x}^{-2}}
\end{array}
Initial program 7.2%
Taylor expanded in x around inf 24.9%
pow1/323.2%
pow-pow47.3%
metadata-eval47.3%
Applied egg-rr47.3%
Taylor expanded in x around inf 51.8%
exp-to-pow49.1%
*-commutative49.1%
rec-exp49.8%
*-commutative49.8%
distribute-rgt-neg-in49.8%
metadata-eval49.8%
exp-to-pow52.5%
Simplified52.5%
(FPCore (x) :precision binary64 (+ 1.0 (cbrt x)))
double code(double x) {
return 1.0 + cbrt(x);
}
public static double code(double x) {
return 1.0 + Math.cbrt(x);
}
function code(x) return Float64(1.0 + cbrt(x)) end
code[x_] := N[(1.0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \sqrt[3]{x}
\end{array}
Initial program 7.2%
Taylor expanded in x around 0 1.8%
sub-neg1.8%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt5.4%
fabs-neg5.4%
unpow1/35.4%
metadata-eval5.4%
pow-sqr5.4%
fabs-sqr5.4%
pow-sqr5.4%
metadata-eval5.4%
unpow1/35.4%
Simplified5.4%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ x 1.0)))) (/ 1.0 (+ (+ (* t_0 t_0) (* (cbrt x) t_0)) (* (cbrt x) (cbrt x))))))
double code(double x) {
double t_0 = cbrt((x + 1.0));
return 1.0 / (((t_0 * t_0) + (cbrt(x) * t_0)) + (cbrt(x) * cbrt(x)));
}
public static double code(double x) {
double t_0 = Math.cbrt((x + 1.0));
return 1.0 / (((t_0 * t_0) + (Math.cbrt(x) * t_0)) + (Math.cbrt(x) * Math.cbrt(x)));
}
function code(x) t_0 = cbrt(Float64(x + 1.0)) return Float64(1.0 / Float64(Float64(Float64(t_0 * t_0) + Float64(cbrt(x) * t_0)) + Float64(cbrt(x) * cbrt(x)))) end
code[x_] := Block[{t$95$0 = N[Power[N[(x + 1.0), $MachinePrecision], 1/3], $MachinePrecision]}, N[(1.0 / N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{x + 1}\\
\frac{1}{\left(t\_0 \cdot t\_0 + \sqrt[3]{x} \cdot t\_0\right) + \sqrt[3]{x} \cdot \sqrt[3]{x}}
\end{array}
\end{array}
herbie shell --seed 2024093
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(/ 1.0 (+ (+ (* (cbrt (+ x 1.0)) (cbrt (+ x 1.0))) (* (cbrt x) (cbrt (+ x 1.0)))) (* (cbrt x) (cbrt x))))
(- (cbrt (+ x 1.0)) (cbrt x)))