| Alternative 1 | |
|---|---|
| Error | 7.5 |
| Cost | 13380 |
\[\begin{array}{l}
t_0 := \frac{\log x}{n}\\
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\left(-t_0\right) + \frac{x}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{t_0}}{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 (if (<= x 600000.0) (/ (- (log (- x -1.0)) (log x)) n) (- (/ (/ (/ -1.0 x) (exp (- (/ (log x) n)))) 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 <= 600000.0) {
tmp = (log((x - -1.0)) - log(x)) / n;
} else {
tmp = -(((-1.0 / x) / exp(-(log(x) / n))) / 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) :: tmp
if (x <= 600000.0d0) then
tmp = (log((x - (-1.0d0))) - log(x)) / n
else
tmp = -((((-1.0d0) / x) / exp(-(log(x) / n))) / 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 tmp;
if (x <= 600000.0) {
tmp = (Math.log((x - -1.0)) - Math.log(x)) / n;
} else {
tmp = -(((-1.0 / x) / Math.exp(-(Math.log(x) / n))) / 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 <= 600000.0: tmp = (math.log((x - -1.0)) - math.log(x)) / n else: tmp = -(((-1.0 / x) / math.exp(-(math.log(x) / n))) / 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 <= 600000.0) tmp = Float64(Float64(log(Float64(x - -1.0)) - log(x)) / n); else tmp = Float64(-Float64(Float64(Float64(-1.0 / x) / exp(Float64(-Float64(log(x) / n)))) / 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) tmp = 0.0; if (x <= 600000.0) tmp = (log((x - -1.0)) - log(x)) / n; else tmp = -(((-1.0 / x) / exp(-(log(x) / n))) / 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_] := If[LessEqual[x, 600000.0], N[(N[(N[Log[N[(x - -1.0), $MachinePrecision]], $MachinePrecision] - N[Log[x], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], (-N[(N[(N[(-1.0 / x), $MachinePrecision] / N[Exp[(-N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision])]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq 600000:\\
\;\;\;\;\frac{\log \left(x - -1\right) - \log x}{n}\\
\mathbf{else}:\\
\;\;\;\;-\frac{\frac{\frac{-1}{x}}{e^{-\frac{\log x}{n}}}}{n}\\
\end{array}
Results
if x < 6e5Initial program 46.8
Taylor expanded in n around inf 14.2
Simplified14.2
[Start]14.2 | \[ \frac{\log \left(1 + x\right) - \log x}{n}
\] |
|---|---|
rational.json-simplify-17 [=>]14.2 | \[ \frac{\log \color{blue}{\left(x - -1\right)} - \log x}{n}
\] |
if 6e5 < x Initial program 20.1
Taylor expanded in x around inf 1.3
Simplified1.3
[Start]1.3 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
rational.json-simplify-2 [=>]1.3 | \[ \frac{e^{\color{blue}{\frac{\log \left(\frac{1}{x}\right)}{n} \cdot -1}}}{n \cdot x}
\] |
rational.json-simplify-9 [=>]1.3 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
rational.json-simplify-10 [=>]1.3 | \[ \frac{e^{\color{blue}{\frac{\frac{\log \left(\frac{1}{x}\right)}{n}}{-1}}}}{n \cdot x}
\] |
rational.json-simplify-47 [=>]1.3 | \[ \frac{e^{\color{blue}{\frac{\log \left(\frac{1}{x}\right)}{n \cdot -1}}}}{n \cdot x}
\] |
rational.json-simplify-9 [=>]1.3 | \[ \frac{e^{\frac{\log \left(\frac{1}{x}\right)}{\color{blue}{-n}}}}{n \cdot x}
\] |
rational.json-simplify-2 [=>]1.3 | \[ \frac{e^{\frac{\log \left(\frac{1}{x}\right)}{-n}}}{\color{blue}{x \cdot n}}
\] |
Applied egg-rr0.4
Taylor expanded in x around 0 0.4
Simplified0.4
[Start]0.4 | \[ -\frac{\frac{-1}{e^{-1 \cdot \frac{\log x}{n}} \cdot x}}{n}
\] |
|---|---|
rational.json-simplify-46 [=>]0.4 | \[ -\frac{\color{blue}{\frac{\frac{-1}{e^{-1 \cdot \frac{\log x}{n}}}}{x}}}{n}
\] |
rational.json-simplify-44 [=>]0.4 | \[ -\frac{\color{blue}{\frac{\frac{-1}{x}}{e^{-1 \cdot \frac{\log x}{n}}}}}{n}
\] |
rational.json-simplify-2 [=>]0.4 | \[ -\frac{\frac{\frac{-1}{x}}{e^{\color{blue}{\frac{\log x}{n} \cdot -1}}}}{n}
\] |
rational.json-simplify-9 [=>]0.4 | \[ -\frac{\frac{\frac{-1}{x}}{e^{\color{blue}{-\frac{\log x}{n}}}}}{n}
\] |
Final simplification6.8
| Alternative 1 | |
|---|---|
| Error | 7.5 |
| Cost | 13380 |
| Alternative 2 | |
|---|---|
| Error | 7.3 |
| Cost | 13380 |
| Alternative 3 | |
|---|---|
| Error | 15.8 |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Error | 16.0 |
| Cost | 7044 |
| Alternative 5 | |
|---|---|
| Error | 16.0 |
| Cost | 6852 |
| Alternative 6 | |
|---|---|
| Error | 16.2 |
| Cost | 6788 |
| Alternative 7 | |
|---|---|
| Error | 39.3 |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Error | 35.7 |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 34.8 |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Error | 41.1 |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Error | 40.6 |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Error | 40.6 |
| Cost | 320 |
| Alternative 13 | |
|---|---|
| Error | 61.1 |
| Cost | 192 |
herbie shell --seed 2023073
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))