How this calculation works
Accept a linear subspace of matrices and measure codeword weight by matrix rank. Hamming code enumeration counts nonzero coordinates; it cannot produce rank distance or rank-metric Singleton defect.
d_R(A,B)=rank_GF(p)(A−B); Aᵣ=#{C∈𝒞:rank(C)=r}; d=min{r>0:Aᵣ>0}.A worked example
The GF(3) span of the 2×2 identity contains 0,I,2I. Their ranks are 0,2,2, giving rank distribution [1,0,2] and minimum rank distance 2.
Good to know
Prime field 2,3,5,7; matrix generators 2–4 rows by 2–4 columns, ≤6 generators, independent span size ≤50,000. Exact elimination and enumerated codebook.
Reference: SageMath: Generic structures for linear codes over the rank metric (opens in a new tab) ↗
Matrix rank distance
A matrix code is a linear subspace of equally sized matrices over one prime field. Add codewords entrywise and multiply them by field scalars, using the listed generator matrices.
Flattening matrices helps remove linear dependencies among generators. After that step, reshape every codeword before measuring its weight; the rank metric depends on matrix structure rather than its flattened nonzero count.
Compare this with the Linear error correcting code distance and weight enumerator calculator. Accept a linear subspace of matrices and measure codeword weight by matrix rank. Hamming code enumeration counts nonzero coordinates; it cannot produce rank distance or rank-metric Singleton defect.
Base-field linear subspace input
Rank distance is the rank of the difference matrix. A nonzero difference concentrated in one row can have many nonzero entries yet rank one, while a sparse diagonal matrix can have full rank.
Because the code is linear, subtracting one codeword from another produces another codeword. Thus minimum nonzero codeword rank equals minimum pairwise rank distance, avoiding a separate quadratic pair search. A full binary2×2 matrix space has sixteen codewords: one zero matrix, nine matrices of rank one and six of rank two. Its minimum nonzero rank distance is one. Reading the same four entries as a Hamming word would classify weight by nonzero entry count and give a different distribution. This is why the generator input preserves matrix shape rather than flattening every code into an ordinary coordinate-distance question. A rank-one matrix may have every entry nonzero.
Removing generator dependencies
First compute an independent generator basis over GF(p). Enumerating all coefficient tuples of that basis visits each codeword once, so redundant user generators cannot inflate the reported distribution.
If the independent dimension is k, the total distribution must sum to p^k. Its rank-zero coefficient must be one, since the only rank-zero matrix is the zero matrix.
Rank weight enumerator
The rank distribution lists A₀ through A_min(m,n). Its first positive-rank nonzero coefficient locates the minimum distance, and a matrix attaining that rank supplies a concrete witness.
For the full binary 2×2 matrix space, there are sixteen matrices: one has rank zero, nine have rank one and six are invertible. This distribution checks both enumeration and elimination. The implementation flattens generator matrices only to find a linearly independent field basis of their span. It then enumerates each coefficient tuple, reconstructs the corresponding matrix and computes its rank over the selected field. A dependent entered generator does not enlarge the code. The reported dimension is the basis rank and the code size is p raised to that dimension. For a zero-dimensional code there is no nonzero word, so a minimum nonzero distance is explicitly undefined rather than set to zero.
Minimum-distance matrix witness
The default identity-generated GF(3) code has dimension one and three words. Multiplying I by either nonzero scalar preserves rank two, so there is no rank-one codeword.
Its distribution is therefore [1,0,2]. Reading matrix entries as Hamming symbols would describe a different metric and would fail to explain why all nonzero scalar multiples share the same full rank.
Rank-metric Singleton bound
The rank-metric Singleton bound for an m×n base-field-linear code is k≤max(m,n)(min(m,n)−d+1). Compare the independent base-field dimension with this bound, using the matrix dimensions shown in the result.
Equality identifies the corresponding maximum-rank-distance parameter condition. It does not change the exhaustive evidence required to compute d, and it should not be inferred solely from a chosen generator family name. The rank-metric Singleton defect compares the dimension with max(m,n) times min(m,n)−d+1. A zero defect indicates equality with this bound under the stated linear-code convention. It does not automatically produce an encoder, a decoder or an error-correction guarantee for a different channel. The work bound applies to the enumerated span size, which grows exponentially with dimension even when each matrix is small.
Matrix-code scope and extension-field exclusions
The initial calculator accepts explicit prime-field matrix generators. Codes presented as vectors over an extension field need a chosen base-field basis before conversion, and that additional representation is outside this input contract.
A zero code has no nonzero codeword, so minimum nonzero rank needs a separate convention rather than an invented finite value. Enumeration caps must remain explicit whenever the independent codebook exceeds the permitted size.
A few questions, answered
Why is rank different from Hamming weight?
Hamming weight counts nonzero entries, while rank measures independent rows or columns.
Are matrices vectors over an extension field?
The input is explicitly a base-field-linear matrix subspace; an extension-field interpretation is not assumed.
Do redundant generators change the code?
No. Dependent generators are removed before enumerating the code.
When is a code maximum rank distance?
The parameter condition is equality in the rank-metric Singleton bound, using the computed minimum rank distance.