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

Commit e793a92

Browse files
committed
added field_based and used it whenever needed
1 parent 5d2ee22 commit e793a92

File tree

1 file changed

+39
-74
lines changed

1 file changed

+39
-74
lines changed

src/sage/coding/code_bounds.py

+39-74
Original file line numberDiff line numberDiff line change
@@ -177,26 +177,42 @@
177177
from .delsarte_bounds import delsarte_bound_hamming_space, \
178178
delsarte_bound_additive_hamming_space
179179

180-
def _check_n_q_d(n, q, d):
180+
def _check_n_q_d(n, q, d, field_based=True):
181181
r"""
182182
Check that the length `n`, alphabet size `q` and minimum distance `d` type
183183
check and make sense for a code over a field.
184184
185185
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.
187189
188-
EXAMPLES::
190+
TESTS::
189191
190192
sage: from sage.coding.code_bounds import _check_n_q_d
191193
sage: _check_n_q_d(20, 16, 5)
192194
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)
194206
Traceback (most recent call last):
195207
...
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
197209
"""
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")
200216
return True
201217

202218

@@ -248,12 +264,13 @@ def codesize_upper_bound(n,d,q,algorithm=None):
248264
20
249265
250266
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)
252269
Traceback (most recent call last):
253270
...
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
255272
"""
256-
_check_n_q_d(n, q, d)
273+
_check_n_q_d(n, q, d, field_based=False)
257274
if algorithm=="gap":
258275
gap.load_package('guava')
259276
return int(gap.eval("UpperBound(%s,%s,%s)"%( n, d, q )))
@@ -288,11 +305,10 @@ def dimension_upper_bound(n,d,q,algorithm=None):
288305
289306
Meaningless code parameters are rejected::
290307
291-
sage: codes.bounds.dimension_upper_bound(-3,3,2)
308+
sage: codes.bounds.dimension_upper_bound(13,3,6)
292309
Traceback (most recent call last):
293310
...
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
296312
"""
297313
_check_n_q_d(n, q, d)
298314
q = ZZ(q)
@@ -328,17 +344,8 @@ def gilbert_lower_bound(n,q,d):
328344
329345
sage: codes.bounds.gilbert_lower_bound(10,2,3)
330346
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
340347
"""
341-
_check_n_q_d(n, q, d)
348+
_check_n_q_d(n, q, d, field_based=False)
342349
ans=q**n/volume_hamming(n,q,d-1)
343350
return ans
344351

@@ -359,17 +366,8 @@ def plotkin_upper_bound(n,q,d, algorithm=None):
359366
192
360367
sage: codes.bounds.plotkin_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
361368
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
371369
"""
372-
_check_n_q_d(n, q, d)
370+
_check_n_q_d(n, q, d, field_based=False)
373371
if algorithm=="gap":
374372
gap.load_package("guava")
375373
ans=gap.eval("UpperBoundPlotkin(%s,%s,%s)"%(n,d,q))
@@ -425,13 +423,6 @@ def griesmer_upper_bound(n,q,d,algorithm=None):
425423
243
426424
sage: codes.bounds.griesmer_upper_bound(11,3,6)
427425
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
435426
"""
436427
_check_n_q_d(n, q, d)
437428
if algorithm=="gap":
@@ -466,17 +457,8 @@ def elias_upper_bound(n,q,d,algorithm=None):
466457
232
467458
sage: codes.bounds.elias_upper_bound(10,2,3,algorithm="gap") # optional - gap_packages (Guava package)
468459
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
478460
"""
479-
_check_n_q_d(n, q, d)
461+
_check_n_q_d(n, q, d, field_based=False)
480462
r = 1-1/q
481463
if algorithm=="gap":
482464
gap.load_package("guava")
@@ -500,13 +482,14 @@ def hamming_upper_bound(n,q,d):
500482
Returns the Hamming upper bound.
501483
502484
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.
504487
505488
The Hamming bound (also known as the sphere packing bound) returns
506489
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
510493
`floor((d-1)/2)`. As all these balls are disjoint, they can never
511494
contain more than the whole vector space.
512495
@@ -526,17 +509,8 @@ def hamming_upper_bound(n,q,d):
526509
527510
sage: codes.bounds.hamming_upper_bound(10,2,3)
528511
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
538512
"""
539-
_check_n_q_d(n, q, d)
513+
_check_n_q_d(n, q, d, field_based=False)
540514
return int((q**n)/(volume_hamming(n, q, int((d-1)/2))))
541515

542516
def singleton_upper_bound(n,q,d):
@@ -563,17 +537,8 @@ def singleton_upper_bound(n,q,d):
563537
564538
sage: codes.bounds.singleton_upper_bound(10,2,3)
565539
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
575540
"""
576-
_check_n_q_d(n, q, d)
541+
_check_n_q_d(n, q, d, field_based=False)
577542
return q**(n - d + 1)
578543

579544
def gv_info_rate(n,delta,q):

0 commit comments

Comments
 (0)