| Alternative 1 | |
|---|---|
| Error | 12.1 |
| Cost | 13908 |
(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.95) (/ (+ (log x) (+ (* (log x) -2.0) (log (+ x 1.0)))) n) (/ (exp (+ (/ (log x) n) 0.0)) (* 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 <= 1.95) {
tmp = (log(x) + ((log(x) * -2.0) + log((x + 1.0)))) / n;
} else {
tmp = exp(((log(x) / n) + 0.0)) / (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) :: tmp
if (x <= 1.95d0) then
tmp = (log(x) + ((log(x) * (-2.0d0)) + log((x + 1.0d0)))) / n
else
tmp = exp(((log(x) / n) + 0.0d0)) / (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 tmp;
if (x <= 1.95) {
tmp = (Math.log(x) + ((Math.log(x) * -2.0) + Math.log((x + 1.0)))) / n;
} else {
tmp = Math.exp(((Math.log(x) / n) + 0.0)) / (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 <= 1.95: tmp = (math.log(x) + ((math.log(x) * -2.0) + math.log((x + 1.0)))) / n else: tmp = math.exp(((math.log(x) / n) + 0.0)) / (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 <= 1.95) tmp = Float64(Float64(log(x) + Float64(Float64(log(x) * -2.0) + log(Float64(x + 1.0)))) / n); else tmp = Float64(exp(Float64(Float64(log(x) / n) + 0.0)) / 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) tmp = 0.0; if (x <= 1.95) tmp = (log(x) + ((log(x) * -2.0) + log((x + 1.0)))) / n; else tmp = exp(((log(x) / n) + 0.0)) / (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_] := If[LessEqual[x, 1.95], N[(N[(N[Log[x], $MachinePrecision] + N[(N[(N[Log[x], $MachinePrecision] * -2.0), $MachinePrecision] + N[Log[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision] + 0.0), $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 1.95:\\
\;\;\;\;\frac{\log x + \left(\log x \cdot -2 + \log \left(x + 1\right)\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{\log x}{n} + 0}}{x \cdot n}\\
\end{array}
Results
if x < 1.94999999999999996Initial program 46.8
Taylor expanded in n around inf 14.0
Simplified14.0
[Start]14.0 | \[ \frac{\log \left(1 + x\right) - \log x}{n}
\] |
|---|---|
rational_best-simplify-1 [=>]14.0 | \[ \frac{\log \color{blue}{\left(x + 1\right)} - \log x}{n}
\] |
rational_best-simplify-16 [=>]14.0 | \[ \frac{\log \color{blue}{\left(x - -1\right)} - \log x}{n}
\] |
Applied egg-rr14.0
Simplified14.0
[Start]14.0 | \[ \frac{\left(\log \left(x + 1\right) + \log x\right) + \left(-\log x \cdot 2\right)}{n}
\] |
|---|---|
rational_best-simplify-1 [<=]14.0 | \[ \frac{\color{blue}{\left(-\log x \cdot 2\right) + \left(\log \left(x + 1\right) + \log x\right)}}{n}
\] |
rational_best-simplify-43 [=>]14.0 | \[ \frac{\color{blue}{\log x + \left(\log \left(x + 1\right) + \left(-\log x \cdot 2\right)\right)}}{n}
\] |
rational_best-simplify-16 [=>]14.0 | \[ \frac{\log x + \left(\log \color{blue}{\left(x - -1\right)} + \left(-\log x \cdot 2\right)\right)}{n}
\] |
Applied egg-rr14.0
Simplified14.0
[Start]14.0 | \[ \frac{\log x + \left(\left(\log \left(x + 1\right) + \log x \cdot -2\right) - 0\right)}{n}
\] |
|---|---|
rational_best-simplify-6 [=>]14.0 | \[ \frac{\log x + \color{blue}{\left(\log \left(x + 1\right) + \log x \cdot -2\right)}}{n}
\] |
rational_best-simplify-1 [=>]14.0 | \[ \frac{\log x + \color{blue}{\left(\log x \cdot -2 + \log \left(x + 1\right)\right)}}{n}
\] |
if 1.94999999999999996 < x Initial program 21.2
Taylor expanded in x around inf 1.8
Simplified1.8
[Start]1.8 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
rational_best-simplify-2 [=>]1.8 | \[ \frac{e^{\color{blue}{\frac{\log \left(\frac{1}{x}\right)}{n} \cdot -1}}}{n \cdot x}
\] |
rational_best-simplify-12 [=>]1.8 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
rational_best-simplify-2 [=>]1.8 | \[ \frac{e^{-\frac{\log \left(\frac{1}{x}\right)}{n}}}{\color{blue}{x \cdot n}}
\] |
Taylor expanded in x around 0 1.8
Simplified1.8
[Start]1.8 | \[ \frac{e^{--1 \cdot \frac{\log x}{n}}}{n \cdot x}
\] |
|---|---|
rational_best-simplify-11 [=>]1.8 | \[ \frac{e^{\color{blue}{0 - -1 \cdot \frac{\log x}{n}}}}{n \cdot x}
\] |
rational_best-simplify-2 [=>]1.8 | \[ \frac{e^{0 - \color{blue}{\frac{\log x}{n} \cdot -1}}}{n \cdot x}
\] |
rational_best-simplify-12 [=>]1.8 | \[ \frac{e^{0 - \color{blue}{\left(-\frac{\log x}{n}\right)}}}{n \cdot x}
\] |
rational_best-simplify-11 [=>]1.8 | \[ \frac{e^{0 - \color{blue}{\left(0 - \frac{\log x}{n}\right)}}}{n \cdot x}
\] |
rational_best-simplify-46 [=>]1.8 | \[ \frac{e^{\color{blue}{\frac{\log x}{n} + \left(0 - 0\right)}}}{n \cdot x}
\] |
metadata-eval [=>]1.8 | \[ \frac{e^{\frac{\log x}{n} + \color{blue}{0}}}{n \cdot x}
\] |
rational_best-simplify-2 [=>]1.8 | \[ \frac{e^{\frac{\log x}{n} + 0}}{\color{blue}{x \cdot n}}
\] |
Final simplification7.4
| Alternative 1 | |
|---|---|
| Error | 12.1 |
| Cost | 13908 |
| Alternative 2 | |
|---|---|
| Error | 7.4 |
| Cost | 13508 |
| Alternative 3 | |
|---|---|
| Error | 15.8 |
| Cost | 7432 |
| Alternative 4 | |
|---|---|
| Error | 15.8 |
| Cost | 6980 |
| Alternative 5 | |
|---|---|
| Error | 15.8 |
| Cost | 6852 |
| Alternative 6 | |
|---|---|
| Error | 16.1 |
| Cost | 6788 |
| Alternative 7 | |
|---|---|
| Error | 29.4 |
| Cost | 584 |
| Alternative 8 | |
|---|---|
| Error | 29.1 |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Error | 39.4 |
| Cost | 192 |
herbie shell --seed 2023092
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))