Ask Your Question

Revision history [back]

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 code unless called with return_code=False
  • only print the information if called with verbose=True

To have it work similar to the one in the 2015 paper, run gabidulin(2, 2, return_code=False, verbose=True).

def gabidulin(n, k, return_code=True, verbose=False):
    r"""
    Return Gabidulin code for the given parameters.
    """
    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'Linearly independent vectors NL ={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('The Gabidulin code with parameters', [n, k, n - k + 1], 'is:')
    msg('CODE_GAB =', GAB)
    msg('Number of codewords:', len(GAB))
    if return_code:
        return GAB
    return

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 code computed Gabidulin code, unless called with return_code=False
  • only print the information if called with verbose=True (the default being False)

To have it work similar to the one in the 2015 paper, run gabidulin(2, 2, return_code=False, verbose=True).(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)
    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'Linearly independent vectors NL ={NL}')
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('The     msg(f'The Gabidulin code with parameters', [n, parameters {[n, k, n - k + 1], 'is:')
    msg('CODE_GAB =', GAB)
    msg('Number 1]} is:')
    msg(f'CODE_GAB = {GAB}')
    msg(f'Number of codewords:', len(GAB))
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)
...

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')
'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.

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 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.