# Sage code for finding generator matrix of MDS code

1. Let $$L$$ be an $$[n,k]$$ code. A $$k\times n$$ matrix $$G$$ whose rows form a basis for $$L$$ is called a generator matrix for $$L$$.

2. A linear $$[n,k,d]$$ code with largest possible minimum distance is called maximum distance $$d$$ separable or MDS code.

I want to find a generator matrix for MDS code using SageMath or in another way, is there any SageMath code to check a matrix is a generator matrix for the MDS code. Any help with the SageMath code for the generator matrix will be appreciated.

You can use LinearCode (with the generator matrix as the argument):

sage: C = LinearCode(random_matrix(GF(11), 3, 7))
sage: C.minimum_distance()
4


However, for general codes (e.g. random codes), finding the minimum distance (and checking if it's MDS) is a hard problem. Therefore, you can only do it for small matrices.

To generate an MDS matrix, you can use concrete constructions, such as the Cauchy matrix. The generator matrix of the associated linear code can be obtained by concatenating it with the identity matrix.

• Could you provide a paper for the hardness of the problem? Nov 17 '21 at 19:59
• @kelalaka See e.g. madhu.seas.harvard.edu/papers/1999/dms-journ.pdf , even approximating the minimum distance up to a constant factor is hard Nov 18 '21 at 13:06