| Alternative 1 | |
|---|---|
| Accuracy | 89.4% |
| Cost | 7044 |
\[\begin{array}{l}
\mathbf{if}\;x \leq 8200:\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{n}}{x}\\
\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 8200.0) (/ (log (/ (+ x 1.0) x)) n) (/ (/ (pow x (/ 1.0 n)) 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 <= 8200.0) {
tmp = log(((x + 1.0) / x)) / n;
} else {
tmp = (pow(x, (1.0 / n)) / 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 <= 8200.0d0) then
tmp = log(((x + 1.0d0) / x)) / n
else
tmp = ((x ** (1.0d0 / n)) / 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 <= 8200.0) {
tmp = Math.log(((x + 1.0) / x)) / n;
} else {
tmp = (Math.pow(x, (1.0 / n)) / 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 <= 8200.0: tmp = math.log(((x + 1.0) / x)) / n else: tmp = (math.pow(x, (1.0 / n)) / 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 <= 8200.0) tmp = Float64(log(Float64(Float64(x + 1.0) / x)) / n); else tmp = Float64(Float64((x ^ Float64(1.0 / n)) / 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 <= 8200.0) tmp = log(((x + 1.0) / x)) / n; else tmp = ((x ^ (1.0 / n)) / 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, 8200.0], N[(N[Log[N[(N[(x + 1.0), $MachinePrecision] / x), $MachinePrecision]], $MachinePrecision] / n), $MachinePrecision], N[(N[(N[Power[x, N[(1.0 / n), $MachinePrecision]], $MachinePrecision] / x), $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 8200:\\
\;\;\;\;\frac{\log \left(\frac{x + 1}{x}\right)}{n}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}\\
\end{array}
Results
if x < 8200Initial program 26.9%
Taylor expanded in n around inf 77.7%
Simplified77.7%
[Start]77.7 | \[ \frac{\log \left(1 + x\right) - \log x}{n}
\] |
|---|---|
log1p-def [=>]77.7 | \[ \frac{\color{blue}{\mathsf{log1p}\left(x\right)} - \log x}{n}
\] |
Applied egg-rr77.7%
[Start]77.7 | \[ \frac{\mathsf{log1p}\left(x\right) - \log x}{n}
\] |
|---|---|
add-log-exp [=>]77.7 | \[ \frac{\color{blue}{\log \left(e^{\mathsf{log1p}\left(x\right) - \log x}\right)}}{n}
\] |
exp-diff [=>]77.7 | \[ \frac{\log \color{blue}{\left(\frac{e^{\mathsf{log1p}\left(x\right)}}{e^{\log x}}\right)}}{n}
\] |
log1p-udef [=>]77.7 | \[ \frac{\log \left(\frac{e^{\color{blue}{\log \left(1 + x\right)}}}{e^{\log x}}\right)}{n}
\] |
add-exp-log [<=]77.7 | \[ \frac{\log \left(\frac{\color{blue}{1 + x}}{e^{\log x}}\right)}{n}
\] |
+-commutative [=>]77.7 | \[ \frac{\log \left(\frac{\color{blue}{x + 1}}{e^{\log x}}\right)}{n}
\] |
add-exp-log [<=]77.7 | \[ \frac{\log \left(\frac{x + 1}{\color{blue}{x}}\right)}{n}
\] |
if 8200 < x Initial program 68.1%
Taylor expanded in x around inf 97.6%
Simplified97.6%
[Start]97.6 | \[ \frac{e^{-1 \cdot \frac{\log \left(\frac{1}{x}\right)}{n}}}{n \cdot x}
\] |
|---|---|
mul-1-neg [=>]97.6 | \[ \frac{e^{\color{blue}{-\frac{\log \left(\frac{1}{x}\right)}{n}}}}{n \cdot x}
\] |
log-rec [=>]97.6 | \[ \frac{e^{-\frac{\color{blue}{-\log x}}{n}}}{n \cdot x}
\] |
mul-1-neg [<=]97.6 | \[ \frac{e^{-\frac{\color{blue}{-1 \cdot \log x}}{n}}}{n \cdot x}
\] |
distribute-neg-frac [=>]97.6 | \[ \frac{e^{\color{blue}{\frac{--1 \cdot \log x}{n}}}}{n \cdot x}
\] |
mul-1-neg [=>]97.6 | \[ \frac{e^{\frac{-\color{blue}{\left(-\log x\right)}}{n}}}{n \cdot x}
\] |
remove-double-neg [=>]97.6 | \[ \frac{e^{\frac{\color{blue}{\log x}}{n}}}{n \cdot x}
\] |
*-commutative [=>]97.6 | \[ \frac{e^{\frac{\log x}{n}}}{\color{blue}{x \cdot n}}
\] |
Applied egg-rr97.1%
[Start]97.6 | \[ \frac{e^{\frac{\log x}{n}}}{x \cdot n}
\] |
|---|---|
add-cube-cbrt [=>]97.1 | \[ \color{blue}{\left(\sqrt[3]{\frac{e^{\frac{\log x}{n}}}{x \cdot n}} \cdot \sqrt[3]{\frac{e^{\frac{\log x}{n}}}{x \cdot n}}\right) \cdot \sqrt[3]{\frac{e^{\frac{\log x}{n}}}{x \cdot n}}}
\] |
pow3 [=>]97.1 | \[ \color{blue}{{\left(\sqrt[3]{\frac{e^{\frac{\log x}{n}}}{x \cdot n}}\right)}^{3}}
\] |
div-inv [=>]97.1 | \[ {\left(\sqrt[3]{\frac{e^{\color{blue}{\log x \cdot \frac{1}{n}}}}{x \cdot n}}\right)}^{3}
\] |
exp-to-pow [=>]97.1 | \[ {\left(\sqrt[3]{\frac{\color{blue}{{x}^{\left(\frac{1}{n}\right)}}}{x \cdot n}}\right)}^{3}
\] |
Applied egg-rr99.1%
[Start]97.1 | \[ {\left(\sqrt[3]{\frac{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}}\right)}^{3}
\] |
|---|---|
rem-cube-cbrt [=>]97.6 | \[ \color{blue}{\frac{{x}^{\left(\frac{1}{n}\right)}}{x \cdot n}}
\] |
associate-/r* [=>]99.1 | \[ \color{blue}{\frac{\frac{{x}^{\left(\frac{1}{n}\right)}}{x}}{n}}
\] |
Final simplification89.4%
| Alternative 1 | |
|---|---|
| Accuracy | 89.4% |
| Cost | 7044 |
| Alternative 2 | |
|---|---|
| Accuracy | 76.3% |
| Cost | 6980 |
| Alternative 3 | |
|---|---|
| Accuracy | 75.9% |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Accuracy | 73.5% |
| Cost | 6788 |
| Alternative 5 | |
|---|---|
| Accuracy | 75.6% |
| Cost | 6788 |
| Alternative 6 | |
|---|---|
| Accuracy | 49.4% |
| Cost | 836 |
| Alternative 7 | |
|---|---|
| Accuracy | 42.1% |
| Cost | 448 |
| Alternative 8 | |
|---|---|
| Accuracy | 37.3% |
| Cost | 320 |
| Alternative 9 | |
|---|---|
| Accuracy | 38.1% |
| Cost | 320 |
| Alternative 10 | |
|---|---|
| Accuracy | 38.1% |
| Cost | 320 |
| Alternative 11 | |
|---|---|
| Accuracy | 4.6% |
| Cost | 192 |
herbie shell --seed 2023135
(FPCore (x n)
:name "2nthrt (problem 3.4.6)"
:precision binary64
(- (pow (+ x 1.0) (/ 1.0 n)) (pow x (/ 1.0 n))))