Calculating a Factorial Base Representation

2.2k Views Asked by At

My friend thought of a system in which each number $n$ (I will first restrict my question to positive integers $n$) is represented by a digit string $(d_l,...,d_1)$ as follows $\forall n \in \mathbb{N}, \exists l \in \mathbb{N}: n = (d_l, d_{l-1}, ..., d_2, d_1) = \sum_{i=1}^l (d_i*(i!))$ where $\forall i \in \mathbb{N}, d_i \in \mathbb{N}: d_i \leq i$ and specifically $\forall i>l, d_i = 0$ ; note that each integer $d_i$ would be represented in decimal with at least 1 digit (in general, these factorial digits can be quite long in decimal representation)- but this is not an issue at the moment [because his system uses a finite alphabet via balanced quinary for each $d_i$].

[In this post, any number shown is in decimal.]

For example, $$1729=2*6! + 2*5! + 2*4! + 1=(2,2,2,0,0,1)$$ and $$1729^3 = (10*12!+9*11!+5*10!+3*9!+6*8!) + 1729 = (10, 9, 5, 3, 6, 0,2,2,2,0,0,1)$$.

My question is: how would this digit string $(d_l,...,d_1)$ be computed most efficiently for general positive integer n? I have mostly just been trying to guess at the largest $l \in \mathbb{N}: l*(l!) \leq n, (l+1)! > n$ and then (once I have found it), I just go through digit-by-digit, working my way down in values of candidate $d_i$ (mostly by squeeze theorem with the goal of finding out that $d_i + 1$ is too large first and then next testing $d_i$ and finding that it works). This process can be quite arduous. What would you recommend doing, algorithmically and efficiently? Bragging rights for Mathematica code that automates the process.

(Using Stirling's formula might be helpful, but it still requires a lot of playing around.)

What modifications would need to be made for general real numbers (including nonintegers)? After the radix point, it works similarly, but with $(i!)^{-1}$ (where, I think, $d_i<i \forall i \in \mathbb{N}$ and where the first such base is $\frac{1}{2!}$).

More generally and philosophically, are there any spiritual problems with this representation? It is meant to be rather compact and alien. What are some cool properties that it exhibits?

1

There are 1 best solutions below

5
On

Use the standard base conversion algorithm, using the fact that the digit weights are not powers of a base but factorials:

$$d_1=n \text{ mod }2, n_1= n \text{ div } 2,$$ $$d_2=n_1 \text{ mod }3, n_2= n_1 \text{ div } 3,$$ $$d_3=n_2 \text{ mod }4, n_3= n_2 \text{ div } 4$$ $$...$$

This is just an inversion of the "Horner" form $n = d_1 + 2(d_2+3(d_3+4(d_4...+ld_l)))$. In the standard case, the increasing integers would be replaced by the base.

w= 2
while N != 0:
    print N % w,
    N/= w
    w+= 1