
(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)) (+ (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)) / (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)) / (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((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[(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]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\frac{1 + \left(x - x\right)}{{t_0}^{2} + \sqrt[3]{x} \cdot \left(t_0 + \sqrt[3]{x}\right)}
\end{array}
\end{array}
Initial program 53.0%
add-exp-log50.8%
pow1/350.6%
log-pow50.6%
+-commutative50.6%
log1p-udef50.6%
Applied egg-rr50.6%
*-commutative50.6%
exp-prod50.5%
unpow1/350.8%
Simplified50.8%
log1p-udef50.8%
add-exp-log53.0%
rem-cube-cbrt53.0%
Applied egg-rr53.0%
rem-cbrt-cube53.0%
flip3--53.1%
rem-cube-cbrt52.7%
rem-cube-cbrt53.9%
associate--l+99.2%
unpow299.2%
distribute-rgt-in99.2%
+-commutative99.2%
Applied egg-rr99.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)) 1.0))
(- (/ (cbrt (+ 1.0 (pow x 3.0))) (cbrt (fma x x (- 1.0 x)))) (cbrt x)))))
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)), 1.0);
} else {
tmp = (cbrt((1.0 + pow(x, 3.0))) / cbrt(fma(x, x, (1.0 - x)))) - cbrt(x);
}
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)), 1.0)); else tmp = Float64(Float64(cbrt(Float64(1.0 + (x ^ 3.0))) / cbrt(fma(x, x, Float64(1.0 - x)))) - cbrt(x)); 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] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[N[(1.0 + N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[N[(x * x + N[(1.0 - x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] - N[Power[x, 1/3], $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}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{1 + {x}^{3}}}{\sqrt[3]{\mathsf{fma}\left(x, x, 1 - x\right)}} - \sqrt[3]{x}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.3%
flip3--4.3%
div-inv4.3%
rem-cube-cbrt3.8%
rem-cube-cbrt4.3%
cbrt-unprod4.3%
pow24.3%
distribute-rgt-out4.3%
+-commutative4.3%
Applied egg-rr4.3%
associate-*r/4.3%
*-rgt-identity4.3%
+-commutative4.3%
associate--l+47.6%
+-inverses47.6%
metadata-eval47.6%
+-commutative47.6%
fma-def47.6%
+-commutative47.6%
+-commutative47.6%
Simplified47.6%
Taylor expanded in x around 0 19.9%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 98.1%
flip3-+98.1%
cbrt-div98.1%
pow398.1%
metadata-eval98.1%
+-commutative98.1%
pow398.1%
fma-def98.1%
metadata-eval98.1%
*-rgt-identity98.1%
Applied egg-rr98.1%
Final simplification60.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))) (t_1 (- t_0 (cbrt x))))
(if (<= t_1 0.0)
(/ 1.0 (fma (cbrt x) (+ t_0 (cbrt x)) 1.0))
(exp (log t_1)))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double t_1 = t_0 - cbrt(x);
double tmp;
if (t_1 <= 0.0) {
tmp = 1.0 / fma(cbrt(x), (t_0 + cbrt(x)), 1.0);
} else {
tmp = exp(log(t_1));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) t_1 = Float64(t_0 - cbrt(x)) tmp = 0.0 if (t_1 <= 0.0) tmp = Float64(1.0 / fma(cbrt(x), Float64(t_0 + cbrt(x)), 1.0)); else tmp = exp(log(t_1)); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 0.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Exp[N[Log[t$95$1], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
t_1 := t_0 - \sqrt[3]{x}\\
\mathbf{if}\;t_1 \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0 + \sqrt[3]{x}, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\log t_1}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.3%
flip3--4.3%
div-inv4.3%
rem-cube-cbrt3.8%
rem-cube-cbrt4.3%
cbrt-unprod4.3%
pow24.3%
distribute-rgt-out4.3%
+-commutative4.3%
Applied egg-rr4.3%
associate-*r/4.3%
*-rgt-identity4.3%
+-commutative4.3%
associate--l+47.6%
+-inverses47.6%
metadata-eval47.6%
+-commutative47.6%
fma-def47.6%
+-commutative47.6%
+-commutative47.6%
Simplified47.6%
Taylor expanded in x around 0 19.9%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 98.1%
add-exp-log98.1%
Applied egg-rr98.1%
Final simplification60.5%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (cbrt (+ 1.0 x)) (cbrt x))))
(if (<= x -1.0)
(/ 1.0 (fma (cbrt x) t_0 1.0))
(/
1.0
(fma
(+ -1.0 (+ 1.0 (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.0) {
tmp = 1.0 / fma(cbrt(x), t_0, 1.0);
} else {
tmp = 1.0 / fma((-1.0 + (1.0 + 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.0) tmp = Float64(1.0 / fma(cbrt(x), t_0, 1.0)); else tmp = Float64(1.0 / fma(Float64(-1.0 + Float64(1.0 + 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.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(-1.0 + N[(1.0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $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:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-1 + \left(1 + \sqrt[3]{x}\right), t_0, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\
\end{array}
\end{array}
if x < -1Initial program 7.4%
flip3--7.4%
div-inv7.4%
rem-cube-cbrt8.7%
rem-cube-cbrt9.7%
cbrt-unprod9.7%
pow29.7%
distribute-rgt-out9.7%
+-commutative9.7%
Applied egg-rr9.7%
associate-*r/9.7%
*-rgt-identity9.7%
+-commutative9.7%
associate--l+50.5%
+-inverses50.5%
metadata-eval50.5%
+-commutative50.5%
fma-def50.5%
+-commutative50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in x around 0 19.9%
if -1 < x Initial program 70.2%
flip3--70.4%
div-inv70.4%
rem-cube-cbrt69.7%
rem-cube-cbrt70.5%
cbrt-unprod70.6%
pow270.6%
distribute-rgt-out70.6%
+-commutative70.6%
Applied egg-rr70.6%
associate-*r/70.6%
*-rgt-identity70.6%
+-commutative70.6%
associate--l+83.9%
+-inverses83.9%
metadata-eval83.9%
+-commutative83.9%
fma-def83.8%
+-commutative83.8%
+-commutative83.8%
Simplified83.8%
expm1-log1p-u83.4%
expm1-udef83.4%
log1p-udef83.4%
add-exp-log83.8%
Applied egg-rr83.8%
pow1/383.2%
pow-pow97.7%
metadata-eval97.7%
Applied egg-rr97.7%
Final simplification76.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (cbrt (+ 1.0 x)) (cbrt x))))
(if (<= x -1.0)
(/ 1.0 (fma (cbrt x) t_0 1.0))
(/ 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.0) {
tmp = 1.0 / fma(cbrt(x), t_0, 1.0);
} 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.0) tmp = Float64(1.0 / fma(cbrt(x), t_0, 1.0)); 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.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + 1.0), $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:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, 1\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 < -1Initial program 7.4%
flip3--7.4%
div-inv7.4%
rem-cube-cbrt8.7%
rem-cube-cbrt9.7%
cbrt-unprod9.7%
pow29.7%
distribute-rgt-out9.7%
+-commutative9.7%
Applied egg-rr9.7%
associate-*r/9.7%
*-rgt-identity9.7%
+-commutative9.7%
associate--l+50.5%
+-inverses50.5%
metadata-eval50.5%
+-commutative50.5%
fma-def50.5%
+-commutative50.5%
+-commutative50.5%
Simplified50.5%
Taylor expanded in x around 0 19.9%
if -1 < x Initial program 70.2%
flip3--70.4%
div-inv70.4%
rem-cube-cbrt69.7%
rem-cube-cbrt70.5%
cbrt-unprod70.6%
pow270.6%
distribute-rgt-out70.6%
+-commutative70.6%
Applied egg-rr70.6%
associate-*r/70.6%
*-rgt-identity70.6%
+-commutative70.6%
associate--l+83.9%
+-inverses83.9%
metadata-eval83.9%
+-commutative83.9%
fma-def83.8%
+-commutative83.8%
+-commutative83.8%
Simplified83.8%
pow1/383.2%
pow-pow97.7%
metadata-eval97.7%
Applied egg-rr97.7%
Final simplification76.4%
(FPCore (x) :precision binary64 (exp (log (- (cbrt (+ 1.0 x)) (cbrt x)))))
double code(double x) {
return exp(log((cbrt((1.0 + x)) - cbrt(x))));
}
public static double code(double x) {
return Math.exp(Math.log((Math.cbrt((1.0 + x)) - Math.cbrt(x))));
}
function code(x) return exp(log(Float64(cbrt(Float64(1.0 + x)) - cbrt(x)))) end
code[x_] := N[Exp[N[Log[N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\sqrt[3]{1 + x} - \sqrt[3]{x}\right)}
\end{array}
Initial program 53.0%
add-exp-log53.0%
Applied egg-rr53.0%
Final simplification53.0%
(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 53.0%
Final simplification53.0%
(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 53.0%
Taylor expanded in x around inf 3.7%
Final simplification3.7%
(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 53.0%
Taylor expanded in x around 0 49.4%
Final simplification49.4%
herbie shell --seed 2023200
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))