Weight Spectra of Gabidulin Rank-metric Codes and Betti Numbers

We consider $q$-matroids and their associated classical matroids derived from Gabidulin rank-metric codes. We express the generalized rank weights of a Gabidulin rank-metric code in terms of Betti numbers of the dual classical matroid associated to the $q$-matroid corresponding to the code. In our main result, we show how these Betti numbers and their elongations determine the generalized weight polynomials for $q$-matorids, in particular, for the Gabidulin rank-metric codes. In addition, we demonstrate how the weight distribution and higher weight spectra of such codes can be determined directly from the associated $q$-matroids by using M\"{o}bius functions of its lattice of $q$-flats.


Introduction
Rank-metric codes were first introduced by Delsarte [7] in 1978, and are referred to as Delsarte rank-metric codes.These codes are defined as F q -subspaces of the space of m × n-matrices over F q (the field with q elements, for q a prime power) where the rank distance between two codewords (i.e.matrices) is given by the rank of their difference.These codes are important for their applications in network coding, public-key cryptography, and distributed storage, topics that thus stimulate the interest in studying the intrinsic properties of these codes.In this work we are interested in a particular case of Delsarte rank-metric codes, widely known as Gabidulin rank-metric codes, introduced independently by Gabidulin [8] in 1985 and Roth [28] in 1991.A Gabidulin rank-metric code C of length n and dimension k may be defined as a k-dimensional subspace of the n-dimensional vector space F n q m over F q m .In this case, the rank-analogue of the Hamming metric is defined as follows.Fix a basis B of F q m over F q to interpret a vector v ∈ F n q m as an (m × n)-matrix A v over F q .Now the rank distance between two codewords v and w is defined as d(v, w) := rank(A v − A w ).In this paper we also consider the Gabidulin rank-metric code which is the set C r of all F Q-linear combination of words of C, where Q = Q r for an arbitrary but fixed positive integer r, equipped with the rank metric.This code is referred to as the extension of C to F Q and denoted by C ⊗ FQ F Q (or C, in short) analogous to the case of Hamming metric codes as considered in [15,21].
For a linear block code C over F q and its extension C ⊗ Fq F Q for some Q = q m with any positive integer m, it is shown in [21] that the number A C,j (Q) of codewords of Hamming weight j in the code C ⊗ Fq F Q is a polynomial in Q.Later, in [15], one generalized the weight polynomials to matroids.Following the work on the connection between generalized weights of a Hamming metric code C and Betti numbers of certain associated matroid M as established in [17], an expression for A C,j (Q) or more generally, for the generalized weight polymials P M,j (Q) of a matroid M , is provided in terms of Betti numbers associated to the Stanley-Reisner ring of the matroid M and its elongations.On the other hand, recently a study on determining the singular homology of q-complexes associated to q-matroids has been initiated in [10].This work is towards a topological approach to connect the generalized rank weights of a rank metric code with homological invariants of the associated q-matroid.This led us to study the q-matroids associated to Gabidulin rank metric codes and their lattices of cycles and flats with a view towards a combinatorial approach to express generalized rank weights and related polynomials in terms of homology of the associated q-matroids.
In this paper, we prove rank-analogues of some classical results for Gabidulin rank-metric codes.To each Gabidulin rank-metric code C, we associate q-matroids M C and M * C as introduced in [24]; which can be viewed as q-analogues of matroids derived from generator matrices and parity check matrices, respectively, for block codes with the Hamming metric.To M C we furthermore associate a classical matroid Cl(M C ) (also mentioned in [24]).We study resolutions of the Stanley-Reisner ring of the independence complexes of the dual classical matroid Cl(M C ) * , and the possible elongations of that matroid.We show how the rank-weight distribution of the code C ⊗ FQ F Q can be determined by the N-graded Betti numbers of the Stanley-Reisner ring corresponding to these resolutions.Furthermore, we generalize the results for arbitrary q-matroids by introducing generalized weight polynomials P M,j for a q-matroid M.
Moreover, we show that the following three pieces of information are equivalent: The weight distribution A C,j (Q r ) for all j, r, the higher weight spectra A (i) Q,j of C for all i, j, and all the φ (l) j (certain alternating functions for Cl(M C ) * for all i, l).This result is a perfect analogue of a corresponding result for usual Hamming block codes and its associated matroids, see [19,Cor. 17].In particular we like to emphasize how the higher rank-weight spectra (for subcodes of all dimensions) of C follow from the rank-weight distribution of C.
A key observation that plays an instrumental role throughout this article is the isomorphism between the lattice of q-flats of the q-matroid M C (resp.lattice of q-cycles of M * C ) and the lattice of flats of the matroid Cl(M C ) (resp.lattice of cycles of Cl(M C ) * ).Moreover, it is well known (see for example [29, p.57] and [16, p. 6]) that all the Betti numbers of the Stanley-Reisner rings of Cl(M C ) * and its elongations can be given by concrete Möbius functions of the lattice of flats of Cl(M C ) and its various truncations and sublattices.We use this fact to show that sometimes it is more convenient to work directly with the lattice of q-flats of M C or the opposite lattice, i.e., of q-cycles of M * C .It is important to mention that alternative methods for determining weight distribution and higher weight spectra is given in [6,5] for the more general notion of Delsarte rank-metric codes.Thus we get a variation of ways to retrieve the triple set of information described above for Gabidulin rank-metric codes; one from resolutions of Stanley-Reisner rings, and one from a direct study of lattices in addition to techniques described by the authors in [6,5] using zeta functions.
The paper is organized as follows.In the next section, we collect some preliminaries and recall basic definitions regarding notions like (q-)matroids, (q, m)polymatroids, and Stanley-Reisner rings associated to matroids.In Section 3 we show how the generalized weights of Gabidulin rank-metric codes, more generally for q-matroids, can be expressed by invariants derived from the mentioned Stanley-Reisner rings.We consider the extended codes C ⊗ FQ F Q in Section 4 and give expressions for their rank-weight distributions using the classical matroids associated to the q-matroids corresponding to the codes.Our main results (Theorems 64 and 70 and Corollary 71) determining generalized rank weights and higher weight spectra of C ⊗ FQ F Q, and more generally, the weight polynomials for q-matroids in terms of Betti numbers, are derived in Section 5.In Section 6 we demonstrate our main results with an example and also show how the weight distribution of uniform q-matroids can be determined directly from its lattice of q-flats.We end this article with a retrospective look in Section 7 where we define a new concept called virtual Betti numbers for lattices satisfying the Jordan-Dedekind property.

