
(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 6 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 (sqrt (+ 1.0 x)))) (t_1 (cbrt (+ 1.0 x)))) (/ 1.0 (fma (cbrt x) (+ (cbrt x) (* t_0 t_0)) (* t_1 t_1)))))
double code(double x) {
double t_0 = cbrt(sqrt((1.0 + x)));
double t_1 = cbrt((1.0 + x));
return 1.0 / fma(cbrt(x), (cbrt(x) + (t_0 * t_0)), (t_1 * t_1));
}
function code(x) t_0 = cbrt(sqrt(Float64(1.0 + x))) t_1 = cbrt(Float64(1.0 + x)) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + Float64(t_0 * t_0)), Float64(t_1 * t_1))) end
code[x_] := Block[{t$95$0 = N[Power[N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = 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] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\sqrt{1 + x}}\\
t_1 := \sqrt[3]{1 + x}\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t\_0 \cdot t\_0, t\_1 \cdot t\_1\right)}
\end{array}
\end{array}
Initial program 7.6%
flip3--7.7%
div-inv7.7%
rem-cube-cbrt7.0%
rem-cube-cbrt10.5%
+-commutative10.5%
distribute-rgt-out10.5%
+-commutative10.5%
fma-define10.5%
add-exp-log10.5%
Applied egg-rr10.5%
associate-*r/10.5%
*-rgt-identity10.5%
+-commutative10.5%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.7%
Applied egg-rr93.7%
pow-sqr93.7%
Simplified93.7%
*-commutative93.7%
pow-unpow93.7%
pow1/293.7%
pow-exp93.7%
metadata-eval93.7%
pow293.7%
add-exp-log93.6%
pow-to-exp93.4%
prod-exp93.2%
pow-exp93.2%
add-log-exp93.2%
log1p-undefine93.2%
+-commutative93.2%
log-pow93.2%
pow1/393.6%
rem-log-exp93.6%
log1p-undefine93.6%
+-commutative93.6%
log-pow94.0%
pow1/394.2%
Applied egg-rr98.5%
pow1/394.4%
add-sqr-sqrt94.4%
unpow-prod-down94.4%
+-commutative94.4%
+-commutative94.4%
Applied egg-rr94.4%
unpow1/395.7%
+-commutative95.7%
unpow1/398.5%
+-commutative98.5%
Simplified98.5%
Final simplification98.5%
(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.6%
flip3--7.7%
div-inv7.7%
rem-cube-cbrt7.0%
rem-cube-cbrt10.5%
+-commutative10.5%
distribute-rgt-out10.5%
+-commutative10.5%
fma-define10.5%
add-exp-log10.5%
Applied egg-rr10.5%
associate-*r/10.5%
*-rgt-identity10.5%
+-commutative10.5%
associate--l+93.2%
+-inverses93.2%
metadata-eval93.2%
+-commutative93.2%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.7%
Applied egg-rr93.7%
pow-sqr93.7%
Simplified93.7%
*-commutative93.7%
pow-unpow93.7%
pow1/293.7%
pow-exp93.7%
metadata-eval93.7%
pow293.7%
add-exp-log93.6%
pow-to-exp93.4%
prod-exp93.2%
pow-exp93.2%
add-log-exp93.2%
log1p-undefine93.2%
+-commutative93.2%
log-pow93.2%
pow1/393.6%
rem-log-exp93.6%
log1p-undefine93.6%
+-commutative93.6%
log-pow94.0%
pow1/394.2%
Applied egg-rr98.5%
pow298.5%
Applied egg-rr98.5%
Final simplification98.5%
(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.6%
add-sqr-sqrt7.3%
add-sqr-sqrt7.5%
difference-of-squares7.6%
pow1/37.6%
sqrt-pow17.6%
metadata-eval7.6%
pow1/37.6%
sqrt-pow17.6%
metadata-eval7.6%
pow1/35.0%
sqrt-pow15.0%
metadata-eval5.0%
pow1/37.6%
sqrt-pow17.6%
metadata-eval7.6%
Applied egg-rr7.6%
Taylor expanded in x around inf 97.9%
associate-+r+97.9%
distribute-rgt-out97.9%
metadata-eval97.9%
*-commutative97.9%
Simplified97.9%
(FPCore (x) :precision binary64 (* (cbrt (/ 1.0 (pow x 2.0))) 0.3333333333333333))
double code(double x) {
return cbrt((1.0 / pow(x, 2.0))) * 0.3333333333333333;
}
public static double code(double x) {
return Math.cbrt((1.0 / Math.pow(x, 2.0))) * 0.3333333333333333;
}
function code(x) return Float64(cbrt(Float64(1.0 / (x ^ 2.0))) * 0.3333333333333333) end
code[x_] := N[(N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{\frac{1}{{x}^{2}}} \cdot 0.3333333333333333
\end{array}
Initial program 7.6%
Taylor expanded in x around inf 49.5%
Final simplification49.5%
(FPCore (x) :precision binary64 (- (cbrt (+ 1.0 x)) (cbrt x)))
double code(double x) {
return cbrt((1.0 + x)) - cbrt(x);
}
public static double code(double x) {
return Math.cbrt((1.0 + x)) - Math.cbrt(x);
}
function code(x) return Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) end
code[x_] := N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{1 + x} - \sqrt[3]{x}
\end{array}
Initial program 7.6%
Final simplification7.6%
(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.6%
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 (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 2024100
(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)))