ExplorationsSquaring the digits, over and over

Happy Numbers

Exhaustively checkedDigitsIterationCyclescurious

Start with a positive whole number written in base 10, square each digit and add the squares, then repeat with the total. For example, 19 becomes 82 because 1² + 9² = 82. Every start eventually reaches 1 or the same eight-number ; a number that reaches 1 is called happy.

Current view: Digit machine

One worked step: each digit raised to the power, then added.

Digit machine · base 10 · power 249
Starting from
4
9

Press Step to raise each digit to the power of 2 and add.

tile
one digit of the number being worked
raised
that digit to the power, sitting under the digit it came from
sum
the terms added together, which becomes the next value

The heavy row is the value being worked; blue tiles are its digits raised to the power, each under the digit it came from; vermilion is their sum, which becomes the next value.

Ready at 49. Run or step to raise each digit to the power of 2 and add.

Now
49
Steps taken
0 / 4
Verdict
Ready

Starting value

The rule reads the digits in the selected base.

Step by step

Use Step for one change you can inspect, or Run to watch the changes accumulate.

Speed
Advanced parameters

Base 10. Happiness is a property of how a number is written, not of the number.

Cases worth seeing

Try this

Pick any number at all and predict, before running it, whether it is happy. How often are you right?

1/5

What is going on

Each explanation begins with a worked example and follows the same operation through intuition, formal statements and proofs. Later sections distinguish what is established from questions that remain open, so you can follow the level of detail useful to you.

Worked by handBoth endings, worked by hand. First 23, which reaches 1.
  1. 232² + 3² = 4 + 913square each digit, then add
  2. 131² + 3² = 1 + 910
  3. 101² + 0² = 1 + 01three steps, and 23 is happy
Now 4, which does not. It runs into a loop of eight and goes round it forever:
  1. 44² = 1616
  2. 161 + 3637
  3. 379 + 4958
  4. 5825 + 6489
  5. 8964 + 81145
  6. 1451 + 16 + 2542
  7. 4216 + 420
  8. 204 + 04back to 4 - and round again, forever

Now run every number below 1000 and sort them by which of those two endings they reach. That is the Destinations view: one card per ending, and a bar for how much of the region falls into it.

Those are the only two endings there are. Not the only two anyone has found - the only two, for every positive , with nothing left unchecked. Layer 3 is why the rule cannot produce a third.

01

What you are seeing

A plain description of the process

Begin with a positive whole number written in base 10. Multiply each digit by itself, add those squares and use the total as the next number. For example, 19 gives 1² + 9² = 82; then 82 gives 8² + 2² = 68.

Repeating the operation gives 68 → 100 → 1. Since 1² = 1, reaching 1 means every later value is also 1. A starting number with this outcome is called happy.

For this square-and-add rule, every positive start either reaches 1 or enters 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4. Those are the only two outcomes, as the finite reduction below proves. Changing the base or the power changes the rule, so that two-outcome statement should not be carried over to the other settings.

02

Why it starts to make sense

Intuition, before any algebra

The rule has a ceiling, and the ceiling is very low.

A four-digit number is at least 1000. The most its digits can contribute is four nines, which is . So every four-digit number gets smaller. The same is true of five digits, six digits, and everything above - the number grows by a of ten per digit while its image grows by only 81.

So no can run away. Whatever you start with, within a few steps you are below 1000 and you stay below 1000. And once a rule is confined to a thousand values and never stops applying, it has to revisit something. From then on it repeats forever.

That is the whole reason this page can be certain of anything: the interesting behaviour has nowhere to hide.

03

The key idea

The bound that closes the space

Write for the sum of the -th powers of the digits of in base . If has digits then

The left-hand quantity is exponential in ; the right-hand one is linear. So there is a width at which the exponential wins:

Every number with digits or more therefore satisfies and strictly decreases. And any number below has at most digits, so its image is at most , which is smaller still - the interval maps into itself.

For base 10 and squares, : the interval is .

