(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}
Results
if x < 52Initial program 47.8
Taylor expanded in n around -inf 12.9
Simplified12.9
Applied egg-rr12.9
if 52 < x Initial program 20.7
Taylor expanded in x around inf 1.6
Simplified1.6
Final simplification6.8
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))))