
(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 (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 57.7%
flip3--57.8%
div-inv57.9%
rem-cube-cbrt57.5%
rem-cube-cbrt59.1%
cbrt-unprod59.1%
pow259.1%
distribute-rgt-out59.1%
+-commutative59.1%
Applied egg-rr59.1%
associate-*r/59.1%
*-rgt-identity59.1%
+-commutative59.1%
associate--l+78.4%
+-inverses78.4%
metadata-eval78.4%
+-commutative78.4%
fma-def78.4%
+-commutative78.4%
+-commutative78.4%
Simplified78.4%
unpow278.4%
cbrt-prod99.2%
Applied egg-rr99.2%
unpow299.2%
Simplified99.2%
Final simplification99.2%
(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) (+ (cbrt x) t_0) 1.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 <= 0.0) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), 1.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 <= 0.0) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), 1.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, 0.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + 1.0), $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 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\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.9%
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+49.6%
+-inverses49.6%
metadata-eval49.6%
+-commutative49.6%
fma-def49.6%
+-commutative49.6%
+-commutative49.6%
Simplified49.6%
Taylor expanded in x around 0 20.0%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 97.3%
Final simplification64.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))) (t_1 (+ (cbrt x) t_0)))
(if (<= x -1.35e+154)
(/ 1.0 (fma (cbrt x) t_1 1.0))
(if (<= x 1.34e+154)
(/ 1.0 (+ (+ (pow t_0 2.0) (cbrt (* x x))) (cbrt (* x (+ 1.0 x)))))
(/ 1.0 (fma (cbrt x) t_1 (pow (+ 1.0 x) 0.6666666666666666)))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double t_1 = cbrt(x) + t_0;
double tmp;
if (x <= -1.35e+154) {
tmp = 1.0 / fma(cbrt(x), t_1, 1.0);
} else if (x <= 1.34e+154) {
tmp = 1.0 / ((pow(t_0, 2.0) + cbrt((x * x))) + cbrt((x * (1.0 + x))));
} else {
tmp = 1.0 / fma(cbrt(x), t_1, pow((1.0 + x), 0.6666666666666666));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) t_1 = Float64(cbrt(x) + t_0) tmp = 0.0 if (x <= -1.35e+154) tmp = Float64(1.0 / fma(cbrt(x), t_1, 1.0)); elseif (x <= 1.34e+154) tmp = Float64(1.0 / Float64(Float64((t_0 ^ 2.0) + cbrt(Float64(x * x))) + cbrt(Float64(x * Float64(1.0 + x))))); else tmp = Float64(1.0 / fma(cbrt(x), t_1, (Float64(1.0 + x) ^ 0.6666666666666666))); 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[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[x, -1.35e+154], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$1 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.34e+154], N[(1.0 / N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[Power[N[(x * x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$1 + N[Power[N[(1.0 + x), $MachinePrecision], 0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
t_1 := \sqrt[3]{x} + t_0\\
\mathbf{if}\;x \leq -1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_1, 1\right)}\\
\mathbf{elif}\;x \leq 1.34 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\left({t_0}^{2} + \sqrt[3]{x \cdot x}\right) + \sqrt[3]{x \cdot \left(1 + x\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_1, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\
\end{array}
\end{array}
if x < -1.35000000000000003e154Initial program 4.6%
flip3--4.6%
div-inv4.6%
rem-cube-cbrt3.6%
rem-cube-cbrt4.6%
cbrt-unprod4.6%
pow24.6%
distribute-rgt-out4.6%
+-commutative4.6%
Applied egg-rr4.6%
associate-*r/4.6%
*-rgt-identity4.6%
+-commutative4.6%
associate--l+4.6%
+-inverses4.6%
metadata-eval4.6%
+-commutative4.6%
fma-def4.6%
+-commutative4.6%
+-commutative4.6%
Simplified4.6%
Taylor expanded in x around 0 19.9%
if -1.35000000000000003e154 < x < 1.34000000000000001e154Initial program 72.8%
flip3--73.1%
div-inv73.1%
rem-cube-cbrt73.0%
rem-cube-cbrt74.6%
cbrt-unprod74.7%
pow274.7%
distribute-rgt-out74.7%
+-commutative74.7%
Applied egg-rr74.7%
associate-*r/74.7%
*-rgt-identity74.7%
+-commutative74.7%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.5%
+-commutative99.5%
+-commutative99.5%
Simplified99.5%
unpow299.5%
cbrt-prod99.4%
Applied egg-rr99.4%
unpow299.4%
Simplified99.4%
fma-udef99.3%
+-commutative99.3%
+-commutative99.3%
distribute-rgt-in99.3%
+-commutative99.3%
associate-+r+99.3%
cbrt-unprod99.5%
cbrt-unprod99.6%
*-commutative99.6%
+-commutative99.6%
Applied egg-rr99.6%
if 1.34000000000000001e154 < x Initial program 4.9%
flip3--4.9%
div-inv4.9%
rem-cube-cbrt3.3%
rem-cube-cbrt4.9%
cbrt-unprod4.9%
pow24.9%
distribute-rgt-out4.9%
+-commutative4.9%
Applied egg-rr4.9%
associate-*r/4.9%
*-rgt-identity4.9%
+-commutative4.9%
associate--l+4.9%
+-inverses4.9%
metadata-eval4.9%
+-commutative4.9%
fma-def4.9%
+-commutative4.9%
+-commutative4.9%
Simplified4.9%
pow1/34.9%
pow-pow91.4%
metadata-eval91.4%
Applied egg-rr91.4%
Final simplification89.4%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ 1.0 (+ (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 / (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 / (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(1.0 / 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[(1.0 / 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}{{t_0}^{2} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)}
\end{array}
\end{array}
Initial program 57.7%
flip3--57.8%
div-inv57.9%
rem-cube-cbrt57.5%
rem-cube-cbrt59.1%
cbrt-unprod59.1%
pow259.1%
distribute-rgt-out59.1%
+-commutative59.1%
Applied egg-rr59.1%
associate-*r/59.1%
*-rgt-identity59.1%
+-commutative59.1%
associate--l+78.4%
+-inverses78.4%
metadata-eval78.4%
+-commutative78.4%
fma-def78.4%
+-commutative78.4%
+-commutative78.4%
Simplified78.4%
unpow278.4%
cbrt-prod99.2%
Applied egg-rr99.2%
unpow299.2%
Simplified99.2%
fma-udef99.2%
+-commutative99.2%
+-commutative99.2%
+-commutative99.2%
+-commutative99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (or (<= x -1.35e+154) (not (<= x 1.34e+154)))
(/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) 1.0))
(/ 1.0 (+ (+ (pow t_0 2.0) (cbrt (* x x))) (cbrt (* x (+ 1.0 x))))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((x <= -1.35e+154) || !(x <= 1.34e+154)) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), 1.0);
} else {
tmp = 1.0 / ((pow(t_0, 2.0) + cbrt((x * x))) + cbrt((x * (1.0 + x))));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if ((x <= -1.35e+154) || !(x <= 1.34e+154)) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), 1.0)); else tmp = Float64(1.0 / Float64(Float64((t_0 ^ 2.0) + cbrt(Float64(x * x))) + 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[Or[LessEqual[x, -1.35e+154], N[Not[LessEqual[x, 1.34e+154]], $MachinePrecision]], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] + N[Power[N[(x * x), $MachinePrecision], 1/3], $MachinePrecision]), $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}\;x \leq -1.35 \cdot 10^{+154} \lor \neg \left(x \leq 1.34 \cdot 10^{+154}\right):\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\left({t_0}^{2} + \sqrt[3]{x \cdot x}\right) + \sqrt[3]{x \cdot \left(1 + x\right)}}\\
\end{array}
\end{array}
if x < -1.35000000000000003e154 or 1.34000000000000001e154 < x Initial program 4.7%
flip3--4.7%
div-inv4.7%
rem-cube-cbrt3.5%
rem-cube-cbrt4.7%
cbrt-unprod4.7%
pow24.7%
distribute-rgt-out4.7%
+-commutative4.7%
Applied egg-rr4.7%
associate-*r/4.7%
*-rgt-identity4.7%
+-commutative4.7%
associate--l+4.7%
+-inverses4.7%
metadata-eval4.7%
+-commutative4.7%
fma-def4.7%
+-commutative4.7%
+-commutative4.7%
Simplified4.7%
Taylor expanded in x around 0 19.9%
if -1.35000000000000003e154 < x < 1.34000000000000001e154Initial program 72.8%
flip3--73.1%
div-inv73.1%
rem-cube-cbrt73.0%
rem-cube-cbrt74.6%
cbrt-unprod74.7%
pow274.7%
distribute-rgt-out74.7%
+-commutative74.7%
Applied egg-rr74.7%
associate-*r/74.7%
*-rgt-identity74.7%
+-commutative74.7%
associate--l+99.5%
+-inverses99.5%
metadata-eval99.5%
+-commutative99.5%
fma-def99.5%
+-commutative99.5%
+-commutative99.5%
Simplified99.5%
unpow299.5%
cbrt-prod99.4%
Applied egg-rr99.4%
unpow299.4%
Simplified99.4%
fma-udef99.3%
+-commutative99.3%
+-commutative99.3%
distribute-rgt-in99.3%
+-commutative99.3%
associate-+r+99.3%
cbrt-unprod99.5%
cbrt-unprod99.6%
*-commutative99.6%
+-commutative99.6%
Applied egg-rr99.6%
Final simplification81.9%
(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 57.7%
Final simplification57.7%
(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 57.7%
add-cube-cbrt57.4%
pow357.4%
Applied egg-rr57.4%
Taylor expanded in x around 0 25.5%
metadata-eval25.5%
pow-base-125.5%
unpow1/354.0%
*-lft-identity54.0%
Simplified54.0%
Final simplification54.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 57.7%
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 57.7%
Taylor expanded in x around 0 54.0%
Final simplification54.0%
herbie shell --seed 2023272
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))