Preliminaries
Throughout this paper q denotes a power of a prime number and F q the finite field with q elements.We fix a positive integer n, and denote by E the set {1, . . ., n} and by E the n-dimensional vector space F n q over F q .By Σ(E) we denote the set of all subspaces of E. We use [j] to denote the quantity q n−1 + q n−2 + • • • + q n−j for any j = 1, • • • , n.We denote by N 0 the set of all nonnegative integers, and by N the set of all positive integers.
In this section, we recall basic definitions and results concerning matroids, their associated Stanley-Reisner rings, and their q-analogues, i.e., (q, m)-polymatroids and q-matroids.

2.1.
Matroids.There are many cryptomorphic definitions of a matroid [32].Here we record the one in terms of rank function: Definition 1.A matroid is a pair (E, r) where E is a finite set and r : 2 E → N 0 is a function satisfying: The function r is called the rank function of the matroid.The rank of a matroid M = (E, r) is r(E).The nullity function n of the matroid is given by n(X) = |X| − r(X) for X ⊆ E. By (R1), this is an integer-valued non-negative function on 2 E .
Next we recall the notions of flats and cycles of a matroid, which play a central role in this paper.Definition 2. Let M = (E, r) be a matroid.A flat of the matroid is a subset From the definition, it follows easily that E is a flat itself.Also, for X ⊆ E, the smallest flat containing X is the set Y = {x ∈ E, r(X ∪ {x}) = r(X)} and moreover, r(Y ) = r(X).The intersection of two flats is a flat.Definition 3. Let M = (E, r) be a matroid, and n be its nullity function.For 0 i n(E), let N i = {X ⊆ E, n(X) = i} and let N i be the set of minimal elements of N i with respect to inclusion.Then the elements of N i are called cycles of M of nullity i. Cycles of nullity 1 are called circuits.
It is proved in [17,Section 3] that the cycles of a matroid are union of circuits, and of course, by definition, ∅ is a cycle (of nullity 0).Definition 4. Let M = (E, r) be a matroid.The dual matroid of M is the matroid It is well known that there is a one to one correspondence between the flats of a matroid and the cycles of its dual, namely, F is a flat of M if and only if E \ F is a cycle of M * .Definition 5. Let M = (E, r) be a matroid.The l th truncation of M is the matroid M (l) = (E, r (l) ) where r (l) (X) := min{r(M ) − l, r(X)}, for any subset X ⊆ E and 0 ≤ l ≤ r(M ), and the l th elongation of M is the matroid M (l) = (E, r (l) ), where r (l) (X) := min{|X|, r(X) + l} for any subset X ⊆ E and 0 ≤ l ≤ n − r(M ).

