
(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 10 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))))
(if (<= x 2.3e+15)
(/
(- (+ 1.0 x) x)
(+
(cbrt (pow (+ 1.0 x) 2.0))
(* (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))))))
(/ 1.0 (* x (+ t_0 (* 2.0 t_0)))))))
double code(double x) {
double t_0 = cbrt((1.0 / x));
double tmp;
if (x <= 2.3e+15) {
tmp = ((1.0 + x) - x) / (cbrt(pow((1.0 + x), 2.0)) + (cbrt(x) * (cbrt(x) + cbrt((1.0 + x)))));
} else {
tmp = 1.0 / (x * (t_0 + (2.0 * t_0)));
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 / x));
double tmp;
if (x <= 2.3e+15) {
tmp = ((1.0 + x) - x) / (Math.cbrt(Math.pow((1.0 + x), 2.0)) + (Math.cbrt(x) * (Math.cbrt(x) + Math.cbrt((1.0 + x)))));
} else {
tmp = 1.0 / (x * (t_0 + (2.0 * t_0)));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 / x)) tmp = 0.0 if (x <= 2.3e+15) tmp = Float64(Float64(Float64(1.0 + x) - x) / Float64(cbrt((Float64(1.0 + x) ^ 2.0)) + Float64(cbrt(x) * Float64(cbrt(x) + cbrt(Float64(1.0 + x)))))); else tmp = Float64(1.0 / Float64(x * Float64(t_0 + Float64(2.0 * t_0)))); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 / x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[x, 2.3e+15], N[(N[(N[(1.0 + x), $MachinePrecision] - x), $MachinePrecision] / N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $MachinePrecision], 1/3], $MachinePrecision] + N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(x * N[(t$95$0 + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{1}{x}}\\
\mathbf{if}\;x \leq 2.3 \cdot 10^{+15}:\\
\;\;\;\;\frac{\left(1 + x\right) - x}{\sqrt[3]{{\left(1 + x\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + \sqrt[3]{1 + x}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x \cdot \left(t\_0 + 2 \cdot t\_0\right)}\\
\end{array}
\end{array}
if x < 2.3e15Initial program 64.5%
pow1/363.9%
add-sqr-sqrt64.2%
pow264.2%
pow-pow64.5%
metadata-eval64.5%
Applied egg-rr64.5%
sqrt-pow263.9%
metadata-eval63.9%
pow1/364.5%
flip3--68.8%
rem-cube-cbrt71.1%
rem-cube-cbrt98.5%
cbrt-unprod98.9%
pow298.9%
distribute-rgt-out99.1%
Applied egg-rr99.1%
if 2.3e15 < x Initial program 4.3%
flip3--4.3%
div-inv4.3%
rem-cube-cbrt3.4%
rem-cube-cbrt4.6%
+-commutative4.6%
distribute-rgt-out4.6%
+-commutative4.6%
fma-define4.6%
add-exp-log4.6%
Applied egg-rr4.6%
associate-*r/4.6%
*-rgt-identity4.6%
+-commutative4.6%
associate--l+92.6%
+-inverses92.6%
metadata-eval92.6%
+-commutative92.6%
exp-prod92.0%
Simplified92.0%
Taylor expanded in x around inf 92.0%
Taylor expanded in x around inf 98.9%
Final simplification98.9%
(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 6.7%
flip3--6.8%
div-inv6.8%
rem-cube-cbrt6.0%
rem-cube-cbrt8.3%
+-commutative8.3%
distribute-rgt-out8.3%
+-commutative8.3%
fma-define8.3%
add-exp-log8.3%
Applied egg-rr8.3%
associate-*r/8.3%
*-rgt-identity8.3%
+-commutative8.3%
associate--l+92.8%
+-inverses92.8%
metadata-eval92.8%
+-commutative92.8%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.7%
Applied egg-rr93.7%
pow-sqr93.7%
Simplified93.7%
sqr-pow93.7%
pow293.7%
pow-to-exp92.8%
*-commutative92.8%
associate-/l*92.8%
metadata-eval92.8%
*-commutative92.8%
*-un-lft-identity92.8%
pow1/292.8%
log-pow92.8%
rem-log-exp92.8%
metadata-eval92.8%
log1p-undefine92.8%
+-commutative92.8%
log-pow93.1%
pow1/393.7%
add-exp-log98.4%
pow298.4%
Applied egg-rr98.4%
pow1/394.3%
+-commutative94.3%
add-sqr-sqrt94.3%
unpow-prod-down94.3%
Applied egg-rr94.3%
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) (* t_0 t_0)))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
return 1.0 / fma(cbrt(x), (cbrt(x) + t_0), (t_0 * t_0));
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), Float64(t_0 * 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[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[(t$95$0 * t$95$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 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 6.7%
flip3--6.8%
div-inv6.8%
rem-cube-cbrt6.0%
rem-cube-cbrt8.3%
+-commutative8.3%
distribute-rgt-out8.3%
+-commutative8.3%
fma-define8.3%
add-exp-log8.3%
Applied egg-rr8.3%
associate-*r/8.3%
*-rgt-identity8.3%
+-commutative8.3%
associate--l+92.8%
+-inverses92.8%
metadata-eval92.8%
+-commutative92.8%
exp-prod92.2%
Simplified92.2%
add-sqr-sqrt92.2%
unpow-prod-down93.7%
Applied egg-rr93.7%
pow-sqr93.7%
Simplified93.7%
sqr-pow93.7%
pow293.7%
pow-to-exp92.8%
*-commutative92.8%
associate-/l*92.8%
metadata-eval92.8%
*-commutative92.8%
*-un-lft-identity92.8%
pow1/292.8%
log-pow92.8%
rem-log-exp92.8%
metadata-eval92.8%
log1p-undefine92.8%
+-commutative92.8%
log-pow93.1%
pow1/393.7%
add-exp-log98.4%
pow298.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (x) :precision binary64 (let* ((t_0 (- (cbrt (+ 1.0 x)) (cbrt x)))) (if (<= t_0 0.0) (pow (+ x (+ x -1.0)) -0.5) t_0)))
double code(double x) {
double t_0 = cbrt((1.0 + x)) - cbrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = pow((x + (x + -1.0)), -0.5);
} else {
tmp = t_0;
}
return tmp;
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 + x)) - Math.cbrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = Math.pow((x + (x + -1.0)), -0.5);
} else {
tmp = t_0;
}
return tmp;
}
function code(x) t_0 = Float64(cbrt(Float64(1.0 + x)) - cbrt(x)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(x + Float64(x + -1.0)) ^ -0.5; else tmp = t_0; end return tmp end
code[x_] := Block[{t$95$0 = N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[Power[N[(x + N[(x + -1.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision], t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} - \sqrt[3]{x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;{\left(x + \left(x + -1\right)\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x #s(literal 1 binary64))) (cbrt.f64 x)) < 0.0Initial program 4.2%
pow1/35.3%
add-sqr-sqrt5.3%
pow25.3%
pow-pow5.3%
metadata-eval5.3%
Applied egg-rr5.3%
pow1/34.1%
Applied egg-rr4.1%
Applied egg-rr8.9%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x #s(literal 1 binary64))) (cbrt.f64 x)) Initial program 66.2%
Final simplification11.1%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (/ 1.0 x)))) (/ 1.0 (* x (+ t_0 (* 2.0 t_0))))))
double code(double x) {
double t_0 = cbrt((1.0 / x));
return 1.0 / (x * (t_0 + (2.0 * t_0)));
}
public static double code(double x) {
double t_0 = Math.cbrt((1.0 / x));
return 1.0 / (x * (t_0 + (2.0 * t_0)));
}
function code(x) t_0 = cbrt(Float64(1.0 / x)) return Float64(1.0 / Float64(x * Float64(t_0 + Float64(2.0 * t_0)))) end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 / x), $MachinePrecision], 1/3], $MachinePrecision]}, N[(1.0 / N[(x * N[(t$95$0 + N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{1}{x}}\\
\frac{1}{x \cdot \left(t\_0 + 2 \cdot t\_0\right)}
\end{array}
\end{array}
Initial program 6.7%
flip3--6.8%
div-inv6.8%
rem-cube-cbrt6.0%
rem-cube-cbrt8.3%
+-commutative8.3%
distribute-rgt-out8.3%
+-commutative8.3%
fma-define8.3%
add-exp-log8.3%
Applied egg-rr8.3%
associate-*r/8.3%
*-rgt-identity8.3%
+-commutative8.3%
associate--l+92.8%
+-inverses92.8%
metadata-eval92.8%
+-commutative92.8%
exp-prod92.2%
Simplified92.2%
Taylor expanded in x around inf 90.5%
Taylor expanded in x around inf 97.1%
Final simplification97.1%
(FPCore (x) :precision binary64 (* 0.3333333333333333 (cbrt (/ 1.0 (pow x 2.0)))))
double code(double x) {
return 0.3333333333333333 * cbrt((1.0 / pow(x, 2.0)));
}
public static double code(double x) {
return 0.3333333333333333 * Math.cbrt((1.0 / Math.pow(x, 2.0)));
}
function code(x) return Float64(0.3333333333333333 * cbrt(Float64(1.0 / (x ^ 2.0)))) end
code[x_] := N[(0.3333333333333333 * N[Power[N[(1.0 / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.3333333333333333 \cdot \sqrt[3]{\frac{1}{{x}^{2}}}
\end{array}
Initial program 6.7%
Taylor expanded in x around inf 49.5%
Final simplification49.5%
(FPCore (x) :precision binary64 (pow (+ x (+ x -1.0)) -0.5))
double code(double x) {
return pow((x + (x + -1.0)), -0.5);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (x + (-1.0d0))) ** (-0.5d0)
end function
public static double code(double x) {
return Math.pow((x + (x + -1.0)), -0.5);
}
def code(x): return math.pow((x + (x + -1.0)), -0.5)
function code(x) return Float64(x + Float64(x + -1.0)) ^ -0.5 end
function tmp = code(x) tmp = (x + (x + -1.0)) ^ -0.5; end
code[x_] := N[Power[N[(x + N[(x + -1.0), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision]
\begin{array}{l}
\\
{\left(x + \left(x + -1\right)\right)}^{-0.5}
\end{array}
Initial program 6.7%
pow1/37.6%
add-sqr-sqrt7.6%
pow27.6%
pow-pow7.6%
metadata-eval7.6%
Applied egg-rr7.6%
pow1/36.5%
Applied egg-rr6.5%
Applied egg-rr9.1%
Final simplification9.1%
(FPCore (x) :precision binary64 (/ 1.0 (+ 1.0 (* x 2.0))))
double code(double x) {
return 1.0 / (1.0 + (x * 2.0));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (1.0d0 + (x * 2.0d0))
end function
public static double code(double x) {
return 1.0 / (1.0 + (x * 2.0));
}
def code(x): return 1.0 / (1.0 + (x * 2.0))
function code(x) return Float64(1.0 / Float64(1.0 + Float64(x * 2.0))) end
function tmp = code(x) tmp = 1.0 / (1.0 + (x * 2.0)); end
code[x_] := N[(1.0 / N[(1.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + x \cdot 2}
\end{array}
Initial program 6.7%
pow1/37.6%
add-sqr-sqrt7.6%
pow27.6%
pow-pow7.6%
metadata-eval7.6%
Applied egg-rr7.6%
pow1/36.5%
Applied egg-rr6.5%
Applied egg-rr7.7%
exp-prod7.7%
unpow-17.7%
log1p-undefine7.7%
rem-exp-log7.7%
count-27.7%
*-commutative7.7%
Simplified7.7%
Final simplification7.7%
(FPCore (x) :precision binary64 (+ x (+ x -1.0)))
double code(double x) {
return x + (x + -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (x + (-1.0d0))
end function
public static double code(double x) {
return x + (x + -1.0);
}
def code(x): return x + (x + -1.0)
function code(x) return Float64(x + Float64(x + -1.0)) end
function tmp = code(x) tmp = x + (x + -1.0); end
code[x_] := N[(x + N[(x + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(x + -1\right)
\end{array}
Initial program 6.7%
pow1/37.6%
add-sqr-sqrt7.6%
pow27.6%
pow-pow7.6%
metadata-eval7.6%
Applied egg-rr7.6%
pow1/36.5%
Applied egg-rr6.5%
Applied egg-rr4.0%
Final simplification4.0%
(FPCore (x) :precision binary64 -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 6.7%
pow1/37.6%
add-sqr-sqrt7.6%
pow27.6%
pow-pow7.6%
metadata-eval7.6%
Applied egg-rr7.6%
pow1/36.5%
Applied egg-rr6.5%
Applied egg-rr4.1%
fma-undefine4.1%
neg-mul-14.1%
+-commutative4.1%
sub-neg4.1%
associate--l+2.0%
*-rgt-identity2.0%
metadata-eval2.0%
distribute-rgt-out--2.0%
count-22.0%
*-lft-identity2.0%
associate--r+2.0%
+-inverses2.0%
metadata-eval2.0%
Simplified2.0%
Final simplification2.0%
(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 2024059
(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)))