?

Average Error: 51.86% → 17.38%
Time: 21.0s
Precision: binary64
Cost: 20620

?

\[{\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)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-22}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{-24}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 0.4:\\ \;\;\;\;\frac{{\left({t_0}^{3}\right)}^{0.3333333333333333}}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n}} - t_0\\ \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))))
   (if (<= (/ 1.0 n) -1e-22)
     (/ t_0 (* n x))
     (if (<= (/ 1.0 n) 1e-24)
       (/ (log (/ (+ 1.0 x) x)) n)
       (if (<= (/ 1.0 n) 0.4)
         (/ (pow (pow t_0 3.0) 0.3333333333333333) (* n x))
         (- (exp (/ x n)) t_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 t_0 = pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-22) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 1e-24) {
		tmp = log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 0.4) {
		tmp = pow(pow(t_0, 3.0), 0.3333333333333333) / (n * x);
	} else {
		tmp = exp((x / n)) - t_0;
	}
	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) :: t_0
    real(8) :: tmp
    t_0 = x ** (1.0d0 / n)
    if ((1.0d0 / n) <= (-1d-22)) then
        tmp = t_0 / (n * x)
    else if ((1.0d0 / n) <= 1d-24) then
        tmp = log(((1.0d0 + x) / x)) / n
    else if ((1.0d0 / n) <= 0.4d0) then
        tmp = ((t_0 ** 3.0d0) ** 0.3333333333333333d0) / (n * x)
    else
        tmp = exp((x / n)) - t_0
    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 t_0 = Math.pow(x, (1.0 / n));
	double tmp;
	if ((1.0 / n) <= -1e-22) {
		tmp = t_0 / (n * x);
	} else if ((1.0 / n) <= 1e-24) {
		tmp = Math.log(((1.0 + x) / x)) / n;
	} else if ((1.0 / n) <= 0.4) {
		tmp = Math.pow(Math.pow(t_0, 3.0), 0.3333333333333333) / (n * x);
	} else {
		tmp = Math.exp((x / n)) - t_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):
	t_0 = math.pow(x, (1.0 / n))
	tmp = 0
	if (1.0 / n) <= -1e-22:
		tmp = t_0 / (n * x)
	elif (1.0 / n) <= 1e-24:
		tmp = math.log(((1.0 + x) / x)) / n
	elif (1.0 / n) <= 0.4:
		tmp = math.pow(math.pow(t_0, 3.0), 0.3333333333333333) / (n * x)
	else:
		tmp = math.exp((x / n)) - t_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)
	t_0 = x ^ Float64(1.0 / n)
	tmp = 0.0
	if (Float64(1.0 / n) <= -1e-22)
		tmp = Float64(t_0 / Float64(n * x));
	elseif (Float64(1.0 / n) <= 1e-24)
		tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n);
	elseif (Float64(1.0 / n) <= 0.4)
		tmp = Float64(((t_0 ^ 3.0) ^ 0.3333333333333333) / Float64(n * x));
	else
		tmp = Float64(exp(Float64(x / n)) - t_0);
	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)
	t_0 = x ^ (1.0 / n);
	tmp = 0.0;
	if ((1.0 / n) <= -1e-22)
		tmp = t_0 / (n * x);
	elseif ((1.0 / n) <= 1e-24)
		tmp = log(((1.0 + x) / x)) / n;
	elseif ((1.0 / n) <= 0.4)
		tmp = ((t_0 ^ 3.0) ^ 0.3333333333333333) / (n * x);
	else
		tmp = exp((x / n)) - t_0;
	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_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-22], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e-24], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.4], N[(N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $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)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-22}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\

\mathbf{elif}\;\frac{1}{n} \leq 10^{-24}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\

\mathbf{elif}\;\frac{1}{n} \leq 0.4:\\
\;\;\;\;\frac{{\left({t_0}^{3}\right)}^{0.3333333333333333}}{n \cdot x}\\