Stanley-Reisner resolutions.
Any matroid M = (E, r) gives rise to a simplicial complex ∆ M of independent sets, i.e., the faces of the complex are given by F = {X ⊆ E, r(X) = |X|}.If K is a field, we can associate to the underlying simplicial complex a monomial ideal I M ⊆ S = K[X e , e ∈ E] defined by where X σ = e∈σ X e .We refer to [13] for the study of such ideals.The Stanley-Reisner ring of the matroid is then the quotient S M = S/I M .This ring has minimal N |E| and N graded free resolutions and as described in [17], they are of the form It is known, in particular, that the numbers β i,α (M ) = β i,α are independent of the minimal free resolution, and when the simplicial complex comes from a matroid (as in our case), also independent of the field K.As one sees β i,j (M ) = β i,j = Σ |α|=j β i,α , for all i, j.Such Betti numbers, for matroids being specified later, will be instrumental for our main results.Definition 6.For i, j, l in question, given a matroid M , we let β (l) i,j (M ) be the N-graded graded Betti number of the l th elongation matrix M (l) .
In particular, β i,j (M ).) 2.3.q-Matroids and (q, m)-polymatroids.For X ∈ Σ(E), we denote by X ⊥ the dual of X (with respect to the standard dot product), i.e., X ⊥ = {x ∈ E : x • y = 0 for all y ∈ X}.It is elementary and well-known that The first part of the following key notion is due to [29, Definition 2].
To us the following special case will be the most important one: Definition 8.A q-matroid is a (q, 1)-polymatroid.
The dual of a q-matroid is obtained from the case m = 1.
Definition 10.Let M = (E, ρ) be a q-matroid.Then a subspace F ⊆ E is called a q-flat if ρ(F ⊕ e ) > ρ(F ) for all e ∈ E\F .
Definition 11.Let M = (E, ρ) be a q-matroid, and η be its nullity function, i.e., η(X) = dim Fq X − ρ(X) for all X ∈ Σ(E).For 0 i η(E), a subspace X ⊆ E of nullity i is called a q-cycle of M if X is minimal in N i w.r.t.inclusion, where The q-cycles of nullity 1 are called q-circuits.
Remark 12. (q, m)-flats and (q, m)-cycles can be defined in analogous ways for (q, m)-polymatroids in general, but we will only treat the case m = 1 in what follows.
We then have: Proof.Let X be a q-flat of a q-matroid M of rank r.From the definition of q-cycle, any subspace strictly contained in a q-cycle A have nullity strictly less the nullity of A, which we assume to be a.
Then from the identity, ρ * (X) = dim X + ρ(X ⊥ ) − ρ(E), it is clear that if any space of the form X ⊕ v has rank strictly greater than that of X, the nullity of any subspace B of X ⊥ of codimension 1 should be strictly one less than that of X ⊥ .So if X is a q-flat, then X ⊥ is a q-cycle.Similar logic proves the converse also. Since We now introduce an important definition, essentially taken from [24]: Definition 14.For every q-matroid M = (E, ρ), we associate a pair where P (E) is the set of all 1-dimensional subspaces of E = F n q , in other words, Moreover, for S ⊆ P (E), we set: where S is the (affine) subspace in E = F n q , spanned by the 1-dimensional subspaces of E in S. Proposition 15.For every q-matriod M = (E, ρ), the pair Cl(M) = (P (E), r ρ ) is a matroid.
Proof.Properties (R1) and (R2) follow directly from the properties (P1) and (P2) of Definition 7, respectively.To prove (R3), we take X, Y ⊆ P (E) and verify: Furthermore, we observe: Lemma 16.Let M = (E, ρ) be a q-matroid and Cl(M) = (P (E), r ρ ) be the classical matroid associated to M. Then S ⊆ P (E) is a flat with rank r(S) = r for Cl(M) if and only if it is of the form P (F ) for some q-flat F of M of q-rank ρ(F ) = r.
Proof.If X = P (F ) for some q-flat F , and If X is not of the form P (F ) for F a q-flat, then X = P (G) for G not a q-flat, or X is not of the form P (H) for any G ∈ Σ(E).If X = P (G) for G not a q-flat, then there exists e such that ρ(G ⊕ e ) = ρ(G).Then r(P Let M be a matroid on the ground set E. It is well known that the set of flats of M is a lattice, where the order is the inclusion order.Moreover, it is well known that this lattice has the Jordan-Dedekind property, and therefore has a well-defined rank function.The minimal element of the lattice is the closure of ∅, its maximal element is E, while the meet of two flats is their intersection, and the join is the closure of their union.Definition 20.A geometric lattice is a finite lattice having the Jordan-Dedekind property, and where its rank function, say r, satisfies: • It is atomistic, i.e., every element is a supremum of a set of atoms.
It is well known that the flats of a matroid constitute a geometric lattice, where the rank function of the lattice corresponds to the rank function of the matroid, for each flat.
Lemma 16 has the following immediate, probably well known, consequence: (c) This holds by (a), since the flats of Cl(M) are well known to do so.

Generalized Weights of q-matroids and Betti numbers
In this section, we consider rank-metric codes and their corresponding (q, m)polymatroids and q-matroids.The main result of this section gives a relation between generalized rank weights of Gabidulin rank-metric codes with Betti numbers of certain classical matroids associated to the q-matroids corresponding to the codes.
Let M m×n (F q ), or simply M, denote the space of all m × n matrices with entries in the finite field F q .Note that M is a vector space over F q of dimension mn.

Definition 22.
(a) By a Delsarte rank-metric code, or simply, a Delsarte code, we mean a F q -linear subspace of M. (b) By a Gabidulin rank-metric code, or a vector rank-metric code, we mean a k-dimensional F q m -linear space C in F n q m .A Gabidulin rank-metric code C is also then a K = km-dimensional linear code over F q .This can be viewed as a special case of a Delsarte code in the following way: Fix once and for all an Therefore, any element a ∈ F q m can be uniquely written as Following Shiromoto [29], we associate to a Delsarte code (resp.Gabidulin rankmetric code) C, a family {C(X) : X ∈ Σ(E)} of subcodes of C, and a (q, m)polymatroid (resp.q-matroid) as follows.

Definition 23.
(a) Let C ⊆ M m×n (F q ) be a Delsarte code.Given any X ∈ Σ(E), C(X) is defined to be the subspace of C consisting of all matrices in C with row spaces contained in X.Let ρ 1 C : Σ(E) −→ N 0 be the function defined as Let C be a Gabidulin rank-metric code over F q m /F q .With respect to the fixed F q -basis B of F q m , we consider the respresentation of codewords by matrices.Then for any X ∈ Σ(E), C(X) is defined similar to the case of Delsarte codes.Let ρ C : Σ(E) −→ N 0 be the function defined as Proposition 24.The pair (E, ρ 1 C ) is a (q, m)-polymatroid, and the pair (E, ρ C ) is a q-matroid.
Proof.The first statement is proved in [29], and the second one then follows automatically, since ρ C (X) = m .It is important to note that q-matroids associated to Gabidulin rank metric codes were first defined in [23, Definition 22 and Theorem 24] and the q-matroid in [23] is same as (E, ρ C ) in Proposition 24.
Remark 25.We note that the nullity function (η 1 C ) * of the dual (q, m)-polymatroid of (E, ρ 1 C ) satisfies: for a Delsarte code, and that the nullity function (η C ) * of the dual of the q-matroid (E, ρ C ) then is given by for a Gabidulin rank-metric code.
Definition 26.Let C ⊆ F n q m be a Gabidulin rank-metric code of length n and dimension k over the extension F q m /F q .Let d be the minimum rank distance of C.
Next we recall the very first construction of MRD codes, independently given by Gabidulin [8] and Delsarte [7].
Example 27.Let m, n, k be positive integers such that m ≥ n ≥ k.If we consider a = (a 1 , . . ., a n ) ∈ F n q m such that {a i : i = 1, . . ., n} is a linearly independent set over F q , then F q m -linear code generated by the following matrix G is an MRD code of length n and dimension k.
. (See, for example, [8] and [26, § 2] for the definition and basic facts about MRD codes.)Example 28.Assume for simplicity that m ≥ n.Let C ⊆ M m×n (F q ) be an MRD code of dimension K over F q .Such a C is a Delsarte code such that K = dim Fq C is divisible by m and C(X) = {0} for all subspaces X of E with dim Fq X ≤ n − K m .The latter follows, for instance, from [11,Proposition 6.2].Thus ) is the uniform q-matroid U (k, n) (i.e. the q-matroid with rank function ρ(X) = min{dim(X), k}.Now we recall the definition of generalized rank weights of Gabidulin rank-metric codes in terms of nullity function of the corresponding (dual) q-matroids.The following definition is from [23] where the authors prove its equivalence with the other existing definitions.Remark 30.In this article, we define the rank support using row spaces, irrespective of m ≥ n or m < n.This is following the definition by Shiromoto in [29] (where one uses column spaces, but of the transposes of our matrices) and thereafter, in [9].As proved in [9, Theorem 37], this d r (C) matches with Ravagnani's definition of generalized weights for Delsarte codes in [27] only if m > n.
Then we express the generalized rank weights in terms of the nullity function of dual q-matroid associated to the code : Proposition 31.For a Gabidulin rank-metric code C over F q m /F q , the r-th generalized rank weight is Proof.Following the definitions of C(X) in Definition 23 and d r in Definition 29(b), we have Therefore, the statement follows from Remark 25, since η * C (X) = dim F q m C(X).
Inspired by Remark 25 and Proposition 31 we have: Definition 32.For any q-matroid M = (E, ρ) we set where η * is the nullity function of the dual q-matroid M * .
It is clear from the above description that, for a Gabidulin rank-metric code C (or more generally, for a q-matroid), the r-th generalized weight is equal to the smallest F q -dimension of any q-cycle of nullity r of M C * .As an immediate consequence, we obtain: Lemma 33.Let C be a Gabidulin rank-metric code over F q m /F q of dimension k.Then for any 1 ≤ r ≤ k, d r = n − m r , where m r is the largest dimension over F q of any q-flat of rank k − r for M C .
Proof.This follows from Definition 32 and Lemma 13.
The next result provides a relation between the generalized rank weights of a Gabidulin rank-metric code C and the cycles of the associated dual matroid Cl(M C ) * of the corresponding q-matroid M C .
Corollary 34.Let Cl(M) be the classical matroid associated to a q-matroid M = (E, ρ).
(a) Any cycle X of Cl(M) * is the complement of projective spaces (when interpreting P (E) as projective (n − 1)-space).Its cardinality is for m the dimension of the flat F for for which the X is the complement of Cl(F ).(b) For a Gabidulin rank-metric code C we have that d r is equal to the smallest j such that there exists a cycle of nullity r and cardinality [j] for the matroid (Cl((E, ρ C )) * .
Proof.Part (a): This follows from Lemma 16.Proof of (b) and, using Lemma 16 again: We use this relation and the following result from [17] about classical matroids to express the generalized rank weights in terms of certain Betti numbers.
Theorem 35.[16, Theorem 2] Let M = (E, r) be a matroid on a finite set E and N i (M ) the set of cycles of M of nullity i.Then Theorem 36.For a Gabidulin rank-metric code C we have that: (a) for the N−graded Betti numbers of the Stanley-Reisner ring associated to the independence complex of the classical matroid Cl(M C ) * (b) These N−graded Betti numbers satisfy β r,s = 0, for all s ≤ q n −1 q−1 where s is not of the form [j] for some j.
Proof.From Corollary 34 we have, can write, d r = min{j|σ ∈ N r (Cl(M) * ) and |σ| = q n−1 + . . .+ q n−j }. ( Now Theorem 35 implies that σ is a cycle of Cl(M C ) * of nullity r and of cardinality [j], if and only if the N-graded Betti number β r,[j] of the associated Stanley-Reisner ring is nonzero.Thus (a) follows directly from the expression of d r in equation (3).
To prove (b), first we recall from Corollary 34 that all the cycles of Cl(M C ) * are of cardinality [j] for some j with 1 ≤ j ≤ n.Now from Theorem 35, it is clear that the N−graded Betti numbers β r,s are zero if s is not of the form [j] for some positive j with j ≤ n.

Number of codewords of each rank weight via classical matroids
For this section we introduce some notations and fix some parameters.Let m, n be positive integers and C ⊆ F n q m be a Gabidulin rank-metric code over F q m /F q of dimension k ≤ min{m, n} with a generator matrix G = [(g i,j )] (i.e. a k × n-matrix, with entries in F q m , and whose row space over F q m is C) .Let Q = q m and Q = Q r for some r ∈ N. Let C = C ⊗ FQ F Q r denote the extension of C and thus C can be considered as a Gabidulin rank-metric code over F Q/F q .
Definition 37.For 0 ≤ s ≤ k, let A Q C,s denote the number of words of rank weight In this and the following section we will find expressions for A Q C,s .First we fix bases for the field extensions considered in this section.Let {g 1 , g 2 , • • • , g r } be an arbitrary but fixed basis for F Q over F Q .Therefore combining the fixed F q -basis {b 1 , . . ., b m } of F Q , we then once and for all use {b i g j } 1≤i≤m,1≤j≤r as a basis for F Q over F q .We use the following ordering of the F q -basis of F Q and consider the representation of codewords in C as (mr × n)matrices with entries in F q with respect to the ordered basis B r .
In this section we express A Q C,s in terms of the nullity function of a classical matroid associated to the q-matroid corresponding to the Gabidulin rank-metric code C.
Proof.The second equality is clear as dim FQ F Q = r.
For the first equality, it is enough to show that C(U ) is isomorphic to C(U ) ⊕r as F Q -vector spaces.We observe that C, which is given as a row space over F Q of a matrix with entries in F Q , can be written as a direct sum The way we have chosen our basis B r to express codewords, it is clear that C Remark 39.The above lemma implies that dim F Q C(U ) is independent of the choice of r so that Q = Q r .
Corollary 40.Let C ⊆ F n Q be a Gabidulin rank-metric code and C be the extended code C ⊗ FQ Q where Q = Q r for some r ∈ N. Then the q-matroids (E, ρ C ) corresponding to the codes C are the same for any r ∈ N.
Proof.For any U ⊆ F n q , we have ), which is independent of r by Lemma 38.
Remark 41.Corollary 40 is an obvious consequence if we consider the equivalent definition of rank function of the q-matroid associated to Gabidulin rank metric code as given in [23, Definition 22].Indeed, ρ C (U ) = rank(GY T ) where G is a generator matrix of C and Y T is the transpose of a generator matrix of U .Since all codes C defined as in Definition 37 have a common generator matrix, the q-matroids associated the codes are also same.Now we move onto giving our main result of this section, i.e., an expression for A Q C,s , the number of codewords with rank weight s for s ∈ {1, . . ., n}, using the classical matroids corresponding to the q-matroid (E, ρ C ).
First we define the some notions associated to C.
Definition 42.Let C be a Gabidulin rank-metric code over F Q /F q of length n and Then following Definition 37 and Definition 42, we have Proposition 43.Let C be a Gabidulin rank-metric code over F Q /F q of length n.
Let M C = (F n q , ρ C ) be its corresponding q-matroid and cl(M C ) = (P (F n q ), r) be the associated classical matroid.Then for where n * Cl(MC) denotes the nullity function of the dual matroid Cl(M C ) * .Proof.We set M C .Let U 1 , . . ., U q n −1 q−1 be the codimension 1 subspaces of E = F n q .Therefore, We use s i to denote the 1 dimensional subspace = n * Cl(MC) (P (E)\{s i , s j }).Following the same argument, we can say dim C(∩ a j=1 U ij ) = n * Cl(MC) (P (E)\{s i1 , . . ., s ia }), for any positive integer a. Therefore Remark 44.A Q C,E is of course non-zero only if m ≥ n, since otherwise there cannot be any codeword of rank n in C.
Proposition 43 can be viewed as a variant of [15,Formula (10)], the proof of which was inspired by [24,Section 5.5.].
Using the result and procedure above we find expressions for the For that first we define the following q-matroid.
Definition 45.Let C be a Gabidulin rank-metric code of length n over F Q /F q and let U be a subspace of E = F n q with dim Fq U = s.By considering C(U ) to be a Gabidulin rank-metric code over F Q /F q , its corresponding q-matroid is defined as M C(U) := (U, ρ U ), where U is identified with F s q and for any subspace Lemma 46.For a Gabidulin rank-metric code C over F Q /F q of length n and for any F q -subspace U of F n q , let η * U be the nullity function of the q-matroid M * C(U) .Then η * U = η * C .In other words, the q-cycles of M C * contained in U and the q-cycles of M * C(U) are the same.
Proof.Since V ⊆ U , whatever basis we pick, we obtain and thus the statement of the lemma follows.
Definition 47.For any subspace U ⊂ E = F n q , with a fixed basis and dot product, and any q-matroid M = (E, ρ) with conullity function η * , we let M U = (U, ρ U ) be the q-matroid with ground space U and conullity function η * U , such that η * U (V ) = η * (V ), for all subspaces V ⊂ U .
From Lemma 46 it is then clear that (M C ) U = M C(U) .
Using Proposition 43 we then obtain the following expression for A Q C,U : Proposition 48.Let C be a Gabidulin rank-metric code over F Q /F q of length n.
Let M = M C = (F n q , ρ C ) be its corresponding q-matroid and Cl(M C ) = (P (F n q ), r) be the associated classical matroid.Then for where n * Cl(MU ) is the nullity function of the dual classical matroid Cl(M U ) * .
Proof.Recall that A Q C,U is the number of codewords in C ⊗ FQ Q, whose rank support is exactly U or the number of codewords in C(U ) whose rank support is exactly Thus the result directly follows from Proposition 43.
Remark 49.In stark constrast to the statement in Lemma 46, n * Cl(MU ) (γ) is not in general equal to n * Cl(M) (γ), for γ contained in P (U ).We have n * Cl(M) (γ) = 0 for all γ ∈ P (U ) if U = E (all cycles of Cl(M) * are to big to be contained in such a P (U )).
Nevertheless, as an immediate consequence of Proposition 48, we get: Here the sum is over all U with dim U = s.Since the number of γ and U is finite for a fixed q, we conclude that: , for all r ∈ Z. Proof.The only thing left to prove is the statement about the degrees.All exponents occurring in the expression for A Q C,s are at most the maximum of the numbers n * U,Cl(M) (U ) for all U of dimension s.But these numbers are simply dim C(U ).
Remark 52.Corollary 51 can be easily derived from descriptions by other authors, and then typically from descriptions of Delsarte codes in general, but we have included it here for completeness of our own exposition.See for example [5, Remark 3.5 and Theorem 3.8].

Number of codewords of each rank weight and Betti numbers
We will briefly demonstrate another well known and more direct way to find the A Q C,s , i.e. the number of words of rank weight From the definition, it follows that

Möbius inversion gives:
But following Lemma 38, we have An advantage with this expression, compared with that in Corollary 50, is that the conullity η * C refers to the same q-matroid M C , for all the U appearing in the formula.
Comparing the two expressions of A Q C,s in Corollary 50 and Proposition 53, we have the following result.
Corollary 54.Let M = M C = (E = F n q , ρ) for a Gabidulin rank-metric code C and let Cl(M U ) be the classical matroid corresponding to the q-matroid M U for a subspace U of E. Then as formal polynomials in Z[X] we have: Proof.These are both polynomials, and the difference between them has zeroes for Q r , for infinitely many r.But any non-zero polynomial over any field (in this case Q or R) has only finitely many zeroes.Hence the difference between the two polynomials appearing in the corollary is the zero polynomial.
Definition 55.For a Gabidulin rank-metric code C, we use A C,s (X) to denote the polynomial(s) in Corollary 54.This is called the s-th generalized rank weight polynomial of the code C.
Definition 56.For any q-matroid M, let P M,s (X) denote the polynomial appearing on the left side in Corollary 54.We call the P M,s (X) the s-th generalized rank weight polynomial of a q-matroid M.
From this result we obtain: Corollary 58.For a Gabidulin rank-metric code we have: , and P MC,s the s-th generalized rank weight polynomial of the q-matroid M C .
Proof.From Definition 32, valid for any q-matroid M: d i (M) = min{dim U |η * (U ) = i} for any q-matroid M. Compare with the right side of Corollory 54.
We now have: Proposition 59.For a q-matroid M = (E = F n q , ρ), let N = Cl(M) * .Then we have: Proof.From Definition 47, it follows directly that the two first lattices are identical.The second and third lattices are isomorphic, by Proposition 21(b).Thus it is sufficient to show that the fourth lattice is isomorphic to any of the three lattices above.
Note that, since U is a q-cycle of M * , then R(U ) = P (E) − P (U ⊥ ) is a cycle of Cl(M) * .Furthermore, if V, W are q-cycles contained in the q-cycle U , then V ⊆ W if and only if P (V ) ⊆ P (W ) if and only if R(V ) ⊆ R(W )).Hence the first and fourth lattices are isomorphic and we get the desired result.
By Corollary 61 and Proposition 62 the Möbius functions of all these lattices can be expressed by Betti numbers relating to the single classical matroid N = Cl(M * C ).In particular the isomorphism between the third and fourth lattices above gives that For the rightmost equality we have used that in general β i,σ (M ) = β i,σ (M | σ ) for a matroid M .We then obtain: Proposition 63.Given a q-matroid M. Then for the classical matroid N = Cl(M) * .
Since we know that there are no other cycles of Cl(M) * than those of the form R(U ), we also know that β (l−1) i,X = 0 for all X ⊆ P (E) not of this form.Hence we obtain Theorem 64.Let M be a q-matroid.Then the s-th generalized weight polynomial of M is given by where N = Cl(M) * , the dual classical matroid corresponding to M. Consequently, the number of codewords of rank weight s in C is We recall the definition: d i (M) = min{dim U |η * (U ) = i}), valid for all qmatroids M. From Proposition 62 we also obtain the following generalization of Corollary 54: Corollary 65.For any q-matroid M we have: Proof.We recall the definition: But by Proposition 62 (the isomorphism between the first and the third lattice there), even the third equality below holds: Proposition 68.Let C be a [n, k] q m Gabidulin rank-metric code.Then where [r, s] q m is the number of F q m -linear subspaces of dimension s contained in F r q m .Proof.Here A C,w (q mr ) is the number of codewords of C = C ⊗ F q m F q mr of rank weight w, which we get by substituting T = q mr in the polynomial A C,w (T ).Now we do the counting in another way.Let c be an element of C which corresponds to a (r × n)-matrix A with rows in C. Let D be the subcode of C generated by the rows of A and it has rank weight w and dimension s.On the other hand, for any subcode D 1 ⊆ C of dimension s and rank weight w, we consider A 1 to be a generator matrix of D 1 .Then left multiplication of a r × s matrix of rank s with A 1 gives an element of C r , which has the same rank weight w.The number of r × s matrices in F q m of rank s is equal to [r, s] q m = Π s−1 i=0 (q mr − q mi ).Therefore, the number of codewords of C of rank weight w is equal • Corollary 71 indicates an extended range of applications for the reasoning above, including an extension of Theorem 70.One could imagine q-matroids coming from a wider class of objects than that of Gabidulin rank-metric codes.An example could be any subset C of the space of (m × n)-matrices over F q , such that the subset C(U ) had cardinality q ms = Q s for some s = s(U ) for all F q -subspaces U of F n q .And C could be defined as just C r .The rank function log Q |C| − log Q |C(U ⊥ )| could then be used to give results like Corollary 71 and possibly to Theorem 70 also, for such "almost affine Gabidulin rank-metric codes", as one could call them.To obtain a full extension of Theorem 70 to such codes, one must also then define, and successfully treat, some hierarchy of natural "almost affine Gabidulin subcodes" from which one could define the A (j) s .Generalizations from linear Hamming codes to almost affine codes were treated in [2] and [18].It is not clear to us how interesting it will be to extend the class of linear (usual), rank-metric Gabidulin rank-metric codes to such an analogous, bigger class of codes.
• For classical matroids the φ j play a role as certain coefficients of the twovariable coboundary polynomials, as is shown in [16, Proposition 5].It is conceivable that they may play a similar role for q-matroids.

