File: codeops.gd

package info (click to toggle)
gap-guava 3.20%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,804 kB
  • sloc: ansic: 20,501; xml: 10,382; makefile: 254; sh: 55
file content (465 lines) | stat: -rw-r--r-- 15,813 bytes parent folder | download
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
#############################################################################
##
#A  codeops.gd               GUAVA                              Reinald Baart
#A                                                        &Jasper Cramwinckel
#A                                                           &Erik Roijackers
##
##  All the code operations
##
##  20 Dec 07 14:24 (CJ) added IsDoublyEvenCode, IsSinglyEvenCode
##                       and IsEvenCode functions
##

#############################################################################
##
#F  WordLength( <C> ) . . . . . . . . . . . .  length of the codewords of <C>
##

#############################################################################
##
#F  IsLinearCode( <C> ) . . . . . . . . . . . . . . . checks if <C> is linear
##
## If so, the record fields will be adjusted to the linear representation
##
DeclareProperty("IsLinearCode", IsCode);

#############################################################################
##
#F  Redundancy( <C> ) . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##
DeclareAttribute("Redundancy", IsCode);


#############################################################################
##
#F  GeneratorMat(C) . . . . .  finds the generator matrix belonging to code C
##
##  Pre: C should contain a generator or check matrix
##
DeclareAttribute("GeneratorMat", IsCode);

#############################################################################
##
#F  CheckMat( <C> ) . . . . . . .  finds the check matrix belonging to code C
##
##  Pre: <C> should be a linear code
##
DeclareAttribute("CheckMat", IsCode);


#############################################################################
##
#F  IsCyclicCode( <C> ) . . . . . . . . . . . . . . . . . . . . . . . . . .
##
DeclareProperty("IsCyclicCode", IsLinearCode);


#############################################################################
##
#F  GeneratorPol( <C> ) . . . . . . . . returns the generator polynomial of C
##
##  Pre: C must have a generator or check polynomial
##
DeclareAttribute("GeneratorPol", IsCode);


#############################################################################
##
#F  CheckPol( <C> ) . . . . . . . .  returns the parity check polynomial of C
##
##  Pre: C must have a generator or check polynomial
##
DeclareAttribute("CheckPol", IsCode);


#############################################################################
##
#F  MinimumDistance( <C> [, <w>] )  . . . .  determines the minimum distance
##
##  MinimumDistance( <C> ) determines the minimum distance of <C>
##  MinimumDistance( <C>, <w> ) determines the minimum distance to a word <w>
##
DeclareAttribute("MinimumDistance", IsCode);


#############################################################################
##
#F  MinimumDistanceCodeword( <C> [, <w>] )  . . . .  determines the minimum
##                                      distance having  minimum distance to w
##                                      (w= zero vector is the default)
##  MinimumDistance( <C>, <w> ) determines the minimum distance to a word <w>
##
DeclareAttribute("MinimumDistanceCodeword", IsCode);

#############################################################################
##
##  MinimumDistanceLeon( <C>, [<p>,<num>] ) determines the minimum distance of <C>
##
DeclareAttribute("MinimumDistanceLeon", IsLinearCode);

#############################################################################
##
##  MinimumDistanceLeon2( <C, p, num> ) determines the minimum distance of <C>
##
#DeclareAttribute("MinimumDistanceLeon2", IsLinearCode, IsInt, IsInt);

#############################################################################
##
#F  DesignedDistance( arg )  . . . . . . . . . . . . . . . . . . . . . . . .
##
##  Cannot be calculated.  Must be set at creation, if at all.
DeclareAttribute("DesignedDistance", IsCode);


#############################################################################
##
#F  LowerBoundMinimumDistance( arg )  . . . . . . . . . . . . . . . . . . .
##
DeclareOperation("LowerBoundMinimumDistance", [IsCode]);


#############################################################################
##
#F  UpperBoundMinimumDistance( arg )  . . . . . . . . . . . . . . . . . . .
##
DeclareOperation("UpperBoundMinimumDistance", [IsCode]);

#############################################################################
##
#F  UpperBoundOptimalMinimumDistance( arg )  . . . . . . . . . . . . . . . .
##
##  UpperBoundMinimumDistance of optimal code with same parameters
##
DeclareAttribute("UpperBoundOptimalMinimumDistance", IsCode);


#############################################################################
##
#F  MinimumWeightOfGenerators( arg )  . . . . . . . . . . . . . . . . . . . .
##
##
DeclareAttribute("MinimumWeightOfGenerators", IsCode);


#############################################################################
##
#F  MinimumWeightWords( <C> ) . . .  returns the code words of minimum weight
##
DeclareAttribute("MinimumWeightWords", IsCode);


