
(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))))
(if (<= (- t_0 (cbrt x)) 0.0)
(/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt x)) (pow t_0 2.0)))
(/
(- (+ 1.0 x) x)
(+ (cbrt (pow (+ 1.0 x) 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 = 1.0 / fma(cbrt(x), (cbrt(x) + cbrt(x)), pow(t_0, 2.0));
} else {
tmp = ((1.0 + x) - x) / (cbrt(pow((1.0 + x), 2.0)) + (cbrt(x) * (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(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(x)), (t_0 ^ 2.0))); else tmp = Float64(Float64(Float64(1.0 + x) - x) / Float64(cbrt((Float64(1.0 + x) ^ 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[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $MachinePrecision], 1/3], $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:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{x}, {t_0}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + x\right) - x}{\sqrt[3]{{\left(1 + x\right)}^{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.1%
flip3--4.1%
div-inv4.1%
rem-cube-cbrt3.9%
rem-cube-cbrt4.1%
cbrt-unprod4.1%
pow24.1%
distribute-rgt-out4.1%
+-commutative4.1%
Applied egg-rr4.1%
associate-*r/4.1%
*-rgt-identity4.1%
+-commutative4.1%
associate--l+49.5%
+-inverses49.5%
metadata-eval49.5%
+-commutative49.5%
fma-def49.5%
+-commutative49.5%
+-commutative49.5%
Simplified49.5%
+-commutative49.5%
expm1-log1p-u47.7%
expm1-udef47.7%
pow1/347.3%
+-commutative47.3%
unpow247.3%
pow-prod-down42.2%
+-commutative42.2%
pow1/342.4%
+-commutative42.4%
pow1/394.1%
pow294.1%
+-commutative94.1%
Applied egg-rr94.1%
expm1-def94.1%
expm1-log1p98.6%
Simplified98.6%
+-commutative98.6%
add-cube-cbrt98.4%
pow398.5%
+-commutative98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 42.6%
unpow1/398.6%
Simplified98.6%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 98.3%
flip3--98.2%
rem-cube-cbrt98.1%
rem-cube-cbrt99.8%
cbrt-unprod99.9%
pow299.9%
distribute-rgt-out99.9%
+-commutative99.9%
Applied egg-rr99.9%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))) (t_1 (- t_0 (cbrt x))))
(if (<= t_1 2e-7)
(/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) (cbrt (* x x))))
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-7) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), cbrt((x * x)));
} 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-7) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), cbrt(Float64(x * x)))); 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-7], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[Power[N[(x * x), $MachinePrecision], 1/3], $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^{-7}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, \sqrt[3]{x \cdot x}\right)}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 1.9999999999999999e-7Initial program 4.9%
flip3--4.9%
div-inv4.9%
rem-cube-cbrt4.7%
rem-cube-cbrt6.3%
cbrt-unprod6.3%
pow26.3%
distribute-rgt-out6.3%
+-commutative6.3%
Applied egg-rr6.3%
associate-*r/6.3%
*-rgt-identity6.3%
+-commutative6.3%
associate--l+50.6%
+-inverses50.6%
metadata-eval50.6%
+-commutative50.6%
fma-def50.7%
+-commutative50.7%
+-commutative50.7%
Simplified50.7%
add-exp-log48.8%
pow1/348.4%
log-pow48.5%
log-pow42.0%
log1p-udef42.0%
Applied egg-rr42.0%
associate-*r*42.0%
metadata-eval42.0%
Simplified42.0%
Taylor expanded in x around inf 48.0%
unpow1/350.3%
unpow250.3%
Simplified50.3%
if 1.9999999999999999e-7 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 99.7%
Final simplification74.8%
(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.9%
flip3--51.9%
div-inv51.9%
rem-cube-cbrt51.8%
rem-cube-cbrt52.7%
cbrt-unprod52.7%
pow252.7%
distribute-rgt-out52.8%
+-commutative52.8%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
+-commutative52.8%
associate--l+75.1%
+-inverses75.1%
metadata-eval75.1%
+-commutative75.1%
fma-def75.1%
+-commutative75.1%
+-commutative75.1%
Simplified75.1%
+-commutative75.1%
expm1-log1p-u74.2%
expm1-udef74.2%
pow1/374.0%
+-commutative74.0%
unpow274.0%
pow-prod-down69.9%
+-commutative69.9%
pow1/370.1%
+-commutative70.1%
pow1/397.0%
pow297.0%
+-commutative97.0%
Applied egg-rr97.0%
expm1-def97.0%
expm1-log1p99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (+ (cbrt x) (cbrt (+ 1.0 x)))))
(if (<= x -1.35e+154)
(/ 1.0 (fma (cbrt x) t_0 1.0))
(if (<= x -1.0)
(/ 1.0 (fma (cbrt x) t_0 (cbrt (* x x))))
(/ 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.35e+154) {
tmp = 1.0 / fma(cbrt(x), t_0, 1.0);
} else if (x <= -1.0) {
tmp = 1.0 / fma(cbrt(x), t_0, cbrt((x * x)));
} 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.35e+154) tmp = Float64(1.0 / fma(cbrt(x), t_0, 1.0)); elseif (x <= -1.0) tmp = Float64(1.0 / fma(cbrt(x), t_0, cbrt(Float64(x * x)))); 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.35e+154], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, -1.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0 + N[Power[N[(x * x), $MachinePrecision], 1/3], $MachinePrecision]), $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.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, 1\right)}\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, \sqrt[3]{x \cdot x}\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 < -1.35000000000000003e154Initial program 4.6%
flip3--4.6%
div-inv4.6%
rem-cube-cbrt3.5%
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 20.0%
if -1.35000000000000003e154 < x < -1Initial program 9.7%
flip3--9.6%
div-inv9.6%
rem-cube-cbrt10.3%
rem-cube-cbrt14.4%
cbrt-unprod14.4%
pow214.4%
distribute-rgt-out14.5%
+-commutative14.5%
Applied egg-rr14.5%
associate-*r/14.5%
*-rgt-identity14.5%
+-commutative14.5%
associate--l+98.9%
+-inverses98.9%
metadata-eval98.9%
+-commutative98.9%
fma-def98.9%
+-commutative98.9%
+-commutative98.9%
Simplified98.9%
add-exp-log95.2%
pow1/394.5%
log-pow94.5%
log-pow0.0%
log1p-udef0.0%
Applied egg-rr0.0%
associate-*r*0.0%
metadata-eval0.0%
Simplified0.0%
Taylor expanded in x around inf 90.6%
unpow1/394.9%
unpow294.9%
Simplified94.9%
if -1 < x Initial program 69.9%
flip3--69.8%
div-inv69.8%
rem-cube-cbrt69.7%
rem-cube-cbrt70.1%
cbrt-unprod70.1%
pow270.1%
distribute-rgt-out70.1%
+-commutative70.1%
Applied egg-rr70.1%
associate-*r/70.1%
*-rgt-identity70.1%
+-commutative70.1%
associate--l+85.2%
+-inverses85.2%
metadata-eval85.2%
+-commutative85.2%
fma-def85.2%
+-commutative85.2%
+-commutative85.2%
Simplified85.2%
pow1/384.4%
pow-pow97.7%
metadata-eval97.7%
Applied egg-rr97.7%
Final simplification85.8%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (+ 1.0 (cbrt x)) (pow (cbrt (+ 1.0 x)) 2.0))))
double code(double x) {
return 1.0 / fma(cbrt(x), (1.0 + cbrt(x)), pow(cbrt((1.0 + x)), 2.0));
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(1.0 + cbrt(x)), (cbrt(Float64(1.0 + x)) ^ 2.0))) end
code[x_] := N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(1.0 + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, 1 + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\end{array}
Initial program 51.9%
flip3--51.9%
div-inv51.9%
rem-cube-cbrt51.8%
rem-cube-cbrt52.7%
cbrt-unprod52.7%
pow252.7%
distribute-rgt-out52.8%
+-commutative52.8%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
+-commutative52.8%
associate--l+75.1%
+-inverses75.1%
metadata-eval75.1%
+-commutative75.1%
fma-def75.1%
+-commutative75.1%
+-commutative75.1%
Simplified75.1%
+-commutative75.1%
expm1-log1p-u74.2%
expm1-udef74.2%
pow1/374.0%
+-commutative74.0%
unpow274.0%
pow-prod-down69.9%
+-commutative69.9%
pow1/370.1%
+-commutative70.1%
pow1/397.0%
pow297.0%
+-commutative97.0%
Applied egg-rr97.0%
expm1-def97.0%
expm1-log1p99.2%
Simplified99.2%
+-commutative99.2%
add-cube-cbrt99.1%
pow399.1%
+-commutative99.1%
Applied egg-rr99.1%
Taylor expanded in x around 0 58.8%
Final simplification58.8%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) 1.0)))
double code(double x) {
return 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), 1.0);
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), 1.0)) end
code[x_] := N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, 1\right)}
\end{array}
Initial program 51.9%
flip3--51.9%
div-inv51.9%
rem-cube-cbrt51.8%
rem-cube-cbrt52.7%
cbrt-unprod52.7%
pow252.7%
distribute-rgt-out52.8%
+-commutative52.8%
Applied egg-rr52.8%
associate-*r/52.8%
*-rgt-identity52.8%
+-commutative52.8%
associate--l+75.1%
+-inverses75.1%
metadata-eval75.1%
+-commutative75.1%
fma-def75.1%
+-commutative75.1%
+-commutative75.1%
Simplified75.1%
Taylor expanded in x around 0 58.6%
Final simplification58.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 51.9%
Final simplification51.9%
(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.9%
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 51.9%
Taylor expanded in x around 0 50.6%
Final simplification50.6%
herbie shell --seed 2023178
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))