Part I Basics of coding theory CHAPTER 1: Basics of coding theory ABSTRACT Coding theory - theory of error correcting codes - is one of the most interesting and applied part of mathematics and informatics. All real communication systems that work with digitally represented data, as CD players, TV, fax machines, internet, satellites, mobiles, require to use error correcting codes because all real channels are, to some extent, noisy - due to interference caused by environment ■ Coding theory problems are therefore among the very basic and most frequent problems of storage and transmission of information. ■ Coding theory results allow to create reliable systems out of unreliable systems to store and/or to transmit information. ■ Coding theory methods are often elegant applications of very basic concepts and methods of (abstract) algebra. This first chapter presents and illustrates the very basic problems, concepts, methods and results of coding theory. prof. Jozef Gruska 2/37 Coding - basic concepts Without coding theory and error-correcting codes there would be no deep-space travel and pictures, no satellite TV, no compact disc, no . . . no . . . no ... . Error-correcting codes are used to correct messages when they are transmitted through noisy channels. channel message W Encoding code word code 1 word Decoding W user source C(W) noise C'(W) Error correcting framework Example message YES or NO YES Encoding YES-00000 ooooo : >01001 Decoding 01001 YES user NO -11111 ooooo A code C over an alphabet E is a subset of £*(C C £*). A q-nary code is a code over an alphabet of q-symbols. A binary code is a code over the alphabet {0,1}. Examples of codes CI = {00, 01,10,11} C2 = {000, 010,101,100} C3 = {00000, 01101,10111,11011} prof. Jozef Gruska IV054 1. Basics of coding theory 3/37 CHANNEL is any physical medium through which information is transmitted. (Telephone lines and the atmosphere are examples of channels.) NOISE may be caused by sunspots, lighting, meteor showers, random radio disturbance, poor typing, poor hearing, .... TRANSMISSION GOALS Q Fast encoding of information. B Easy transmission of encoded messages. B Fast decoding of received messages. Reliable correction of errors introduced in the channel. 0 Maximum transfer of information per unit time. BASIC METHOD OF FIGHTING ERRORS: REDUNDANCY!!! 0 is encoded as 00000 and 1 is encoded as 11111. prof. Jozef Gruska 4/37 IMPORTANCE of ERROR-CORRECTING CODES In a good cryptosystem a change of a single bit of the cryptotext should change so many bits of the plaintext obtained from the cryptotext that the plaintext gets uncomprehensible. Methods to detect and correct errors when cryptotexts are transmitted are therefore much needed. Also many non-cryptographic applications require error-correcting codes. For example, mobiles, CD-players,... prof. Jozef Gruska 5/37 BASIC IDEA The details of techniques used to protect information against noise in practice are sometimes rather complicated, but basic principles are easily understood. The key idea is that in order to protect a message against a noise, we should encode the message by adding some redundant information to the message. In such a case, even if the message is corrupted by a noise, there will be enough redundancy in the encoded message to recover - to decode the message completely. prof. Jozef Gruska 6/37 EXAMPLE In case of the encoding 0^ 000 1 ^ 111 the probability of the bit error p <\ , and the majority voting decoding 000, 001, 010,100 -> 000 and 111, 110,101, 011 -> 111 the probability of an erroneous decoding (if there are 2 or 3 errors) is 3p2(l-p) + p3 = 3p2-2p3

