
(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/325.6%
Applied egg-rr25.6%
pow1/352.5%
flip3--52.5%
div-inv52.5%
add-sqr-sqrt25.3%
cbrt-unprod25.1%
rem-cube-cbrt25.0%
cbrt-unprod25.0%
add-sqr-sqrt52.1%
rem-cube-cbrt52.8%
pow252.8%
distribute-rgt-out52.8%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
+-commutative52.8%
associate--l+99.3%
+-commutative99.3%
fma-def99.3%
+-commutative99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 0.0)
(* 0.3333333333333333 (pow (cbrt x) -2.0))
(/
(+ 1.0 (- x x))
(fma (cbrt x) (+ (cbrt x) t_0) (cbrt (pow (+ 1.0 x) 2.0)))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((t_0 - cbrt(x)) <= 0.0) {
tmp = 0.3333333333333333 * pow(cbrt(x), -2.0);
} else {
tmp = (1.0 + (x - x)) / fma(cbrt(x), (cbrt(x) + t_0), cbrt(pow((1.0 + x), 2.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(0.3333333333333333 * (cbrt(x) ^ -2.0)); else tmp = Float64(Float64(1.0 + Float64(x - x)) / fma(cbrt(x), Float64(cbrt(x) + t_0), cbrt((Float64(1.0 + x) ^ 2.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[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $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[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $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 0:\\
\;\;\;\;0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1 + \left(x - x\right)}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
add-cube-cbrt3.6%
pow33.6%
Applied egg-rr3.6%
Taylor expanded in x around inf 1.0%
unpow1/34.2%
associate-+r+4.2%
+-commutative4.2%
metadata-eval4.2%
pow-base-14.2%
*-lft-identity4.2%
distribute-rgt-out4.2%
unpow1/34.2%
metadata-eval4.2%
Simplified4.2%
associate--l+4.2%
flip-+4.2%
Applied egg-rr4.2%
unpow24.2%
difference-of-squares4.2%
+-commutative4.2%
associate-+l-98.5%
+-inverses98.5%
--rgt-identity98.5%
associate--r-98.5%
+-commutative98.5%
associate--r-98.5%
+-commutative98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef4.7%
Applied egg-rr4.7%
expm1-def98.5%
expm1-log1p98.5%
/-rgt-identity98.5%
Simplified98.5%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.3%
pow1/347.7%
Applied egg-rr47.7%
pow1/399.3%
flip3--99.3%
div-inv99.3%
add-sqr-sqrt47.6%
cbrt-unprod47.6%
rem-cube-cbrt47.6%
cbrt-unprod47.6%
add-sqr-sqrt99.2%
rem-cube-cbrt99.8%
pow299.8%
distribute-rgt-out99.8%
Applied egg-rr99.8%
associate-*r/99.8%
*-rgt-identity99.8%
+-commutative99.8%
associate--l+99.8%
+-commutative99.8%
fma-def99.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
unpow299.8%
cbrt-unprod99.9%
pow299.9%
Applied egg-rr99.9%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 0.0)
(* 0.3333333333333333 (pow (cbrt x) -2.0))
(/ (- (+ 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));
double tmp;
if ((t_0 - cbrt(x)) <= 0.0) {
tmp = 0.3333333333333333 * pow(cbrt(x), -2.0);
} else {
tmp = ((1.0 + x) - x) / (pow(t_0, 2.0) + (cbrt(x) * (cbrt(x) + t_0)));
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x));
double tmp;
if ((t_0 - Math.cbrt(x)) <= 0.0) {
tmp = 0.3333333333333333 * Math.pow(Math.cbrt(x), -2.0);
} else {
tmp = ((1.0 + x) - x) / (Math.pow(t_0, 2.0) + (Math.cbrt(x) * (Math.cbrt(x) + 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(0.3333333333333333 * (cbrt(x) ^ -2.0)); else tmp = Float64(Float64(Float64(1.0 + x) - x) / Float64((t_0 ^ 2.0) + Float64(cbrt(x) * Float64(cbrt(x) + 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[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], 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]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;t_0 - \sqrt[3]{x} \leq 0:\\
\;\;\;\;0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + x\right) - x}{{t_0}^{2} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
add-cube-cbrt3.6%
pow33.6%
Applied egg-rr3.6%
Taylor expanded in x around inf 1.0%
unpow1/34.2%
associate-+r+4.2%
+-commutative4.2%
metadata-eval4.2%
pow-base-14.2%
*-lft-identity4.2%
distribute-rgt-out4.2%
unpow1/34.2%
metadata-eval4.2%
Simplified4.2%
associate--l+4.2%
flip-+4.2%
Applied egg-rr4.2%
unpow24.2%
difference-of-squares4.2%
+-commutative4.2%
associate-+l-98.5%
+-inverses98.5%
--rgt-identity98.5%
associate--r-98.5%
+-commutative98.5%
associate--r-98.5%
+-commutative98.5%
Simplified98.5%
expm1-log1p-u98.5%
expm1-udef4.7%
Applied egg-rr4.7%
expm1-def98.5%
expm1-log1p98.5%
/-rgt-identity98.5%
Simplified98.5%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.3%
pow1/347.7%
Applied egg-rr47.7%
pow1/399.3%
add-sqr-sqrt47.7%
cbrt-unprod47.7%
flip3--47.6%
rem-cube-cbrt47.6%
cbrt-unprod47.6%
add-sqr-sqrt47.6%
rem-cube-cbrt47.6%
pow247.6%
Applied egg-rr99.8%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (- (cbrt (+ 1.0 x)) (cbrt x))))
(if (<= t_0 2e-6)
(* 0.3333333333333333 (pow (cbrt x) -2.0))
(exp (log t_0)))))
double code(double x) {
double t_0 = cbrt((1.0 + x)) - cbrt(x);
double tmp;
if (t_0 <= 2e-6) {
tmp = 0.3333333333333333 * pow(cbrt(x), -2.0);
} else {
tmp = exp(log(t_0));
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x)) - Math.cbrt(x);
double tmp;
if (t_0 <= 2e-6) {
tmp = 0.3333333333333333 * Math.pow(Math.cbrt(x), -2.0);
} else {
tmp = Math.exp(Math.log(t_0));
}
return tmp;
}
function code(x) t_0 = Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) tmp = 0.0 if (t_0 <= 2e-6) tmp = Float64(0.3333333333333333 * (cbrt(x) ^ -2.0)); else tmp = exp(log(t_0)); 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[t$95$0, 2e-6], N[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[Exp[N[Log[t$95$0], $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} - \sqrt[3]{x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;e^{\log t_0}\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 1.99999999999999991e-6Initial program 4.7%
add-cube-cbrt4.0%
pow34.0%
Applied egg-rr4.0%
Taylor expanded in x around inf 1.0%
unpow1/34.7%
associate-+r+4.7%
+-commutative4.7%
metadata-eval4.7%
pow-base-14.7%
*-lft-identity4.7%
distribute-rgt-out4.7%
unpow1/34.7%
metadata-eval4.7%
Simplified4.7%
associate--l+4.7%
flip-+4.7%
Applied egg-rr4.7%
unpow24.7%
difference-of-squares4.7%
+-commutative4.7%
associate-+l-98.2%
+-inverses98.2%
--rgt-identity98.2%
associate--r-98.2%
+-commutative98.2%
associate--r-98.2%
+-commutative98.2%
Simplified98.2%
expm1-log1p-u98.2%
expm1-udef5.1%
Applied egg-rr5.1%
expm1-def98.2%
expm1-log1p98.2%
/-rgt-identity98.2%
Simplified98.2%
if 1.99999999999999991e-6 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.7%
add-exp-log99.7%
Applied egg-rr99.7%
Final simplification99.0%
(FPCore (x) :precision binary64 (let* ((t_0 (- (cbrt (+ 1.0 x)) (cbrt x)))) (if (<= t_0 2e-6) (* 0.3333333333333333 (pow (cbrt x) -2.0)) t_0)))
double code(double x) {
double t_0 = cbrt((1.0 + x)) - cbrt(x);
double tmp;
if (t_0 <= 2e-6) {
tmp = 0.3333333333333333 * pow(cbrt(x), -2.0);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x)) - Math.cbrt(x);
double tmp;
if (t_0 <= 2e-6) {
tmp = 0.3333333333333333 * Math.pow(Math.cbrt(x), -2.0);
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) tmp = 0.0 if (t_0 <= 2e-6) tmp = Float64(0.3333333333333333 * (cbrt(x) ^ -2.0)); else tmp = t_0; 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[t$95$0, 2e-6], N[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} - \sqrt[3]{x}\\
\mathbf{if}\;t_0 \leq 2 \cdot 10^{-6}:\\
\;\;\;\;0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 1.99999999999999991e-6Initial program 4.7%
add-cube-cbrt4.0%
pow34.0%
Applied egg-rr4.0%
Taylor expanded in x around inf 1.0%
unpow1/34.7%
associate-+r+4.7%
+-commutative4.7%
metadata-eval4.7%
pow-base-14.7%
*-lft-identity4.7%
distribute-rgt-out4.7%
unpow1/34.7%
metadata-eval4.7%
Simplified4.7%
associate--l+4.7%
flip-+4.7%
Applied egg-rr4.7%
unpow24.7%
difference-of-squares4.7%
+-commutative4.7%
associate-+l-98.2%
+-inverses98.2%
--rgt-identity98.2%
associate--r-98.2%
+-commutative98.2%
associate--r-98.2%
+-commutative98.2%
Simplified98.2%
expm1-log1p-u98.2%
expm1-udef5.1%
Applied egg-rr5.1%
expm1-def98.2%
expm1-log1p98.2%
/-rgt-identity98.2%
Simplified98.2%
if 1.99999999999999991e-6 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.7%
Final simplification99.0%
(FPCore (x) :precision binary64 (if (or (<= x -1.05) (not (<= x 0.25))) (* 0.3333333333333333 (pow (cbrt x) -2.0)) (+ 1.0 (* x -0.6666666666666666))))
double code(double x) {
double tmp;
if ((x <= -1.05) || !(x <= 0.25)) {
tmp = 0.3333333333333333 * pow(cbrt(x), -2.0);
} else {
tmp = 1.0 + (x * -0.6666666666666666);
}
return tmp;
}
public static double code(double x) {
double tmp;
if ((x <= -1.05) || !(x <= 0.25)) {
tmp = 0.3333333333333333 * Math.pow(Math.cbrt(x), -2.0);
} else {
tmp = 1.0 + (x * -0.6666666666666666);
}
return tmp;
}
function code(x) tmp = 0.0 if ((x <= -1.05) || !(x <= 0.25)) tmp = Float64(0.3333333333333333 * (cbrt(x) ^ -2.0)); else tmp = Float64(1.0 + Float64(x * -0.6666666666666666)); end return tmp end
code[x_] := If[Or[LessEqual[x, -1.05], N[Not[LessEqual[x, 0.25]], $MachinePrecision]], N[(0.3333333333333333 * N[Power[N[Power[x, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(x * -0.6666666666666666), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \lor \neg \left(x \leq 0.25\right):\\
\;\;\;\;0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}\\
\mathbf{else}:\\
\;\;\;\;1 + x \cdot -0.6666666666666666\\
\end{array}
\end{array}
if x < -1.05000000000000004 or 0.25 < x Initial program 5.9%
add-cube-cbrt5.2%
pow35.2%
Applied egg-rr5.2%
Taylor expanded in x around inf 1.0%
unpow1/35.2%
associate-+r+5.2%
+-commutative5.2%
metadata-eval5.2%
pow-base-15.2%
*-lft-identity5.2%
distribute-rgt-out5.2%
unpow1/35.2%
metadata-eval5.2%
Simplified5.2%
associate--l+5.2%
flip-+5.2%
Applied egg-rr5.2%
unpow25.2%
difference-of-squares5.2%
+-commutative5.2%
associate-+l-97.3%
+-inverses97.3%
--rgt-identity97.3%
associate--r-97.3%
+-commutative97.3%
associate--r-97.3%
+-commutative97.3%
Simplified97.3%
expm1-log1p-u97.3%
expm1-udef5.7%
Applied egg-rr5.7%
expm1-def97.3%
expm1-log1p97.3%
/-rgt-identity97.3%
Simplified97.3%
if -1.05000000000000004 < x < 0.25Initial program 100.0%
pow1/348.8%
Applied egg-rr48.8%
pow1/3100.0%
flip3--99.9%
div-inv99.9%
add-sqr-sqrt48.7%
cbrt-unprod48.7%
rem-cube-cbrt48.7%
cbrt-unprod48.7%
add-sqr-sqrt99.9%
rem-cube-cbrt99.9%
pow299.9%
distribute-rgt-out99.9%
Applied egg-rr99.9%
associate-*r/99.9%
*-rgt-identity99.9%
+-commutative99.9%
associate--l+99.9%
+-commutative99.9%
fma-def99.9%
+-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in x around 0 95.8%
*-commutative95.8%
Simplified95.8%
Final simplification96.6%
(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 50.6%
Final simplification50.6%
herbie shell --seed 2023332
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))