
(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 15 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
(/
1.0
(*
x
(+
(cbrt (+ (/ 1.0 x) (/ 2.0 (* x x))))
(+
(cbrt (fma (pow x -0.5) (pow x -0.5) (/ 1.0 (* x x))))
(cbrt (/ 1.0 x)))))))
double code(double x) {
return 1.0 / (x * (cbrt(((1.0 / x) + (2.0 / (x * x)))) + (cbrt(fma(pow(x, -0.5), pow(x, -0.5), (1.0 / (x * x)))) + cbrt((1.0 / x)))));
}
function code(x) return Float64(1.0 / Float64(x * Float64(cbrt(Float64(Float64(1.0 / x) + Float64(2.0 / Float64(x * x)))) + Float64(cbrt(fma((x ^ -0.5), (x ^ -0.5), Float64(1.0 / Float64(x * x)))) + cbrt(Float64(1.0 / x)))))) end
code[x_] := N[(1.0 / N[(x * N[(N[Power[N[(N[(1.0 / x), $MachinePrecision] + N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(N[Power[x, -0.5], $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision] + N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(1.0 / x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot \left(\sqrt[3]{\frac{1}{x} + \frac{2}{x \cdot x}} + \left(\sqrt[3]{\mathsf{fma}\left({x}^{-0.5}, {x}^{-0.5}, \frac{1}{x \cdot x}\right)} + \sqrt[3]{\frac{1}{x}}\right)\right)}
\end{array}
Initial program 6.4%
Applied rewrites8.9%
Taylor expanded in x around inf
lower-/.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-cbrt.f64N/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-+.f64N/A
Applied rewrites98.1%
Applied rewrites98.2%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (sqrt x))))
(/
1.0
(*
x
(+
(cbrt (+ (/ 1.0 x) (/ 2.0 (* x x))))
(+ (cbrt (/ 1.0 x)) (cbrt (fma t_0 t_0 (/ 1.0 (* x x))))))))))
double code(double x) {
double t_0 = 1.0 / sqrt(x);
return 1.0 / (x * (cbrt(((1.0 / x) + (2.0 / (x * x)))) + (cbrt((1.0 / x)) + cbrt(fma(t_0, t_0, (1.0 / (x * x)))))));
}
function code(x) t_0 = Float64(1.0 / sqrt(x)) return Float64(1.0 / Float64(x * Float64(cbrt(Float64(Float64(1.0 / x) + Float64(2.0 / Float64(x * x)))) + Float64(cbrt(Float64(1.0 / x)) + cbrt(fma(t_0, t_0, Float64(1.0 / Float64(x * x)))))))) end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, N[(1.0 / N[(x * N[(N[Power[N[(N[(1.0 / x), $MachinePrecision] + N[(2.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[N[(1.0 / x), $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(t$95$0 * t$95$0 + N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\sqrt{x}}\\
\frac{1}{x \cdot \left(\sqrt[3]{\frac{1}{x} + \frac{2}{x \cdot x}} + \left(\sqrt[3]{\frac{1}{x}} + \sqrt[3]{\mathsf{fma}\left(t\_0, t\_0, \frac{1}{x \cdot x}\right)}\right)\right)}
\end{array}
\end{array}
Initial program 7.1%
Applied rewrites9.4%
Taylor expanded in x around inf
lower-/.f64N/A
lower-*.f64N/A
lower-+.f64N/A
lower-cbrt.f64N/A
lower-+.f64N/A
lower-/.f64N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
unpow2N/A
lower-*.f64N/A
lower-+.f64N/A
Applied rewrites97.9%
Applied rewrites97.9%
Applied rewrites97.9%
Final simplification97.9%
(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 2024230
(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)))