Average Error: 33.2 → 24.5
Time: 11.9s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -6.102214542556524 \cdot 10^{-17}:\\ \;\;\;\;{\left(\sqrt{1 + x}\right)}^{\left(\frac{1}{n}\right)} \cdot {\left(\sqrt{1 + x}\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;\frac{1}{n} \leq 1.6734669923262524 \cdot 10^{-14}:\\ \;\;\;\;\left(\frac{1}{n \cdot x} - \frac{0.5}{x \cdot \left(n \cdot x\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}}\right)\\ \end{array}\]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;\frac{1}{n} \leq -6.102214542556524 \cdot 10^{-17}:\\
\;\;\;\;{\left(\sqrt{1 + x}\right)}^{\left(\frac{1}{n}\right)} \cdot {\left(\sqrt{1 + x}\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\

\mathbf{elif}\;\frac{1}{n} \leq 1.6734669923262524 \cdot 10^{-14}:\\
\;\;\;\;\left(\frac{1}{n \cdot x} - \frac{0.5}{x \cdot \left(n \cdot x\right)}\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{{\left(1 + x\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\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 (<= (/ 1.0 n) -6.102214542556524e-17)
   (-
    (* (pow (sqrt (+ 1.0 x)) (/ 1.0 n)) (pow (sqrt (+ 1.0 x)) (/ 1.0 n)))
    (pow x (/ 1.0 n)))
   (if (<= (/ 1.0 n) 1.6734669923262524e-14)
     (+ (- (/ 1.0 (* n x)) (/ 0.5 (* x (* n x)))) (/ (log x) (* x (* n n))))
     (log (exp (- (pow (+ 1.0 x) (/ 1.0 n)) (pow x (/ 1.0 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 ((1.0 / n) <= -6.102214542556524e-17) {
		tmp = (pow(sqrt(1.0 + x), (1.0 / n)) * pow(sqrt(1.0 + x), (1.0 / n))) - pow(x, (1.0 / n));
	} else if ((1.0 / n) <= 1.6734669923262524e-14) {
		tmp = ((1.0 / (n * x)) - (0.5 / (x * (n * x)))) + (log(x) / (x * (n * n)));
	} else {
		tmp = log(exp(pow((1.0 + x), (1.0 / n)) - pow(x, (1.0 / 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 3 regimes
  2. if (/.f64 1 n) < -6.10221454255652389e-17

    1. Initial program 3.9

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

      \[\leadsto {\color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1}\right)}}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
    4. Applied unpow-prod-down_binary64_4984.0

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

    if -6.10221454255652389e-17 < (/.f64 1 n) < 1.67346699232625238e-14

    1. Initial program 45.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)}}\]

    if 1.67346699232625238e-14 < (/.f64 1 n)

    1. Initial program 9.5

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

      \[\leadsto {\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \color{blue}{\log \left(e^{{x}^{\left(\frac{1}{n}\right)}}\right)}\]
    4. Applied add-log-exp_binary64_4589.7

      \[\leadsto \color{blue}{\log \left(e^{{\left(x + 1\right)}^{\left(\frac{1}{n}\right)}}\right)} - \log \left(e^{{x}^{\left(\frac{1}{n}\right)}}\right)\]
    5. Applied diff-log_binary64_5119.8

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

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

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

Reproduce

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