Changeset 7751:adb0d92010f4
- Timestamp:
- 12/15/07 16:29:09 (5 years ago)
- Branch:
- default
- Parents:
- 7747:8ae981773265 (diff), 7750:0194e639d9f4 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 2 edited
-
sage/coding/linear_code.py (modified) (38 diffs)
-
sage/coding/linear_code.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/coding/linear_code.py
r7723 r7751 2 2 Linear Codes 3 3 4 VERSION: 0. 84 VERSION: 0.9 5 5 6 6 Let $ F$ be a finite field (we denote the finite field with $q$ elements … … 17 17 called the {\it dual space} of $C$. 18 18 19 If $ F=\FF_2$ then $ C$ is called a {\it binary code}.20 If $ F = \FF_q$ then $ C$ is called a {\it $ q$-ary code}.21 The elements of a code $ C$ are called {\it codewords}.19 If $ F=\FF_2$ then $C$ is called a {\it binary code}. 20 If $ F = \FF_q$ then $C$ is called a {\it $ q$-ary code}. 21 The elements of a code $C$ are called {\it codewords}. 22 22 23 23 Let $ F$ be a finite field with $ q$ elements. Here's a constructive … … 68 68 \item 69 69 The spectrum (weight distribution), minimum distance 70 programs (calling Steve Linton's C programs), and zeta_function for71 the Duursma zeta function.70 programs (calling Steve Linton's C programs), characteristic function, 71 and several implementations of the Duursma zeta function. 72 72 \item 73 interface with A. Brouwer's online tables, as wellas74 be st_known_linear_code, bounds_minimum_distance which call tables73 interface with best_known_linear_code (interface with A. Brouwer's online tables has 74 been disabled), bounds_minimum_distance which call tables 75 75 in GUAVA (updated May 2006) created by Cen Tjhai instead of the online 76 76 internet tables. 77 77 \item 78 ToricCode, TrivialCode (in a separate module, you will find the constructions78 ToricCode, TrivialCode (in a separate "guava.py" module, you will find the constructions 79 79 Hamming codes, "random" linear codes, Golay codes, binary Reed-Muller codes, 80 80 binary quadratic and extended quadratic residue codes, cyclic codes, all … … 147 147 Completely rewritten zeta_function (old version is now zeta_function2) 148 148 and a new function, LinearCodeFromVectorSpace. 149 -- DJ (2007-11): added zeta_polynomial, weight_enumerator, 150 chinen_polynomial; improved best_known_code; 151 made some pythonic revisions; 152 added is_equivalent (for binary codes) 149 153 150 154 TESTS: … … 157 161 158 162 #***************************************************************************** 159 # Copyright (C) 2005 David Joyner <wdj @usna.edu>160 # 2006 William Stein <wstein@ ucsd.edu>163 # Copyright (C) 2005 David Joyner <wdjoyner@gmail.com> 164 # 2006 William Stein <wstein@gmail.com> 161 165 # 162 # Distributed under the terms of the GNU General Public License (GPL) 166 # Distributed under the terms of the GNU General Public License (GPL), 167 # version 2 or later (at your preference). 163 168 # 164 169 # http://www.gnu.org/licenses/ … … 169 174 import sage.modules.module as module 170 175 import sage.modules.free_module_element as fme 171 #from sage.databases.lincodes import linear_code_bound172 176 from sage.interfaces.all import gap 173 174 # TODO -- import *'s SUCK -- this must all be fixed and made explicit!! 175 from sage.misc.preparser import * 176 from sage.rings.finite_field import * 177 from sage.groups.perm_gps.permgroup import * 178 177 from sage.rings.finite_field import GF 178 from sage.groups.perm_gps.permgroup import PermutationGroup 179 179 from sage.matrix.matrix_space import MatrixSpace 180 181 180 from sage.rings.arith import GCD, rising_factorial, binomial 182 183 181 from sage.groups.all import SymmetricGroup 184 182 from sage.misc.sage_eval import sage_eval 185 183 from sage.misc.misc import prod, add 186 from sage.misc.functional import log 184 from sage.misc.functional import log, is_even, is_odd 187 185 from sage.rings.rational_field import QQ 188 186 from sage.structure.parent_gens import ParentWithGens … … 191 189 from sage.rings.integer_ring import IntegerRing 192 190 from sage.combinat.set_partition import SetPartitions 191 from sage.rings.real_mpfr import RR ## RealField 193 192 194 193 ZZ = IntegerRing() … … 230 229 z = 'Z(%s)*%s'%(q, [0]*n) # GAP zero vector as a string 231 230 dist = gap.eval("w:=DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")") 231 ## for some reason, this commented code doesn't work: 232 #dist0 = gap("DistancesDistributionMatFFEVecFFE("+Gmat+", GF("+str(q)+"),"+z+")") 233 #v0 = dist0._matrix_(F) 234 #print dist0,v0 232 235 #d = G.DistancesDistributionMatFFEVecFFE(k, z) 233 v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,n+2)] 236 v = [eval(gap.eval("w["+str(i)+"]")) for i in range(1,n+2)] ## because GAP returns vectors in compressed form 234 237 return v 235 238 … … 243 246 244 247 OUTPUT: 245 Returns a minimum weight vector v, the"message" vector m such that m*G = v, and the (minimum) weight, as a triple. 248 Returns a minimum weight vector v of the code generated by Gmat 249 ## , the"message" vector m such that m*G = v, and the (minimum) distance, as a triple. 246 250 247 251 EXAMPLES: 248 252 sage: Gstr = "Z(2)*[[1,1,1,0,0,0,0], [1,0,0,1,1,0,0], [0,1,0,1,0,1,0], [1,1,0,1,0,0,1]]" 249 253 sage: sage.coding.linear_code.min_wt_vec(Gstr,GF(2)) 250 [[0, 1, 0, 1, 0, 1, 0], [0, 0, 1, 0], 3]254 (0, 0, 1, 0, 1, 1, 0) 251 255 252 256 Here Gstr is a generator matrix of the Hamming [7,4,3] binary code. … … 254 258 AUTHOR: David Joyner (11-2005) 255 259 """ 260 from sage.rings.finite_field import gap_to_sage 256 261 gap.eval("G:="+Gmat) 257 k = int(gap.eval( 'Length(G)'))262 k = int(gap.eval("Length(G)")) 258 263 q = F.order() 259 264 qstr = str(q) 260 gap.eval("C:=GeneratorMatCode("+Gmat+",GF("+qstr+"))") 261 n = int(gap.eval("WordLength(C)")) 262 zerovec = [0 for i in range(n)] 263 zerovecstr = "Z("+qstr+")*"+str(zerovec) 264 all = [] 265 for i in range(1,k+1): 266 P = gap.eval("P:=AClosestVectorCombinationsMatFFEVecFFECoords("+Gmat+", GF("+qstr+"),"+zerovecstr+","+str(i)+","+str(0)+"); d:=WeightVecFFE(P[1])") 267 v = gap.eval("v:=List(P[1], i->i)") 268 m = gap.eval("m:=List(P[2], i->i)") 269 dist = gap.eval("d") 270 #print v,m,dist 271 #print [gap.eval("v["+str(i+1)+"]") for i in range(n)] 272 all.append([[gap_to_sage(gap.eval("v["+str(i+1)+"]"),F) 273 for i in range(n)], 274 [gap_to_sage(gap.eval("m["+str(i+1)+"]"),F) 275 for i in range(k)],int(dist)]) 276 ans = all[0] 277 for x in all: 278 if x[2]<ans[2] and x[2]>0: 279 ans = x 280 return ans 265 C = gap(Gmat).GeneratorMatCode(F) 266 n = int(C.WordLength()) 267 cg = C.MinimumDistanceCodeword() 268 c = [gap_to_sage(cg[j],F) for j in range(1,n+1)] 269 V = VectorSpace(F,n) 270 return V(c) 271 ## this older code returns more info but may be slower: 272 #zerovec = [0 for i in range(n)] 273 #zerovecstr = "Z("+qstr+")*"+str(zerovec) 274 #all = [] 275 #for i in range(1,k+1): 276 # P = gap.eval("P:=AClosestVectorCombinationsMatFFEVecFFECoords("+Gmat+", GF("+qstr+"),"+zerovecstr+","+str(i)+","+str(0)+"); d:=WeightVecFFE(P[1])") 277 # v = gap("[List(P[1], i->i)]") 278 # m = gap("[List(P[2], i->i)]") 279 # dist = gap.eval("d") 280 # #print v,m,dist 281 # #print [gap.eval("v["+str(i+1)+"]") for i in range(n)] 282 # all.append([v._matrix_(F),m._matrix_(F),int(dist)]) 283 #ans = all[0] 284 #for x in all: 285 # if x[2]<ans[2] and x[2]>0: 286 # ans = x 287 #return ans 281 288 282 289 ## def minimum_distance_lower_bound(n,k,F): … … 342 349 EXAMPLES: 343 350 sage: best_known_linear_code(10,5,GF(2)) # long time 351 Linear code of length 10, dimension 5 over Finite Field of size 2 352 sage: gap.eval("C:=BestKnownLinearCode(10,5,GF(2))") 344 353 'a linear [10,5,4]2..4 shortened code' 345 354 … … 350 359 """ 351 360 q = F.order() 352 return gap.eval("BestKnownLinearCode(%s,%s,GF(%s))"%(n,k,q)) 361 C = gap("BestKnownLinearCode(%s,%s,GF(%s))"%(n,k,q)) 362 G = C.GeneratorMat() 363 k = G.Length() 364 n = G[1].Length() 365 Gs = G._matrix_(F) 366 MS = MatrixSpace(F,k,n) 367 return LinearCode(MS(Gs)) 368 #return gap.eval("BestKnownLinearCode(%s,%s,GF(%s))"%(n,k,q)) 353 369 354 370 def bounds_minimum_distance(n,k,F): … … 467 483 468 484 def random(self): 485 """ 486 EXAMPLES: 487 sage: C = HammingCode(3,GF(4,'a')) 488 sage: Cc = C.galois_closure(GF(2)) 489 sage: c = C.random() 490 sage: V = VectorSpace(GF(4,'a'),21) 491 sage: c2 = V([x^2 for x in c.list()]) 492 sage: c2 in C 493 False 494 495 """ 496 from sage.rings.finite_field import gap_to_sage 469 497 F = self.base_ring() 470 498 q = F.order() 471 499 G = self.gen_mat() 472 500 n = len(G.columns()) 473 Gstr = str(gap(G)) 474 gap.eval("C:=GeneratorMatCode("+Gstr+",GF("+str(q)+"))") 475 gap.eval("c:=Random( C )") 476 ans = [gap_to_sage(gap.eval("c["+str(i)+"]"),F) for i in range(1,n+1)] 501 Cg = gap(G).GeneratorMatCode(F) 502 c = Cg.Random() 503 ans = [gap_to_sage(c[i],F) for i in range(1,n+1)] 477 504 V = VectorSpace(F,n) 478 505 return V(ans) … … 613 640 gapG = gap(G) 614 641 Gstr = "%s*Z(%s)^0"%(gapG, q) 615 return min_wt_vec(Gstr,F)[2]642 return hamming_weight(min_wt_vec(Gstr,F)) 616 643 617 644 def genus(self): … … 675 702 Does not work for very long codes since the syndrome table grows too large. 676 703 """ 704 from sage.rings.finite_field import gap_to_sage 677 705 F = self.base_ring() 678 706 q = F.order() … … 713 741 return TrivialCode(F,n) 714 742 Gstr = str(gap(G)) 715 C = gap.GeneratorMatCode(Gstr, 'GF(%s)'%q)716 743 #H = C.CheckMat() 717 744 #A = H._matrix_(GF(q)) 718 745 #return LinearCode(A) ## This does not work when k = n-1 for a mysterious reason. 719 ## less pythonic way 1:720 gap.eval("C:=DualCode(GeneratorMatCode("+Gstr+",GF("+str(q)+")))")721 gap.eval("G:=GeneratorMat(C)")722 G = [[gap_to_sage(gap.eval("G["+str(i)+"]["+str(j)+"]"),F) for j in range(1,n+1)] for i in range(1,n-k+1)]746 ## less pythonic way : 747 C = gap("DualCode(GeneratorMatCode("+Gstr+",GF("+str(q)+")))") 748 G = C.GeneratorMat() 749 Gs = G._matrix_(F) 723 750 MS = MatrixSpace(F,n-k,n) 724 #print G, MS(G) 725 return LinearCode(MS(G)) 726 ## less pythonic way 2: 727 Hmat = gap.eval("H:=CheckMat( C )") 728 H = [[gap_to_sage(gap.eval("H["+str(i)+"]["+str(j)+"]"),F) 729 for j in range(1,n+1)] for i in range(1,n-k+1)] 730 MS = MatrixSpace(F,n-k,n) 731 return LinearCode(MS(H)) 751 return LinearCode(MS(Gs)) 732 752 733 753 def extended_code(self): … … 749 769 750 770 """ 751 from sage.rings.finite_field import gap_to_sage752 771 G = self.gen_mat() 753 772 F = self.base_ring() … … 757 776 Gstr = str(gap(G)) 758 777 gap.eval( "G:="+Gstr ) 759 gap.eval("C:=GeneratorMatCode(G,GF("+str(q)+"))")760 gap.eval("Gx:=GeneratorMat( ExtendedCode(C) )")761 Gx = [[gap_to_sage(gap.eval("Gx["+str(i)+"]["+str(j)+"]"),F)762 for j in range(1,n+2)] for i in range(1,k+1)]778 C = gap("GeneratorMatCode(G,GF("+str(q)+"))") 779 Cx = C.ExtendedCode() 780 Gx = Cx.GeneratorMat() 781 Gxs = Gx._matrix_(F) 763 782 MS = MatrixSpace(F,k,n+1) 764 return LinearCode(MS(Gx ))783 return LinearCode(MS(Gxs)) 765 784 766 785 def check_mat(self): … … 885 904 sage: C = ExtendedTernaryGolayCode() 886 905 sage: M11 = MathieuGroup(11) 887 sage: G = C.permutation_automorphism_group() ## this should take < 15 seconds # long time906 sage: G = C.permutation_automorphism_group() ## this should take < 15 seconds # long time 888 907 sage: G.is_isomorphic(M11) # long time 889 908 True 890 909 910 WARNING: - *Ugly code, which should be replaced by a call to Robert Miller's nice program.* 911 - Known to mysteriously crash in one example. 891 912 """ 892 913 F = self.base_ring() … … 935 956 def permuted_code(self,p): 936 957 r""" 937 Returns the permuted code -- the code $C$ which is equivalen et958 Returns the permuted code -- the code $C$ which is equivalent 938 959 to self via the column permutation $p$. 939 960 … … 1024 1045 if mode=="verbose": 1025 1046 print "\n",gap.eval("Display(G)"),"\n" 1026 gap.eval("C:=GeneratorMatCode(G,GF("+str(q)+"))") 1027 gap.eval("Gp:=GeneratorMat( C )") 1028 Gp = [[gap_to_sage(gap.eval("Gp["+str(i)+"]["+str(j)+"]"),F) 1029 for j in range(1,n+1)] for i in range(1,k+1)] 1047 C = gap("GeneratorMatCode(G,GF("+str(q)+"))") 1048 Gp = C.GeneratorMat() 1049 Gs = Gp._matrix_(F) 1030 1050 MS = MatrixSpace(F,k,n) 1031 return LinearCode(MS(G p)),p1051 return LinearCode(MS(Gs)),p 1032 1052 1033 1053 def module_composition_factors(self,gp): … … 1071 1091 EXAMPLES: 1072 1092 sage: C = HammingCode(3,GF(4,'a')) 1073 sage: C 1093 sage: Cc = C.galois_closure(GF(2)) 1094 sage: C; Cc 1074 1095 Linear code of length 21, dimension 18 over Finite Field in a of size 2^2 1075 sage: Cc = C.galois_closure(GF(2))1076 sage: Cc1077 1096 Linear code of length 21, dimension 20 over Finite Field in a of size 2^2 1078 1097 sage: c = C.random() 1079 sage: c ## random output1080 (1, 0, 1, 1, 1, a, 0, a, a + 1, a + 1, a + 1, a + 1, a, 1, a + 1, a + 1, 0, a + 1, 0, 1, 1)1081 1098 sage: V = VectorSpace(GF(4,'a'),21) 1082 1099 sage: c2 = V([x^2 for x in c.list()]) … … 1232 1249 return 0 1233 1250 1251 def weight_enumerator(self,names="xy"): 1252 """ 1253 Returns the weight enumerator of the code. 1254 1255 EXAMPLES: 1256 sage: C = HammingCode(3,GF(2)) 1257 sage: C.weight_enumerator() 1258 x^7 + 7*x^4*y^3 + 7*x^3*y^4 + y^7 1259 sage: C.weight_enumerator(names="st") 1260 s^7 + 7*s^4*t^3 + 7*s^3*t^4 + t^7 1261 """ 1262 spec = self.spectrum() 1263 n = self.length() 1264 from sage.rings.polynomial.polynomial_ring import PolynomialRing 1265 R = PolynomialRing(QQ,2,names) 1266 x,y = R.gens() 1267 we = sum([spec[i]*x**(n-i)*y**i for i in range(n+1)]) 1268 return we 1269 1270 def zeta_polynomial(self,name = "T"): 1271 r""" 1272 Returns the Duursma zeta polynomial of the code. 1273 1274 Assumes minimum_distance(C) > 1 and minimum_distance(C^\perp) > 1. 1275 1276 EXAMPLES: 1277 sage: C = HammingCode(3,GF(2)) 1278 sage: C.zeta_polynomial() 1279 2/5*T^2 + 2/5*T + 1/5 1280 sage: C = best_known_linear_code(6,3,GF(2)) 1281 sage: C.minimum_distance() 1282 3 1283 sage: C.zeta_polynomial() 1284 2/5*T^2 + 2/5*T + 1/5 1285 sage: C = HammingCode(4,GF(2)) 1286 sage: C.zeta_polynomial() 1287 16/429*T^6 + 16/143*T^5 + 80/429*T^4 + 32/143*T^3 + 30/143*T^2 + 2/13*T + 1/13 1288 1289 REFERENCES: 1290 1291 I. Duursma, "From weight enumerators to zeta functions}, 1292 in {\bf Discrete Applied Mathematics}, vol. 111, no. 1-2, 1293 pp. 55-73, 2001. 1294 """ 1295 n = self.length() 1296 q = (self.base_ring()).characteristic() 1297 d = self.minimum_distance() 1298 dperp = (self.dual_code()).minimum_distance() 1299 if d == 1 or dperp == 1: 1300 print "\n WARNING: There is no guarantee this function works when the minimum distance" 1301 print " of the code or of the dual code equals 1.\n" 1302 from sage.rings.polynomial.polynomial_ring import PolynomialRing 1303 from sage.rings.fraction_field import FractionField 1304 from sage.rings.power_series_ring import PowerSeriesRing 1305 RT = PolynomialRing(QQ,"%s"%name) 1306 R = PolynomialRing(QQ,3,"xy%s"%name) 1307 x,y,T = R.gens() 1308 we = self.weight_enumerator() 1309 A = R(we) 1310 B = A(x+y,y,T)-(x+y)**n 1311 Bs = B.coefficients() 1312 b = [Bs[i]/binomial(n,i+d) for i in range(len(Bs))] 1313 r = n-d-dperp+2 1314 #print B,Bs,b,r 1315 P_coeffs = [] 1316 for i in range(len(b)): 1317 if i == 0: 1318 P_coeffs.append(b[0]) 1319 if i == 1: 1320 P_coeffs.append(b[1] - (q+1)*b[0]) 1321 if i>1: 1322 P_coeffs.append(b[i] - (q+1)*b[i-1] + q*b[i-2]) 1323 #print P_coeffs 1324 P = sum([P_coeffs[i]*T**i for i in range(r+1)]) 1325 return RT(P) 1326 1327 def chinen_polynomial(self): 1328 """ 1329 Returns the Chinen zeta polynomial of the code. 1330 1331 EXAMPLES: 1332 sage: C = HammingCode(3,GF(2)) 1333 sage: C.chinen_polynomial() 1334 (2*sqrt(2)*t^3/5 + 2*sqrt(2)*t^2/5 + 2*t^2/5 + sqrt(2)*t/5 + 2*t/5 + 1/5)/(sqrt(2) + 1) 1335 sage: C = TernaryGolayCode() 1336 sage: C.chinen_polynomial() 1337 (6*sqrt(3)*t^3/7 + 6*sqrt(3)*t^2/7 + 6*t^2/7 + 2*sqrt(3)*t/7 + 6*t/7 + 2/7)/(2*sqrt(3) + 2) 1338 1339 This last output agrees with the corresponding example given in Chinen's paper below. 1340 1341 REFERENCES: 1342 Chinen, K. "An abundance of invariant polynomials 1343 satisfying the Riemann hypothesis", April 2007 preprint. 1344 1345 """ 1346 from sage.rings.polynomial.polynomial_ring import PolynomialRing, polygen 1347 #from sage.calculus.functional import expand 1348 from sage.calculus.calculus import sqrt, SymbolicExpressionRing, var 1349 C = self 1350 n = C.length() 1351 RT = PolynomialRing(QQ,2,"Ts") 1352 T,s = FractionField(RT).gens() 1353 t = PolynomialRing(QQ,"t").gen() 1354 Cd = C.dual_code() 1355 k = C.dimension() 1356 q = (C.base_ring()).characteristic() 1357 d = C.minimum_distance() 1358 dperp = Cd.minimum_distance() 1359 if dperp > d: 1360 P = RT(C.zeta_polynomial()) 1361 ## SAGE does not find dealing with sqrt(int) *as an algebraic object* 1362 ## an easy thing to do. Some tricky gymnastics are used to 1363 ## make SAGE deal with objects over QQ(sqrt(q)) nicely. 1364 if is_even(n): 1365 Pd = q**(k-n/2)*RT(Cd.zeta_polynomial())*T**(dperp - d) 1366 if not(is_even(n)): 1367 Pd = s*q**(k-(n+1)/2)*RT(Cd.zeta_polynomial())*T**(dperp - d) 1368 CP = P+Pd 1369 f = CP/CP(1,s) 1370 return f(t,sqrt(q)) 1371 if dperp < d: 1372 P = RT(C.zeta_polynomial())*T**(d - dperp) 1373 if is_even(n): 1374 Pd = q**(k-n/2)*RT(Cd.zeta_polynomial()) 1375 if not(is_even(n)): 1376 Pd = s*q**(k-(n+1)/2)*RT(Cd.zeta_polynomial()) 1377 CP = P+Pd 1378 f = CP/CP(1,s) 1379 return f(t,sqrt(q)) 1380 if dperp == d: 1381 P = RT(C.zeta_polynomial()) 1382 if is_even(n): 1383 Pd = q**(k-n/2)*RT(Cd.zeta_polynomial()) 1384 if not(is_even(n)): 1385 Pd = s*q**(k-(n+1)/2)*RT(Cd.zeta_polynomial()) 1386 CP = P+Pd 1387 f = CP/CP(1,s) 1388 return f(t,sqrt(q)) 1389 1390 def zeta_function(self,name = "T"): 1391 r""" 1392 Returns the Duursma zeta function of the code. 1393 1394 EXAMPLES: 1395 1396 """ 1397 P = self.zeta_polynomial() 1398 q = (self.base_ring()).characteristic() 1399 RT = PolynomialRing(QQ,"%s"%name) 1400 T = RT.gen() 1401 return P/((1-T)*(1-q*T)) 1402 1234 1403 def zeta_function2(self,mode=None): 1235 1404 r""" 1236 1405 Returns the Duursma zeta function of the code. 1406 1407 NOTE: This is somewhat experimental code. It sometimes 1408 returns "fail" for a reason I don't fully understand. 1409 However, when it does return a polynomial, the answer is 1410 (as far as I know) correct. *Experimental code* included to 1411 study a particular implementation. 1237 1412 1238 1413 INPUT: … … 1263 1438 Trans. A.M.S., 351 (1999)3609-3639. 1264 1439 1265 NOTE: This is somewhat experimental code. It sometimes1266 returns "fail" for a reason I don't fully understand.1267 However, when it does return a polynomial, the answer is1268 (as far as I know) correct.1269 1440 """ 1270 1441 from sage.rings.polynomial.polynomial_ring import PolynomialRing … … 1277 1448 n = self.length() 1278 1449 k = self.dimension() 1450 dperp = (self.dual_code()).minimum_distance() 1451 if d == 1 or dperp == 1: 1452 print "\n WARNING: There is no guarantee this function works when the minimum distance\n" 1453 print " of the code or of the dual code equals 1.\n" 1279 1454 gammaC = n+1-d # C.genus() 1280 1455 if mode=="dual": … … 1323 1498 return "fails" 1324 1499 1325 def zeta_function (self,mode=None):1500 def zeta_function3(self,mode=None): 1326 1501 r""" 1327 1502 Returns the Duursma zeta function of the code. 1503 1504 NOTE: This sometimes returns "fail" for a reason I don't fully 1505 understand. However, when it does return a polynomial, the answer is 1506 (as far as I know) correct. *Experimental code* included to 1507 study a particular implementation. 1328 1508 1329 1509 INPUT: … … 1337 1517 1338 1518 EXAMPLES: 1339 sage : C = HammingCode(3,GF(2))1340 sage : C.zeta_function()1519 sage.: C = HammingCode(3,GF(2)) 1520 sage.: C.zeta_function3() 1341 1521 (2/5*T^2 + 2/5*T + 1/5)/(2*T^2 - 3*T + 1) 1342 sage : C = ExtendedTernaryGolayCode()1343 sage : C.zeta_function()1522 sage.: C = ExtendedTernaryGolayCode() 1523 sage.: C.zeta_function3() 1344 1524 (3/7*T^2 + 3/7*T + 1/7)/(3*T^2 - 4*T + 1) 1345 sage : C.zeta_function(mode="dual")1525 sage.: C.zeta_function3(mode="dual") 1346 1526 ((3/7*T^2 + 3/7*T + 1/7)/(3*T^2 - 4*T + 1), 1347 1527 (729/7*T^2 + 729/7*T + 243/7)/(729*T^2 - 972*T + 243)) … … 1356 1536 n = self.length() 1357 1537 k = self.dimension() 1538 dperp = (self.dual_code()).minimum_distance() 1539 if d == 1 or dperp == 1: 1540 print "\n WARNING: There is no guarantee this function works when the minimum distance\n" 1541 print " of the code or of the dual code equals 1.\n" 1358 1542 gammaC = n+1-k-d 1359 1543 if mode=="dual": … … 1423 1607 1424 1608 """ 1425 from sage.rings.finite_field import gap_to_sage1426 1609 G = self.gen_mat() 1427 1610 F = self.base_ring() … … 1432 1615 Gstr = str(gap(G)) 1433 1616 gap.eval( "G:="+Gstr ) 1434 gap.eval("C:=GeneratorMatCode(G,GF("+str(q)+"))")1435 gap.eval("Gp:=GeneratorMat( PuncturedCode(C,%s) )"%L)1436 kL = eval(gap.eval("kL:=Length(Gp)")) ## this is = dim(CL), usually = k1437 G2 = [[gap_to_sage(gap.eval("Gp["+str(i)+"]["+str(j)+"]"),F)1438 for j in range(1,nL+1)] for i in range(1,kL+1)]1617 C = gap("GeneratorMatCode(G,GF("+str(q)+"))") 1618 CP = C.PuncturedCode(L) 1619 Gp = CP.GeneratorMat() 1620 kL = Gp.Length() ## this is = dim(CL), usually = k 1621 G2 = Gp._matrix_(F) 1439 1622 MS = MatrixSpace(F,kL,nL) 1440 1623 return LinearCode(MS(G2)) … … 1455 1638 1456 1639 """ 1457 from sage.rings.finite_field import gap_to_sage1458 1640 G = self.gen_mat() 1459 1641 F = self.base_ring() … … 1464 1646 Gstr = str(gap(G)) 1465 1647 gap.eval("G:="+Gstr ) 1466 gap.eval("C:=GeneratorMatCode(G,GF("+str(q)+"))") 1467 gap.eval("Gs:=GeneratorMat( DualCode(PuncturedCode(DualCode(C),%s)) )"%str(L)) 1468 kL = eval(gap.eval("kL:=Length(Gs)")) ## this is = dim(CL), usually = k 1469 Gs = [[gap_to_sage(gap.eval("Gs["+str(i)+"]["+str(j)+"]"),F) 1470 for j in range(1,nL+1)] for i in range(1,kL+1)] 1648 C = gap("GeneratorMatCode(G,GF("+str(q)+"))") 1649 Cd = C.DualCode() 1650 Cdp = Cd.PuncturedCode(L) 1651 Cdpd = Cdp.DualCode() 1652 Gs = Cdpd.GeneratorMat() 1653 kL = Gs.Length() ## this is = dim(CL), usually = k 1654 Gss = Gs._matrix_(F) 1471 1655 MS = MatrixSpace(F,kL,nL) 1472 return LinearCode(MS(Gs ))1656 return LinearCode(MS(Gss)) 1473 1657 1474 1658 def binomial_moment(self,i): … … 1488 1672 0 1489 1673 sage: C.binomial_moment(3) # long time 1490 41674 0 1491 1675 sage: C.binomial_moment(4) # long time 1492 1676 35 … … 1596 1780 1597 1781 RETURN: 1598 The data v,m as in Duursama [ 1]1782 The data v,m as in Duursama [D] 1599 1783 1600 1784 EXAMPLES: 1601 1785 1602 1786 REFERENCES: 1603 [ 1] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials"1787 [D] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 1604 1788 1605 1789 """ … … 1630 1814 1631 1815 RETURN: 1632 The coefficients $q_0, q_1, ...,$ of $q(T)$ as in Duursama [ 1].1816 The coefficients $q_0, q_1, ...,$ of $q(T)$ as in Duursama [D]. 1633 1817 1634 1818 EXAMPLES: 1635 1819 1636 1820 REFERENCES: 1637 [ 1] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials"1821 [D] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 1638 1822 1639 1823 """ … … 1655 1839 m = ZZ(C.sd_duursma_data(i)[1]) 1656 1840 #print m,v,d,d0,c0 1841 if m<0 or v<0: 1842 raise ValueError("This case not implemented.") 1657 1843 PR = PolynomialRing(QQ,"T") 1658 1844 T = PR.gen() … … 1702 1888 1703 1889 It is a general fact about Duursma zeta polynomials that P(1) = 1. 1890 1891 REFERENCES: 1892 [D] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 1704 1893 """ 1705 1894 d0 = C.divisor() … … 1707 1896 P = C.sd_duursma_q(type,d0) 1708 1897 PR = P.parent() 1709 T = PR.gen()1898 T = FractionField(PR).gen() 1710 1899 if type == 1: return P 1711 1900 if type == 2: return P/(1-2*T+2*T**2) -
sage/coding/linear_code.py
r7750 r7751 466 466 # Ub(7,4) = 3 follows by the Griesmer bound. 467 467 def __init__(self, gen_mat): 468 base_ring = gen_mat[0 ][0].parent()468 base_ring = gen_mat[0,0].parent() 469 469 ParentWithGens.__init__(self, base_ring) 470 470 self.__gens = gen_mat.rows() 471 471 self.__gen_mat = gen_mat 472 self.__length = len(gen_mat [0])472 self.__length = len(gen_mat.row(0)) 473 473 self.__dim = gen_mat.rank() 474 474 … … 1121 1121 MS = MatrixSpace(F,r,n) 1122 1122 Grref = G3.echelon_form() 1123 G = MS([Grref [i]for i in range(r)])1123 G = MS([Grref.row(i) for i in range(r)]) 1124 1124 return LinearCode(G) 1125 1125
Note: See TracChangeset
for help on using the changeset viewer.
