All published worksheets from http://sagenb.org
Image: ubuntu2004
Constructing Linear Codes
To construct linear codes, one must first construct the proper Matrix Space. The example that follows gives a name , , for the set of matrices with entries in that have 4 rows and 9 columns.
Now we can define the generator matrix. First, we are naming this matrix and saying that it belongs to , the matrix space defined above. We then list the rows of the matrix as vectors. These are our generating codewords.
Finally, We construct our linear code with generator matrix .
We can get the generator matrix of the code with the command gen_mat()
We can also construct linear codes over .
Getting back to our first exmaple, to get a generator matrix is systematic form, we can use:
Note that this matrix is not in standard form but is in systematic form, meaning that it can be put in standard form by permuting its columns. Doing so gives a generator matrix for an equivalent code. To get a matrix into standard form, we permute the columns in order to obtain the identity matrix on the left. We do this by making a permutation matrix, that is, a matrix, such that when a matrix is multliplied by on the right, the colmns of are permuted. For each pair of columns we wish to swap, we construct an elementary matrix which when is multliplied by on the right, that pair of columns are swapped. If there is only one pair of columns which we need to swap, this elementary matrix is the permutation matrix we need. If not, we can contruct as many elementary matrices as we need, and their product will be our permutation matrix.
In the example above, we need to swap columns 4 and 5 in order to get a matrix in standard form. In Sage, however, the numbering starts with zero, so we need to call columns 4 and 5 columns 3 and 4 respectively. The following command constructs an elementary matrix.
This elementary matrix is simply the identity matrix with columns 4 and 5 interchanged. Since this is the only pair of columns we need to interchange, this is our permutation matrix.
To change the columns back, we simply need to multiply the new matrix by again.
If we had also wanted to swap columns 1 and 9 we would have done the following:
swapped columns 4 and 5 and also swapped columns 1 and 9. The permutation matrix is the identity matrix with these columns interchanged.
We can use the following command to find the parity check matrix for the code.
And to get its transpose,
If we want to multiply a vector by a matrix, we first have to declare the proper vector space, and then use the following syntax to create a vector:
If is a message that we wish to encode by multiplying it by G, we do so as follows:
Here we are creating a vector of length 9. We then see if this vector, , is a codeword.
Here are some more helpful functions.
C.is_permutation_equivalent(D) is a command tells wether the code C is equivalent to the code D. This can be used to see if a code is equivalent to its dual.
Problem 1. Construct a linear code C over of length 11 and dimension 5. Find its minimal distance. Form a message vector of length 5 over the same field and encode it by multiplying it by the generator matrix of C. Change the encoded word by adding an error vector to it of weight less than or equal to . Confirm that this word is not a codeword by multiplying it by the check matrix for the code. Repeat for a code of the same length and dimension over The minimum distance command will not work for , however, so instead of finding it's mimimal distance make an error of weight 1.
Problem 2. Find the distance of the binary linear codes with each of the following parity check matrices.
(a) (b)
Problem 3. Do exercise 4.18 from the text.
Problem 4. No problem 4, there was a mistake here.
Problem 5. Construct a binary code of length 6 as follows: for every construct a 6-bit word , where
,
,
(i)Show that is a linear code.
(ii)Find a generator and parity check matrix for .
Problem 6. Construct a linear code C over such that the generator matix is where is an identity matrix and is symmetric (equal to its transpose). Is self dual? If not, is equivalent to ? If is equivalent to , construct a permutation matrix such that is a generator matrix for .
For those of you taking math 527, also do problems 4.9 and 4.10 from the text.