"""nodoctest1Linear codes2"""34#*****************************************************************************5#6# Sage: Copyright (C) 2005 William Stein <[email protected]>7# 2005 Steven Sivek8#9# Distributed under the terms of the GNU General Public License (GPL)10#11# This code is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14# General Public License for more details.15#16# The full text of the GPL is available at:17#18# http://www.gnu.org/licenses/19#*****************************************************************************2021import re2223def parse_bound_html(text, n, k):24lower, upper = -1, -125bound = re.compile(r'(?P<type>[LU])b\('26r'(?P<n>[0-9]*),(?P<k>[0-9]*)'27r'\) = (?P<val>[0-9]*) ');2829for line in re.split(r'[\s,]*\n', text):30m = bound.search(line)31if m and int(m.group('n')) == n and int(m.group('k')) == k:32if m.group('type') == 'L':33lower = int(m.group('val'))34elif m.group('type') == 'U':35upper = int(m.group('val'))36return lower, upper3738## def linear_code_bound(q, n, k, verbose=False):39## r"""40## Find bounds on the minimum distance of linear codes over GF(q)41## with length n and dimension k, courtesy of42## \url{http://www.win.tue.nl/~aeb/voorlincod.html}.43## If no bounds are in the database, returns lower and upper44## bounds of -1.4546## INPUT:47## q -- integer, the field order, which must be in48## [2, 3, 4, 5, 7, 8, 9]49## n -- integer, the length of the code50## k -- integer, the dimension of the code51## verbose -- bool (default=False), print verbose message5253## OUTPUT:54## integer -- lower bound55## integer -- upper bound56## str -- text about why the bounds are as given5758## EXAMPLES:59## To find lower and upper bounds for values q=7, n=32, k=8, type60## sage: lower, upper, text = linear_code_bound(7, 32, 8) # optional -- needs internet61## sage: lower # optional62## 1963## sage: upper # optional64## 2165## sage: text # optional66## '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]'6768## When bounds are not known the upper and lower returned bounds are -1:69## sage: linear_code_bound(9, 32, 200) # optional -- needs internet70## (-1, -1, '(error executing -why-)')7172## This function raises an IOError if an error occurs downloading73## data or parsing it. It raises a ValueError if the q input is74## invalid.7576## AUTHOR: 2005-11-14: Steven Sivek77## """78## q = Integer(q)79## if not q in [2, 3, 4, 5, 7, 8, 9]:80## raise ValueError, "q (=%s) must be in [2,3,4,5,7,8,9]"%q81## n = Integer(n)82## k = Integer(k)8384## param = ("%s/%s/%s"%(q,n,k)).replace('L','')8586## url = "http://homepages.cwi.nl/htbin/aeb/lincodbd/"+param87## if verbose:88## print "Looking up the bounds at %s"%url89## f = urllib.urlopen(url)90## s = f.read()91## f.close()9293## i = s.find("<PRE>")94## j = s.find("</PRE>")95## if i == -1 or j == -1:96## raise IOError, "Error parsing data (missing pre tags)."97## text = s[i+5:j].strip()98## lower, upper = parse_bound_html(text, n, k)99100## return lower, upper, text101102103104