Average Error: 30.0 → 6.0
Time: 12.5s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 97.60932735527969:\\ \;\;\;\;-\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log x - \mathsf{log1p}\left(x\right)}{n}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq 97.60932735527969:\\
\;\;\;\;-\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log x - \mathsf{log1p}\left(x\right)}{n}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot 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 (<= x 97.60932735527969)
   (- (log1p (expm1 (/ (- (log x) (log1p x)) n))))
   (/ (exp (/ (log x) n)) (* 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 (x <= 97.60932735527969) {
		tmp = -log1p(expm1((log(x) - log1p(x)) / n));
	} else {
		tmp = exp(log(x) / n) / (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 x < 97.6093273552796887

    1. Initial program 36.1

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

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

      \[\leadsto \color{blue}{-\frac{\log x - \mathsf{log1p}\left(x\right)}{n}} \]
    4. Applied log1p-expm1-u_binary649.5

      \[\leadsto -\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log x - \mathsf{log1p}\left(x\right)}{n}\right)\right)} \]

    if 97.6093273552796887 < x

    1. Initial program 21.9

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification6.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 97.60932735527969:\\ \;\;\;\;-\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\log x - \mathsf{log1p}\left(x\right)}{n}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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