Average Error: 32.9 → 7.7
Time: 16.0s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{\mathsf{log1p}\left(x\right)}{n}\\ t_2 := e^{t_1}\\ t_3 := \frac{\log x}{n}\\ \mathbf{if}\;x \leq 1.45 \cdot 10^{-294}:\\ \;\;\;\;\frac{{t_2}^{3} + {\left(-t_0\right)}^{3}}{{t_2}^{2} + \left(t_0 \cdot t_0 + t_2 \cdot t_0\right)}\\ \mathbf{elif}\;x \leq 44000:\\ \;\;\;\;\mathsf{fma}\left(0.5, \frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_1}^{3}, t_1\right)\right) - \mathsf{fma}\left(0.5, \frac{{\log x}^{2}}{n \cdot n}, \mathsf{fma}\left(0.16666666666666666, {t_3}^{3}, t_3\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{t_3}}{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 x (/ 1.0 n)))
        (t_1 (/ (log1p x) n))
        (t_2 (exp t_1))
        (t_3 (/ (log x) n)))
   (if (<= x 1.45e-294)
     (/
      (+ (pow t_2 3.0) (pow (- t_0) 3.0))
      (+ (pow t_2 2.0) (+ (* t_0 t_0) (* t_2 t_0))))
     (if (<= x 44000.0)
       (-
        (fma
         0.5
         (/ (pow (log1p x) 2.0) (* n n))
         (fma 0.16666666666666666 (pow t_1 3.0) t_1))
        (fma
         0.5
         (/ (pow (log x) 2.0) (* n n))
         (fma 0.16666666666666666 (pow t_3 3.0) t_3)))
       (/ (exp t_3) (* 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(x, (1.0 / n));
	double t_1 = log1p(x) / n;
	double t_2 = exp(t_1);
	double t_3 = log(x) / n;
	double tmp;
	if (x <= 1.45e-294) {
		tmp = (pow(t_2, 3.0) + pow(-t_0, 3.0)) / (pow(t_2, 2.0) + ((t_0 * t_0) + (t_2 * t_0)));
	} else if (x <= 44000.0) {
		tmp = fma(0.5, (pow(log1p(x), 2.0) / (n * n)), fma(0.16666666666666666, pow(t_1, 3.0), t_1)) - fma(0.5, (pow(log(x), 2.0) / (n * n)), fma(0.16666666666666666, pow(t_3, 3.0), t_3));
	} else {
		tmp = exp(t_3) / (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 = x ^ Float64(1.0 / n)
	t_1 = Float64(log1p(x) / n)
	t_2 = exp(t_1)
	t_3 = Float64(log(x) / n)
	tmp = 0.0
	if (x <= 1.45e-294)
		tmp = Float64(Float64((t_2 ^ 3.0) + (Float64(-t_0) ^ 3.0)) / Float64((t_2 ^ 2.0) + Float64(Float64(t_0 * t_0) + Float64(t_2 * t_0))));
	elseif (x <= 44000.0)
		tmp = Float64(fma(0.5, Float64((log1p(x) ^ 2.0) / Float64(n * n)), fma(0.16666666666666666, (t_1 ^ 3.0), t_1)) - fma(0.5, Float64((log(x) ^ 2.0) / Float64(n * n)), fma(0.16666666666666666, (t_3 ^ 3.0), t_3)));
	else
		tmp = Float64(exp(t_3) / 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[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Log[1 + x], $MachinePrecision] / n), $MachinePrecision]}, Block[{t$95$2 = N[Exp[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]}, If[LessEqual[x, 1.45e-294], N[(N[(N[Power[t$95$2, 3.0], $MachinePrecision] + N[Power[(-t$95$0), 3.0], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$2, 2.0], $MachinePrecision] + N[(N[(t$95$0 * t$95$0), $MachinePrecision] + N[(t$95$2 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 44000.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$1, 3.0], $MachinePrecision] + t$95$1), $MachinePrecision]), $MachinePrecision] - N[(0.5 * N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[(n * n), $MachinePrecision]), $MachinePrecision] + N[(0.16666666666666666 * N[Power[t$95$3, 3.0], $MachinePrecision] + t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[t$95$3], $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 := {x}^{\left(\frac{1}{n}\right)}\\
t_1 := \frac{\mathsf{log1p}\left(x\right)}{n}\\
t_2 := e^{t_1}\\
t_3 := \frac{\log x}{n}\\
\mathbf{if}\;x \leq 1.45 \cdot 10^{-294}:\\
\;\;\;\;\frac{{t_2}^{3} + {\left(-t_0\right)}^{3}}{{t_2}^{2} + \left(t_0 \cdot t_0 + t_2 \cdot t_0\right)}\\

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

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


\end{array}

Error

Derivation

  1. Split input into 3 regimes
  2. if x < 1.45e-294

    1. Initial program 40.5

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

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

    if 1.45e-294 < x < 44000

    1. Initial program 47.1

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

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

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

    if 44000 < x

    1. Initial program 21.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.45 \cdot 10^{-294}:\\ \;\;\;\;\frac{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)}^{3} + {\left(-{x}^{\left(\frac{1}{n}\right)}\right)}^{3}}{{\left(e^{\frac{\mathsf{log1p}\left(x\right)}{n}}\right)}^{2} + \left({x}^{\left(\frac{1}{n}\right)} \cdot {x}^{\left(\frac{1}{n}\right)} + e^{\frac{\mathsf{log1p}\left(x\right)}{n}} \cdot {x}^{\left(\frac{1}{n}\right)}\right)}\\ \mathbf{elif}\;x \leq 44000:\\ \;\;\;\;\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)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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