2cbrt (problem 3.3.4)

?

Percentage Accurate: 53.0% → 99.1%
Time: 11.3s
Precision: binary64
Cost: 65280

?

\[\sqrt[3]{x + 1} - \sqrt[3]{x} \]
\[\begin{array}{l} t_0 := \sqrt[3]{1 + x}\\ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, \left(t_0 \cdot \sqrt[3]{{t_0}^{2}}\right) \cdot \sqrt[3]{t_0}\right)} \end{array} \]
(FPCore (x) :precision binary64 (- (cbrt (+ x 1.0)) (cbrt x)))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (cbrt (+ 1.0 x))))
   (/
    1.0
    (fma
     (cbrt x)
     (+ (cbrt x) t_0)
     (* (* t_0 (cbrt (pow t_0 2.0))) (cbrt t_0))))))
double code(double x) {
	return cbrt((x + 1.0)) - cbrt(x);
}
double code(double x) {
	double t_0 = cbrt((1.0 + x));
	return 1.0 / fma(cbrt(x), (cbrt(x) + t_0), ((t_0 * cbrt(pow(t_0, 2.0))) * cbrt(t_0)));
}
function code(x)
	return Float64(cbrt(Float64(x + 1.0)) - cbrt(x))
end
function code(x)
	t_0 = cbrt(Float64(1.0 + x))
	return Float64(1.0 / fma(cbrt(x), Float64(cbrt(x) + t_0), Float64(Float64(t_0 * cbrt((t_0 ^ 2.0))) * cbrt(t_0))))
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]}, N[(1.0 / N[(N[Power[x, 1/3], $MachinePrecision] * N[(N[Power[x, 1/3], $MachinePrecision] + t$95$0), $MachinePrecision] + N[(N[(t$95$0 * N[Power[N[Power[t$95$0, 2.0], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[t$95$0, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\sqrt[3]{x + 1} - \sqrt[3]{x}
\begin{array}{l}
t_0 := \sqrt[3]{1 + x}\\
\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + t_0, \left(t_0 \cdot \sqrt[3]{{t_0}^{2}}\right) \cdot \sqrt[3]{t_0}\right)}
\end{array}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 14 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Derivation?

  1. Initial program 52.9%

    \[\sqrt[3]{x + 1} - \sqrt[3]{x} \]
  2. Applied egg-rr53.1%

    \[\leadsto \color{blue}{\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)}} \]
    Step-by-step derivation

    [Start]52.9

    \[ \sqrt[3]{x + 1} - \sqrt[3]{x} \]

    flip3-- [=>]53.0

    \[ \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 [=>]53.0

    \[ \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 [=>]52.7

    \[ \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 [=>]53.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 [=>]53.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 [=>]53.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 [=>]53.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 [<=]53.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)}} \]
  3. Simplified76.2%

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)}} \]
    Step-by-step derivation

    [Start]53.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/ [=>]53.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 [=>]53.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 [=>]53.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+ [=>]76.2

    \[ \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 [=>]76.2

    \[ \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 [=>]76.2

    \[ \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 [=>]76.2

    \[ \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 [=>]76.2

    \[ \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 [=>]76.2

    \[ \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 [=>]76.2

    \[ \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)} \]
  4. Applied egg-rr99.1%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{\left(\sqrt[3]{1 + x} \cdot \sqrt[3]{{\left(\sqrt[3]{1 + x}\right)}^{2}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}}\right)} \]
    Step-by-step derivation

    [Start]76.2

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)} \]

    unpow2 [=>]76.2

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{\color{blue}{\left(1 + x\right) \cdot \left(1 + x\right)}}\right)} \]

    cbrt-prod [=>]99.1

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}}\right)} \]

    add-cube-cbrt [=>]99.0

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \sqrt[3]{1 + x} \cdot \color{blue}{\left(\left(\sqrt[3]{\sqrt[3]{1 + x}} \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right)}\right)} \]

    associate-*r* [=>]99.0

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \color{blue}{\left(\sqrt[3]{1 + x} \cdot \left(\sqrt[3]{\sqrt[3]{1 + x}} \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right)\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}}\right)} \]

    cbrt-unprod [=>]99.1

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \left(\sqrt[3]{1 + x} \cdot \color{blue}{\sqrt[3]{\sqrt[3]{1 + x} \cdot \sqrt[3]{1 + x}}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right)} \]

    pow2 [=>]99.1

    \[ \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{1 + x} + \sqrt[3]{x}, \left(\sqrt[3]{1 + x} \cdot \sqrt[3]{\color{blue}{{\left(\sqrt[3]{1 + x}\right)}^{2}}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right)} \]
  5. Final simplification99.1%

    \[\leadsto \frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, \sqrt[3]{x} + \sqrt[3]{1 + x}, \left(\sqrt[3]{1 + x} \cdot \sqrt[3]{{\left(\sqrt[3]{1 + x}\right)}^{2}}\right) \cdot \sqrt[3]{\sqrt[3]{1 + x}}\right)} \]

