
(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 x)))) (/ (+ 1.0 (- x x)) (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 + (x - x)) / fma(cbrt(x), (cbrt(x) + t_0), pow(t_0, 2.0));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(Float64(1.0 + Float64(x - x)) / 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[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / 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 + \left(x - x\right)}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, {t_0}^{2}\right)}
\end{array}
\end{array}
Initial program 52.5%
pow1/324.6%
Applied egg-rr24.6%
Applied egg-rr53.2%
associate-*r/53.2%
*-rgt-identity53.2%
+-commutative53.2%
associate--l+99.1%
+-commutative99.1%
fma-def99.1%
+-commutative99.1%
+-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 5e-11)
(/ 1.0 (* (cbrt x) (+ t_0 (* (cbrt x) 2.0))))
(/ 1.0 (- (pow (+ (cbrt x) t_0) 2.0) (cbrt (* x (+ 1.0 x))))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((t_0 - cbrt(x)) <= 5e-11) {
tmp = 1.0 / (cbrt(x) * (t_0 + (cbrt(x) * 2.0)));
} else {
tmp = 1.0 / (pow((cbrt(x) + t_0), 2.0) - cbrt((x * (1.0 + x))));
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
double tmp;
if ((t_0 - Math.cbrt(x)) <= 5e-11) {
tmp = 1.0 / (Math.cbrt(x) * (t_0 + (Math.cbrt(x) * 2.0)));
} else {
tmp = 1.0 / (Math.pow((Math.cbrt(x) + t_0), 2.0) - Math.cbrt((x * (1.0 + x))));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - cbrt(x)) <= 5e-11) tmp = Float64(1.0 / Float64(cbrt(x) * Float64(t_0 + Float64(cbrt(x) * 2.0)))); else tmp = Float64(1.0 / Float64((Float64(cbrt(x) + t_0) ^ 2.0) - cbrt(Float64(x * Float64(1.0 + 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], 5e-11], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[(N[Power[x, 1/3], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Power[N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision], 2.0], $MachinePrecision] - N[Power[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;t_0 - \sqrt[3]{x} \leq 5 \cdot 10^{-11}:\\
\;\;\;\;\frac{1}{\sqrt[3]{x} \cdot \left(t_0 + \sqrt[3]{x} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{{\left(\sqrt[3]{x} + t_0\right)}^{2} - \sqrt[3]{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 5.00000000000000018e-11Initial program 4.3%
flip3--4.3%
div-inv4.3%
rem-cube-cbrt3.9%
rem-cube-cbrt4.3%
+-commutative4.3%
distribute-rgt-out4.3%
+-commutative4.3%
fma-def4.3%
add-exp-log4.3%
Applied egg-rr2.3%
associate-*r/2.3%
*-rgt-identity2.3%
+-commutative2.3%
associate--l+47.8%
+-inverses47.8%
metadata-eval47.8%
+-commutative47.8%
exp-prod47.2%
Simplified47.2%
Taylor expanded in x around inf 46.3%
expm1-log1p-u46.3%
expm1-udef5.5%
+-commutative5.5%
unpow1/35.5%
unpow25.5%
cbrt-prod5.5%
pow25.5%
Applied egg-rr5.5%
expm1-def98.5%
expm1-log1p98.5%
fma-udef98.4%
unpow298.4%
distribute-lft-out98.4%
+-commutative98.4%
associate-+r+98.4%
count-298.4%
Simplified98.4%
if 5.00000000000000018e-11 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 98.5%
pow1/397.3%
Applied egg-rr97.3%
Applied egg-rr99.8%
Final simplification99.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))) (t_1 (- t_0 (cbrt x))))
(if (<= t_1 2e-6)
(/ 1.0 (* (cbrt x) (+ t_0 (* (cbrt x) 2.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 <= 2e-6) {
tmp = 1.0 / (cbrt(x) * (t_0 + (cbrt(x) * 2.0)));
} else {
tmp = exp(log(t_1));
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
double t_1 = t_0 - Math.cbrt(x);
double tmp;
if (t_1 <= 2e-6) {
tmp = 1.0 / (Math.cbrt(x) * (t_0 + (Math.cbrt(x) * 2.0)));
} else {
tmp = Math.exp(Math.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 <= 2e-6) tmp = Float64(1.0 / Float64(cbrt(x) * Float64(t_0 + Float64(cbrt(x) * 2.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, 2e-6], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[(N[Power[x, 1/3], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $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 2 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\sqrt[3]{x} \cdot \left(t_0 + \sqrt[3]{x} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{\log t_1}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 1.99999999999999991e-6Initial program 5.1%
flip3--5.3%
div-inv5.3%
rem-cube-cbrt5.0%
rem-cube-cbrt5.8%
+-commutative5.8%
distribute-rgt-out5.8%
+-commutative5.8%
fma-def5.8%
add-exp-log5.8%
Applied egg-rr3.8%
associate-*r/3.8%
*-rgt-identity3.8%
+-commutative3.8%
associate--l+48.6%
+-inverses48.6%
metadata-eval48.6%
+-commutative48.6%
exp-prod48.0%
Simplified48.0%
Taylor expanded in x around inf 46.7%
expm1-log1p-u46.7%
expm1-udef6.4%
+-commutative6.4%
unpow1/36.4%
unpow26.4%
cbrt-prod6.4%
pow26.4%
Applied egg-rr6.4%
expm1-def98.0%
expm1-log1p98.0%
fma-udef98.0%
unpow298.0%
distribute-lft-out97.9%
+-commutative97.9%
associate-+r+97.9%
count-297.9%
Simplified97.9%
if 1.99999999999999991e-6 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.2%
add-exp-log99.2%
Applied egg-rr99.2%
Final simplification98.6%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ (+ 1.0 (- x x)) (+ (pow t_0 2.0) (* (cbrt x) (+ (cbrt x) t_0))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return (1.0 + (x - x)) / (pow(t_0, 2.0) + (cbrt(x) * (cbrt(x) + t_0)));
}
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) * (Math.cbrt(x) + t_0)));
}
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(cbrt(x) + t_0)))) 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[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $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(\sqrt[3]{x} + t_0\right)}
\end{array}
\end{array}
Initial program 52.5%
pow1/324.6%
Applied egg-rr24.6%
Applied egg-rr53.2%
+-commutative53.2%
associate--l+99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x))) (t_1 (- t_0 (cbrt x)))) (if (<= t_1 2e-6) (/ 1.0 (* (cbrt x) (+ t_0 (* (cbrt x) 2.0)))) 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 <= 2e-6) {
tmp = 1.0 / (cbrt(x) * (t_0 + (cbrt(x) * 2.0)));
} else {
tmp = t_1;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
double t_1 = t_0 - Math.cbrt(x);
double tmp;
if (t_1 <= 2e-6) {
tmp = 1.0 / (Math.cbrt(x) * (t_0 + (Math.cbrt(x) * 2.0)));
} else {
tmp = 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 <= 2e-6) tmp = Float64(1.0 / Float64(cbrt(x) * Float64(t_0 + Float64(cbrt(x) * 2.0)))); else tmp = 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, 2e-6], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(t$95$0 + N[(N[Power[x, 1/3], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
t_1 := t_0 - \sqrt[3]{x}\\
\mathbf{if}\;t_1 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{\sqrt[3]{x} \cdot \left(t_0 + \sqrt[3]{x} \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 1.99999999999999991e-6Initial program 5.1%
flip3--5.3%
div-inv5.3%
rem-cube-cbrt5.0%
rem-cube-cbrt5.8%
+-commutative5.8%
distribute-rgt-out5.8%
+-commutative5.8%
fma-def5.8%
add-exp-log5.8%
Applied egg-rr3.8%
associate-*r/3.8%
*-rgt-identity3.8%
+-commutative3.8%
associate--l+48.6%
+-inverses48.6%
metadata-eval48.6%
+-commutative48.6%
exp-prod48.0%
Simplified48.0%
Taylor expanded in x around inf 46.7%
expm1-log1p-u46.7%
expm1-udef6.4%
+-commutative6.4%
unpow1/36.4%
unpow26.4%
cbrt-prod6.4%
pow26.4%
Applied egg-rr6.4%
expm1-def98.0%
expm1-log1p98.0%
fma-udef98.0%
unpow298.0%
distribute-lft-out97.9%
+-commutative97.9%
associate-+r+97.9%
count-297.9%
Simplified97.9%
if 1.99999999999999991e-6 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.2%
Final simplification98.6%
(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 52.5%
Final simplification52.5%
(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 52.5%
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 52.5%
Taylor expanded in x around 0 49.8%
Final simplification49.8%
herbie shell --seed 2023306
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))