?

Average Error: 32.3 → 7.1
Time: 23.7s
Precision: binary64
Cost: 85892

?

\[{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)} \]
\[\begin{array}{l} t_0 := \log \left(1 + x\right)\\ \mathbf{if}\;x \leq 120000:\\ \;\;\;\;-1 \cdot \left(\frac{-1 \cdot \left(t_0 - \log x\right)}{n} + \frac{-0.16666666666666666 \cdot \left({t_0}^{3} - {\log x}^{3}\right)}{{n}^{3}}\right) + 0.5 \cdot \left(\frac{{t_0}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-\left(-\frac{\log x}{n}\right)}}{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 (log (+ 1.0 x))))
   (if (<= x 120000.0)
     (+
      (*
       -1.0
       (+
        (/ (* -1.0 (- t_0 (log x))) n)
        (/
         (* -0.16666666666666666 (- (pow t_0 3.0) (pow (log x) 3.0)))
         (pow n 3.0))))
      (*
       0.5
       (- (/ (pow t_0 2.0) (pow n 2.0)) (/ (pow (log x) 2.0) (pow n 2.0)))))
     (/ (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 t_0 = log((1.0 + x));
	double tmp;
	if (x <= 120000.0) {
		tmp = (-1.0 * (((-1.0 * (t_0 - log(x))) / n) + ((-0.16666666666666666 * (pow(t_0, 3.0) - pow(log(x), 3.0))) / pow(n, 3.0)))) + (0.5 * ((pow(t_0, 2.0) / pow(n, 2.0)) - (pow(log(x), 2.0) / pow(n, 2.0))));
	} 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) :: t_0
    real(8) :: tmp
    t_0 = log((1.0d0 + x))
    if (x <= 120000.0d0) then
        tmp = ((-1.0d0) * ((((-1.0d0) * (t_0 - log(x))) / n) + (((-0.16666666666666666d0) * ((t_0 ** 3.0d0) - (log(x) ** 3.0d0))) / (n ** 3.0d0)))) + (0.5d0 * (((t_0 ** 2.0d0) / (n ** 2.0d0)) - ((log(x) ** 2.0d0) / (n ** 2.0d0))))
    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 t_0 = Math.log((1.0 + x));
	double tmp;
	if (x <= 120000.0) {
		tmp = (-1.0 * (((-1.0 * (t_0 - Math.log(x))) / n) + ((-0.16666666666666666 * (Math.pow(t_0, 3.0) - Math.pow(Math.log(x), 3.0))) / Math.pow(n, 3.0)))) + (0.5 * ((Math.pow(t_0, 2.0) / Math.pow(n, 2.0)) - (Math.pow(Math.log(x), 2.0) / Math.pow(n, 2.0))));
	} 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):
	t_0 = math.log((1.0 + x))
	tmp = 0
	if x <= 120000.0:
		tmp = (-1.0 * (((-1.0 * (t_0 - math.log(x))) / n) + ((-0.16666666666666666 * (math.pow(t_0, 3.0) - math.pow(math.log(x), 3.0))) / math.pow(n, 3.0)))) + (0.5 * ((math.pow(t_0, 2.0) / math.pow(n, 2.0)) - (math.pow(math.log(x), 2.0) / math.pow(n, 2.0))))
	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)
	t_0 = log(Float64(1.0 + x))
	tmp = 0.0
	if (x <= 120000.0)
		tmp = Float64(Float64(-1.0 * Float64(Float64(Float64(-1.0 * Float64(t_0 - log(x))) / n) + Float64(Float64(-0.16666666666666666 * Float64((t_0 ^ 3.0) - (log(x) ^ 3.0))) / (n ^ 3.0)))) + Float64(0.5 * Float64(Float64((t_0 ^ 2.0) / (n ^ 2.0)) - Float64((log(x) ^ 2.0) / (n ^ 2.0)))));
	else
		tmp = Float64(exp(Float64(-Float64(-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)
	t_0 = log((1.0 + x));
	tmp = 0.0;
	if (x <= 120000.0)
		tmp = (-1.0 * (((-1.0 * (t_0 - log(x))) / n) + ((-0.16666666666666666 * ((t_0 ^ 3.0) - (log(x) ^ 3.0))) / (n ^ 3.0)))) + (0.5 * (((t_0 ^ 2.0) / (n ^ 2.0)) - ((log(x) ^ 2.0) / (n ^ 2.0))));
	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_] := Block[{t$95$0 = N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, 120000.0], N[(N[(-1.0 * N[(N[(N[(-1.0 * N[(t$95$0 - N[Log[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision] + N[(N[(-0.16666666666666666 * N[(N[Power[t$95$0, 3.0], $MachinePrecision] - N[Power[N[Log[x], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[n, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(N[(N[Power[t$95$0, 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $MachinePrecision] - N[(N[Power[N[Log[x], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[n, 2.0], $MachinePrecision]), $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}
t_0 := \log \left(1 + x\right)\\
\mathbf{if}\;x \leq 120000:\\
\;\;\;\;-1 \cdot \left(\frac{-1 \cdot \left(t_0 - \log x\right)}{n} + \frac{-0.16666666666666666 \cdot \left({t_0}^{3} - {\log x}^{3}\right)}{{n}^{3}}\right) + 0.5 \cdot \left(\frac{{t_0}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{-\left(-\frac{\log x}{n}\right)}}{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 < 1.2e5

    1. Initial program 46.5

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

      \[\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. Simplified14.1

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

      [Start]14.1

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

      rational_best_oopsla_all_46_json_45_simplify-107 [=>]14.1

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

    if 1.2e5 < 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 1.2

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

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

      [Start]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]1.2

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

      \[\leadsto \color{blue}{\frac{e^{--1 \cdot \frac{\log x}{n}}}{n \cdot x}} \]
    5. Simplified1.2

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

      [Start]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-92 [=>]1.2

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

      rational_best_oopsla_all_46_json_45_simplify-74 [=>]1.2

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

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

Alternatives

Alternative 1
Error7.3
Cost52996
\[\begin{array}{l} t_0 := \log \left(1 + x\right)\\ \mathbf{if}\;x \leq 27000:\\ \;\;\;\;\left(-\frac{-1 \cdot \left(t_0 - \log x\right)}{n}\right) + 0.5 \cdot \left(\frac{{t_0}^{2}}{{n}^{2}} - \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-\left(-\frac{\log x}{n}\right)}}{x \cdot n}\\ \end{array} \]
Alternative 2
Error7.4
Cost46532
\[\begin{array}{l} t_0 := \frac{\log x}{n}\\ \mathbf{if}\;x \leq 88000:\\ \;\;\;\;\left(0.5 \cdot \frac{{x}^{2}}{{n}^{2}} + \frac{\log \left(1 + x\right)}{n}\right) - \left(t_0 + 0.5 \cdot \frac{{\log x}^{2}}{{n}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-\left(-t_0\right)}}{x \cdot n}\\ \end{array} \]
Alternative 3
Error12.1
Cost13508
\[\begin{array}{l} \mathbf{if}\;\frac{1}{n} \leq 10^{-5}:\\ \;\;\;\;\frac{\log \left(1 + x\right) - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{x}{n} + 1\right) - {x}^{\left(\frac{1}{n}\right)}\\ \end{array} \]
Alternative 4
Error7.2
Cost13508
\[\begin{array}{l} \mathbf{if}\;x \leq 210000:\\ \;\;\;\;\frac{\log \left(1 + x\right) - \log x}{n}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-\left(-\frac{\log x}{n}\right)}}{x \cdot n}\\ \end{array} \]
Alternative 5
Error16.2
Cost7304
\[\begin{array}{l} \mathbf{if}\;x \leq 0.98:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{1}{x} - \frac{0.5}{{x}^{2}}}{n}\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+120}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+158}:\\ \;\;\;\;\frac{1}{x \cdot n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error16.3
Cost6852
\[\begin{array}{l} \mathbf{if}\;x \leq 1:\\ \;\;\;\;\frac{x - \log x}{n}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+120}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{+153}:\\ \;\;\;\;\frac{1}{x \cdot n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 7
Error16.5
Cost6788
\[\begin{array}{l} \mathbf{if}\;x \leq 0.55:\\ \;\;\;\;\frac{-\log x}{n}\\ \mathbf{elif}\;x \leq 2.1 \cdot 10^{+86}:\\ \;\;\;\;\frac{\frac{1}{x}}{n}\\ \mathbf{elif}\;x \leq 4.5 \cdot 10^{+120}:\\ \;\;\;\;0\\ \mathbf{elif}\;x \leq 3.4 \cdot 10^{+153}:\\ \;\;\;\;\frac{1}{x \cdot n}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 8
Error28.8
Cost584
\[\begin{array}{l} t_0 := \frac{1}{x \cdot n}\\ \mathbf{if}\;n \leq -18:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 5.8 \cdot 10^{-58}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 9
Error28.4
Cost584
\[\begin{array}{l} t_0 := \frac{\frac{1}{x}}{n}\\ \mathbf{if}\;n \leq -11:\\ \;\;\;\;t_0\\ \mathbf{elif}\;n \leq 1.55 \cdot 10^{-57}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 10
Error38.7
Cost64
\[0 \]

Error

Reproduce?

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