Alternatives

Alternative 1
Accuracy88.9%
Cost39432
\[\begin{array}{l} t_0 := \sqrt[3]{x} + \sqrt[3]{1 + x}\\ \mathbf{if}\;x \leq -1.34 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{1 + \sqrt[3]{x} \cdot t_0}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, \sqrt[3]{{\left(1 + x\right)}^{2}}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, e^{0.6666666666666666 \cdot \mathsf{log1p}\left(x\right)}\right)}\\ \end{array} \]
Alternative 2
Accuracy88.8%
Cost39368
\[\begin{array}{l} t_0 := \sqrt[3]{x} + \sqrt[3]{1 + x}\\ t_1 := \sqrt[3]{x} \cdot t_0\\ \mathbf{if}\;x \leq -1.34 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{1 + t_1}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{t_1 + \sqrt[3]{{\left(1 + x\right)}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, e^{0.6666666666666666 \cdot \mathsf{log1p}\left(x\right)}\right)}\\ \end{array} \]
Alternative 3
Accuracy99.1%
Cost39168
\[\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} \]
Alternative 4
Accuracy88.8%
Cost33160
\[\begin{array}{l} t_0 := \sqrt[3]{x} + \sqrt[3]{1 + x}\\ t_1 := \sqrt[3]{x} \cdot t_0\\ \mathbf{if}\;x \leq -1.34 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{1 + t_1}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+154}:\\ \;\;\;\;\frac{1}{t_1 + \sqrt[3]{{\left(1 + x\right)}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\ \end{array} \]
Alternative 5
Accuracy78.3%
Cost32900
\[\begin{array}{l} t_0 := \sqrt[3]{x} + \sqrt[3]{1 + x}\\ \mathbf{if}\;x \leq -1:\\ \;\;\;\;\frac{1}{1 + \sqrt[3]{x} \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(\sqrt[3]{x}, t_0, {\left(1 + x\right)}^{0.6666666666666666}\right)}\\ \end{array} \]
Alternative 6
Accuracy60.5%
Cost32776
\[\begin{array}{l} t_0 := \sqrt[3]{1 + x}\\ t_1 := \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+14}:\\ \;\;\;\;\frac{1}{1 + t_1}\\ \mathbf{elif}\;x \leq 2.75 \cdot 10^{+14}:\\ \;\;\;\;t_0 - {\left(\sqrt[3]{\sqrt[3]{x}}\right)}^{3}\\ \mathbf{else}:\\ \;\;\;\;e^{-\mathsf{log1p}\left(t_1\right)}\\ \end{array} \]
Alternative 7
Accuracy60.5%
Cost26249
\[\begin{array}{l} t_0 := \sqrt[3]{1 + x}\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{+14} \lor \neg \left(x \leq 2.75 \cdot 10^{+14}\right):\\ \;\;\;\;\frac{1}{1 + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 - {\left(\sqrt[3]{\sqrt[3]{x}}\right)}^{3}\\ \end{array} \]
Alternative 8
Accuracy60.6%
Cost20169
\[\begin{array}{l} t_0 := \sqrt[3]{1 + x}\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+15} \lor \neg \left(x \leq 3.7 \cdot 10^{+14}\right):\\ \;\;\;\;\frac{1}{1 + \sqrt[3]{x} \cdot \left(\sqrt[3]{x} + t_0\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 - \sqrt[3]{x}\\ \end{array} \]
Alternative 9
Accuracy53.0%
Cost13120
\[\sqrt[3]{1 + x} - \sqrt[3]{x} \]
Alternative 10
Accuracy50.6%
Cost6848
\[1 + \left(x \cdot 0.3333333333333333 - \sqrt[3]{x}\right) \]
Alternative 11
Accuracy50.4%
Cost6592
\[1 - \sqrt[3]{x} \]
Alternative 12
Accuracy3.6%
Cost64
\[0 \]
Alternative 13
Accuracy49.4%
Cost64
\[1 \]

Reproduce?

herbie shell --seed 2023160 
(FPCore (x)
  :name "2cbrt (problem 3.3.4)"
  :precision binary64
  (- (cbrt (+ x 1.0)) (cbrt x)))