
(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))) (t_1 (pow t_0 2.0)))
(/
1.0
(fma
(cbrt x)
(/ (+ x (+ 1.0 x)) (+ t_1 (* (cbrt x) (- (cbrt x) t_0))))
t_1))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double t_1 = pow(t_0, 2.0);
return 1.0 / fma(cbrt(x), ((x + (1.0 + x)) / (t_1 + (cbrt(x) * (cbrt(x) - t_0)))), t_1);
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) t_1 = t_0 ^ 2.0 return Float64(1.0 / fma(cbrt(x), Float64(Float64(x + Float64(1.0 + x)) / Float64(t_1 + Float64(cbrt(x) * Float64(cbrt(x) - t_0)))), t_1)) end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Power[t$95$0, 2.0], $MachinePrecision]}, N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[(x + N[(1.0 + x), $MachinePrecision]), $MachinePrecision] / N[(t$95$1 + N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
t_1 := {t\_0}^{2}\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \frac{x + \left(1 + x\right)}{t\_1 + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} - t\_0\right)}, t\_1\right)}
\end{array}
\end{array}
Initial program 6.4%
flip3--7.0%
div-inv7.0%
rem-cube-cbrt5.8%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.9%
Applied egg-rr93.9%
pow293.9%
add-exp-log93.4%
log-pow93.2%
log1p-undefine93.2%
pow1/293.2%
log-pow93.2%
rem-log-exp93.2%
metadata-eval93.2%
pow-to-exp92.9%
pow1/398.5%
+-commutative98.5%
Applied egg-rr98.5%
flip3-+98.4%
+-commutative98.4%
rem-cube-cbrt98.9%
rem-cube-cbrt99.5%
+-commutative99.5%
+-commutative99.5%
+-commutative99.5%
pow299.5%
+-commutative99.5%
distribute-rgt-out--99.5%
Applied egg-rr99.5%
Final simplification99.5%
(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 6.4%
flip3--7.0%
div-inv7.0%
rem-cube-cbrt5.8%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.9%
Applied egg-rr93.9%
pow293.9%
add-exp-log93.4%
log-pow93.2%
log1p-undefine93.2%
pow1/293.2%
log-pow93.2%
rem-log-exp93.2%
metadata-eval93.2%
pow-to-exp92.9%
pow1/398.5%
+-commutative98.5%
Applied egg-rr98.5%
Final simplification98.5%
(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 6.4%
flip3--7.0%
div-inv7.0%
rem-cube-cbrt5.8%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.9%
Applied egg-rr93.9%
pow293.9%
add-exp-log93.4%
log-pow93.2%
log1p-undefine93.2%
pow1/293.2%
log-pow93.2%
rem-log-exp93.2%
metadata-eval93.2%
pow-to-exp92.9%
pow1/398.5%
+-commutative98.5%
Applied egg-rr98.5%
fma-undefine98.4%
+-commutative98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (* (cbrt x) 2.0) (pow (cbrt (+ 1.0 x)) 2.0))))
double code(double x) {
return 1.0 / fma(cbrt(x), (cbrt(x) * 2.0), pow(cbrt((1.0 + x)), 2.0));
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) * 2.0), (cbrt(Float64(1.0 + x)) ^ 2.0))) end
code[x_] := N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] * 2.0), $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}, \sqrt[3]{x} \cdot 2, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\end{array}
Initial program 6.4%
flip3--7.0%
div-inv7.0%
rem-cube-cbrt5.8%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.9%
Applied egg-rr93.9%
pow293.9%
add-exp-log93.4%
log-pow93.2%
log1p-undefine93.2%
pow1/293.2%
log-pow93.2%
rem-log-exp93.2%
metadata-eval93.2%
pow-to-exp92.9%
pow1/398.5%
+-commutative98.5%
Applied egg-rr98.5%
Taylor expanded in x around inf 97.1%
Final simplification97.1%
(FPCore (x) :precision binary64 (let* ((t_0 (/ 1.0 (cbrt x)))) (* t_0 (* t_0 0.3333333333333333))))
double code(double x) {
double t_0 = 1.0 / cbrt(x);
return t_0 * (t_0 * 0.3333333333333333);
}
public static double code(double x) {
double t_0 = 1.0 / Math.cbrt(x);
return t_0 * (t_0 * 0.3333333333333333);
}
function code(x) t_0 = Float64(1.0 / cbrt(x)) return Float64(t_0 * Float64(t_0 * 0.3333333333333333)) end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * N[(t$95$0 * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt[3]{x}}\\
t\_0 \cdot \left(t\_0 \cdot 0.3333333333333333\right)
\end{array}
\end{array}
Initial program 6.4%
add-cube-cbrt6.4%
pow36.4%
pow-to-exp6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 46.0%
exp-to-pow48.5%
pow348.5%
add-cube-cbrt49.1%
*-commutative49.1%
add-sqr-sqrt49.0%
associate-*l*49.0%
cbrt-div49.2%
metadata-eval49.2%
unpow249.2%
cbrt-prod49.0%
sqrt-div49.0%
metadata-eval49.0%
sqrt-unprod49.0%
add-sqr-sqrt49.0%
Applied egg-rr96.9%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (cbrt (pow x -2.0))))
double code(double x) {
return 0.3333333333333333 * cbrt(pow(x, -2.0));
}
public static double code(double x) {
return 0.3333333333333333 * Math.cbrt(Math.pow(x, -2.0));
}
function code(x) return Float64(0.3333333333333333 * cbrt((x ^ -2.0))) end
code[x_] := N[(0.3333333333333333 * N[Power[N[Power[x, -2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \sqrt[3]{{x}^{-2}}
\end{array}
Initial program 6.4%
add-cube-cbrt6.4%
pow36.4%
pow-to-exp6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 46.0%
exp-to-pow48.5%
pow348.5%
add-cube-cbrt49.1%
*-commutative49.1%
pow-flip52.2%
metadata-eval52.2%
Applied egg-rr52.2%
Final simplification52.2%
(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.4%
Taylor expanded in x around 0 1.8%
sub-neg1.8%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt5.2%
fabs-neg5.2%
unpow1/35.2%
metadata-eval5.2%
pow-sqr5.2%
fabs-sqr5.2%
pow-sqr5.2%
metadata-eval5.2%
unpow1/35.2%
Simplified5.2%
(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 2024116
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform default (/ 1 (+ (* (cbrt (+ x 1)) (cbrt (+ x 1))) (* (cbrt x) (cbrt (+ x 1))) (* (cbrt x) (cbrt x)))))
(- (cbrt (+ x 1.0)) (cbrt x)))