
(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
(if (<= x 4e+15)
(/
1.0
(fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) (cbrt (pow (+ 1.0 x) 2.0))))
(/ (* (cbrt x) 0.3333333333333333) x)))
double code(double x) {
double tmp;
if (x <= 4e+15) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), cbrt(pow((1.0 + x), 2.0)));
} else {
tmp = (cbrt(x) * 0.3333333333333333) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 4e+15) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), cbrt((Float64(1.0 + x) ^ 2.0)))); else tmp = Float64(Float64(cbrt(x) * 0.3333333333333333) / x); end return tmp end
code[x_] := If[LessEqual[x, 4e+15], 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] + N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{+15}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{x} \cdot 0.3333333333333333}{x}\\
\end{array}
\end{array}
if x < 4e15Initial program 56.2%
flip3--61.4%
div-inv61.4%
rem-cube-cbrt60.8%
rem-cube-cbrt98.7%
+-commutative98.7%
distribute-rgt-out98.6%
+-commutative98.6%
fma-define98.6%
add-exp-log98.4%
Applied egg-rr98.1%
associate-*r/98.1%
*-rgt-identity98.1%
+-commutative98.1%
associate--l+98.1%
+-inverses98.1%
metadata-eval98.1%
+-commutative98.1%
exp-prod97.9%
Simplified97.9%
add-sqr-sqrt97.9%
unpow-prod-down98.8%
Applied egg-rr98.8%
pow-sqr98.8%
Simplified98.8%
sqr-pow98.8%
pow298.8%
pow-to-exp98.3%
*-commutative98.3%
associate-/l*98.3%
metadata-eval98.3%
*-commutative98.3%
*-un-lft-identity98.3%
pow1/298.3%
log-pow98.3%
rem-log-exp98.3%
metadata-eval98.3%
log1p-undefine98.3%
+-commutative98.3%
log-pow98.8%
pow1/398.6%
add-exp-log98.6%
pow298.6%
Applied egg-rr98.8%
if 4e15 < x Initial program 4.1%
Taylor expanded in x around inf 26.4%
+-commutative26.4%
fma-define26.4%
Simplified26.4%
frac-2neg26.4%
div-inv26.4%
*-commutative26.4%
Applied egg-rr26.4%
un-div-inv26.4%
add-sqr-sqrt0.0%
associate-/r*0.0%
Applied egg-rr77.6%
Taylor expanded in x around inf 99.1%
Final simplification99.0%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) (pow t_0 2.0)))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return 1.0 / fma(cbrt(x), (cbrt(x) + t_0), pow(t_0, 2.0));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), (t_0 ^ 2.0))) end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t\_0, {t\_0}^{2}\right)}
\end{array}
\end{array}
Initial program 6.8%
flip3--7.0%
div-inv7.0%
rem-cube-cbrt6.7%
rem-cube-cbrt9.3%
+-commutative9.3%
distribute-rgt-out9.3%
+-commutative9.3%
fma-define9.3%
add-exp-log9.3%
Applied egg-rr9.3%
associate-*r/9.3%
*-rgt-identity9.3%
+-commutative9.3%
associate--l+93.7%
+-inverses93.7%
metadata-eval93.7%
+-commutative93.7%
exp-prod92.6%
Simplified92.6%
add-sqr-sqrt92.6%
unpow-prod-down94.3%
Applied egg-rr94.3%
pow-sqr94.3%
Simplified94.3%
sqr-pow94.3%
pow294.3%
pow-to-exp93.7%
*-commutative93.7%
associate-/l*93.7%
metadata-eval93.7%
*-commutative93.7%
*-un-lft-identity93.7%
pow1/293.7%
log-pow93.7%
rem-log-exp93.7%
metadata-eval93.7%
log1p-undefine93.7%
+-commutative93.7%
log-pow93.9%
pow1/394.5%
add-exp-log98.5%
pow298.5%
Applied egg-rr98.5%
pow298.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= x 9.6e+14)
(/ (- (+ 1.0 x) x) (+ (pow t_0 2.0) (* (cbrt x) (+ (cbrt x) t_0))))
(/ (* (cbrt x) 0.3333333333333333) x))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if (x <= 9.6e+14) {
tmp = ((1.0 + x) - x) / (pow(t_0, 2.0) + (cbrt(x) * (cbrt(x) + t_0)));
} else {
tmp = (cbrt(x) * 0.3333333333333333) / x;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
double tmp;
if (x <= 9.6e+14) {
tmp = ((1.0 + x) - x) / (Math.pow(t_0, 2.0) + (Math.cbrt(x) * (Math.cbrt(x) + t_0)));
} else {
tmp = (Math.cbrt(x) * 0.3333333333333333) / x;
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (x <= 9.6e+14) tmp = Float64(Float64(Float64(1.0 + x) - x) / Float64((t_0 ^ 2.0) + Float64(cbrt(x) * Float64(cbrt(x) + t_0)))); else tmp = Float64(Float64(cbrt(x) * 0.3333333333333333) / x); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 9.6e+14], N[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] / x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;x \leq 9.6 \cdot 10^{+14}:\\
\;\;\;\;\frac{\left(1 + x\right) - x}{{t\_0}^{2} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{x} \cdot 0.3333333333333333}{x}\\
\end{array}
\end{array}
if x < 9.6e14Initial program 60.6%
pow1/359.1%
pow-to-exp58.3%
Applied egg-rr58.3%
exp-to-pow59.1%
pow1/360.6%
flip3--66.3%
rem-cube-cbrt65.7%
rem-cube-cbrt98.8%
pow298.8%
distribute-rgt-out98.7%
+-commutative98.7%
Applied egg-rr98.7%
if 9.6e14 < x Initial program 4.1%
Taylor expanded in x around inf 26.7%
+-commutative26.7%
fma-define26.7%
Simplified26.7%
frac-2neg26.7%
div-inv26.7%
*-commutative26.7%
Applied egg-rr26.7%
un-div-inv26.7%
add-sqr-sqrt0.0%
associate-/r*0.0%
Applied egg-rr77.7%
Taylor expanded in x around inf 99.0%
Final simplification99.0%
(FPCore (x)
:precision binary64
(if (<= x 2.4e+15)
(/
1.0
(fma
(cbrt x)
(+ (cbrt x) (cbrt (+ 1.0 x)))
(pow (+ 1.0 x) 0.6666666666666666)))
(/ (* (cbrt x) 0.3333333333333333) x)))
double code(double x) {
double tmp;
if (x <= 2.4e+15) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), pow((1.0 + x), 0.6666666666666666));
} else {
tmp = (cbrt(x) * 0.3333333333333333) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 2.4e+15) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), (Float64(1.0 + x) ^ 0.6666666666666666))); else tmp = Float64(Float64(cbrt(x) * 0.3333333333333333) / x); end return tmp end
code[x_] := If[LessEqual[x, 2.4e+15], 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] + N[Power[N[(1.0 + x), $MachinePrecision], 0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.4 \cdot 10^{+15}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{x} \cdot 0.3333333333333333}{x}\\
\end{array}
\end{array}
if x < 2.4e15Initial program 56.2%
flip3--61.4%
div-inv61.4%
rem-cube-cbrt60.8%
rem-cube-cbrt98.7%
+-commutative98.7%
distribute-rgt-out98.6%
+-commutative98.6%
fma-define98.6%
add-exp-log98.4%
Applied egg-rr98.1%
associate-*r/98.1%
*-rgt-identity98.1%
+-commutative98.1%
associate--l+98.1%
+-inverses98.1%
metadata-eval98.1%
+-commutative98.1%
exp-prod97.9%
Simplified97.9%
add-sqr-sqrt97.9%
unpow-prod-down98.8%
Applied egg-rr98.8%
pow-sqr98.8%
Simplified98.8%
sqr-pow98.8%
pow298.8%
pow-to-exp98.3%
*-commutative98.3%
associate-/l*98.3%
metadata-eval98.3%
*-commutative98.3%
*-un-lft-identity98.3%
pow1/298.3%
log-pow98.3%
rem-log-exp98.3%
metadata-eval98.3%
log1p-undefine98.3%
+-commutative98.3%
log-pow98.8%
pow1/398.6%
add-exp-log98.6%
pow298.6%
Applied egg-rr98.6%
pow298.6%
pow1/398.5%
pow-pow98.5%
metadata-eval98.5%
Applied egg-rr98.5%
if 2.4e15 < x Initial program 4.1%
Taylor expanded in x around inf 26.4%
+-commutative26.4%
fma-define26.4%
Simplified26.4%
frac-2neg26.4%
div-inv26.4%
*-commutative26.4%
Applied egg-rr26.4%
un-div-inv26.4%
add-sqr-sqrt0.0%
associate-/r*0.0%
Applied egg-rr77.6%
Taylor expanded in x around inf 99.1%
Final simplification99.0%
(FPCore (x) :precision binary64 (/ (* x (- (/ 0.3333333333333333 x) (/ 0.1111111111111111 (pow x 2.0)))) (pow (cbrt x) 2.0)))
double code(double x) {
return (x * ((0.3333333333333333 / x) - (0.1111111111111111 / pow(x, 2.0)))) / pow(cbrt(x), 2.0);
}
public static double code(double x) {
return (x * ((0.3333333333333333 / x) - (0.1111111111111111 / Math.pow(x, 2.0)))) / Math.pow(Math.cbrt(x), 2.0);
}
function code(x) return Float64(Float64(x * Float64(Float64(0.3333333333333333 / x) - Float64(0.1111111111111111 / (x ^ 2.0)))) / (cbrt(x) ^ 2.0)) end
code[x_] := N[(N[(x * N[(N[(0.3333333333333333 / x), $MachinePrecision] - N[(0.1111111111111111 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \left(\frac{0.3333333333333333}{x} - \frac{0.1111111111111111}{{x}^{2}}\right)}{{\left(\sqrt[3]{x}\right)}^{2}}
\end{array}
Initial program 6.8%
Taylor expanded in x around inf 29.1%
+-commutative29.1%
fma-define29.1%
Simplified29.1%
*-un-lft-identity29.1%
add-cbrt-cube18.3%
pow-sqr18.3%
metadata-eval18.3%
cbrt-prod28.3%
unpow228.3%
cbrt-prod28.2%
times-frac28.1%
*-commutative28.1%
pow228.1%
Applied egg-rr28.1%
associate-*r/28.2%
Simplified77.7%
Taylor expanded in x around inf 97.3%
associate-*r/97.4%
metadata-eval97.4%
associate-*r/97.4%
metadata-eval97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (x) :precision binary64 (/ (+ 0.3333333333333333 (* x (* -0.1111111111111111 (pow x -2.0)))) (pow (cbrt x) 2.0)))
double code(double x) {
return (0.3333333333333333 + (x * (-0.1111111111111111 * pow(x, -2.0)))) / pow(cbrt(x), 2.0);
}
public static double code(double x) {
return (0.3333333333333333 + (x * (-0.1111111111111111 * Math.pow(x, -2.0)))) / Math.pow(Math.cbrt(x), 2.0);
}
function code(x) return Float64(Float64(0.3333333333333333 + Float64(x * Float64(-0.1111111111111111 * (x ^ -2.0)))) / (cbrt(x) ^ 2.0)) end
code[x_] := N[(N[(0.3333333333333333 + N[(x * N[(-0.1111111111111111 * N[Power[x, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{0.3333333333333333 + x \cdot \left(-0.1111111111111111 \cdot {x}^{-2}\right)}{{\left(\sqrt[3]{x}\right)}^{2}}
\end{array}
Initial program 6.8%
Taylor expanded in x around inf 29.1%
+-commutative29.1%
fma-define29.1%
Simplified29.1%
*-un-lft-identity29.1%
add-cbrt-cube18.3%
pow-sqr18.3%
metadata-eval18.3%
cbrt-prod28.3%
unpow228.3%
cbrt-prod28.2%
times-frac28.1%
*-commutative28.1%
pow228.1%
Applied egg-rr28.1%
associate-*r/28.2%
Simplified77.7%
Taylor expanded in x around inf 97.3%
sub-neg97.3%
distribute-lft-in97.3%
*-commutative97.3%
associate-*r*97.3%
rgt-mult-inverse97.4%
metadata-eval97.4%
distribute-lft-neg-in97.4%
metadata-eval97.4%
unpow297.4%
associate-/r*97.4%
*-rgt-identity97.4%
associate-*r/97.4%
unpow-197.4%
unpow-197.4%
pow-sqr97.4%
metadata-eval97.4%
Simplified97.4%
Final simplification97.4%
(FPCore (x) :precision binary64 (/ (* (cbrt x) 0.3333333333333333) x))
double code(double x) {
return (cbrt(x) * 0.3333333333333333) / x;
}
public static double code(double x) {
return (Math.cbrt(x) * 0.3333333333333333) / x;
}
function code(x) return Float64(Float64(cbrt(x) * 0.3333333333333333) / x) end
code[x_] := N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x} \cdot 0.3333333333333333}{x}
\end{array}
Initial program 6.8%
Taylor expanded in x around inf 29.1%
+-commutative29.1%
fma-define29.1%
Simplified29.1%
frac-2neg29.1%
div-inv29.0%
*-commutative29.0%
Applied egg-rr29.0%
un-div-inv29.1%
add-sqr-sqrt0.0%
associate-/r*0.0%
Applied egg-rr77.6%
Taylor expanded in x around inf 97.1%
Final simplification97.1%
(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 6.8%
Taylor expanded in x around 0 1.8%
sub-neg1.8%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt5.5%
fabs-neg5.5%
unpow1/35.5%
metadata-eval5.5%
pow-sqr5.5%
fabs-sqr5.5%
pow-sqr5.5%
metadata-eval5.5%
unpow1/35.5%
Simplified5.5%
Final simplification5.5%
(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 2024060
(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)))