#############################################################################
##
#F  WeightDistribution( <C> ) . . . returns the weight distribution of a code
##
DeclareAttribute("WeightDistribution", IsCode);


#############################################################################
##
#F  InnerDistribution( <C> )  . . . . . .  the inner distribution of the code
##
##  The average distance distribution of distances between all codewords
##
DeclareAttribute("InnerDistribution", IsCode);


#############################################################################
##
#F  OuterDistribution( <C> )  . . . . . . . . . . . . . . . . . . . . . . .
##
##  the number of codewords on a distance i from all elements of GF(q)^n
##
DeclareAttribute("OuterDistribution", IsCode);


#############################################################################
##
#F  CodewordVector( <l>, <C> )
##
##  returns the element of the code <C> corresponding to the coefficient
##  list <l>. This is a synonym for \* for codes
DeclareOperation("CodewordVector", [IsList, IsCode]);


#############################################################################
##
#F  InformationWord( C, c )  . . . . . . . "decodes" a codeword in C to the
##                                information "message" word m, so m*C=c
##
DeclareOperation("InformationWord", [IsCode,IsCodeword]);


#############################################################################
##
#F  IsSelfDualCode( <C> ) . . . . . . . . . determines whether C is self dual
##
##  i.o.w. each codeword is orthogonal to all codewords (including itself)
##
DeclareProperty("IsSelfDualCode", IsCode);


#############################################################################
##
#F  \*( <l>, <C> )  . . . . .  the codeword belonging to information vector x
##
##  only valid if C is linear!
##


#############################################################################
##
#F  \+( <l>, <C> )  . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##
##DeclareOperation("\+", [IsCodeword,IsCode]);

#############################################################################
##
#F  \+( <C>, <l> )  . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##
##DeclareOperation("\+", [IsCode,IsCodeword]);

#############################################################################
##
#F  \+( <C>, <C> )  . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##
##DeclareOperation("\+", [IsCode,IsCode]);

#############################################################################
##
#F  \in( <l>, <C> ) . . . . . .  true if the vector is an element of the code
##
##


#############################################################################
##
#F  \=( <C1>, <C2> )  . . . . .  tests if Set(Elements(C1))=Set(Elements(C2))
##
##  Post: returns a boolean
##


#############################################################################
##
#F  SyndromeTable ( <C> ) . . . . . . . . . . . . . . . a Syndrome table of C
##
DeclareAttribute("SyndromeTable", IsCode);


#############################################################################
##
#F  StandardArray( <C> )  . . . . . . . . . . . . a standard array for code C
##
##  Post: returns a 3D-matrix. The first row contains all the codewords of C.
##  The other rows contain the cosets, preceded by their coset leaders.
##
DeclareAttribute("StandardArray", IsCode);


#############################################################################
##
#F  AutomorphismGroup( <C> )  . . . . . . . .  the automorphism group of code
##
##  The automorphism group is the largest permutation group of degree n such
##  that for each permutation in the group C' = C. Binary codes only. Calls
##  Leon's C code.
##
DeclareAttribute("AutomorphismGroup", IsCode);

#############################################################################
##
#F  PermutationGroup( <C> )  . . . . . . . .  the permutation group of code
##
##  The largest permutation group of degree n such
##  that for each permutation pn in the group pC = C. Written in GAP.
##  May be removed in future versions.
##
DeclareAttribute("PermutationGroup", IsCode);


#############################################################################
##
#F  PermutationAutomorphismGroup( <C> )  . . . . the permutation group of code
##
##  The largest permutation group of degree n such
##  that for each permutation pn in the group pC = C. Written in GAP.
##
DeclareAttribute("PermutationAutomorphismGroup", IsCode);

#############################################################################
##
#F  IsSelfOrthogonalCode( <C> ) . . . . . . . . . . . . . . . . . . . . . .
##
DeclareProperty("IsSelfOrthogonalCode", IsCode);

#############################################################################
##
#F  IsDoublyEvenCode( <C> ) . . . . . . . . . . . . . . . . . . . . . . . .
##
##  Return true if and only if the code C is a binary linear code which has
##  all codewords of weight divisible by 4 only.
##
##  If a binary linear code is self-orthogonal and the weight of each row
##  in its generator matrix is divisibly by 4, the code is doubly-even
##  (see Theorem 1.4.8 in  W. C. Huffman and V. Pless, "Fundamentals of
##  error-correcting codes", Cambridge Univ. Press, 2003.)
##
DeclareProperty("IsDoublyEvenCode", IsLinearCode);

