Average Error: 33.0 → 24.0
Time: 9.5s
Precision: 64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\]
\[\begin{array}{l} \mathbf{if}\;n \le -35447295026.760864:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{{x}^{2}}}{n} + \frac{\log x \cdot 1}{x \cdot {n}^{2}}\\ \mathbf{elif}\;n \le 604142.656624356867:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{\log x}{x \cdot {n}^{2}}, \frac{\frac{1}{n}}{x}\right) + \frac{-0.5}{{x}^{2} \cdot n}\\ \end{array}\]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;n \le -35447295026.760864:\\
\;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{{x}^{2}}}{n} + \frac{\log x \cdot 1}{x \cdot {n}^{2}}\\

\mathbf{elif}\;n \le 604142.656624356867:\\
\;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\

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

\end{array}
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 VAR;
	if ((n <= -35447295026.760864)) {
		VAR = ((((1.0 / x) - (0.5 / pow(x, 2.0))) / n) + ((log(x) * 1.0) / (x * pow(n, 2.0))));
	} else {
		double VAR_1;
		if ((n <= 604142.6566243569)) {
			VAR_1 = (pow((x + 1.0), (1.0 / n)) - pow(x, (1.0 / n)));
		} else {
			VAR_1 = (fma(1.0, (log(x) / (x * pow(n, 2.0))), ((1.0 / n) / x)) + (-0.5 / (pow(x, 2.0) * n)));
		}
		VAR = VAR_1;
	}
	return VAR;
}

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 < -35447295026.760864

    1. Initial program 44.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{n}, \frac{1}{x} - \frac{0.5}{{x}^{2}}, \frac{\log x \cdot 1}{x \cdot {n}^{2}}\right)}\]
    4. Using strategy rm
    5. Applied fma-udef32.5

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

      \[\leadsto \color{blue}{\frac{\frac{1}{x} - \frac{0.5}{{x}^{2}}}{n}} + \frac{\log x \cdot 1}{x \cdot {n}^{2}}\]

    if -35447295026.760864 < n < 604142.6566243569

    1. Initial program 3.3

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

    if 604142.6566243569 < n

    1. Initial program 44.9

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{n}, \frac{1}{x} - \frac{0.5}{{x}^{2}}, \frac{\log x \cdot 1}{x \cdot {n}^{2}}\right)}\]
    4. Taylor expanded around inf 32.6

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{1}{x}, \frac{1}{n} - \frac{\log \left(\frac{1}{x}\right)}{{n}^{2}}, \frac{-0.5}{{x}^{2} \cdot n}\right)}\]
    6. Using strategy rm
    7. Applied fma-udef32.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;n \le -35447295026.760864:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{{x}^{2}}}{n} + \frac{\log x \cdot 1}{x \cdot {n}^{2}}\\ \mathbf{elif}\;n \le 604142.656624356867:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(1, \frac{\log x}{x \cdot {n}^{2}}, \frac{\frac{1}{n}}{x}\right) + \frac{-0.5}{{x}^{2} \cdot n}\\ \end{array}\]

Reproduce

herbie shell --seed 2020071 +o rules:numerics
(FPCore (x n)
  :name "2nthrt (problem 3.4.6)"
  :precision binary64
  (- (pow (+ x 1) (/ 1 n)) (pow x (/ 1 n))))