Average Error: 32.2 → 8.3
Time: 12.5s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := \frac{\mathsf{log1p}\left(x\right)}{n}\\ t_1 := \frac{\log x}{n}\\ t_2 := e^{t_1}\\ \mathbf{if}\;x \leq 2 \cdot 10^{-223}:\\ \;\;\;\;{\left(\frac{n}{-\log x}\right)}^{-1}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-193}:\\ \;\;\;\;e^{t_0} - t_2\\ \mathbf{elif}\;x \leq 3100000:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_0}^{3}, t_0\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_1}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, t_1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{t_2}{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
 (let* ((t_0 (/ (log1p x) n)) (t_1 (/ (log x) n)) (t_2 (exp t_1)))
   (if (<= x 2e-223)
     (pow (/ n (- (log x))) -1.0)
     (if (<= x 6.2e-193)
       (- (exp t_0) t_2)
       (if (<= x 3100000.0)
         (-
          (fma
           0.5
           (/ (pow (log1p x) 2.0) (* n n))
           (fma 0.16666666666666666 (pow t_0 3.0) t_0))
          (fma
           0.16666666666666666
           (pow t_1 3.0)
           (fma 0.5 (/ (pow (log x) 2.0) (* n n)) t_1)))
         (/ t_2 (* 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 t_0 = log1p(x) / n;
	double t_1 = log(x) / n;
	double t_2 = exp(t_1);
	double tmp;
	if (x <= 2e-223) {
		tmp = pow((n / -log(x)), -1.0);
	} else if (x <= 6.2e-193) {
		tmp = exp(t_0) - t_2;
	} else if (x <= 3100000.0) {
		tmp = fma(0.5, (pow(log1p(x), 2.0) / (n * n)), fma(0.16666666666666666, pow(t_0, 3.0), t_0)) - fma(0.16666666666666666, pow(t_1, 3.0), fma(0.5, (pow(log(x), 2.0) / (n * n)), t_1));
	} else {
		tmp = t_2 / (x * n);
	}
	return tmp;
}
function code(x, n)
	return Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - (x ^ Float64(1.0 / n)))
end
function code(x, n)
	t_0 = Float64(log1p(x) / n)
	t_1 = Float64(log(x) / n)
	t_2 = exp(t_1)
	tmp = 0.0
	if (x <= 2e-223)
		tmp = Float64(n / Float64(-log(x))) ^ -1.0;
	elseif (x <= 6.2e-193)
		tmp = Float64(exp(t_0) - t_2);
	elseif (x <= 3100000.0)
		tmp = Float64(fma(0.5, Float64((log1p(x) ^ 2.0) / Float64(n * n)), fma(0.16666666666666666, (t_0 ^ 3.0), t_0)) - fma(0.16666666666666666, (t_1 ^ 3.0), fma(0.5, Float64((log(x) ^ 2.0) / Float64(n * n)), t_1)));
	else
		tmp = Float64(t_2 / Float64(x * n));
	end
	return tmp
end
code[x_, n_] := N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, n_] := Block[{t$95$0 = N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]}, Block[{t$95$2 = N[Exp[t$95$1], $MachinePrecision]}, If[LessEqual[x, 2e-223], N[Power[N[(n / (-N[Log[x], $MachinePrecision])), $MachinePrecision], -1.0], $MachinePrecision], If[LessEqual[x, 6.2e-193], N[(N[Exp[t$95$0], $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[x, 3100000.0], N[(N[(0.5 * N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * n), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[Power[t$95$0, 3.0], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] - N[(0.16666666666666666 * N[Power[t$95$1, 3.0], $MachinePrecision] + N[(0.5 * N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * n), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$2 / N[(x * n), $MachinePrecision]), $MachinePrecision]]]]]]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
t_0 := \frac{\mathsf{log1p}\left(x\right)}{n}\\
t_1 := \frac{\log x}{n}\\
t_2 := e^{t_1}\\
\mathbf{if}\;x \leq 2 \cdot 10^{-223}:\\
\;\;\;\;{\left(\frac{n}{-\log x}\right)}^{-1}\\

\mathbf{elif}\;x \leq 6.2 \cdot 10^{-193}:\\
\;\;\;\;e^{t_0} - t_2\\

\mathbf{elif}\;x \leq 3100000:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_0}^{3}, t_0\right)\right) - \mathsf{fma}\left(0.16666666666666666, {t_1}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, t_1\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{t_2}{x \cdot n}\\


\end{array}

Error

Bits error versus x

Bits error versus n

Derivation

  1. Split input into 4 regimes
  2. if x < 1.9999999999999999e-223

    1. Initial program 39.5

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

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

      \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(x\right) - \log x}{n}} \]
    4. Applied egg-rr21.7

      \[\leadsto \color{blue}{{\left(\frac{n}{\mathsf{log1p}\left(x\right) - \log x}\right)}^{-1}} \]
    5. Taylor expanded in x around 0 21.7

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

    if 1.9999999999999999e-223 < x < 6.2000000000000004e-193

    1. Initial program 41.6

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

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

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

    if 6.2000000000000004e-193 < x < 3.1e6

    1. Initial program 50.7

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\mathsf{log1p}\left(x\right)}{n}\right)}^{3}, \frac{\mathsf{log1p}\left(x\right)}{n}\right)\right) - \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\log x}{n}\right)}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, \frac{\log x}{n}\right)\right)} \]

    if 3.1e6 < x

    1. Initial program 20.3

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2 \cdot 10^{-223}:\\ \;\;\;\;{\left(\frac{n}{-\log x}\right)}^{-1}\\ \mathbf{elif}\;x \leq 6.2 \cdot 10^{-193}:\\ \;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - e^{\frac{\log x}{n}}\\ \mathbf{elif}\;x \leq 3100000:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\mathsf{log1p}\left(x\right)}{n}\right)}^{3}, \frac{\mathsf{log1p}\left(x\right)}{n}\right)\right) - \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\log x}{n}\right)}^{3}, \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, \frac{\log x}{n}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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