\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 4 regimes
  2. if (/.f64 1 n) < -1e-22

    1. Initial program 9.3

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
      Proof

      [Start]6.81

      \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x} \]

      mul-1-neg [=>]6.81

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

      log-rec [=>]6.81

      \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]

      mul-1-neg [<=]6.81

      \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]

      distribute-neg-frac [=>]6.81

      \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]

      mul-1-neg [=>]6.81

      \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]

      remove-double-neg [=>]6.81

      \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]

      *-commutative [=>]6.81

      \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    4. Taylor expanded in x around 0 6.81

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{n \cdot x}} \]
    5. Simplified6.81

      \[\leadsto \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}} \]
      Proof

      [Start]6.81

      \[ \frac{e^{\frac{\log x}{n}}}{n \cdot x} \]

      *-rgt-identity [<=]6.81

      \[ \frac{e^{\color{blue}{\frac{\log x}{n} \cdot 1}}}{n \cdot x} \]

      associate-*l/ [=>]6.81

      \[ \frac{e^{\color{blue}{\frac{\log x \cdot 1}{n}}}}{n \cdot x} \]

      associate-*r/ [<=]6.81

      \[ \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x} \]

      exp-to-pow [=>]6.81

      \[ \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{n \cdot x} \]

      *-commutative [<=]6.81

      \[ \frac{{x}^{\left(\frac{1}{n}\right)}}{\color{blue}{x \cdot n}} \]

    if -1e-22 < (/.f64 1 n) < 9.99999999999999924e-25

    1. Initial program 70.04

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

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

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

      [Start]21.42

      \[ \frac{\log \left(1 + x\right) - \log x}{n} \]

      log1p-def [=>]21.42

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

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

    if 9.99999999999999924e-25 < (/.f64 1 n) < 0.40000000000000002

    1. Initial program 67.1

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \]
      Proof

      [Start]51.82

      \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x} \]

      mul-1-neg [=>]51.82

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

      log-rec [=>]51.82

      \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x} \]

      mul-1-neg [<=]51.82

      \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x} \]

      distribute-neg-frac [=>]51.82

      \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x} \]

      mul-1-neg [=>]51.82

      \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x} \]

      remove-double-neg [=>]51.82

      \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x} \]

      *-commutative [=>]51.82

      \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}} \]
    4. Applied egg-rr51.87

      \[\leadsto \frac{\color{blue}{{\left({\left({x}^{\left(\frac{1}{n}\right)}\right)}^{3}\right)}^{0.3333333333333333}}}{x \cdot n} \]

    if 0.40000000000000002 < (/.f64 1 n)

    1. Initial program 6.27

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

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

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

      [Start]6.27

      \[ e^{\frac{\log \left(1 + x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)} \]

      log1p-def [=>]0.68

      \[ e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)} \]
    4. Taylor expanded in x around 0 0.98

      \[\leadsto e^{\color{blue}{\frac{x}{n}}} - {x}^{\left(\frac{1}{n}\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification17.38

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-22}:\\ \;\;\;\;\frac{{x}^{\left(\frac{1}{n}\right)}}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{-24}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 0.4:\\ \;\;\;\;\frac{{\left({\left({x}^{\left(\frac{1}{n}\right)}\right)}^{3}\right)}^{0.3333333333333333}}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n}} - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error17.38%
Cost14092
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-22}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;\frac{1}{n} \leq 10^{-24}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;\frac{1}{n} \leq 0.4:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{n}} - t_0\\ \end{array} \]
Alternative 2
Error17.8%
Cost13776
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;n \leq -1.85 \cdot 10^{+24}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;n \leq -2 \cdot 10^{-306}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \mathbf{elif}\;n \leq 1.2:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{elif}\;n \leq 5.8 \cdot 10^{+22}:\\ \;\;\;\;\frac{e^{\frac{\log x}{n}}}{n \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{n} \cdot \log \left(\frac{x}{1 + x}\right)\\ \end{array} \]
Alternative 3
Error17.83%
Cost7504
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ t_1 := \frac{t_0}{n \cdot x}\\ \mathbf{if}\;n \leq -1.95 \cdot 10^{+24}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{elif}\;n \leq -2 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;n \leq 0.8:\\ \;\;\;\;\left(1 + \frac{x}{n}\right) - t_0\\ \mathbf{elif}\;n \leq 5.9 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{n} \cdot \log \left(\frac{x}{1 + x}\right)\\ \end{array} \]
Alternative 4
Error12.04%
Cost7308
\[\begin{array}{l} t_0 := {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{if}\;x \leq 2.8 \cdot 10^{-211}:\\ \;\;\;\;\log x \cdot \frac{-1}{n}\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-193}:\\ \;\;\;\;1 - t_0\\ \mathbf{elif}\;x \leq 100:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{n \cdot x}\\ \end{array} \]
Alternative 5
Error25.01%
Cost7116
\[\begin{array}{l} \mathbf{if}\;x \leq 2.8 \cdot 10^{-211}:\\ \;\;\;\;\log x \cdot \frac{-1}{n}\\ \mathbf{elif}\;x \leq 1.9 \cdot 10^{-193}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \mathbf{elif}\;x \leq 0.86:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 2.9 \cdot 10^{+118}:\\ \;\;\;\;\frac{\frac{1}{x} + \left(\frac{1}{x} \cdot \frac{0.3333333333333333}{x \cdot x} + \frac{-0.5}{x \cdot x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{n} \cdot 0\\ \end{array} \]
Alternative 6
Error19.2%
Cost7108
\[\begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;1 - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
Alternative 7
Error23.77%
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 0.86:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 1.4 \cdot 10^{+118}:\\ \;\;\;\;\frac{\frac{1}{x} + \left(\frac{1}{x} \cdot \frac{0.3333333333333333}{x \cdot x} + \frac{-0.5}{x \cdot x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{n} \cdot 0\\ \end{array} \]
Alternative 8
Error25.96%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{+221}:\\ \;\;\;\;\frac{\frac{1}{x} + \left(\frac{1}{x} \cdot \frac{0.3333333333333333}{x \cdot x} + \frac{-0.5}{x \cdot x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(1 + \frac{1}{n \cdot x}\right)\\ \end{array} \]
Alternative 9
Error24.14%
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.6:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+118}:\\ \;\;\;\;\frac{\frac{1}{x} + \left(\frac{1}{x} \cdot \frac{0.3333333333333333}{x \cdot x} + \frac{-0.5}{x \cdot x}\right)}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{n} \cdot 0\\ \end{array} \]
Alternative 10
Error55.08%
Cost841
\[\begin{array}{l} \mathbf{if}\;n \leq -820000000 \lor \neg \left(n \leq -2 \cdot 10^{-270}\right):\\ \;\;\;\;\frac{\frac{1}{n}}{x}\\ \mathbf{else}:\\ \;\;\;\;-1 + \left(1 + \frac{1}{n \cdot x}\right)\\ \end{array} \]
Alternative 11
Error63.25%
Cost320
\[\frac{1}{n \cdot x} \]
Alternative 12
Error62.66%
Cost320
\[\frac{\frac{1}{n}}{x} \]

Error

Reproduce?

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