
(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 8 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)) (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 + (x - x)) / 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(Float64(1.0 + Float64(x - x)) / 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[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / 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 + \left(x - x\right)}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, \frac{1}{{t_0}^{-2}}\right)}
\end{array}
\end{array}
Initial program 55.2%
pow1/328.7%
Applied egg-rr28.7%
Applied egg-rr55.4%
associate-*r/55.4%
*-rgt-identity55.4%
+-commutative55.4%
associate--l+99.3%
+-commutative99.3%
fma-def99.3%
+-commutative99.3%
+-commutative99.3%
Simplified99.3%
+-commutative99.3%
metadata-eval99.3%
sub-neg99.3%
flip--78.7%
metadata-eval78.7%
fma-neg78.7%
metadata-eval78.7%
cbrt-undiv78.9%
clear-num78.8%
clear-num78.9%
cbrt-undiv78.7%
metadata-eval78.7%
fma-neg78.7%
metadata-eval78.7%
flip--99.2%
sub-neg99.2%
metadata-eval99.2%
Applied egg-rr99.2%
unpow299.2%
frac-times99.3%
metadata-eval99.3%
inv-pow99.3%
inv-pow99.3%
pow-prod-up99.3%
+-commutative99.3%
metadata-eval99.3%
Applied egg-rr99.3%
Final simplification99.3%
(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 55.2%
add-cube-cbrt54.9%
pow355.0%
Applied egg-rr55.0%
rem-cube-cbrt55.2%
flip3--55.2%
div-inv55.2%
rem-cube-cbrt54.9%
+-commutative54.9%
rem-cube-cbrt55.4%
pow255.4%
remove-double-div55.4%
remove-double-div55.4%
+-commutative55.4%
distribute-rgt-out55.4%
+-commutative55.4%
+-commutative55.4%
Applied egg-rr55.4%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
*-lft-identity99.3%
+-commutative99.3%
fma-def99.3%
Simplified99.3%
Final simplification99.3%
(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 55.2%
add-cube-cbrt54.9%
pow355.0%
Applied egg-rr55.0%
rem-cube-cbrt55.2%
flip3--55.2%
div-inv55.2%
rem-cube-cbrt54.9%
+-commutative54.9%
rem-cube-cbrt55.4%
pow255.4%
remove-double-div55.4%
remove-double-div55.4%
+-commutative55.4%
distribute-rgt-out55.4%
+-commutative55.4%
+-commutative55.4%
Applied egg-rr55.4%
associate--l+99.3%
+-inverses99.3%
metadata-eval99.3%
*-lft-identity99.3%
metadata-eval99.3%
+-inverses99.3%
associate--l+55.4%
*-rgt-identity55.4%
associate--l+99.3%
Simplified99.3%
Final simplification99.3%
(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 55.2%
flip3--55.2%
div-inv55.2%
rem-cube-cbrt54.9%
rem-cube-cbrt55.4%
+-commutative55.4%
distribute-rgt-out55.4%
+-commutative55.4%
fma-def55.4%
add-exp-log55.4%
Applied egg-rr54.1%
associate-*r/54.1%
*-rgt-identity54.1%
+-commutative54.1%
associate--l+76.8%
+-inverses76.8%
metadata-eval76.8%
+-commutative76.8%
exp-prod76.5%
Simplified76.5%
Taylor expanded in x around 0 61.9%
Final simplification61.9%
(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 55.2%
Final simplification55.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 55.2%
add-cube-cbrt54.9%
pow355.0%
Applied egg-rr55.0%
Taylor expanded in x around 0 27.4%
metadata-eval27.4%
pow-base-127.4%
unpow1/354.1%
*-lft-identity54.1%
Simplified54.1%
Final simplification54.1%
(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 55.2%
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 55.2%
Taylor expanded in x around 0 53.9%
Final simplification53.9%
herbie shell --seed 2023339
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))