On finding the smallest happy numbers of any heights
Gabriel Lapointe

TL;DR
This paper develops a recursive and algorithmic approach to identify the smallest happy numbers across different heights and bases, utilizing properties of height and modular arithmetic for efficient computation.
Contribution
It introduces a recursive relationship and an algorithm for finding smallest happy numbers of any height in various bases, including binary and ternary, based on their properties.
Findings
Derived recursive relationship between smallest happy numbers and height.
Developed an algorithm exploiting height properties for computation.
Established equations using modular arithmetic for binary and ternary bases.
Abstract
This paper focuses on finding the smallest happy number for each height in any numerical base. Using the properties of the height, we deduce a recursive relationship between the smallest happy number and the height where the initial height is function of the numerical base. With the usage of the recursive relationship, we build an algorithm that exploits the properties of the height in order to find all of those smallest happy numbers with unknown height. However, with the modular arithmetic, we conclude on an equation that calculates the smallest happy numbers based on known heights for binary and ternary bases.
| 3 | 0 | 1 | 14 | 6 | 18 |
| 4 | 1 | 3 | 15 | 6 | 19 |
| 5 | 1 | 4 | 16 | 6 | 21 |
| 6 | 2 | 6 | 17 | 7 | 22 |
| 7 | 2 | 7 | 18 | 7 | 24 |
| 8 | 3 | 9 | 19 | 7 | 25 |
| 9 | 3 | 10 | 20 | 7 | 27 |
| 10 | 5 | 12 | 21 | 8 | 28 |
| 11 | 6 | 13 | 22 | 10 | 30 |
| 12 | 4 | 15 | 23 | 10 | 31 |
| 13 | 5 | 16 | 24 | 8 | 33 |
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Taxonomy
TopicsNumerical Methods and Algorithms · Polynomial and algebraic computation · Advanced Mathematical Theories and Applications
ON FINDING THE SMALLEST HAPPY NUMBERS OF ANY HEIGHTS
GABRIEL LAPOINTE
Abstract.
This paper focuses on finding the smallest happy number for each height in any numerical base. Using the properties of the height, we deduce a recursive relationship between the smallest happy number and the height where the initial height is function of the numerical base. With the usage of the recursive relationship, we build an algorithm that exploits the properties of the height in order to find all of those smallest happy numbers with unknown height. However, with the modular arithmetic, we conclude on an equation that calculates the smallest happy numbers based on known heights for binary and ternary bases.
Key words and phrases:
Number theory, Smallest happy numbers, Height, Algorithm, Modular arithmetic
2010 Mathematics Subject Classification:
Mathematics Subject Classification 2010: 11B37, 11Y55, 11Y16, 11A07
1. Introduction
Researches have been done on smallest happy numbers mainly in decimal base for heights [math] to using the modular arithmetic as shown in theorems 2 to 4 [2] and theorem 3 [6]. Moreover, there is an algorithm that searches for the smallest happy number of an unknown height as shown in [6]. In this paper, we give and describe this algorithm usable for any numerical base . Instead of continuing to search for the smallest happy numbers for any height greater than in decimal base, we are interested on the binary and ternary bases. Small numerical bases may give hints on an equation or an efficient algorithm to obtain the smallest happy number of any height for larger numerical bases.
Let be an integer. In the numerical base , can be written as a unique sum
[TABLE]
where the positive integers are the digits of and for all . We note as a vector of its digits in base as being where we note as the length of and the digit of starting from the left for .
Definition 1.1**.**
Let be the numerical base of a positive integer . We define a function where
[TABLE]
where in base .
To simplify the notation, we note for all , where is the function composition operator. The identity is defined as .
Definition 1.2**.**
Let be the numerical base of a positive integer . We call a happy number if and only if there is such that .
Definition 1.3**.**
We define the height of a happy number in base as where
[TABLE]
Definition 1.4**.**
We define the smallest happy number in numerical base for any height by the function where
[TABLE]
To simplify the notation, we will use and . If there is ambiguity, we will precise the numerical base (e.g. ).
2. Smallest happy numbers
The objective of this section is to show that there is a relationship between subsequent heights of smallest happy numbers for all base . Then, we get a general equation for on which the algorithm will be based.
The following result shows that the function is defined uniquely for every .
Theorem 2.1**.**
For all , there is a unique such that and .
Proof.
To prove the existence, we have to show that there is a happy such that . We proceed by induction on . For , we have such that for all . Lets assume that there is a happy such that . Let such that . Thus, and is also happy. In virtue of the induction hypothesis, which proves the existence for all .
Let where . Then, let without loss of generality. Having or contradict the definition 1.4. Thus, which proves the uniqueness.
We deduce from the definition 1.4 that . ∎
We note that is the unique integer of height [math]. If , then . This ensures that is the smallest happy number of height for all .
Lemma 2.2**.**
If , then .
Proof.
By theorem 2.1, for all . We proceed by contrapositive and suppose that . Since , we have, in virtue of the lemma 6 [1], that . Applying this with our hypothesis implies that a contradiction with the theorem 2.1. Therefore, . ∎
We want to show that the smallest happy numbers are strictly increasing as their height increases starting at a certain height when . However, even if , it is generally not true. For example, using brute-force, we calculate that and . We see that . The next result ensure that is strictly increasing when for all and for the binary base.
Lemma 2.3**.**
If for all and if , then for all .
Proof.
Let’s proceed by induction on . For the base case, we have to show that . Since for all and if , we apply the lemma 2.2 and then get the result. Suppose that holds for a certain . We have to show that it also holds for .
Suppose that for all and if . In virtue of the corollary 7 [1], there is such that . It follows that which is maximal if any for all and . By induction on with the theorem 2.1, one shows that for all . Therefore, it is generally false to say that .
Suppose instead that for all and if . By the lemma 2.2, we have . Using the induction hypothesis, we get . Therefore, for all . ∎
Let be the integer part function of and be the ceiling function of . The operator in the expression denotes the concatenation of and .
Let denotes the total number of digits of , where is the number of digits lower than and the number of . We also note where is the integer containing the digits lower than and the digits . The next results give boundaries on and .
Corollary 2.4**.**
We have for all .
Proof.
Let . By definition of , we know that
[TABLE]
In virtue of the lemma 2.1 [4], . With the equation (5), it implies that and . With , we deduce that
[TABLE]
The inequation (6) is equivalent to
[TABLE]
which gives . Since , we have . Therefore,
[TABLE]
∎
Since we found the lower bound for , we can deduce an upper bound on .
Corollary 2.5**.**
We have for all .
Proof.
By definition of , we have . Applying the lemma 2.1 [4] and the corollary 2.4, we obtain
[TABLE]
∎
Now that we have found boundaries on and its number of digits, we use them in order to demonstrate a recursive relation between and starting with an initial height .
Lemma 2.6**.**
We have .
Proof.
In virtue of the theorem 2.1, we have if and only if there is such that .
By definition of the integer part function, there is a positive integer such that
[TABLE]
In virtue of the lemma 2.1 [4] and the equation (7), we have
[TABLE]
Equivalently, with the equation (7), the inequation (8) can be rewritten as
[TABLE]
After simplification of the inequation (9) we get
[TABLE]
∎
Theorem 2.7**.**
Let be the smallest height such that . If , then for all and .
Proof.
In virtue of the theorem 2.1, there is such that . The lemma 2.6 implies that . Let’s proceed by induction on and suppose that and . We want to show that is impossible in order to show that .
We know that . If , we have . This gives either , where contains only digits between and , or where contains only the digits . The second case will be taken as if . If , by the corollary 2.5, we have that
[TABLE]
Suppose now that . This means that . Since , we have that . Thus, we have that
[TABLE]
It follows from the equation (11) and the corollary 2.5 that
[TABLE]
We know that . We deduce that
[TABLE]
because to have maximal, we have to have . Combining the inequations (12) and (13) in the equation (11) gives
[TABLE]
However, which contradict the theorem 2.1 because . Therefore, we have to have .
Suppose now that for a certain . We need to show that it holds for . In virtue of the theorem 2.1, there is such that . Suppose that . Applying on both sides gives
[TABLE]
Since for all , the lemma 2.3 implies that . Therefore, we get the same contradiction as in the method used in the induction base case. Thus, and then, using the induction hypothesis, we obtain .
Therefore, for all and if . ∎
With the result given by the theorem 2.7, we deduce the recursive relation between and with the following corollary.
Corollary 2.8**.**
If , then
[TABLE]
Proof.
By definition of , we can write
[TABLE]
Applying to the equation (17) gives
[TABLE]
Since , we apply the theorem 2.7 and get
[TABLE]
if and only if
[TABLE]
Substituting the equation (20) in (17) gives the result. ∎
We conclude this section on the following questions:
- (1)
How can the initial height be expressed in function of the base ? 2. (2)
Can we get a sharper lower bound on ?
3. Algorithm evaluating with unknown
In this section, the objective is to use the corollary 2.8 in order to build two algorithms. The first one searches for the minimal for an unknown height and the second one searches for corresponding to found. We will see that evaluating the remainder of is an important computational obstacle to consider. Also, we will explain why these algorithms cannot search for based on a given .
For this section, we define a function taking the base as the input parameter. The function denotes the upper bound of iterations done in the algorithm 2. In virtue of lemma 2.1 [4], exists and is finite.
Let be the set of solutions of . The objective of the algorithm 1 is to find .
Theorem 3.1**.**
For any , the algorithm 1 terminates with any and returns for an unknown .
Proof.
If , then and the algorithm terminates and returns [math]. If and , then we get with times the -digit. This solution is trivially minimal because the other solutions, if they exist, have more than digits.
Suppose that and . We have to show that the algorithm stops when the current candidate is the minimal solution . Let with times the digit 1. Trivially, where .
By construction, the algorithm initializes and with times the digit and runs through a subset of numbers. Let be an iterator where and .
Let be a counter of iterations in the loop and be the value of at the iteration. For all , the algorithm ensures that because in every case, it either increments a digit of or increments and fix with times the digit .
Let and suppose that where at each iteration . We have to show that . We can observe three general cases:
- (1)
If , then increases by one implying that . 2. (2)
If , either the algorithm falls into the case (i) or for all . 3. (3)
If , either the algorithm falls into the case (i) or for all where because by definition of , we know that .
Therefore, for all at each iteration .
If and , then for all . The values when are ignored because the addition is commutative in and we run through in ascending order. Also, is invariant to the permutations of the digits of . Thus, the algorithm has already tested those values where up to permutation. Therefore, if is an ignored value, then . This also means that
[TABLE]
We have to show that the algorithm ends with . We have shown that for all and that each time increments, is reset to with times the digit one. We have also shown that for all . Thus, the loop either stops when or reaches its upper bound when . Therefore, the algorithm ends with .
Let . We have to show that . If , then a contradiction with . If , then which is also a contradiction with . Thus, .
Since increases, and the ignored values cannot be the minimal solution searched, the algorithm returns for any and . ∎
In order to find , we need to know . From the corollary 2.8, we deduce that there is such that . Equivalently,
[TABLE]
where .
The second objective of this section is to build an algorithm that searches for . We note the possible candidate of .
Theorem 3.2**.**
The algorithm 2 ends and returns for an unknown and for any where , and .
Proof.
Let be the iterations in the loop and an unknown height. In virtue of the theorem 2.1, we know that for all height , there is a unique positive integer such that . Thus, we have to prove that . By corollary 2.5, we have . However, we show that can be improved in order to reduce the number of iterations processed by the algorithm. It will then follow that .
By construction, the algorithm initializes , where per algorithm 1. If we remove times the digit , then using the corollary 2.8 gives
[TABLE]
Let . We apply the algorithm 1 on to output at iteration where . Since we removed times the digit , they have to be added back to by respecting the constraints . Lagrange’s theorem states that every positive integer can be written as a sum of 4 squares. This implies that where if and only if is a perfect square. In such case, .
Suppose that is not a perfect square. It follows that . Because , then the lower bound of increases of when
[TABLE]
or equivalently if
[TABLE]
Hence, once
[TABLE]
because . Thus, once which ensures that . Therefore, we deduce that
[TABLE]
and .
We have to show that the algorithm returns . If , then , where and means we remove the last digits to . Thus, we only keep the minimal solution , for iterations , and we update to ensure that is always minimal. Therefore, there is such that the algorithm returns for all . ∎
The algorithms 1 and 2 have been implemented in the C++ language. The source code is available at https://github.com/glapointe7/SmallestHappyNumbers. To test the algorithm 2, we validated our results with those of [6](page 1924) in the decimal base.
In the table 1, we compared our upper bound to the number of iterations maximal, noted , among integers in order to obtain for bases .
We conclude this section on the following questions:
- (1)
Can we improve the time complexity of the algorithms 1 and 2? 2. (2)
According to the table 1, our upper bound could be sharper. How can we get a sharper upper bound ?
4. Smallest Happy Numbers in Binary Base
In this section, the objective is to obtain an equation that calculates for all using the corollary 2.8. After computing for we get , , , and . We see that for . Moreover, the smallest height when is per theorem 2.7. Thus, we showed that for all in binary base. Therefore, we choose the initial height to fit with the corollary 4.1.
Corollary 4.1**.**
For all , we have
[TABLE]
and its inverse
[TABLE]
Proof.
For the result is obvious. For , we can apply the corollary 2.8 where because . Therefore, the equation (28) is directly obtained and then, we deduce the equation (29). ∎
Using the tetration, which is the iterated exponentiation, the equation (28) can be defined analytically. We present a new notation inspired from [3] to simplify the notations.
Definition 4.1**.**
Let and . We define the adapted Knuth’s up-arrow notation as being
[TABLE]
where is a scalar and is repeated times. The real multiplication operator is used between and . If , then .
Knowing that the initial condition is , we have
[TABLE]
If we continue with one more iteration, we get
[TABLE]
Using the induction on , we obtain the equation
[TABLE]
Recall that a Mersenne’s prime number is a prime number , where is prime. In virtue of the corollary 4.1, we note that is a possible subset of the Mersenne’s prime number set. In particular, is a Mersenne’s prime number for which are given by [5]. This leads us to the following conjecture because nowadays, we cannot tell if is a Mersenne’s prime number or not. This holds also for all .
Conjecture 1**.**
For all , is a Mersenne’s prime number.
5. Smallest Happy Numbers in Ternary Base
In this section, the objective is to find an equation that finds for all by using the relation (22). We have to calculate the remainder of and find such that
[TABLE]
By brute-force, we obtain that , and . In virtue of the theorem 2.7, the smallest height when is . We showed that for all . Then, we choose to fit with the lemma 5.1.
By definition of , the only digit that can be contained in is one in ternary base. After applying the algorithm 2 for , we found that . Let denotes the set of all possible values of in ternary base where
[TABLE]
In order to find , we calculate by using the relation (22). We find that the rest of the division of by is . Thus, and then, . Therefore,
[TABLE]
Note that for . Using induction on , we get that or . Thus,
[TABLE]
for all .
We see that for . Let’s generalize the relation (37) for all .
Lemma 5.1**.**
For all in ternary base, we have
[TABLE]
Proof.
We proceed by induction on . For , we have where with . Suppose that for a certain . We have . Using the induction hypothesis and knowing that , we deduce that is written in the same form as described by the relation (37) where . Thus, and then . In virtue of the set of possible integers in (35), we get . Therefore, which shows that the equation (38) holds for all . ∎
The equation (38) can be solved using the same method as the one we applied for the binary base in section 4. Before solving the equation (38), let’s see an example for and for in order to get an intuition on the general solution. Knowing that , we have
[TABLE]
Then, for we have
[TABLE]
Continuing with we would see the pattern repeating. However, in order to fit with this pattern, the coefficient in (5) and (5) has to be written instead.
Theorem 5.2**.**
For all , we have
[TABLE]
Proof.
We proceed by induction on . Since in ternary base, we have by definition 4.1 that . Suppose that the equation (41) is verified for a certain . In virtue of the lemma 5.1, we have
[TABLE]
We apply the induction hypothesis on the equation (42) and obtain
[TABLE]
In virtue of the definition 4.1, it follows that
[TABLE]
Therefore, the equation (41) is verified for all . ∎
We conclude this section with the following questions:
- (1)
If this method can be generalized, what would be the general equation solving the equation (16) for all and ? 2. (2)
If the method cannot be generalized, what method would solve the equation (16) for all and ?
Acknowledgments
I want to thank Maxime Toussaint, candidate to Ph.D in Computer Science at University of Sherbrooke, for his time to review this paper and his valuable advices.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] H.G. Grundman and E.A. Teeple, Generalized happy numbers Fibonacci Quart. 39 (2001), 462–466.
- 2[2] H.G. Grundman and E.A. Teeple, Heights of happy numbers and cubic happy numbers Fibonacci Quart. 41 (2003), 301–306.
- 3[3] Knuth, D. E. Mathematics and Computer Science: Coping with Finiteness. Advances in Our Ability to Compute are Bringing Us Substantially Closer to Ultimate Limitations. Science 194 (1976), 1235–1242.
- 4[4] May Mei, Andrew Read-Mc Farland Numbers and the Heights of their Happiness ar Xiv:1511.01441 v 2 (2016), 1–5.
- 5[5] N. J. A. Sloane. The On-Line Encyclopedia of Integer Sequences, http://oeis.org. Sequence A 001348.
- 6[6] Tianxin Cai and Xia Zhou On the Heights of Happy Numbers Rocky Mountain J. Math. 38 (2008), no. 6, 1921–1926.
