| Alternative 1 | |
|---|---|
| Error | 36.6 |
| Cost | 324 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 1.35:\\
\;\;\;\;\frac{1}{n}\\
\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}
Results
if x < 1Initial program 47.0
Taylor expanded in x around 0 47.1
Simplified1.8
if 1 < x Initial program 20.3
Taylor expanded in x around inf 40.1
Simplified40.1
Applied egg-rr20.4
Taylor expanded in x around inf 20.3
| Alternative 1 | |
|---|---|
| Error | 36.6 |
| Cost | 324 |
| Alternative 2 | |
|---|---|
| Error | 38.9 |
| Cost | 192 |
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))))