2

Given a real number $r$ and a non-negative integer $n$, is there a way to accurately find the $n^{th}$ (with the integer being the $0^{th}$ number in the continued fraction. If this can not be done for all $r$ what are some specific ones, like $\pi$ or $e$. I already now how to do this square roots.

  • Have you looked at http://en.wikipedia.org/wiki/Continued_fraction#Motivation_and_notation? The representation of $e$ has a predictable pattern to it, but the representation of $\pi$ seems random. – Sammy Black Mar 21 '13 at 01:22
  • Oh yes, $e$ has an easy to see pattern. For $\pi$, am I sure there is some formula to find it. It is not a random number generator. – Christopher King Mar 21 '13 at 01:29
  • 1
    AFAIK there is no reason to believe there is a closed-form formula for the simple continued fraction representation of $\pi$. – Robert Israel Mar 21 '13 at 01:32
  • Why wouldn't there be. They have closed form for the monster known as the decimal system. You can find any digit of $\pi$ without finding out the previous ones. – Christopher King Mar 21 '13 at 01:38
  • @PyRulez Would you care to provide a reference for that, please? That's actually true in binary - they're the so-called digit extraction algorithms such as http://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula - but to the best of my knowledge there isn't any known decimal version of that algorithm to date. – Steven Stadnicki Mar 21 '13 at 01:42
  • 1
    Actually there are algorithms for extracting decimal digits of pi: see http://www.plouffe.fr/simon/articlepi.html In any case, an algorithm is not the same thing as a formula. – Robert Israel Mar 21 '13 at 04:24

2 Answers2

3

You can do it recursively: $$\eqalign{f_0(r) &= \lfloor r \rfloor\cr f_{n+1}(r) &= f_n\left( \frac{1}{r - \lfloor r \rfloor}\right)\cr}$$ Of course this may require numerical calculations with very high precision. Actually, if $r$ is a rational number but you don't know it, no finite precision numerical calculation will suffice.

Robert Israel
  • 448,999
  • Yes, I was worried about that. – Christopher King Mar 21 '13 at 01:37
  • But if you know $r$ to a given precision you can still extract many accurate coefficients of its continued fraction; what's more, there are algorithms that will avoid the high-precision division by smart use of extended GCD algorithms. – Steven Stadnicki Mar 21 '13 at 01:41
  • 1
    The point is that though you may know $x$ is within some arbitrarily small $\epsilon$ of $2$, if you do not know whether $x \ge 2$ or $x < 2$, you can't say whether the continued fraction starts with $1$ or $2$. – Robert Israel Mar 21 '13 at 04:05
3

For arbitrary real numbers, there's no better method known than the 'abstract' one of simply extracting the digits through the usual recurrence relation; even for non-quadratic algebraic numbers — even for a number as simple as $\sqrt{2}+\sqrt{3}$! — nothing is known about any structure to the coefficients.

By contrast, if the goal is to take a number known to some precision and churn out an appropriate number of coefficients for its continued fraction, then there are excellent algorithms for doing that - and that might be enough to find some structure in the coefficients which can then be proven in a non-algorithmic fashion (for instance, the patterns in the continued fraction coefficients of $e$, or of quadratic surds, or in the Liouville numbers). The simplest way is to take a rational approximation $\frac ab$ to your number $r$ (for instance, if you have a decimal expansion $r=d_0.d_1d_2d_3d_4\ldots d_n$ to n digits of precision, then set $a=d_0d_1d_2\ldots d_n$ and $b=10^n$) and then run the extended Euclidean algorithm for the GCD on $a$ and $b$; the 'partial quotients' found along the way are precisely the coefficients of the continued fraction. See http://en.wikipedia.org/wiki/Euclidean_algorithm#Continued_fractions for the basics of the method; if you're interested in more details, volume 2 of Knuth's Art Of Computer Programming (specifically, section 4.5.3, problem 47 within that section and the references there) is an excellent next step.