Average Error: 33.2 → 25.0
Time: 15.9s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \leq -3.4419418499706947 \cdot 10^{+39}:\\ \;\;\;\;\frac{\frac{1}{n} - \frac{0.5}{n \cdot x}}{x} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{elif}\;n \leq 601298.5732088129:\\ \;\;\;\;\sqrt[3]{{\left({\left(1 + x\right)}^{\left(\frac{1}{n}\right)}\right)}^{3}} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log x}{x \cdot \left(n \cdot n\right)} + \frac{1}{x} \cdot \left(\frac{1}{n} - \log \left(e^{\frac{0.5}{n \cdot x}}\right)\right)\\ \end{array}\]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;n \leq -3.4419418499706947 \cdot 10^{+39}:\\
\;\;\;\;\frac{\frac{1}{n} - \frac{0.5}{n \cdot x}}{x} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\

\mathbf{elif}\;n \leq 601298.5732088129:\\
\;\;\;\;\sqrt[3]{{\left({\left(1 + x\right)}^{\left(\frac{1}{n}\right)}\right)}^{3}} - {x}^{\left(\frac{1}{n}\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log x}{x \cdot \left(n \cdot n\right)} + \frac{1}{x} \cdot \left(\frac{1}{n} - \log \left(e^{\frac{0.5}{n \cdot x}}\right)\right)\\

\end{array}
(FPCore (x n)
 :precision binary64
 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
(FPCore (x n)
 :precision binary64
 (if (<= n -3.4419418499706947e+39)
   (+ (/ (- (/ 1.0 n) (/ 0.5 (* n x))) x) (/ (log x) (* x (* n n))))
   (if (<= n 601298.5732088129)
     (- (cbrt (pow (pow (+ 1.0 x) (/ 1.0 n)) 3.0)) (pow x (/ 1.0 n)))
     (+
      (/ (log x) (* x (* n n)))
      (* (/ 1.0 x) (- (/ 1.0 n) (log (exp (/ 0.5 (* n x))))))))))
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 tmp;
	if (n <= -3.4419418499706947e+39) {
		tmp = (((1.0 / n) - (0.5 / (n * x))) / x) + (log(x) / (x * (n * n)));
	} else if (n <= 601298.5732088129) {
		tmp = cbrt(pow(pow((1.0 + x), (1.0 / n)), 3.0)) - pow(x, (1.0 / n));
	} else {
		tmp = (log(x) / (x * (n * n))) + ((1.0 / x) * ((1.0 / n) - log(exp(0.5 / (n * x)))));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus n

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 3 regimes
  2. if n < -3.44194184997069467e39

    1. Initial program 44.3

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{x \cdot n} - \frac{0.5}{x \cdot \left(x \cdot n\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary64_41932.7

      \[\leadsto \left(\frac{1}{x \cdot n} - \frac{\color{blue}{1 \cdot 0.5}}{x \cdot \left(x \cdot n\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    6. Applied times-frac_binary64_42532.7

      \[\leadsto \left(\frac{1}{x \cdot n} - \color{blue}{\frac{1}{x} \cdot \frac{0.5}{x \cdot n}}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    7. Applied *-un-lft-identity_binary64_41932.7

      \[\leadsto \left(\frac{\color{blue}{1 \cdot 1}}{x \cdot n} - \frac{1}{x} \cdot \frac{0.5}{x \cdot n}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    8. Applied times-frac_binary64_42532.2

      \[\leadsto \left(\color{blue}{\frac{1}{x} \cdot \frac{1}{n}} - \frac{1}{x} \cdot \frac{0.5}{x \cdot n}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    9. Applied distribute-lft-out--_binary64_37132.2

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{0.5}{x \cdot n}\right)} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    10. Using strategy rm
    11. Applied pow1_binary64_48032.2

      \[\leadsto \frac{1}{x} \cdot \color{blue}{{\left(\frac{1}{n} - \frac{0.5}{x \cdot n}\right)}^{1}} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    12. Applied pow1_binary64_48032.2

      \[\leadsto \color{blue}{{\left(\frac{1}{x}\right)}^{1}} \cdot {\left(\frac{1}{n} - \frac{0.5}{x \cdot n}\right)}^{1} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    13. Applied pow-prod-down_binary64_49032.2

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

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

    if -3.44194184997069467e39 < n < 601298.57320881286

    1. Initial program 9.2

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    2. Using strategy rm
    3. Applied add-cbrt-cube_binary64_4559.2

      \[\leadsto \color{blue}{\sqrt[3]{\left({\left(x + 1\right)}^{\left(\frac{1}{n}\right)} \cdot {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}\right) \cdot {\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}} - {x}^{\left(\frac{1}{n}\right)}\]
    4. Simplified9.2

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

    if 601298.57320881286 < n

    1. Initial program 45.0

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{x \cdot n} - \frac{0.5}{x \cdot \left(x \cdot n\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity_binary64_41933.6

      \[\leadsto \left(\frac{1}{x \cdot n} - \frac{\color{blue}{1 \cdot 0.5}}{x \cdot \left(x \cdot n\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    6. Applied times-frac_binary64_42533.6

      \[\leadsto \left(\frac{1}{x \cdot n} - \color{blue}{\frac{1}{x} \cdot \frac{0.5}{x \cdot n}}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    7. Applied *-un-lft-identity_binary64_41933.6

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

      \[\leadsto \left(\color{blue}{\frac{1}{x} \cdot \frac{1}{n}} - \frac{1}{x} \cdot \frac{0.5}{x \cdot n}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    9. Applied distribute-lft-out--_binary64_37133.1

      \[\leadsto \color{blue}{\frac{1}{x} \cdot \left(\frac{1}{n} - \frac{0.5}{x \cdot n}\right)} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
    10. Using strategy rm
    11. Applied add-log-exp_binary64_45832.9

      \[\leadsto \frac{1}{x} \cdot \left(\frac{1}{n} - \color{blue}{\log \left(e^{\frac{0.5}{x \cdot n}}\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification25.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -3.4419418499706947 \cdot 10^{+39}:\\ \;\;\;\;\frac{\frac{1}{n} - \frac{0.5}{n \cdot x}}{x} + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{elif}\;n \leq 601298.5732088129:\\ \;\;\;\;\sqrt[3]{{\left({\left(1 + x\right)}^{\left(\frac{1}{n}\right)}\right)}^{3}} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log x}{x \cdot \left(n \cdot n\right)} + \frac{1}{x} \cdot \left(\frac{1}{n} - \log \left(e^{\frac{0.5}{n \cdot x}}\right)\right)\\ \end{array}\]

Reproduce

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