
(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 9 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 (+ (+ (cbrt (pow x 2.0)) (cbrt (* x (+ 1.0 x)))) (pow (cbrt (+ 1.0 x)) 2.0))))
double code(double x) {
return 1.0 / ((cbrt(pow(x, 2.0)) + cbrt((x * (1.0 + x)))) + pow(cbrt((1.0 + x)), 2.0));
}
public static double code(double x) {
return 1.0 / ((Math.cbrt(Math.pow(x, 2.0)) + Math.cbrt((x * (1.0 + x)))) + Math.pow(Math.cbrt((1.0 + x)), 2.0));
}
function code(x) return Float64(1.0 / Float64(Float64(cbrt((x ^ 2.0)) + cbrt(Float64(x * Float64(1.0 + x)))) + (cbrt(Float64(1.0 + x)) ^ 2.0))) end
code[x_] := N[(1.0 / N[(N[(N[Power[N[Power[x, 2.0], $MachinePrecision], 1/3], $MachinePrecision] + N[Power[N[(x * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(\sqrt[3]{{x}^{2}} + \sqrt[3]{x \cdot \left(1 + x\right)}\right) + {\left(\sqrt[3]{1 + x}\right)}^{2}}
\end{array}
Initial program 7.5%
add-exp-log7.5%
Applied egg-rr7.5%
rem-exp-log7.5%
flip3--7.5%
+-commutative7.5%
+-commutative7.5%
rem-cube-cbrt7.7%
rem-cube-cbrt11.1%
div-sub7.9%
Applied egg-rr7.8%
div-sub11.1%
associate--l+98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
fma-define98.4%
+-commutative98.4%
+-commutative98.4%
Simplified98.4%
fma-undefine98.4%
+-commutative98.4%
distribute-rgt-in98.4%
associate-+r+98.4%
pow298.4%
cbrt-unprod98.8%
Applied egg-rr98.8%
associate-+l+98.7%
+-commutative98.7%
*-commutative98.7%
+-commutative98.7%
Simplified98.7%
Taylor expanded in x around 0 99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ 1.0 (+ (pow t_0 2.0) (* (cbrt x) (+ t_0 (cbrt x)))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return 1.0 / (pow(t_0, 2.0) + (cbrt(x) * (t_0 + cbrt(x))));
}
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) * (t_0 + Math.cbrt(x))));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(1.0 / Float64((t_0 ^ 2.0) + Float64(cbrt(x) * Float64(t_0 + cbrt(x))))) 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[(t$95$0 + N[Power[x, 1/3], $MachinePrecision]), $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(t\_0 + \sqrt[3]{x}\right)}
\end{array}
\end{array}
Initial program 7.5%
add-exp-log7.5%
Applied egg-rr7.5%
rem-exp-log7.5%
flip3--7.5%
+-commutative7.5%
+-commutative7.5%
rem-cube-cbrt7.7%
rem-cube-cbrt11.1%
div-sub7.9%
Applied egg-rr7.8%
div-sub11.1%
associate--l+98.4%
+-inverses98.4%
metadata-eval98.4%
+-commutative98.4%
fma-define98.4%
+-commutative98.4%
+-commutative98.4%
Simplified98.4%
fma-undefine98.4%
+-commutative98.4%
+-commutative98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (/ (+ (* (cbrt (/ 1.0 (pow x 2.0))) -0.1111111111111111) (* (cbrt x) 0.3333333333333333)) x))
double code(double x) {
return ((cbrt((1.0 / pow(x, 2.0))) * -0.1111111111111111) + (cbrt(x) * 0.3333333333333333)) / x;
}
public static double code(double x) {
return ((Math.cbrt((1.0 / Math.pow(x, 2.0))) * -0.1111111111111111) + (Math.cbrt(x) * 0.3333333333333333)) / x;
}
function code(x) return Float64(Float64(Float64(cbrt(Float64(1.0 / (x ^ 2.0))) * -0.1111111111111111) + Float64(cbrt(x) * 0.3333333333333333)) / 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[(N[Power[x, 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\sqrt[3]{\frac{1}{{x}^{2}}} \cdot -0.1111111111111111 + \sqrt[3]{x} \cdot 0.3333333333333333}{x}
\end{array}
Initial program 7.5%
add-sqr-sqrt7.8%
add-sqr-sqrt7.3%
difference-of-squares7.4%
pow1/37.4%
sqrt-pow17.4%
metadata-eval7.4%
pow1/37.4%
sqrt-pow17.4%
metadata-eval7.4%
pow1/35.3%
sqrt-pow15.3%
metadata-eval5.3%
pow1/37.5%
sqrt-pow17.4%
metadata-eval7.4%
Applied egg-rr7.4%
Taylor expanded in x around inf 97.7%
associate-+r+97.7%
distribute-rgt-out97.7%
metadata-eval97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (/ 1.0 (cbrt (pow x 2.0)))))
double code(double x) {
return 0.3333333333333333 * (1.0 / cbrt(pow(x, 2.0)));
}
public static double code(double x) {
return 0.3333333333333333 * (1.0 / Math.cbrt(Math.pow(x, 2.0)));
}
function code(x) return Float64(0.3333333333333333 * Float64(1.0 / cbrt((x ^ 2.0)))) end
code[x_] := N[(0.3333333333333333 * N[(1.0 / N[Power[N[Power[x, 2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \frac{1}{\sqrt[3]{{x}^{2}}}
\end{array}
Initial program 7.5%
Taylor expanded in x around inf 96.2%
cbrt-div96.5%
metadata-eval96.5%
Applied egg-rr96.5%
Final simplification96.5%
(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.5%
add-exp-log7.5%
Applied egg-rr7.5%
Taylor expanded in x around inf 96.2%
*-commutative96.2%
exp-to-pow90.9%
*-commutative90.9%
rec-exp90.9%
mul-1-neg90.9%
associate-*r*90.9%
metadata-eval90.9%
*-commutative90.9%
exp-to-pow96.2%
Simplified96.2%
Final simplification96.2%
(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}
\\
\frac{0.3333333333333333}{\sqrt[3]{{x}^{2}}}
\end{array}
Initial program 7.5%
Taylor expanded in x around inf 96.2%
cbrt-div96.5%
metadata-eval96.5%
unpow296.5%
cbrt-prod95.8%
un-div-inv95.8%
cbrt-prod96.5%
unpow296.5%
Applied egg-rr96.5%
Final simplification96.5%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (cbrt (* (/ 1.0 x) (/ 1.0 x)))))
double code(double x) {
return 0.3333333333333333 * cbrt(((1.0 / x) * (1.0 / x)));
}
public static double code(double x) {
return 0.3333333333333333 * Math.cbrt(((1.0 / x) * (1.0 / x)));
}
function code(x) return Float64(0.3333333333333333 * cbrt(Float64(Float64(1.0 / x) * Float64(1.0 / x)))) end
code[x_] := N[(0.3333333333333333 * N[Power[N[(N[(1.0 / x), $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \sqrt[3]{\frac{1}{x} \cdot \frac{1}{x}}
\end{array}
Initial program 7.5%
Taylor expanded in x around inf 96.2%
add-sqr-sqrt96.2%
sqrt-div96.2%
metadata-eval96.2%
sqrt-pow196.2%
metadata-eval96.2%
pow196.2%
sqrt-div96.2%
metadata-eval96.2%
sqrt-pow196.2%
metadata-eval96.2%
pow196.2%
Applied egg-rr96.2%
Final simplification96.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 7.5%
Taylor expanded in x around inf 96.2%
pow1/389.6%
pow-flip89.6%
pow-pow89.6%
metadata-eval89.6%
metadata-eval89.6%
Applied egg-rr89.6%
Final simplification89.6%
(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 7.5%
Taylor expanded in x around 0 1.7%
sub-neg1.7%
rem-square-sqrt0.0%
fabs-sqr0.0%
rem-square-sqrt6.8%
fabs-neg6.8%
unpow1/36.8%
metadata-eval6.8%
pow-sqr6.8%
fabs-sqr6.8%
pow-sqr6.8%
metadata-eval6.8%
unpow1/36.8%
Simplified6.8%
Taylor expanded in x around inf 6.8%
Final simplification6.8%
(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 2024083
(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)))