Ask Your Question
1

Generating Gabidulin codes

asked 2023-05-17 15:49:24 +0100

lake.chao gravatar image

updated 2023-05-20 17:18:59 +0100

slelievre gravatar image

I saw an algorithm in the paper

Ismael Gutierrez Garcia; Yesneri Zuleta Saldarriaga.
"An algorithm to generate binary Gabidulin codes using Sage."
IEEE Latin America Transactions, vol. 13, no. 5, pp. 1469-1477, May 2015,
doi: 10.1109/TLA.2015.7112004.

that can be used to generate Gabidulin codes.

When I run gab_yz(2, 2), this error occurs:

------------------------------------------------------------------------
AttributeError    Traceback (most recent call last)
<ipython-input-9-f7a4cca9f105> in <module>()
----> 1 gab_yz(Integer(3),Integer(2))
<ipython-input-8-54b8ef1a8277> in gab_yz(m, K)
     74             while y<len(pp):
     75                 CC=C[u](pp[y])
---> 76                 GP=CC.full_simplify()
     77                 y=y+Integer(1)
     78                 CL+=[R(CC)]

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4609)()
    485             AttributeError: 'LeftZeroSemigroup_with_category.element_class' object has no attribute 'blah_blah'
    486         """
--> 487         return self.getattr_from_category(name)
    488 
    489     cdef getattr_from_category(self, name):

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4718)()
    498         else:
    499             cls = P._abstract_element_class
--> 500         return getattr_from_other_class(self, cls, name)
    501 
    502     def __dir__(self):

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/cpython/getattr.pyx in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:2614)()
    392         dummy_error_message.cls = type(self)
    393         dummy_error_message.name = name
--> 394         raise AttributeError(dummy_error_message)
    395     attribute = <object>attr
    396     # Check for a descriptor (__get__ in Python)

AttributeError: 'sage.rings.polynomial.polynomial_zz_pex.Polynomial_ZZ_pEX' object has no attribute 'full_simplify'

Here is the definition of gab_yz:

def gab_yz(m,K):
    n=m
    var('w,a')
    ratpoly.<a> = PolynomialRing(ZZ)
    qq=2^(n)
    GG=GF(qq,'a')
    Z=GG.list()
    nset=[y for y in Z if y!=0]
    N=Combinations(nset,n).list()
    U=[vector(z) for z in Z]
    mset = [w for w in U if w!=0]
    M=Combinations(mset,n).list()
    Q=[]
    i=0
    while i<len(M):
        V=VectorSpace(GF(2), n)
        V= V.subspace(M[i])
        base=V.basis()
        if len(base)==n:
           Q+=[M[i]]
        else:
            Q+=[base]
        i=i+1
    j=randint(0,len(M)-1)
    NL=Q[j]
    print('Linearly independent vectors NL=', NL)

    pp=[]
    for t in range(len(NL)):
        ss=0
        for g in range(n):
           ss+=NL[t][g]*(a^g)
           pp+=[ss]
    print('Linearly independent vectors in polynomial representation', pp)
    mj=K
    r=m
    d=mj-1
    q=2^(r)
    G= GF(q,'a')

    ratpoly.<x> = PolynomialRing(ZZ)
    L=list(G)
    N=Tuples(L,d+1).list()
    C=[]
    print('Linearized polynomial of linear degree less than',mj,':')
    ii=0
    while ii<len(N):
        s=0
        k=0
        while k<(d+1):
            s+=N[ii][k]*(x^2^(k))
            k=k+1
        ii=ii+1
        print(' ',s)
        C+=[s]
    print('Number of linearized polynomial', len(C))

    GAB=[]
    CC=[]
    SS=[]
    R=PolynomialRing(Zmod(2),'a')
    l=0
    u=0
    while u<len(C):
        CL=[]
        y=0
        if u==0:
            while y<len(pp):
                CC=0
                y=y+1
                CL+=[CC]
                GAB+=[CL]
        else:
            while y<len(pp):
                CC=C[u](pp[y])
                GP=CC.full_simplify()
                y=y+1
                CL+=[R(CC)]
            GAB+=[CL]
        u=u+1
    print('The Gabidulin code with parameters' ,[n,mj,n-mj+1],'is:')
    print('CODE_GAB=',GAB)
    print('Number of codeword is:',len(GA))
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2023-05-20 17:26:53 +0100

slelievre gravatar image

updated 2023-05-25 13:18:58 +0100

The gab_yz function from the 2015 paper no longer works in modern Sage.

Furthermore, it can be made quite a lot more concise.

Here is a rewritten version which will

  • actually return the computed Gabidulin code, unless called with return_code=False
  • only print the information if called with verbose=True (the default being False)

(the original function only displays information, but returns nothing).

def gabidulin(n, k, return_code=True, verbose=False):
    r"""
    Return a Gabidulin code for the given parameters.

    INPUT:

    - ``n``, ``k`` -- the parameters
    - ``return_code``: whether to return the Gabidulin code
    - ``verbose``: whether to print information
    """
    msg = print if verbose else lambda *args, **opt: None

    F = GF(2)
    try:
        G = GF((2, n), 'a')  # works in Sage >= 9.5.beta0
    except TypeError:
        G = GF(2^n, 'a')  # fallback for Sage <= 9.4
    a = G.gen()

    V = VectorSpace(F, n)
    R = F['a']
    x = polygen(G)

    nset = [g for g in G if g]
    N = Combinations(nset, n)
    mset = [vector(z) for z in nset]
    M = Combinations(mset, n)
    Q = [mi if W.dimension() == n else W.basis()
         for mi in M for W in [V.subspace(mi)]]
    NL = choice(Q)
    msg(f'Linearly independent vectors g = {NL}')

    pp = [sum(f[g] * a^g for g in range(n)) for f in NL]
    msg(f'Linearly independent vectors in polynomial representation: {pp}')

    L = list(G)
    N = Tuples(L, k)
    C = [sum(ni[j] * x^(2^j) for j in range(k)) for ni in N]
    msg(f'Linearized polynomial of linear degree less than {k}:')
    msg('\n'.join(f'  {c}' for c in C))
    msg(f'Number of linearized polynomials: {len(C)}')

    GAB = [[R.zero()] * len(pp)] +  [[R(c(p)) for p in pp] for c in C[1:]]
    msg(f'The Gabidulin code with parameters {[n, k, n - k + 1]} is:')
    msg(f'CODE_GAB = {GAB}')
    msg(f'Number of codewords: {len(GAB)}')

    if return_code:
        return GAB
    return

To have it return a Gabidulin code that can be reused, run for instance:

sage: g = gabidulin(2, 2)
sage: g
...

To have it work similar to the function in the paper, run for instance:

sage: gabidulin(2, 2, return_code=False, verbose=True)
...

Note: The input GF((2, n), 'a') is only accepted in recent versions of Sage.

This was introduced by Sage Trac ticket 17568, merged in Sage 9.5.beta0 (and also discussed at the duplicate Sage trac ticket 31709).

I recommend installing SageMath 10.0, see the Sage installation guide.

edit flag offensive delete link more

Comments

MRD codes is a buliding block for the constant dimension code. Now, we have express the MRD codes with polymial How to rewrite the polynomial to matrices?

lake.chao gravatar imagelake.chao ( 2024-05-13 17:31:31 +0100 )edit
0

answered 2023-05-20 21:56:44 +0100

lake.chao gravatar image

updated 2023-06-06 10:55:48 +0100

slelievre gravatar image

It seems that I have solved the problem by myself.

If possible, please help me check this code and see if it can generate any suitable parameter MRD codes.

def gabidulin(n, k, d, q=2, return_code=True, verbose=False):
    r"""
    Return a Gabidulin code for the given parameters.
    INPUT:
    - ``n``, ``k`` -- the parameters
    - ``return_code``: whether to return the Gabidulin code
    - ``verbose``: whether to print information
    """
    msg = print if verbose else lambda *args, **opt: None
    F = GF(q)
    G = GF(q^n, 'a')
    a = G.gen()
    V = VectorSpace(F, n)
    R = F['a']
    x = polygen(G)
    nset = [g for g in G if g]
    N = Combinations(nset, n)
    mset = [vector(z) for z in nset]
    M = Combinations(mset, n)
    Q = [mi if W.dimension() == n else W.basis()
         for mi in M for W in [V.subspace(mi)]]
    NL = choice(Q)
    msg(f'NL Linearly independent vectors g = {NL}')
    pp = [sum(f[g] * a^g for g in range(n)) for f in NL]
    msg(f'pp Linearly independent vectors in polynomial representation: {pp}')
    L = list(G)
    print(L)
    N = Tuples(L, k - d + 1)
    print(f'N = {N}')
    L = list(G)
    C = [sum(ni[j] * x^q^j for j in range(k - d + 1)) for ni in N]
    GAB = [[R.zero()] * len(pp)] +  [[R(c(p)) for p in pp] for c in C[1:]]
    filename = f'mrdcodes_{n}_{k}_{d}_{q}.txt'
    with open(filename, 'w+') as file:
        for c in GAB:
            file.write(str(c))
    print(f'GAB length = {len(GAB)}')
    if return_code:
        return GAB
    return

gabidulin(3, 3, 2, 3, 0, 0)
edit flag offensive delete link more

Comments

MRD codes is a buliding block for the constant dimension code. Now, we have express the MRD codes with polymial How to rewrite the polynomial to matrices?

Thank you so much and I appreciate your help.

lake.chao gravatar imagelake.chao ( 2024-05-13 17:28:39 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-05-17 15:49:24 +0100

Seen: 602 times

Last updated: Jun 06 '23