The share of happy numbers never settles
Worth reading first: The staircase that shows the whole orbit · Fifty-four numbers funnel into 6174.
Take a number, square each of its digits and add the squares. Do it again to the result, and keep going. Starting from 7 the sequence is 49, then , then , then , then 1, and then 1 for ever. Starting from 4 it is 16, 37, 58, 89, 145, 42, 20, and then 4 again: a cycle of eight numbers that goes round indefinitely. A number whose sequence reaches 1 is called happy, a name that seems to have come from a British schoolroom in the 1960s and reached the literature through Richard Guy’s Unsolved Problems in Number Theory; one that does not is unhappy, or sad.
This is one more finite routine on the digits of a number, of the kind that Kaprekar’s routine and the differences round a ring studied, and like them it can be completely solved by a bounded search: every number is happy or falls into the eight-cycle, and nothing else can happen. The surprise is what that solution does not settle. Asked what proportion of numbers are happy, the iteration gives an answer that changes with the range over which it is asked, and changes for ever: the share of happy numbers has no limiting value at all.
The two facts sit side by side in this essay. The first is a statement about where each orbit goes and is proved by checking a few hundred cases. The second is a statement about how the answers are distributed across all numbers, and it turns out to be a self-similar question about the map’s own behaviour at a smaller scale, which is why it cannot be settled by checking.
Everything comes down
The reason every orbit can be traced is that the map shrinks large numbers, and shrinks them fast. A number with digits is at least , while its digit-square sum is at most , which is what all nines give. For the comparison is against , and the gap only widens: the number grows exponentially in its length and the sum linearly. So a number of four or more digits always maps to something smaller, and repeating the map must bring any starting value below 1,000 in finitely many steps.
Three-digit numbers need a little more care, and the figure supplies it. It plots the digit-square sum of every from 1 to 999 against , with the dashed diagonal marking where a number would equal its own sum. Above 243 every point lies below the diagonal, because the largest sum any three-digit number has is , from 999. So an orbit that enters the three-digit range drops below 244 at once, and numbers below 244 map to at most 163 — attained by 199. After that the orbit lives in a set of 163 numbers, and a map on a finite set must eventually repeat — the same pigeonhole that forces the orbit a computer draws into a cycle, since a machine has only finitely many numbers to visit.
Following each of those 163 numbers until it repeats is a small computation, and it finds exactly two cycles: the fixed point 1 and the eight numbers 4, 16, 37, 58, 89, 145, 42, 20. There are no others, so every positive integer, however large, is either happy or ends on that cycle. The colours in the figure are the two fates: happy points, unhappy points, and the eight cycle members, which are the only numbers that never leave.
This is the shape of most digit routines. The staircase that shows the whole orbit drew iteration on a continuous interval, where fixed points are crossings of a curve with the diagonal and their stability is a slope. Here the “curve” is a cloud of points, discontinuous everywhere, and the only structure that survives is the inequality with the diagonal. That one inequality is enough to make the long-term behaviour of every orbit a finite matter, which is exactly what fails for the Collatz map, whose values can climb.
How long an orbit takes
The map shrinks numbers so fast that orbits are short. Every happy number below a hundred thousand reaches 1 within seven steps, and the figure lists, for each number of steps from none to seven, the smallest happy number that needs exactly that many: 1, 10, 13, 23, 19, 7, 356 and 78,999. The pattern in the last three is the point. The orbit of 356 begins , and 70 goes to 49, which is where 7’s orbit went; 78,999 goes to . Each record is the smallest number whose digit-square sum is the previous record.
That makes the next record easy to describe and impossible to write out. It is the smallest number whose digits’ squares add up to 78,999. Nines contribute the most per digit, so the fewest digits is the aim: 976 digits would give at most , a surplus of 57 over the target, and replacing nines by smaller digits removes 17 (an eight), 32 (a seven), 45, 56 and so on, none of which sum to 57. With 977 digits it can be done, and the smallest arrangement is 3788 followed by 973 nines. The record after that has more digits than there are atoms in the observable universe.
So the height of a happy number is unbounded, but it grows like an iterated logarithm: to need one more step, a number must be roughly exponentially longer than the previous record. Every number anybody will ever write down is within a dozen steps of its fate. That is the dynamics of a map that shrinks by an exponential factor, and it is the reverse of the climb of a Collatz orbit, where a number of a hundred digits may rise for hundreds of steps before falling.
Counting the happy ones
Once every number is known to be happy or not, the natural next question is how common happiness is. Of the numbers from 1 to 1,000, 143 are happy. Of the first ten thousand, 1,442; of the first hundred thousand, 14,377; of the first million, 143,071; of the first ten million, 1,418,854. Each count is close to 14 per cent of the range, and the figure plots the running share for every up to ten million. A reasonable reading of it is that the share is converging, slowly, to something near 0.143.
The reading is wrong, and the figure is a fair illustration of why a running count can mislead. The curve drifts, gently, and a drift this slow cannot be distinguished from a slow convergence by looking at seven powers of ten. Nothing in the counts says that the drift will continue, and nothing says that it will stop. To settle the matter the count has to go far beyond what can be enumerated number by number, and that needs a different way to count.
The different way comes from noticing what the map actually reads. The digit-square sum of a number depends only on how many of each digit it contains, not on their order, and whether a number is happy depends only on its digit-square sum. So the happy numbers below are counted by counting digit strings of length according to their digit-square sum, and then adding up the counts for the sums that are happy. That is the same simplification that makes Kaprekar’s routine small, applied not to one step but to a whole range at once.
A distribution of sums
The digit-square sum of a number chosen at random below is a sum of independent copies of — the digits of a random number are independent and uniform, which is the fact that made almost every orbit fair for the doubling map — where is a digit chosen uniformly from 0 to 9. Its distribution is the distribution of one digit’s square convolved with itself times, and that is a short computation even for : the sum can be at most , the distribution is a list of that length, and each convolution step adds one digit. The share of happy numbers below is then the total probability of the happy sums. No individual number of a thousand digits is ever examined; the computation is exact apart from rounding.
The result is the figure, and it does not converge. Below the share is 0.142 — of the thousand numbers 0 to 999, 142 are happy, the 143 in the running count included 1,000 itself. It wanders near 0.14 for the first dozen digit lengths, falls to a minimum of 0.118 at 18 digits, climbs back, and by a few hundred digits it is oscillating with a large amplitude: 0.186 at 403 digits, near 0.144 at 700, 0.172 at 800, 0.147 at 1,000. The share among numbers below has no limit as grows, and therefore the share among numbers below has none either.
The figure is not a proof that the oscillation continues past a thousand digits, but the mechanism makes it inevitable. A single digit’s square has mean and standard deviation about , so the digit-square sum of a -digit number is concentrated around , within a few multiples of . For that is around 11,500, give or take 500. The share of happy numbers below is therefore almost exactly the share of happy numbers in a window around 11,500 — a question about five-digit numbers. Those, in turn, map to around , a question about three-digit numbers. The share at one scale is a smoothed reading of the share at a scale logarithmically smaller, and because the small-scale share is uneven, the large-scale share inherits its unevenness, magnified and smeared but never removed.
A density that does not exist
What the figure displays was proved by Justin Gilmer in 2013. A set of positive integers has a natural density if the share of its members among tends to a limit; Gilmer showed that the happy numbers have upper density, the largest limit point of that share, above 0.185, and lower density, the smallest, below 0.114. The two cannot meet, so there is no density. The exact computation by digit count already shows the gap from 0.118 to 0.186, and the running share at values of that are not powers of ten can dip below anything the powers of ten show.
His argument is the mechanism described above turned into estimates. If the share of happy numbers near some size is high, then numbers of about digits are happy in a high share too, because their digit-square sums cluster near ; and a run of such digit lengths gives a range of over which the running share is high. The same works for low shares. So once one window of unusual happiness exists, it propagates to ever larger scales, and the oscillation is permanent. It is a dynamical statement about the map acting on distributions rather than on numbers, in the spirit of the histogram an orbit leaves, where a chaotic map’s long-run behaviour was read off the distribution it preserves rather than off any one orbit: the map sends a distribution of -digit numbers to a nearly normal distribution of sums near , and the share of happiness is a quantity that this action carries from one scale to the next.
This is the genuinely surprising connection. The same failure occurs for the leading digits of whole numbers, which Benford’s law is about: the share of numbers up to that begin with 1 swings between about 11 per cent, at just below a power of ten, and 56 per cent, at just below twice one, and has no limit. In both cases the property depends on a number through something like its logarithm — its length, its leading digits — and natural density, which weighs each number up to equally, cannot average over a quantity that cycles on a logarithmic scale. Benford’s law is rescued by averaging differently — with each number weighted by , the logarithmic density of numbers beginning with 1 exists and equals — and whether some such averaging rescues the happy numbers too is a cleaner question than the natural density that fails.
Cubes, and other bases
Nothing in the argument that every orbit comes down depends on squaring or on base ten, and both can be changed. Summing the cubes of the digits instead, a number of five or more digits is again larger than its sum, and following every number below ten thousand finds nine fates in base ten: five fixed points, 1, 153, 370, 371 and 407, each of which is the sum of the cubes of its own digits — — and four cycles, 55 → 250 → 133, 136 → 244, 160 → 217 → 352, and 919 → 1459. The squares in base ten are, by comparison, a tidy case.
Changing the base for squares gives the figure. In base every orbit ends below , so following every number up to that bound finds every cycle, and the figure draws them as bars proportional to their lengths for every base from 2 to 25. Most bases have several cycles of assorted lengths — counting fixed points, base 15 has ten and base 23 fifteen — and base 20 has a single cycle of length 26 besides the fixed point. Only in bases 2 and 4 is 1 the only fate, so that every number is happy. A search of every base up to 300 finds no third such base, and published searches have gone much further without finding one; whether any other “happy base” exists is open, and expected not to.
Base 2 is happy for a trivial reason: the digits are 0 and 1, so the map counts the ones in the binary expansion, and the count of ones of any number above 1 is smaller than the number. Base 4 is a coincidence of small numbers, and the evidence for it being the last is purely computational. The same contrast between a structural reason and a numerical accident runs through the numbers that fool every base, where a property that looks as if it should depend on the base turns out to be forced by arithmetic in some bases and accidental in others.
Where the computation stops
Every figure here is either a finite enumeration or an exact computation over a finite range, and both kinds stop somewhere. The classification into two fates is complete: it is proved by the inequality and a check of 163 numbers, and no figure is needed beyond the one that draws the inequality. The record heights are complete up to 78,999 and described beyond it, and the description is a proof, not an extrapolation.
The density is different. The exact share by digit count is computed to a thousand digits and plotted; the picture shows the oscillation and suggests its persistence, but the persistence is Gilmer’s theorem, not the figure’s. A thousand digits is a long way, and the oscillation could in principle die out at ten thousand digits for all the picture says; the mechanism, which carries unevenness from one scale to the next, is what rules that out. Equally, the shares plotted are for ranges ending at powers of ten. The running share up to an arbitrary moves within each block of digit lengths as well, and the true upper and lower densities — the extreme values the running share keeps returning to — are known only within bounds.
The bases figure has a similar limit. It finds every cycle in each base shown, but the claim that 2 and 4 are the only happy bases is a statement about all bases, and the figure stops at 25 while the search stops at 300.
Still open: how long a run of happy numbers can be
Happy numbers can come in runs of consecutive integers. The first pair is 31 and 32; the first three in a row are 1,880 to 1,882; four start at 7,839, and five at 44,488, which is also the longest run below a million. Esam El-Sedy and Samir Siksek showed in 2000 that there are runs of every length — arbitrarily long blocks of consecutive happy numbers exist — by building numbers whose digits can be adjusted to steer each member of the block’s digit-square sum onto a happy value. The constructions give enormous numbers, and the smallest run of each length is known only for small lengths.
The bigger questions are about the density’s shape. What exactly are the upper and lower densities of the happy numbers? Gilmer’s bounds — above 0.185 and below 0.114 — come with estimates of the extreme values the running share approaches, but the exact values are not known, and it is not even known whether they are attained in any simple pattern of . Is there a natural averaging method — logarithmic density, or some weighted variant — under which the happy numbers have a well-defined share, and what is that share? And beyond happy numbers, which properties of a number that depend only on its multiset of digits can have a natural density at all? For the happy numbers the answer is now known to be no; for the general question there is a heuristic, which this essay has followed, and not a theorem.
Two fates and no proportion
Every number is happy or falls into the cycle 4, 16, 37, 58, 89, 145, 42, 20, because a number of four or more digits exceeds its digit-square sum and a check of the 163 numbers below 164 finds no other cycle. Orbits are short: the smallest happy numbers of heights 0 to 7 are 1, 10, 13, 23, 19, 7, 356 and 78,999, and the next has 977 digits. But the share of happy numbers has no limit. Counted exactly over the numbers below , by convolving the distribution of digit squares, it falls to 0.118 at 18 digits and rises to 0.186 at 403, because a -digit number’s sum lies near and the happiness of numbers there is the same uneven question at a logarithmically smaller scale. Only in bases 2 and 4 is every number happy, as far as anyone has looked.
What links here
Computed from the collection, not written here: the essays that point at this one.
Shares its objects with
Essays that name at least two of the same things, and that neither author linked.
- A point that pulls, and a point that pushes — both name fixed point, iteration, orbit
- Square it and keep the middle — both name fixed point, iteration, orbit
- A difference too small to draw — both name iteration, orbit
- A map that shrinks everything — both name fixed point, iteration
- Every flat graph is a pile of circles — both name fixed point, iteration
- Every site in the middle of its own cell — both name fixed point, iteration
Named objects
A dashed tag is an object no other essay names yet.
ConvolutionCycleDigit sumFixed pointIterationNatural densityOrbit