Average Error: 32.4 → 7.1
Time: 13.8s
Precision: binary64
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 6906.254529779961:\\ \;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n}\\ \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 6906.254529779961)
   (/ (log (/ (+ x 1.0) 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 <= 6906.254529779961) {
		tmp = log(((x + 1.0) / x)) / n;
	} else {
		tmp = exp((log(x) / n)) / (x * n);
	}
	return tmp;
}
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    code = ((x + 1.0d0) ** (1.0d0 / n)) - (x ** (1.0d0 / n))
end function
real(8) function code(x, n)
    real(8), intent (in) :: x
    real(8), intent (in) :: n
    real(8) :: tmp
    if (x <= 6906.254529779961d0) then
        tmp = log(((x + 1.0d0) / x)) / n
    else
        tmp = exp((log(x) / n)) / (x * n)
    end if
    code = tmp
end function
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 <= 6906.254529779961) {
		tmp = Math.log(((x + 1.0) / x)) / 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 <= 6906.254529779961:
		tmp = math.log(((x + 1.0) / x)) / 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 <= 6906.254529779961)
		tmp = Float64(log(Float64(Float64(x + 1.0) / x)) / n);
	else
		tmp = Float64(exp(Float64(log(x) / n)) / Float64(x * n));
	end
	return tmp
end
function tmp = code(x, n)
	tmp = ((x + 1.0) ^ (1.0 / n)) - (x ^ (1.0 / n));
end
function tmp_2 = code(x, n)
	tmp = 0.0;
	if (x <= 6906.254529779961)
		tmp = log(((x + 1.0) / x)) / n;
	else
		tmp = exp((log(x) / n)) / (x * n);
	end
	tmp_2 = 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, 6906.254529779961], N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $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 6906.254529779961:\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n}\\

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


\end{array}

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 < 6906.2545297799606

    1. Initial program 47.0

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

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

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

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

    if 6906.2545297799606 < x

    1. Initial program 20.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6906.254529779961:\\ \;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{x \cdot n}\\ \end{array} \]

Reproduce

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