-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgcodes.xml
More file actions
3241 lines (2990 loc) · 124 KB
/
Copy pathalgcodes.xml
File metadata and controls
3241 lines (2990 loc) · 124 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0"?>
<!-- This file is part of the book -->
<!-- -->
<!-- Abstract Algebra: Theory and Applications -->
<!-- -->
<!-- Text: Copyright (C) 1997-2025 Thomas W. Judson -->
<!-- Sage: Copyright (C) 2010-2025 Robert A. Beezer -->
<!-- See the file COPYING for copying conditions. -->
<!-- This file is part of the book -->
<!-- -->
<!-- See the file COPYING for copying conditions. -->
<chapter xmlns:xi="http://www.w3.org/2001/XInclude" xml:id="algcodes">
<title>Algebraic Coding Theory</title>
<introduction>
<p>
Coding theory is an application of algebra that has become increasingly important over the last several decades.
When we transmit data,
we are concerned about sending a message over a channel that could be affected by <q>noise.</q>
We wish to be able to encode and decode the information in a manner that will allow the detection,
and possibly the correction, of errors caused by noise.
This situation arises in many areas of communications,
including radio, telephone,
television, computer communications,
and digital media technology.
Probability, combinatorics, group theory, linear algebra,
and polynomial rings over finite fields all play important roles in coding theory.
</p>
</introduction>
<section xml:id="algcodes-section-error-detecting-correcting-codes">
<title>Error-Detecting and Correcting Codes</title>
<introduction>
<p>
Let us examine a simple model of a communications system for transmitting and receiving coded messages (<xref ref="algcodes-figure-encoding"/>).
</p>
<figure xml:id="algcodes-figure-encoding">
<caption>Encoding and decoding messages</caption>
<!-- Replaced figure with tikz figure - TWJ 5/10/2010 -->
<image width="60%" xml:id="algcodes-encode-decode">
<description>A vertical flow chart where an m-digit message is passed to an encoder which is represented by a rectangle to become an n-digit codeword which is passed to a transmitter that is also represented by a rectangle. The outcome of the transmitter may have noise and is passed to the receiver which is prepresented by a rectangle. The receiver passes an n-digit received word to a decoder that is represented by a rectangle. The decoder produces an m-digit received word or an error.</description>
<latex-image>
<xi:include href="tikz/algcodes-encode-decode.tex" parse="text"/>
</latex-image>
</image>
</figure>
<p>
Uncoded messages may be composed of letters or characters,
but typically they consist of binary <m>m</m>-tuples.
These messages are encoded into codewords,
consisting of binary <m>n</m>-tuples,
by a device called an <term>encoder</term>.
The message is transmitted and then decoded.
We will consider the occurrence of errors during transmission.
An <term>error</term> occurs if there is a change in one or more bits in the codeword.
A <term>decoding scheme</term> is a method that either converts an arbitrarily received <m>n</m>-tuple into a meaningful decoded message or gives an error message for that <m>n</m>-tuple.
If the received message is a codeword
(one of the special <m>n</m>-tuples allowed to be transmitted),
then the decoded message must be the unique message that was encoded into the codeword.
For received non-codewords,
the decoding scheme will give an error indication,
or, if we are more clever,
will actually try to correct the error and reconstruct the original message.
Our goal is to transmit error-free messages as cheaply and quickly as possible.
</p>
<example xml:id="algcodes-example-repeat">
<p>
One possible coding scheme would be to send a message several times and to compare the received copies with one another.
Suppose that the message to be encoded is a binary <m>n</m>-tuple <m>(x_{1}, x_{2}, \ldots,
x_{n})</m>.
The message is encoded into a binary <m>3n</m>-tuple by simply repeating the message three times:
<me>
(x_{1}, x_{2}, \ldots, x_{n}) \mapsto (x_{1}, x_{2}, \ldots, x_{n}, x_{1}, x_{2}, \ldots, x_{n}, x_{1}, x_{2}, \ldots, x_{n})
</me>.
To decode the message,
we choose as the <m>i</m>th digit the one that appears in the <m>i</m>th place in at least two of the three transmissions.
For example, if the original message is <m>(0110)</m>,
then the transmitted message will be <m>(0110\; 0110\; 0110)</m>.
If there is a transmission error in the fifth digit,
then the received codeword will be <m>(0110\; 1110\; 0110)</m>,
which will be correctly decoded as <m>(0110)</m>.<fn>
We will adopt the convention that bits are numbered left to right in binary <m>n</m>-tuples.
</fn> This triple-repetition method will automatically detect and correct all single errors,
but it is slow and inefficient:
to send a message consisting of <m>n</m> bits,
<m>2n</m> extra bits are required,
and we can only detect and correct single errors.
We will see that it is possible to find an encoding scheme that will encode a message of <m>n</m> bits into <m>m</m> bits with <m>m</m> much smaller than <m>3n</m>.
</p>
</example>
<example xml:id="algcodes-example-even-parity">
<p>
<term>Even parity</term>, a commonly used coding scheme,
is much more efficient than the simple repetition scheme.
The <acro>ASCII</acro> (American Standard Code for Information Interchange) coding system uses binary <m>8</m>-tuples,
yielding <m>2^{8} = 256</m> possible <m>8</m>-tuples.
However, only seven bits are needed since there are only
<m>2^7 = 128</m> <acro>ASCII</acro> characters.
What can or should be done with the extra bit?
Using the full eight bits, we can detect single transmission errors.
For example, the <acro>ASCII</acro> codes for A, B, and C are
<md>
<mrow>\text{A} & = 65_{10} = 01000001_{2},</mrow>
<mrow>\text{B} & = 66_{10} = 01000010_{2},</mrow>
<mrow>\text{C} & = 67_{10} = 01000011_{2}</mrow>
</md>.
Notice that the leftmost bit is always set to 0;
that is, the <m>128</m> <acro>ASCII</acro> characters have codes
<md>
<mrow>00000000_{2} & = 0_{10},</mrow>
<mrow>& \vdots</mrow>
<mrow>01111111_{2} & = 127_{10}</mrow>
</md>.
The bit can be used for error checking on the other seven bits.
It is set to either <m>0</m> or <m>1</m> so that the total number of <m>1</m> bits in the representation of a character is even.
Using even parity, the codes for A, B, and C now become
<md>
<mrow>\text{A} & = 01000001_{2},</mrow>
<mrow>\text{B} & = 01000010_{2},</mrow>
<mrow>\text{C} & = 11000011_{2}</mrow>
</md>.
Suppose an A is sent and a transmission error in the sixth bit is caused by noise over the communication channel so that <m>(0100\; 0101)</m> is received.
We know an error has occurred since the received word has an odd number of <m>1</m>s,
and we can now request that the codeword be transmitted again.
When used for error checking,
the leftmost bit is called a <term>parity check bit</term>.
</p>
<p>
By far the most common error-detecting codes used in computers are based on the addition of a parity bit.
Typically, a computer stores information in <m>m</m>-tuples called <term>words</term>.
Common word lengths are <m>8</m>,
<m>16</m>, and <m>32</m> bits.
One bit in the word is set aside as the parity check bit,
and is not used to store information.
This bit is set to either <m>0</m> or <m>1</m>,
depending on the number of <m>1</m>s in the word.
</p>
<p>
Adding a parity check bit allows the detection of all single errors because changing a single bit either increases or decreases the number of <m>1</m>s by one,
and in either case the parity has been changed from even to odd,
so the new word is not a codeword.
(We could also construct an error detection scheme based on <term>odd parity</term>;
that is, we could set the parity check bit so that a codeword always has an odd number of <m>1</m>s.)
</p>
</example>
<p>
The even parity system is easy to implement, but has two drawbacks.
First, multiple errors are not detectable.
Suppose an A is sent and the first and seventh bits are changed from <m>0</m> to <m>1</m>.
The received word is a codeword,
but will be decoded into a C instead of an A. Second,
we do not have the ability to correct errors.
If the 8-tuple <m>(1001\; 1000)</m> is received,
we know that an error has occurred,
but we have no idea which bit has been changed.
We will now investigate a coding scheme that will not only allow us to detect transmission errors but will actually correct the errors.
</p>
<example xml:id="algcodes-example-nearest">
<p>
Suppose that our original message is either a <m>0</m> or a <m>1</m>,
and that <m>0</m> encodes to <m>(000)</m> and <m>1</m> encodes to <m>(111)</m>.
If only a single error occurs during transmission,
we can detect and correct the error.
For example, if a <m>(101)</m> is received,
then the second bit must have been changed from a <m>1</m> to a <m>0</m>.
The originally transmitted codeword must have been <m>(111)</m>.
This method will detect and correct all single errors.
</p>
<table xml:id="algcodes-table-repetition-code">
<title>A repetition code</title>
<tabular halign="center" top="medium">
<col/>
<col/>
<col/>
<col/>
<col/>
<col/>
<col/>
<col/>
<col/>
<row>
<cell>Transmitted</cell>
<cell colspan="8">Received Word</cell>
</row>
<row bottom="medium">
<cell>Codeword</cell>
<cell><m>000</m></cell>
<cell><m>001</m></cell>
<cell><m>010</m></cell>
<cell><m>011</m></cell>
<cell><m>100</m></cell>
<cell><m>101</m></cell>
<cell><m>110</m></cell>
<cell><m>111</m></cell>
</row>
<row>
<cell><m>000</m></cell>
<cell><m>0</m></cell>
<cell><m>1</m></cell>
<cell><m>1</m></cell>
<cell><m>2</m></cell>
<cell><m>1</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>3</m></cell>
</row>
<row bottom="medium">
<cell><m>111</m></cell>
<cell><m>3</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>1</m></cell>
<cell><m>2</m></cell>
<cell><m>1</m></cell>
<cell><m>1</m></cell>
<cell><m>0</m></cell>
</row>
</tabular>
</table>
<p>
In <xref ref="algcodes-table-repetition-code"/>,
we present all possible words that might be received for the transmitted codewords <m>(000)</m> and <m>(111)</m>.
<xref ref="algcodes-table-repetition-code"/> also shows the number of bits by which each received <m>3</m>-tuple differs from each original codeword.
</p>
</example>
</introduction>
<subsection xml:id="algcodes-subsection-max-likelihood">
<title>Maximum-Likelihood Decoding</title>
<!-- Label repaired. Suggested by R. Beezer. -->
<!-- TWJ - 12/19/2011 -->
<p>
The coding scheme presented in <xref ref="algcodes-example-nearest"/> is not a complete solution to the problem because it does not account for the possibility of multiple errors.
For example,
either a (000) or a (111) could be sent and a (001) received.
We have no means of deciding from the received word whether there was a single error in the third bit or two errors,
one in the first bit and one in the second.
No matter what coding scheme is used,
an incorrect message could be received.
We could transmit a (000),
have errors in all three bits,
and receive the codeword (111).
It is important to make explicit assumptions about the likelihood and distribution of transmission errors so that,
in a particular application,
it will be known whether a given error detection scheme is appropriate.
We will assume that transmission errors are rare, and,
that when they do occur, they occur independently in each bit;
that is, if <m>p</m> is the probability of an error in one bit and <m>q</m> is the probability of an error in a different bit,
then the probability of errors occurring in both of these bits at the same time is <m>pq</m>.
We will also assume that a received <m>n</m>-tuple is decoded into a codeword that is closest to it;
that is, we assume that the receiver uses
<idx><h>Maximum-likelihood decoding</h></idx><term>maximum-likelihood decoding</term>.<fn>
This section requires a knowledge of probability,
but can be skipped without loss of continuity.
</fn></p>
<figure xml:id="algcodes-figure-channel">
<caption>Binary symmetric channel</caption>
<!-- Replaced figure with tikz figure - TWJ 5/10/2010 -->
<image width="40%" xml:id="algcodes-binary-channel">
<description>A schematic diagram where a zero has probabilty p that it will be decoded as a zero and probability q that it will be decoded as a one, which are represented by arrows from 0 to 0 and 1 to 1, respectively. A one has probabilty p that it will be decoded as a one and probability q that it will be decoded as a zero, which are represented by arrows from 1 to 1 and 0 to 1, respectively.</description>
<latex-image>
<xi:include href="tikz/algcodes-binary-channel.tex" parse="text"/>
</latex-image>
</image>
</figure>
<p>
A <term>binary symmetric channel</term><idx><h>Binary symmetric channel</h></idx> is a model that consists of a transmitter capable of sending a binary signal,
either a <m>0</m> or a <m>1</m>, together with a receiver.
Let <m>p</m> be the probability that the signal is correctly received.
Then <m>q = 1 - p</m> is the probability of an incorrect reception.
If a <m>1</m> is sent,
then the probability that a <m>1</m> is received is <m>p</m> and the probability that a <m>0</m> is received is <m>q</m> (<xref ref="algcodes-figure-channel"/>).
The probability that no errors occur during the transmission of a binary codeword of length <m>n</m> is <m>p^{n}</m>.
For example,
if <m>p=0.999</m> and a message consisting of 10,000 bits is sent,
then the probability of a perfect transmission is
<me>
(0.999)^{10,000} \approx 0.00005
</me>.
</p>
<theorem>
<statement>
<p>
If a binary <m>n</m>-tuple
<m>(x_{1}, \ldots,
x_{n})</m> is transmitted across a binary symmetric channel with probability <m>p</m> that no error will occur in each coordinate,
then the probability that there are errors in exactly <m>k</m> coordinates is
<me>
\binom{n}{k} q^kp^{n - k}
</me>.
</p>
</statement>
<proof>
<p>
Fix <m>k</m> different coordinates.
We first compute the probability that an error has occurred in this fixed set of coordinates.
The probability of an error occurring in a particular one of these <m>k</m> coordinates is <m>q</m>;
the probability that an error will not occur in any of the remaining <m>n-k</m> coordinates is <m>p</m>.
The probability of each of these <m>n</m> independent events is <m>q^{k}p^{n-k}</m>.
The number of possible error patterns with exactly <m>k</m> errors occurring is equal to
<me>
\binom{n}{k} = \frac{n!}{k!(n - k)!}
</me>,
the number of combinations of <m>n</m> things taken <m>k</m> at a time.
Each of these error patterns has probability <m>q^{k}p^{n-k}</m> of occurring;
hence, the probability of all of these error patterns is
<me>
\binom{n}{k} q^{k}p^{n - k}
</me>.
</p>
</proof>
</theorem>
<example xml:id="algcodes-example-probability">
<p>
Suppose that <m>p = 0.995</m> and a <m>500</m>-bit message is sent.
The probability that the message was sent error-free is
<me>
p^{n} = (0.995)^{500} \approx 0.082
</me>.
The probability of exactly one error occurring is
<me>
\binom{n}{1} qp^{n - 1}= 500(0.005)(0.995)^{499} \approx 0.204
</me>.
The probability of exactly two errors is
<me>
\binom{n}{2} q^{2}p^{n - 2}= \frac{500 \cdot 499}{2}(0.005)^{2}(0.995)^{498} \approx 0.257
</me>.
The probability of more than two errors is approximately
<me>
1 - 0.082 - 0.204 - 0.257 = 0.457
</me>.
</p>
</example>
</subsection>
<subsection xml:id="algcodes-subsection-block-codes">
<title>Block Codes</title>
<p>
If we are to develop efficient error-detecting and error-correcting codes,
we will need more sophisticated mathematical tools.
Group theory will allow faster methods of encoding and decoding messages.
A code is an <m>(n, m)</m>-<term>block code</term>
if the information that is to be coded can be divided into blocks of <m>m</m> binary digits,
each of which can be encoded into <m>n</m> binary digits.
More specifically, an <m>(n, m)</m>-block code consists of an
<term>encoding function</term>
<me>
E:{\mathbb Z}^{m}_{2} \rightarrow {\mathbb Z}^{n}_{2}
</me>
and a <term>decoding function</term>
<me>
D:{\mathbb Z}^{n}_{2} \rightarrow {\mathbb Z}^{m}_{2}
</me>.
A <term>codeword</term> is any element in the image of <m>E</m>.
We also require that <m>E</m> be one-to-one so that two information blocks will not be encoded into the same codeword.
If our code is to be error-correcting,
then <m>D</m> must be onto.
</p>
<example xml:id="algcodes-example-block-code">
<p>
The even-parity coding system developed to detect single errors in <acro>ASCII</acro> characters is an <m>(8,7)</m>-block code.
The encoding function is
<me>
E(x_7, x_6, \ldots, x_1) = (x_8, x_7, \ldots, x_1)
</me>,
where <m>x_8 = x_7 + x_6 + \cdots + x_1</m> with addition in <m>{\mathbb Z}_2</m>.
</p>
</example>
<p>
Let <m>{\mathbf x} = (x_1, \ldots,
x_n)</m> and <m>{\mathbf y} = (y_1, \ldots,
y_n)</m> be binary <m>n</m>-tuples.
The <term>Hamming distance</term><idx><h>Hamming distance</h></idx>
or <term>distance</term>, <m>d({\mathbf x}, {\mathbf y})</m>,
between <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> is the number of bits in which
<m>{\mathbf x}</m> and <m>{\mathbf y}</m> differ.
The distance between two codewords is the minimum number of transmission errors required to change one codeword into the other.
The <term>minimum distance</term><idx><h>Code</h><h>minimum distance of</h></idx> for a code,
<m>d_{\min}</m>,
is the minimum of all distances <m>d({\mathbf x}, {\mathbf y})</m>,
where <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> are distinct codewords.
The <idx><h>Weight of a codeword</h></idx><term>weight</term>,
<m>w({\mathbf x})</m>, of a binary codeword
<m>{\mathbf x}</m> is the number of <m>1</m>s in <m>{\mathbf x}</m>.
Clearly, <m>w({\mathbf x}) = d({\mathbf x}, {\mathbf 0})</m>,
where <m>{\mathbf 0} = (00 \cdots 0)</m>.
<notation>
<usage><m>d(\mathbf x, \mathbf y)</m></usage>
<description>Hamming distance between <m>\mathbf x</m> and <m>\mathbf y</m></description>
</notation>
<notation>
<usage><m>d_{\min}</m></usage>
<description>the minimum distance of a code</description>
</notation>
<notation>
<usage><m>w(\mathbf x)</m></usage>
<description>the weight of <m>\mathbf x</m></description>
</notation>
</p>
<example xml:id="algcodes-example-min-distance">
<p>
Let <m>{\mathbf x} = (10101)</m>,
<m>{\mathbf y} = (11010)</m>,
and <m>{\mathbf z} = (00011)</m> be all of the codewords in some code <m>C</m>.
Then we have the following Hamming distances:
<me>
d({\mathbf x},{\mathbf y}) = 4, \qquad d({\mathbf x},{\mathbf z}) = 3, \qquad d({\mathbf y},{\mathbf z}) = 3
</me>.
The minimum distance for this code is 3.
We also have the following weights:
<me>
w({\mathbf x}) = 3, \qquad w({\mathbf y}) = 3, \qquad w({\mathbf z}) = 2
</me>.
</p>
</example>
<p>
The following proposition lists some basic properties about the weight of a codeword and the distance between two codewords.
The proof is left as an exercise.
</p>
<proposition>
<statement>
<p>
Let <m>{\mathbf x}</m>, <m>{\mathbf y}</m>,
and <m>{\mathbf z}</m> be binary <m>n</m>-tuples.
Then
<ol>
<li>
<p>
<m>w({\mathbf x}) = d( {\mathbf x}, {\mathbf 0})</m>;
</p>
</li>
<li>
<p>
<m>d( {\mathbf x}, {\mathbf y}) \geq 0</m>;
</p>
</li>
<li>
<p>
<m>d( {\mathbf x}, {\mathbf y}) = 0</m> exactly when <m>{\mathbf x} = {\mathbf y}</m>;
</p>
</li>
<li>
<p>
<m>d( {\mathbf x}, {\mathbf y})= d( {\mathbf y}, {\mathbf x})</m>;
</p>
</li>
<li>
<p>
<m>d( {\mathbf x}, {\mathbf y}) \leq d( {\mathbf x}, {\mathbf z}) + d( {\mathbf z}, {\mathbf y})</m>.
</p>
</li>
</ol>
</p>
</statement>
</proposition>
<p>
The weights in a particular code are usually much easier to compute than the Hamming distances between all codewords in the code.
If a code is set up carefully,
we can use this fact to our advantage.
</p>
<p>
Suppose that <m>{\mathbf x} = (1101)</m> and
<m>{\mathbf y} = (1100)</m> are codewords in some code.
If we transmit <m>(1101)</m> and an error occurs in the rightmost bit,
then (1100) will be received.
Since <m>(1100)</m> is a codeword,
the decoder will decode <m>(1100)</m> as the transmitted message.
This code is clearly not very appropriate for error detection.
The problem is that <m>d({\mathbf x}, {\mathbf y}) = 1</m>.
If <m>{\mathbf x} = (1100)</m> and <m>{\mathbf y} = (1010)</m> are codewords,
then <m>d({\mathbf x}, {\mathbf y}) = 2</m>.
If <m>{\mathbf x}</m> is transmitted and a single error occurs,
then <m>{\mathbf y}</m> can never be received.
<xref ref="algcodes-table-4-bit-words"/> gives the distances between all 4-bit codewords in which the first three bits carry information and the fourth is an even parity check bit.
We can see that the minimum distance here is <m>2</m>;
hence, the code is suitable as a single error-detecting code.
</p>
<table xml:id="algcodes-table-4-bit-words">
<title>Distances between 4-bit codewords</title>
<tabular halign="center" top="medium" left="medium" right="medium">
<row bottom="medium">
<cell/>
<cell><m>0000</m></cell>
<cell><m>0011</m></cell>
<cell><m>0101</m></cell>
<cell><m>0110</m></cell>
<cell><m>1001</m></cell>
<cell><m>1010</m></cell>
<cell><m>1100</m></cell>
<cell><m>1111</m></cell>
</row>
<row>
<cell><m>0000</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>4</m></cell>
</row>
<row>
<cell><m>0011</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>4 </m></cell>
<cell><m>2</m></cell>
</row>
<row>
<cell><m>0101</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>4</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
</row>
<row>
<cell><m>0110</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
<cell><m>4</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
</row>
<row>
<cell><m>1001</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>4</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
</row>
<row>
<cell><m>1010</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>4</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
</row>
<row>
<cell><m>1100</m></cell>
<cell><m>2</m></cell>
<cell><m>4</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
<cell><m>2</m></cell>
</row>
<row bottom="medium">
<cell><m>1111</m></cell>
<cell><m>4</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>2</m></cell>
<cell><m>0</m></cell>
</row>
</tabular>
</table>
<p>
To determine exactly what the error-detecting and error-correcting capabilities for a code are,
we need to analyze the minimum distance for the code.
Let <m>{\mathbf x}</m> and <m>{\mathbf y}</m> be codewords.
If <m>d({\mathbf x}, {\mathbf y}) = 1</m> and an error occurs where
<m>{\mathbf x}</m> and <m>{\mathbf y}</m> differ,
then <m>{\mathbf x}</m> is changed to <m>{\mathbf y}</m>.
The received codeword is <m>{\mathbf y}</m> and no error message is given.
Now suppose <m>d({\mathbf x}, {\mathbf y}) = 2</m>.
Then a single error cannot change
<m>{\mathbf x}</m> to <m>{\mathbf y}</m>.
Therefore, if <m>d_{\min} = 2</m>,
we have the ability to detect single errors.
However, suppose that <m>d({\mathbf x}, {\mathbf y}) = 2</m>,
<m>{\mathbf y}</m> is sent,
and a noncodeword <m>{\mathbf z}</m> is received such that
<me>
d({\mathbf x}, {\mathbf z}) = d({\mathbf y}, {\mathbf z}) = 1
</me>.
Then the decoder cannot decide between
<m>{\mathbf x}</m> and <m>{\mathbf y}</m>.
Even though we are aware that an error has occurred,
we do not know what the error is.
</p>
<p>
Suppose <m>d_{\min} \geq 3</m>.
Then the maximum-likelihood decoding scheme corrects all single errors.
Starting with a codeword <m>{\mathbf x}</m>,
an error in the transmission of a single bit gives
<m>{\mathbf y}</m> with <m>d({\mathbf x}, {\mathbf y}) = 1</m>,
but <m>d({\mathbf z}, {\mathbf y}) \geq 2</m> for any other codeword <m>{\mathbf z} \neq {\mathbf x}</m>.
If we do not require the correction of errors,
then we can detect multiple errors when a code has a minimum distance that is greater than or equal to <m>3</m>.
</p>
<theorem xml:id="algcodes-theorem-min-distance">
<statement>
<p>
Let <m>C</m> be a code with <m>d_{\min} = 2n + 1</m>.
Then <m>C</m> can correct any <m>n</m> or fewer errors.
Furthermore,
any <m>2n</m> or fewer errors can be detected in <m>C</m>.
</p>
</statement>
<proof>
<p>
Suppose that a codeword <m>{\mathbf x}</m> is sent and the word
<m>{\mathbf y}</m> is received with at most <m>n</m> errors.
Then <m>d( {\mathbf x}, {\mathbf y}) \leq n</m>.
If <m>{\mathbf z}</m> is any codeword other than <m>{\mathbf x}</m>, then
<me>
2n+1 \leq d( {\mathbf x}, {\mathbf z}) \leq d( {\mathbf x}, {\mathbf y}) + d( {\mathbf y}, {\mathbf z}) \leq n + d( {\mathbf y}, {\mathbf z})
</me>.
Hence, <m>d({\mathbf y}, {\mathbf z} ) \geq n+1</m> and
<m>{\mathbf y}</m> will be correctly decoded as <m>{\mathbf x}</m>.
Now suppose that <m>{\mathbf x}</m> is transmitted and
<m>{\mathbf y}</m> is received and that at least one error has occurred,
but not more than <m>2n</m> errors.
Then <m>1 \leq d( {\mathbf x}, {\mathbf y} ) \leq 2n</m>.
Since the minimum distance between codewords is <m>2n +1</m>,
<m>{\mathbf y}</m> cannot be a codeword.
Consequently,
the code can detect between <m>1</m> and <m>2n</m> errors.
</p>
</proof>
</theorem>
<example xml:id="algcodes-example-single-correct">
<p>
In <xref ref="algcodes-table-hamming-distance"/>,
the codewords <m>{\mathbf c}_1 = (00000)</m>,
<m>{\mathbf c}_2 = (00111)</m>,
<m>{\mathbf c}_3 = (11100)</m>,
and <m>{\mathbf c}_4 = (11011)</m> determine a single error-correcting code.
</p>
<table xml:id="algcodes-table-hamming-distance">
<title>Hamming distances for an error-correcting code</title>
<tabular halign="center" top="medium" left="medium" right="medium">
<row bottom="medium">
<cell/>
<cell><m>00000</m></cell>
<cell><m>00111</m></cell>
<cell><m>11100</m></cell>
<cell><m>11011</m></cell>
</row>
<row>
<cell><m>00000 </m></cell>
<cell><m>0</m></cell>
<cell><m>3</m></cell>
<cell><m>3</m></cell>
<cell><m>4</m></cell>
</row>
<row>
<cell><m>00111 </m></cell>
<cell><m>3</m></cell>
<cell><m>0</m></cell>
<cell><m>4</m></cell>
<cell><m>3</m></cell>
</row>
<row>
<cell><m>11100 </m></cell>
<cell><m>3</m></cell>
<cell><m>4</m></cell>
<cell><m>0</m></cell>
<cell><m>3</m></cell>
</row>
<row bottom="medium">
<cell><m>11011 </m></cell>
<cell><m>4</m></cell>
<cell><m>3</m></cell>
<cell><m>3</m></cell>
<cell><m>0</m></cell>
</row>
</tabular>
</table>
</example>
</subsection>
<subsection xml:id="algcodes-subsection-historical-note">
<title>Historical Note</title>
<p>
Modern coding theory began in 1948 with C. Shannon's<idx><h>Shannon, C.</h></idx>
paper, <q>A Mathematical Theory of Information</q>
[7]. This paper offered an example of an algebraic code,
and Shannon's Theorem proclaimed exactly how good codes could be expected to be.
Richard Hamming<idx><h>Hamming, R.</h></idx>
began working with linear codes at Bell Labs in the late 1940s and early 1950s after becoming frustrated because the programs that he was running could not recover from simple errors generated by noise.
Coding theory has grown tremendously in the past several decades.
<em>The Theory of Error-Correcting Codes</em>,
by MacWilliams and Sloane [5], published in 1977,
already contained over 1500 references.
Linear codes (Reed-Muller <m>(32, 6)</m>-block codes) were used on NASA's Mariner space probes.
More recent space probes such as Voyager have used what are called convolution codes.
Currently, very active research is being done with Goppa codes,
which are heavily dependent on algebraic geometry.
</p>
</subsection>
</section>
<section xml:id="algcodes-section-linear-codes">
<title>Linear Codes</title>
<introduction>
<p>
To gain more knowledge of a particular code and develop more efficient techniques of encoding,
decoding,
and error detection, we need to add additional structure to our codes.
One way to accomplish this is to require that the code also be a group.
A <term>group code</term><idx><h>Code</h><h>group</h></idx>
is a code that is also a subgroup of <m>{\mathbb Z}_2^n</m>.
</p>
<p>
To check that a code is a group code,
we need only verify one thing.
If we add any two elements in the code,
the result must be an <m>n</m>-tuple that is again in the code.
It is not necessary to check that the inverse of the <m>n</m>-tuple is in the code,
since every codeword is its own inverse,
nor is it necessary to check that <m>{\mathbf 0}</m> is a codeword.
For instance,
<me>
(11000101) + (11000101) = (00000000)
</me>.
</p>
<example xml:id="algcodes-example-weights">
<p>
Suppose that we have a code that consists of the following 7-tuples:
<md>
<mrow>&(0000000) & & (0001111) & & (0010101) & & (0011010)</mrow>
<mrow>&(0100110) & & (0101001) & & (0110011) & & (0111100)</mrow>
<mrow>&(1000011) & & (1001100) & & (1010110) & & (1011001)</mrow>
<mrow>&(1100101) & & (1101010) & & (1110000) & & (1111111)</mrow>
</md>.
It is a straightforward though tedious task to verify that this code is also a subgroup of
<m>{\mathbb Z}_2^7</m> and, therefore, a group code.
This code is a single error-detecting and single error-correcting code,
but it is a long and tedious process to compute all of the distances between pairs of codewords to determine that <m>d_{\min} = 3</m>.
It is much easier to see that the minimum weight of all the nonzero codewords is <m>3</m>.
As we will soon see, this is no coincidence.
However, the relationship between weights and distances in a particular code is heavily dependent on the fact that the code is a group.
</p>
</example>
<lemma>
<statement>
<p>
Let <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> be binary <m>n</m>-tuples.
Then <m>w({\mathbf x} + {\mathbf y}) = d({\mathbf x}, {\mathbf y})</m>.
</p>
</statement>
<proof>
<p>
Suppose that <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> are binary <m>n</m>-tuples.
Then the distance between <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> is exactly the number of places in which
<m>{\mathbf x}</m> and <m>{\mathbf y}</m> differ.
But <m>{\mathbf x}</m> and
<m>{\mathbf y}</m> differ in a particular coordinate exactly when the sum in the coordinate is <m>1</m>, since
<md>
<mrow>1 + 1 & = 0</mrow>
<mrow>0 + 0 & = 0</mrow>
<mrow>1 + 0 & = 1</mrow>
<mrow>0 + 1 & = 1</mrow>
</md>.
Consequently,
the weight of the sum must be the distance between the two codewords.
</p>
</proof>
</lemma>
<theorem>
<statement>
<p>
Let <m>d_{\min}</m> be the minimum distance for a group code <m>C</m>.
Then <m>d_{\min}</m> is the minimum weight of all the nonzero codewords in <m>C</m>.
That is,
<me>
d_{\min} = \min\{ w({\mathbf x}) : { {\mathbf x} \neq {\mathbf 0} } \}
</me>.
</p>
</statement>
<proof>
<p>
Observe that
<md>
<mrow>d_{\min} & = \min \{ d({\mathbf x},{\mathbf y}) : {\mathbf x}\neq{\mathbf y} \}</mrow>
<mrow>&= \min \{ d({\mathbf x},{\mathbf y}) : {\mathbf x}+{\mathbf y} \neq {\mathbf 0} \}</mrow>
<mrow>&= \min\{ w({\mathbf x} + {\mathbf y}) : {\mathbf x}+{\mathbf y}\neq {\mathbf 0} \}</mrow>
<mrow>& = \min\{ w({\mathbf z}) : {\mathbf z} \neq {\mathbf 0} \}</mrow>
</md>.
</p>
</proof>
</theorem>
</introduction>
<subsection xml:id="algcodes-subsection-linear-codes">
<title>Linear Codes</title>
<p>
From <xref ref="algcodes-example-weights"/>,
it is now easy to check that the minimum nonzero weight is <m>3</m>;
hence, the code does indeed detect and correct all single errors.
We have now reduced the problem of finding <q>good</q>
codes to that of generating group codes.
One easy way to generate group codes is to employ a bit of matrix theory.
</p>
<p>
Define the <term>inner product</term><idx><h>Inner product</h></idx>
of two binary <m>n</m>-tuples to be
<me>
{\mathbf x} \cdot {\mathbf y} = x_1 y_1 + \cdots + x_n y_n
</me>,
where <m>{\mathbf x} = (x_1, x_2, \ldots,
x_n)^\transpose</m> and <m>{\mathbf y} = (y_1, y_2, \ldots,
y_n)^\transpose</m> are column vectors.<fn>
Since we will be working with matrices,
we will write binary <m>n</m>-tuples as column vectors for the remainder of this chapter.
</fn> For example,
if <m>{\mathbf x} = (011001)^\transpose</m> and <m>{\mathbf y} = (110101)^\transpose</m>,
then <m>{\mathbf x} \cdot {\mathbf y} = 0</m>.
We can also look at an inner product as the product of a row matrix with a column matrix; that is,
<md>
<mrow>{\mathbf x} \cdot {\mathbf y} & = {\mathbf x}^\transpose {\mathbf y}</mrow>
<mrow>& =
\begin{pmatrix}
x_1 & x_2 & \cdots & x_n
\end{pmatrix}
\begin{pmatrix}
y_1 \\ y_2 \\ \vdots \\ y_n
\end{pmatrix}</mrow>
<mrow>& = x_{1}y_{1} + x_{2}y_{2} + \cdots + x_{n}y_{n}</mrow>
</md>.
</p>
<example xml:id="algcodes-example-matrixcodes">
<p>
Suppose that the words to be encoded consist of all binary <m>3</m>-tuples and that our encoding scheme is even-parity.
To encode an arbitrary <m>3</m>-tuple,
we add a fourth bit to obtain an even number of <m>1</m>s.
Notice that an arbitrary <m>n</m>-tuple
<m>{\mathbf x} = (x_1, x_2, \ldots,
x_n)^\transpose</m> has an even number of <m>1</m>s exactly when <m>x_1 + x_2 + \cdots + x_n = 0</m>;
hence, a <m>4</m>-tuple <m>{\mathbf x} = (x_1, x_2, x_3, x_4)^\transpose</m> has an even number of <m>1</m>s if <m> x_1+ x_2+ x_3+ x_4 = 0</m>, or
<me>
{\mathbf x} \cdot {\mathbf 1} = {\mathbf x}^\transpose {\mathbf 1} =
\begin{pmatrix}
x_1 & x_2 & x_3 & x_4
\end{pmatrix}
\begin{pmatrix}
1 \\ 1 \\ 1 \\ 1
\end{pmatrix} = 0
</me>.
This example leads us to hope that there is a connection between matrices and coding theory.
</p>
</example>
<p>
Let <m>{\mathbb M}_{m \times n}({\mathbb Z}_2)</m> denote the set of all
<m>m \times n</m> matrices with entries in <m>{\mathbb Z}_2</m>.
We do matrix operations as usual except that all our addition and multiplication operations occur in <m>{\mathbb Z}_2</m>.
Define the <term>null space</term><idx><h>Matrix</h><h>null space of</h></idx><idx><h>Null space</h><h>of a matrix</h></idx> of a matrix
<m>H \in {\mathbb M}_{m \times n}({\mathbb Z}_2)</m> to be the set of all binary <m>n</m>-tuples
<m>{\mathbf x}</m> such that <m>H{\mathbf x} = {\mathbf 0}</m>.
We denote the null space of a matrix <m>H</m> by <m>\Null(H)</m>.
<notation>
<usage><m>\mathbb M_{m \times n}(\mathbf Z_2)</m></usage>
<description>the set of <m>m \times n</m> matrices with entries in <m>\mathbb Z_2</m></description>
</notation>
<notation>
<usage><m>\Null(H)</m></usage>
<description>null space of a matrix <m>H</m></description>
</notation>
</p>
<example xml:id="algcodes-example-group-code">
<p>
Suppose that
<me>
H =
\begin{pmatrix}
0 & 1 & 0 & 1 & 0 \\
1 & 1 & 1 & 1 & 0 \\
0 & 0 & 1 & 1 & 1
\end{pmatrix}
</me>.
For a <m>5</m>-tuple <m>{\mathbf x} = (x_1, x_2, x_3, x_4, x_5)^\transpose</m> to be in the null space of <m>H</m>,
<m>H{\mathbf x} = {\mathbf 0}</m>.
Equivalently,
the following system of equations must be satisfied:
<md>
<mrow>x_2 + x_4 & = 0</mrow>
<mrow>x_1 + x_2 + x_3 + x_4 & = 0</mrow>
<mrow>x_3 + x_4 + x_5 & = 0</mrow>
</md>.
The set of binary <m>5</m>-tuples satisfying these equations is
<me>
(00000) \qquad (11110) \qquad (10101) \qquad (01011)
</me>.
This code is easily determined to be a group code.
</p>
</example>
<theorem>
<statement>
<p>
Let <m>H</m> be in <m>{\mathbb M}_{m \times n}({\mathbb Z}_2)</m>.
Then the null space of <m>H</m> is a group code.
</p>
</statement>
<proof>
<p>
Since each element of <m>{\mathbb Z}_2^n</m> is its own inverse,
the only thing that really needs to be checked here is closure.
Let <m>{\mathbf x}, {\mathbf y} \in \Null(H)</m> for some matrix <m>H</m> in <m>{\mathbb M}_{m \times n}({\mathbb Z}_2)</m>.
Then <m>H{\mathbf x} = {\mathbf 0}</m> and <m>H{\mathbf y} = {\mathbf 0}</m>.
So
<me>
H({\mathbf x}+{\mathbf y}) = H{\mathbf x} + H{\mathbf y} = {\mathbf 0} + {\mathbf 0} = {\mathbf 0}
</me>.
Hence, <m>{\mathbf x} + {\mathbf y}</m> is in the null space of <m>H</m> and therefore must be a codeword.
</p>
</proof>
</theorem>
<!-- typo correction. Suggested by J. Buller. -->