# Perfect code

In coding theory, a **perfect code** , or also **densely packed code** , denotes a block code in which each word has the smallest Hamming distance to exactly one code word (and not to several) , where is.

With the mostly used maximum likelihood decoding this means that each received word has exactly one code word to which it has the smallest Hamming distance and to which it can be clearly assigned. The name is derived *perfectly* from this, because there are no ambiguous decoding options.

## Mathematical description

Let a block code with , representing the alphabet used . All code words have a minimum Hamming distance of . He can with it

Correct mistakes.

To be perfect, must be the minimum Hamming distance between two code words of a code is odd, because otherwise for at least one word to exist, which contradicts the definition of perfect codes.

Since the code corrects errors, a word can be uniquely assigned to a code word if the Hamming distance is. Conversely, this means for a specific code word that all words are decoded with a Hamming distance of at most after . As a set it is written like this:

This set is also known as a sphere (sometimes hypercube) with a radius around . The number of elements of can be calculated as follows:

For faults there of possible positions for the error. Incorrect symbol values are available for each fault location. There are bullets. These are disjoint subsets of the . This results in the inequality

Dissolved after and with follows:

This inequality for the number of code words is called **Hamming's limit** or also **spherical packing ****limit** .

A perfect code is characterized by the fact that all words are contained in exactly one of the spheres (in other words: the spheres cover the space). Therefore equality holds for the Hamming bound itself.

## Alternative interpretation

This limit can also be illustrated as follows (for the sake of simplicity only explained using binary codes, i.e. for ):

For an error-correcting code, the decoder must receive enough information to be able to differentiate between all of the following cases:

- different information words and each
- all possible patterns of bit errors of the bits of a code word

Since there are possibilities to distribute bit errors to bits, this results in a total of

Cases that have to be differentiated with the available bits, that is

- .

Equality applies to a perfect code, i.e. the bits carry exactly the minimum information required. This (in) equation corresponds to the above general definition for the case and .

One is actually only interested in the correction of the information bits , for which less additional information would be sufficient - these bits of additional information would then have to be error-free, which of course is usually not guaranteed. Correction of *all* bits is therefore necessary.

## Known Perfect Codes

If the alphabet size is a prime power , then:

If there is a perfect code with parameters with , there is a code with the same parameters, so one of the following codes is:

- A trivial code: A code is called
*trivial*here ,- if he either only , d. H. contains a single code word: or
- if it all contains possible code words of the given block length: .

- A binary repetition code with an odd code word length. The parameters are .
- A Hamming code over the finite body , with parameters .
- The binary Golay code with parameters .
- The Golay ternary code with parameters with .

stands for a positive natural number .

The codes and have the same parameters and can therefore correct the same number of errors with the same block length . The conversion of a trivial code into a linear code with the same parameters is simple: If the code contains a single code word, the zero vector can serve as the only code word instead , and the resulting code is linear. The only remaining trivial code is the one that contains all possible words of the given block length. But this is already linear. The rest of the codes from the list are already linear codes . For every perfect code that is generally not a linear code, there is a linear code with the same parameters - provided the size of the alphabet is a prime power.

It is open whether and for which parameters there are non-trivial perfect codes, if the alphabet size is not a prime power.

For practical purposes the trivial codes are of no interest because either

- no information can be transmitted or
- no errors can be detected or corrected.