ArticleslgStudy

science

Golomb coding

Golomb coding is a science 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 Golomb coding rather than just read about it. In short: Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s.

Golomb coding — main illustration
Golomb coding — illustration

Key takeaways

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

Reference excerpt

Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb coding highly suitable for situations in which the occurrence of small values in the input stream is significantly more likely than large values.

Rice coding Rice coding (invented by Robert F. Rice) denotes using a subset of the family of Golomb codes to produce a simpler (but possibly suboptimal) prefix code. Rice used this set of codes in an adaptive coding scheme; "Rice coding" can refer either to that adaptive scheme or to using that subset of Golomb codes. Whereas a Golomb code has a tunable parameter that can be any positive integer value, Rice codes are those in which the tunable parameter is a power of two. This makes Rice codes convenient for use on a computer, since multiplication and division by 2 can be implemented more efficiently in binary arithmetic. Rice was motivated to propose this simpler subset due to the fact that geometric distributions are often varying with time, not precisely known, or both, so selecting the seemingly optimal code might not be very advantageous. Rice coding is used as the entropy encoding stage in a number of lossless image compression and audio data compression methods.

Overview

Construction of codes Golomb coding uses a tunable parameter M to divide an input value x into two parts: q, the result of a division by M, and r, the remainder. The quotient is sent in unary coding, followed by the remainder in truncated binary encoding. When M=1, Golomb coding is equivalent to unary coding. Golomb–Rice codes can be thought of as codes that indicate a number by the position of the bin (q), and the offset within the bin (r). The example figure shows the position q and offset r for the encoding of integer x using Golomb–Rice parameter M = 3, with source probabilities following a geometric distribution with p(0) = 0.2. Formally, the two parts are given by the following expression, where x is the nonnegative integer being encoded: q=⌊xM⌋ and r=x−qM.

Both q and r will be encoded using variable numbers of bits: q by a unary code, and r by b bits for Rice code, or a choice between b and b+1 bits for Golomb code (i.e. M is not a power of 2), with b=⌊log2(M)⌋. If r<2b+1−M, then use b bits to encode r; otherwise, use b+1 bits to encode r. Clearly, b=log2(M) if M is a power of 2 and we can encode all values of r with b bits. The integer x treated by Golomb was the run length of a Bernoulli process, which has a geometric distribution starting at 0. The best choice of parameter M is a function of the corresponding Bernoulli process, which is parameterized by p=P(x=0) the probability of success in a given Bernoulli trial. M is either the median of the distribution or the median ±1. It can be determined by these inequalities: (1−p)M+(1−p)M+1≤1<(1−p)M−1+(1−p)M, which are solved by M=⌈−log⁡(2−p)log⁡(1−p)⌉. For the example with p(0) = 0.2: M=⌈−log⁡(1.8)log⁡(0.8)⌉=⌈2.634⌉=3. The Golomb code for this distribution is equivalent to the Huffman code for the same probabilities, if it were possible to compute the Huffman code for the infinite set of source values.

Use with signed integers Golomb's scheme was designed to encode sequences of non-negative numbers. However, it is easily extended to accept sequences containing negative numbers using an overlap and interleave scheme, in which all values are reassigned to some positive number in a unique and reversible way. The sequence begins: 0, −1, 1, −2, 2, −3, 3, −4, 4, ... The n-th negative value (i.e., ⁠−n⁠) is mapped to the nth odd number (⁠2n−1⁠), and the mth positive value is mapped to the m-th even number (⁠2m⁠). This may be expressed mathematically as follows: a positive value x is mapped to (x′=2|x|=2x, x≥0), and a negative value y is mapped to (y′=2|y|−1=−2y−1, y<0). Such a code may be used for simplicity, even if suboptimal. Truly optimal codes for two-sided geometric distributions include multiple variants of the Golomb code, depending on the distribution parameters, including this one.

Simple algorithm Below is the Rice–Golomb encoding, where the remainder code uses simple truncated binary encoding, also named "Rice coding" (other varying-length binary encodings, like arithmetic or Huffman encodings, are possible for the remainder codes, if the statistic distribution of remainder codes is not flat, and notably when not all possible remainders after the division are used). In this algorithm, if the M parameter is a power of 2, it becomes equivalent to the simpler Rice encoding:

Fix the parameter M to an integer value. For N, the number to be encoded, find quotient = q = floor(N/M) remainder = r = N modulo M Generate codeword The code format : <Quotient code><Remainder code>, where Quotient code (in unary coding) Write a q-length string of 1 bits (alternatively, of 0 bits) Write a 0 bit (respectively, a 1 bit) Remainder code (in truncated binary encoding) Let b=⌊log2(M)⌋ If r<2b+1−M code r in binary representation using b bits. If r≥2b+1−M code the number r+2b+1−M in binary representation using b + 1 bits. Decoding:

Decode the unary representation of q (count the number of 1 in the beginning of the code) Skip the 0 delimiter Let b=⌊log2(M)⌋ Interpret next b bits as a binary number r'. If r′<2b+1−M holds, then the remainder r=r′ Otherwise interpret b + 1 bits as a binary number r', the remainder is given by r=r′−2b+1+M Compute N=q∗M+r

Example Set M = 10. Thus b=⌊log2(10)⌋=3. The cutoff is 2b+1−M=16−10=6.

For example, with a Rice–Golomb encoding using parameter M = 10, the decimal number 42 would first be split into q = 4 and r = 2, and would be encoded as qcode(q),rcode(r) = qcode(4),rcode(2) = 11110,010 (you don't need to encode the separating comma in the output stream, because the 0 at the end of the q code is enough to say when q ends and r begins; both the qcode and rcode are self-delimited).

… excerpt ends here. Continue reading the full article.

Illustrations

Golomb coding: This image shows the redundancy, in bits, of the Golomb code, when M is chosen optimally, for  1 − p(0) ≥ 0.45
This image shows the redundancy, in bits, of the Golomb code, when M is chosen optimally, for 1 − p(0) ≥ 0.45
Golomb coding: Golomb-coded Rice algorithm experiment compression ratios
Golomb-coded Rice algorithm experiment compression ratios

Worked examples

Example 1 — a first encounter with Golomb coding

Start with the simplest possible case. Write down what Golomb coding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, 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 Golomb 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 Golomb 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 Golomb coding

In research
Golomb coding appears in science 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 Golomb 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
Golomb coding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data compression, Entropy coding, so understanding it makes those chapters shorter.
In everyday life
Look for Golomb 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 “Golomb coding” →

How to study Golomb coding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Golomb 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 Golomb coding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Golomb coding in simple terms?

Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s.

Why does Golomb coding matter?

Because it connects several science 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 Golomb 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 Golomb coding.

Tags

  • Data compression
  • Entropy coding

Keep exploring