
(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 5 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 (pow x -1.0))) (t_1 (pow (- x -1.0) 0.3333333333333333)))
(if (<= x 2e+14)
(/
(- (- x -1.0) x)
(fma
t_1
t_1
(*
(pow x 0.3333333333333333)
(fma (pow x 0.3333333333333333) 1.0 t_1))))
(* (* t_0 t_0) 0.3333333333333333))))
double code(double x) {
double t_0 = cbrt(pow(x, -1.0));
double t_1 = pow((x - -1.0), 0.3333333333333333);
double tmp;
if (x <= 2e+14) {
tmp = ((x - -1.0) - x) / fma(t_1, t_1, (pow(x, 0.3333333333333333) * fma(pow(x, 0.3333333333333333), 1.0, t_1)));
} else {
tmp = (t_0 * t_0) * 0.3333333333333333;
}
return tmp;
}
function code(x) t_0 = cbrt((x ^ -1.0)) t_1 = Float64(x - -1.0) ^ 0.3333333333333333 tmp = 0.0 if (x <= 2e+14) tmp = Float64(Float64(Float64(x - -1.0) - x) / fma(t_1, t_1, Float64((x ^ 0.3333333333333333) * fma((x ^ 0.3333333333333333), 1.0, t_1)))); else tmp = Float64(Float64(t_0 * t_0) * 0.3333333333333333); end return tmp end
code[x_] := Block[{t$95$0 = N[Power[N[Power[x, -1.0], $MachinePrecision], 1/3], $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(x - -1.0), $MachinePrecision], 0.3333333333333333], $MachinePrecision]}, If[LessEqual[x, 2e+14], N[(N[(N[(x - -1.0), $MachinePrecision] - x), $MachinePrecision] / N[(t$95$1 * t$95$1 + N[(N[Power[x, 0.3333333333333333], $MachinePrecision] * N[(N[Power[x, 0.3333333333333333], $MachinePrecision] * 1.0 + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * t$95$0), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{{x}^{-1}}\\
t_1 := {\left(x - -1\right)}^{0.3333333333333333}\\
\mathbf{if}\;x \leq 2 \cdot 10^{+14}:\\
\;\;\;\;\frac{\left(x - -1\right) - x}{\mathsf{fma}\left(t\_1, t\_1, {x}^{0.3333333333333333} \cdot \mathsf{fma}\left({x}^{0.3333333333333333}, 1, t\_1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 \cdot t\_0\right) \cdot 0.3333333333333333\\
\end{array}
\end{array}
if x < 2e14Initial program 52.6%
lift--.f64N/A
lift-+.f64N/A
lift-cbrt.f64N/A
lift-cbrt.f64N/A
flip3--N/A
lower-/.f64N/A
rem-cube-cbrtN/A
rem-cube-cbrtN/A
lower--.f64N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lower-fma.f64N/A
Applied rewrites96.3%
if 2e14 < x Initial program 4.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6445.5
Applied rewrites45.5%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval51.6
Applied rewrites51.6%
lift-cbrt.f64N/A
lift-pow.f64N/A
metadata-evalN/A
pow-flipN/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
count-2-revN/A
log-prodN/A
exp-prodN/A
unpow1/3N/A
pow-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-*.f64N/A
log-prodN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-log.f6490.7
Applied rewrites90.7%
lift-exp.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
exp-prodN/A
*-commutativeN/A
count-2-revN/A
exp-prodN/A
count-2-revN/A
*-commutativeN/A
pow-to-expN/A
pow2N/A
pow1/3N/A
unpow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6498.1
Applied rewrites98.1%
(FPCore (x) :precision binary64 (let* ((t_0 (cbrt (pow x -1.0)))) (* (* t_0 t_0) 0.3333333333333333)))
double code(double x) {
double t_0 = cbrt(pow(x, -1.0));
return (t_0 * t_0) * 0.3333333333333333;
}
public static double code(double x) {
double t_0 = Math.cbrt(Math.pow(x, -1.0));
return (t_0 * t_0) * 0.3333333333333333;
}
function code(x) t_0 = cbrt((x ^ -1.0)) return Float64(Float64(t_0 * t_0) * 0.3333333333333333) end
code[x_] := Block[{t$95$0 = N[Power[N[Power[x, -1.0], $MachinePrecision], 1/3], $MachinePrecision]}, N[(N[(t$95$0 * t$95$0), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt[3]{{x}^{-1}}\\
\left(t\_0 \cdot t\_0\right) \cdot 0.3333333333333333
\end{array}
\end{array}
Initial program 7.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6446.7
Applied rewrites46.7%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval52.5
Applied rewrites52.5%
lift-cbrt.f64N/A
lift-pow.f64N/A
metadata-evalN/A
pow-flipN/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
count-2-revN/A
log-prodN/A
exp-prodN/A
unpow1/3N/A
pow-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-*.f64N/A
log-prodN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-log.f6489.3
Applied rewrites89.3%
lift-exp.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-log.f64N/A
exp-prodN/A
*-commutativeN/A
count-2-revN/A
exp-prodN/A
count-2-revN/A
*-commutativeN/A
pow-to-expN/A
pow2N/A
pow1/3N/A
unpow-prod-downN/A
lift-pow.f64N/A
lift-pow.f64N/A
cbrt-prodN/A
lower-*.f64N/A
lower-cbrt.f64N/A
lower-cbrt.f6496.2
Applied rewrites96.2%
(FPCore (x)
:precision binary64
(if (<= x 1.75e+155)
(* (cbrt (pow x -2.0)) 0.3333333333333333)
(*
(exp (* (* (* (log x) 2.0) -1.0) 0.3333333333333333))
0.3333333333333333)))
double code(double x) {
double tmp;
if (x <= 1.75e+155) {
tmp = cbrt(pow(x, -2.0)) * 0.3333333333333333;
} else {
tmp = exp((((log(x) * 2.0) * -1.0) * 0.3333333333333333)) * 0.3333333333333333;
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.75e+155) {
tmp = Math.cbrt(Math.pow(x, -2.0)) * 0.3333333333333333;
} else {
tmp = Math.exp((((Math.log(x) * 2.0) * -1.0) * 0.3333333333333333)) * 0.3333333333333333;
}
return tmp;
}
function code(x) tmp = 0.0 if (x <= 1.75e+155) tmp = Float64(cbrt((x ^ -2.0)) * 0.3333333333333333); else tmp = Float64(exp(Float64(Float64(Float64(log(x) * 2.0) * -1.0) * 0.3333333333333333)) * 0.3333333333333333); end return tmp end
code[x_] := If[LessEqual[x, 1.75e+155], N[(N[Power[N[Power[x, -2.0], $MachinePrecision], 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision], N[(N[Exp[N[(N[(N[(N[Log[x], $MachinePrecision] * 2.0), $MachinePrecision] * -1.0), $MachinePrecision] * 0.3333333333333333), $MachinePrecision]], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.75 \cdot 10^{+155}:\\
\;\;\;\;\sqrt[3]{{x}^{-2}} \cdot 0.3333333333333333\\
\mathbf{else}:\\
\;\;\;\;e^{\left(\left(\log x \cdot 2\right) \cdot -1\right) \cdot 0.3333333333333333} \cdot 0.3333333333333333\\
\end{array}
\end{array}
if x < 1.74999999999999992e155Initial program 9.2%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6487.4
Applied rewrites87.4%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval95.0
Applied rewrites95.0%
if 1.74999999999999992e155 < x Initial program 4.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f644.8
Applied rewrites4.8%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval8.7
Applied rewrites8.7%
lift-cbrt.f64N/A
lift-pow.f64N/A
metadata-evalN/A
pow-flipN/A
inv-powN/A
pow-to-expN/A
*-commutativeN/A
count-2-revN/A
log-prodN/A
exp-prodN/A
unpow1/3N/A
pow-expN/A
lower-exp.f64N/A
lower-*.f64N/A
lower-*.f64N/A
log-prodN/A
count-2-revN/A
*-commutativeN/A
lower-*.f64N/A
lift-log.f6489.2
Applied rewrites89.2%
(FPCore (x) :precision binary64 (* (cbrt (pow x -2.0)) 0.3333333333333333))
double code(double x) {
return cbrt(pow(x, -2.0)) * 0.3333333333333333;
}
public static double code(double x) {
return Math.cbrt(Math.pow(x, -2.0)) * 0.3333333333333333;
}
function code(x) return Float64(cbrt((x ^ -2.0)) * 0.3333333333333333) end
code[x_] := N[(N[Power[N[Power[x, -2.0], $MachinePrecision], 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{{x}^{-2}} \cdot 0.3333333333333333
\end{array}
Initial program 7.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6446.7
Applied rewrites46.7%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval52.5
Applied rewrites52.5%
(FPCore (x) :precision binary64 (* (cbrt (* (pow x -1.0) (* (pow x -0.5) (pow x -0.5)))) 0.3333333333333333))
double code(double x) {
return cbrt((pow(x, -1.0) * (pow(x, -0.5) * pow(x, -0.5)))) * 0.3333333333333333;
}
public static double code(double x) {
return Math.cbrt((Math.pow(x, -1.0) * (Math.pow(x, -0.5) * Math.pow(x, -0.5)))) * 0.3333333333333333;
}
function code(x) return Float64(cbrt(Float64((x ^ -1.0) * Float64((x ^ -0.5) * (x ^ -0.5)))) * 0.3333333333333333) end
code[x_] := N[(N[Power[N[(N[Power[x, -1.0], $MachinePrecision] * N[(N[Power[x, -0.5], $MachinePrecision] * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision] * 0.3333333333333333), $MachinePrecision]
\begin{array}{l}
\\
\sqrt[3]{{x}^{-1} \cdot \left({x}^{-0.5} \cdot {x}^{-0.5}\right)} \cdot 0.3333333333333333
\end{array}
Initial program 7.0%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
pow1/3N/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f64N/A
unpow2N/A
lower-*.f6446.7
Applied rewrites46.7%
lift-pow.f64N/A
lift-*.f64N/A
lift-pow.f64N/A
unpow1/3N/A
lower-cbrt.f64N/A
pow2N/A
inv-powN/A
pow-flipN/A
lower-pow.f64N/A
metadata-eval52.5
Applied rewrites52.5%
lift-pow.f64N/A
sqr-powN/A
metadata-evalN/A
inv-powN/A
metadata-evalN/A
inv-powN/A
lower-*.f64N/A
inv-powN/A
lower-pow.f64N/A
inv-powN/A
lower-pow.f6452.5
Applied rewrites52.5%
lift-pow.f64N/A
sqr-powN/A
lower-*.f64N/A
lower-pow.f64N/A
metadata-evalN/A
lower-pow.f64N/A
metadata-eval52.5
Applied rewrites52.5%
herbie shell --seed 2025064
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
:pre (and (> x 1.0) (< x 1e+308))
:alt
(! :herbie-platform c (/ 1 (+ (* (cbrt (+ x 1)) (cbrt (+ x 1))) (* (cbrt x) (cbrt (+ x 1))) (* (cbrt x) (cbrt x)))))
(- (cbrt (+ x 1.0)) (cbrt x)))