Two different ways of determining rank-weight spectra
In this section, we demonstrate with concrete examples how to determine (generalized) rank-weight spectra of Gabidulin rank-metric codes.While in the first example we use the expression in Theorem 64 to determine the rank-weight distribution and Proposition 68 to determine the higher weight spectra, in the second example we consider the class of MRD codes and determine the weight spectra directly from the corresponding (uniform) q-matroids.
Example 74.Consider the field extension F 2 4 /F 2 of degree 4, and let a be a root in F 2 4 of the irreducible polynomial X 4 + X + 1 in F 2 [X] so that F 2 4 = F 2 (a).Let C be the rank-metric code of length 4 over the extension F 2 4 of F 2 such that a generator matrix of C is given by Let M C be the q-matroid over F 4 2 corresponding to the rank-metric code C and let N be the classical matroid Cl(M C ) * .We consider the simplicial complex ∆ N associated to the matroid N .
We remark that this is a case, where m = n(= 4), but we are not making any considerations here, about what happens if we look at column spaces instead of row spaces.We just follow the recipe described above and find the weight spectrum of the code, as described, using row spaces as supports.Here we list the (elongated) Betti numbers of the Stanley-Reisner ring associated to the simplicial complex ∆ C .Note that, if M is a q-matroid of rank k, then the cycles of Cl(M) * with nullity i have cardinalities q n−1 + q n−2 + • • • + q k−i for 1 ≤ i ≤ k.Let c i denote a cycle of cardinality q n−1 + q n−2 + • • • + q k−i with nullity i.Note that there are n k−i cycles c i of nullity i in the lattice L * and there are k−j k−i = k−j i−j many cycles c j of nullity j contained in c i . Then Here d = n − k + 1.As we know that β i,σ = 0 if and only if σ ∈ N i (the cycles of nullity i), by Corollary 34, the nonzero N P (E) -graded Betti numbers of Cl(M) * are of the form β i,q n−1 +•••+q k−i for 1 ≤ i ≤ k.Thus using the recursive formula for the Möbius function of L * , we get the expression for the non-zero Betti numbers as follows,  (q 4m − q 3m − q 2m + q m ) = (q 2m − 1)(q 2m − q m )A (2) d+1 n d + 1 (q 2m − 1)(q 2m − q m ) = (q 2m − 1)(q 2m − q m )A

