# Perfect digit-to-digit invariant

In number theory, a perfect digit-to-digit invariant (PDDI) (also known as a Munchausen number[1]) is a natural number in a given number base ${\displaystyle b}$ that is equal to the sum of its digits each raised to the power of itself. For example, in base 3 (ternary) there are three: 1, 12, and 22. The term "Munchausen number" was coined by Dutch mathematician and software engineer Daan van Berkel in 2009,[2] as this evokes the story of Baron Munchausen raising himself up by his own ponytail because each digit is raised to the power of itself.[3][4]

## Definition

Let ${\displaystyle n}$ be a natural number. We define the perfect digit-to-digit invariant function for base ${\displaystyle b>1}$ ${\displaystyle F_{b}:\mathbb {N} \rightarrow \mathbb {N} }$ to be the following:

${\displaystyle F_{b}(n)=\sum _{i=0}^{k-1}{d_{i}}^{d_{i}}}$.

where ${\displaystyle k=\lfloor \log _{b}{n}\rfloor +1}$ is the number of digits in the number in base ${\displaystyle b}$ and

${\displaystyle d_{i}={\frac {n{\bmod {b^{i+1}}}-n{\bmod {b^{i}}}}{b^{i}}}}$

is the value of each digit of the number. As 00 is usually undefined, there are typically two conventions used, one where it is taken to be equal to one, and another where it is taken to be equal to zero.[5][6] A natural number ${\displaystyle n}$ is a perfect digit-to-digit invariant if it is a fixed point for ${\displaystyle F_{b}}$, which occurs if ${\displaystyle F_{b}(n)=n}$. For the first convention, ${\displaystyle 1}$ is a fixed point for all ${\displaystyle b}$, and thus is a trivial perfect digit-to-digit invariant for all ${\displaystyle b}$, and all other perfect digit-to-digit invariants are nontrivial perfect digit-to-digit invariants. For the second convention, both ${\displaystyle 0}$ and ${\displaystyle 1}$ are trivial perfect digit-to-digit invariants.

For example, the number 3435 in base ${\displaystyle b=10}$ is a perfect digit-to-digit invariant because ${\displaystyle 3^{3}+4^{4}+3^{3}+5^{5}=27+256+27+3125=3435}$.

For ${\displaystyle b=2}$, in the first convention ${\displaystyle 0^{0}=1}$, ${\displaystyle F_{b}(n)}$ is simply the number of digits ${\displaystyle k}$ in the base 2 representation, and in the second convention ${\displaystyle 0^{0}=0}$, ${\displaystyle F_{b}(n)}$ is simply the digit sum.

A natural number ${\displaystyle n}$ is a sociable digit-to-digit invariant if it is a periodic point for ${\displaystyle F_{b}}$, where ${\displaystyle F_{b}^{k}(n)=n}$ for a positive integer ${\displaystyle k}$, and forms a cycle of period ${\displaystyle k}$. A perfect digit-to-digit invariant is a sociable digit-to-digit invariant with ${\displaystyle k=1}$, and a amicable digit-to-digit invariant is a sociable digit-to-digit invariant with ${\displaystyle k=2}$.

All natural numbers ${\displaystyle n}$ are preperiodic points for ${\displaystyle F_{b}}$, regardless of the base. This is because all natural numbers of base ${\displaystyle b}$ with ${\displaystyle k}$ digits satisfy ${\displaystyle b^{k-1}\leq n\leq (k){(b-1)}^{b-1}}$. However, when ${\displaystyle k\geq b+1}$, then ${\displaystyle b^{k-1}>(k){(b-1)}^{b-1}}$, so any ${\displaystyle n}$ will satisfy ${\displaystyle n>F_{b}(n)}$ until ${\displaystyle n. There are a finite number of natural numbers less than ${\displaystyle b^{b+1}}$, so the number is guaranteed to reach a periodic point or a fixed point less than ${\displaystyle b^{b+1}}$, making it a preperiodic point. This means also that there are a finite number of perfect digit-to-digit invariant and cycles for any given base ${\displaystyle b}$.

The number of iterations ${\displaystyle i}$ needed for ${\displaystyle F_{b}^{i}(n)}$ to reach a fixed point is the ${\displaystyle b}$-factorion function's persistence of ${\displaystyle n}$, and undefined if it never reaches a fixed point.

## Perfect digit-to-digit invariants and cycles of ${\displaystyle F_{b}}$ for specific ${\displaystyle b}$

All numbers are represented in base ${\displaystyle b}$.

### Convention ${\displaystyle 0^{0}=1}$

Base Nontrivial perfect digit-to-digit invariants (${\displaystyle n\neq 1}$) Cycles
2 10 ${\displaystyle \varnothing }$
3 12, 22 2 → 11 → 2
4 131, 313 2 → 10 → 2
5 ${\displaystyle \varnothing }$

2 → 4 → 2011 → 12 → 10 → 2

104 → 2013 → 113 → 104

6 22352, 23452

4 → 1104 → 1111 → 4

23445 → 24552 → 50054 → 50044 → 24503 → 23445

7 13454 12066 → 536031 → 265204 → 265623 → 551155 → 51310 → 12125 → 12066
8 405 → 6466 → 421700 → 3110776 → 6354114 → 142222 → 421 → 405
9 31, 156262, 1656547
10 3435
11
12 3A67A54832

### Convention ${\displaystyle 0^{0}=0}$

Base Nontrivial perfect digit-to-digit invariants (${\displaystyle n\neq 0}$, ${\displaystyle n\neq 1}$)[1] Cycles
2 ${\displaystyle \varnothing }$ ${\displaystyle \varnothing }$
3 12, 22 2 → 11 → 2
4 130, 131, 313 ${\displaystyle \varnothing }$
5 103, 2024

2 → 4 → 2011 → 11 → 2

9 → 2012 → 9

6 22352, 23452

5 → 22245 → 23413 → 1243 → 1200 → 5

53 → 22332 → 150 → 22250 → 22305 → 22344 → 2311 → 53

7 13454
8 400, 401
9 30, 31, 156262, 1647063, 1656547, 34664084
10 3435, 438579088
11 ${\displaystyle \varnothing }$ ${\displaystyle \varnothing }$
12 3A67A54832

## Programming examples

The examples below implements the perfect digit-to-digit invariant function described in the definition above to search for perfect digit-to-digit invariants and cycles in Python for the two conventions.

### Convention ${\displaystyle 0^{0}=1}$

def pddif(x, b):
total = 0
while x > 0:
total = total + pow(x % b, x % b)
x = x // b

def pddif_cycle(x, b):
seen = []
while x not in seen:
seen.append(x)
x = pddif(x, b)
cycle = []
while x not in cycle:
cycle.append(x)
x = pddif(x, b)
return cycle


### Convention ${\displaystyle 0^{0}=0}$

def pddif(x, b):
total = 0
while x > 0:
if x % b > 0:
total = total + pow(x % b, x % b)
x = x // b

def pddif_cycle(x, b):
seen = []
while x not in seen:
seen.append(x)
x = pdif(x, b)
cycle = []
while x not in cycle:
cycle.append(x)
x = pdif(x, b)
return cycle