# What is the distribution of leading digits of the squares?

Inspired by How can 0.149162536... be normal?, I ask for the distribution of the leading coefficients of $1,4,9,16,25,36\ldots$. (namely $1,4,9,1,2,3\ldots$) Does a Benford-like law apply?

The online encyclopedia of integer sequences has it, and has a tantalizing link to something called Gelfand's question.

• It might. The idea of Benford is that the distribution is 'heavy tailed' along the natural numbers so as to be relatively flat in a log-scale graph. I worry that this is not the case for this particular distribution, however, as the growth of the sequence is slow under the $\log$... – A Blumenthal Apr 23 '13 at 21:16
• Benford holds on the nose, for instance, for first digits of sequences with a fixed rate of exponential growth, like the powers of $2^n$. The proof invokes the unique ergodicity of irrational rotation on the circle and a clever choice of conjugacy. – A Blumenthal Apr 23 '13 at 21:17
• I added the ergodic-theory tag to reflect the connection I mentioned in my last comment. – A Blumenthal Apr 23 '13 at 21:19
• Here are the frequencies I got for the first $10^5$ positive integers (from $1$ to $9$): $0.1916$, $0.1470$, $0.1239$ $0.1092$, $0.0987$, $0.0908$, $0.0845$, $0.0793$, $0.0751$. Note that these do not agree with Benford's law. – Lord Soth Apr 23 '13 at 22:49

Of the $n$ digit numbers, the leading digit of $m^2$ will be $1$ if $\frac m{10^{n-1}}$ is in the range $[1,\sqrt 2]$ or $[\sqrt {10},\sqrt{20}]$. The first will account for about $(\sqrt 2-1)10^{n-1}$, the second will account for $(\sqrt {20}-\sqrt{10})10^{n-1}$ out of $9\cdot 10^{n-1}$ numbers of that length, so going up to a given number of digits about $0.1916$ of all numbers up to $n$ digits have squares that start with $1$

The values for other leading digits can be computed similarly. The results are: $$\begin {array}{r | l} \text{leading digit} & \text{fraction} \\ \hline 1&0.191564\\2&0.146992\\3&0.12392\\4&0.109176\\5&0.098702\\6&0.090766\\7&0.084483\\8&0.079348\\9&0.075049\end{array}$$

These match user17762's result for up to $5$ digit numbers nicely.

• I think you are using $n$ both for the number and the number of digits, which makes it a bit confusing... – user17762 Apr 24 '13 at 0:41
• @user17762: You are right. Fixed. Thanks – Ross Millikan Apr 24 '13 at 1:29

The leading digit doesn't seem to follow Benford's law. Below is a plot, where the frequency of first digit from the squares of the first $1,000,000$ numbers are plotted.

The Benford law is $$p(d) \propto \log_{10}\left(1+\dfrac1{d}\right)$$

The empirical law given by $$p(d) \propto \log_{10}\left(1+\dfrac1{\sqrt{d}}\right)$$ seems to be a better fit.

\begin{array}{|c|c|c|c|} \hline \text{Digit} & \text{Benford's law} & \text{Frequency of $1^{st}$ digit of a square} & \text{Emperical law}\\ \hline 1 & 0.3010 & 0.1916 & 0.1867\\ 2 & 0.1761 & 0.1470 & 0.1441\\ 3 & 0.1249 & 0.1239 & 0.1228\\ 4 & 0.0969 & 0.1092 & 0.1092\\ 5 & 0.0792 & 0.0987 & 0.0996\\ 6 & 0.0669 & 0.0908 & 0.0922\\ 7 & 0.0580 & 0.0845 & 0.0864\\ 8 & 0.0512 & 0.0793 & 0.0816\\ 9 & 0.0458 & 0.0751 & 0.0775\\ \hline \end{array}

• Your Benford's law does not look right. – Lord Soth Apr 23 '13 at 22:53
• @LordSoth Thanks updated now. I can't imagine how I drew a pdf where one pdf was always above another one =) – user17762 Apr 23 '13 at 23:02
• I want to believe your empirical law but the mismatch looks significant, maybe we need to look at the first $10^{10}$ numbers (say). I have also tried the same thing for cubes (with $d^{1/3}$) but that gave an even worse fit. – Lord Soth Apr 23 '13 at 23:19