Maybe powers of π don't have unexpectedly good approximations?
After I wrote recently about Ramanujan’s approximation \(\pi^4\approx 2143/22\), writing “why do powers of \(\pi\) seem to have unusually good rational approximations?”, Timothy Chow emailed to challenge my assumption, asking what evidence I had that their approximations were unusually good. So that led me to do a little statistical experiment to test that hypothesis, and the experiment showed…that the approximations seem to be about as good as we would expect, no more, no less. Not unusually good. Chow was correct, and my earlier statement was overstated. So if Ramanujan’s approximation is not just random fluctuation (which for all I know it could be), it at least does not seem to be part of a pattern of many good rational approximations for small powers of \(\pi\). Below are some details of how I came to this conclusion.
First off, one gets good rational approximations by truncating the continued fraction representation of a number. for instance, Ramanujan’s approximation can be obtained from the continued fraction
\[\pi^4=97 + \cfrac{1}{2 + \cfrac{1}{2 + \cfrac{1}{3 + \cfrac{1}{1+\cfrac{1}{16539+\cdots}}}}}\]by stopping just before the big number \(16539\). You want to stop at those points, roughly speaking, because the accuracy of your approximation (as measured for instance by how many decimal digits you get correct) comes from combining all of the terms up to and including the big one you stopped before, but the complexity of your approximation (how many digits it takes to write it down) comes from only the terms before you stopped. When you stop just before a big term, you get a lot of accuracy for free. And so the question I was really asking was “why do the powers of \(\pi\) have unusually big terms in their continued fractions?” But the question I should have asked first was “do the powers of \(\pi\) have unusually big terms in their continued fractions?”
For a random number, the terms of the continued fraction will be distributed according to the Gauss–Kuzmin distribution, according to which the probability of seeing a term with value exactly \(k\) is
\[- \log_2 \left( 1 - \frac{1}{(1+k)^2}\right).\]This is a heavy-tailed distribution, so one should expect to see some large numbers from time to time. What I wanted to test was a null hypothesis that the continued fraction for powers of \(\pi\) are distributed in this way. If the tests revealed a low likelihood of this being true, it would suggest that they have some other distribution, confirming what I wrote in my earlier post. If they didn’t, it still might mean that there was something unusual about those terms, but it would have to be more subtle, subtle enough to be undetected by the statistical tests I used.
This is exactly the sort of thing Pearson’s \(\chi^2\) test is good for. So I set up a \(\chi^2\) test in R comparing the observed data (the frequencies of each value in the continued fraction terms for \(\pi\), \(\pi^2\), \(\pi^3\), and \(\pi^4\), as taken from OEIS) with the Gauss–Kuzmin distribution. I omitted the initial term from each continued fraction, because those are the integer parts of the powers of \(\pi\), which are both nonrandom and uninteresting for approximation purposes. I also grouped the terms of the continued fractions into six exponentially-growing buckets, by mapping each term \(t_i\) to \(\min\bigl(5,\lfloor\log_2 t_i\rfloor\bigr)\), because the \(\chi^2\) test works better when it has only a small number of well-populated frequency counts to compare, rather than \(16539\) of them, many empty or with only one representative. This meant also computing the Gauss–Kuzmin probabilities for the same buckets. These buckets still don’t have uniform probabilities but I thought it better to stick to my first choice of bucketing rather than to repeatedly adjust the parameters of the test. Even with this bucketing the \(\chi^2\) test still wasn’t strong enough to work well on the OEIS data taken separately for each individual power of \(\pi\). Instead I had to concatenate the data for the four powers I had chosen into a single test to get it to work without R complaining.
Because I am more fluent in Python than R, I did this as a Python script to generate a very short R script, but it would have been as easy to do the whole thing directly in R. The results: a \(p\)-value somewhat greater than \(\tfrac12\) (not small). So the null hypothesis was not rejected and I do not have evidence that the powers of \(\pi\) have unusually big terms in their continued fractions.