
(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 (sqrt x))) (t_1 (cbrt (+ 1.0 x)))) (/ (+ 1.0 (- x x)) (fma (cbrt x) (+ (* t_0 t_0) t_1) (pow t_1 2.0)))))
double code(double x) {
double t_0 = cbrt(sqrt(x));
double t_1 = cbrt((1.0 + x));
return (1.0 + (x - x)) / fma(cbrt(x), ((t_0 * t_0) + t_1), pow(t_1, 2.0));
}
function code(x) t_0 = cbrt(sqrt(x)) t_1 = cbrt(Float64(1.0 + x)) return Float64(Float64(1.0 + Float64(x - x)) / fma(cbrt(x), Float64(Float64(t_0 * t_0) + t_1), (t_1 ^ 2.0))) end
code[x_] := Block[{t$95$0 = N[Power[N[Sqrt[x], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = 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[(t$95$0 * t$95$0), $MachinePrecision] + t$95$1), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{\sqrt{x}}\\
t_1 := \sqrt[3]{1 + x}\\
\frac{1 + \left(x - x\right)}{\mathsf{fma}\left(\sqrt[3]{x}, t\_0 \cdot t\_0 + t\_1, {t\_1}^{2}\right)}
\end{array}
\end{array}
Initial program 6.8%
add-exp-log5.9%
pow1/34.7%
log-pow4.8%
+-commutative4.8%
log1p-udef4.8%
Applied egg-rr4.8%
*-commutative4.8%
exp-prod4.9%
unpow1/36.0%
Simplified6.0%
log1p-udef6.0%
add-exp-log6.8%
+-commutative6.8%
flip3--7.2%
div-inv7.2%
add-sqr-sqrt7.2%
cbrt-unprod6.7%
pow36.3%
add-cube-cbrt6.0%
cbrt-unprod6.1%
add-sqr-sqrt6.0%
rem-cube-cbrt9.0%
Applied egg-rr9.0%
associate-*r/9.0%
*-rgt-identity9.0%
+-commutative9.0%
associate--l+98.5%
+-commutative98.5%
fma-def98.6%
+-commutative98.6%
+-commutative98.6%
+-commutative98.6%
Simplified98.6%
pow1/394.5%
add-sqr-sqrt94.5%
unpow-prod-down94.5%
pow-prod-up94.5%
metadata-eval94.5%
Applied egg-rr94.5%
*-rgt-identity94.5%
metadata-eval94.5%
pow-sqr94.5%
unpow1/395.9%
*-rgt-identity95.9%
unpow1/398.6%
*-rgt-identity98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 0.0)
(/
1.0
(fma (cbrt x) (+ (cbrt x) t_0) (sqrt (+ 1.0 (* x 1.3333333333333333)))))
(+
(pow (pow (+ 1.0 x) 2.0) 0.16666666666666666)
(- 0.0 (pow x 0.3333333333333333))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((t_0 - cbrt(x)) <= 0.0) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), sqrt((1.0 + (x * 1.3333333333333333))));
} else {
tmp = pow(pow((1.0 + x), 2.0), 0.16666666666666666) + (0.0 - pow(x, 0.3333333333333333));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - cbrt(x)) <= 0.0) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), sqrt(Float64(1.0 + Float64(x * 1.3333333333333333))))); else tmp = Float64(((Float64(1.0 + x) ^ 2.0) ^ 0.16666666666666666) + Float64(0.0 - (x ^ 0.3333333333333333))); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[Sqrt[N[(1.0 + N[(x * 1.3333333333333333), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision] + N[(0.0 - N[Power[x, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;t\_0 - \sqrt[3]{x} \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t\_0, \sqrt{1 + x \cdot 1.3333333333333333}\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(1 + x\right)}^{2}\right)}^{0.16666666666666666} + \left(0 - {x}^{0.3333333333333333}\right)\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
flip3--4.2%
div-inv4.2%
rem-cube-cbrt3.2%
rem-cube-cbrt4.2%
+-commutative4.2%
distribute-rgt-out4.2%
+-commutative4.2%
fma-def4.2%
add-exp-log4.2%
Applied egg-rr4.2%
associate-*r/4.2%
*-rgt-identity4.2%
+-commutative4.2%
associate--l+92.9%
+-inverses92.9%
metadata-eval92.9%
+-commutative92.9%
exp-prod91.9%
Simplified91.9%
add-sqr-sqrt91.9%
sqrt-unprod69.8%
pow-prod-down70.7%
prod-exp70.7%
metadata-eval70.7%
Applied egg-rr70.7%
Taylor expanded in x around 0 20.0%
*-commutative20.0%
Simplified20.0%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 56.6%
pow1/353.5%
Applied egg-rr53.5%
pow1/358.6%
sqr-pow57.1%
pow-prod-down58.8%
pow258.8%
metadata-eval58.8%
Applied egg-rr58.8%
Final simplification21.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (cbrt (+ 1.0 x))))
(if (<= (- t_0 (cbrt x)) 0.0)
(/ 1.0 (fma (cbrt x) (+ (cbrt x) t_0) 1.0))
(+
(pow (pow (+ 1.0 x) 2.0) 0.16666666666666666)
(- 0.0 (pow x 0.3333333333333333))))))
double code(double x) {
double t_0 = cbrt((1.0 + x));
double tmp;
if ((t_0 - cbrt(x)) <= 0.0) {
tmp = 1.0 / fma(cbrt(x), (cbrt(x) + t_0), 1.0);
} else {
tmp = pow(pow((1.0 + x), 2.0), 0.16666666666666666) + (0.0 - pow(x, 0.3333333333333333));
}
return tmp;
}
function code(x) t_0 = cbrt(Float64(1.0 + x)) tmp = 0.0 if (Float64(t_0 - cbrt(x)) <= 0.0) tmp = Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), 1.0)); else tmp = Float64(((Float64(1.0 + x) ^ 2.0) ^ 0.16666666666666666) + Float64(0.0 - (x ^ 0.3333333333333333))); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision], 0.0], N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[Power[N[(1.0 + x), $MachinePrecision], 2.0], $MachinePrecision], 0.16666666666666666], $MachinePrecision] + N[(0.0 - N[Power[x, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\mathbf{if}\;t\_0 - \sqrt[3]{x} \leq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t\_0, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(1 + x\right)}^{2}\right)}^{0.16666666666666666} + \left(0 - {x}^{0.3333333333333333}\right)\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
flip3--4.2%
div-inv4.2%
rem-cube-cbrt3.2%
rem-cube-cbrt4.2%
+-commutative4.2%
distribute-rgt-out4.2%
+-commutative4.2%
fma-def4.2%
add-exp-log4.2%
Applied egg-rr4.2%
associate-*r/4.2%
*-rgt-identity4.2%
+-commutative4.2%
associate--l+92.9%
+-inverses92.9%
metadata-eval92.9%
+-commutative92.9%
exp-prod91.9%
Simplified91.9%
Taylor expanded in x around 0 20.0%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 56.6%
pow1/353.5%
Applied egg-rr53.5%
pow1/358.6%
sqr-pow57.1%
pow-prod-down58.8%
pow258.8%
metadata-eval58.8%
Applied egg-rr58.8%
Final simplification21.9%
(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 6.8%
add-exp-log5.9%
pow1/34.7%
log-pow4.8%
+-commutative4.8%
log1p-udef4.8%
Applied egg-rr4.8%
*-commutative4.8%
exp-prod4.9%
unpow1/36.0%
Simplified6.0%
*-un-lft-identity6.0%
exp-prod4.9%
Applied egg-rr4.9%
exp-1-e4.9%
Simplified4.9%
Applied egg-rr9.0%
associate-*r/9.0%
*-rgt-identity9.0%
associate--l+98.6%
+-inverses98.6%
metadata-eval98.6%
+-commutative98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (+ 1.0 x)))) (/ (+ 1.0 (- x x)) (+ (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 + (x - x)) / (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 + (x - x)) / (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(Float64(1.0 + Float64(x - x)) / 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[(N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision] / 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 + \left(x - x\right)}{{t\_0}^{2} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t\_0\right)}
\end{array}
\end{array}
Initial program 6.8%
add-exp-log5.9%
pow1/34.7%
log-pow4.8%
+-commutative4.8%
log1p-udef4.8%
Applied egg-rr4.8%
*-commutative4.8%
exp-prod4.9%
unpow1/36.0%
Simplified6.0%
log1p-udef6.0%
add-exp-log6.8%
+-commutative6.8%
flip3--7.2%
div-inv7.2%
add-sqr-sqrt7.2%
cbrt-unprod6.7%
pow36.3%
add-cube-cbrt6.0%
cbrt-unprod6.1%
add-sqr-sqrt6.0%
rem-cube-cbrt9.0%
Applied egg-rr9.0%
associate-*r/9.0%
*-rgt-identity9.0%
+-commutative9.0%
associate--l+98.5%
+-commutative98.5%
fma-def98.6%
+-commutative98.6%
+-commutative98.6%
+-commutative98.6%
Simplified98.6%
fma-udef98.5%
+-commutative98.5%
+-commutative98.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x) :precision binary64 (let* ((t_0 (- (cbrt (+ 1.0 x)) (cbrt x)))) (if (<= t_0 0.0) 1.0 t_0)))
double code(double x) {
double t_0 = cbrt((1.0 + x)) - cbrt(x);
double tmp;
if (t_0 <= 0.0) {
tmp = 1.0;
} 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 = 1.0;
} 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 = 1.0; 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], 1.0, t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{1 + x} - \sqrt[3]{x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.2%
Taylor expanded in x around 0 5.9%
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 56.6%
Final simplification8.5%
(FPCore (x) :precision binary64 (- (cbrt (+ 1.0 x)) (* (cbrt (sqrt x)) (pow x 0.16666666666666666))))
double code(double x) {
return cbrt((1.0 + x)) - (cbrt(sqrt(x)) * pow(x, 0.16666666666666666));
}
public static double code(double x) {
return Math.cbrt((1.0 + x)) - (Math.cbrt(Math.sqrt(x)) * Math.pow(x, 0.16666666666666666));
}
function code(x) return Float64(cbrt(Float64(1.0 + x)) - Float64(cbrt(sqrt(x)) * (x ^ 0.16666666666666666))) end
code[x_] := N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[(N[Power[N[Sqrt[x], $MachinePrecision], 1/3], $MachinePrecision] * N[Power[x, 0.16666666666666666], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{1 + x} - \sqrt[3]{\sqrt{x}} \cdot {x}^{0.16666666666666666}
\end{array}
Initial program 6.8%
pow1/37.9%
*-rgt-identity7.9%
add-sqr-sqrt7.9%
associate-*l*7.9%
unpow-prod-down7.9%
pow1/27.8%
pow-pow7.8%
metadata-eval7.8%
Applied egg-rr7.8%
unpow1/37.9%
*-rgt-identity7.9%
Simplified7.9%
Final simplification7.9%
(FPCore (x) :precision binary64 (+ (cbrt (+ 1.0 x)) (- 0.0 (pow x 0.3333333333333333))))
double code(double x) {
return cbrt((1.0 + x)) + (0.0 - pow(x, 0.3333333333333333));
}
public static double code(double x) {
return Math.cbrt((1.0 + x)) + (0.0 - Math.pow(x, 0.3333333333333333));
}
function code(x) return Float64(cbrt(Float64(1.0 + x)) + Float64(0.0 - (x ^ 0.3333333333333333))) end
code[x_] := N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] + N[(0.0 - N[Power[x, 0.3333333333333333], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{1 + x} + \left(0 - {x}^{0.3333333333333333}\right)
\end{array}
Initial program 6.8%
pow1/37.9%
Applied egg-rr7.9%
Final simplification7.9%
(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.8%
Taylor expanded in x around inf 4.1%
Final simplification4.1%
(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.8%
Taylor expanded in x around 0 6.3%
Final simplification6.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 2024026
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:herbie-target
(/ 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)))