| Alternative 1 | |
|---|---|
| Error | 2.29% |
| Cost | 7560 |
(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) -0.0002)
(* t_0 (/ (/ 1.0 n) x))
(if (<= (/ 1.0 n) 0.0005)
(/ (log1p (/ 1.0 x)) n)
(- (exp (/ (log1p 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) <= -0.0002) {
tmp = t_0 * ((1.0 / n) / x);
} else if ((1.0 / n) <= 0.0005) {
tmp = log1p((1.0 / x)) / n;
} else {
tmp = exp((log1p(x) / n)) - t_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 t_0 = Math.pow(x, (1.0 / n));
double tmp;
if ((1.0 / n) <= -0.0002) {
tmp = t_0 * ((1.0 / n) / x);
} else if ((1.0 / n) <= 0.0005) {
tmp = Math.log1p((1.0 / x)) / n;
} else {
tmp = Math.exp((Math.log1p(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) <= -0.0002: tmp = t_0 * ((1.0 / n) / x) elif (1.0 / n) <= 0.0005: tmp = math.log1p((1.0 / x)) / n else: tmp = math.exp((math.log1p(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) <= -0.0002) tmp = Float64(t_0 * Float64(Float64(1.0 / n) / x)); elseif (Float64(1.0 / n) <= 0.0005) tmp = Float64(log1p(Float64(1.0 / x)) / n); else tmp = Float64(exp(Float64(log1p(x) / n)) - t_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_] := Block[{t$95$0 = N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(1.0 / n), $MachinePrecision], -0.0002], N[(t$95$0 * N[(N[(1.0 / n), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(1.0 / n), $MachinePrecision], 0.0005], N[(N[Log[1 + N[(1.0 / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[Exp[N[(N[Log[1 + x], $MachinePrecision] / 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 -0.0002:\\
\;\;\;\;t_0 \cdot \frac{\frac{1}{n}}{x}\\
\mathbf{elif}\;\frac{1}{n} \leq 0.0005:\\
\;\;\;\;\frac{\mathsf{log1p}\left(\frac{1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{\mathsf{log1p}\left(x\right)}{n}} - t_0\\
\end{array}
Results
if (/.f64 1 n) < -2.0000000000000001e-4Initial program 1.1
Taylor expanded in x around inf 1.15
Simplified1.15
[Start]1.15 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
mul-1-neg [=>]1.15 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
log-rec [=>]1.15 | \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]1.15 | \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
distribute-neg-frac [=>]1.15 | \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x}
\] |
mul-1-neg [=>]1.15 | \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x}
\] |
remove-double-neg [=>]1.15 | \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x}
\] |
*-commutative [=>]1.15 | \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}}
\] |
Applied egg-rr2.27
Applied egg-rr1.47
Simplified1.47
[Start]1.47 | \[ \frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{\sqrt[3]{x \cdot x}}}{n \cdot \sqrt[3]{x}}
\] |
|---|---|
associate-/l/ [=>]1.47 | \[ \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{\left(n \cdot \sqrt[3]{x}\right) \cdot \sqrt[3]{x \cdot x}}}
\] |
Applied egg-rr1.15
if -2.0000000000000001e-4 < (/.f64 1 n) < 5.0000000000000001e-4Initial program 69.89
Taylor expanded in n around inf 24.38
Simplified24.39
[Start]24.38 | \[ \frac{\log \left(1 + x\right) - \log x}{n}
\] |
|---|---|
log1p-def [=>]24.39 | \[ \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n}
\] |
Applied egg-rr24.22
Applied egg-rr24.22
Simplified2.21
[Start]24.22 | \[ \frac{\mathsf{log1p}\left(\frac{x + 1}{x} - 1\right)}{n}
\] |
|---|---|
*-lft-identity [<=]24.22 | \[ \frac{\mathsf{log1p}\left(\frac{\color{blue}{1 \cdot \left(x + 1\right)}}{x} - 1\right)}{n}
\] |
associate-*l/ [<=]27.43 | \[ \frac{\mathsf{log1p}\left(\color{blue}{\frac{1}{x} \cdot \left(x + 1\right)} - 1\right)}{n}
\] |
distribute-rgt-in [=>]27.43 | \[ \frac{\mathsf{log1p}\left(\color{blue}{\left(x \cdot \frac{1}{x} + 1 \cdot \frac{1}{x}\right)} - 1\right)}{n}
\] |
+-commutative [=>]27.43 | \[ \frac{\mathsf{log1p}\left(\color{blue}{\left(1 \cdot \frac{1}{x} + x \cdot \frac{1}{x}\right)} - 1\right)}{n}
\] |
*-lft-identity [=>]27.43 | \[ \frac{\mathsf{log1p}\left(\left(\color{blue}{\frac{1}{x}} + x \cdot \frac{1}{x}\right) - 1\right)}{n}
\] |
rgt-mult-inverse [=>]24.22 | \[ \frac{\mathsf{log1p}\left(\left(\frac{1}{x} + \color{blue}{1}\right) - 1\right)}{n}
\] |
associate--l+ [=>]2.21 | \[ \frac{\mathsf{log1p}\left(\color{blue}{\frac{1}{x} + \left(1 - 1\right)}\right)}{n}
\] |
metadata-eval [=>]2.21 | \[ \frac{\mathsf{log1p}\left(\frac{1}{x} + \color{blue}{0}\right)}{n}
\] |
if 5.0000000000000001e-4 < (/.f64 1 n) Initial program 6.73
Taylor expanded in n around 0 6.73
Simplified2.09
[Start]6.73 | \[ e^{\frac{\log \left(1 + x\right)}{n}} - {x}^{\left(\frac{1}{n}\right)}
\] |
|---|---|
log1p-def [=>]2.09 | \[ e^{\frac{\color{blue}{\mathsf{log1p}\left(x\right)}}{n}} - {x}^{\left(\frac{1}{n}\right)}
\] |
Final simplification1.99
| Alternative 1 | |
|---|---|
| Error | 2.29% |
| Cost | 7560 |
| Alternative 2 | |
|---|---|
| Error | 3.1% |
| Cost | 7304 |
| Alternative 3 | |
|---|---|
| Error | 2.46% |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Error | 2.46% |
| Cost | 7304 |
| Alternative 5 | |
|---|---|
| Error | 19.34% |
| Cost | 7113 |
| Alternative 6 | |
|---|---|
| Error | 25.19% |
| Cost | 6852 |
| Alternative 7 | |
|---|---|
| Error | 25.38% |
| Cost | 6788 |
| Alternative 8 | |
|---|---|
| Error | 54.99% |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Error | 44.45% |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Error | 63.32% |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Error | 62.73% |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Error | 95.46% |
| Cost | 192 |
herbie shell --seed 2023090
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))