Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/databases/lincodes.py
6915 views
1
"""nodoctest
2
Linear codes
3
"""
4
5
#*****************************************************************************
6
#
7
# Sage: Copyright (C) 2005 William Stein <[email protected]>
8
# 2005 Steven Sivek
9
#
10
# Distributed under the terms of the GNU General Public License (GPL)
11
#
12
# This code is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
# General Public License for more details.
16
#
17
# The full text of the GPL is available at:
18
#
19
# http://www.gnu.org/licenses/
20
#*****************************************************************************
21
22
import re
23
24
def parse_bound_html(text, n, k):
25
lower, upper = -1, -1
26
bound = re.compile(r'(?P<type>[LU])b\('
27
r'(?P<n>[0-9]*),(?P<k>[0-9]*)'
28
r'\) = (?P<val>[0-9]*) ');
29
30
for line in re.split(r'[\s,]*\n', text):
31
m = bound.search(line)
32
if m and int(m.group('n')) == n and int(m.group('k')) == k:
33
if m.group('type') == 'L':
34
lower = int(m.group('val'))
35
elif m.group('type') == 'U':
36
upper = int(m.group('val'))
37
return lower, upper
38
39
## def linear_code_bound(q, n, k, verbose=False):
40
## r"""
41
## Find bounds on the minimum distance of linear codes over GF(q)
42
## with length n and dimension k, courtesy of
43
## \url{http://www.win.tue.nl/~aeb/voorlincod.html}.
44
## If no bounds are in the database, returns lower and upper
45
## bounds of -1.
46
47
## INPUT:
48
## q -- integer, the field order, which must be in
49
## [2, 3, 4, 5, 7, 8, 9]
50
## n -- integer, the length of the code
51
## k -- integer, the dimension of the code
52
## verbose -- bool (default=False), print verbose message
53
54
## OUTPUT:
55
## integer -- lower bound
56
## integer -- upper bound
57
## str -- text about why the bounds are as given
58
59
## EXAMPLES:
60
## To find lower and upper bounds for values q=7, n=32, k=8, type
61
## sage: lower, upper, text = linear_code_bound(7, 32, 8) # optional -- needs internet
62
## sage: lower # optional
63
## 19
64
## sage: upper # optional
65
## 21
66
## sage: text # optional
67
## 'Lb(32,8) = 19 DG4\n\nUb(32,8) = 21 follows by a one-step Griesmer bound from:\nUb(10,7) = 3 is found by considering shortening to:\nUb(9,6) = 3 is found by construction B:\n[consider deleting the (at most) 6 coordinates of a word in the dual]'
68
69
## When bounds are not known the upper and lower returned bounds are -1:
70
## sage: linear_code_bound(9, 32, 200) # optional -- needs internet
71
## (-1, -1, '(error executing -why-)')
72
73
## This function raises an IOError if an error occurs downloading
74
## data or parsing it. It raises a ValueError if the q input is
75
## invalid.
76
77
## AUTHOR: 2005-11-14: Steven Sivek
78
## """
79
## q = Integer(q)
80
## if not q in [2, 3, 4, 5, 7, 8, 9]:
81
## raise ValueError, "q (=%s) must be in [2,3,4,5,7,8,9]"%q
82
## n = Integer(n)
83
## k = Integer(k)
84
85
## param = ("%s/%s/%s"%(q,n,k)).replace('L','')
86
87
## url = "http://homepages.cwi.nl/htbin/aeb/lincodbd/"+param
88
## if verbose:
89
## print "Looking up the bounds at %s"%url
90
## f = urllib.urlopen(url)
91
## s = f.read()
92
## f.close()
93
94
## i = s.find("<PRE>")
95
## j = s.find("</PRE>")
96
## if i == -1 or j == -1:
97
## raise IOError, "Error parsing data (missing pre tags)."
98
## text = s[i+5:j].strip()
99
## lower, upper = parse_bound_html(text, n, k)
100
101
## return lower, upper, text
102
103
104