Average Error: 32.9 → 23.1
Time: 10.4s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \leq -61669447.7829862 \lor \neg \left(n \leq 1919560313.2622035\right):\\ \;\;\;\;\frac{1}{x} \cdot \left(\frac{1}{n} - \log \left(e^{\frac{0.5}{n \cdot x}}\right)\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x \cdot \left(1 + x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)\right)}{n}} - {x}^{\left(\frac{1}{n}\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 -61669447.7829862 \lor \neg \left(n \leq 1919560313.2622035\right):\\
\;\;\;\;\frac{1}{x} \cdot \left(\frac{1}{n} - \log \left(e^{\frac{0.5}{n \cdot x}}\right)\right) + \frac{\log x}{x \cdot \left(n \cdot n\right)}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{x \cdot \left(1 + x \cdot \left(x \cdot 0.3333333333333333 + -0.5\right)\right)}{n}} - {x}^{\left(\frac{1}{n}\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 (or (<= n -61669447.7829862) (not (<= n 1919560313.2622035)))
   (+
    (* (/ 1.0 x) (- (/ 1.0 n) (log (exp (/ 0.5 (* n x))))))
    (/ (log x) (* x (* n n))))
   (-
    (exp (/ (* x (+ 1.0 (* x (+ (* x 0.3333333333333333) -0.5)))) 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 ((n <= -61669447.7829862) || !(n <= 1919560313.2622035)) {
		tmp = ((1.0 / x) * ((1.0 / n) - log(exp(0.5 / (n * x))))) + (log(x) / (x * (n * n)));
	} else {
		tmp = exp((x * (1.0 + (x * ((x * 0.3333333333333333) + -0.5)))) / 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 2 regimes
  2. if n < -61669447.7829862013 or 1919560313.26220345 < 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 32.4

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

      \[\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_binary6432.3

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

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

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

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

      \[\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_binary6431.6

      \[\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)}\]

    if -61669447.7829862013 < n < 1919560313.26220345

    1. Initial program 3.2

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

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

      \[\leadsto e^{\color{blue}{\frac{\log \left(x + 1\right)}{n}}} - {x}^{\left(\frac{1}{n}\right)}\]
    5. Taylor expanded around 0 22.0

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

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

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

Reproduce

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