When I was in school, I stared at this graph for weeks, if not months, trying to figure out an equation for the number of digits in . And I never could figure it out. However, even though I was not able to figure this out for myself, there is a very good approximation using Stirling’s approximation. The next integer after gives the number of digits in , and

The graph below shows just how accurate this approximation really is. The solid curve is the approximation; the dots are the values of . Not bad at all… the error in the curve is smaller than the size of the dots.

The following output from a calculator shows just how close the approximation to is to the real answer. There are also additional terms to Stirling’s series that would get even closer answers.

As I mentioned earlier in this series, I’m still mildly annoyed with my adolescent self that I wasn’t able to figure this out for myself… especially given the months that I spent staring at this problem trying to figure out the answer.

First, I’m annoyed that I didn’t think to investigate . I had ample experience using log tables (after all, this was the 1980s, before scientific calculators were in the mainstream) and I should have known this.

Second, I’m annoyed that I didn’t have at the tips of my fingers the change of base formula

Third, I’m annoyed that, even though I knew calculus pretty well, I wasn’t able to get at least the first couple of terms of Stirling’s series on my own even though the derivation was entirely in my grasp. To begin,

For example, if , then would be the areas of the 9 rectangles shown below (since $\ln 1 = 0$):

The areas of these nine rectangles is closely approximated by the area under the curve between and . (Indeed, I chose a Riemann sum with midpoints so that the approximation between the Riemann sum and the integral would be very close.)

In general, for instead of , we have

This is a standard integral that can be obtained via integration by parts:

We can see that this is already taking the form of Stirling’s approximation, given above. Indeed, this is surprisingly close. Let’s use the Taylor approximation for :

By way of comparison, the first few terms of the Stirling series for are

We see that the above argument, starting with an elementary Riemann sum, provides the first two significant terms in this series. Also, while the third term is incorrect, it’s closer to the correct third term that we have any right to expect:

The correct third term of can also be found using elementary calculus, though the argument is much more sophisticated that the one above. See the MathWorld website for details.