
(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 (- x x)) (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 + (x - x)) / fma(cbrt(x), (cbrt(x) + t_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), (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[Power[t$95$0, 2.0], $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, {t\_0}^{2}\right)}
\end{array}
\end{array}
Initial program 6.1%
flip3--6.1%
div-inv6.1%
rem-cube-cbrt5.5%
rem-cube-cbrt7.6%
+-commutative7.6%
distribute-rgt-out7.6%
+-commutative7.6%
fma-define7.6%
add-exp-log7.6%
Applied egg-rr7.6%
associate-*r/7.6%
*-rgt-identity7.6%
+-commutative7.6%
associate--l+92.9%
+-commutative92.9%
+-commutative92.9%
Simplified92.9%
*-commutative92.9%
log1p-undefine92.9%
exp-to-pow92.9%
metadata-eval92.9%
pow-sqr92.9%
+-commutative92.9%
pow1/394.3%
+-commutative94.3%
pow1/398.5%
pow298.5%
+-commutative98.5%
Applied egg-rr98.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.1%
flip3--6.1%
div-inv6.1%
rem-cube-cbrt5.5%
rem-cube-cbrt7.6%
+-commutative7.6%
distribute-rgt-out7.6%
+-commutative7.6%
fma-define7.6%
add-exp-log7.6%
Applied egg-rr7.6%
associate-*r/7.6%
*-rgt-identity7.6%
+-commutative7.6%
associate--l+92.9%
+-commutative92.9%
+-commutative92.9%
Simplified92.9%
*-commutative92.9%
log1p-undefine92.9%
exp-to-pow92.9%
metadata-eval92.9%
pow-sqr92.9%
+-commutative92.9%
pow1/394.3%
+-commutative94.3%
pow1/398.5%
pow298.5%
+-commutative98.5%
Applied egg-rr98.5%
fma-undefine98.5%
+-commutative98.5%
Applied egg-rr98.5%
Taylor expanded in x around 0 98.5%
(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}
\\
\frac{0.3333333333333333}{{\left(\sqrt[3]{x}\right)}^{2}}
\end{array}
Initial program 6.1%
Taylor expanded in x around inf 46.0%
cbrt-div46.1%
metadata-eval46.1%
un-div-inv46.1%
unpow246.1%
cbrt-prod97.1%
pow297.1%
Applied egg-rr97.1%
(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 6.1%
Taylor expanded in x around inf 46.0%
add-sqr-sqrt46.0%
pow246.0%
*-commutative46.0%
sqrt-prod45.8%
cbrt-div46.0%
metadata-eval46.0%
sqrt-div45.9%
metadata-eval45.9%
unpow245.9%
cbrt-prod96.7%
sqrt-unprod96.5%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
unpow-prod-down96.9%
inv-pow96.9%
pow-pow97.1%
metadata-eval97.1%
pow297.1%
rem-square-sqrt97.1%
Applied egg-rr97.1%
Final simplification97.1%
(FPCore (x) :precision binary64 (if (<= x 1.35e+154) (* 0.3333333333333333 (cbrt (/ 1.0 (* x x)))) (* 0.3333333333333333 (pow x -0.6666666666666666))))
double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = 0.3333333333333333 * cbrt((1.0 / (x * x)));
} else {
tmp = 0.3333333333333333 * pow(x, -0.6666666666666666);
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.35e+154) {
tmp = 0.3333333333333333 * Math.cbrt((1.0 / (x * x)));
} else {
tmp = 0.3333333333333333 * Math.pow(x, -0.6666666666666666);
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.35e+154) tmp = Float64(0.3333333333333333 * cbrt(Float64(1.0 / Float64(x * x)))); else tmp = Float64(0.3333333333333333 * (x ^ -0.6666666666666666)); end return tmp end
code[x_] := If[LessEqual[x, 1.35e+154], N[(0.3333333333333333 * N[Power[N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], N[(0.3333333333333333 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;0.3333333333333333 \cdot \sqrt[3]{\frac{1}{x \cdot x}}\\
\mathbf{else}:\\
\;\;\;\;0.3333333333333333 \cdot {x}^{-0.6666666666666666}\\
\end{array}
\end{array}
if x < 1.35000000000000003e154Initial program 7.8%
Taylor expanded in x around inf 95.9%
unpow295.9%
Applied egg-rr95.9%
if 1.35000000000000003e154 < x Initial program 4.7%
Taylor expanded in x around inf 4.7%
pow1/34.7%
pow-flip7.3%
pow-pow89.2%
metadata-eval89.2%
metadata-eval89.2%
Applied egg-rr89.2%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (pow x -0.6666666666666666)))
double code(double x) {
return 0.3333333333333333 * pow(x, -0.6666666666666666);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.3333333333333333d0 * (x ** (-0.6666666666666666d0))
end function
public static double code(double x) {
return 0.3333333333333333 * Math.pow(x, -0.6666666666666666);
}
def code(x): return 0.3333333333333333 * math.pow(x, -0.6666666666666666)
function code(x) return Float64(0.3333333333333333 * (x ^ -0.6666666666666666)) end
function tmp = code(x) tmp = 0.3333333333333333 * (x ^ -0.6666666666666666); end
code[x_] := N[(0.3333333333333333 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot {x}^{-0.6666666666666666}
\end{array}
Initial program 6.1%
Taylor expanded in x around inf 46.0%
pow1/343.1%
pow-flip44.5%
pow-pow89.2%
metadata-eval89.2%
metadata-eval89.2%
Applied egg-rr89.2%
(FPCore (x) :precision binary64 (cbrt x))
double code(double x) {
return cbrt(x);
}
public static double code(double x) {
return Math.cbrt(x);
}
function code(x) return cbrt(x) end
code[x_] := N[Power[x, 1/3], $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{x}
\end{array}
Initial program 6.1%
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%
Taylor expanded in x around inf 5.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 2024157
(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)))