A map from a finite set to itself, applied forever, must repeat. The dynamics are a finite functional , and this page enumerates it.

04

Formal statement

Precisely what is being claimed

Fix a base and a power , and let be the digit-power map.

  1. There is an explicit with , and for every , .
  2. Consequently every enters and is .
  3. The of are exactly the cycles of restricted to - a finite list, which the Destinations view shows in full.
  4. For , : , and the list is together with .

Statement 4 is a , not a report of a search. Statements 1 to 3 are what make it one.

05

Proof

Complete, and short enough to read

The bound. As in layer 3. Both inequalities are immediate from the definition of base- notation, and the comparison holds for all larger widths too: increasing by one multiplies the right-hand side by and the left-hand side by , and .

. are non-increasing once above and confined once below, so after finitely many steps the orbit lies in a set of elements. An infinite in a finite set repeats a value; from the first repeat onward the orbit is periodic, because is a of the current value alone.

The list. Every cycle lies in , and has been enumerated. Nothing outside it can be periodic, because points outside strictly decrease. ∎

The last line is the part worth pausing on. "We checked all of them" is normally a confession; here it is the end of the , because a separate argument established that all of them is a finite list.

06

Limits and frontier

Where this page stops being able to help

What is settled is settled. For any base and power in reach, the , the sizes and the longest journey to 1 are complete answers. There is no larger computation that would refine them.

What is not settled is how many. Look at the "How many are happy" view. The proportion of happy numbers below drops from 30% to 20% to 14.3% and then appears to hold there. It looks exactly like a converging to a density.

There is no density. The upper of that proportion has been proved to be strictly greater than its lower limit, so the keeps moving and never settles. The oscillation happens at scales no browser will ever draw. Everything visible in that figure is consistent with a that does not exist - which is a good reason to distrust flat-looking tails in general.

The refused cells are real. In the Base × power view, six are hatched out. Their regions are finite - that is a and it applies to every base and power - but finite is not the same as small: base 16 with fourth powers confines its to about a million states, and this page declines to enumerate them. The claim "the space is finite" and the claim "we can check the space" are different claims, and conflating them is how a lot of computational mathematics goes wrong.

Compare with Gilbreath's difference field. There, a verification to establishes nothing about the , because the space is infinite and is a of it. Here, a verification of 999 states establishes everything. The difference is not diligence. It is whether anything forces the space to close.

What is actually established

Every statement on this page, with its status, its exact scope, and the date that status was last checked.

Proved

For any base b and power p, every orbit of the digit-power map ends up inside a fixed finite interval, and that interval maps into itself.

Scope
Every base and power, not only the ones offered here.
Why
A number with d digits in base b is at least b^(d−1), while the sum of its digit powers is at most d·(b−1)^p. The first grows exponentially in d and the second only linearly, so beyond some width every number maps strictly downward. Below that width the largest possible image is smaller still, so the interval cannot be escaped.
Status checked
Exhaustively checked

In base 10 with squares the rule has exactly two cycles: the fixed point 1, and the eight-cycle 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

Scope
All 999 states of the closed region - and therefore every positive integer, since every number is carried inside the region after finitely many strictly decreasing steps.
Why
This is the case where exhaustion is a proof rather than evidence. The region argument above bounds the dynamics; enumerating the bounded region leaves nothing outside it. Every positive integer is either happy or falls into that one cycle - there is no third possibility and no unexamined tail.
Computation (exact)
Exact integer arithmetic over all 999 states of the region, enumerated in your browser. Complete for the region, and the region is provably everything. Algorithm digit-power-1.
Status checked
Exhaustively checked

Every happy number below 1000 reaches 1 within six steps, and six is attained - 356 is one of the values that needs all six.

Scope
The 142 happy values in 1 … 999. Larger numbers first fall into this range.
Why
A bound rather than a record: because the region is closed, no search could turn up a longer journey from inside it. It is not a bound on every start. A larger number spends its first steps falling into the region, so it can take longer - 78,999 needs seven.
Computation (exact)
Every state of the region walked to its cycle with exact integer arithmetic. The figure is a maximum over the region, not a maximum over what was tried. Algorithm digit-power-1.
Status checked
Exhaustively checked

