
(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 9 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 x))))
(*
(+ 1.0 (- x x))
(/ 1.0 (+ (pow t_0 2.0) (* (cbrt x) (+ t_0 (cbrt x))))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return (1.0 + (x - x)) * (1.0 / (pow(t_0, 2.0) + (cbrt(x) * (t_0 + cbrt(x)))));
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
return (1.0 + (x - x)) * (1.0 / (Math.pow(t_0, 2.0) + (Math.cbrt(x) * (t_0 + Math.cbrt(x)))));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(Float64(1.0 + Float64(x - x)) * Float64(1.0 / Float64((t_0 ^ 2.0) + Float64(cbrt(x) * Float64(t_0 + cbrt(x)))))) end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\left(1 + \left(x - x\right)\right) \cdot \frac{1}{{t_0}^{2} + \sqrt[3]{x} \cdot \left(t_0 + \sqrt[3]{x}\right)}
\end{array}
\end{array}
Initial program 55.8%
add-exp-log53.7%
pow1/353.5%
log-pow53.5%
+-commutative53.5%
log1p-udef53.5%
Applied egg-rr53.5%
*-commutative53.5%
exp-prod53.4%
unpow1/353.8%
Simplified53.8%
pow1/326.2%
Applied egg-rr26.2%
pow1/353.8%
flip3--53.7%
div-inv53.7%
rem-cube-cbrt53.7%
log1p-udef53.7%
add-exp-log53.5%
rem-cube-cbrt54.0%
pow254.0%
log1p-udef54.0%
add-exp-log54.0%
distribute-rgt-out54.0%
Applied egg-rr56.1%
associate--l+99.2%
+-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 0.0)
(/ 1.0 (fma (cbrt x) (+ t_0 (cbrt x)) (cbrt (* x x))))
(log (* (exp (- (cbrt x))) (exp t_0))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((t_0 - cbrt(x)) <= 0.0) {
tmp = 1.0 / fma(cbrt(x), (t_0 + cbrt(x)), cbrt((x * x)));
} else {
tmp = log((exp(-cbrt(x)) * exp(t_0)));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - cbrt(x)) <= 0.0) tmp = Float64(1.0 / fma(cbrt(x), Float64(t_0 + cbrt(x)), cbrt(Float64(x * x)))); else tmp = log(Float64(exp(Float64(-cbrt(x))) * exp(t_0))); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(x * x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[(-N[Power[x, 1/3], $MachinePrecision])], $MachinePrecision] * N[Exp[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;t_0 - \sqrt[3]{x} \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0 + \sqrt[3]{x}, \sqrt[3]{x \cdot x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{-\sqrt[3]{x}} \cdot e^{t_0}\right)\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
flip3--4.2%
div-inv4.2%
rem-cube-cbrt3.8%
rem-cube-cbrt4.2%
cbrt-unprod4.2%
pow24.2%
distribute-rgt-out4.2%
+-commutative4.2%
Applied egg-rr4.2%
associate-*r/4.2%
*-rgt-identity4.2%
+-commutative4.2%
associate--l+47.5%
+-inverses47.5%
metadata-eval47.5%
+-commutative47.5%
fma-def47.5%
+-commutative47.5%
+-commutative47.5%
Simplified47.5%
pow1/345.3%
pow-pow42.7%
metadata-eval42.7%
Applied egg-rr42.7%
Taylor expanded in x around inf 45.3%
unpow245.3%
unpow1/347.5%
Simplified47.5%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.1%
add-exp-log97.5%
pow1/397.5%
log-pow97.5%
+-commutative97.5%
log1p-udef97.5%
Applied egg-rr97.5%
*-commutative97.5%
exp-prod97.5%
unpow1/397.5%
Simplified97.5%
pow1/346.4%
Applied egg-rr46.4%
pow1/397.5%
sub-neg97.5%
+-commutative97.5%
add-log-exp97.5%
add-log-exp97.5%
sum-log97.5%
log1p-udef97.5%
add-exp-log99.2%
Applied egg-rr99.2%
Final simplification75.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (cbrt (+ 1.0 x)) (cbrt x))))
(if (<= x -1.35e+154)
(/ 1.0 (fma (cbrt x) t_0 1.0))
(if (<= x -1.0)
(/ 1.0 (fma (cbrt x) t_0 (cbrt (* x x))))
(/ 1.0 (fma (cbrt x) t_0 (pow (+ 1.0 x) 0.6666666666666666)))))))
double code(double x) {
double t_0 = cbrt((1.0 + x)) + cbrt(x);
double tmp;
if (x <= -1.35e+154) {
tmp = 1.0 / fma(cbrt(x), t_0, 1.0);
} else if (x <= -1.0) {
tmp = 1.0 / fma(cbrt(x), t_0, cbrt((x * x)));
} else {
tmp = 1.0 / fma(cbrt(x), t_0, pow((1.0 + x), 0.6666666666666666));
}
return tmp;
}
function code(x) t_0 = Float64(cbrt(Float64(1.0 + x)) + cbrt(x)) tmp = 0.0 if (x <= -1.35e+154) tmp = Float64(1.0 / fma(cbrt(x), t_0, 1.0)); elseif (x <= -1.0) tmp = Float64(1.0 / fma(cbrt(x), t_0, cbrt(Float64(x * x)))); else tmp = Float64(1.0 / fma(cbrt(x), t_0, (Float64(1.0 + x) ^ 0.6666666666666666))); end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.35e+154], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + N[Power[N[(x * x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + N[Power[N[(1.0 + x), $MachinePrecision], 0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} + \sqrt[3]{x}\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, 1\right)}\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, \sqrt[3]{x \cdot x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\
\end{array}
\end{array}
if x < -1.35000000000000003e154Initial program 4.8%
flip3--4.8%
div-inv4.8%
rem-cube-cbrt3.7%
rem-cube-cbrt4.8%
cbrt-unprod4.8%
pow24.8%
distribute-rgt-out4.8%
+-commutative4.8%
Applied egg-rr4.8%
associate-*r/4.8%
*-rgt-identity4.8%
+-commutative4.8%
associate--l+4.8%
+-inverses4.8%
metadata-eval4.8%
+-commutative4.8%
fma-def4.8%
+-commutative4.8%
+-commutative4.8%
Simplified4.8%
Taylor expanded in x around 0 20.0%
if -1.35000000000000003e154 < x < -1Initial program 9.4%
flip3--9.5%
div-inv9.5%
rem-cube-cbrt10.9%
rem-cube-cbrt11.3%
cbrt-unprod11.3%
pow211.3%
distribute-rgt-out11.3%
+-commutative11.3%
Applied egg-rr11.3%
associate-*r/11.3%
*-rgt-identity11.3%
+-commutative11.3%
associate--l+99.1%
+-inverses99.1%
metadata-eval99.1%
+-commutative99.1%
fma-def99.2%
+-commutative99.2%
+-commutative99.2%
Simplified99.2%
pow1/394.7%
pow-pow0.0%
metadata-eval0.0%
Applied egg-rr0.0%
Taylor expanded in x around inf 90.3%
unpow290.3%
unpow1/394.8%
Simplified94.8%
if -1 < x Initial program 72.6%
flip3--72.5%
div-inv72.5%
rem-cube-cbrt72.1%
rem-cube-cbrt72.7%
cbrt-unprod72.7%
pow272.7%
distribute-rgt-out72.7%
+-commutative72.7%
Applied egg-rr72.7%
associate-*r/72.7%
*-rgt-identity72.7%
+-commutative72.7%
associate--l+82.3%
+-inverses82.3%
metadata-eval82.3%
+-commutative82.3%
fma-def82.2%
+-commutative82.2%
+-commutative82.2%
Simplified82.2%
pow1/381.8%
pow-pow97.8%
metadata-eval97.8%
Applied egg-rr97.8%
Final simplification88.6%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (+ (cbrt (+ 1.0 x)) (cbrt x)) 1.0)))
double code(double x) {
return 1.0 / fma(cbrt(x), (cbrt((1.0 + x)) + cbrt(x)), 1.0);
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(Float64(1.0 + x)) + cbrt(x)), 1.0)) end
code[x_] := N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, 1\right)}
\end{array}
Initial program 55.8%
flip3--55.7%
div-inv55.7%
rem-cube-cbrt55.5%
rem-cube-cbrt56.1%
cbrt-unprod56.2%
pow256.2%
distribute-rgt-out56.2%
+-commutative56.2%
Applied egg-rr56.2%
associate-*r/56.2%
*-rgt-identity56.2%
+-commutative56.2%
associate--l+75.9%
+-inverses75.9%
metadata-eval75.9%
+-commutative75.9%
fma-def75.9%
+-commutative75.9%
+-commutative75.9%
Simplified75.9%
Taylor expanded in x around 0 61.4%
Final simplification61.4%
(FPCore (x) :precision binary64 (- (cbrt (+ (/ x (/ (+ x -1.0) x)) (/ -1.0 (+ x -1.0)))) (cbrt x)))
double code(double x) {
return cbrt(((x / ((x + -1.0) / x)) + (-1.0 / (x + -1.0)))) - cbrt(x);
}
public static double code(double x) {
return Math.cbrt(((x / ((x + -1.0) / x)) + (-1.0 / (x + -1.0)))) - Math.cbrt(x);
}
function code(x) return Float64(cbrt(Float64(Float64(x / Float64(Float64(x + -1.0) / x)) + Float64(-1.0 / Float64(x + -1.0)))) - cbrt(x)) end
code[x_] := N[(N[Power[N[(N[(x / N[(N[(x + -1.0), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{x}{\frac{x + -1}{x}} + \frac{-1}{x + -1}} - \sqrt[3]{x}
\end{array}
Initial program 55.8%
add-exp-log53.7%
pow1/353.5%
log-pow53.5%
+-commutative53.5%
log1p-udef53.5%
Applied egg-rr53.5%
*-commutative53.5%
exp-prod53.4%
unpow1/353.8%
Simplified53.8%
log1p-udef53.8%
+-commutative53.8%
add-exp-log55.8%
flip-+55.0%
metadata-eval55.0%
div-sub55.0%
sub-neg55.0%
metadata-eval55.0%
sub-neg55.0%
metadata-eval55.0%
Applied egg-rr55.0%
associate-/l*55.8%
Simplified55.8%
Final simplification55.8%
(FPCore (x) :precision binary64 (- (cbrt (+ 1.0 x)) (cbrt x)))
double code(double x) {
return cbrt((1.0 + x)) - cbrt(x);
}
public static double code(double x) {
return Math.cbrt((1.0 + x)) - Math.cbrt(x);
}
function code(x) return Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) end
code[x_] := N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{1 + x} - \sqrt[3]{x}
\end{array}
Initial program 55.8%
Final simplification55.8%
(FPCore (x) :precision binary64 (+ 1.0 (- (* x 0.3333333333333333) (cbrt x))))
double code(double x) {
return 1.0 + ((x * 0.3333333333333333) - cbrt(x));
}
public static double code(double x) {
return 1.0 + ((x * 0.3333333333333333) - Math.cbrt(x));
}
function code(x) return Float64(1.0 + Float64(Float64(x * 0.3333333333333333) - cbrt(x))) end
code[x_] := N[(1.0 + N[(N[(x * 0.3333333333333333), $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(x \cdot 0.3333333333333333 - \sqrt[3]{x}\right)
\end{array}
Initial program 55.8%
Taylor expanded in x around 0 53.2%
+-commutative53.2%
unpow253.2%
associate-*r*53.2%
distribute-rgt-out53.2%
*-commutative53.2%
Simplified53.2%
Taylor expanded in x around 0 53.8%
*-commutative53.8%
Simplified53.8%
associate--l+53.8%
+-commutative53.8%
Applied egg-rr53.8%
Final simplification53.8%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 55.8%
Taylor expanded in x around inf 3.6%
Final simplification3.6%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 55.8%
Taylor expanded in x around 0 52.6%
Final simplification52.6%
herbie shell --seed 2023271
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))