Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

am very grateful for your reply, which almost completely solved my problem.

In fact, the MRD code has a third parameter d, d<=k, (assuming n>=k), which can generate q ^ {n * (k-d+1)} codewords. Let's skip this first.

But when I run the program, there were still issues:

TypeError Traceback (most recent call last) <ipython-input-9-4a93261ea30c> in <module>() ----> 1 g = gabidulin(Integer(2), Integer(2))

<ipython-input-8-40945cd68ef7> in gabidulin(n, k, return_code, verbose) 11 msg = print if verbose else lambda args, *opt: None 12 F = GF(Integer(2)) ---> 13 G = GF((Integer(2), n), 'a') 14 a = G.gen() 15

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)() 365 False 366 """ --> 367 key, kwds = self.create_key_and_extra_args(args, *kwds) 368 version = self.get_version(sage_version) 369 return self.get_object(version, key, kwds)

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/finite_rings/finite_field_constructor.py in create_key_and_extra_args(self, order, name, modulus, names, impl, proof, check_irreducible, prefix, repr, elem_cache, **kwds) 523 raise NotImplementedError("ring extension with prescribed %s is not implemented"%key) 524 with WithProof('arithmetic', proof): --> 525 order = Integer(order) 526 if order <= 1: 527 raise ValueError("the order of a finite field must be at least 2")

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6967)() 740 return 741 --> 742 raise TypeError("unable to coerce %s to an integer" % type(x)) 743 744 def __reduce__(self):

TypeError: unable to coerce <class 'tuple'=""> to an integer

am very grateful for your reply, which almost completely solved my problem.

In fact, the MRD code has a third parameter d, d<=k, d, d <= k, (assuming n>=k), n >= k), which can generate q ^ {n * (k-d+1)} (k-d+1)} codewords. Let's skip this first.

But when I run the program, there were still issues:

TypeError     Traceback (most recent call last)
<ipython-input-9-4a93261ea30c> in <module>()
----> 1 g = gabidulin(Integer(2), Integer(2))

Integer(2)) <ipython-input-8-40945cd68ef7> in gabidulin(n, k, return_code, verbose) 11 msg = print if verbose else lambda args, *opt: *args, **opt: None 12 F = GF(Integer(2)) ---> 13 G = GF((Integer(2), n), 'a') 14 a = G.gen() 15

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)() 365 False 366 """ --> 367 key, kwds = self.create_key_and_extra_args(args, *kwds) self.create_key_and_extra_args(*args, **kwds) 368 version = self.get_version(sage_version) 369 return self.get_object(version, key, kwds)

kwds) /opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/finite_rings/finite_field_constructor.py in create_key_and_extra_args(self, order, name, modulus, names, impl, proof, check_irreducible, prefix, repr, elem_cache, **kwds) 523 raise NotImplementedError("ring extension with prescribed %s is not implemented"%key) 524 with WithProof('arithmetic', proof): --> 525 order = Integer(order) 526 if order <= 1: 527 raise ValueError("the order of a finite field must be at least 2")

2") /opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6967)() 740 return 741 --> 742 raise TypeError("unable to coerce %s to an integer" % type(x)) 743 744 def __reduce__(self):

__reduce__(self): TypeError: unable to coerce <class 'tuple'=""> 'tuple'> to an integer

integer

am Thank you very grateful much for your reply, which almost completely solved my problem.

In fact, the MRD code has a code and guidance.
I tried to generalize the generating code by adding the
third parameter d, d <= k, (assuming n >= k), and slightly modifying the code as follows, but it doesn't seem to work.

C = [sum(ni[j] * x^2^j for j in range(k)) for ni in N]

is modified into the following:

C = [sum(ni[j] * x^2^j for j in range(k-d+1)) for ni in N]

As a running example, gabidulin(3,3,2,0,0) is same to gabidulin(3,3,1,0,0), which can generate q ^ {n * (k-d+1)} codewords. Let's skip this first.

But when I run the program, there were still issues:surprised me a lot.

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

