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
|
{
"metadata": {
"name": "",
"signature": "sha256:6e9582656e16b2ddb2a1a599466d473ed1824284ac996f30e627d64aae2d0daa"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"10 Groups and rings"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 09:Page 457"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"(3,4) parity check code.\"\n",
"def parity_checker(word):\n",
" count=0#Initially the number of 1s is zero\n",
" for i in range(0,4):#Ranges till 4 as the size of the received word is 4\n",
" if word[i]!='0':\n",
" count=count+1#Counts the number of 1s in the given code\n",
" \n",
" if count%2==0:#Even weight can only be detected by this checker\n",
" return \"No, error cannot be detected\"\n",
" else:\n",
" return \"Yes, error can be detected\"\n",
"print \"0010-\",parity_checker(str('0010'))\n",
"print \"1001-\",parity_checker(str('1001'))\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(3,4) parity check code.\n",
"0010- Yes, error can be detected\n",
"1001- No, error cannot be detected\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 10:Page 457"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"(6,7) parity check code.\"\n",
"def parity_checker(word):\n",
" count=0#Initially the number of 1s is zero\n",
" for i in range(0,7):#Ranges till 7 as the received word consists of 7 digits\n",
" if word[i]!='0':\n",
" count=count+1#Counts the number of 1s in the given code\n",
" \n",
" if count%2==0:#Even weight can only be detected by this checker\n",
" return \"No, error cannot be detected\"\n",
" else:\n",
" return \"Yes, error can be detected\"\n",
" \n",
"\n",
"print \"1101010-\",parity_checker(str('1101010'))\n",
"print \"1010011-\",parity_checker(str('1010011'))\n",
"print \"0011111-\",parity_checker(str('0011111'))\n",
"print \"1001101-\",parity_checker(str('1001101'))\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"(6,7) parity check code.\n",
"1101010- No, error cannot be detected\n",
"1010011- No, error cannot be detected\n",
"0011111- Yes, error can be detected\n",
"1001101- No, error cannot be detected\n"
]
}
],
"prompt_number": 2
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 11:Page 457"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"Consider (2,6) encoding function\"\n",
"encode=[\"00\",\"01\",\"10\",\"11\"]#Set of data to be encoded\n",
"k=0#Value for filling the distance is initially set to zero\n",
"distance=[\"\" for i in range(7)]#Array that can hold all possible combinations of distance value ie. 6 combinations\n",
"def e(word):#Function that returns the encoded value\n",
" \n",
" if word==\"00\":\n",
" return str(\"000000\")\n",
" elif word==\"10\":\n",
" return str(\"101010\")\n",
" elif word==\"01\":\n",
" return str(\"011110\")\n",
" elif word==\"11\":\n",
" return str(\"111000\")\n",
"def d(word1,word2):\n",
" \n",
" count=0#Variable that counts the number of 1s\n",
" data1=str(e(word1))\n",
" \n",
" data2=str(e(word2))#Convert into string for indexing which facilitates bitwise operation\n",
" \n",
" for i in range(0,6):\n",
" if data1[i]!=data2[i]:\n",
" count=count+1#XOR implementation\n",
" return count\n",
"for i in range(0,4):\n",
" for j in range(i+1,4):\n",
" \n",
" distance[k]=d(encode[i],encode[j])\n",
" print \"d(e(\",encode[i],\"),e(\",encode[j],\"))=\",distance[k]\n",
" k=k+1\n",
"print \"Minimum distance is\",min(distance)#Finds the minimum distance\n",
"print \"Since the minimum distance is\",min(distance),\"the code will detect\",(min(distance)-1),\"or fewer errors\"\n",
" \n",
" \n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Consider (2,6) encoding function\n",
"d(e( 00 ),e( 01 ))= 4\n",
"d(e( 00 ),e( 10 ))= 3\n",
"d(e( 00 ),e( 11 ))= 3\n",
"d(e( 01 ),e( 10 ))= 3\n",
"d(e( 01 ),e( 11 ))= 3\n",
"d(e( 10 ),e( 11 ))= 2\n",
"Minimum distance is 2\n",
"Since the minimum distance is 2 the code will detect 1 or fewer errors\n"
]
}
],
"prompt_number": 3
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 12:Page 458"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"Consider (3,9) encoding function\"\n",
"encode=[\"000\",\"001\",\"010\",\"011\",\"100\",\"101\",\"110\",\"111\"]#Set of data to be encoded\n",
"k=0#Value for filling the distance is initially set to zero\n",
"distance=[\"\" for i in range(28)]#Array that can hold all possible combinations of distance value ie. 6 combinations\n",
"def e(word):#Function that returns the encoded value\n",
" \n",
" if word==\"000\":\n",
" return str(\"000000000\")\n",
" elif word==\"001\":\n",
" return str(\"011100101\")\n",
" elif word==\"010\":\n",
" return str(\"010101000\")\n",
" elif word==\"011\":\n",
" return str(\"110010001\")\n",
" elif word==\"100\":\n",
" return str(\"010011010\")\n",
" elif word==\"101\":\n",
" return str(\"111101011\")\n",
" elif word==\"110\":\n",
" return str(\"001011000\")\n",
" elif word==\"111\":\n",
" return str(\"110000111\")\n",
"def d(word1,word2):\n",
" \n",
" count=0#Variable that counts the number of 1s\n",
" data1=str(e(word1))\n",
" \n",
" data2=str(e(word2))#Convert into string for indexing which facilitates bitwise operation\n",
" \n",
" for i in range(0,9):#Since it is a (3,9) encoder\n",
" if data1[i]!=data2[i]:\n",
" count=count+1#XOR implementation\n",
" return count\n",
"for i in range(0,8):#Since there are eight possibilities with three digits\n",
" for j in range(i+1,8):\n",
" \n",
" distance[k]=d(encode[i],encode[j])\n",
" print \"d(e(\",encode[i],\"),e(\",encode[j],\"))=\",distance[k]\n",
" k=k+1\n",
"print \"Minimum distance is\",min(distance)#Finds the minimum distance\n",
"print \"Since the minimum distance is\",min(distance),\"the code will detect\",(min(distance)-1),\"or fewer errors\"\n",
" \n",
" \n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Consider (3,9) encoding function\n",
"d(e( 000 ),e( 001 ))= 5\n",
"d(e( 000 ),e( 010 ))= 3\n",
"d(e( 000 ),e( 011 ))= 4\n",
"d(e( 000 ),e( 100 ))= 4\n",
"d(e( 000 ),e( 101 ))= 7\n",
"d(e( 000 ),e( 110 ))= 3\n",
"d(e( 000 ),e( 111 ))= 5\n",
"d(e( 001 ),e( 010 ))= 4\n",
"d(e( 001 ),e( 011 ))= 5\n",
"d(e( 001 ),e( 100 ))= 7\n",
"d(e( 001 ),e( 101 ))= 4\n",
"d(e( 001 ),e( 110 ))= 6\n",
"d(e( 001 ),e( 111 ))= 4\n",
"d(e( 010 ),e( 011 ))= 5\n",
"d(e( 010 ),e( 100 ))= 3\n",
"d(e( 010 ),e( 101 ))= 4\n",
"d(e( 010 ),e( 110 ))= 4\n",
"d(e( 010 ),e( 111 ))= 6\n",
"d(e( 011 ),e( 100 ))= 4\n",
"d(e( 011 ),e( 101 ))= 5\n",
"d(e( 011 ),e( 110 ))= 5\n",
"d(e( 011 ),e( 111 ))= 3\n",
"d(e( 100 ),e( 101 ))= 5\n",
"d(e( 100 ),e( 110 ))= 3\n",
"d(e( 100 ),e( 111 ))= 5\n",
"d(e( 101 ),e( 110 ))= 6\n",
"d(e( 101 ),e( 111 ))= 4\n",
"d(e( 110 ),e( 111 ))= 8\n",
"Minimum distance is 3\n",
"Since the minimum distance is 3 the code will detect 2 or fewer errors\n"
]
}
],
"prompt_number": 4
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example 13:Page 458"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print \"To prove the given set to be a group code\"\n",
"print \"Since 00000 belongs to the set, identity is satisfied\"\n",
"result=[\"\" for i in range(5)]#List that holds the result of xor\n",
"word=['00000','10101','01110','11011']#Initial set of encoded words\n",
"count=0#Variable that counts the number of pairs that satisfies the closure property\n",
"for i in range(0,4):\n",
" for j in range(i+1,4):#Possible combinations of words\n",
" data1=word[i]\n",
" data2=word[j]\n",
" print \"\\n\"\n",
" print data1,\"exor\",data2,\"=\",\n",
" for k in range(0,5):#XOR gate operations\n",
" if data1[k]!=data2[k]:\n",
" result[k]=1\n",
" print result[k],\n",
" else:\n",
" \n",
" result[k]=0\n",
" print result[k],\n",
" result1=''.join(str(e) for e in result)#Converts list to string for comparing purpose\n",
" for r in range(0,4):#Checks if it belongs to the given set of words\n",
" \n",
" if result1==word[r]:\n",
" count=count+1\n",
"if count==6:#Since there are 6 possible pairs of words\n",
" print \"\\nClosure property is satisfied as we found that if x and y belongs to the set, then x xor y also belongs to the set.\"\n",
"else:\n",
" print \"Closure property is not satisfied\"\n",
" \n",
"print \"Associativity can be satisfies and also each element has an inverse.\"\n",
"print \"Hence, it is a group code\"\n"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"To prove the given set to be a group code\n",
"Since 00000 belongs to the set, identity is satisfied\n",
"\n",
"\n",
"00000 exor 10101 = 1 0 1 0 1 \n",
"\n",
"00000 exor 01110 = 0 1 1 1 0 \n",
"\n",
"00000 exor 11011 = 1 1 0 1 1 \n",
"\n",
"10101 exor 01110 = 1 1 0 1 1 \n",
"\n",
"10101 exor 11011 = 0 1 1 1 0 \n",
"\n",
"01110 exor 11011 = 1 0 1 0 1 \n",
"Closure property is satisfied as we found that if x and y belongs to the set, then x xor y also belongs to the set.\n",
"Associativity can be satisfies and also each element has an inverse.\n",
"Hence, it is a group code\n"
]
}
],
"prompt_number": 5
}
],
"metadata": {}
}
]
}
|