Virtual Betti numbers
The two examples in Section 6 are really different, in the sense that in Example 74 we work with the Stanley-Reisner ring of the classical matroid N = Cl(M) * , find its independence complex, and cycles, and treat it as any classical matroid, regardless of the fact that it "comes from" a q-matroid.In Example 75, however, we do not touch any classical matroid at all, in our concrete computations.The classical matroid basically just serves as a justification there, to work with Möbius functions of the lattice of q-cycles of M * .We only know how to associate Stanley-Reisner rings to the independence complex of classical matroids and their elongations.From those rings we have seen that we can derive the Betti numbers of minimal resolutions as modules over polynomial rings.Moreover, it is clear that, via Corollary 61, we can associate well-defined Möbius-numbers to each such Betti number, where these numbers are defined in terms of the lattice of cycles of the matroid in question.Equivalently, it can be defined in terms of the inverted lattice, in this case the geometric lattice of flats of the dual matroid.We now define: Definition 76.Let L be a lattice with rank function r.For l ∈ {0, 1, • • • , r(L)}, let L (l) be the lattice obtained by replacing all the points of L of rank at most l by a single point, which then becomes the zero of L (l) .Then the rank function of L (l) is given by r (l) (P ) = r(P ) − l for any P ∈ L with r(P ) ≥ l and 0, otherwise.We set V (l) i,P = (−1) r(P )−l µ (l) (0, P ) if r(P ) = l + i, 0 otherwise, and V i,P = V (0) i,P .
Here µ (l) is the Möbius function of the lattice L (l) .
Definition 77.Let L be a lattice with rank function r.Then for a given nonnegative function f : L → N 0 , we set i,P , and , and We call V (l),f i,j the l-th elongated virtual N-graded Betti numbers and V f i the ungraded virtual Betti numbers.
For a Gabidulin rank-metric code C, we have already seen that the lattice of q-cycles of M * C and the lattice of cycles of N * = Cl(M C ) * are isomorphic and if U be a q-cycle with dim U = j, then the cardinality of its corresponding cycle R(U ) of N * is q n−1 + q n−2 + • • • + q n−j .We then associate the functions f 1 and f 2 to these lattices, respectively, where f 1 (U ) = dim U , and f 2 (X) = |X| if X is of the form R(U ) for U a q-cycle of dimension j, and 0 otherwise (or just f 2 = |X| for all X ⊆ P (E)).It is then evident that: , for each q-cycle U , and that:  [j] one can replace these invariants with the virtual Betti numbers, and thus reformulate all these results, only referring directly to the lattice of q-cycles of M * C .In practical situations, one might prefer to use different lattices depending on the tools one has at hand, as explained in Examples 75 and 74.
On behalf of all authors, the corresponding author states that there is no conflict of interest.
and so X is not a flat.Definition 17.Let (E, R) be a poset.The opposite of a poset (E, R) is the poset (E, S) where xSy ⇔ yRx.Definition 18. (i) Let (E, R) be a finite poset.A chain C in E is a totally ordered subset of E (meaning aRb or bRa for a, b in C). (ii) The length of a chain is equal to the cardinality of the chain minus 1.The length of a finite poset is the maximal length of chains in the poset.(iii) If the poset has the Jordan-Dedekind property (meaning: all maximal chains have the same length), then the rank of an element x ∈ E is the length of the poset ([0, x], R).Definition 19.A finite lattice is a finite poset P = (E, R), where there exists a maximal element, denoted by 1, a minimal element, denoted by 0, and for any two elements a, b ∈ E, there exists a least upper bound (or join) a ∨ b and a greatest lower bound (or meet) a ∧ b.An atom is a minimal element of the subset E\{0}.The opposite lattice P * of a lattice P satisfies 0 P * = 1 P , 1 P * = 0 P , a ∨ P * b = a ∧ P b and a ∧ P * b = a ∨ P b.