TypeError     Traceback (most recent call last)
<ipython-input-9-4a93261ea30c> in <module>()
----> 1 g = gabidulin(Integer(2), Integer(2))

<ipython-input-8-40945cd68ef7> in gabidulin(n, k, return_code, verbose)
     11     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
     12     F = GF(Integer(2))
---> 13     GF(2)
G = GF((Integer(2), n), GF(2^n, 'a')
     14     a = G.gen()
     15 

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/structure/factory.pyx in sage.structure.factory.UniqueFactory.__call__ (build/cythonized/sage/structure/factory.c:2162)()
    365             False
    366         """
--> 367         key, kwds = self.create_key_and_extra_args(*args, **kwds)
    368         version = self.get_version(sage_version)
    369     
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)
N = Tuples(L, k)
print(f'N={N}')
C = [sum(ni[j] * x^2^j for j in range(k-d+1)) 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, d]} is:')
print(f'CODE_GAB = {GAB}')
print(f'Number of codewords: {len(GAB)}')

#write codes to file
fh=open('mrdcodes.txt','w+')
for i in range(len(GAB)):
    fh.write(str(GAB[i]))

if return_code:
    return self.get_object(version, key, kwds)

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/finite_rings/finite_field_constructor.py in create_key_and_extra_args(self, order, name, modulus, names, impl, proof, check_irreducible, prefix, repr, elem_cache, **kwds)
    523                 raise NotImplementedError("ring extension with prescribed %s is not implemented"%key)
    524         with WithProof('arithmetic', proof):
--> 525             order = Integer(order)
    526             if order <= 1:
    527                 raise ValueError("the order of a finite field must be at least 2")

/opt/sagemath-9.0/local/lib/python3.7/site-packages/sage/rings/integer.pyx in sage.rings.integer.Integer.__init__ (build/cythonized/sage/rings/integer.c:6967)()
    740                     GAB
return
    741 
--> 742                 raise TypeError("unable to coerce %s to an integer" % type(x))
    743 
    744     def __reduce__(self):

TypeError: unable to coerce <class 'tuple'> to an integer

g = gabidulin(3,3,2,0,0)

Thank you very much for your code and guidance.
I tried try to generalize the generating code by adding the third parameter d and slightly modifying the code as follows, but it doesn't seem to work.

C = [sum(ni[j] * x^2^j for j in range(k)) for ni in N]

is modified into the following:

C = [sum(ni[j] * x^2^j for j in range(k-d+1)) for ni in N]

As a running example, the codes generated by gabidulin(3,3,2,0,0) is same to that of gabidulin(3,3,1,0,0), which surprised me a lot. Actually, the size of the codes generated by gabidulin(3,3,2,0,0) should be 64, not 512.

def gabidulin(n, k, d, 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)
G = GF(2^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)
N = Tuples(L, k)
print(f'N={N}')
C = [sum(ni[j] * x^2^j for j in range(k-d+1)) 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, d]} is:')
print(f'CODE_GAB = {GAB}')
print(f'Number of codewords: {len(GAB)}')

#write codes to file
fh=open('mrdcodes.txt','w+')
for i in range(len(GAB)):
    fh.write(str(GAB[i]))

if return_code:
    return GAB
return

g = gabidulin(3,3,2,0,0)

Thank you very much for your code and guidance.

I try to generalize the generating code by adding the third parameter d d and slightly modifying the code as follows, but it doesn't seem to work.

C = [sum(ni[j] * x^2^j for j in range(k)) for ni in N]

N]

is modified into the following:

C = [sum(ni[j] * x^2^j for j in range(k-d+1)) for ni in N]

N]

As a running example, the codes generated by gabidulin(3,3,2,0,0) gabidulin(3,3,2,0,0) is same to that of gabidulin(3,3,1,0,0), gabidulin(3,3,1,0,0), which surprised me a lot. lot.

Actually, the size of the codes generated by gabidulin(3,3,2,0,0) gabidulin(3,3,2,0,0) should be 64, not 512.

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

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)
 G = GF(2^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)
 N = Tuples(L, k)
 print(f'N={N}')
 C = [sum(ni[j] * x^2^j for j in range(k-d+1)) for ni in N]
#msg(f'Linearized     # msg(f'Linearized polynomial of linear degree less than {k}:')
#msg('\n'.join(f'     # 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, d]} is:')
 print(f'CODE_GAB = {GAB}')
 print(f'Number of codewords: {len(GAB)}')

#write     # write codes to file
 fh=open('mrdcodes.txt','w+')
 for i in range(len(GAB)):
     fh.write(str(GAB[i]))

 if return_code:
     return GAB
 return

g = gabidulin(3,3,2,0,0)

g = gabidulin(3,3,2,0,0)

Thank you very much for your It seems that I have solved the problem by myself. If possible, please help me check this code and guidance. see if it can generate any suitable parameter MRD codes

I try to generalize the generating code by adding the third parameter d and slightly modifying the code as follows, but it doesn't seem to work.

C = [sum(ni[j] * x^2^j for j in range(k)) for ni in N]

is modified into the following:

C = [sum(ni[j] * x^2^j for j in range(k-d+1)) for ni in N]

As a running example, the codes generated by gabidulin(3,3,2,0,0) is same to that of gabidulin(3,3,1,0,0), which surprised me a lot.

Actually, the size of the codes generated by gabidulin(3,3,2,0,0) should be 64, not 512.

def gabidulin(n, k, d, q=2, return_code=True, verbose=False):
    r"""
    Return a Gabidulin code for the given parameters.
     INPUT:
     - ``n``, ``k`` n, k -- the parameters
    - ``return_code``: return_code: whether to return the Gabidulin code
    - ``verbose``: verbose: whether to print information
    """
    msg = print if verbose else lambda *args, **opt: args, *opt: None
    F = GF(2)
GF(q)
    G = GF(2^n, 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)
k-d+1)
    print(f'N={N}')
    L = list(G)
    C = [sum(ni[j] * x^2^j x^q^j for j in range(k-d+1)) 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()] 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, d]} is:')
    print(f'CODE_GAB = {GAB}')
    print(f'Number of codewords: {len(GAB)}')

    # write codes to file
    fh=open('mrdcodes.txt','w+')
    for i in range(len(GAB)):
        fh.write(str(GAB[i]))

fname=f'mrdcodes_{n}_{k}_{d}_{q}.txt'
    fh=open(fname,'w+')
    for c in GAB: 
fh.write(str(c)) print(f'GAB length ={len(GAB)}')
if return_code: return GAB return g = gabidulin(3,3,2,0,0)
return

gabidulin(3,3,2,3,0,0)

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 ``n``, ``k`` -- the parameters
    - return_code: ``return_code``: whether to return the Gabidulin code
    - verbose: ``verbose``: whether to print information
    """
    msg = print if verbose else lambda args, *opt: *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:]]
    fname=f'mrdcodes_{n}_{k}_{d}_{q}.txt'
    fh=open(fname,'w+')
    for c in GAB: 
fh.write(str(c)) print(f'GAB length ={len(GAB)}') if return_code: return GAB return

return gabidulin(3,3,2,3,0,0)

gabidulin(3,3,2,3,0,0)

It seems that I have solved the problem by myself. myself.

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

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}')
k - d + 1)
    print(f'N = {N}')
    L = list(G)
    C = [sum(ni[j] * x^q^j for j in range(k-d+1)) range(k - d + 1)) for ni in N]
    GAB=[[R.zero()] GAB = [[R.zero()] * len(pp)] +  [[R(c(p)) for p in pp] for c in C[1:]]
    fname=f'mrdcodes_{n}_{k}_{d}_{q}.txt'
    fh=open(fname,'w+')
filename = f'mrdcodes_{n}_{k}_{d}_{q}.txt'
    with open(filename, 'w+') as file:
        for c in GAB:       
        fh.write(str(c))
GAB:
            file.write(str(c))
    print(f'GAB length ={len(GAB)}')
= {len(GAB)}')
    if return_code:
        return GAB
    return

gabidulin(3,3,2,3,0,0)
gabidulin(3, 3, 2, 3, 0, 0)