#############################################################################
##
#F  IsSinglyEvenCode( <C> ) . . . . . . . . . . . . . . . . . . . . . . . .
##
##  Return true if and only if the code C is a self-orthogonal binary linear
##  code which is not doubly-even.
##
DeclareProperty("IsSinglyEvenCode", IsLinearCode);

#############################################################################
##
#F  IsEvenCode( <C> ) . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##  Return true if and only if the code C is a binary linear code which has
##  even weight codewords--regardless whether or not it is self-orgthogonal.
##
DeclareProperty("IsEvenCode", IsLinearCode);

#############################################################################
##
#F  CodeIsomorphism( <C1>, <C2> ) . . the permutation that translates C1 into
#F                         C2 if C1 and C2 are equivalent, or false otherwise
##
DeclareOperation("CodeIsomorphism", [IsCode, IsCode]);


#############################################################################
##
#F  IsEquivalent( <C1>, <C2> )  . . . . . .  true if C1 and C2 are equivalent
##
##  that is if there exists a permutation that transforms C1 into C2.
##  If returnperm is true, this permutation (if it exists) is returned;
##  else the function only returns true or false.
##
DeclareOperation("IsEquivalent", [IsCode, IsCode]);


#############################################################################
##
#F  RootsOfCode( <C> )  . . . .  the roots of the generator polynomial of <C>
##
##  It finds the roots by trying all elements of the extension field
##
DeclareAttribute("RootsOfCode", IsCode);


#############################################################################
##
#F  DistancesDistribution( <C>, <w> ) . . .  distribution of distances from a
#F                                               word w to all codewords of C
##
DeclareOperation("DistancesDistribution", [IsCode, IsCodeword]);


#############################################################################
##
#F  Syndrome( <C>, <c> )  . . . . . . .  the syndrome of word <c> in code <C>
##
DeclareOperation("Syndrome", [IsCode, IsCodeword]);


#############################################################################
##
#F  CodewordNr( <C>, <i> )  . . . . . . . . . . . . . . . . .  elements(C)[i]
##
DeclareOperation("CodewordNr", [IsCode, IsList]);


#############################################################################
##
#F  String( <C> ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
##
##


#############################################################################
##
#F  CodeDescription( <C> )  . . . . . . . . . . . . . . . . . . . . . . . . .
##
DeclareOperation("CodeDescription", [IsCode]);


#############################################################################
##
#F  Print( <C> )  . . . . . . . . . . . . .  prints short information about C
##
##


#############################################################################
##
#F  Display( <C> )  . . . . . . . . . . . .  prints the history of the code C
##
##


#############################################################################
##
#F  Save( <filename>, <C>, <var-name> ) . . . . . writes the code C to a file
##
##  with variable name var-name. It can be read back by calling
##  Read (filename); the code then has the name var-name.
##  All fields of the code record are stored except,
##  in case of a linear or cyclic code, the elements.
##  Pre: filename is accessible for writing
##
DeclareOperation("Save", [IsString, IsCode, IsString]);


#############################################################################
##
#F  History( <C> )  . . . . . . . . . . . . . . . shows the history of a code
##
DeclareOperation("History", [IsCode]);


######################################################################################
#F           MinimumDistanceRandom( <C>, <num>, <s> )
##
## This is a simpler version than Leon's method, which does not put G in st form.
## (this works welland is in some cases faster than the st form one)
## Input: C is a linear code
##        num is an integer >0 which represents the number of iterations
##        s is an integer between 1 and n which represents the columns considered
##           in the algorithm.
## Output: an integer >= min dist(C), and hopefully equal to it!
##         a codework of that weight
##
## Algorithm: randomly permute the columns of the gen mat G of C
##              by a permutation rho - call new mat Gp
##            break Gp into (A,B), where A is kxs and B is kx(n-s)
##            compute code C_A generated by rows of A
##            find min weight codeword c_A of C_A and w_A=wt(c_A)
##              using AClosestVectorCombinationsMatFFEVecFFECoords
##            extend c_A to a corresponding codeword c_p in C_Gp
##            return c=rho^(-1)(c_p) and wt=wt(c_p)=wt(c)
##
DeclareOperation("MinimumDistanceRandom",[IsCode,IsInt,IsInt]);

############################################################################
#F  MinimumWeight( <C> )
##
## This function calls an external C program to compute the minimum Hamming
## weight of a linear code over GF(2) and GF(3). The external program is
## "minimum-weight"
##
## Author: CJ, Tjhai
##
DeclareAttribute("MinimumWeight", IsLinearCode);

DeclareOperation("GuavaCosetLeadersMatFFE",[IsMatrix,IsFFECollection]);