Happy number: Difference between revisions
Tag: references removed |
|||
Line 585: | Line 585: | ||
===Base-power congruence relations=== |
===Base-power congruence relations=== |
||
Given a base <math>b</math>, if <math>m</math> is a [[prime number|prime]] [[divisor]] of <math>b - 1</math>, and the power <math>p \equiv 1 \bmod (m - 1)</math>, then all happy numbers <math>n</math> in base <math>b</math> must satisfy the congruence relation <math>n \equiv 1 \bmod m</math>. <ref>{{Cite arxiv |title=Consecutive Happy Numbers |arxiv=math/0607213 |author1=Pan |first1=Hao |year=2006 |
Given a base <math>b</math>, if <math>m</math> is a [[prime number|prime]] [[divisor]] of <math>b - 1</math>, and the power <math>p \equiv 1 \bmod (m - 1)</math>, then all happy numbers <math>n</math> in base <math>b</math> must satisfy the congruence relation <math>n \equiv 1 \bmod m</math>. <ref>{{Cite arxiv |title=Consecutive Happy Numbers |arxiv=math/0607213 |author1=Pan |first1=Hao |year=2006}}</ref> For example, all happy numbers in [[base 3]] when summing up powers of their digits must be odd, and all happy numbers in [[base 4]] and [[base 10]] when summing up odd powers (e.g. cubes, fifth powers, seventh powers, etc.) of their digits must have a remainder of 1 when dividing by 3. |
||
== Generalising to arbitrary functions == |
== Generalising to arbitrary functions == |
Revision as of 17:22, 24 August 2019
A happy number in base- is defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits in base-, and repeat the process until the number either equals 1 (where it will stay), or it loops endlessly in a cycle that does not include 1. Those numbers for which this process ends in 1 are happy numbers, while those that do not end in 1 are unhappy numbers (or sad numbers).[1]
Origin
The origin of happy numbers is not clear. Happy numbers were brought to the attention of Reg Allenby (a British author and senior lecturer in pure mathematics at Leeds University) by his daughter, who had learned of them at school. However, they "may have originated in Russia" (Guy 2004:§E34).
Overview
More formally, let be a natural number. The number of digits in can be found by
- ,
where is the number base. The digits of can be found as follows:
and
where .
We define the happy function in base to be the following:
- .
A number is happy in base if and unhappy otherwise, where represents the -th iteration of on .[2]
For example, in base 10, 19 is happy, as
If is happy, then is happy for all ; if is unhappy, then is unhappy for all . The happiness of a number is unaffected by rearranging the digits and by inserting or removing any number of zeros anywhere in the number.
There are infinitely many happy numbers, as 1 is a happy number, and for every , ( in base ) is happy, since its sum is 1. Indeed, the happiness of a number is preserved by removing or inserting zeroes at will, since they do not contribute to the cross sum.
A natural number is a fixed point for the happy function if . and are trivially fixed points for all . A natural number is a periodic point for the happy function if for a positive integer , where is the prime period of . Fixed points are periodic points with a prime period of 1. All natural numbers are preperiodic points for the happy function, regardless of the base. This is because if , , so any will satisfy until . There are a finite number of natural numbers less than , so after enough iterations of it is guaranteed to reach a periodic point or a fixed point less than , making it a preperiodic point.
Numbers in base lead to periodic or fixed points of numbers .
If , then the bound can be reduced. Let be the number for which the sum of squares of digits is largest among the numbers less than .
- because .
Let be the number for which the sum of squares of digits is largest among the numbers less than .
- because .
Let be the number for which the sum of squares of digits is largest among the numbers less than .
Let be the number for which the sum of squares of digits is largest among the numbers less than .
. Thus, numbers in base lead to periodic or fixed points of numbers .
Given a periodic point with prime period , the associated sequence of periodic points for any natural number is a cycle, and is the period of the cycle.
Happy bases
A happy base is a number base whose only periodic points for the happy function are the trivial fixed points at 0 and 1. The only known happy bases are 2 and 4. There are no others less than 5×108.[3]
General formulas for fixed and periodic points
There are general formulas for finding fixed and periodic points, and thus unhappy numbers, for a particular base .
Fixed points
Any two-digit fixed point in base with natural number digits has to satisfy the quadratic Diophantine equation .
There are no three-digit fixed points for any base.
Let be a three-digit number in base with natural number digits . Then a fixed point of the happy function is given by a solution to the the Diophantine equation . However, has to be equal to zero or 1 for any , because the maximum value can take is . As a result, there are actually two related equations to solve
- when
- when
corresponding to two-digit and three-digit fixed points respectively. Now let and . Then the Diophantine equation for the three-digit fixed point becomes
However, for all values of . Thus, there are no solutions to the Diophantine equation, and there are no three-digit fixed points.
Base b = m2k + m + k
Let be positive integers and the number base . Then:
- is a fixed point for base for all
Let the digits of be and . Then
Thus, is a fixed point for base for all .
- is a fixed point for base for all .
Let the digits of be and . Then
Thus, is a fixed point for base for all .
The table below gives the number base (in decimal) and the fixed points (in the number base) for every .
1 | 2 | 3 | 4 | |
---|---|---|---|---|
1 | 3, 12, 22 | 5, 23, 33 | 7, 34, 44 | 9, 45, 55 |
2 | 7, 13, 63 | 12, 25, A5 | 17, 37, E7 | 22, 49, I9 |
3 | 13, 14, C4 | 23, 27, L7 | 33, 3A, UA | 43, 4D, [39]D |
4 | 21, 15, K5 | 38, 29, [36]9 | 55, 3D, [52]D | 72, 4H, [68]H |
Base b = Tk + 2 + (k2 + 4)m
Let be positive integers and the number base , where the triangular number . Then:
- is a fixed point for base for all .
Let the digits of be and . Then
Thus, is a fixed point for base for all .
- is a fixed point for base for all .
Let the digits of be and . Then
Thus, is a fixed point for base for all .
The table below gives the number base (in decimal) and the fixed points (in the number base) for every .
1 | 2 | 3 | 4 | |
---|---|---|---|---|
1 | 3, 22, 12 | 5, 23, 33 | 8, 24, 64 | 12, 25, A5 |
2 | 8, 64, 24 | 13, 67, 77 | 21, 6A, FA | 32, 6D, QD |
3 | 13, A6, 36 | 21, AB, BB | 34, AG, OG | 52, AL, [42]L |
4 | 18, E8, 48 | 29, EF, FF | 57, EM, XM | 72, ET, [58]T |
One-digit periodic points with prime period of 2
In base , given a one-digit periodic point with prime period 2 , is a two-digit periodic point with prime period 2 with natural number digits . The numbers have to satisfy the system of quadratic Diophantine equations
Base b = k3
Let be a positive integer greater than , and the number base . Then and are periodic points with a prime period of 2, generating a cycle .
Let and . Then
Thus, and with a prime period of 2 for base .
2 | 8 | 4 | 20 |
3 | 27 | 9 | 30 |
4 | 64 | G | 40 |
5 | 125 | P | 50 |
Base b = k3 + 2k
Let be a positive integer and the number base . Then, and are periodic points with a prime period of 2, generating a cycle .
Let and . Then
Thus, and with a prime period of 2 for base .
1 | 3 | 2 | 11 |
2 | 12 | 5 | 21 |
3 | 33 | A | 31 |
4 | 72 | H | 41 |
5 | 135 | P | 51 |
Base b = 4k3 - 1
Let be a positive integer and the number base . Then, and are periodic points with a prime period of 2, generating a cycle .
Let and . Then
Thus, and with a prime period of 2 for base .
1 | 3 | 2 | 11 |
2 | 31 | 8 | 22 |
3 | 107 | I | 33 |
4 | 255 | W | 44 |
Base b = 4k3 + 8k2 + 8k3 + 3
Let be a positive integer and the number base . Then, and are periodic points with a prime period of 2, generating a cycle .
Let and . Then
Thus, and with a prime period of 2 for base .
1 | 23 | 5 | 12 |
2 | 83 | D | 23 |
3 | 207 | P | 34 |
4 | 419 | [41] | 45 |
Specific bases
Base 2
In base 2, the process of defining numbers reduces down to digit sum iteration, as and , and iterated digit sums always reduces down to 1, making base 2 a happy base.
Base 4
It has been proven above that in base one only needs to check numbers for cycles and fixed points, as all numbers above will eventually fall below . In base 4, that upper limit is . The following sequences lead to the fixed point 1:
- 3 → 21 → 11 → 2 → 10 → 1
- 23 → 31 → 22 → 20 → 10 → 1
- 33 → 102 → 11 → 2 → 10 → 1
With rearrangements and/or insertions of zero digits, this shows that every number in the interval [1, 102] is happy. As a result, every number in base 4 is happy, and base 4 is a happy base.
Base 6
It has been proven above that in base one only needs to check numbers for cycles and fixed points, as all numbers above will eventually fall below . In base 6, that upper limit is . An exhaustive search then shows that every number in the interval [1, 122] eventually reaches either the eight-number cycle
- 5 → 41 → 25 → 45 → 105 → 42 → 32 → 21 → 5
and is unhappy or the trivial fixed point 1 and is happy. Because base 6 has no other fixed points except for 1, no positive integer other than 1 is the sum of the squares of its own digits.
In base 6, the 7 happy numbers up to 1000 are:
- 1, 10, 100, 112, 121, 211, 1000
The distinct combinations of digits that form happy numbers below 10000 are (the rest are just rearrangements and/or insertions of zero digits):
- 1, 112, 1135, 1335, 2555
Base 10
It has been proven above that in base one only needs to check numbers for cycles and fixed points, as all numbers above will eventually fall below . In base 10, that upper limit is . An exhaustive search then shows that every number in the interval [1, 162] eventually reaches either the eight-number cycle
- 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4 → ...
and is unhappy or the trivial fixed point 1 and is happy. Because base 10 has no other fixed points except for 1, no positive integer other than 1 is the sum of the squares of its own digits.
All numbers of the form 10n + 3 or 10n + 9 for n greater than 0 are happy. To see this, note that
- All such numbers will have at least two digits.
- The first digit will always be 1 due to the 10n.
- The last digit will always be either 3 or 9.
- Any other digits will always be 0 (and therefore will not contribute to the sum of squares of the digits).
- The sequence for numbers ending in 3 is: 12 + 32 = 10 → 12 = 1.
- The sequence for numbers ending in 9 is: 12 + 92 = 82 → 82 + 22 = 64 + 4 = 68 → 62 + 82 = 36 + 64 = 100 → 1.
In base 10, the 143 happy numbers up to 1000 are:
- 1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100, 103, 109, 129, 130, 133, 139, 167, 176, 188, 190, 192, 193, 203, 208, 219, 226, 230, 236, 239, 262, 263, 280, 291, 293, 301, 302, 310, 313, 319, 320, 326, 329, 331, 338, 356, 362, 365, 367, 368, 376, 379, 383, 386, 391, 392, 397, 404, 409, 440, 446, 464, 469, 478, 487, 490, 496, 536, 556, 563, 565, 566, 608, 617, 622, 623, 632, 635, 637, 638, 644, 649, 653, 655, 656, 665, 671, 673, 680, 683, 694, 700, 709, 716, 736, 739, 748, 761, 763, 784, 790, 793, 802, 806, 818, 820, 833, 836, 847, 860, 863, 874, 881, 888, 899, 901, 904, 907, 910, 912, 913, 921, 923, 931, 932, 937, 940, 946, 964, 970, 973, 989, 998, 1000 (sequence A007770 in the OEIS).
The distinct combinations of digits that form happy numbers below 1000 are (the rest are just rearrangements and/or insertions of zero digits):
- 1, 7, 13, 19, 23, 28, 44, 49, 68, 79, 129, 133, 139, 167, 188, 226, 236, 239, 338, 356, 367, 368, 379, 446, 469, 478, 556, 566, 888, 899. (sequence A124095 in the OEIS).
The first pair of consecutive happy numbers is 31 and 32.[4] The first set of three consecutive is 1880, 1881, and 1882.[5] It has been proved that there exist sequences of consecutive happy numbers of any natural-number length.[6] The beginning of the first run of at least n consecutive happy numbers for n = 1, 2, 3, ... is[7]
- 1, 31, 1880, 7839, 44488, 7899999999999959999999996, 7899999999999959999999996, ...
By inspection of the first million or so happy numbers, it appears that they have a natural density of around 0.15. Perhaps surprisingly, then, the happy numbers do not have an asymptotic density. The upper density of the happy numbers is greater than 0.18577, and the lower density is less than 0.1138.[8]
The number of happy numbers up to 10n for 1 ≤n ≤ 20 is[9]
- 3, 20, 143, 1442, 14377, 143071, 1418854, 14255667, 145674808, 1492609148, 15091199357, 149121303586, 1443278000870, 13770853279685, 130660965862333, 1245219117260664, 12024696404768025, 118226055080025491, 1183229962059381238, 12005034444292997294.
Happy prime
A happy prime is a number that is both happy and prime. Unlike happy numbers, rearranging the digits of a happy prime will not necessarily create another happy prime. For instance, in base 10, while 19 is a happy prime, 91 = 13 × 7 is not prime (but is still happy).
Base 2 and Base 4
As base 2 and base 4 are happy bases, all prime numbers are happy primes.
Base 6
In base 6, the happy primes below 10000 are
- 211, 1021, 1335, 2011, 2555, 3351, 5255, and 5525
Base 10
In base 10, the happy primes below 500 are
- 7, 13, 19, 23, 31, 79, 97, 103, 109, 139, 167, 193, 239, 263, 293, 313, 331, 367, 379, 383, 397, 409, 487 (sequence A035497 in the OEIS).
The palindromic prime 10150006 + 7426247×1075000 + 1 is a happy prime with 150007 digits because the many 0s do not contribute to the sum of squared digits, and 12 + 72 + 42 + 22 + 62 + 22 + 42 + 72 + 12 = 176, which is a happy number. Paul Jobling discovered the prime in 2005.[10]
As of 2010[update], the largest known happy prime is 242643801 − 1 (a Mersenne prime).[dubious – discuss] Its decimal expansion has 12837064 digits.[11]
Higher powers
A variation to the happy numbers problem is to find the sum of the digits raised to the -th power rather than the sum of the squares of the digits.
let be a natural number. The number of digits in can be found by
- ,
where is the number base. The digits of can be found as follows:
and
where .
We define the modified happy function in base to be the following:
- .
A number is happy in base if and unhappy otherwise, where represents the -th iteration of .
All natural numbers are preperiodic points for the happy function, regardless of the base. This is because if , , so any will satisfy until . There are a finite number of natural numbers less than , so the number is guaranteed to reach a periodic point or a fixed point less than , making it a preperiodic point.
Numbers in base lead to fixed or periodic points of numbers .
If , then the bound can be reduced. Let be the number for which the sum of squares of digits is largest among the numbers less than .
- because
Let be the number for which the sum of squares of digits is largest among the numbers less than .
- because
Let be the number for which the sum of squares of digits is largest among the numbers less than .
Let be the number for which the sum of squares of digits is largest among the numbers less than .
. Thus, numbers in base lead to cycles or fixed points of numbers .
For higher powers, the density of happy numbers declines.
Specific powers
p = 1
When , the sequence iteration reduces down to the digit sum. The only fixed points are the single-digit numbers in base , and there are no periodic points with prime period greater than 1. A number is happy in base if . In base 2, all numbers are happy.
Standard/Squares (p = 2)
Base | Nontrivial Fixed Points | Cycles | Comments |
---|---|---|---|
2 |
| ||
3 | 12, 22 | 2 → 11 → 2 |
|
4 |
| ||
5 | 23, 33 | 4 → 31 → 20 → 4 | |
6 | 5 → 41 → 25 → 45 → 105 → 42 → 32 → 21 → 5 | ||
7 | 13, 34, 44, 63 | 2 → 4 → 22 → 11 → 2 | |
8 | 24, 64 |
4 → 20 → 4 5 → 31 → 12 → 5 15 → 32 → 15 |
|
9 | 45, 55 | 58 → 108 → 72 → 58 | |
10 | 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4 | ||
12 | 25, A5 |
5 → 21 → 5 8 → 54 → 35 → 2A → 88 → A8 → 118 → 56 → 51 → 22 → 8 18 → 55 → 42 → 18 68 → 84 → 68 |
|
14 | 5 → 1B → 8A → BA → 11B → 8B → D3 → CA → 136 → 34 → 5
29 → 85 → 61 → 29 |
||
16 | D → A9 → B5 → 92 → 55 → 32 → D |
Cubes (p = 3)
Base | Nontrivial Fixed Points | Cycles | Comments |
---|---|---|---|
2 |
| ||
3 |
| ||
4 |
| ||
6 |
|
| |
10 |
|
p = 4
Base | Nontrivial Fixed Points | Cycles | Comments |
---|---|---|---|
2 |
| ||
3 |
121 → 200 → 121 122 → 1020 → 122 |
| |
4 | 3 → 1101 → 3 | ||
6 |
214 → 1133 → 432 → 1345 → 4243 → 2345 → 4310 → 1322 → 310 → 214 3 → 213 → 242 → 1200 → 25 → 2545 → 11014 → 1111 → 4 → 1104 → 1110 → 3 5350 → 10055 → 5443 → 5350 |
| |
10 |
2178 → 6514 → 2178 1138 → 4179 → 9219 → 13139 → 6725 → 4338 → 4514 → 1138 |
|
p = 5
Base | Nontrivial Fixed Points | Cycles | Comments |
---|---|---|---|
2 |
| ||
3 |
| ||
4 |
3 → 3303 → 23121 → 10311 → 3312 → 20013 → 10110 → 3 3311 → 13220 → 10310 → 3311 |
|
Specific bases
Base 2
In base 2, the process of defining numbers reduces down to digit sum iteration, as and , and iterated digit sums always reduces down to 1, making base 2 a happy base.
Balanced ternary
In balanced ternary, the digits are 1, −1 and 0. This results in the following:
- With even powers , the happiness (or sadness) of a number is an indication also of being odd (or even). Specifically, because 3 − 1 = 2, the sum of every digit of a base-3 number will indicate divisibility by 2 if and only if the sum of digits ends in 0 or 2. As and , for every pair of digits 1 or −1, their sum is 0 and the sum of their squares is 2. If there are an even number of {1, −1} sets, the number is sad and if there are an odd number, the number is happy. In this case, the result always end in a one-digit cycle of 0, 1 or 2, repeated infinitely.[citation needed]
- With odd powers , the process of defining numbers reduces down to digit sum iteration, as , and .
Base-power congruence relations
Given a base , if is a prime divisor of , and the power , then all happy numbers in base must satisfy the congruence relation . [12] For example, all happy numbers in base 3 when summing up powers of their digits must be odd, and all happy numbers in base 4 and base 10 when summing up odd powers (e.g. cubes, fifth powers, seventh powers, etc.) of their digits must have a remainder of 1 when dividing by 3.
Generalising to arbitrary functions
Let be a natural number. The number of digits in can be found by
- ,
where is the number base. The digits of can be found as follows:
and
where .
Given an arbitrary function , we define the modified happy function in base to be the following:
- .
A number is happy in base if and unhappy otherwise, where represents the -th iteration of .
An example of such a function is the factorial , where in base 10, there exist fixed points 1, 2, 145 and 40585 and cycles:
- 169 → 363601 → 1454 → 169.
- 4 → 24 → 26 → 722 → 5044 → 168 → 41041 → 51 → 121 → 4
In base 4, the fixed points are 1, 2, and 13, while the only cycle is:
- 3 → 12
However, only 0 and 1 are happy, regardless of the base.
Programming example
The examples below apply the 'happy' process described in the definition of happy given at the top of this article, repeatedly; after each time, they check for both halt conditions: reaching 1, and repeating a number. Everything else is bookkeeping (for example, the Python example precomputes the squares of all 10 digits).
A simple test in Python to check if a number is happy:[13]
def square(x):
return int(x) * int(x)
def happy(number):
return sum(map(square, list(str(number))))
def is_happy(number):
seen_numbers = set()
while number > 1 and (number not in seen_numbers):
seen_numbers.add(number)
number = happy(number)
return number == 1
When the algorithm ends in a cycle of repeating numbers, this cycle always includes the number 4, so it is not even necessary to store previous numbers in the sequence:
def is_happy(n):
return (n == 1 or n > 4 and is_happy(happy(n)))
See also
References
- ^ "Sad Number". Wolfram Research, Inc. Retrieved 16 September 2009.
- ^ Gilmer, Justin (2011). "On the Density of Happy Numbers". Integers. 13 (2). arXiv:1110.3836. Bibcode:2011arXiv1110.3836G.
- ^ Sloane, N. J. A. (ed.). "Sequence A161872 (Smallest unhappy number in base n)". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.
- ^ Sloane, N. J. A. (ed.). "Sequence A035502 (Lower of pair of consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation. Retrieved 8 April 2011.
- ^ Sloane, N. J. A. (ed.). "Sequence A072494 (First of triples of consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation. Retrieved 8 April 2011.
- ^ Pan, Hao (2006). "Consecutive Happy Numbers". arXiv:math/0607213.
- ^ Sloane, N. J. A. (ed.). "Sequence A055629 (Beginning of first run of at least n consecutive happy numbers)". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.
- ^ Gilmer, Justin (2011). "On the Density of Happy Numbers". Integers. 13 (2). arXiv:1110.3836. Bibcode:2011arXiv1110.3836G.
- ^ Sloane, N. J. A. (ed.). "Sequence A068571 (Number of happy numbers <= 10^n)". The On-Line Encyclopedia of Integer Sequences. OEIS Foundation.
- ^ Chris K. Caldwell. "The Prime Database: 10150006 + 7426247 · 1075000 + 1". utm.edu.
- ^ Chris K. Caldwell. "The Prime Database: 242643801 − 1". utm.edu.
{{cite web}}
: no-break space character in|title=
at position 41 (help) - ^ Pan, Hao (2006). "Consecutive Happy Numbers". arXiv:math/0607213.
- ^ Happy Number Rosetta Code
Literature
- Guy, Richard (2004). Unsolved Problems in Number Theory (3rd ed.). Springer-Verlag. ISBN 0-387-20860-7.
{{cite book}}
: Invalid|ref=harv
(help)
External links
- Schneider, Walter: Mathews: Happy Numbers.
- Weisstein, Eric W. "Happy Number". MathWorld.
- calculate if a number is happy
- Happy Numbers at The Math Forum.
- 145 and the Melancoil at Numberphile.
- Symonds, Ria. "7 and Happy Numbers". Numberphile. Brady Haran.