0

What's a numerically stable way to compute $$ \frac{2^{1/n}}{2^{1/n}-1} $$ for large (integer) $n$?

Charles
  • 32,999
  • 1
    Can't you use a series expansion $2^{\frac{1}{n}} = e^{\frac{\log(2)}{n}} = 1 + \frac{\log(2)}{n} + \frac{1}{2}\left(\frac{\log(2)}{n}\right)^2 + \ldots$? – Winther May 02 '16 at 04:57
  • How large $n$ and how accurate do you need the result? You should be able to evaluate it up to $n\sim 10^{10}$ directly with the built-in power-function without having to worry too much (assuming standard double-precision numbers). For much higher values there will likely be problems with underflow in the computation, but in this regime the error in the $O(1/n^2)$ Taylor expansion is much less than what you can represent with double precision so you are safe using this. – Winther May 02 '16 at 06:48
  • 2
    In some languages there is a built-in function named expm1 or something similar, which implements $e^x-1$ avoiding cancellation when $x\approx 0$. Then $2^{1/n}-1$ is expm1(x * log (2)). There is no numerical problem with the numerator. –  May 12 '16 at 02:14
  • 2

1 Answers1

1

In the same spirit as Winter's comment, you can use Taylor series and get $$\frac{2^{1/n}}{2^{1/n}-1}=\frac{n}{\log (2)}+\frac{1}{2}+\frac{\log (2)}{12 n}-\frac{\log ^3(2)}{720 n^3}+O\left(\frac{1}{n^4}\right)$$ For $n=100$, the exact value would be $$144.77008171108427365$$ while the above approximation would give $$144.77008171108427312$$