s + 1. B A code C can correct up to t errors if h(C) > 2t + 1. Proof (1) Trivial. (2) Suppose h(C) > 2t + 1. Let a codeword x is transmitted and a word y is recceived with h(x, y) < t. If x' =/= x is a codeword, then h(y, x') > t + 1 because otherwise h(y, x') < t + 1 and therefore h(x, x') < h(x, y) + h(y, x') < 2t + 1 what contradicts the assumption h(C) > 2t + 1. prof. JozefGruska IV054 1. Basics of coding theory 10/37 Binary symmetric channel Consider a transition of binary symbols such that each symbol has probability of error P<\- 0 Binary symmetric channel If n symbols are transmitted, then the probability of t errors is p^l-p)-^) In the case of binary symmetric channels, the "nearest neighbour decoding strategy" is also "maximum likelihood decoding strategy". Example Consider C = {000,111} and the nearest neighbour decoding strategy. Probability that the received word is decoded correctly as 000 is (l-p)3 + 3p(l-p)2, as 111 is (l-p)3 + 3p(l-p)2, Therefore Perr(C) = 1 - ((1 - p)3 + 3p(l - p)2) is probability of erroneous decoding. Example If p = 0.01, then Perr(C) = 0.000298 and only one word in 3356 will reach the user with an error. prof. Jozef Gruska 11/37 POWER of PARITY BITS Example Let all 2 of binary words of length 11 be codewords. Let the probability p of a bit error be 1CP8. Let bits be transmitted at the rate 107 bits per second. The probability that a word is transmitted incorrectly is approximately llp(l-p)10«^. Therefore j^s ■ ^ = 0.1 of words per second are transmitted incorrectly. One wrong word is transmitted every 10 seconds, 360 erroneous words every hour and 8640 words every day without being detected! Let now one parity bit be added. Any single error can be detected!!! The probability of at least two errors is: Therefore approximately ■ « 5.5 ■ 10 words per second are transmitted with an undetectable error. Corollary One undetected error occurs only every 2000 days! (2000 ~ 5 5x86400 )• 1 - (i - p)12 -12(1 -p^p^Qii-pyop2 66 prof. Jozef Gruska IV054 1. Basics of coding theory 12/37 TWO-DIMENSIONAL PARITY CODE The two-dimensional parity code arranges the data into a two-dimensional array and then to each row (column) parity bit is attached. Example Binary string 10001011000100101111 is represented and encoded as follows 1 0 0 0 1 0 110 0 0 10 0 1 0 1111 Question How much better is two-dimensional encoding than one-dimensional encoding? 1 0 0 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 0 prof. Jozef Gruska 13/37 Notation and Examples Notation: An (n, M, c/)-code C is a code such that ■ n - is the length of codewords. ■ M - is the number of codewords. ■ d - is the minimum distance in C. Example: CI = {00, 01,10,11} is a (2,4,l)-code. C2 = {000, 011,101,110} is a (3,4,2)-code. C3 = {00000,01101,10110,11011} is a (5,4,3)-code. Comment: A good (n, M, c/)-code has small n and large M and d. Examples from deep space travels Examples (Transmission of photographs from the deep space) ■ In 1965-69 Mariner 4-5 took the first photographs of another planet - 22 photos. Each photo was divided into 200 x 200 elementary squares - pixels. Each pixel was assigned 6 bits representing 64 levels of brightness. Hadamard code was used. Transmission rate: 8.3 bits per second. ■ In 1970-72 Mariners 6-8 took such photographs that each picture was broken into 700 x 832 squares. Reed-Muller (32,64,16) code was used. Transmission rate was 16200 bits per second. (Much better pictures) prof. Jozef Gruska 15/37 HADAMARD CODE In Mariner 5, 6-bit pixels were encoded using 32-bit long Hadamard code that could correct up to 7 errors. Hadamard code has 64 codewords. 32 of them are represented by the 32 x 32 matrix H = {hu}, where 0 < /', j < 31 and — ^_^s0t0 + a1bi+... + aibi where i and j have binary representations / = a4a3a2a1a0, j = b4b3b2b1b0 The remaing 32 codewords are represented by the matrix —H. Decoding is quite simple. prof. Jozef Gruska 16/37 CODE RATE For g-nary (n, M, c/)-code we define code rate, or information rate, R, by n The code rate represents the ratio of the number of needed input data symbols to the number of transmitted code symbols. Code rate (6/32 for Hadamard code), is an important parameter for real implementations, because it shows what fraction of the bandwidth is being used to transmit actual data. prof. Jozef Gruska 17/37 The ISBN-code Each book till 1.1.2007 had International Standard Book Number which was a 10-digit codeword produced by the publisher with the following structure: / p m w = xi... xio language publisher number weighted check sum 0 07 709503 0 such that X);=i lx> = 0 (m0i^ll) The publisher had to put X into the 10-th position if xio = 10. The ISBN code was designed to detect: (a) any single error (b) any double error created by a transposition Single error detection Let X = xi... xio be a correct code and let Y = xi ... xj_iyjxj+i ... xio with yj = xj + a, a / 0 In such a case: E/!i '// = E/!i i* +J* / 0 (modll) prof. Jozef Gruska 18/37 The ISBN-code Transposition detection Let xj and xk be exchanged. E/fi '// = E/fi * + (k-j)xj + k)xk = (k-j)(xj - xk) / 0 (modll) if k / 7 and Xj / x/c. prof. Jozef Gruska 19/37 New ISBN code Starting 1.1.2007 instead of 10-digit ISBN code a 13-digit ISBN code is being used. New ISBN number can be obtained from the old one by preceeding the old code with three digits 978. For details about 13-digit ISBN see http://www.isbn-international.org/en/revision.html prof. Jozef Gruska 20/37 Equivalence of codes Definition Two g-ary codes are called equivalent if one can be obtained from the other by a combination of operations of the following type: (a) a permutation of the positions of the code. (b) a permutation of symbols appearing in a fixed position. Question: Let a code be displayed as an M x n matrix. To what correspond operations (a) and (b)? Claim: Distances between codewords are unchanged by operations (a), (b). Consequently, equivalent codes have the same parameters (n,M,d) (and correct the same number of errors). Examples of equivalent codes Lemma Any q-ary (n, M, c/)-code over an alphabet {0,1,..., q — 1} is equivalent to an (n, M, c/)-code which contains the all-zero codeword 00 ... 0. Proof Trivial. The main coding theory problem A good (n, M, c/)-code has small n, large M and large d. The main coding theory problem is to optimize one of the parameters n, M, d for given values of the other two. Notation: Aq(n, d) is the largest M such that there is an q-nary (n, M, d)-code. (a) Aq(n,l) = q"; (b) Aq{n,n) = q. (a) obvious; (b) Let C be an q-nary (n, M, n)-code. Any two distinct codewords of C differ in all n positions. Hence symbols in any fixed position of M codewords have to be different => Aq(n, n) < q. Since the q-nary repetition code is (n, q, n)-code, we get Aq(n, n) > q. Theorem Proof prof. Jozef Gruska 22/37 EXAMPLE Example Proof that A>(5, 3) = 4. (a) Code C3 is a (5,4, 3)-code, hence ,42(5,3) > 4. (b) Let C be a (5, M, 3)-code with M = 5. ■ By previous lemma we can assume that 00000 G C. ■ C has to contain at most one codeword with at least four l's. (otherwise d(x,y) < 2 for two such codewords x, y) ■ Since 00000 G C, there can be no codeword in C with at most one or two 1. ■ Since d = 3, C cannot contain three codewords with three l's. ■ Since M > 4, there have to be in C two codewords with three l's. (say 11100, 00111), the only possible codeword with four or five l's is then 11011. prof. Jozef Gruska 23/37 Design of one code from another code Theorem Suppose d is odd. Then a binary (n, M, c/)-code exists if a binary (n + 1, M, d + l)-code exists. Proof Only if case: Let C be a binary (n, M, d) code. Let C = {xi ... x„x„+i |xi ...x„eC, x„+i = (J2"=i *') mod 2} Since parity of all codewords in C' is even, d(x',y') is even for all x',y'eC. Hence d(C') is even. Since d < d(C') < d + 1 and d is odd, d(C') = d + l. Hence C' is an (n + 1, M, d + l)-code. If case: Let D be an (n + 1, M, d + l)-code. Choose code words x, y of D such that d(x,y) = d + l. Find a position in which x, y differ and delete this position from all codewords of D. Resulting code is an (n, M, d)-code. prof. Jozef Gruska IV054 1. Basics of coding theory 24/37 A corollary Corollary: If d is odd, then A2(n, d) = A2(n +l,d + 1). If d is even, then A2(n, d) = A2(n — l,d — 1). Example A>(5, 3) = 4 =>• A2(6,4) = 4 (5,4, 3)-code =>• (6,4,4)-code 0 0 0 0 0 0 110 1 1 0 1 1 0 by addinscheck- 110 11 prof. Jozef Gruska 25/37 A sphere and its contents Notation F^ - is a set of all words of length n over the alphabet {0,1, 2,..., q — 1} Definition For any codeword u£F," and any integer r > 0 the sphere of radius r and centre u is denoted by S(u, r) = {v e F"q\d{u, v) sro1 G)(«-iy and therefore Mn,<0>^){q_lV prof. Jozef Gruska 29/37 Error Detection Error detection is much more modest aim than error correction. Error detection is suitable in the cases that channel is so good that probability of error is small and if an error is detected, the receiver can ask to renew the transmission. For example, two main requirements for many telegraphy codes used to be: ■ Any two codewords had to have distance at least 2; ■ No codeword could be obtained from another codeword by transposition of two adjacent letters. prof. Jozef Gruska 30/37 Pictures of Saturn taken by Voyager Pictures of Saturn taken by Voyager, in 1980, had 800 x 800 pixels with 8 levels of brightness. Since pictures were in color, each picture was transmitted three times; each time through different color filter. The full color picture was represented by 3 x 800 x 800 x 8 = 13360000 bits. To transmit pictures Voyager used the Golay code G24. prof. Jozef Gruska 31/37 General coding problem Important problems of information theory are how to define formally such concepts as information and how to store or transmit information efficiently. Let X be a random variable (source) which takes any value x with probability p(x). The entropy of X is defined by S(X) = -J2xP(x)lg p(x) and it is considered to be the information content of X. In a special case of a binary variable X which takes on the value 1 with probability p and the value 0 with probability 1 — p S(X) = H(p) = -plgp-(l- p)lg(l - p) Problem: What is the minimal number of bits needed to transmit n values of XI Basic idea: To encode more probable outputs of X by shorter binary words. Example (Morse code - 1838) a - b c d -.. e . f g -■ h .... i .. j — k-.- 1 m - n -. o — P ■-■ q -■- r .-. s ... t - u ..- v w .- x y -■- z -.. prof. Jozef Gruska 32/37 Shannon's noisless coding theorem Shannon's noiseless coding theorem says that in order to transmit n values of X, we need, and it is sufficient, to use nS(X) bits. More exactly, we cannot do better than the bound nS(X) says, and we can reach the bound nS(X) as close as desirable. Example Let a source X produce the value 1 with probability p = \ and the value 0 with probability 1 — p = | Assume we want to encode blocks of the outputs of X of length 4. By Shannon's theorem we need 4/-/(|) = 3.245 bits per blocks (in average) A simple and practical method known as Huffman code requires in this case 3.273 bits per a 4-bit message. mess. code mess. code mess. code mess. code 0000 10 0100 010 1000 011 1100 11101 0001 000 0101 11001 1001 11011 1101 111110 0010 001 0110 11010 1010 11100 1110 111101 0011 11000 0111 1111000 1011 111111 1111 1111001 Observe that this is a prefix code - no codeword is a prefix of another codeword. prof. Jozef Gruska 33/37 Design of Huffman code Given a sequence of n objects, xi,... , x„ with probabilities pi > ... > p„. Stage 1 - shrinking of the sequence. ■ Replace x„_i,x„ with a new object y„_i with probability p„-i + p„ and rearrange sequence so one has again non-increasing probabilities. ■ Keep doing the above step till the sequence shrinks to two objects. .50 .50 .50 .50 .50 .50 .15 .15 .15 .15 .22 .28 .12 .12 .12 .13^ ^15^ HÜ .10 .10 .10^ ^12^ .04 .05 .08^ JioH Xt4^ ^\ i)2"H Stage 2 - extending the code - Apply again and again the following method If C = {ci,. .., cr} is a prefix optimal code for a source Sr, then C' = {c[,. an optimal code for Sr+i, where c'i = Q 1