
(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
(let* ((t_0 (cbrt (/ 1.0 (pow x 2.0)))))
(/
(+
(* -0.1388888888888889 t_0)
(+ (* t_0 0.027777777777777776) (* 0.3333333333333333 (cbrt x))))
x)))
double code(double x) {
double t_0 = cbrt((1.0 / pow(x, 2.0)));
return ((-0.1388888888888889 * t_0) + ((t_0 * 0.027777777777777776) + (0.3333333333333333 * cbrt(x)))) / x;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 / Math.pow(x, 2.0)));
return ((-0.1388888888888889 * t_0) + ((t_0 * 0.027777777777777776) + (0.3333333333333333 * Math.cbrt(x)))) / x;
}
function code(x) t_0 = cbrt(Float64(1.0 / (x ^ 2.0))) return Float64(Float64(Float64(-0.1388888888888889 * t_0) + Float64(Float64(t_0 * 0.027777777777777776) + Float64(0.3333333333333333 * cbrt(x)))) / x) end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(N[(-0.1388888888888889 * t$95$0), $MachinePrecision] + N[(N[(t$95$0 * 0.027777777777777776), $MachinePrecision] + N[(0.3333333333333333 * N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{1}{{x}^{2}}}\\
\frac{-0.1388888888888889 \cdot t\_0 + \left(t\_0 \cdot 0.027777777777777776 + 0.3333333333333333 \cdot \sqrt[3]{x}\right)}{x}
\end{array}
\end{array}
Initial program 7.2%
add-sqr-sqrt6.8%
add-sqr-sqrt7.0%
difference-of-squares7.0%
pow1/37.0%
sqrt-pow17.0%
metadata-eval7.0%
pow1/37.0%
sqrt-pow17.0%
metadata-eval7.0%
pow1/34.7%
sqrt-pow14.7%
metadata-eval4.7%
pow1/37.1%
sqrt-pow17.1%
metadata-eval7.1%
Applied egg-rr7.1%
Taylor expanded in x around inf 97.8%
Final simplification97.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= x 1.35e+154)
(/
(+ 1.0 (- x x))
(+ (pow t_0 2.0) (+ (cbrt (pow x 2.0)) (cbrt (* x (+ 1.0 x))))))
(/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) 1.0)))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if (x <= 1.35e+154) {
tmp = (1.0 + (x - x)) / (pow(t_0, 2.0) + (cbrt(pow(x, 2.0)) + cbrt((x * (1.0 + x)))));
} else {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), 1.0);
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (x <= 1.35e+154) tmp = Float64(Float64(1.0 + Float64(x - x)) / Float64((t_0 ^ 2.0) + Float64(cbrt((x ^ 2.0)) + cbrt(Float64(x * Float64(1.0 + x)))))); else tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), 1.0)); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 1.35e+154], N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[(N[Power[N[Power[x, 2.0], $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1 + \left(x - x\right)}{{t\_0}^{2} + \left(\sqrt[3]{{x}^{2}} + \sqrt[3]{x \cdot \left(1 + x\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t\_0, 1\right)}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.8%
add-cbrt-cube9.8%
pow39.8%
Applied egg-rr9.8%
rem-cbrt-cube9.8%
flip3--9.9%
rem-cube-cbrt10.0%
rem-cube-cbrt13.7%
div-sub10.4%
Applied egg-rr10.4%
div-sub13.7%
associate--l+99.0%
*-commutative99.0%
Simplified99.0%
if 1.35000000000000003e154 < x Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.1%
rem-cube-cbrt4.8%
+-commutative4.8%
distribute-rgt-out4.8%
+-commutative4.8%
fma-define4.8%
add-exp-log4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+92.0%
+-inverses92.0%
metadata-eval92.0%
+-commutative92.0%
exp-prod91.0%
Simplified91.0%
add-sqr-sqrt91.0%
unpow-prod-down92.8%
Applied egg-rr92.8%
pow-sqr92.8%
Simplified92.8%
Taylor expanded in x around 0 19.9%
Final simplification57.9%
(FPCore (x)
:precision binary64
(if (<= x 1.35e+154)
(+
(* -0.1111111111111111 (cbrt (/ 1.0 (pow x 5.0))))
(* (cbrt (/ 1.0 (pow x 2.0))) 0.3333333333333333))
(/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) 1.0))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = (-0.1111111111111111 * cbrt((1.0 / pow(x, 5.0)))) + (cbrt((1.0 / pow(x, 2.0))) * 0.3333333333333333);
} else {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = Float64(Float64(-0.1111111111111111 * cbrt(Float64(1.0 / (x ^ 5.0)))) + Float64(cbrt(Float64(1.0 / (x ^ 2.0))) * 0.3333333333333333)); else tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), 1.0)); end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[(N[(-0.1111111111111111 * N[Power[N[(1.0 / N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[(N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;-0.1111111111111111 \cdot \sqrt[3]{\frac{1}{{x}^{5}}} + \sqrt[3]{\frac{1}{{x}^{2}}} \cdot 0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, 1\right)}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.8%
Taylor expanded in x around inf 46.8%
Taylor expanded in x around inf 96.3%
if 1.35000000000000003e154 < x Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.1%
rem-cube-cbrt4.8%
+-commutative4.8%
distribute-rgt-out4.8%
+-commutative4.8%
fma-define4.8%
add-exp-log4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+92.0%
+-inverses92.0%
metadata-eval92.0%
+-commutative92.0%
exp-prod91.0%
Simplified91.0%
add-sqr-sqrt91.0%
unpow-prod-down92.8%
Applied egg-rr92.8%
pow-sqr92.8%
Simplified92.8%
Taylor expanded in x around 0 19.9%
Final simplification56.6%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (cbrt (/ 0.037037037037037035 (pow x 2.0))) (/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) 1.0))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = cbrt((0.037037037037037035 / pow(x, 2.0)));
} else {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), 1.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = cbrt(Float64(0.037037037037037035 / (x ^ 2.0))); else tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), 1.0)); end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[Power[N[(0.037037037037037035 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.037037037037037035}{{x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, 1\right)}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.8%
add-cbrt-cube9.8%
pow39.8%
Applied egg-rr9.8%
Taylor expanded in x around inf 94.4%
if 1.35000000000000003e154 < x Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.1%
rem-cube-cbrt4.8%
+-commutative4.8%
distribute-rgt-out4.8%
+-commutative4.8%
fma-define4.8%
add-exp-log4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+92.0%
+-inverses92.0%
metadata-eval92.0%
+-commutative92.0%
exp-prod91.0%
Simplified91.0%
add-sqr-sqrt91.0%
unpow-prod-down92.8%
Applied egg-rr92.8%
pow-sqr92.8%
Simplified92.8%
Taylor expanded in x around 0 19.9%
Final simplification55.7%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (cbrt (/ 0.037037037037037035 (pow x 2.0))) (pow (* (cbrt x) (sqrt 2.0)) -2.0)))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = cbrt((0.037037037037037035 / pow(x, 2.0)));
} else {
tmp = pow((cbrt(x) * sqrt(2.0)), -2.0);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = Math.cbrt((0.037037037037037035 / Math.pow(x, 2.0)));
} else {
tmp = Math.pow((Math.cbrt(x) * Math.sqrt(2.0)), -2.0);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = cbrt(Float64(0.037037037037037035 / (x ^ 2.0))); else tmp = Float64(cbrt(x) * sqrt(2.0)) ^ -2.0; end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[Power[N[(0.037037037037037035 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[Power[N[(N[Power[x, 1/3], $MachinePrecision] * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], -2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.037037037037037035}{{x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt[3]{x} \cdot \sqrt{2}\right)}^{-2}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.8%
add-cbrt-cube9.8%
pow39.8%
Applied egg-rr9.8%
Taylor expanded in x around inf 94.4%
if 1.35000000000000003e154 < x Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.1%
rem-cube-cbrt4.8%
+-commutative4.8%
distribute-rgt-out4.8%
+-commutative4.8%
fma-define4.8%
add-exp-log4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+92.0%
+-inverses92.0%
metadata-eval92.0%
+-commutative92.0%
exp-prod91.0%
Simplified91.0%
inv-pow91.0%
add-sqr-sqrt91.0%
unpow-prod-down91.0%
+-commutative91.0%
+-commutative91.0%
Applied egg-rr91.0%
pow-sqr91.0%
metadata-eval91.0%
Simplified91.0%
Taylor expanded in x around inf 19.9%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (cbrt (/ 0.037037037037037035 (pow x 2.0))) (/ 1.0 (+ 1.0 (* (cbrt x) (+ 1.0 (cbrt x)))))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = cbrt((0.037037037037037035 / pow(x, 2.0)));
} else {
tmp = 1.0 / (1.0 + (cbrt(x) * (1.0 + cbrt(x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = Math.cbrt((0.037037037037037035 / Math.pow(x, 2.0)));
} else {
tmp = 1.0 / (1.0 + (Math.cbrt(x) * (1.0 + Math.cbrt(x))));
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = cbrt(Float64(0.037037037037037035 / (x ^ 2.0))); else tmp = Float64(1.0 / Float64(1.0 + Float64(cbrt(x) * Float64(1.0 + cbrt(x))))); end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[Power[N[(0.037037037037037035 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], N[(1.0 / N[(1.0 + N[(N[Power[x, 1/3], $MachinePrecision] * N[(1.0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\sqrt[3]{\frac{0.037037037037037035}{{x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + \sqrt[3]{x} \cdot \left(1 + \sqrt[3]{x}\right)}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 9.8%
add-cbrt-cube9.8%
pow39.8%
Applied egg-rr9.8%
Taylor expanded in x around inf 94.4%
if 1.35000000000000003e154 < x Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.1%
rem-cube-cbrt4.8%
+-commutative4.8%
distribute-rgt-out4.8%
+-commutative4.8%
fma-define4.8%
add-exp-log4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+92.0%
+-inverses92.0%
metadata-eval92.0%
+-commutative92.0%
exp-prod91.0%
Simplified91.0%
Taylor expanded in x around 0 17.7%
(FPCore (x) :precision binary64 (cbrt (/ 0.037037037037037035 (pow x 2.0))))
double code(double x) {
return cbrt((0.037037037037037035 / pow(x, 2.0)));
}
public static double code(double x) {
return Math.cbrt((0.037037037037037035 / Math.pow(x, 2.0)));
}
function code(x) return cbrt(Float64(0.037037037037037035 / (x ^ 2.0))) end
code[x_] := N[Power[N[(0.037037037037037035 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{0.037037037037037035}{{x}^{2}}}
\end{array}
Initial program 7.2%
add-cbrt-cube7.2%
pow37.2%
Applied egg-rr7.2%
Taylor expanded in x around inf 47.9%
(FPCore (x) :precision binary64 (cbrt x))
double code(double x) {
return cbrt(x);
}
public static double code(double x) {
return Math.cbrt(x);
}
function code(x) return cbrt(x) end
code[x_] := N[Power[x, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\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.2%
fabs-neg5.2%
unpow1/35.2%
metadata-eval5.2%
pow-sqr5.2%
fabs-sqr5.2%
pow-sqr5.2%
metadata-eval5.2%
unpow1/35.2%
Simplified5.2%
Taylor expanded in x around inf 5.2%
(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 2024145
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (cbrt (+ x 1)) (cbrt (+ x 1))) (* (cbrt x) (cbrt (+ x 1))) (* (cbrt x) (cbrt x)))))
(- (cbrt (+ x 1.0)) (cbrt x)))