Average Error: 32.9 → 23.3
Time: 10.3s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \leq -3292888712184467.5 \lor \neg \left(n \leq 28730378.808545448\right):\\ \;\;\;\;\left(\frac{\frac{1}{x}}{n} - \frac{0.5}{x \cdot \left(n \cdot x\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - e^{\frac{\log x}{n}}\\ \end{array}\]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;n \leq -3292888712184467.5 \lor \neg \left(n \leq 28730378.808545448\right):\\
\;\;\;\;\left(\frac{\frac{1}{x}}{n} - \frac{0.5}{x \cdot \left(n \cdot x\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\

\mathbf{else}:\\
\;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - e^{\frac{\log x}{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
 (if (or (<= n -3292888712184467.5) (not (<= n 28730378.808545448)))
   (+ (- (/ (/ 1.0 x) n) (/ 0.5 (* x (* n x)))) (/ (log x) (* x (* n n))))
   (- (pow (+ 1.0 x) (/ 1.0 n)) (exp (/ (log 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 tmp;
	if ((n <= -3292888712184467.5) || !(n <= 28730378.808545448)) {
		tmp = (((1.0 / x) / n) - (0.5 / (x * (n * x)))) + (log(x) / (x * (n * n)));
	} else {
		tmp = pow((1.0 + x), (1.0 / n)) - exp(log(x) / n);
	}
	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 2 regimes
  2. if n < -3292888712184467.5 or 28730378.808545448 < n

    1. Initial program 45.2

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

      \[\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.0

      \[\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 associate-/r*_binary64_2331.5

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

    if -3292888712184467.5 < n < 28730378.808545448

    1. Initial program 4.4

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    2. Using strategy rm
    3. Applied pow-to-exp_binary64_1484.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \leq -3292888712184467.5 \lor \neg \left(n \leq 28730378.808545448\right):\\ \;\;\;\;\left(\frac{\frac{1}{x}}{n} - \frac{0.5}{x \cdot \left(n \cdot x\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - e^{\frac{\log x}{n}}\\ \end{array}\]

Reproduce

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