ArticleslgStudy

mathematics

Fibonacci coding

Fibonacci coding is a mathematics topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Fibonacci coding rather than just read about it. In short: In mathematics and computing, Fibonacci coding is a universal code which encodes positive integers into binary code words. It is one example of representations of integers based on Fibonacci numbers.

Key takeaways

  • Fibonacci coding belongs to mathematics; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Fibonacci coding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Fibonacci coding from memory before moving on to harder problems.

Reference excerpt

In mathematics and computing, Fibonacci coding is a universal code which encodes positive integers into binary code words. It is one example of representations of integers based on Fibonacci numbers. 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 N, if d(0),d(1),…,d(k−1),d(k) represent the digits of the code word representing N then we have:

N=∑i=0k−1d(i)F(i+2), and d(k−1)=d(k)=1. where F(i) is the ith Fibonacci number, and so F(i+2) is the ith distinct Fibonacci number starting with 1,2,3,5,8,13,…. The last bit d(k) 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 N:

Find the largest Fibonacci number equal to or less than N; subtract this number from N, keeping track of the remainder. If the number subtracted was the ith Fibonacci number F(i), put a 1 in place i − 2 in the code word (counting the rightmost bit as place 0). Repeat the previous steps, substituting the remainder for 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 numbers) 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.

Example The following table shows that the number 65 is represented in Fibonacci coding as 0100100011, since 65 = 2 + 8 + 55. The first two Fibonacci numbers (0 and 1) are not used, and an additional 1 is always appended.

011235813213455−F(0)F(1)F(2)F(3)F(4)F(5)F(6)F(7)F(8)F(9)F(10)additional−−0100100011

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 numbers. 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 Varicode, a practical application Zeckendorf's theorem Maximal entropy random walk

References

Allouche, Jean-Paul; Shallit, Jeffrey (2003). Automatic Sequences: Theory, Applications, Generalizations. Cambridge University Press. p. 105. ISBN 978-0-521-82332-6. Zbl 1086.11015. Fraenkel, Aviezri S.; Klein, Shmuel T. (1996). "Robust universal complete codes for transmission and compression". Discrete Applied Mathematics. 64 (1): 31–55. doi:10.1016/0166-218X(93)00116-H. ISSN 0166-218X. Zbl 0874.94026.

Further reading Stakhov, A. P. (2009). The Mathematics of Harmony: From Euclid to Contemporary Mathematics and Computer Science. Singapore: World Scientific Publishing.

Worked examples

Example 1 — a first encounter with Fibonacci coding

Start with the simplest possible case. Write down what Fibonacci coding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In mathematics, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Fibonacci coding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Fibonacci coding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Fibonacci coding

In research
Fibonacci coding appears in mathematics research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Fibonacci coding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Fibonacci coding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data compression, Fibonacci numbers, Lossless compression algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Fibonacci coding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Fibonacci coding” →

How to study Fibonacci coding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Fibonacci coding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Fibonacci coding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Fibonacci coding in simple terms?

In mathematics and computing, Fibonacci coding is a universal code which encodes positive integers into binary code words. It is one example of representations of integers based on Fibonacci numbers.

Why does Fibonacci coding matter?

Because it connects several mathematics ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Fibonacci coding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Fibonacci coding.

Tags

  • Data compression
  • Fibonacci numbers
  • Lossless compression algorithms
  • Non-standard positional numeral systems

Keep exploring