Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit 179ac5e

Browse files
committed
cleanup of Griesmer bound, docs and examples
1 parent 3b80b3e commit 179ac5e

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

src/sage/coding/code_bounds.py

+60-30
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171

172172
from sage.interfaces.all import gap
173173
from sage.rings.all import QQ, RR, ZZ, RDF
174+
from sage.arith.misc import is_prime_power
174175
from sage.arith.all import factorial
175176
from sage.functions.all import log, sqrt
176177
from sage.misc.decorators import rename_keyword
@@ -221,6 +222,8 @@ def codesize_upper_bound(n,d,q,algorithm=None):
221222
222223
sage: codes.bounds.codesize_upper_bound(19,10,2)
223224
20
225+
sage: codes.bounds.codesize_upper_bound(19,10,2,algorithm="gap") # optional - gap_packages (Guava package)
226+
20
224227
"""
225228
if algorithm=="gap":
226229
gap.load_package('guava')
@@ -255,11 +258,12 @@ def dimension_upper_bound(n,d,q,algorithm=None):
255258
256259
"""
257260
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)
260264

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))
263267

264268

265269
def volume_hamming(n,q,r):
@@ -282,7 +286,7 @@ def gilbert_lower_bound(n,q,d):
282286
Returns Gilbert-Varshamov lower bound.
283287
284288
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`
286290
287291
EXAMPLES::
288292
@@ -297,8 +301,10 @@ def plotkin_upper_bound(n,q,d, algorithm=None):
297301
r"""
298302
Returns Plotkin upper bound.
299303
300-
Returns Plotkin upper bound for number of elements in the largest
304+
Returns Plotkin upper bound for number of elements in a largest
301305
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.
302308
The algorithm="gap" option wraps Guava's UpperBoundPlotkin.
303309
304310
EXAMPLES::
@@ -332,35 +338,59 @@ def griesmer_upper_bound(n,q,d,algorithm=None):
332338
Returns the Griesmer upper bound.
333339
334340
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,
337343
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+
::
339362
340363
sage: codes.bounds.griesmer_upper_bound(10,2,3)
341364
128
342365
sage: codes.bounds.griesmer_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
343366
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
344376
"""
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)
349392
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
364394

365395

366396
@rename_keyword(deprecation=6094, method="algorithm")
@@ -369,7 +399,7 @@ def elias_upper_bound(n,q,d,algorithm=None):
369399
Returns the Elias upper bound.
370400
371401
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
373403
GAP's UpperBoundElias.
374404
375405
EXAMPLES::
@@ -424,7 +454,7 @@ def hamming_upper_bound(n,q,d):
424454
where M is the maximum number of codewords and `V(n,e)` is
425455
equal to the contents of a ball of radius e. This bound is useful
426456
for small values of d. Codes for which equality holds are called
427-
perfect.
457+
perfect. See e.g. [HP2003]_.
428458
429459
EXAMPLES::
430460
@@ -437,7 +467,7 @@ def singleton_upper_bound(n,q,d):
437467
r"""
438468
Returns the Singleton upper bound.
439469
440-
Returns the Singleton upper bound for number of elements in the
470+
Returns the Singleton upper bound for number of elements in a
441471
largest code of minimum distance d in `\GF{q}^n`.
442472
Wraps GAP's UpperBoundSingleton.
443473

0 commit comments

Comments
 (0)