
(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 5 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)) (+ (pow t_0 2.0) (* (cbrt x) (+ t_0 (cbrt x)))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return (1.0 + (x - x)) / (pow(t_0, 2.0) + (cbrt(x) * (t_0 + cbrt(x))));
}
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) * (t_0 + Math.cbrt(x))));
}
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(t_0 + cbrt(x))))) 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[(t$95$0 + N[Power[x, 1/3], $MachinePrecision]), $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(t\_0 + \sqrt[3]{x}\right)}
\end{array}
\end{array}
Initial program 7.3%
pow1/34.8%
Applied egg-rr4.8%
pow1/37.3%
flip3--7.3%
div-inv7.3%
rem-cube-cbrt6.8%
+-commutative6.8%
rem-cube-cbrt9.7%
pow29.7%
+-commutative9.7%
distribute-rgt-out9.7%
+-commutative9.7%
Applied egg-rr9.7%
associate--l+98.5%
+-inverses98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
+-inverses98.5%
Simplified98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (/ (fma (cbrt x) 0.3333333333333333 (/ -0.1111111111111111 (pow (cbrt x) 2.0))) x))
double code(double x) {
return fma(cbrt(x), 0.3333333333333333, (-0.1111111111111111 / pow(cbrt(x), 2.0))) / x;
}
function code(x) return Float64(fma(cbrt(x), 0.3333333333333333, Float64(-0.1111111111111111 / (cbrt(x) ^ 2.0))) / x) end
code[x_] := N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333 + N[(-0.1111111111111111 / N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\sqrt[3]{x}, 0.3333333333333333, \frac{-0.1111111111111111}{{\left(\sqrt[3]{x}\right)}^{2}}\right)}{x}
\end{array}
Initial program 7.3%
add-sqr-sqrt7.0%
add-sqr-sqrt7.2%
difference-of-squares7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
pow1/37.3%
sqrt-pow17.3%
metadata-eval7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-rgt-out98.0%
metadata-eval98.0%
Simplified98.0%
expm1-log1p-u98.0%
expm1-undefine7.9%
fma-define7.9%
cbrt-div7.9%
metadata-eval7.9%
unpow27.9%
cbrt-prod7.9%
associate-*l/7.9%
metadata-eval7.9%
pow27.9%
Applied egg-rr7.9%
sub-neg7.9%
metadata-eval7.9%
+-commutative7.9%
log1p-undefine7.9%
rem-exp-log7.9%
associate-+r+98.0%
metadata-eval98.0%
+-lft-identity98.0%
*-lft-identity98.0%
*-lft-identity98.0%
fma-undefine98.0%
*-commutative98.0%
fma-define98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x) :precision binary64 (/ (+ (* (cbrt x) 0.3333333333333333) (* -0.1111111111111111 (pow x -0.6666666666666666))) x))
double code(double x) {
return ((cbrt(x) * 0.3333333333333333) + (-0.1111111111111111 * pow(x, -0.6666666666666666))) / x;
}
public static double code(double x) {
return ((Math.cbrt(x) * 0.3333333333333333) + (-0.1111111111111111 * Math.pow(x, -0.6666666666666666))) / x;
}
function code(x) return Float64(Float64(Float64(cbrt(x) * 0.3333333333333333) + Float64(-0.1111111111111111 * (x ^ -0.6666666666666666))) / x) end
code[x_] := N[(N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(-0.1111111111111111 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x} \cdot 0.3333333333333333 + -0.1111111111111111 \cdot {x}^{-0.6666666666666666}}{x}
\end{array}
Initial program 7.3%
add-sqr-sqrt7.0%
add-sqr-sqrt7.2%
difference-of-squares7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
pow1/37.3%
sqrt-pow17.3%
metadata-eval7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-rgt-out98.0%
metadata-eval98.0%
Simplified98.0%
pow1/398.0%
pow-flip98.0%
pow-pow98.0%
metadata-eval98.0%
metadata-eval98.0%
Applied egg-rr98.0%
Final simplification98.0%
(FPCore (x) :precision binary64 (* (* (cbrt x) 0.3333333333333333) (/ 1.0 x)))
double code(double x) {
return (cbrt(x) * 0.3333333333333333) * (1.0 / x);
}
public static double code(double x) {
return (Math.cbrt(x) * 0.3333333333333333) * (1.0 / x);
}
function code(x) return Float64(Float64(cbrt(x) * 0.3333333333333333) * Float64(1.0 / x)) end
code[x_] := N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\sqrt[3]{x} \cdot 0.3333333333333333\right) \cdot \frac{1}{x}
\end{array}
Initial program 7.3%
add-sqr-sqrt7.0%
add-sqr-sqrt7.2%
difference-of-squares7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
pow1/37.3%
sqrt-pow17.3%
metadata-eval7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-rgt-out98.0%
metadata-eval98.0%
Simplified98.0%
div-inv97.9%
fma-define97.9%
cbrt-div97.9%
metadata-eval97.9%
unpow297.9%
cbrt-prod97.9%
associate-*l/97.9%
metadata-eval97.9%
pow297.9%
Applied egg-rr97.9%
Taylor expanded in x around inf 96.9%
Final simplification96.9%
(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 7.3%
Taylor expanded in x around 0 1.8%
sub-neg1.8%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt5.4%
fabs-neg5.4%
unpow1/35.4%
metadata-eval5.4%
pow-sqr5.4%
fabs-sqr5.4%
pow-sqr5.4%
metadata-eval5.4%
unpow1/35.4%
Simplified5.4%
Final simplification5.4%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ x 1.0)))) (/ 1.0 (+ (+ (* t_0 t_0) (* (cbrt x) t_0)) (* (cbrt x) (cbrt x))))))
double code(double x) {
double t_0 = cbrt((x + 1.0));
return 1.0 / (((t_0 * t_0) + (cbrt(x) * t_0)) + (cbrt(x) * cbrt(x)));
}
public static double code(double x) {
double t_0 = Math.cbrt((x + 1.0));
return 1.0 / (((t_0 * t_0) + (Math.cbrt(x) * t_0)) + (Math.cbrt(x) * Math.cbrt(x)));
}
function code(x) t_0 = cbrt(Float64(x + 1.0)) return Float64(1.0 / Float64(Float64(Float64(t_0 * t_0) + Float64(cbrt(x) * t_0)) + Float64(cbrt(x) * cbrt(x)))) end
code[x_] := Block[{t$95$0 = N[Power[N[(x + 1.0), $MachinePrecision], 1/3], $MachinePrecision]}, N[(1.0 / N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{x + 1}\\
\frac{1}{\left(t\_0 \cdot t\_0 + \sqrt[3]{x} \cdot t\_0\right) + \sqrt[3]{x} \cdot \sqrt[3]{x}}
\end{array}
\end{array}
herbie shell --seed 2024074
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(/ 1.0 (+ (+ (* (cbrt (+ x 1.0)) (cbrt (+ x 1.0))) (* (cbrt x) (cbrt (+ x 1.0)))) (* (cbrt x) (cbrt x))))
(- (cbrt (+ x 1.0)) (cbrt x)))