Changeset 7751:adb0d92010f4


Ignore:
Timestamp:
12/15/07 16:29:09 (5 years ago)
Author:
mabshoff@…
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.
Message:

merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sage/coding/linear_code.py

    r7723 r7751  
    22Linear Codes 
    33 
    4 VERSION: 0.8 
     4VERSION: 0.9 
    55 
    66Let $ F$ be a finite field (we denote the finite field with $q$ elements 
     
    1717called the {\it dual space} of  $C$. 
    1818 
    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}.  
     19If $ F=\FF_2$ then $C$ is called a {\it binary code}.  
     20If $ F = \FF_q$ then $C$ is called a {\it $ q$-ary code}. 
     21The elements of a code $C$ are called {\it codewords}.  
    2222 
    2323Let $ F$ be a finite field with $ q$ elements. Here's a constructive  
     
    6868\item 
    6969The spectrum (weight distribution), minimum distance  
    70 programs (calling Steve Linton's C programs), and zeta_function for 
    71 the Duursma zeta function. 
     70programs (calling Steve Linton's C programs), characteristic function, 
     71and several implementations of the Duursma zeta function. 
    7272\item 
    73 interface with A. Brouwer's online tables, as well as 
    74 best_known_linear_code, bounds_minimum_distance which call tables 
     73interface with best_known_linear_code (interface with A. Brouwer's online tables has 
     74been disabled), bounds_minimum_distance which call tables 
    7575in GUAVA (updated May 2006) created by Cen Tjhai instead of the online 
    7676internet tables. 
    7777\item 
    78 ToricCode, TrivialCode (in a separate module, you will find the constructions 
     78ToricCode, TrivialCode (in a separate "guava.py" module, you will find the constructions 
    7979Hamming codes, "random" linear codes, Golay codes, binary Reed-Muller codes, 
    8080binary quadratic and extended quadratic residue codes, cyclic codes, all 
     
    147147Completely rewritten zeta_function (old version is now zeta_function2) 
    148148and 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) 
    149153 
    150154TESTS: 
     
    157161 
    158162#***************************************************************************** 
    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> 
    161165# 
    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). 
    163168# 
    164169#                  http://www.gnu.org/licenses/ 
     
    169174import sage.modules.module as module 
    170175import sage.modules.free_module_element as fme 
    171 #from sage.databases.lincodes import linear_code_bound 
    172176from 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  
     177from sage.rings.finite_field import GF 
     178from sage.groups.perm_gps.permgroup import PermutationGroup 
    179179from sage.matrix.matrix_space import MatrixSpace 
    180  
    181180from sage.rings.arith import GCD, rising_factorial, binomial 
    182  
    183181from sage.groups.all import SymmetricGroup 
    184182from sage.misc.sage_eval import sage_eval 
    185183from sage.misc.misc import prod, add 
    186 from sage.misc.functional import log 
     184from sage.misc.functional import log, is_even, is_odd 
    187185from sage.rings.rational_field import QQ 
    188186from sage.structure.parent_gens import ParentWithGens 
     
    191189from sage.rings.integer_ring import IntegerRing 
    192190from sage.combinat.set_partition import SetPartitions 
     191from sage.rings.real_mpfr import RR      ## RealField 
    193192 
    194193ZZ = IntegerRing() 
     
    230229    z = 'Z(%s)*%s'%(q, [0]*n)     # GAP zero vector as a string 
    231230    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 
    232235    #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 
    234237    return v 
    235238 
     
    243246     
    244247    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. 
    246250 
    247251    EXAMPLES: 
    248252        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]]" 
    249253        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) 
    251255 
    252256    Here Gstr is a generator matrix of the Hamming [7,4,3] binary code.  
     
    254258    AUTHOR: David Joyner (11-2005) 
    255259    """  
     260    from sage.rings.finite_field import gap_to_sage 
    256261    gap.eval("G:="+Gmat) 
    257     k = int(gap.eval('Length(G)')) 
     262    k = int(gap.eval("Length(G)")) 
    258263    q = F.order() 
    259264    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 
    281288 
    282289## def minimum_distance_lower_bound(n,k,F): 
     
    342349    EXAMPLES: 
    343350        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))") 
    344353        'a linear [10,5,4]2..4 shortened code' 
    345354 
     
    350359    """ 
    351360    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)) 
    353369     
    354370def bounds_minimum_distance(n,k,F): 
     
    467483 
    468484    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 
    469497        F = self.base_ring() 
    470498        q = F.order() 
    471499        G = self.gen_mat() 
    472500        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)] 
    477504        V = VectorSpace(F,n) 
    478505        return V(ans) 
     
    613640        gapG = gap(G) 
    614641        Gstr = "%s*Z(%s)^0"%(gapG, q) 
    615         return min_wt_vec(Gstr,F)[2] 
     642        return hamming_weight(min_wt_vec(Gstr,F)) 
    616643 
    617644    def genus(self): 
     
    675702        Does not work for very long codes since the syndrome table grows too large. 
    676703        """ 
     704        from sage.rings.finite_field import gap_to_sage 
    677705        F = self.base_ring() 
    678706        q = F.order() 
     
    713741            return TrivialCode(F,n) 
    714742        Gstr = str(gap(G))          
    715         C = gap.GeneratorMatCode(Gstr, 'GF(%s)'%q) 
    716743        #H = C.CheckMat() 
    717744        #A = H._matrix_(GF(q)) 
    718745        #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) 
    723750        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)) 
    732752 
    733753    def extended_code(self): 
     
    749769  
    750770        """ 
    751         from sage.rings.finite_field import gap_to_sage 
    752771        G = self.gen_mat() 
    753772        F = self.base_ring() 
     
    757776        Gstr = str(gap(G)) 
    758777        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) 
    763782        MS = MatrixSpace(F,k,n+1) 
    764         return LinearCode(MS(Gx)) 
     783        return LinearCode(MS(Gxs)) 
    765784     
    766785    def check_mat(self): 
     
    885904            sage: C = ExtendedTernaryGolayCode() 
    886905            sage: M11 = MathieuGroup(11) 
    887             sage: G = C.permutation_automorphism_group()  ## this should take < 15 seconds                                    # long time 
     906            sage: G = C.permutation_automorphism_group()  ## this should take < 15 seconds  # long time 
    888907            sage: G.is_isomorphic(M11)        # long time 
    889908            True 
    890909 
     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. 
    891912        """ 
    892913        F = self.base_ring() 
     
    935956    def permuted_code(self,p): 
    936957        r""" 
    937         Returns the permuted code -- the code $C$ which is equivalenet 
     958        Returns the permuted code -- the code $C$ which is equivalent 
    938959        to self via the column permutation $p$. 
    939960 
     
    10241045        if mode=="verbose": 
    10251046            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) 
    10301050        MS = MatrixSpace(F,k,n) 
    1031         return LinearCode(MS(Gp)),p 
     1051        return LinearCode(MS(Gs)),p 
    10321052         
    10331053    def module_composition_factors(self,gp): 
     
    10711091        EXAMPLES: 
    10721092            sage: C = HammingCode(3,GF(4,'a')) 
    1073             sage: C 
     1093            sage: Cc = C.galois_closure(GF(2)) 
     1094            sage: C; Cc 
    10741095            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: Cc 
    10771096            Linear code of length 21, dimension 20 over Finite Field in a of size 2^2 
    10781097            sage: c = C.random() 
    1079             sage: c  ## random output 
    1080             (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) 
    10811098            sage: V = VectorSpace(GF(4,'a'),21) 
    10821099            sage: c2 = V([x^2 for x in c.list()]) 
     
    12321249        return 0 
    12331250 
     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 
    12341403    def zeta_function2(self,mode=None): 
    12351404        r""" 
    12361405        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. 
    12371412 
    12381413        INPUT: 
     
    12631438             Trans. A.M.S., 351 (1999)3609-3639. 
    12641439 
    1265         NOTE: This is somewhat experimental code. It sometimes 
    1266         returns "fail" for a reason I don't fully understand. 
    1267         However, when it does return a polynomial, the answer is 
    1268         (as far as I know) correct. 
    12691440        """ 
    12701441        from sage.rings.polynomial.polynomial_ring import PolynomialRing 
     
    12771448        n = self.length() 
    12781449        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" 
    12791454        gammaC = n+1-d #  C.genus()  
    12801455        if mode=="dual": 
     
    13231498        return "fails" 
    13241499 
    1325     def zeta_function(self,mode=None): 
     1500    def zeta_function3(self,mode=None): 
    13261501        r""" 
    13271502        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. 
    13281508 
    13291509        INPUT: 
     
    13371517 
    13381518        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()  
    13411521            (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() 
    13441524            (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") 
    13461526            ((3/7*T^2 + 3/7*T + 1/7)/(3*T^2 - 4*T + 1), 
    13471527             (729/7*T^2 + 729/7*T + 243/7)/(729*T^2 - 972*T + 243)) 
     
    13561536        n = self.length() 
    13571537        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" 
    13581542        gammaC = n+1-k-d 
    13591543        if mode=="dual": 
     
    14231607 
    14241608        """ 
    1425         from sage.rings.finite_field import gap_to_sage 
    14261609        G = self.gen_mat() 
    14271610        F = self.base_ring() 
     
    14321615        Gstr = str(gap(G)) 
    14331616        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 = k 
    1437         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) 
    14391622        MS = MatrixSpace(F,kL,nL) 
    14401623        return LinearCode(MS(G2)) 
     
    14551638 
    14561639        """ 
    1457         from sage.rings.finite_field import gap_to_sage 
    14581640        G = self.gen_mat() 
    14591641        F = self.base_ring() 
     
    14641646        Gstr = str(gap(G)) 
    14651647        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) 
    14711655        MS = MatrixSpace(F,kL,nL) 
    1472         return LinearCode(MS(Gs)) 
     1656        return LinearCode(MS(Gss)) 
    14731657 
    14741658    def binomial_moment(self,i): 
     
    14881672            0 
    14891673            sage: C.binomial_moment(3)    # long time 
    1490             4 
     1674            0 
    14911675            sage: C.binomial_moment(4)    # long time 
    14921676            35 
     
    15961780            
    15971781        RETURN:   
    1598            The data v,m as in Duursama [1] 
     1782           The data v,m as in Duursama [D] 
    15991783     
    16001784        EXAMPLES: 
    16011785     
    16021786        REFERENCES: 
    1603             [1] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 
     1787            [D] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 
    16041788 
    16051789        """ 
     
    16301814     
    16311815        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]. 
    16331817 
    16341818        EXAMPLES: 
    16351819 
    16361820        REFERENCES: 
    1637             [1] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 
     1821            [D] I. Duursma, "Extremal weight enumerators and ultraspherical polynomials" 
    16381822 
    16391823        """ 
     
    16551839        m = ZZ(C.sd_duursma_data(i)[1]) 
    16561840        #print m,v,d,d0,c0 
     1841        if m<0 or v<0: 
     1842            raise ValueError("This case not implemented.") 
    16571843        PR = PolynomialRing(QQ,"T") 
    16581844        T = PR.gen() 
     
    17021888 
    17031889        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" 
    17041893        """ 
    17051894        d0 = C.divisor() 
     
    17071896        P = C.sd_duursma_q(type,d0) 
    17081897        PR = P.parent() 
    1709         T = PR.gen() 
     1898        T = FractionField(PR).gen() 
    17101899        if type == 1: return P 
    17111900        if type == 2: return P/(1-2*T+2*T**2) 
  • sage/coding/linear_code.py

    r7750 r7751  
    466466    #    Ub(7,4) = 3 follows by the Griesmer bound. 
    467467    def __init__(self, gen_mat): 
    468         base_ring = gen_mat[0][0].parent() 
     468        base_ring = gen_mat[0,0].parent() 
    469469        ParentWithGens.__init__(self, base_ring) 
    470470        self.__gens = gen_mat.rows() 
    471471        self.__gen_mat = gen_mat 
    472         self.__length = len(gen_mat[0]) 
     472        self.__length = len(gen_mat.row(0)) 
    473473        self.__dim = gen_mat.rank() 
    474474 
     
    11211121        MS = MatrixSpace(F,r,n) 
    11221122        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)]) 
    11241124        return LinearCode(G) 
    11251125 
Note: See TracChangeset for help on using the changeset viewer.