| Alternative 1 | |
|---|---|
| Error | 17.38% |
| Cost | 14092 |
(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 (pow x (/ 1.0 n))))
(if (<= (/ 1.0 n) -1e-22)
(/ t_0 (* n x))
(if (<= (/ 1.0 n) 1e-24)
(/ (log (/ (+ 1.0 x) x)) n)
(if (<= (/ 1.0 n) 0.4)
(/ (pow (pow t_0 3.0) 0.3333333333333333) (* n x))
(- (exp (/ x n)) t_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 t_0 = pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1e-22) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 1e-24) {
tmp = log(((1.0 + x) / x)) / n;
} else if ((1.0 / n) <= 0.4) {
tmp = pow(pow(t_0, 3.0), 0.3333333333333333) / (n * x);
} else {
tmp = exp((x / n)) - t_0;
}
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 = x ** (1.0d0 / n)
if ((1.0d0 / n) <= (-1d-22)) then
tmp = t_0 / (n * x)
else if ((1.0d0 / n) <= 1d-24) then
tmp = log(((1.0d0 + x) / x)) / n
else if ((1.0d0 / n) <= 0.4d0) then
tmp = ((t_0 ** 3.0d0) ** 0.3333333333333333d0) / (n * x)
else
tmp = exp((x / n)) - t_0
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.pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -1e-22) {
tmp = t_0 / (n * x);
} else if ((1.0 / n) <= 1e-24) {
tmp = Math.log(((1.0 + x) / x)) / n;
} else if ((1.0 / n) <= 0.4) {
tmp = Math.pow(Math.pow(t_0, 3.0), 0.3333333333333333) / (n * x);
} else {
tmp = Math.exp((x / n)) - t_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): t_0 = math.pow(x, (1.0 / n)) tmp = 0 if (1.0 / n) <= -1e-22: tmp = t_0 / (n * x) elif (1.0 / n) <= 1e-24: tmp = math.log(((1.0 + x) / x)) / n elif (1.0 / n) <= 0.4: tmp = math.pow(math.pow(t_0, 3.0), 0.3333333333333333) / (n * x) else: tmp = math.exp((x / n)) - t_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) t_0 = x ^ Float64(1.0 / n) tmp = 0.0 if (Float64(1.0 / n) <= -1e-22) tmp = Float64(t_0 / Float64(n * x)); elseif (Float64(1.0 / n) <= 1e-24) tmp = Float64(log(Float64(Float64(1.0 + x) / x)) / n); elseif (Float64(1.0 / n) <= 0.4) tmp = Float64(((t_0 ^ 3.0) ^ 0.3333333333333333) / Float64(n * x)); else tmp = Float64(exp(Float64(x / n)) - t_0); 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 = x ^ (1.0 / n); tmp = 0.0; if ((1.0 / n) <= -1e-22) tmp = t_0 / (n * x); elseif ((1.0 / n) <= 1e-24) tmp = log(((1.0 + x) / x)) / n; elseif ((1.0 / n) <= 0.4) tmp = ((t_0 ^ 3.0) ^ 0.3333333333333333) / (n * x); else tmp = exp((x / n)) - t_0; 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[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -1e-22], N[(t$95$0 / N[(n * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 1e-24], N[(N[Log[N[(N[(1.0 + x), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.4], N[(N[Power[N[Power[t$95$0, 3.0], $MachinePrecision], 0.3333333333333333], $MachinePrecision] / N[(n * x), $MachinePrecision]), $MachinePrecision], N[(N[Exp[N[(x / n), $MachinePrecision]], $MachinePrecision] - t$95$0), $MachinePrecision]]]]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
t_0 := {x}^{\left(\frac{1}{n}\right)}\\
\mathbf{if}\;\frac{1}{n} \leq -1 \cdot 10^{-22}:\\
\;\;\;\;\frac{t_0}{n \cdot x}\\
\mathbf{elif}\;\frac{1}{n} \leq 10^{-24}:\\
\;\;\;\;\frac{\log \left(\frac{1 + x}{x}\right)}{n}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.4:\\
\;\;\;\;\frac{{\left({t_0}^{3}\right)}^{0.3333333333333333}}{n \cdot x}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{n}} - t_0\\
\end{array}
Results
if (/.f64 1 n) < -1e-22Initial program 9.3
Taylor expanded in x around inf 6.81
Simplified6.81
[Start]6.81 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
mul-1-neg [=>]6.81 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
log-rec [=>]6.81 | \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]6.81 | \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
distribute-neg-frac [=>]6.81 | \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x}
\] |
mul-1-neg [=>]6.81 | \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x}
\] |
remove-double-neg [=>]6.81 | \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x}
\] |
*-commutative [=>]6.81 | \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}}
\] |
Taylor expanded in x around 0 6.81
Simplified6.81
[Start]6.81 | \[ \frac{e^{\frac{\log x}{n}}}{n \cdot x}
\] |
|---|---|
*-rgt-identity [<=]6.81 | \[ \frac{e^{\color{blue}{\frac{\log x}{n} \cdot 1}}}{n \cdot x}
\] |
associate-*l/ [=>]6.81 | \[ \frac{e^{\color{blue}{\frac{\log x \cdot 1}{n}}}}{n \cdot x}
\] |
associate-*r/ [<=]6.81 | \[ \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x}
\] |
exp-to-pow [=>]6.81 | \[ \frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{n \cdot x}
\] |
*-commutative [<=]6.81 | \[ \frac{{x}^{\left(\frac{1}{n}\right)}}{\color{blue}{x \cdot n}}
\] |
if -1e-22 < (/.f64 1 n) < 9.99999999999999924e-25Initial program 70.04
Taylor expanded in n around inf 21.42
Simplified21.42
[Start]21.42 | \[ \frac{\log \left(1 + x\right) - \log x}{n}
\] |
|---|---|
log1p-def [=>]21.42 | \[ \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n}
\] |
Applied egg-rr21.23
if 9.99999999999999924e-25 < (/.f64 1 n) < 0.40000000000000002Initial program 67.1
Taylor expanded in x around inf 51.82
Simplified51.82
[Start]51.82 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
mul-1-neg [=>]51.82 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
log-rec [=>]51.82 | \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]51.82 | \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
distribute-neg-frac [=>]51.82 | \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x}
\] |
mul-1-neg [=>]51.82 | \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x}
\] |
remove-double-neg [=>]51.82 | \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x}
\] |
*-commutative [=>]51.82 | \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}}
\] |
Applied egg-rr51.87
if 0.40000000000000002 < (/.f64 1 n) Initial program 6.27
Taylor expanded in n around 0 6.27
Simplified0.68
[Start]6.27 | \[ e^{\frac{\log \left(1 + x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}
\] |
|---|---|
log1p-def [=>]0.68 | \[ e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}
\] |
Taylor expanded in x around 0 0.98
Final simplification17.38
| Alternative 1 | |
|---|---|
| Error | 17.38% |
| Cost | 14092 |
| Alternative 2 | |
|---|---|
| Error | 17.8% |
| Cost | 13776 |
| Alternative 3 | |
|---|---|
| Error | 17.83% |
| Cost | 7504 |
| Alternative 4 | |
|---|---|
| Error | 12.04% |
| Cost | 7308 |
| Alternative 5 | |
|---|---|
| Error | 25.01% |
| Cost | 7116 |
| Alternative 6 | |
|---|---|
| Error | 19.2% |
| Cost | 7108 |
| Alternative 7 | |
|---|---|
| Error | 23.77% |
| Cost | 6852 |
| Alternative 8 | |
|---|---|
| Error | 25.96% |
| Cost | 6788 |
| Alternative 9 | |
|---|---|
| Error | 24.14% |
| Cost | 6788 |
| Alternative 10 | |
|---|---|
| Error | 55.08% |
| Cost | 841 |
| Alternative 11 | |
|---|---|
| Error | 63.25% |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Error | 62.66% |
| Cost | 320 |
herbie shell --seed 2023089
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))