Average Error: 32.5 → 11.9
Time: 28.1s
Precision: binary64
Cost: 13188
\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;-\mathsf{expm1}\left(\frac{\log x}{n}\right)\\ \mathbf{else}:\\ \;\;\;\;3 - 3\\ \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 1.0) (- (expm1 (/ (log x) n))) (- 3.0 3.0)))
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 <= 1.0) {
		tmp = -expm1((log(x) / n));
	} else {
		tmp = 3.0 - 3.0;
	}
	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 <= 1.0) {
		tmp = -Math.expm1((Math.log(x) / n));
	} else {
		tmp = 3.0 - 3.0;
	}
	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 <= 1.0:
		tmp = -math.expm1((math.log(x) / n))
	else:
		tmp = 3.0 - 3.0
	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 <= 1.0)
		tmp = Float64(-expm1(Float64(log(x) / n)));
	else
		tmp = Float64(3.0 - 3.0);
	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, 1.0], (-N[(Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]] - 1), $MachinePrecision]), N[(3.0 - 3.0), $MachinePrecision]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;-\mathsf{expm1}\left(\frac{\log x}{n}\right)\\

\mathbf{else}:\\
\;\;\;\;3 - 3\\


\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 < 1

    1. Initial program 47.0

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

      \[\leadsto \color{blue}{1 - e^{\frac{\log x}{n}}} \]
    3. Simplified1.8

      \[\leadsto \color{blue}{-\mathsf{expm1}\left(\frac{\log x}{n}\right)} \]
      Proof

    if 1 < 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 40.1

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x}} \]
      Proof
    4. Applied egg-rr20.4

      \[\leadsto \color{blue}{3 - \left(3 + \frac{e^{\frac{\log x}{n}}}{-x}\right)} \]
    5. Taylor expanded in x around inf 20.3

      \[\leadsto 3 - \color{blue}{3} \]
  3. Recombined 2 regimes into one program.

Alternatives

Alternative 1
Error36.6
Cost324
\[\begin{array}{l} \mathbf{if}\;x \leq 1.35:\\ \;\;\;\;\frac{1}{n}\\ \mathbf{else}:\\ \;\;\;\;3 - 3\\ \end{array} \]
Alternative 2
Error38.9
Cost192
\[3 - 3 \]

Error

Reproduce

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