171
171
172
172
from sage .interfaces .all import gap
173
173
from sage .rings .all import QQ , RR , ZZ , RDF
174
+ from sage .arith .misc import is_prime_power
174
175
from sage .arith .all import factorial
175
176
from sage .functions .all import log , sqrt
176
177
from sage .misc .decorators import rename_keyword
@@ -221,6 +222,8 @@ def codesize_upper_bound(n,d,q,algorithm=None):
221
222
222
223
sage: codes.bounds.codesize_upper_bound(19,10,2)
223
224
20
225
+ sage: codes.bounds.codesize_upper_bound(19,10,2,algorithm="gap") # optional - gap_packages (Guava package)
226
+ 20
224
227
"""
225
228
if algorithm == "gap" :
226
229
gap .load_package ('guava' )
@@ -255,11 +258,12 @@ def dimension_upper_bound(n,d,q,algorithm=None):
255
258
256
259
"""
257
260
q = ZZ (q )
258
- if algorithm == "LP" :
259
- return delsarte_bound_additive_hamming_space (n ,d ,q )
261
+ if is_prime_power (q ) and n > 0 and d > 0 and n in ZZ and d in ZZ : # sanity check
262
+ if algorithm == "LP" :
263
+ return delsarte_bound_additive_hamming_space (n ,d ,q )
260
264
261
- else : # algorithm==None or algorithm=="gap":
262
- return int (log (codesize_upper_bound (n ,d ,q ,algorithm = algorithm ),q ))
265
+ else : # algorithm==None or algorithm=="gap":
266
+ return int (log (codesize_upper_bound (n ,d ,q ,algorithm = algorithm ),q ))
263
267
264
268
265
269
def volume_hamming (n ,q ,r ):
@@ -282,7 +286,7 @@ def gilbert_lower_bound(n,q,d):
282
286
Returns Gilbert-Varshamov lower bound.
283
287
284
288
Returns Gilbert-Varshamov lower bound for number of elements in a largest code of
285
- minimum distance d in `\GF{q}^n`.
289
+ minimum distance d in `\GF{q}^n`. See :wikipedia:`Gilbert-Varshamov_bound`
286
290
287
291
EXAMPLES::
288
292
@@ -297,8 +301,10 @@ def plotkin_upper_bound(n,q,d, algorithm=None):
297
301
r"""
298
302
Returns Plotkin upper bound.
299
303
300
- Returns Plotkin upper bound for number of elements in the largest
304
+ Returns Plotkin upper bound for number of elements in a largest
301
305
code of minimum distance d in `\GF{q}^n`.
306
+ More precisely this is a generalization of Plotkin's result for q=2
307
+ to bigger q due to Berlekamp.
302
308
The algorithm="gap" option wraps Guava's UpperBoundPlotkin.
303
309
304
310
EXAMPLES::
@@ -332,35 +338,59 @@ def griesmer_upper_bound(n,q,d,algorithm=None):
332
338
Returns the Griesmer upper bound.
333
339
334
340
Returns the Griesmer upper bound for number of elements in a
335
- largest linear code of minimum distance d in `\GF{q}^n`.
336
- If the method is "GAP", it wraps GAP's UpperBoundGriesmer.
341
+ largest linear code of minimum distance d in `\GF{q}^n`, cf. [HP2003]_ .
342
+ If the method is "GAP", it wraps GAP's UpperBoundGriesmer. Namely,
337
343
338
- EXAMPLES::
344
+ .. MATH::
345
+
346
+ `n\geq \sum_{i=0}^{k-1} \lceil d/q^i \rceil.`
347
+
348
+ To compute the bound, we keep summing up the terms on the RHS
349
+ until we start violating the inequality.
350
+
351
+
352
+ EXAMPLES:
353
+
354
+ The bound is reached for the ternary Golay codes::
355
+
356
+ sage: codes.bounds.griesmer_upper_bound(12,3,6)
357
+ 729
358
+ sage: codes.bounds.griesmer_upper_bound(11,3,5)
359
+ 729
360
+
361
+ ::
339
362
340
363
sage: codes.bounds.griesmer_upper_bound(10,2,3)
341
364
128
342
365
sage: codes.bounds.griesmer_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
343
366
128
367
+
368
+ TESTS::
369
+
370
+ sage: codes.bounds.griesmer_upper_bound(10,6,5)
371
+ 0
372
+ sage: codes.bounds.griesmer_upper_bound(11,3,6)
373
+ 243
374
+ sage: codes.bounds.griesmer_upper_bound(11,3,6)
375
+ 243
344
376
"""
345
- if algorithm == "gap" :
346
- gap .load_package ("guava" )
347
- ans = gap .eval ("UpperBoundGriesmer(%s,%s,%s)" % (n ,d ,q ))
348
- return QQ (ans )
377
+ if is_prime_power (q ) and n > 0 and d > 0 and n in ZZ and d in ZZ : # sanity check
378
+ if algorithm == "gap" :
379
+ gap .load_package ("guava" )
380
+ ans = gap .eval ("UpperBoundGriesmer(%s,%s,%s)" % (n ,d ,q ))
381
+ return QQ (ans )
382
+ else :
383
+ from sage .functions .other import ceil
384
+ den = 1
385
+ s = 0
386
+ k = 0
387
+ while s <= n :
388
+ s += ceil (d / den )
389
+ den *= q
390
+ k = k + 1
391
+ return q ** (k - 1 )
349
392
else :
350
- den = 1
351
- s = 0
352
- k = 1
353
- add = 0
354
- while s <= n :
355
- if not (add == 1 ):
356
- if d % den == 0 :
357
- add = int (d / den )
358
- else :
359
- add = int (d / den )+ 1
360
- s = s + add
361
- den = den * q
362
- k = k + 1
363
- return q ** (k - 1 )
393
+ return 0
364
394
365
395
366
396
@rename_keyword (deprecation = 6094 , method = "algorithm" )
@@ -369,7 +399,7 @@ def elias_upper_bound(n,q,d,algorithm=None):
369
399
Returns the Elias upper bound.
370
400
371
401
Returns the Elias upper bound for number of elements in the largest
372
- code of minimum distance d in `\GF{q}^n`. Wraps
402
+ code of minimum distance d in `\GF{q}^n`, cf. [HP2003]_ . Wraps
373
403
GAP's UpperBoundElias.
374
404
375
405
EXAMPLES::
@@ -424,7 +454,7 @@ def hamming_upper_bound(n,q,d):
424
454
where M is the maximum number of codewords and `V(n,e)` is
425
455
equal to the contents of a ball of radius e. This bound is useful
426
456
for small values of d. Codes for which equality holds are called
427
- perfect.
457
+ perfect. See e.g. [HP2003]_.
428
458
429
459
EXAMPLES::
430
460
@@ -437,7 +467,7 @@ def singleton_upper_bound(n,q,d):
437
467
r"""
438
468
Returns the Singleton upper bound.
439
469
440
- Returns the Singleton upper bound for number of elements in the
470
+ Returns the Singleton upper bound for number of elements in a
441
471
largest code of minimum distance d in `\GF{q}^n`.
442
472
Wraps GAP's UpperBoundSingleton.
443
473
0 commit comments