In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
and computing, Fibonacci coding is a
universal code which encodes positive integers into binary
code word Code word may refer to:
* Code word (communication), an element of a standardized code or protocol
* Code word (figure of speech), designed to convey a predetermined meaning to a receptive audience, while remaining inconspicuous to others
** Proce ...
s. It is one example of representations of integers based on
Fibonacci number
In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
s. Each code word ends with "11" and contains no other instances of "11" before the end.
The Fibonacci code is closely related to the
Zeckendorf representation
In mathematics, Zeckendorf's theorem, named after Belgian amateur mathematician Edouard Zeckendorf, is a theorem about the representation of integers as sums of Fibonacci numbers.
Zeckendorf's theorem states that every positive integer can be re ...
, a positional
numeral system
A numeral system is a writing system for expressing numbers; that is, a mathematical notation for representing numbers of a given set, using digits or other symbols in a consistent manner.
The same sequence of symbols may represent differe ...
that uses
Zeckendorf's theorem
In mathematics, Zeckendorf's theorem, named after Belgian amateur mathematician Edouard Zeckendorf, is a theorem about the representation of integers as sums of Fibonacci numbers.
Zeckendorf's theorem states that every positive integer can be r ...
and has the property that no number has a representation with consecutive 1s. The Fibonacci code word for a particular integer is exactly the integer's Zeckendorf representation with the order of its digits reversed and an additional "1" appended to the end.
Definition
For a number
, if
represent the digits of the code word representing
then we have:
:
where is the th
Fibonacci number
In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
, and so is the th distinct Fibonacci number starting with
. The last bit
is always an appended bit of 1 and does not carry place value.
It can be shown that such a coding is unique, and the only occurrence of "11" in any code word is at the end (that is, ''d''(''k''−1) and ''d''(''k'')). The penultimate bit is the most significant bit and the first bit is the least significant bit. Also, leading zeros cannot be omitted as they can be in, for example, decimal numbers.
The first few Fibonacci codes are shown below, and also their so-called
''implied probability'', the value for each number that has a minimum-size code in Fibonacci coding.
To encode an integer :
# Find the largest
Fibonacci number
In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
equal to or less than '; subtract this number from ', keeping track of the remainder.
# If the number subtracted was the th Fibonacci number , put a 1 in place in the code word (counting the left most digit as place 0).
# Repeat the previous steps, substituting the remainder for ', until a remainder of 0 is reached.
# Place an additional 1 after the rightmost digit in the code word.
To decode a code word, remove the final "1", assign the remaining the values 1,2,3,5,8,13... (the
Fibonacci number
In mathematics, the Fibonacci sequence is a Integer sequence, sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many w ...
s) to the bits in the code word, and sum the values of the "1" bits.
Comparison with other universal codes
Fibonacci coding has a useful property that sometimes makes it attractive in comparison to other universal codes: it is an example of a
self-synchronizing code
In coding theory, especially in telecommunications, a self-synchronizing code is a uniquely decodable code in which the symbol stream formed by a portion of one code word, or by the overlapped portion of any two adjacent code words, is not a ...
, making it easier to recover data from a damaged stream. With most other universal codes, if a single
bit
The bit is the most basic unit of information in computing and digital communication. The name is a portmanteau of binary digit. The bit represents a logical state with one of two possible values. These values are most commonly represented as ...
is altered, then none of the data that comes after it will be correctly read. With Fibonacci coding, on the other hand, a changed bit may cause one token to be read as two, or cause two tokens to be read incorrectly as one, but reading a "0" from the stream will stop the errors from propagating further. Since the only stream that has no "0" in it is a stream of "11" tokens, the total
edit distance
In computational linguistics and computer science, edit distance is a string metric, i.e. a way of quantifying how dissimilar two String (computing), strings (e.g., words) are to one another, that is measured by counting the minimum number of opera ...
between a stream damaged by a single bit error and the original stream is at most three.
This approach, encoding using sequence of symbols, in which some patterns (like "11") are forbidden, can be freely generalized.
Example
The following table shows that the number 65 is represented in Fibonacci coding as 0100100011, since . The first two Fibonacci numbers (0 and 1) are not used, and an additional 1 is always appended.
:
Generalizations
The Fibonacci encodings for the positive integers are binary strings that end with "11" and contain no other instances of "11". This can be generalized to binary strings that end with ''N'' consecutive 1s and contain no other instances of ''N'' consecutive 1s. For instance, for ''N'' = 3 the positive integers are encoded as 111, 0111, 00111, 10111, 000111, 100111, 010111, 110111, 0000111, 1000111, 0100111, …. In this case, the number of encodings as a function of string length is given by the sequence of
tribonacci number
In mathematics, the Fibonacci numbers form a sequence defined recursively by:
:F_n =
\begin
0 & n = 0 \\
1 & n = 1 \\
F_ + F_ & n > 1
\end
That is, after two starting values, each number is the sum of the two preceding numbers.
The Fibonacci seq ...
s.
For general constraints defining which symbols are allowed after a given symbol, the maximal information rate can be obtained by first finding the optimal transition probabilities using a
maximal entropy random walk
A maximal entropy random walk (MERW) is a popular type of biased random walk on a graph, in which transition probabilities are chosen accordingly to the principle of maximum entropy, which says that the probability distribution which best repres ...
, then using an
entropy coder
In information theory, an entropy coding (or entropy encoding) is any lossless data compression method that attempts to approach the lower bound declared by Shannon's source coding theorem, which states that any lossless data compression method m ...
(with switched encoder and decoder) to encode a message as a sequence of symbols fulfilling the found optimal transition probabilities.
See also
*
Golden ratio base
Golden ratio base is a non-integer positional numeral system that uses the golden ratio (the irrational number \frac ≈ 1.61803399 symbolized by the Greek letter φ) as its base. It is sometimes referred to as base-φ, golden mean b ...
*
NegaFibonacci coding In mathematics, negafibonacci coding is a universal code which encodes nonzero integers into binary code words. It is similar to Fibonacci coding, except that it allows both positive and negative integers to be represented. All codes end with "11" ...
*
Ostrowski numeration
In mathematics, Ostrowski numeration, named after Alexander Ostrowski, is either of two related numeration systems based on continued fractions: a non-standard positional numeral system for integers and a non-integer representation of real number ...
*
Universal code
*
Varicode Varicode is a self-synchronizing code for use in PSK31. It supports all ASCII characters, but the characters used most frequently in English have shorter codes. The space between characters is indicated by a 00 sequence, an implementation of Fibona ...
, a practical application
*
Zeckendorf's theorem
In mathematics, Zeckendorf's theorem, named after Belgian amateur mathematician Edouard Zeckendorf, is a theorem about the representation of integers as sums of Fibonacci numbers.
Zeckendorf's theorem states that every positive integer can be r ...
*
Maximal entropy random walk
A maximal entropy random walk (MERW) is a popular type of biased random walk on a graph, in which transition probabilities are chosen accordingly to the principle of maximum entropy, which says that the probability distribution which best repres ...
References
*
*
Further reading
*
{{DEFAULTSORT:Fibonacci Coding
Non-standard positional numeral systems
Lossless compression algorithms
Fibonacci numbers
Data compression