Perfect digital invariant

From HandWiki
Revision as of 21:31, 6 March 2023 by AnLinks (talk | contribs) (fix)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

In number theory, a perfect digital invariant (PDI) is a number in a given number base ([math]\displaystyle{ b }[/math]) that is the sum of its own digits each raised to a given power ([math]\displaystyle{ p }[/math]).[1][2]

Definition

Let [math]\displaystyle{ n }[/math] be a natural number. The perfect digital invariant function (also known as a happy function, from happy numbers) for base [math]\displaystyle{ b \gt 1 }[/math] and power [math]\displaystyle{ p \gt 0 }[/math] [math]\displaystyle{ F_{p, b} : \mathbb{N} \rightarrow \mathbb{N} }[/math] is defined as:

[math]\displaystyle{ F_{p, b}(n) = \sum_{i=0}^{k - 1} d_i^p. }[/math]

where [math]\displaystyle{ k = \lfloor \log_{b}{n} \rfloor + 1 }[/math] is the number of digits in the number in base [math]\displaystyle{ b }[/math], and

[math]\displaystyle{ d_i = \frac{n \bmod{b^{i+1}} - n \bmod b^i}{b^i} }[/math]

is the value of each digit of the number. A natural number [math]\displaystyle{ n }[/math] is a perfect digital invariant if it is a fixed point for [math]\displaystyle{ F_{p, b} }[/math], which occurs if [math]\displaystyle{ F_{p, b}(n) = n }[/math]. [math]\displaystyle{ 0 }[/math] and [math]\displaystyle{ 1 }[/math] are trivial perfect digital invariants for all [math]\displaystyle{ b }[/math] and [math]\displaystyle{ p }[/math], all other perfect digital invariants are nontrivial perfect digital invariants.

For example, the number 4150 in base [math]\displaystyle{ b = 10 }[/math] is a perfect digital invariant with [math]\displaystyle{ p = 5 }[/math], because [math]\displaystyle{ 4150 = 4^5 + 1^5 + 5^5 + 0^5 }[/math].

A natural number [math]\displaystyle{ n }[/math] is a sociable digital invariant if it is a periodic point for [math]\displaystyle{ F_{p, b} }[/math], where [math]\displaystyle{ F_{p,b}^k(n) = n }[/math] for a positive integer [math]\displaystyle{ k }[/math] (here [math]\displaystyle{ F_{p,b}^k }[/math] is the [math]\displaystyle{ k }[/math]th iterate of [math]\displaystyle{ F_{p,b} }[/math]), and forms a cycle of period [math]\displaystyle{ k }[/math]. A perfect digital invariant is a sociable digital invariant with [math]\displaystyle{ k = 1 }[/math], and a amicable digital invariant is a sociable digital invariant with [math]\displaystyle{ k = 2 }[/math].

All natural numbers [math]\displaystyle{ n }[/math] are preperiodic points for [math]\displaystyle{ F_{p, b} }[/math], regardless of the base. This is because if [math]\displaystyle{ k \geq p + 2 }[/math], [math]\displaystyle{ n \geq b^{k-1} \gt b^p k }[/math], so any [math]\displaystyle{ n }[/math] will satisfy [math]\displaystyle{ n \gt F_{b,p}(n) }[/math] until [math]\displaystyle{ n \lt b^{p+1} }[/math]. There are a finite number of natural numbers less than [math]\displaystyle{ b^{p+1} }[/math], so the number is guaranteed to reach a periodic point or a fixed point less than [math]\displaystyle{ b^{p+1} }[/math], making it a preperiodic point.

Numbers in base [math]\displaystyle{ b \gt p }[/math] lead to fixed or periodic points of numbers [math]\displaystyle{ n \leq (p - 2)^p + p (b - 1)^p }[/math].

The number of iterations [math]\displaystyle{ i }[/math] needed for [math]\displaystyle{ F_{p,b}^{i}(n) }[/math] to reach a fixed point is the perfect digital invariant function's persistence of [math]\displaystyle{ n }[/math], and undefined if it never reaches a fixed point.

[math]\displaystyle{ F_{1, b} }[/math] is the digit sum. The only perfect digital invariants are the single-digit numbers in base [math]\displaystyle{ b }[/math], and there are no periodic points with prime period greater than 1.

[math]\displaystyle{ F_{p, 2} }[/math] reduces to [math]\displaystyle{ F_{1, 2} }[/math], as for any power [math]\displaystyle{ p }[/math], [math]\displaystyle{ 0^p = 0 }[/math] and [math]\displaystyle{ 1^p = 1 }[/math].

