Average Error: 32.6 → 9.0
Time: 16.6s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := {\log x}^{2}\\ t_1 := \frac{\log x}{n}\\ t_2 := \log \left(x + 1\right)\\ t_3 := {\log x}^{3}\\ \mathbf{if}\;x \leq 2.7 \cdot 10^{-246}:\\ \;\;\;\;\frac{x}{n} + \left(\frac{t_3}{{n}^{3}} \cdot -0.16666666666666666 - \mathsf{fma}\left(0.5, \frac{t_0}{n \cdot n}, t_1\right)\right)\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-225}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-13}:\\ \;\;\;\;\left(0.5 \cdot \frac{{t_2}^{2}}{{n}^{2}} + \left(0.041666666666666664 \cdot \frac{{t_2}^{4}}{{n}^{4}} + \left(\frac{t_3 \cdot -0.16666666666666666 + 0.16666666666666666 \cdot {t_2}^{3}}{{n}^{3}} + \frac{t_2 - \log x}{n}\right)\right)\right) + \left(\frac{t_0}{{n}^{2}} \cdot -0.5 + \frac{{\log x}^{4}}{{n}^{4}} \cdot -0.041666666666666664\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{t_1}}{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 (pow (log x) 2.0))
        (t_1 (/ (log x) n))
        (t_2 (log (+ x 1.0)))
        (t_3 (pow (log x) 3.0)))
   (if (<= x 2.7e-246)
     (+
      (/ x n)
      (-
       (* (/ t_3 (pow n 3.0)) -0.16666666666666666)
       (fma 0.5 (/ t_0 (* n n)) t_1)))
     (if (<= x 1.7e-225)
       (- (pow (+ x 1.0) (/ 1.0 n)) (expm1 (log1p (pow x (/ 1.0 n)))))
       (if (<= x 2.1e-13)
         (+
          (+
           (* 0.5 (/ (pow t_2 2.0) (pow n 2.0)))
           (+
            (* 0.041666666666666664 (/ (pow t_2 4.0) (pow n 4.0)))
            (+
             (/
              (+
               (* t_3 -0.16666666666666666)
               (* 0.16666666666666666 (pow t_2 3.0)))
              (pow n 3.0))
             (/ (- t_2 (log x)) n))))
          (+
           (* (/ t_0 (pow n 2.0)) -0.5)
           (* (/ (pow (log x) 4.0) (pow n 4.0)) -0.041666666666666664)))
         (/ (exp t_1) (* 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 = pow(log(x), 2.0);
	double t_1 = log(x) / n;
	double t_2 = log((x + 1.0));
	double t_3 = pow(log(x), 3.0);
	double tmp;
	if (x <= 2.7e-246) {
		tmp = (x / n) + (((t_3 / pow(n, 3.0)) * -0.16666666666666666) - fma(0.5, (t_0 / (n * n)), t_1));
	} else if (x <= 1.7e-225) {
		tmp = pow((x + 1.0), (1.0 / n)) - expm1(log1p(pow(x, (1.0 / n))));
	} else if (x <= 2.1e-13) {
		tmp = ((0.5 * (pow(t_2, 2.0) / pow(n, 2.0))) + ((0.041666666666666664 * (pow(t_2, 4.0) / pow(n, 4.0))) + ((((t_3 * -0.16666666666666666) + (0.16666666666666666 * pow(t_2, 3.0))) / pow(n, 3.0)) + ((t_2 - log(x)) / n)))) + (((t_0 / pow(n, 2.0)) * -0.5) + ((pow(log(x), 4.0) / pow(n, 4.0)) * -0.041666666666666664));
	} else {
		tmp = exp(t_1) / (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 = log(x) ^ 2.0
	t_1 = Float64(log(x) / n)
	t_2 = log(Float64(x + 1.0))
	t_3 = log(x) ^ 3.0
	tmp = 0.0
	if (x <= 2.7e-246)
		tmp = Float64(Float64(x / n) + Float64(Float64(Float64(t_3 / (n ^ 3.0)) * -0.16666666666666666) - fma(0.5, Float64(t_0 / Float64(n * n)), t_1)));
	elseif (x <= 1.7e-225)
		tmp = Float64((Float64(x + 1.0) ^ Float64(1.0 / n)) - expm1(log1p((x ^ Float64(1.0 / n)))));
	elseif (x <= 2.1e-13)
		tmp = Float64(Float64(Float64(0.5 * Float64((t_2 ^ 2.0) / (n ^ 2.0))) + Float64(Float64(0.041666666666666664 * Float64((t_2 ^ 4.0) / (n ^ 4.0))) + Float64(Float64(Float64(Float64(t_3 * -0.16666666666666666) + Float64(0.16666666666666666 * (t_2 ^ 3.0))) / (n ^ 3.0)) + Float64(Float64(t_2 - log(x)) / n)))) + Float64(Float64(Float64(t_0 / (n ^ 2.0)) * -0.5) + Float64(Float64((log(x) ^ 4.0) / (n ^ 4.0)) * -0.041666666666666664)));
	else
		tmp = Float64(exp(t_1) / 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[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]}, Block[{t$95$2 = N[Log[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]}, If[LessEqual[x, 2.7e-246], N[(N[(x / n), $MachinePrecision] + N[(N[(N[(t$95$3 / N[Power[n, 3.0], $MachinePrecision]), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - N[(0.5 * N[(t$95$0 / N[(n * n), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.7e-225], N[(N[Power[N[(x + 1.0), $MachinePrecision], N[(1.0 / n), $MachinePrecision]], $MachinePrecision] - N[(Exp[N[Log[1 + N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 2.1e-13], N[(N[(N[(0.5 * N[(N[Power[t$95$2, 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.041666666666666664 * N[(N[Power[t$95$2, 4.0], $MachinePrecision] / N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(t$95$3 * -0.16666666666666666), $MachinePrecision] + N[(0.16666666666666666 * N[Power[t$95$2, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[n, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(t$95$2 - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(t$95$0 / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] + N[(N[(N[Power[N[Log[x], $MachinePrecision], 4.0], $MachinePrecision] / N[Power[n, 4.0], $MachinePrecision]), $MachinePrecision] * -0.041666666666666664), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[t$95$1], $MachinePrecision] / 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 := {\log x}^{2}\\
t_1 := \frac{\log x}{n}\\
t_2 := \log \left(x + 1\right)\\
t_3 := {\log x}^{3}\\
\mathbf{if}\;x \leq 2.7 \cdot 10^{-246}:\\
\;\;\;\;\frac{x}{n} + \left(\frac{t_3}{{n}^{3}} \cdot -0.16666666666666666 - \mathsf{fma}\left(0.5, \frac{t_0}{n \cdot n}, t_1\right)\right)\\

\mathbf{elif}\;x \leq 1.7 \cdot 10^{-225}:\\
\;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\

\mathbf{elif}\;x \leq 2.1 \cdot 10^{-13}:\\
\;\;\;\;\left(0.5 \cdot \frac{{t_2}^{2}}{{n}^{2}} + \left(0.041666666666666664 \cdot \frac{{t_2}^{4}}{{n}^{4}} + \left(\frac{t_3 \cdot -0.16666666666666666 + 0.16666666666666666 \cdot {t_2}^{3}}{{n}^{3}} + \frac{t_2 - \log x}{n}\right)\right)\right) + \left(\frac{t_0}{{n}^{2}} \cdot -0.5 + \frac{{\log x}^{4}}{{n}^{4}} \cdot -0.041666666666666664\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{t_1}}{x \cdot n}\\


\end{array}

Error

Derivation

  1. Split input into 4 regimes
  2. if x < 2.6999999999999999e-246

    1. Initial program 40.8

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

      \[\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(\frac{\log x}{n} + \left(0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}} + 0.16666666666666666 \cdot \frac{{\log x}^{3}}{{n}^{3}}\right)\right)} \]
    3. Simplified19.9

      \[\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.5, \frac{{\log x}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {\left(\frac{\log x}{n}\right)}^{3}, \frac{\log x}{n}\right)\right)} \]
    4. Taylor expanded in x around 0 19.9

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

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

    if 2.6999999999999999e-246 < x < 1.7e-225

    1. Initial program 43.1

      \[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
    2. Applied egg-rr43.1

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

    if 1.7e-225 < x < 2.09999999999999989e-13

    1. Initial program 49.0

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

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

    if 2.09999999999999989e-13 < x

    1. Initial program 21.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.7 \cdot 10^{-246}:\\ \;\;\;\;\frac{x}{n} + \left(\frac{{\log x}^{3}}{{n}^{3}} \cdot -0.16666666666666666 - \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, \frac{\log x}{n}\right)\right)\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-225}:\\ \;\;\;\;{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - \mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\left(\frac{1}{n}\right)}\right)\right)\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{-13}:\\ \;\;\;\;\left(0.5 \cdot \frac{{\log \left(x + 1\right)}^{2}}{{n}^{2}} + \left(0.041666666666666664 \cdot \frac{{\log \left(x + 1\right)}^{4}}{{n}^{4}} + \left(\frac{{\log x}^{3} \cdot -0.16666666666666666 + 0.16666666666666666 \cdot {\log \left(x + 1\right)}^{3}}{{n}^{3}} + \frac{\log \left(x + 1\right) - \log x}{n}\right)\right)\right) + \left(\frac{{\log x}^{2}}{{n}^{2}} \cdot -0.5 + \frac{{\log x}^{4}}{{n}^{4}} \cdot -0.041666666666666664\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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