| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 52228 |

(FPCore (x) :precision binary64 (- (cbrt (+ x 1.0)) (cbrt x)))
(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) (cbrt x)) (pow t_0 2.0)))
(/
(- (+ 1.0 x) x)
(+ (cbrt (pow (+ 1.0 x) 2.0)) (* (cbrt x) (+ (cbrt x) t_0)))))))double code(double x) {
return cbrt((x + 1.0)) - cbrt(x);
}
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) + cbrt(x)), pow(t_0, 2.0));
} else {
tmp = ((1.0 + x) - x) / (cbrt(pow((1.0 + x), 2.0)) + (cbrt(x) * (cbrt(x) + t_0)));
}
return tmp;
}
function code(x) return Float64(cbrt(Float64(x + 1.0)) - cbrt(x)) end
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) + cbrt(x)), (t_0 ^ 2.0))); else tmp = Float64(Float64(Float64(1.0 + x) - x) / Float64(cbrt((Float64(1.0 + x) ^ 2.0)) + Float64(cbrt(x) * Float64(cbrt(x) + t_0)))); end return tmp end
code[x_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], 1/3], $MachinePrecision] - N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision]
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] + N[Power[x, 1/3], $MachinePrecision]), $MachinePrecision] + N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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] + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\sqrt[3]{x + 1} - \sqrt[3]{x}
\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} + \sqrt[3]{x}, {t_0}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + x\right) - x}{\sqrt[3]{{\left(1 + x\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)}\\
\end{array}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
if (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) < 0.0Initial program 4.1%
Applied egg-rr4.1%
[Start]4.1% | \[ \sqrt[3]{x + 1} - \sqrt[3]{x}
\] |
|---|---|
flip3-- [=>]4.1% | \[ \color{blue}{\frac{{\left(\sqrt[3]{x + 1}\right)}^{3} - {\left(\sqrt[3]{x}\right)}^{3}}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}}
\] |
div-inv [=>]4.1% | \[ \color{blue}{\left({\left(\sqrt[3]{x + 1}\right)}^{3} - {\left(\sqrt[3]{x}\right)}^{3}\right) \cdot \frac{1}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}}
\] |
rem-cube-cbrt [=>]3.9% | \[ \left(\color{blue}{\left(x + 1\right)} - {\left(\sqrt[3]{x}\right)}^{3}\right) \cdot \frac{1}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
rem-cube-cbrt [=>]4.1% | \[ \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
cbrt-unprod [=>]4.1% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\color{blue}{\sqrt[3]{\left(x + 1\right) \cdot \left(x + 1\right)}} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
pow2 [=>]4.1% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt[3]{\color{blue}{{\left(x + 1\right)}^{2}}} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
distribute-rgt-out [=>]4.1% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \color{blue}{\sqrt[3]{x} \cdot \left(\sqrt[3]{x} + \sqrt[3]{x + 1}\right)}}
\] |
+-commutative [<=]4.1% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \color{blue}{\left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}}
\] |
Simplified49.5%
[Start]4.1% | \[ \left(\left(x + 1\right) - x\right) \cdot \frac{1}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
|---|---|
associate-*r/ [=>]4.1% | \[ \color{blue}{\frac{\left(\left(x + 1\right) - x\right) \cdot 1}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}}
\] |
*-rgt-identity [=>]4.1% | \[ \frac{\color{blue}{\left(x + 1\right) - x}}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
+-commutative [=>]4.1% | \[ \frac{\color{blue}{\left(1 + x\right)} - x}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
associate--l+ [=>]49.5% | \[ \frac{\color{blue}{1 + \left(x - x\right)}}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
+-inverses [=>]49.5% | \[ \frac{1 + \color{blue}{0}}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
metadata-eval [=>]49.5% | \[ \frac{\color{blue}{1}}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}
\] |
+-commutative [=>]49.5% | \[ \frac{1}{\color{blue}{\sqrt[3]{x} \cdot \left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right) + \sqrt[3]{{\left(x + 1\right)}^{2}}}}
\] |
fma-def [=>]49.5% | \[ \frac{1}{\color{blue}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x + 1} + \sqrt[3]{x}, \sqrt[3]{{\left(x + 1\right)}^{2}}\right)}}
\] |
+-commutative [=>]49.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{\color{blue}{1 + x}} + \sqrt[3]{x}, \sqrt[3]{{\left(x + 1\right)}^{2}}\right)}
\] |
+-commutative [=>]49.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{{\color{blue}{\left(1 + x\right)}}^{2}}\right)}
\] |
Applied egg-rr94.1%
[Start]49.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)}
\] |
|---|---|
+-commutative [=>]49.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{{\color{blue}{\left(x + 1\right)}}^{2}}\right)}
\] |
expm1-log1p-u [=>]47.7% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt[3]{{\left(x + 1\right)}^{2}}\right)\right)}\right)}
\] |
expm1-udef [=>]47.7% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{e^{\mathsf{log1p}\left(\sqrt[3]{{\left(x + 1\right)}^{2}}\right)} - 1}\right)}
\] |
pow1/3 [=>]47.3% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\color{blue}{{\left({\left(x + 1\right)}^{2}\right)}^{0.3333333333333333}}\right)} - 1\right)}
\] |
+-commutative [<=]47.3% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left({\left({\color{blue}{\left(1 + x\right)}}^{2}\right)}^{0.3333333333333333}\right)} - 1\right)}
\] |
unpow2 [=>]47.3% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left({\color{blue}{\left(\left(1 + x\right) \cdot \left(1 + x\right)\right)}}^{0.3333333333333333}\right)} - 1\right)}
\] |
pow-prod-down [<=]42.2% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\color{blue}{{\left(1 + x\right)}^{0.3333333333333333} \cdot {\left(1 + x\right)}^{0.3333333333333333}}\right)} - 1\right)}
\] |
+-commutative [=>]42.2% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left({\color{blue}{\left(x + 1\right)}}^{0.3333333333333333} \cdot {\left(1 + x\right)}^{0.3333333333333333}\right)} - 1\right)}
\] |
pow1/3 [<=]42.4% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\color{blue}{\sqrt[3]{x + 1}} \cdot {\left(1 + x\right)}^{0.3333333333333333}\right)} - 1\right)}
\] |
+-commutative [=>]42.4% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\sqrt[3]{x + 1} \cdot {\color{blue}{\left(x + 1\right)}}^{0.3333333333333333}\right)} - 1\right)}
\] |
pow1/3 [<=]94.1% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\sqrt[3]{x + 1} \cdot \color{blue}{\sqrt[3]{x + 1}}\right)} - 1\right)}
\] |
pow2 [=>]94.1% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left(\color{blue}{{\left(\sqrt[3]{x + 1}\right)}^{2}}\right)} - 1\right)}
\] |
+-commutative [<=]94.1% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left({\left(\sqrt[3]{\color{blue}{1 + x}}\right)}^{2}\right)} - 1\right)}
\] |
Simplified98.6%
[Start]94.1% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, e^{\mathsf{log1p}\left({\left(\sqrt[3]{1 + x}\right)}^{2}\right)} - 1\right)}
\] |
|---|---|
expm1-def [=>]94.1% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(\sqrt[3]{1 + x}\right)}^{2}\right)\right)}\right)}
\] |
expm1-log1p [=>]98.6% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{{\left(\sqrt[3]{1 + x}\right)}^{2}}\right)}
\] |
Applied egg-rr98.5%
[Start]98.6% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
|---|---|
+-commutative [=>]98.6% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{\color{blue}{x + 1}} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
add-cube-cbrt [=>]98.4% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \color{blue}{\left(\sqrt[3]{\sqrt[3]{x + 1}} \cdot \sqrt[3]{\sqrt[3]{x + 1}}\right) \cdot \sqrt[3]{\sqrt[3]{x + 1}}} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
pow3 [=>]98.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \color{blue}{{\left(\sqrt[3]{\sqrt[3]{x + 1}}\right)}^{3}} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
+-commutative [<=]98.5% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, {\left(\sqrt[3]{\sqrt[3]{\color{blue}{1 + x}}}\right)}^{3} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
Taylor expanded in x around inf 42.6%
Simplified98.6%
[Start]42.6% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, {x}^{0.3333333333333333} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
|---|---|
unpow1/3 [=>]98.6% | \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \color{blue}{\sqrt[3]{x}} + \sqrt[3]{x}, {\left(\sqrt[3]{1 + x}\right)}^{2}\right)}
\] |
if 0.0 < (-.f64 (cbrt.f64 (+.f64 x 1)) (cbrt.f64 x)) Initial program 98.3%
Applied egg-rr99.9%
[Start]98.3% | \[ \sqrt[3]{x + 1} - \sqrt[3]{x}
\] |
|---|---|
flip3-- [=>]98.2% | \[ \color{blue}{\frac{{\left(\sqrt[3]{x + 1}\right)}^{3} - {\left(\sqrt[3]{x}\right)}^{3}}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}}
\] |
rem-cube-cbrt [=>]98.1% | \[ \frac{\color{blue}{\left(x + 1\right)} - {\left(\sqrt[3]{x}\right)}^{3}}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
rem-cube-cbrt [=>]99.8% | \[ \frac{\left(x + 1\right) - \color{blue}{x}}{\sqrt[3]{x + 1} \cdot \sqrt[3]{x + 1} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
cbrt-unprod [=>]99.9% | \[ \frac{\left(x + 1\right) - x}{\color{blue}{\sqrt[3]{\left(x + 1\right) \cdot \left(x + 1\right)}} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
pow2 [=>]99.9% | \[ \frac{\left(x + 1\right) - x}{\sqrt[3]{\color{blue}{{\left(x + 1\right)}^{2}}} + \left(\sqrt[3]{x} \cdot \sqrt[3]{x} + \sqrt[3]{x + 1} \cdot \sqrt[3]{x}\right)}
\] |
distribute-rgt-out [=>]99.9% | \[ \frac{\left(x + 1\right) - x}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \color{blue}{\sqrt[3]{x} \cdot \left(\sqrt[3]{x} + \sqrt[3]{x + 1}\right)}}
\] |
+-commutative [<=]99.9% | \[ \frac{\left(x + 1\right) - x}{\sqrt[3]{{\left(x + 1\right)}^{2}} + \sqrt[3]{x} \cdot \color{blue}{\left(\sqrt[3]{x + 1} + \sqrt[3]{x}\right)}}
\] |
Final simplification99.2%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 52228 |
| Alternative 2 | |
|---|---|
| Accuracy | 75.7% |
| Cost | 45892 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 39168 |
| Alternative 4 | |
|---|---|
| Accuracy | 87.6% |
| Cost | 33032 |
| Alternative 5 | |
|---|---|
| Accuracy | 59.7% |
| Cost | 32640 |
| Alternative 6 | |
|---|---|
| Accuracy | 59.4% |
| Cost | 26176 |
| Alternative 7 | |
|---|---|
| Accuracy | 54.1% |
| Cost | 13120 |
| Alternative 8 | |
|---|---|
| Accuracy | 3.6% |
| Cost | 64 |
| Alternative 9 | |
|---|---|
| Accuracy | 50.4% |
| Cost | 64 |
herbie shell --seed 2023178
(FPCore (x)
:name "2cbrt (problem 3.3.4)"
:precision binary64
(- (cbrt (+ x 1.0)) (cbrt x)))