For every natural number [math]\displaystyle{ k \gt 1 }[/math], if [math]\displaystyle{ p \lt b }[/math], [math]\displaystyle{ (b - 1) \equiv 0 \bmod k }[/math] and [math]\displaystyle{ (p - 1) \equiv 0 \bmod \phi(k) }[/math], then for every natural number [math]\displaystyle{ n }[/math], if [math]\displaystyle{ n \equiv m \bmod k }[/math], then [math]\displaystyle{ F_{p, b}(n) \equiv m \bmod k }[/math], where [math]\displaystyle{ \phi(k) }[/math] is Euler's totient function.

No upper bound can be determined for the size of perfect digital invariants in a given base and arbitrary power, and it is not currently known whether or not the number of perfect digital invariants for an arbitrary base is finite or infinite.[1]

F2,b

By definition, any three-digit perfect digital invariant [math]\displaystyle{ n = d_2 d_1 d_0 }[/math] for [math]\displaystyle{ F_{2, b} }[/math] with natural number digits [math]\displaystyle{ 0 \leq d_0 \lt b }[/math], [math]\displaystyle{ 0 \leq d_1 \lt b }[/math], [math]\displaystyle{ 0 \leq d_2 \lt b }[/math] has to satisfy the cubic Diophantine equation [math]\displaystyle{ d_0^2 + d_1^2 + d_2^2 = d_2 b^2 + d_1 b + d_0 }[/math]. [math]\displaystyle{ d_2 }[/math] has to be equal to 0 or 1 for any [math]\displaystyle{ b \gt 2 }[/math], because the maximum value [math]\displaystyle{ n }[/math] can take is [math]\displaystyle{ n = (2 - 1)^2 + 2 (b - 1)^2 = 1 + 2 (b - 1)^2 \lt 2 b^2 }[/math]. As a result, there are actually two related quadratic Diophantine equations to solve:

[math]\displaystyle{ d_0^2 + d_1^2 = d_1 b + d_0 }[/math] when [math]\displaystyle{ d_2 = 0 }[/math], and
[math]\displaystyle{ d_0^2 + d_1^2 + 1 = b^2 + d_1 b + d_0 }[/math] when [math]\displaystyle{ d_2 = 1 }[/math].

The two-digit natural number [math]\displaystyle{ n = d_1 d_0 }[/math] is a perfect digital invariant in base

[math]\displaystyle{ b = d_1 + \frac{d_0 (d_0 - 1)}{d_1}. }[/math]

This can be proven by taking the first case, where [math]\displaystyle{ d_2 = 0 }[/math], and solving for [math]\displaystyle{ b }[/math]. This means that for some values of [math]\displaystyle{ d_0 }[/math] and [math]\displaystyle{ d_1 }[/math], [math]\displaystyle{ n }[/math] is not a perfect digital invariant in any base, as [math]\displaystyle{ d_1 }[/math] is not a divisor of [math]\displaystyle{ d_0 (d_0 - 1) }[/math]. Moreover, [math]\displaystyle{ d_0 \gt 1 }[/math], because if [math]\displaystyle{ d_0 = 0 }[/math] or [math]\displaystyle{ d_0 = 1 }[/math], then [math]\displaystyle{ b = d_1 }[/math], which contradicts the earlier statement that [math]\displaystyle{ 0 \leq d_1 \lt b }[/math].

There are no three-digit perfect digital invariants for [math]\displaystyle{ F_{2, b} }[/math], which can be proven by taking the second case, where [math]\displaystyle{ d_2 = 1 }[/math], and letting [math]\displaystyle{ d_0 = b - a_0 }[/math] and [math]\displaystyle{ d_1 = b - a_1 }[/math]. Then the Diophantine equation for the three-digit perfect digital invariant becomes

[math]\displaystyle{ (b - a_0)^2 + (b - a_1)^2 + 1 = b^2 + (b - a_1) b + (b - a_0) }[/math]
[math]\displaystyle{ b^2 - 2 a_0 b + a_0^2 + b^2 - 2 a_1 b + a_1^2 + 1 = b^2 + (b - a_1) b + (b - a_0) }[/math]
[math]\displaystyle{ 2 b^2 - 2 (a_0 + a_1) b + a_0^2 + a_1^2 + 1 = b^2 + (b - a_1) b + (b - a_0) }[/math]
[math]\displaystyle{ b^2 + (b - 2 (a_0 + a_1)) b + a_0^2 + a_1^2 + 1 = b^2 + (b - a_1) b + (b - a_0) }[/math]

