Average Error: 33.0 → 6.8
Time: 15.0s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 52:\\ \;\;\;\;\left(\frac{\log \left(\frac{x + 1}{x}\right)}{n} + \frac{-0.16666666666666666}{{n}^{3}} \cdot \left({\log x}^{3} - {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right)\right) + \frac{0.5}{n} \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n} - \frac{{\log x}^{2}}{n}\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 52.0)
   (+
    (+
     (/ (log (/ (+ x 1.0) x)) n)
     (*
      (/ -0.16666666666666666 (pow n 3.0))
      (- (pow (log x) 3.0) (pow (log1p x) 3.0))))
    (* (/ 0.5 n) (- (/ (pow (log1p x) 2.0) n) (/ (pow (log x) 2.0) 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 <= 52.0) {
		tmp = ((log(((x + 1.0) / x)) / n) + ((-0.16666666666666666 / pow(n, 3.0)) * (pow(log(x), 3.0) - pow(log1p(x), 3.0)))) + ((0.5 / n) * ((pow(log1p(x), 2.0) / n) - (pow(log(x), 2.0) / n)));
	} else {
		tmp = exp((log(x) / n)) / (x * n);
	}
	return tmp;
}
public static double code(double x, double n) {
	return Math.pow((x + 1.0), (1.0 / n)) - Math.pow(x, (1.0 / n));
}
public static double code(double x, double n) {
	double tmp;
	if (x <= 52.0) {
		tmp = ((Math.log(((x + 1.0) / x)) / n) + ((-0.16666666666666666 / Math.pow(n, 3.0)) * (Math.pow(Math.log(x), 3.0) - Math.pow(Math.log1p(x), 3.0)))) + ((0.5 / n) * ((Math.pow(Math.log1p(x), 2.0) / n) - (Math.pow(Math.log(x), 2.0) / n)));
	} else {
		tmp = Math.exp((Math.log(x) / n)) / (x * n);
	}
	return tmp;
}
def code(x, n):
	return math.pow((x + 1.0), (1.0 / n)) - math.pow(x, (1.0 / n))
def code(x, n):
	tmp = 0
	if x <= 52.0:
		tmp = ((math.log(((x + 1.0) / x)) / n) + ((-0.16666666666666666 / math.pow(n, 3.0)) * (math.pow(math.log(x), 3.0) - math.pow(math.log1p(x), 3.0)))) + ((0.5 / n) * ((math.pow(math.log1p(x), 2.0) / n) - (math.pow(math.log(x), 2.0) / n)))
	else:
		tmp = math.exp((math.log(x) / n)) / (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)
	tmp = 0.0
	if (x <= 52.0)
		tmp = Float64(Float64(Float64(log(Float64(Float64(x + 1.0) / x)) / n) + Float64(Float64(-0.16666666666666666 / (n ^ 3.0)) * Float64((log(x) ^ 3.0) - (log1p(x) ^ 3.0)))) + Float64(Float64(0.5 / n) * Float64(Float64((log1p(x) ^ 2.0) / n) - Float64((log(x) ^ 2.0) / n))));
	else
		tmp = Float64(exp(Float64(log(x) / n)) / 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_] := If[LessEqual[x, 52.0], N[(N[(N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision] + N[(N[(-0.16666666666666666 / N[Power[n, 3.0], $MachinePrecision]), $MachinePrecision] * N[(N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision] - N[Power[N[Log[1 + x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(0.5 / n), $MachinePrecision] * N[(N[(N[Power[N[Log[1 + x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision] - N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / n), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]], $MachinePrecision] / N[(x * n), $MachinePrecision]), $MachinePrecision]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq 52:\\
\;\;\;\;\left(\frac{\log \left(\frac{x + 1}{x}\right)}{n} + \frac{-0.16666666666666666}{{n}^{3}} \cdot \left({\log x}^{3} - {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right)\right) + \frac{0.5}{n} \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n} - \frac{{\log x}^{2}}{n}\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if x < 52

    1. Initial program 47.8

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

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

      \[\leadsto \color{blue}{\left(\frac{\mathsf{log1p}\left(x\right) - \log x}{n} - \frac{-0.16666666666666666}{{n}^{3}} \cdot \left({\left(\mathsf{log1p}\left(x\right)\right)}^{3} - {\log x}^{3}\right)\right) + \frac{0.5}{n} \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n} - \frac{{\log x}^{2}}{n}\right)} \]
    4. Applied egg-rr12.9

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

    if 52 < x

    1. Initial program 20.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 52:\\ \;\;\;\;\left(\frac{\log \left(\frac{x + 1}{x}\right)}{n} + \frac{-0.16666666666666666}{{n}^{3}} \cdot \left({\log x}^{3} - {\left(\mathsf{log1p}\left(x\right)\right)}^{3}\right)\right) + \frac{0.5}{n} \cdot \left(\frac{{\left(\mathsf{log1p}\left(x\right)\right)}^{2}}{n} - \frac{{\log x}^{2}}{n}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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