| Alternative 1 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 7560 |
(FPCore (x n) :precision binary64 (- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))
(FPCore (x n) :precision binary64 (if (<= x 0.55) (- (expm1 (/ (log x) n))) (* (/ 1.0 n) (/ (pow x (/ 1.0 n)) x))))
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 <= 0.55) {
tmp = -expm1((log(x) / n));
} else {
tmp = (1.0 / n) * (pow(x, (1.0 / n)) / x);
}
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 <= 0.55) {
tmp = -Math.expm1((Math.log(x) / n));
} else {
tmp = (1.0 / n) * (Math.pow(x, (1.0 / n)) / x);
}
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 <= 0.55: tmp = -math.expm1((math.log(x) / n)) else: tmp = (1.0 / n) * (math.pow(x, (1.0 / n)) / x) 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 <= 0.55) tmp = Float64(-expm1(Float64(log(x) / n))); else tmp = Float64(Float64(1.0 / n) * Float64((x ^ Float64(1.0 / n)) / x)); 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, 0.55], (-N[(Exp[N[(N[Log[x], $MachinePrecision] / n), $MachinePrecision]] - 1), $MachinePrecision]), N[(N[(1.0 / n), $MachinePrecision] * N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]]
{\left(x + 1\right)}^{\left(\frac{1}{n}\right)} - {x}^{\left(\frac{1}{n}\right)}
\begin{array}{l}
\mathbf{if}\;x \leq 0.55:\\
\;\;\;\;-\mathsf{expm1}\left(\frac{\log x}{n}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{n} \cdot \frac{{x}^{\left(\frac{1}{n}\right)}}{x}\\
\end{array}
Results
if x < 0.55000000000000004Initial program 28.4%
Taylor expanded in x around 0 28.4%
Simplified28.4%
[Start]28.4 | \[ 1 - e^{\frac{\log x}{n}}
\] |
|---|---|
*-rgt-identity [<=]28.4 | \[ 1 - e^{\frac{\color{blue}{\log x \cdot 1}}{n}}
\] |
associate-*r/ [<=]28.4 | \[ 1 - e^{\color{blue}{\log x \cdot \frac{1}{n}}}
\] |
unpow-1 [<=]28.4 | \[ 1 - e^{\log x \cdot \color{blue}{{n}^{-1}}}
\] |
exp-to-pow [=>]28.4 | \[ 1 - \color{blue}{{x}^{\left({n}^{-1}\right)}}
\] |
unpow-1 [=>]28.4 | \[ 1 - {x}^{\color{blue}{\left(\frac{1}{n}\right)}}
\] |
Taylor expanded in x around 0 28.4%
Simplified97.1%
[Start]28.4 | \[ 1 - e^{\frac{\log x}{n}}
\] |
|---|---|
sub-neg [=>]28.4 | \[ \color{blue}{1 + \left(-e^{\frac{\log x}{n}}\right)}
\] |
+-commutative [=>]28.4 | \[ \color{blue}{\left(-e^{\frac{\log x}{n}}\right) + 1}
\] |
neg-sub0 [=>]28.4 | \[ \color{blue}{\left(0 - e^{\frac{\log x}{n}}\right)} + 1
\] |
metadata-eval [<=]28.4 | \[ \left(\color{blue}{\log 1} - e^{\frac{\log x}{n}}\right) + 1
\] |
associate-+l- [=>]28.4 | \[ \color{blue}{\log 1 - \left(e^{\frac{\log x}{n}} - 1\right)}
\] |
metadata-eval [=>]28.4 | \[ \color{blue}{0} - \left(e^{\frac{\log x}{n}} - 1\right)
\] |
sub0-neg [=>]28.4 | \[ \color{blue}{-\left(e^{\frac{\log x}{n}} - 1\right)}
\] |
expm1-def [=>]97.1 | \[ -\color{blue}{\mathsf{expm1}\left(\frac{\log x}{n}\right)}
\] |
if 0.55000000000000004 < x Initial program 68.0%
Taylor expanded in x around inf 97.0%
Simplified97.0%
[Start]97.0 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
log-rec [=>]97.0 | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]97.0 | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [=>]97.0 | \[ \frac{e^{-1 \cdot \frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
distribute-frac-neg [=>]97.0 | \[ \frac{e^{-1 \cdot \color{blue}{\left(-\frac{\log x}{n}\right)}}}{n \cdot x}
\] |
neg-mul-1 [<=]97.0 | \[ \frac{e^{\color{blue}{-\left(-\frac{\log x}{n}\right)}}}{n \cdot x}
\] |
remove-double-neg [=>]97.0 | \[ \frac{e^{\color{blue}{\frac{\log x}{n}}}}{n \cdot x}
\] |
*-rgt-identity [<=]97.0 | \[ \frac{e^{\frac{\color{blue}{\log x \cdot 1}}{n}}}{n \cdot x}
\] |
associate-*r/ [<=]97.0 | \[ \frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{n \cdot x}
\] |
unpow-1 [<=]97.0 | \[ \frac{e^{\log x \cdot \color{blue}{{n}^{-1}}}}{n \cdot x}
\] |
exp-to-pow [=>]97.0 | \[ \frac{\color{blue}{{x}^{\left({n}^{-1}\right)}}}{n \cdot x}
\] |
unpow-1 [=>]97.0 | \[ \frac{{x}^{\color{blue}{\left(\frac{1}{n}\right)}}}{n \cdot x}
\] |
*-commutative [=>]97.0 | \[ \frac{{x}^{\left(\frac{1}{n}\right)}}{\color{blue}{x \cdot n}}
\] |
Applied egg-rr98.2%
[Start]97.0 | \[ \frac{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}
\] |
|---|---|
associate-/r* [=>]98.3 | \[ \color{blue}{\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}}
\] |
div-inv [=>]98.2 | \[ \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x} \cdot \frac{1}{n}}
\] |
Final simplification97.7%
| Alternative 1 | |
|---|---|
| Accuracy | 97.9% |
| Cost | 7560 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.2% |
| Cost | 7304 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 7180 |
| Alternative 5 | |
|---|---|
| Accuracy | 88.0% |
| Cost | 6985 |
| Alternative 6 | |
|---|---|
| Accuracy | 74.8% |
| Cost | 6788 |
| Alternative 7 | |
|---|---|
| Accuracy | 54.2% |
| Cost | 585 |
| Alternative 8 | |
|---|---|
| Accuracy | 54.9% |
| Cost | 585 |
| Alternative 9 | |
|---|---|
| Accuracy | 54.9% |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Accuracy | 39.1% |
| Cost | 64 |
herbie shell --seed 2023152
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))