[math]\displaystyle{ 2 (a_0 + a_1) \gt a_1 }[/math] for all values of [math]\displaystyle{ 0 \lt a_1 \leq b }[/math]. Thus, there are no solutions to the Diophantine equation, and there are no three-digit perfect digital invariants for [math]\displaystyle{ F_{2, b} }[/math].

F3,b

There are just four numbers, after unity, which are the sums of the cubes of their digits:

[math]\displaystyle{ 153=1^3+5^3+3^3 }[/math]
[math]\displaystyle{ 370=3^3+7^3+0^3 }[/math]
[math]\displaystyle{ 371=3^3+7^3+1^3 }[/math]
[math]\displaystyle{ 407=4^3+0^3+7^3. }[/math]

These are odd facts, very suitable for puzzle columns and likely to amuse amateurs, but there is nothing in them which appeals to the mathematician. (sequence A046197 in the OEIS)

— G. H. Hardy, A Mathematician's Apology

By definition, any four-digit perfect digital invariant [math]\displaystyle{ n }[/math] for [math]\displaystyle{ F_{3, b} }[/math] with natural number digits [math]\displaystyle{ 0 \leq d_0 \lt b }[/math], [math]\displaystyle{ 0 \leq d_1 \lt b }[/math], [math]\displaystyle{ 0 \leq d_2 \lt b }[/math], [math]\displaystyle{ 0 \leq d_3 \lt b }[/math] has to satisfy the quartic Diophantine equation [math]\displaystyle{ d_0^3 + d_1^3 + d_2^3 + d_3^3 = d_3 b^3 + d_2 b^2 + d_1 b + d_0 }[/math]. [math]\displaystyle{ d_3 }[/math] has to be equal to 0, 1, 2 for any [math]\displaystyle{ b \gt 3 }[/math], because the maximum value [math]\displaystyle{ n }[/math] can take is [math]\displaystyle{ n = (3 - 2)^3 + 3 (b - 1)^3 = 1 + 3 (b - 1)^3 \lt 3 b^3 }[/math]. As a result, there are actually three related cubic Diophantine equations to solve

[math]\displaystyle{ d_0^3 + d_1^3 + d_2^3 = d_2 b^2 + d_1 b + d_0 }[/math] when [math]\displaystyle{ d_3 = 0 }[/math]
[math]\displaystyle{ d_0^3 + d_1^3 + d_2^3 + 1 = b^3 + d_2 b^2 + d_1 b + d_0 }[/math] when [math]\displaystyle{ d_3 = 1 }[/math]
[math]\displaystyle{ d_0^3 + d_1^3 + d_2^3 + 8 = 2 b^3 + d_2 b^2 + d_1 b + d_0 }[/math] when [math]\displaystyle{ d_3 = 2 }[/math]

We take the first case, where [math]\displaystyle{ d_3 = 0 }[/math].

b = 3k + 1

Let [math]\displaystyle{ k }[/math] be a positive integer and the number base [math]\displaystyle{ b = 3 k + 1 }[/math]. Then:

  • [math]\displaystyle{ n_1 = kb^2 + (2k + 1)b }[/math] is a perfect digital invariant for [math]\displaystyle{ F_{3, b} }[/math] for all [math]\displaystyle{ k }[/math].
  • [math]\displaystyle{ n_2 = kb^2 + (2k + 1)b + 1 }[/math] is a perfect digital invariant for [math]\displaystyle{ F_{3, b} }[/math] for all [math]\displaystyle{ k }[/math].
  • [math]\displaystyle{ n_3 = (k + 1)b^2 + (2k + 1) }[/math] is a perfect digital invariant for [math]\displaystyle{ F_{3, b} }[/math] for all [math]\displaystyle{ k }[/math].
Perfect digital invariants
[math]\displaystyle{ k }[/math] [math]\displaystyle{ b }[/math] [math]\displaystyle{ n_1 }[/math] [math]\displaystyle{ n_2 }[/math] [math]\displaystyle{ n_3 }[/math]
1 4 130 131 203
2 7 250 251 305
3 10 370 371 407
4 13 490 491 509
5 16 5B0 5B1 60B
6 19 6D0 6D1 70D
7 22 7F0 7F1 80F
8 25 8H0 8H1 90H
9 28 9J0 9J1 A0J

