This project explores a novel method for encoding integers using a representation based on the golden ratio (
It's conjectured the binary sequence 101
never occurs in this representation. This has been experimentally verified on millions of values.
You can run the available tests on this function by cloning this repository, installing the required dependencies and running:
$ python test.py
Here's what it looks like:
Original Integer irradix Representation Interpreted as Binary isPrime Prime Comparison Binary Expansion (%)
------------------------------------------------------------------------------------------------------------------------------------
1 1 1 False 0 100.00
2 10 2 True 3 100.00
3 11 3 True 3 100.00
4 100 4 False 0 100.00
5 110 6 False 2 100.00
6 111 7 True 1 100.00
7 1000 8 False 2 133.33
8 1001 9 False 0 100.00
The golden ratio
Encoding integers using base
This suggests that base
This section provides a detailed explanation of the conversion algorithms used in the irradix
and derradix
functions, including their mathematical foundations. Both algorithms revolve around the idea of encoding and decoding integers using a base
The irradix
function converts a positive integer
The result,
The derradix
function performs the inverse operation, converting a base
In this equation,
As discussed earlier, in the derradix
function, we must apply the ceiling operation iteratively at each step of the summation:
This corresponds to the code, where the ceiling is applied after each multiplication by
-
Sign Handling: The above algorithms omit sign handling for clarity. In practice, if the original integer is negative, the algorithm first converts it to a positive number, performs the conversion, and then adds a negative sign to the final result.
-
Termination Conditions in
irradix
:-
$(\text{thresh})$ : A small threshold value that stops the loop once the magnitude of$( w_0 )$ is sufficiently small. -
$(\text{quanta})$ : Represents a precision level, ensuring that the algorithm's results are accurate. -
$(\epsilon)$ : A small value related to the precision of floating-point arithmetic, ensuring that the loop halts when further iterations no longer contribute meaningful digits.
-
We analyzed the first 1,000 integers encoded using the base
Interestingly, when we mapped the first 1,000 integers through the base
This anomaly indicates that the base
From a statistical number theory perspective, the observed increase in prime density could be an artifact of how base
One of the key applications of the base
The practical efficiency of this packing method lies in its ability to represent multiple integers in a compressed format, using the inherent properties of the base
It is noteworthy that the sequence "101" corresponds to the binary representation of the number 5. In the context of base
Given the expansion factor of approximately 1.44 in base
However, the observed prime density in the binary set is significantly higher, around 9.5%. This discrepancy suggests that the base
The first and last few lines of the data table:
Original Integer irradix Representation Interpreted as Binary isPrime Prime Comparison Binary Expansion (%)
------------------------------------------------------------------------------------------------------------------------------------
1 1 1 False 0 100.00
2 10 2 True 3 100.00
3 11 3 True 3 100.00
4 100 4 False 0 100.00
5 110 6 False 2 100.00
6 111 7 True 1 100.00
7 1000 8 False 2 133.33
8 1001 9 False 0 100.00
...
988 10000000000100 8196 False 0 140.00
989 10000000000110 8198 False 0 140.00
990 10000000000111 8199 False 0 140.00
991 10000000010000 8208 False 2 140.00
992 10000000010010 8210 False 0 140.00
993 10000000010011 8211 False 0 140.00
994 10000000011000 8216 False 0 140.00
995 10000000011001 8217 False 0 140.00
996 10000000011100 8220 False 0 140.00
997 10000000011110 8222 False 2 140.00
998 10000000011111 8223 False 0 140.00
999 10000001000000 8256 False 0 140.00
1000 10000001000010 8258 False 0 140.00
Prime Density:
Original: 16.80%
Interpret base-phi rep as binary: 9.40%
Prime Comparison Key:
3: Both Original and Binary Interpretations are Prime
2: Original is Prime, Binary Interpretation is Not
1: Binary Interpretation is Prime, Original is Not
0: Neither Original nor Binary Interpretation is Prime
This unexpected increase in prime density raises intriguing questions about the nature of the base
The exploration of base
The Python API provided here leverages the mathematical properties of the golden ratio
-
irradix(num)
: Converts a given integer into its base$\phi$ representation. This function handles the decomposition of the number into coefficients that correspond to powers of$\phi$ , returning a string that represents the number in base$\phi$ . -
derradix(rep)
: Decodes a base$\phi$ encoded string back into the original integer. It reconstructs the number by summing the products of the coefficients and powers of$\phi$ , with a ceiling operation applied at each step to ensure accuracy. -
encode(nums)
: Packs a list of arbitrarily-sized integers using the base$\phi$ encoding scheme. This function concatenates the encoded integers, handles padding, and converts the final sequence into an array of bytes. -
decode(chunks)
: Unpacks a sequence of encoded integers from an input of bytes, by reconstructing the original sequence, and decoding it back into the list of integers.