
(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 (/ (+ (cbrt (* x 0.037037037037037035)) (* -0.1111111111111111 (pow x -0.6666666666666666))) x))
double code(double x) {
return (cbrt((x * 0.037037037037037035)) + (-0.1111111111111111 * pow(x, -0.6666666666666666))) / x;
}
public static double code(double x) {
return (Math.cbrt((x * 0.037037037037037035)) + (-0.1111111111111111 * Math.pow(x, -0.6666666666666666))) / x;
}
function code(x) return Float64(Float64(cbrt(Float64(x * 0.037037037037037035)) + Float64(-0.1111111111111111 * (x ^ -0.6666666666666666))) / x) end
code[x_] := N[(N[(N[Power[N[(x * 0.037037037037037035), $MachinePrecision], 1/3], $MachinePrecision] + N[(-0.1111111111111111 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x \cdot 0.037037037037037035} + -0.1111111111111111 \cdot {x}^{-0.6666666666666666}}{x}
\end{array}
Initial program 6.4%
add-sqr-sqrt6.0%
add-sqr-sqrt6.3%
difference-of-squares6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/33.9%
sqrt-pow13.9%
metadata-eval3.9%
pow1/36.2%
sqrt-pow16.4%
metadata-eval6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 98.5%
*-un-lft-identity98.5%
Applied egg-rr98.7%
associate-*r/98.7%
*-lft-identity98.7%
*-commutative98.7%
Simplified98.7%
pow1/398.7%
pow-pow98.7%
metadata-eval98.7%
Applied egg-rr98.7%
(FPCore (x) :precision binary64 (/ (* (cbrt x) 0.3333333333333333) x))
double code(double x) {
return (cbrt(x) * 0.3333333333333333) / x;
}
public static double code(double x) {
return (Math.cbrt(x) * 0.3333333333333333) / x;
}
function code(x) return Float64(Float64(cbrt(x) * 0.3333333333333333) / x) end
code[x_] := N[(N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{x} \cdot 0.3333333333333333}{x}
\end{array}
Initial program 6.4%
add-sqr-sqrt6.0%
add-sqr-sqrt6.3%
difference-of-squares6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/33.9%
sqrt-pow13.9%
metadata-eval3.9%
pow1/36.2%
sqrt-pow16.4%
metadata-eval6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around inf 97.7%
*-commutative97.7%
Simplified97.7%
(FPCore (x) :precision binary64 (* (cbrt x) (/ 0.3333333333333333 x)))
double code(double x) {
return cbrt(x) * (0.3333333333333333 / x);
}
public static double code(double x) {
return Math.cbrt(x) * (0.3333333333333333 / x);
}
function code(x) return Float64(cbrt(x) * Float64(0.3333333333333333 / x)) end
code[x_] := N[(N[Power[x, 1/3], $MachinePrecision] * N[(0.3333333333333333 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{x} \cdot \frac{0.3333333333333333}{x}
\end{array}
Initial program 6.4%
add-sqr-sqrt6.0%
add-sqr-sqrt6.3%
difference-of-squares6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/33.9%
sqrt-pow13.9%
metadata-eval3.9%
pow1/36.2%
sqrt-pow16.4%
metadata-eval6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around inf 97.7%
*-commutative97.7%
Simplified97.7%
associate-/l*97.7%
*-commutative97.7%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (/ (cbrt x) x)))
double code(double x) {
return 0.3333333333333333 * (cbrt(x) / x);
}
public static double code(double x) {
return 0.3333333333333333 * (Math.cbrt(x) / x);
}
function code(x) return Float64(0.3333333333333333 * Float64(cbrt(x) / x)) end
code[x_] := N[(0.3333333333333333 * N[(N[Power[x, 1/3], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \frac{\sqrt[3]{x}}{x}
\end{array}
Initial program 6.4%
add-sqr-sqrt6.0%
add-sqr-sqrt6.3%
difference-of-squares6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/36.3%
sqrt-pow16.3%
metadata-eval6.3%
pow1/33.9%
sqrt-pow13.9%
metadata-eval3.9%
pow1/36.2%
sqrt-pow16.4%
metadata-eval6.4%
Applied egg-rr6.4%
Taylor expanded in x around inf 98.5%
Taylor expanded in x around inf 97.7%
*-commutative97.7%
Simplified97.7%
associate-/l*97.7%
Applied egg-rr97.7%
*-commutative97.7%
associate-*l/97.7%
associate-*r/97.6%
Simplified97.6%
(FPCore (x) :precision binary64 (+ (cbrt x) 1.0))
double code(double x) {
return cbrt(x) + 1.0;
}
public static double code(double x) {
return Math.cbrt(x) + 1.0;
}
function code(x) return Float64(cbrt(x) + 1.0) end
code[x_] := N[(N[Power[x, 1/3], $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{x} + 1
\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.3%
fabs-neg5.3%
unpow1/35.3%
metadata-eval5.3%
pow-sqr5.3%
fabs-sqr5.3%
pow-sqr5.3%
metadata-eval5.3%
unpow1/35.3%
Simplified5.3%
Final simplification5.3%
(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 2024113
(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)))