177
177
from .delsarte_bounds import delsarte_bound_hamming_space , \
178
178
delsarte_bound_additive_hamming_space
179
179
180
- def _check_n_q_d (n , q , d ):
180
+ def _check_n_q_d (n , q , d , field_based = True ):
181
181
r"""
182
182
Check that the length `n`, alphabet size `q` and minimum distance `d` type
183
183
check and make sense for a code over a field.
184
184
185
185
More precisely, checks that the parameters are positive integers, that `q`
186
- is a prime power, and that `n >= d`. Raises a ``ValueError`` otherwise.
186
+ is a prime power for codes over a field, or, more generally, that
187
+ `q` is of size at least 2, and that `n >= d`. Raises a ``ValueError``
188
+ otherwise.
187
189
188
- EXAMPLES ::
190
+ TESTS ::
189
191
190
192
sage: from sage.coding.code_bounds import _check_n_q_d
191
193
sage: _check_n_q_d(20, 16, 5)
192
194
True
193
- sage: _check_n_q_d(20, 16, 21)
195
+ sage: _check_n_q_d(20, 16, 6, field_based=False)
196
+ True
197
+ sage: _check_n_q_d(20, 21, 16)
198
+ Traceback (most recent call last):
199
+ ...
200
+ ValueError: The alphabet size does not make sense for a code over a field
201
+ sage: _check_n_q_d(20, -21, 16)
202
+ Traceback (most recent call last):
203
+ ...
204
+ ValueError: The alphabet size must be an integer >1
205
+ sage: _check_n_q_d(20, 2, 26)
194
206
Traceback (most recent call last):
195
207
...
196
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
208
+ ValueError: The length or minimum distance does not make sense
197
209
"""
198
- if not ( is_prime_power (q ) and d > 0 and n >= d and n in ZZ and d in ZZ ):
199
- raise ValueError ("The length, alphabet size and minimum distance does not make sense for a code over a field" )
210
+ if (q not in ZZ ) or (q < 2 ):
211
+ raise ValueError ("The alphabet size must be an integer >1" )
212
+ if field_based == True and (not is_prime_power (q )):
213
+ raise ValueError ("The alphabet size does not make sense for a code over a field" )
214
+ if not ( d > 0 and n >= d and n in ZZ and d in ZZ ):
215
+ raise ValueError ("The length or minimum distance does not make sense" )
200
216
return True
201
217
202
218
@@ -248,12 +264,13 @@ def codesize_upper_bound(n,d,q,algorithm=None):
248
264
20
249
265
250
266
Meaningless parameters are rejected::
251
- sage: codes.bounds.codesize_upper_bound(10, 20, 16)
267
+
268
+ sage: codes.bounds.codesize_upper_bound(10, -20, 6)
252
269
Traceback (most recent call last):
253
270
...
254
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
271
+ ValueError: The length or minimum distance does not make sense
255
272
"""
256
- _check_n_q_d (n , q , d )
273
+ _check_n_q_d (n , q , d , field_based = False )
257
274
if algorithm == "gap" :
258
275
gap .load_package ('guava' )
259
276
return int (gap .eval ("UpperBound(%s,%s,%s)" % ( n , d , q )))
@@ -288,11 +305,10 @@ def dimension_upper_bound(n,d,q,algorithm=None):
288
305
289
306
Meaningless code parameters are rejected::
290
307
291
- sage: codes.bounds.dimension_upper_bound(-3 ,3,2 )
308
+ sage: codes.bounds.dimension_upper_bound(13 ,3,6 )
292
309
Traceback (most recent call last):
293
310
...
294
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
295
-
311
+ ValueError: The alphabet size does not make sense for a code over a field
296
312
"""
297
313
_check_n_q_d (n , q , d )
298
314
q = ZZ (q )
@@ -328,17 +344,8 @@ def gilbert_lower_bound(n,q,d):
328
344
329
345
sage: codes.bounds.gilbert_lower_bound(10,2,3)
330
346
128/7
331
-
332
- TESTS:
333
-
334
- Meaningless parameters are rejected::
335
-
336
- sage: codes.bounds.gilbert_lower_bound(10, 6, 3)
337
- Traceback (most recent call last):
338
- ...
339
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
340
347
"""
341
- _check_n_q_d (n , q , d )
348
+ _check_n_q_d (n , q , d , field_based = False )
342
349
ans = q ** n / volume_hamming (n ,q ,d - 1 )
343
350
return ans
344
351
@@ -359,17 +366,8 @@ def plotkin_upper_bound(n,q,d, algorithm=None):
359
366
192
360
367
sage: codes.bounds.plotkin_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
361
368
192
362
-
363
- TESTS:
364
-
365
- Meaningless parameters are rejected::
366
-
367
- sage: codes.bounds.plotkin_upper_bound(10, 16, 20)
368
- Traceback (most recent call last):
369
- ...
370
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
371
369
"""
372
- _check_n_q_d (n , q , d )
370
+ _check_n_q_d (n , q , d , field_based = False )
373
371
if algorithm == "gap" :
374
372
gap .load_package ("guava" )
375
373
ans = gap .eval ("UpperBoundPlotkin(%s,%s,%s)" % (n ,d ,q ))
@@ -425,13 +423,6 @@ def griesmer_upper_bound(n,q,d,algorithm=None):
425
423
243
426
424
sage: codes.bounds.griesmer_upper_bound(11,3,6)
427
425
243
428
-
429
- Meaningless parameters are rejected::
430
-
431
- sage: codes.bounds.griesmer_upper_bound(10, 16, 20)
432
- Traceback (most recent call last):
433
- ...
434
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
435
426
"""
436
427
_check_n_q_d (n , q , d )
437
428
if algorithm == "gap" :
@@ -466,17 +457,8 @@ def elias_upper_bound(n,q,d,algorithm=None):
466
457
232
467
458
sage: codes.bounds.elias_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
468
459
232
469
-
470
- TESTS:
471
-
472
- Meaningless parameters are rejected::
473
-
474
- sage: codes.bounds.elias_upper_bound(10, 16, 20)
475
- Traceback (most recent call last):
476
- ...
477
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
478
460
"""
479
- _check_n_q_d (n , q , d )
461
+ _check_n_q_d (n , q , d , field_based = False )
480
462
r = 1 - 1 / q
481
463
if algorithm == "gap" :
482
464
gap .load_package ("guava" )
@@ -500,13 +482,14 @@ def hamming_upper_bound(n,q,d):
500
482
Returns the Hamming upper bound.
501
483
502
484
Returns the Hamming upper bound for number of elements in the
503
- largest code of minimum distance d in `\GF{q}^n`.
485
+ largest code of length n and minimum distance d over alphabet
486
+ of size q.
504
487
505
488
The Hamming bound (also known as the sphere packing bound) returns
506
489
an upper bound on the size of a code of length `n`, minimum distance
507
- `d`, over a field of size `q`. The Hamming bound is obtained by
508
- dividing the contents of the entire space
509
- `\GF{q} ^n` by the contents of a ball with radius
490
+ `d`, over an alphabet of size `q`. The Hamming bound is obtained by
491
+ dividing the contents of the entire Hamming space
492
+ `q ^n` by the contents of a ball with radius
510
493
`floor((d-1)/2)`. As all these balls are disjoint, they can never
511
494
contain more than the whole vector space.
512
495
@@ -526,17 +509,8 @@ def hamming_upper_bound(n,q,d):
526
509
527
510
sage: codes.bounds.hamming_upper_bound(10,2,3)
528
511
93
529
-
530
- TESTS:
531
-
532
- Meaningless parameters are rejected::
533
-
534
- sage: codes.bounds.hamming_upper_bound(10, 16, 20)
535
- Traceback (most recent call last):
536
- ...
537
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
538
512
"""
539
- _check_n_q_d (n , q , d )
513
+ _check_n_q_d (n , q , d , field_based = False )
540
514
return int ((q ** n )/ (volume_hamming (n , q , int ((d - 1 )/ 2 ))))
541
515
542
516
def singleton_upper_bound (n ,q ,d ):
@@ -563,17 +537,8 @@ def singleton_upper_bound(n,q,d):
563
537
564
538
sage: codes.bounds.singleton_upper_bound(10,2,3)
565
539
256
566
-
567
- TESTS:
568
-
569
- Meaningless parameters are rejected::
570
-
571
- sage: codes.bounds.singleton_upper_bound(10, 16, 20)
572
- Traceback (most recent call last):
573
- ...
574
- ValueError: The length, alphabet size and minimum distance does not make sense for a code over a field
575
540
"""
576
- _check_n_q_d (n , q , d )
541
+ _check_n_q_d (n , q , d , field_based = False )
577
542
return q ** (n - d + 1 )
578
543
579
544
def gv_info_rate (n ,delta ,q ):
0 commit comments