In base 2 and base 4, with squares, every positive integer is happy. In base 12 only seven values in the whole region are.

Scope
Bases 2 to 16 with powers 2 to 4, excluding the combinations whose region is too large to enumerate here.
Why
The strongest evidence on the page that happiness is a property of notation and not of number. It also does not survive changing the power: base 4 with cubes has nine cycles and most numbers are not happy.
Computation (exact)
Each base and power enumerated over its own complete region. Six combinations - base 11 and above with fourth powers - have a finite region that this page will not enumerate, and are shown as refused rather than guessed at. Algorithm digit-power-1.
Status checked
Exhaustively checked

With cubes in base 10 the rule has five fixed points: 1, 153, 370, 371 and 407.

Scope
All 9,999 states of the region for base 10 with power 3.
Why
These are exactly the three-digit numbers equal to the sum of the cubes of their own digits - the Armstrong, or narcissistic, numbers. The connection is not a coincidence: a fixed point of the digit-cube map is by definition such a number.
Computation (exact)
Exact enumeration of the whole region in your browser. Fixed points are read off the cycle structure, not searched for. Algorithm digit-power-1.
Status checked
Proved

The happy numbers have no natural density: the proportion below x does not converge.

Scope
The happy numbers in base 10 with squares, as a subset of the positive integers.
Why
The upper density has been proved to exceed the lower density, which is exactly the statement that the limiting proportion does not exist. This page can only draw a finite prefix of that proportion, and the prefix looks like it is converging - which is why the figure is captioned rather than left to speak for itself. The specific numerical bounds in the literature have not been checked here.
Status checked
Observed in this run

Among the first 100,000 positive integers, 14,377 are happy - about 14.4%.

Scope
The single range 1 … 100,000 in base 10 with squares. Produced by this page, for this range only.
Why
Recorded as an observation and nothing more. It is tempting to read it as an estimate of a density, and there is no density for it to estimate.
Computation (exact)
Each value classified by table lookup after one exact step into the region. Complete for the range stated, and evidence about no other range. Algorithm digit-power-1.
Status checked

Sources

Review notes show which bibliographic details Mathomaly has checked and which remain unresolved. Checking a publication record does not independently verify its proof.

  1. Richard K. Guy, Unsolved Problems in Number Theory, Springer, third edition, 2004. Link

    Standard reference; happy numbers and their digit-power relatives appear among the elementary iteration problems.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: publisher record.

    Publisher confirms the author, third edition and 2004 print publication. This check does not verify every section attribution.

  2. Justin Gilmer, On the density of happy numbers, Integers 13, A48, 2013. Link

    Establishes separated upper and lower density bounds for base-ten happy numbers, so their natural density does not exist.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Journal PDF confirms Justin Gilmer, Integers 13 (2013), A48.

  3. A007770 - Happy numbers, The On-Line Encyclopedia of Integer Sequences. Link

    The sequence itself, with the standard references.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Checked the sequence identifier, definition and displayed initial terms on the database entry.

  4. A003132 - Sum of squares of digits of n, The On-Line Encyclopedia of Integer Sequences. Link

    The map itself, independent of what it is being used for.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Checked the sequence identifier, definition and displayed initial terms on the database entry.

  5. A005188 - Armstrong (narcissistic) numbers, The On-Line Encyclopedia of Integer Sequences. Link

    Cited for the cube case: 153, 370, 371 and 407 are fixed points of the digit-cube map precisely because they are three-digit Armstrong numbers.

    Bibliographic record checked. This is not an independent verification of the proof.

    Bibliographic review:

    AI-assisted bibliographic audit. Evidence type: source text.

    Checked the sequence identifier, definition and displayed initial terms on the database entry.

Connected by how they work, not by sharing a topic label.