Average Error: 32.8 → 8.1
Time: 16.5s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := \frac{\log x}{n}\\ \mathbf{if}\;x \leq 8.40015892724182 \cdot 10^{-225}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{{x}^{3}}{n}, \frac{x}{n}\right) - \mathsf{fma}\left(0.5, x \cdot \frac{x}{n}, t_0\right)\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_1 := e^{t_0}\\ \mathbf{if}\;x \leq 3.820976062708217 \cdot 10^{-206}:\\ \;\;\;\;\frac{x}{n} + \left(1 - t_1\right)\\ \mathbf{elif}\;x \leq 3872.7799695531517:\\ \;\;\;\;\begin{array}{l} t_2 := \sqrt{x + 1}\\ \frac{\log \left(\frac{t_2}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \log \left(\frac{t_2}{\sqrt[3]{x}}\right)}{n} \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_1}{x \cdot n}\\ \end{array}\\ \end{array} \]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
t_0 := \frac{\log x}{n}\\
\mathbf{if}\;x \leq 8.40015892724182 \cdot 10^{-225}:\\
\;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{{x}^{3}}{n}, \frac{x}{n}\right) - \mathsf{fma}\left(0.5, x \cdot \frac{x}{n}, t_0\right)\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_1 := e^{t_0}\\
\mathbf{if}\;x \leq 3.820976062708217 \cdot 10^{-206}:\\
\;\;\;\;\frac{x}{n} + \left(1 - t_1\right)\\

\mathbf{elif}\;x \leq 3872.7799695531517:\\
\;\;\;\;\begin{array}{l}
t_2 := \sqrt{x + 1}\\
\frac{\log \left(\frac{t_2}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \log \left(\frac{t_2}{\sqrt[3]{x}}\right)}{n}
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{x \cdot n}\\


\end{array}\\


\end{array}
(FPCore (x n)
 :precision binary64
 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
(FPCore (x n)
 :precision binary64
 (let* ((t_0 (/ (log x) n)))
   (if (<= x 8.40015892724182e-225)
     (-
      (fma 0.3333333333333333 (/ (pow x 3.0) n) (/ x n))
      (fma 0.5 (* x (/ x n)) t_0))
     (let* ((t_1 (exp t_0)))
       (if (<= x 3.820976062708217e-206)
         (+ (/ x n) (- 1.0 t_1))
         (if (<= x 3872.7799695531517)
           (let* ((t_2 (sqrt (+ x 1.0))))
             (/
              (+ (log (/ t_2 (* (cbrt x) (cbrt x)))) (log (/ t_2 (cbrt x))))
              n))
           (/ t_1 (* x n))))))))
double code(double x, double n) {
	return pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n));
}
double code(double x, double n) {
	double t_0 = log(x) / n;
	double tmp;
	if (x <= 8.40015892724182e-225) {
		tmp = fma(0.3333333333333333, (pow(x, 3.0) / n), (x / n)) - fma(0.5, (x * (x / n)), t_0);
	} else {
		double t_1 = exp(t_0);
		double tmp_1;
		if (x <= 3.820976062708217e-206) {
			tmp_1 = (x / n) + (1.0 - t_1);
		} else if (x <= 3872.7799695531517) {
			double t_2 = sqrt(x + 1.0);
			tmp_1 = (log(t_2 / (cbrt(x) * cbrt(x))) + log(t_2 / cbrt(x))) / n;
		} else {
			tmp_1 = t_1 / (x * n);
		}
		tmp = tmp_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus n

Derivation

  1. Split input into 4 regimes
  2. if x < 8.4001589272418198e-225

    1. Initial program 40.8

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Taylor expanded in n around inf 20.3

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    3. Simplified20.3

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    4. Taylor expanded in x around 0 20.3

      \[\leadsto \color{blue}{\left(\frac{x}{n} + 0.3333333333333333 \cdot \frac{{x}^{3}}{n}\right) - \left(0.5 \cdot \frac{{x}^{2}}{n} + \frac{\log x}{n}\right)} \]
    5. Simplified20.3

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.3333333333333333, \frac{{x}^{3}}{n}, \frac{x}{n}\right) - \mathsf{fma}\left(0.5, \frac{x}{n} \cdot x, \frac{\log x}{n}\right)} \]

    if 8.4001589272418198e-225 < x < 3.82097606270821704e-206

    1. Initial program 44.5

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Taylor expanded in x around 0 44.1

      \[\leadsto \color{blue}{\left(\frac{x}{n} + 1\right) - e^{\frac{\log x}{n}}} \]
    3. Simplified44.1

      \[\leadsto \color{blue}{\left(1 - e^{\frac{\log x}{n}}\right) + \frac{x}{n}} \]

    if 3.82097606270821704e-206 < x < 3872.77996955315166

    1. Initial program 49.9

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Taylor expanded in n around inf 11.0

      \[\leadsto \color{blue}{\frac{\log \left(1 + x\right) - \log x}{n}} \]
    3. Simplified11.0

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    4. Applied log1p-udef_binary6411.0

      \[\leadsto \frac{\color{blue}{\log \left(1 + x\right)} - \log x}{n} \]
    5. Applied diff-log_binary6410.9

      \[\leadsto \frac{\color{blue}{\log \left(\frac{1 + x}{x}\right)}}{n} \]
    6. Applied add-cube-cbrt_binary6411.0

      \[\leadsto \frac{\log \left(\frac{1 + x}{\color{blue}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}}\right)}{n} \]
    7. Applied add-sqr-sqrt_binary6411.0

      \[\leadsto \frac{\log \left(\frac{\color{blue}{\sqrt{1 + x} \cdot \sqrt{1 + x}}}{\left(\sqrt[3]{x} \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x}}\right)}{n} \]
    8. Applied times-frac_binary6411.0

      \[\leadsto \frac{\log \color{blue}{\left(\frac{\sqrt{1 + x}}{\sqrt[3]{x} \cdot \sqrt[3]{x}} \cdot \frac{\sqrt{1 + x}}{\sqrt[3]{x}}\right)}}{n} \]
    9. Applied log-prod_binary6411.1

      \[\leadsto \frac{\color{blue}{\log \left(\frac{\sqrt{1 + x}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \log \left(\frac{\sqrt{1 + x}}{\sqrt[3]{x}}\right)}}{n} \]

    if 3872.77996955315166 < x

    1. Initial program 21.0

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Taylor expanded in x around inf 1.4

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}} \]
    3. Simplified1.4

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification8.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 8.40015892724182 \cdot 10^{-225}:\\ \;\;\;\;\mathsf{fma}\left(0.3333333333333333, \frac{{x}^{3}}{n}, \frac{x}{n}\right) - \mathsf{fma}\left(0.5, x \cdot \frac{x}{n}, \frac{\log x}{n}\right)\\ \mathbf{elif}\;x \leq 3.820976062708217 \cdot 10^{-206}:\\ \;\;\;\;\frac{x}{n} + \left(1 - e^{\frac{\log x}{n}}\right)\\ \mathbf{elif}\;x \leq 3872.7799695531517:\\ \;\;\;\;\frac{\log \left(\frac{\sqrt{x + 1}}{\sqrt[3]{x} \cdot \sqrt[3]{x}}\right) + \log \left(\frac{\sqrt{x + 1}}{\sqrt[3]{x}}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

herbie shell --seed 2022081 
(FPCore (x n)
  :name "2nthrt (problem 3.4.6)"
  :precision binary64
  (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))