
(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 7 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 t_0)))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return 1.0 / fma(cbrt(x), (cbrt(x) + t_0), (t_0 * t_0));
}
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 * 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[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[(t$95$0 * t$95$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 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 6.9%
flip3--7.2%
div-inv7.2%
rem-cube-cbrt6.4%
rem-cube-cbrt8.9%
+-commutative8.9%
distribute-rgt-out8.9%
+-commutative8.9%
fma-define8.9%
add-exp-log8.9%
Applied egg-rr8.9%
associate-*r/8.9%
*-rgt-identity8.9%
+-commutative8.9%
associate--l+93.4%
+-inverses93.4%
metadata-eval93.4%
+-commutative93.4%
exp-prod92.5%
Simplified92.5%
add-sqr-sqrt92.5%
unpow-prod-down94.2%
Applied egg-rr94.2%
pow-sqr94.2%
Simplified94.2%
sqrt-pow292.5%
associate-/l*92.5%
pow-sqr92.5%
sqr-pow92.5%
add-sqr-sqrt92.5%
unpow-prod-down94.2%
pow1/294.2%
pow-exp94.2%
metadata-eval94.2%
exp-prod94.0%
*-commutative94.0%
log1p-undefine94.0%
pow-to-exp94.2%
pow1/395.5%
+-commutative95.5%
pow1/295.5%
pow-exp95.5%
metadata-eval95.5%
exp-prod94.7%
*-commutative94.7%
log1p-undefine94.7%
pow-to-exp94.5%
pow1/398.3%
+-commutative98.3%
Applied egg-rr98.3%
Final simplification98.3%
(FPCore (x) :precision binary64 (let* ((t_0 (- (cbrt (+ 1.0 x)) (cbrt x)))) (if (<= t_0 0.0) (/ (* (cbrt x) 0.25) x) t_0)))
double code(double x) {
double t_0 = cbrt((1.0 + x)) - cbrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = (cbrt(x) * 0.25) / x;
} 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 <= 0.0) {
tmp = (Math.cbrt(x) * 0.25) / x;
} 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 <= 0.0) tmp = Float64(Float64(cbrt(x) * 0.25) / x); 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, 0.0], N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.25), $MachinePrecision] / x), $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} - \sqrt[3]{x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{\sqrt[3]{x} \cdot 0.25}{x}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x #s(literal 1 binary64))) (cbrt.f64 x)) < 0.0Initial program 4.2%
flip3--4.2%
div-inv4.2%
rem-cube-cbrt3.5%
rem-cube-cbrt4.5%
+-commutative4.5%
distribute-rgt-out4.5%
+-commutative4.5%
fma-define4.5%
add-exp-log4.5%
Applied egg-rr4.5%
associate-*r/4.5%
*-rgt-identity4.5%
+-commutative4.5%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
Taylor expanded in x around inf 92.2%
Taylor expanded in x around inf 20.7%
Simplified20.7%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x #s(literal 1 binary64))) (cbrt.f64 x)) Initial program 63.7%
Final simplification22.7%
(FPCore (x) :precision binary64 (/ (+ (* (cbrt x) 0.3333333333333333) (* (cbrt (/ 1.0 (pow x 2.0))) -0.1111111111111111)) x))
double code(double x) {
return ((cbrt(x) * 0.3333333333333333) + (cbrt((1.0 / pow(x, 2.0))) * -0.1111111111111111)) / x;
}
public static double code(double x) {
return ((Math.cbrt(x) * 0.3333333333333333) + (Math.cbrt((1.0 / Math.pow(x, 2.0))) * -0.1111111111111111)) / x;
}
function code(x) return Float64(Float64(Float64(cbrt(x) * 0.3333333333333333) + Float64(cbrt(Float64(1.0 / (x ^ 2.0))) * -0.1111111111111111)) / x) end
code[x_] := N[(N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] + N[(N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * -0.1111111111111111), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x} \cdot 0.3333333333333333 + \sqrt[3]{\frac{1}{{x}^{2}}} \cdot -0.1111111111111111}{x}
\end{array}
Initial program 6.9%
add-sqr-sqrt6.8%
add-sqr-sqrt6.8%
difference-of-squares6.8%
pow1/36.8%
sqrt-pow16.8%
metadata-eval6.8%
pow1/36.8%
sqrt-pow16.8%
metadata-eval6.8%
pow1/34.6%
sqrt-pow14.6%
metadata-eval4.6%
pow1/36.9%
sqrt-pow16.9%
metadata-eval6.9%
Applied egg-rr6.9%
Taylor expanded in x around inf 98.0%
associate-+r+98.0%
+-commutative98.0%
distribute-rgt-out98.0%
metadata-eval98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x) :precision binary64 (if (<= x 1.32e+154) (* 0.3333333333333333 (cbrt (/ 1.0 (pow x 2.0)))) (/ (* (cbrt x) 0.25) x)))
double code(double x) {
double tmp;
if (x <= 1.32e+154) {
tmp = 0.3333333333333333 * cbrt((1.0 / pow(x, 2.0)));
} else {
tmp = (cbrt(x) * 0.25) / x;
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.32e+154) {
tmp = 0.3333333333333333 * Math.cbrt((1.0 / Math.pow(x, 2.0)));
} else {
tmp = (Math.cbrt(x) * 0.25) / x;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.32e+154) tmp = Float64(0.3333333333333333 * cbrt(Float64(1.0 / (x ^ 2.0)))); else tmp = Float64(Float64(cbrt(x) * 0.25) / x); end return tmp end
code[x_] := If[LessEqual[x, 1.32e+154], N[(0.3333333333333333 * N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.25), $MachinePrecision] / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;0.3333333333333333 \cdot \sqrt[3]{\frac{1}{{x}^{2}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt[3]{x} \cdot 0.25}{x}\\
\end{array}
\end{array}
if x < 1.31999999999999998e154Initial program 9.0%
Taylor expanded in x around inf 94.9%
if 1.31999999999999998e154 < x Initial program 4.7%
flip3--4.7%
div-inv4.7%
rem-cube-cbrt3.0%
rem-cube-cbrt4.7%
+-commutative4.7%
distribute-rgt-out4.7%
+-commutative4.7%
fma-define4.7%
add-exp-log4.7%
Applied egg-rr4.7%
associate-*r/4.7%
*-rgt-identity4.7%
+-commutative4.7%
associate--l+91.7%
+-inverses91.7%
metadata-eval91.7%
+-commutative91.7%
exp-prod90.8%
Simplified90.8%
Taylor expanded in x around inf 90.8%
Taylor expanded in x around inf 20.7%
Simplified20.7%
(FPCore (x) :precision binary64 (/ (* (cbrt x) 0.25) x))
double code(double x) {
return (cbrt(x) * 0.25) / x;
}
public static double code(double x) {
return (Math.cbrt(x) * 0.25) / x;
}
function code(x) return Float64(Float64(cbrt(x) * 0.25) / x) end
code[x_] := N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.25), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x} \cdot 0.25}{x}
\end{array}
Initial program 6.9%
flip3--7.2%
div-inv7.2%
rem-cube-cbrt6.4%
rem-cube-cbrt8.9%
+-commutative8.9%
distribute-rgt-out8.9%
+-commutative8.9%
fma-define8.9%
add-exp-log8.9%
Applied egg-rr8.9%
associate-*r/8.9%
*-rgt-identity8.9%
+-commutative8.9%
associate--l+93.4%
+-inverses93.4%
metadata-eval93.4%
+-commutative93.4%
exp-prod92.5%
Simplified92.5%
Taylor expanded in x around inf 90.6%
Taylor expanded in x around inf 20.7%
Simplified20.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 6.9%
Taylor expanded in x around 0 1.8%
sub-neg1.8%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt5.5%
fabs-neg5.5%
unpow1/35.5%
metadata-eval5.5%
pow-sqr5.5%
fabs-sqr5.5%
pow-sqr5.5%
metadata-eval5.5%
unpow1/35.5%
Simplified5.5%
(FPCore (x) :precision binary64 (- (cbrt x)))
double code(double x) {
return -cbrt(x);
}
public static double code(double x) {
return -Math.cbrt(x);
}
function code(x) return Float64(-cbrt(x)) end
code[x_] := (-N[Power[x, 1/3], $MachinePrecision])
\begin{array}{l}
\\
-\sqrt[3]{x}
\end{array}
Initial program 6.9%
Taylor expanded in x around 0 4.4%
associate--l+4.4%
*-commutative4.4%
Simplified4.4%
Taylor expanded in x around 0 1.8%
Simplified1.8%
(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 2024103
(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)))