
(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 (/ (+ (* (cbrt (/ 1.0 (pow x 2.0))) -0.1111111111111111) (cbrt (* x 0.037037037037037035))) x))
double code(double x) {
return ((cbrt((1.0 / pow(x, 2.0))) * -0.1111111111111111) + cbrt((x * 0.037037037037037035))) / x;
}
public static double code(double x) {
return ((Math.cbrt((1.0 / Math.pow(x, 2.0))) * -0.1111111111111111) + Math.cbrt((x * 0.037037037037037035))) / x;
}
function code(x) return Float64(Float64(Float64(cbrt(Float64(1.0 / (x ^ 2.0))) * -0.1111111111111111) + cbrt(Float64(x * 0.037037037037037035))) / x) end
code[x_] := N[(N[(N[(N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * -0.1111111111111111), $MachinePrecision] + N[Power[N[(x * 0.037037037037037035), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{\frac{1}{{x}^{2}}} \cdot -0.1111111111111111 + \sqrt[3]{x \cdot 0.037037037037037035}}{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%
associate-+r+98.5%
distribute-rgt-out98.5%
metadata-eval98.5%
*-commutative98.5%
Simplified98.5%
expm1-log1p-u92.7%
expm1-undefine92.7%
Applied egg-rr92.7%
expm1-define92.7%
Simplified92.7%
expm1-log1p-u98.5%
add-cbrt-cube98.4%
pow1/391.5%
pow391.5%
unpow-prod-down91.5%
rem-cube-cbrt91.5%
metadata-eval91.5%
Applied egg-rr91.5%
unpow1/398.7%
Simplified98.7%
(FPCore (x) :precision binary64 (/ (+ (* -0.1111111111111111 (pow x -0.6666666666666666)) (* (cbrt x) 0.3333333333333333)) x))
double code(double x) {
return ((-0.1111111111111111 * pow(x, -0.6666666666666666)) + (cbrt(x) * 0.3333333333333333)) / x;
}
public static double code(double x) {
return ((-0.1111111111111111 * Math.pow(x, -0.6666666666666666)) + (Math.cbrt(x) * 0.3333333333333333)) / x;
}
function code(x) return Float64(Float64(Float64(-0.1111111111111111 * (x ^ -0.6666666666666666)) + Float64(cbrt(x) * 0.3333333333333333)) / x) end
code[x_] := N[(N[(N[(-0.1111111111111111 * N[Power[x, -0.6666666666666666], $MachinePrecision]), $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{-0.1111111111111111 \cdot {x}^{-0.6666666666666666} + \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%
associate-+r+98.5%
distribute-rgt-out98.5%
metadata-eval98.5%
*-commutative98.5%
Simplified98.5%
pow1/398.5%
pow-flip98.5%
pow-pow98.5%
metadata-eval98.5%
metadata-eval98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (/ 1.0 (* 3.0 (pow (cbrt x) 2.0))))
double code(double x) {
return 1.0 / (3.0 * pow(cbrt(x), 2.0));
}
public static double code(double x) {
return 1.0 / (3.0 * Math.pow(Math.cbrt(x), 2.0));
}
function code(x) return Float64(1.0 / Float64(3.0 * (cbrt(x) ^ 2.0))) end
code[x_] := N[(1.0 / N[(3.0 * N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{3 \cdot {\left(\sqrt[3]{x}\right)}^{2}}
\end{array}
Initial program 6.4%
flip3--6.6%
div-inv6.6%
rem-cube-cbrt6.3%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.1%
+-inverses93.1%
metadata-eval93.1%
+-commutative93.1%
exp-prod92.2%
Simplified92.2%
Taylor expanded in x around inf 22.9%
distribute-rgt1-in22.9%
metadata-eval22.9%
Simplified22.9%
/-rgt-identity22.9%
Applied egg-rr23.6%
Simplified97.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.4%
flip3--6.6%
div-inv6.6%
rem-cube-cbrt6.3%
rem-cube-cbrt8.6%
+-commutative8.6%
distribute-rgt-out8.6%
+-commutative8.6%
fma-define8.6%
add-exp-log8.6%
Applied egg-rr8.6%
associate-*r/8.6%
*-rgt-identity8.6%
+-commutative8.6%
associate--l+93.1%
+-inverses93.1%
metadata-eval93.1%
+-commutative93.1%
exp-prod92.2%
Simplified92.2%
Taylor expanded in x around inf 22.9%
distribute-rgt1-in22.9%
metadata-eval22.9%
Simplified22.9%
associate-/r*22.8%
add-cbrt-cube14.3%
frac-times14.3%
metadata-eval14.3%
pow-prod-up14.3%
metadata-eval14.3%
cbrt-prod22.1%
*-un-lft-identity22.1%
times-frac22.1%
pow-flip22.1%
metadata-eval22.1%
pow-flip22.1%
metadata-eval22.1%
Applied egg-rr23.3%
/-rgt-identity23.3%
associate-*r/23.3%
times-frac23.3%
*-inverses53.0%
*-commutative53.0%
associate-*l/53.0%
associate-/l*52.8%
unpow1/349.5%
exp-to-pow49.7%
*-commutative49.7%
exp-prod89.4%
associate-*l*89.4%
rem-log-exp89.4%
exp-to-pow89.7%
unpow1/390.5%
*-commutative90.5%
exp-to-pow97.0%
metadata-eval97.0%
Simplified97.0%
Final simplification97.0%
(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 6.4%
pow1/37.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 51.4%
exp-to-pow48.7%
*-commutative48.7%
rec-exp50.1%
mul-1-neg50.1%
associate-*r*50.1%
metadata-eval50.1%
*-commutative50.1%
exp-to-pow52.8%
Simplified52.8%
(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 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%
(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 6.4%
Taylor expanded in x around inf 4.1%
Taylor expanded in x around 0 4.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 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)))