
(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) (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 7.4%
add-cbrt-cube7.4%
pow1/37.4%
pow37.4%
Applied egg-rr7.4%
unpow1/37.4%
rem-cbrt-cube7.4%
flip3--7.7%
rem-cube-cbrt7.3%
rem-cube-cbrt10.8%
div-sub7.7%
Applied egg-rr7.7%
div-sub10.8%
+-commutative10.8%
associate--l+98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
fma-define98.4%
+-commutative98.4%
+-commutative98.4%
+-commutative98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x)
:precision binary64
(/
(+
(* -0.1388888888888889 (pow x -0.6666666666666666))
(+
(* (pow x -0.6666666666666666) 0.027777777777777776)
(* (cbrt x) 0.3333333333333333)))
x))
double code(double x) {
return ((-0.1388888888888889 * pow(x, -0.6666666666666666)) + ((pow(x, -0.6666666666666666) * 0.027777777777777776) + (cbrt(x) * 0.3333333333333333))) / x;
}
public static double code(double x) {
return ((-0.1388888888888889 * Math.pow(x, -0.6666666666666666)) + ((Math.pow(x, -0.6666666666666666) * 0.027777777777777776) + (Math.cbrt(x) * 0.3333333333333333))) / x;
}
function code(x) return Float64(Float64(Float64(-0.1388888888888889 * (x ^ -0.6666666666666666)) + Float64(Float64((x ^ -0.6666666666666666) * 0.027777777777777776) + Float64(cbrt(x) * 0.3333333333333333))) / x) end
code[x_] := N[(N[(N[(-0.1388888888888889 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[x, -0.6666666666666666], $MachinePrecision] * 0.027777777777777776), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.1388888888888889 \cdot {x}^{-0.6666666666666666} + \left({x}^{-0.6666666666666666} \cdot 0.027777777777777776 + \sqrt[3]{x} \cdot 0.3333333333333333\right)}{x}
\end{array}
Initial program 7.4%
add-sqr-sqrt7.1%
add-sqr-sqrt7.2%
difference-of-squares7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
pow1/37.2%
sqrt-pow17.3%
metadata-eval7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 98.3%
pow1/398.3%
pow-flip98.3%
pow-pow98.3%
metadata-eval98.3%
metadata-eval98.3%
Applied egg-rr98.3%
pow1/398.3%
pow-flip98.3%
pow-pow98.3%
metadata-eval98.3%
metadata-eval98.3%
Applied egg-rr98.3%
Final simplification98.3%
(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 7.4%
add-sqr-sqrt7.1%
add-sqr-sqrt7.2%
difference-of-squares7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/37.2%
sqrt-pow17.2%
metadata-eval7.2%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
pow1/37.2%
sqrt-pow17.3%
metadata-eval7.3%
Applied egg-rr7.3%
Taylor expanded in x around inf 98.3%
associate-+r+98.3%
distribute-rgt-out98.3%
metadata-eval98.3%
Simplified98.3%
Final simplification98.3%
(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 7.4%
add-sqr-sqrt7.1%
fma-neg6.9%
pow1/35.0%
sqrt-pow15.0%
metadata-eval5.0%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
Applied egg-rr4.9%
Taylor expanded in x around inf 53.1%
exp-to-pow50.3%
*-commutative50.3%
rec-exp51.4%
*-commutative51.4%
distribute-rgt-neg-in51.4%
metadata-eval51.4%
exp-to-pow54.2%
Simplified54.2%
Final simplification54.2%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (pow (cbrt x) -2.0)))
double code(double x) {
return 0.3333333333333333 * pow(cbrt(x), -2.0);
}
public static double code(double x) {
return 0.3333333333333333 * Math.pow(Math.cbrt(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, 1/3], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot {\left(\sqrt[3]{x}\right)}^{-2}
\end{array}
Initial program 7.4%
add-sqr-sqrt7.1%
fma-neg6.9%
pow1/35.0%
sqrt-pow15.0%
metadata-eval5.0%
pow1/34.9%
sqrt-pow14.9%
metadata-eval4.9%
Applied egg-rr4.9%
Taylor expanded in x around inf 53.1%
exp-to-pow50.3%
*-commutative50.3%
rec-exp51.4%
*-commutative51.4%
distribute-rgt-neg-in51.4%
metadata-eval51.4%
exp-to-pow54.2%
unpow1/350.9%
exp-to-pow51.1%
*-commutative51.1%
exp-prod89.4%
associate-*l*89.4%
*-commutative89.4%
exp-prod89.4%
exp-to-pow88.9%
unpow1/396.3%
Simplified96.3%
Final simplification96.3%
(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 7.4%
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%
Final simplification5.5%
(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 7.4%
pow1/38.4%
pow-to-exp7.7%
Applied egg-rr7.7%
Taylor expanded in x around inf 5.2%
Taylor expanded in x around 0 4.1%
Final simplification4.1%
(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 2024053
(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)))