Average Error: 32.8 → 7.6
Time: 19.4s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := {\left(\mathsf{log1p}\left(x\right)\right)}^{2}\\ t_1 := {\log x}^{2}\\ \mathbf{if}\;x \leq 1.765246649597966 \cdot 10^{-276}:\\ \;\;\;\;\frac{1}{\frac{\left(\log x + \mathsf{log1p}\left(x\right)\right) \cdot n}{t_0 - t_1}}\\ \mathbf{else}:\\ \;\;\;\;\begin{array}{l} t_2 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;x \leq 4.641095742691318 \cdot 10^{-262}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t_2\\ \mathbf{elif}\;x \leq 5540.777704054234:\\ \;\;\;\;\begin{array}{l} t_3 := \frac{\mathsf{log1p}\left(x\right)}{n}\\ t_4 := \frac{\log x}{n}\\ \mathsf{fma}\left(0.5, \frac{t_0}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_3}^{3}, t_3\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_4}^{3}, \mathsf{fma}\left(0.5, \frac{t_1}{n \cdot n}, t_4\right)\right) \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_2}{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 := {\left(\mathsf{log1p}\left(x\right)\right)}^{2}\\
t_1 := {\log x}^{2}\\
\mathbf{if}\;x \leq 1.765246649597966 \cdot 10^{-276}:\\
\;\;\;\;\frac{1}{\frac{\left(\log x + \mathsf{log1p}\left(x\right)\right) \cdot n}{t_0 - t_1}}\\

\mathbf{else}:\\
\;\;\;\;\begin{array}{l}
t_2 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;x \leq 4.641095742691318 \cdot 10^{-262}:\\
\;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - t_2\\

\mathbf{elif}\;x \leq 5540.777704054234:\\
\;\;\;\;\begin{array}{l}
t_3 := \frac{\mathsf{log1p}\left(x\right)}{n}\\
t_4 := \frac{\log x}{n}\\
\mathsf{fma}\left(0.5, \frac{t_0}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_3}^{3}, t_3\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_4}^{3}, \mathsf{fma}\left(0.5, \frac{t_1}{n \cdot n}, t_4\right)\right)
\end{array}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_2}{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 (pow (log1p x) 2.0)) (t_1 (pow (log x) 2.0)))
   (if (<= x 1.765246649597966e-276)
     (/ 1.0 (/ (* (+ (log x) (log1p x)) n) (- t_0 t_1)))
     (let* ((t_2 (pow x (/ 1.0 n))))
       (if (<= x 4.641095742691318e-262)
         (- (pow (+ x 1.0) (/ 1.0 n)) t_2)
         (if (<= x 5540.777704054234)
           (let* ((t_3 (/ (log1p x) n)) (t_4 (/ (log x) n)))
             (-
              (fma
               0.5
               (/ t_0 (* n n))
               (fma 0.16666666666666666 (pow t_3 3.0) t_3))
              (fma
               0.16666666666666666
               (pow t_4 3.0)
               (fma 0.5 (/ t_1 (* n n)) t_4))))
           (/ t_2 (* 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 = pow(log1p(x), 2.0);
	double t_1 = pow(log(x), 2.0);
	double tmp;
	if (x <= 1.765246649597966e-276) {
		tmp = 1.0 / (((log(x) + log1p(x)) * n) / (t_0 - t_1));
	} else {
		double t_2 = pow(x, (1.0 / n));
		double tmp_1;
		if (x <= 4.641095742691318e-262) {
			tmp_1 = pow((x + 1.0), (1.0 / n)) - t_2;
		} else if (x <= 5540.777704054234) {
			double t_3 = log1p(x) / n;
			double t_4 = log(x) / n;
			tmp_1 = fma(0.5, (t_0 / (n * n)), fma(0.16666666666666666, pow(t_3, 3.0), t_3)) - fma(0.16666666666666666, pow(t_4, 3.0), fma(0.5, (t_1 / (n * n)), t_4));
		} else {
			tmp_1 = t_2 / (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 < 1.76524664959796603e-276

    1. Initial program 39.7

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{n}{\mathsf{log1p}\left(x\right) - \log x}}} \]
    5. Applied flip--_binary6421.3

      \[\leadsto \frac{1}{\frac{n}{\color{blue}{\frac{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - \log x \cdot \log x}{\mathsf{log1p}\left(x\right) + \log x}}}} \]
    6. Applied associate-/r/_binary6421.3

      \[\leadsto \frac{1}{\color{blue}{\frac{n}{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - \log x \cdot \log x} \cdot \left(\mathsf{log1p}\left(x\right) + \log x\right)}} \]
    7. Simplified21.3

      \[\leadsto \frac{1}{\color{blue}{\frac{n}{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - {\log x}^{2}}} \cdot \left(\mathsf{log1p}\left(x\right) + \log x\right)} \]
    8. Applied pow1_binary6421.3

      \[\leadsto \frac{1}{\frac{n}{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - {\log x}^{2}} \cdot \color{blue}{{\left(\mathsf{log1p}\left(x\right) + \log x\right)}^{1}}} \]
    9. Applied pow1_binary6421.3

      \[\leadsto \frac{1}{\color{blue}{{\left(\frac{n}{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - {\log x}^{2}}\right)}^{1}} \cdot {\left(\mathsf{log1p}\left(x\right) + \log x\right)}^{1}} \]
    10. Applied pow-prod-down_binary6421.3

      \[\leadsto \frac{1}{\color{blue}{{\left(\frac{n}{\mathsf{log1p}\left(x\right) \cdot \mathsf{log1p}\left(x\right) - {\log x}^{2}} \cdot \left(\mathsf{log1p}\left(x\right) + \log x\right)\right)}^{1}}} \]
    11. Simplified21.4

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

    if 1.76524664959796603e-276 < x < 4.6410957426913177e-262

    1. Initial program 39.5

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]

    if 4.6410957426913177e-262 < x < 5540.77770405423416

    1. Initial program 48.3

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

      \[\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. Simplified12.2

      \[\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 5540.77770405423416 < x

    1. Initial program 20.6

      \[{\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{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification7.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.765246649597966 \cdot 10^{-276}:\\ \;\;\;\;\frac{1}{\frac{\left(\log x + \mathsf{log1p}\left(x\right)\right) \cdot n}{{\left(\mathsf{log1p}\left(x\right)\right)}^{2} - {\log x}^{2}}}\\ \mathbf{elif}\;x \leq 4.641095742691318 \cdot 10^{-262}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 5540.777704054234:\\ \;\;\;\;\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{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}\\ \end{array} \]

Reproduce

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