
(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 8 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)))) (/ 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 52.0%
flip3--52.2%
div-inv52.2%
rem-cube-cbrt51.5%
rem-cube-cbrt52.8%
+-commutative52.8%
distribute-rgt-out52.8%
+-commutative52.8%
fma-def52.8%
add-exp-log52.8%
Applied egg-rr50.5%
associate-*r/50.5%
*-rgt-identity50.5%
+-commutative50.5%
associate--l+69.6%
+-inverses69.6%
metadata-eval69.6%
+-commutative69.6%
exp-prod69.3%
Simplified69.3%
sqr-pow69.3%
pow269.3%
metadata-eval69.3%
prod-exp69.3%
pow-prod-down69.7%
sqr-pow69.7%
pow-exp69.6%
*-commutative69.6%
log1p-udef69.6%
pow-to-exp69.4%
pow1/399.2%
+-commutative99.2%
pow299.2%
Applied egg-rr99.2%
unpow199.2%
pow-plus99.2%
+-commutative99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) (exp (* (log1p x) 0.6666666666666666)))))
double code(double x) {
return 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), exp((log1p(x) * 0.6666666666666666)));
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), exp(Float64(log1p(x) * 0.6666666666666666)))) end
code[x_] := N[(1.0 / 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] + N[Exp[N[(N[Log[1 + x], $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, e^{\mathsf{log1p}\left(x\right) \cdot 0.6666666666666666}\right)}
\end{array}
Initial program 52.0%
flip3--52.2%
div-inv52.2%
rem-cube-cbrt51.5%
rem-cube-cbrt52.8%
+-commutative52.8%
distribute-rgt-out52.8%
+-commutative52.8%
fma-def52.8%
add-exp-log52.8%
Applied egg-rr50.5%
associate-*r/50.5%
*-rgt-identity50.5%
+-commutative50.5%
associate--l+69.6%
+-inverses69.6%
metadata-eval69.6%
+-commutative69.6%
exp-prod69.3%
Simplified69.3%
add-exp-log69.3%
log-pow69.6%
rem-log-exp69.6%
Applied egg-rr69.6%
Final simplification69.6%
(FPCore (x) :precision binary64 (/ 1.0 (fma (cbrt x) (+ (cbrt x) (cbrt (+ 1.0 x))) 1.0)))
double code(double x) {
return 1.0 / fma(cbrt(x), (cbrt(x) + cbrt((1.0 + x))), 1.0);
}
function code(x) return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + cbrt(Float64(1.0 + x))), 1.0)) end
code[x_] := N[(1.0 / 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] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, 1\right)}
\end{array}
Initial program 52.0%
flip3--52.2%
div-inv52.2%
rem-cube-cbrt51.5%
rem-cube-cbrt52.8%
+-commutative52.8%
distribute-rgt-out52.8%
+-commutative52.8%
fma-def52.8%
add-exp-log52.8%
Applied egg-rr50.5%
associate-*r/50.5%
*-rgt-identity50.5%
+-commutative50.5%
associate--l+69.6%
+-inverses69.6%
metadata-eval69.6%
+-commutative69.6%
exp-prod69.3%
Simplified69.3%
Taylor expanded in x around 0 57.7%
Final simplification57.7%
(FPCore (x) :precision binary64 (exp (log (- (cbrt (+ 1.0 x)) (cbrt x)))))
double code(double x) {
return exp(log((cbrt((1.0 + x)) - cbrt(x))));
}
public static double code(double x) {
return Math.exp(Math.log((Math.cbrt((1.0 + x)) - Math.cbrt(x))));
}
function code(x) return exp(log(Float64(cbrt(Float64(1.0 + x)) - cbrt(x)))) end
code[x_] := N[Exp[N[Log[N[(N[Power[N[(1.0 + x), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
e^{\log \left(\sqrt[3]{1 + x} - \sqrt[3]{x}\right)}
\end{array}
Initial program 52.0%
add-exp-log52.0%
Applied egg-rr52.0%
Final simplification52.0%
(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 52.0%
Final simplification52.0%
(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 52.0%
add-cube-cbrt51.6%
pow351.6%
Applied egg-rr51.6%
Taylor expanded in x around 0 22.0%
metadata-eval22.0%
pow-base-122.0%
unpow1/349.4%
*-lft-identity49.4%
Simplified49.4%
Final simplification49.4%
(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 52.0%
Taylor expanded in x around inf 3.7%
Final simplification3.7%
(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 52.0%
Taylor expanded in x around 0 49.4%
Final simplification49.4%
herbie shell --seed 2024033
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))