Average Error: 32.9 → 7.1
Time: 18.3s
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 6834308.8393940255:\\ \;\;\;\;\begin{array}{l} t_1 := \frac{\mathsf{log1p}\left(x\right)}{n}\\ \mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_1}^{3}, t_1\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_0}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, t_0\right)\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{t_0}}{x \cdot n}\\ \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 6834308.8393940255:\\
\;\;\;\;\begin{array}{l}
t_1 := \frac{\mathsf{log1p}\left(x\right)}{n}\\
\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_1}^{3}, t_1\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_0}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, t_0\right)\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{t_0}}{x \cdot n}\\


\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 6834308.8393940255)
     (let* ((t_1 (/ (log1p x) n)))
       (-
        (fma
         0.5
         (/ (pow (log1p x) 2.0) (* n n))
         (fma 0.16666666666666666 (pow t_1 3.0) t_1))
        (fma
         0.16666666666666666
         (pow t_0 3.0)
         (fma 0.5 (/ (pow (log x) 2.0) (* n n)) t_0))))
     (/ (exp t_0) (* 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 <= 6834308.8393940255) {
		double t_1_1 = log1p(x) / n;
		tmp = fma(0.5, (pow(log1p(x), 2.0) / (n * n)), fma(0.16666666666666666, pow(t_1_1, 3.0), t_1_1)) - fma(0.16666666666666666, pow(t_0, 3.0), fma(0.5, (pow(log(x), 2.0) / (n * n)), t_0));
	} else {
		tmp = exp(t_0) / (x * n);
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus n

Derivation

  1. Split input into 2 regimes
  2. if x < 6834308.8393940255

    1. Initial program 46.9

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

      \[\leadsto \color{blue}{\left(0.5 \cdot \frac{{\log \left(1 + x\right)}^{2}}{{n}^{2}} + \left(0.16666666666666666 \cdot \frac{{\log \left(1 + x\right)}^{3}}{{n}^{3}} + \frac{\log \left(1 + x\right)}{n}\right)\right) - \left(0.16666666666666666 \cdot \frac{{\log x}^{3}}{{n}^{3}} + \left(0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}} + \frac{\log x}{n}\right)\right)} \]
    3. Simplified13.7

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

    if 6834308.8393940255 < x

    1. Initial program 20.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6834308.8393940255:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\mathsf{log1p}\left(x\right)}{n}\right)}^{3}, \frac{\mathsf{log1p}\left(x\right)}{n}\right)\right) - \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\log x}{n}\right)}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, \frac{\log x}{n}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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