Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Fibonacci coding
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Universal code which encodes positive integers into binary code words}} {{more footnotes|date=January 2013}} {{numeral systems}} In [[mathematics]] and computing, '''Fibonacci coding''' is a [[universal code (data compression)|universal code]]{{citation needed|date=October 2015}} which encodes positive integers into binary [[Code word (communication)|code word]]s. It is one example of representations of integers based on [[Fibonacci number]]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]], a positional [[numeral system]] that uses [[Zeckendorf's theorem]] 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 <math>N\!</math>, if <math>d(0),d(1),\ldots,d(k-1),d(k)\!</math> represent the digits of the code word representing <math>N\!</math> then we have: : <math>N = \sum_{i=0}^{k-1} d(i) F(i+2),\text{ and }d(k-1)=d(k)=1.\!</math> where {{math|''F''(''i'')}} is the {{math|''i''}}th [[Fibonacci number]], and so {{math|''F''(''i''+2)}} is the {{math|''i''}}th distinct Fibonacci number starting with <math>1,2,3,5,8,13,\ldots</math>. The last bit <math>d(k)</math> 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 [[Universal code (data compression)#Relationship to practical compression|''implied probability'']], the value for each number that has a minimum-size code in Fibonacci coding. {|class="wikitable" style="text-align:right;" ! Symbol !! Fibonacci representation !! Fibonacci code word !! Implied probability |- | 1 || <math>F(2)</math> || 11 || 1/4 |- | 2 || <math>F(3)</math> || 011 || 1/8 |- | 3 || <math>F(4)</math> || 0011 || 1/16 |- | 4 || <math>F(2) + F(4)</math> || 1011 || 1/16 |- | 5 || <math>F(5)</math> || 00011 || 1/32 |- | 6 || <math>F(2) + F(5)</math> || 10011 || 1/32 |- | 7 || <math>F(3) + F(5)</math> || 01011 || 1/32 |- | 8 || <math>F(6)</math> || 000011 || 1/64 |- | 9 || <math>F(2) + F(6)</math> || 100011 || 1/64 |- | 10 || <math>F(3) + F(6)</math> || 010011 || 1/64 |- | 11 || <math>F(4) + F(6)</math> || 001011 || 1/64 |- | 12 || <math>F(2)+F(4)+F(6)</math>|| 101011 || 1/64 |- | 13 || <math>F(7)</math> || 0000011 || 1/128 |- | 14 || <math>F(2) + F(7)</math> || 1000011 || 1/128 |- |} To encode an integer {{Mvar|N}}: # Find the largest [[Fibonacci number]] equal to or less than ''{{Mvar|N}}''; subtract this number from ''{{Mvar|N}}'', keeping track of the remainder. # If the number subtracted was the {{Mvar|i}}th Fibonacci number {{Math|''F''(''i'')}}, put a 1 in place {{Math|''i'' − 2}} in the code word (counting the left most digit as place 0). # Repeat the previous steps, substituting the remainder for ''{{Mvar|N}}'', 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]]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]], making it easier to recover data from a damaged stream. With most other universal codes, if a single [[bit]] 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]] 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.<ref>{{cite arXiv |eprint=0710.3861 |last1=Duda |first1=Jarek |title=Optimal encoding on discrete lattice with translational invariant constrains using statistical algorithms |year=2007 |class=cs.IT }}</ref> ==Example== The following table shows that the number 65 is represented in Fibonacci coding as 0100100011, since {{nowrap|1=65 = 2 + 8 + 55}}. The first two Fibonacci numbers (0 and 1) are not used, and an additional 1 is always appended. :<math>\begin{array}{ccccccccccc|c} \hline 0 & 1 & 1 & 2 & 3 & 5 & 8 & 13 & 21 & 34 & 55 & - \\ \hline F(0) & F(1) & F(2) & F(3) & F(4) & F(5) & F(6) & F(7) & F(8) & F(9) & F(10) & \scriptstyle\text{additional} \\ \hline - & - & 0 & 1 & 0 & 0 & 1 & 0 & 0 & 0 & 1 & 1 \\ \hline \end{array}</math> ==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]]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]], then using an [[entropy coder]] (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]] *[[NegaFibonacci coding]] *[[Ostrowski numeration]] *[[Universal code (data compression)|Universal code]] *[[Varicode]], a practical application *[[Zeckendorf's theorem]] *[[Maximal entropy random walk]] ==References== {{Reflist}} * {{cite book | last1 = Allouche | first1 = Jean-Paul | last2 = Shallit | first2 = Jeffrey | author2-link = Jeffrey Shallit | isbn = 978-0-521-82332-6 | publisher = [[Cambridge University Press]] | title = Automatic Sequences: Theory, Applications, Generalizations | url = https://archive.org/details/automaticsequenc00jpal | url-access = limited | year = 2003 | zbl=1086.11015 | page=[https://archive.org/details/automaticsequenc00jpal/page/n122 105] }} * {{cite journal | last1=Fraenkel | first1=Aviezri S. | last2=Klein | first2=Shmuel T. |title=Robust universal complete codes for transmission and compression | journal=Discrete Applied Mathematics | volume=64 | number=1 | year=1996 | pages=31β55 | doi = 10.1016/0166-218X(93)00116-H | zbl=0874.94026 | issn=0166-218X | citeseerx=10.1.1.37.3064 }} ==Further reading== *{{cite book | last = Stakhov | first = A. P. | title = The Mathematics of Harmony: From Euclid to Contemporary Mathematics and Computer Science | year = 2009 | publisher = [[World Scientific Publishing]] | location = Singapore }} {{Compression Methods}} {{DEFAULTSORT:Fibonacci Coding}} [[Category:Non-standard positional numeral systems]] [[Category:Lossless compression algorithms]] [[Category:Fibonacci numbers]] [[Category:Data compression]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation needed
(
edit
)
Template:Cite arXiv
(
edit
)
Template:Cite book
(
edit
)
Template:Cite journal
(
edit
)
Template:Compression Methods
(
edit
)
Template:Math
(
edit
)
Template:More footnotes
(
edit
)
Template:Mvar
(
edit
)
Template:Nowrap
(
edit
)
Template:Numeral systems
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sidebar with collapsible groups
(
edit
)