Proposition 21 .
(a)  As posets ordered by inclusion, the set of flats of Cl(M), and the set of q-flats of M are isomorphic.(b) The posets of cycles of Cl(M) * and q-cycles of M * are isomorphic.(c) The poset of q-flats of M constitute a geometric lattice.Proof.(a)From Lemma 16 there is a bijection between the flats of Cl(M) and the flats of M. Since it is inclusion-preserving, the lattices are isomorphic.(b) This holds since by (a) their opposite lattices are isomorphic.

Definition 29 .
[23, Definition 5]  Let C be a Gabidulin rank-metric code over F q m /F q .(a)The rank support Rsupp(c) of any codeword c ∈ C is the F q -linear row space of M B (c) (the matrix representation of c, as in the text following Definition 22.) For a subcode D of C, its rank support Rsupp(D) is the F q -linear span of the set {Rsupp(d) : d ∈ D}.(b) Let dim F q m C = k.Then for 1 ≤ r ≤ k, the r-th generalized rank weight of C is defined as d r (C) = min{dim Fq Rsupp(D), D is a subcode of C with dim F q m (D) = r}.
X) = i} = min{s| there exist γ, U with dim(U ) = s and γ ⊂ P (U ) and n * Cl(MU ) (γ) = i} = min{s| there exists U with dim(U ) = s and n * Cl(MU ) (P (U )) = i} = min{s| there exists U with dim(U ) = s and η * M (U ) = i} = d i .This proves the corollary.Definition 66.Given a Gabidulin rank-metric code C. Then the i-th generalized rank weight distribution of C is the integer vector whose u-th component, 0 ≤ u ≤ n, is defined by A , where, for any U ⊆ E, A (i) C,U := |{D ⊆ C : dim(D) = i, Rsupp(D) = U }|.The following two results can be viewed as an adaptation to the rank-metric situation of the arguments given in [21, Lemma 5.4, Prop.5.28].Lemma 67.For an element c ∈ C, let M be the corresponding (r × n) matrix, referring to our fixed basis {g 1 , • • • , g r } of F Q r over F Q .Let D be the subspace of C generated by the rows of the matrix M .Then wt(c) = wt(D) := dim Fq Rsupp(D), where wt(c) denotes the rank weight of c. Proof.Let c = (c 1 , . . ., c n ) ∈ C, and c j = r−1 i=0 c i,j g i , so that the ijth entry of A is c i,j .From definitions of rank weight and rank support, it follows that wt(c) = wt(D).

.
So in Example 74, we really did use the "virtual Betti numbers"V (l) i,j = V (l),f1 i,j to determine A C,w (Q) (or A C,w ( Q) if one prefers).Itis clear in that all results in the previous sections, involving the β (l) i,R(U) or the β (l)