b = 3k + 2

Let [math]\displaystyle{ k }[/math] be a positive integer and the number base [math]\displaystyle{ b = 3 k + 2 }[/math]. Then:

  • [math]\displaystyle{ n_1 = kb^2 + (2k + 1) }[/math] is a perfect digital invariant for [math]\displaystyle{ F_{3, b} }[/math] for all [math]\displaystyle{ k }[/math].
Perfect digital invariants
[math]\displaystyle{ k }[/math] [math]\displaystyle{ b }[/math] [math]\displaystyle{ n_1 }[/math]
1 5 103
2 8 205
3 11 307
4 14 409
5 17 50B
6 20 60D
7 23 70F
8 26 80H
9 29 90J

b = 6k + 4

Let [math]\displaystyle{ k }[/math] be a positive integer and the number base [math]\displaystyle{ b = 6 k + 4 }[/math]. Then:

  • [math]\displaystyle{ n_4 = kb^2 + (3k + 2)b + (2k + 1) }[/math] is a perfect digital invariant for [math]\displaystyle{ F_{3, b} }[/math] for all [math]\displaystyle{ k }[/math].
Perfect digital invariants
[math]\displaystyle{ k }[/math] [math]\displaystyle{ b }[/math] [math]\displaystyle{ n_4 }[/math]
0 4 021
1 10 153
2 16 285
3 22 3B7
4 28 4E9

Fp,b

All numbers are represented in base [math]\displaystyle{ b }[/math].

[math]\displaystyle{ p }[/math] [math]\displaystyle{ b }[/math] Nontrivial perfect digital invariants Cycles
2 3 12, 22 2 → 11 → 2
4 [math]\displaystyle{ \varnothing }[/math] [math]\displaystyle{ \varnothing }[/math]
5 23, 33 4 → 31 → 20 → 4
6 [math]\displaystyle{ \varnothing }[/math] 5 → 41 → 25 → 45 → 105 → 42 → 32 → 21 → 5
7 13, 34, 44, 63 2 → 4 → 22 → 11 → 2

16 → 52 → 41 → 23 → 16

8 24, 64

4 → 20 → 4

5 → 31 → 12 → 5

15 → 32 → 15

9 45, 55

58 → 108 → 72 → 58

75 → 82 → 75

10 [math]\displaystyle{ \varnothing }[/math] 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4
11 56, 66

5 → 23 → 12 → 5

68 → 91 → 75 → 68

12 25, A5

5 → 21 → 5

8 → 54 → 35 → 2A → 88 → A8 → 118 → 56 → 51 → 22 → 8

18 → 55 → 42 → 18

68 → 84 → 68

13 14, 36, 67, 77, A6, C4 28 → 53 → 28

79 → A0 → 79

98 → B2 → 98

14 [math]\displaystyle{ \varnothing }[/math] 1B → 8A → BA → 11B → 8B → D3 → CA → 136 → 34 → 1B

29 → 61 → 29

15 78, 88 2 → 4 → 11 → 2

8 → 44 → 22 → 8

15 → 1B → 82 → 48 → 55 → 35 → 24 → 15

2B → 85 → 5E → EB → 162 → 2B

4E → E2 → D5 → CE → 17A → A0 → 6A → 91 → 57 → 4E

9A → C1 → 9A

D6 → DA → 12E → D6

16 [math]\displaystyle{ \varnothing }[/math] D → A9 → B5 → 92 → 55 → 32 → D
3 3 122 2 → 22 → 121 → 101 → 2
4 20, 21, 130, 131, 203, 223, 313, 332 [math]\displaystyle{ \varnothing }[/math]
5 103, 433 14 → 230 → 120 → 14
6 243, 514, 1055 13 → 44 → 332 → 142 → 201 → 13
7 12, 22, 250, 251, 305, 505

2 → 11 → 2

13 → 40 → 121 → 13

23 → 50 → 236 → 506 → 665 → 1424 → 254 → 401 → 122 → 23

51 → 240 → 132 → 51

160 → 430 → 160

161 → 431 → 161

466 → 1306 → 466

516 → 666 → 1614 → 552 → 516

8 134, 205, 463, 660, 661 662 → 670 → 1057 → 725 → 734 → 662
9 30, 31, 150, 151, 570, 571, 1388

38 → 658 → 1147 → 504 → 230 → 38

