
(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 11 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) (/ t_0 (cbrt (/ 1.0 (+ 1.0 x))))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return 1.0 / fma(cbrt(x), (cbrt(x) + t_0), (t_0 / cbrt((1.0 / (1.0 + x)))));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), Float64(t_0 / cbrt(Float64(1.0 / Float64(1.0 + x)))))) 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[(t$95$0 / N[Power[N[(1.0 / N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $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, \frac{t_0}{\sqrt[3]{\frac{1}{1 + x}}}\right)}
\end{array}
\end{array}
Initial program 51.5%
flip3--51.8%
div-inv51.8%
rem-cube-cbrt51.3%
rem-cube-cbrt53.1%
cbrt-unprod53.2%
pow253.2%
distribute-rgt-out53.1%
+-commutative53.1%
Applied egg-rr53.1%
associate-*r/53.1%
*-rgt-identity53.1%
+-commutative53.1%
associate--l+72.9%
+-inverses72.9%
metadata-eval72.9%
+-commutative72.9%
fma-def72.9%
+-commutative72.9%
+-commutative72.9%
Simplified72.9%
Applied egg-rr99.2%
add-cbrt-cube99.1%
pow399.1%
Applied egg-rr99.1%
cube-div99.2%
metadata-eval99.2%
rem-cube-cbrt99.2%
Applied egg-rr99.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))
(pow (pow t_1 3.0) 0.3333333333333333))))
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 = pow(pow(t_1, 3.0), 0.3333333333333333);
}
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 ^ 3.0) ^ 0.3333333333333333; 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], N[Power[N[Power[t$95$1, 3.0], $MachinePrecision], 0.3333333333333333], $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}, \sqrt[3]{x} + t_0, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left({t_1}^{3}\right)}^{0.3333333333333333}\\
\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-cbrt4.1%
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+44.7%
+-inverses44.7%
metadata-eval44.7%
+-commutative44.7%
fma-def44.7%
+-commutative44.7%
+-commutative44.7%
Simplified44.7%
Taylor expanded in x around 0 20.0%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 96.5%
add-cbrt-cube96.5%
pow1/396.5%
pow396.5%
Applied egg-rr96.5%
Final simplification59.1%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) (/ 1.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), (1.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), Float64(1.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[(1.0 / N[Power[t$95$0, -2.0], $MachinePrecision]), $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, \frac{1}{{t_0}^{-2}}\right)}
\end{array}
\end{array}
Initial program 51.5%
flip3--51.8%
div-inv51.8%
rem-cube-cbrt51.3%
rem-cube-cbrt53.1%
cbrt-unprod53.2%
pow253.2%
distribute-rgt-out53.1%
+-commutative53.1%
Applied egg-rr53.1%
associate-*r/53.1%
*-rgt-identity53.1%
+-commutative53.1%
associate--l+72.9%
+-inverses72.9%
metadata-eval72.9%
+-commutative72.9%
fma-def72.9%
+-commutative72.9%
+-commutative72.9%
Simplified72.9%
pow1/371.9%
Applied egg-rr71.9%
unpow1/372.9%
unpow272.9%
cbrt-prod99.2%
*-un-lft-identity99.2%
associate-*r*99.2%
metadata-eval99.2%
div-inv99.2%
clear-num99.2%
associate-/r/99.2%
inv-pow99.2%
pow199.2%
pow-div99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Final simplification99.2%
(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 51.5%
flip3--51.8%
div-inv51.8%
rem-cube-cbrt51.3%
rem-cube-cbrt53.1%
cbrt-unprod53.2%
pow253.2%
distribute-rgt-out53.1%
+-commutative53.1%
Applied egg-rr53.1%
associate-*r/53.1%
*-rgt-identity53.1%
+-commutative53.1%
associate--l+72.9%
+-inverses72.9%
metadata-eval72.9%
+-commutative72.9%
fma-def72.9%
+-commutative72.9%
+-commutative72.9%
Simplified72.9%
unpow272.9%
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)))) (/ (+ 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 51.5%
add-cube-cbrt51.4%
pow351.4%
Applied egg-rr51.4%
rem-cube-cbrt51.5%
flip3--51.8%
+-commutative51.8%
rem-cube-cbrt51.3%
rem-cube-cbrt53.1%
div-sub51.6%
Applied egg-rr51.6%
div-sub53.1%
associate--l+99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (cbrt x) (cbrt (+ 1.0 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(x) + cbrt((1.0 + 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(x) + cbrt(Float64(1.0 + 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[x, 1/3], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 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]{x} + \sqrt[3]{1 + 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--8.2%
div-inv8.2%
rem-cube-cbrt7.7%
rem-cube-cbrt11.9%
cbrt-unprod11.9%
pow211.9%
distribute-rgt-out11.9%
+-commutative11.9%
Applied egg-rr11.9%
associate-*r/11.9%
*-rgt-identity11.9%
+-commutative11.9%
associate--l+49.3%
+-inverses49.3%
metadata-eval49.3%
+-commutative49.3%
fma-def49.2%
+-commutative49.2%
+-commutative49.2%
Simplified49.2%
Taylor expanded in x around 0 20.0%
if -1 < x Initial program 69.4%
flip3--69.5%
div-inv69.5%
rem-cube-cbrt69.0%
rem-cube-cbrt69.9%
cbrt-unprod69.9%
pow269.9%
distribute-rgt-out69.9%
+-commutative69.9%
Applied egg-rr69.9%
associate-*r/69.9%
*-rgt-identity69.9%
+-commutative69.9%
associate--l+82.5%
+-inverses82.5%
metadata-eval82.5%
+-commutative82.5%
fma-def82.5%
+-commutative82.5%
+-commutative82.5%
Simplified82.5%
pow1/381.9%
pow-pow97.6%
metadata-eval97.6%
Applied egg-rr97.6%
Final simplification75.1%
(FPCore (x) :precision binary64 (pow (pow (- (cbrt (+ 1.0 x)) (cbrt x)) 3.0) 0.3333333333333333))
double code(double x) {
return pow(pow((cbrt((1.0 + x)) - cbrt(x)), 3.0), 0.3333333333333333);
}
public static double code(double x) {
return Math.pow(Math.pow((Math.cbrt((1.0 + x)) - Math.cbrt(x)), 3.0), 0.3333333333333333);
}
function code(x) return (Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) ^ 3.0) ^ 0.3333333333333333 end
code[x_] := N[Power[N[Power[N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision]
\begin{array}{l}
\\
{\left({\left(\sqrt[3]{1 + x} - \sqrt[3]{x}\right)}^{3}\right)}^{0.3333333333333333}
\end{array}
Initial program 51.5%
add-cbrt-cube51.5%
pow1/351.5%
pow351.5%
Applied egg-rr51.5%
Final simplification51.5%
(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 51.5%
add-exp-log51.5%
Applied egg-rr51.5%
Final simplification51.5%
(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 51.5%
Final simplification51.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 51.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 51.5%
Taylor expanded in x around 0 47.7%
Final simplification47.7%
herbie shell --seed 2023257
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))