Beispiel #1
0
def HammingCode(r,F):
    r"""
    Implements the Hamming codes.

    The `r^{th}` Hamming code over `F=GF(q)` is an
    `[n,k,d]` code with length `n=(q^r-1)/(q-1)`,
    dimension `k=(q^r-1)/(q-1) - r` and minimum distance
    `d=3`. The parity check matrix of a Hamming code has rows
    consisting of all nonzero vectors of length r in its columns,
    modulo a scalar factor so no parallel columns arise. A Hamming code
    is a single error-correcting code.

    INPUT:


    -  ``r`` - an integer 2

    -  ``F`` - a finite field.


    OUTPUT: Returns the r-th q-ary Hamming code.

    EXAMPLES::

        sage: HammingCode(3,GF(2))
        Linear code of length 7, dimension 4 over Finite Field of size 2
        sage: C = HammingCode(3,GF(3)); C
        Linear code of length 13, dimension 10 over Finite Field of size 3
        sage: C.minimum_distance()
        3
        sage: C.minimum_distance(algorithm='gap') # long time, check d=3
        3
        sage: C = HammingCode(3,GF(4,'a')); C
        Linear code of length 21, dimension 18 over Finite Field in a of size 2^2
    """
    q = F.order()
    n =  (q**r-1)/(q-1)
    k = n-r
    MS = MatrixSpace(F,n,r)
    X = ProjectiveSpace(r-1,F)
    PFn = [list(p) for p in X.point_set(F).points(F)]
    H = MS(PFn).transpose()
    Cd = LinearCode(H)
    # Hamming code always has distance 3, so we provide the distance.
    return LinearCode(Cd.dual_code().gen_mat(), d=3)
def HammingCode(r, F):
    r"""
    Implements the Hamming codes.
    
    The `r^{th}` Hamming code over `F=GF(q)` is an
    `[n,k,d]` code with length `n=(q^r-1)/(q-1)`,
    dimension `k=(q^r-1)/(q-1) - r` and minimum distance
    `d=3`. The parity check matrix of a Hamming code has rows
    consisting of all nonzero vectors of length r in its columns,
    modulo a scalar factor so no parallel columns arise. A Hamming code
    is a single error-correcting code.
    
    INPUT:
    
    
    -  ``r`` - an integer 2
    
    -  ``F`` - a finite field.
    
    
    OUTPUT: Returns the r-th q-ary Hamming code.
    
    EXAMPLES::
    
        sage: HammingCode(3,GF(2))
        Linear code of length 7, dimension 4 over Finite Field of size 2
        sage: C = HammingCode(3,GF(3)); C
        Linear code of length 13, dimension 10 over Finite Field of size 3
        sage: C.minimum_distance()
        3
        sage: C.minimum_distance(algorithm='gap') # long time, check d=3
        3
        sage: C = HammingCode(3,GF(4,'a')); C
        Linear code of length 21, dimension 18 over Finite Field in a of size 2^2
    """
    q = F.order()
    n = (q**r - 1) / (q - 1)
    k = n - r
    MS = MatrixSpace(F, n, r)
    X = ProjectiveSpace(r - 1, F)
    PFn = [list(p) for p in X.point_set(F).points(F)]
    H = MS(PFn).transpose()
    Cd = LinearCode(H)
    # Hamming code always has distance 3, so we provide the distance.
    return LinearCode(Cd.dual_code().gen_mat(), d=3)