152 → 158 → 778 → 1571 → 572 → 578 → 1308 → 660 → 530 → 178 → 1151 → 152

638 → 1028 → 638

818 → 1358 → 818

10 153, 370, 371, 407

55 → 250 → 133 → 55

136 → 244 → 136

160 → 217 → 352 → 160

919 → 1459 → 919

11 32, 105, 307, 708, 966, A06, A64

3 → 25 → 111 → 3

9 → 603 → 201 → 9

A → 82A → 1162 → 196 → 790 → 895 → 1032 → 33 → 4A → 888 → 1177 → 576 → 5723 → A3 → 8793 → 1210 → A

25A → 940 → 661 → 364 → 25A

366 → 388 → 876 → 894 → A87 → 1437 → 366

49A → 1390 → 629 → 797 → 1077 → 575 → 49A

12 577, 668, A83, 11AA
13 490, 491, 509, B85 13 → 22 → 13
14 136, 409
15 C3A, D87
16 23, 40, 41, 156, 173, 208, 248, 285, 4A5, 580, 581, 60B, 64B, 8C0, 8C1, 99A, AA9, AC3, CA8, E69, EA0, EA1
4 3 [math]\displaystyle{ \varnothing }[/math]

121 → 200 → 121

122 → 1020 → 122

4 1103, 3303 3 → 1101 → 3
5 2124, 2403, 3134

1234 → 2404 → 4103 → 2323 → 1234

2324 → 2434 → 4414 → 11034 → 2324

3444 → 11344 → 4340 → 4333 → 3444

6 [math]\displaystyle{ \varnothing }[/math]
7 [math]\displaystyle{ \varnothing }[/math]
8 20, 21, 400, 401, 420, 421
9 432, 2466
5 3 1020, 1021, 2102, 10121 [math]\displaystyle{ \varnothing }[/math]
4 200

3 → 3303 → 23121 → 10311 → 3312 → 20013 → 10110 → 3

3311 → 13220 → 10310 → 3311

Extension to negative integers

Perfect digital invariants can be extended to the negative integers by use of a signed-digit representation to represent each integer.

Balanced ternary

In balanced ternary, the digits are 1, −1 and 0. This results in the following:

  • With odd powers [math]\displaystyle{ p \equiv 1 \bmod 2 }[/math], [math]\displaystyle{ F_{p, \text{bal}3} }[/math] reduces down to digit sum iteration, as [math]\displaystyle{ (-1)^p = -1 }[/math], [math]\displaystyle{ 0^p = 0 }[/math] and [math]\displaystyle{ 1^p = 1 }[/math].
  • With even powers [math]\displaystyle{ p \equiv 0 \bmod 2 }[/math], [math]\displaystyle{ F_{p, \text{bal}3} }[/math] indicates whether the number is even or odd, as the sum of each digit will indicate divisibility by 2 if and only if the sum of digits ends in 0. As [math]\displaystyle{ 0^p = 0 }[/math] and [math]\displaystyle{ (-1)^p = 1^p = 1 }[/math], for every pair of digits 1 or −1, their sum is 0 and the sum of their squares is 2.

Relation to happy numbers

Main page: 3

A happy number [math]\displaystyle{ n }[/math] for a given base [math]\displaystyle{ b }[/math] and a given power [math]\displaystyle{ p }[/math] is a preperiodic point for the perfect digital invariant function [math]\displaystyle{ F_{p, b} }[/math] such that the [math]\displaystyle{ m }[/math]-th iteration of [math]\displaystyle{ F_{p, b} }[/math] is equal to the trivial perfect digital invariant [math]\displaystyle{ 1 }[/math], and an unhappy number is one such that there exists no such [math]\displaystyle{ m }[/math].

Programming example

The example below implements the perfect digital invariant function described in the definition above to search for perfect digital invariants and cycles in Python. This can be used to find happy numbers.

def pdif(x: int, p: int, b: int) -> int:
    """Perfect digital invariant function."""
    total = 0
    while x > 0:
        total = total + pow(x % b, p)
        x = x // b
    return total

def pdif_cycle(x: int, p: int, b: int) -> list[int]:
    seen = []
    while x not in seen:
        seen.append(x)
        x = pdif(x, p, b)
    cycle = []
    while x not in cycle:
        cycle.append(x)
        x = pdif(x, p, b)
    return cycle

See also

References

  1. 1.0 1.1 Perfect and PluPerfect Digital Invariants by Scott Moore
  2. PDIs by Harvey Heinz

External links