ExplorationsSquaring the digits, over and over
Happy Numbers
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 cycleDefinition: A cycle is a repeating loop of states reached by a rule.; a number that reaches 1 is called happy.
Current view: Digit machine
One worked step: each digit raised to the power, then added.
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.
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?
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.
- 232² + 3² = 4 + 913square each digit, then add
- 131² + 3² = 1 + 910
- 101² + 0² = 1 + 01three steps, and 23 is happy
- 44² = 1616
- 161 + 3637
- 379 + 4958
- 5825 + 6489
- 8964 + 81145
- 1451 + 16 + 2542
- 4216 + 420
- 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 integerDefinition: An integer is a whole-number value, including zero and negative whole numbers, with no fractional part., with nothing left unchecked. Layer 3 is why the rule cannot produce a third.
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 base-10Definition: Decimal notation writes numbers in base ten, using digits 0 through 9 and place values based on powers of ten. 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.
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 factorDefinition: A divisor of n is an integer that divides n with no remainder. of ten per digit while its image grows by only 81.
So no orbitDefinition: The orbit of a starting value is the sequence of states produced by repeated iteration. 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.
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 graphDefinition: A graph is a collection of nodes joined by edges that record relationships or transitions., and this page enumerates it.
Formal statement
Precisely what is being claimed
Fix a base and a power , and let be the digit-power map.
- There is an explicit with , and for every , .
- Consequently every orbitDefinition: The orbit of a starting value is the sequence of states produced by repeated iteration. enters and is eventually periodicDefinition: A sequence is eventually periodic if, after some finite beginning, it repeats with a fixed positive period forever..
- The cyclesDefinition: A cycle is a repeating loop of states reached by a rule. of are exactly the cycles of restricted to - a finite list, which the Destinations view shows in full.
- For , : , and the list is together with .
Statement 4 is a theoremDefinition: A theorem is a mathematical statement established by a proof from accepted definitions and earlier results., not a report of a search. Statements 1 to 3 are what make it one.
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 .
Eventual periodicityDefinition: A sequence is eventually periodic if, after some finite beginning, it repeats with a fixed positive period forever.. OrbitsDefinition: The orbit of a starting value is the sequence of states produced by repeated iteration. are non-increasing once above and confined once below, so after finitely many steps the orbit lies in a set of elements. An infinite sequenceDefinition: A sequence is an ordered list of values, usually indexed by whole numbers. in a finite set repeats a value; from the first repeat onward the orbit is periodic, because is a functionDefinition: A function assigns exactly one output to each allowed input. of the current value alone.
The cycleDefinition: A cycle is a repeating loop of states reached by a rule. 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 proofDefinition: A proof is a finite argument showing that a conclusion follows from stated assumptions., because a separate argument established that all of them is a finite list.
Limits and frontier
Where this page stops being able to help
What is settled is settled. For any base and power in reach, the cyclesDefinition: A cycle is a repeating loop of states reached by a rule., the basinDefinition: A basin of attraction contains the starting states whose paths approach a particular attractor. 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 sequenceDefinition: A sequence is an ordered list of values, usually indexed by whole numbers. converging to a density.
There is no density. The upper limitDefinition: A limit is the value that a sequence or function approaches under a stated limiting process. of that proportion has been proved to be strictly greater than its lower limit, so the ratioDefinition: A ratio compares two quantities by division, describing how large one is relative to the other. keeps moving and never settles. The oscillation happens at scales no browser will ever draw. Everything visible in that figure is consistent with a convergenceDefinition: A sequence converges when its terms approach a definite limit as the index grows. 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 combinationsDefinition: A combination is a selection of items where order does not matter. are hatched out. Their regions are finite - that is a theoremDefinition: A theorem is a mathematical statement established by a proof from accepted definitions and earlier results. and it applies to every base and power - but finite is not the same as small: base 16 with fourth powers confines its orbitsDefinition: The orbit of a starting value is the sequence of states produced by repeated iteration. 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 conjectureDefinition: A conjecture is a precise mathematical claim supported by evidence but not yet proved., because the space is infinite and is a prefixDefinition: A prefix is an initial segment of a string or sequence, beginning at its first position. 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.
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
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
- Sources
- A007770 - Happy numbers
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
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
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
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
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.
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.
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.
- 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.
- 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.
- 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.
Related by mechanism
Connected by how they work, not by sharing a topic label.