1 Introduction and motivation

Rank-metric codes are linear spaces of matrices of given size, with entries in a finite field \(\mathbb {F}_q\). The set of \(n\times m\) matrices over a field is a metric space when endowed with the rank metric: The distance between two matrices is the rank of their difference. Rank-metric codes were introduced by Delsarte in [6]. Gabidulin [9] and Roth [16] later independently rediscovered the family of rank-metric codes, which are linear over the field extension \(\mathbb {F}_{q^m}\). The study of rank-metric codes is motivated by their applications to linear network coding, code-based cryptography, and distributed storage.

The mathematical theory of rank-metric codes includes the study of code invariants and their bounds. Beyond the size of its elements, also called codewords, and its dimension, two basic invariants of a rank-metric code are its minimum distance and maximum rank. The minimum distance of a nonzero rank-metric code is the least rank of a nonzero matrix in the code, while its maximum rank is the maximum rank of an element of the code. The Singleton bound involves the dimension of a rank-metric code and its minimum distance, while the Anticode bound involves the dimension of a code and its maximum rank. Codes which meet the Singleton bound go under the name of Maximum Rank Distance codes (MRD codes) and were first studied by Delsarte in [6]. Codes attaining the Anticode bound were studied by Meshulam in [13], with a different motivation and terminology. Within coding theory, they are known as optimal anticodes. While MRD codes are of direct applied interest, optimal anticodes are mostly of theoretical interest. For example, they can be used to define the generalized weights, a family of code invariants. This was done in [14], where the properties of optimal anticodes are studied.

For a fixed minimum distance d, MRD codes are the rank-metric codes which have minimum distance d and the largest dimension according to the Singleton bound. Conversely, one could fix a dimension k and ask what are the codes of dimension k and largest minimum distance. It turns out that, if k is divisible by the maximum between n and m, these are the MRD codes. Else, they are a different family of codes, called quasi MRD codes. This last family of codes was introduced and studied in [3].

Something similar happens for the Anticode bound: The optimal anticodes are the rank-metric codes of largest dimension, among those with a fixed maximum rank. Similarly to the case of MRD codes, the dimension of optimal anticodes is divisible by the maximum between n and m, say m. Moreover, for a fixed k divisible by m, optimal anticodes are the codes with least maximum rank, among those of dimension k. In this paper, we study the family of rank-metric codes whose dimension is not divisible by m and whose maximum rank is the least possible for codes of that dimension, according to the Anticode bound. As these are not optimal anticodes, we call them quasi optimal anticodes (qOACs).

The paper is organized as follows: In Sect. 3 we define qOACs and dually qOACs. We give a complete structural classification of dually qOACs and a partial one of qOACs. In Sect. 4 we study the generalized weights of dually qOACs and of a family of qOACs. In Sect. 5 we study their the weight distribution, while in Sect. 6 we compute the associated q-polymatroids.

2 Preliminaries

In this section we give an introduction to rank-metric codes and state some results that we will need throughout the paper. Let q a prime power and \(\mathbb {F}_q^{ \, n \times m }\) the linear space of \(n \times m\) matrices with entries in the finite field \(\mathbb {F}_q\). Up to transposition, we may assume without loss of generality that \(n \le m\). Throughout the paper, we denote by \(e_1,\ldots ,e_\ell \) the canonical basis of \(\mathbb {F}_q^\ell \), i.e., \(e_i\) is the vector whose coordinates are all zero, except for a one in position i.

Definition 2.1

The rank distance of \(A, B \in \mathbb {F}_q^{ \, n \times m }\) is given by the function

$$\begin{aligned} d : \mathbb {F}_q^{ \, n \times m }\times \mathbb {F}_q^{ \, n \times m }&\longrightarrow \mathbb {N}\\ (A,B) \qquad&\longmapsto \text{ rank }(A-B). \\ \end{aligned}$$

A rank-metric code \({\mathcal {C}}\) is a \(\mathbb {F}_q\)-linear subspace of \(\mathbb {F}_q^{ \, n \times m }\) equipped with the rank distance. The dimension of \({\mathcal {C}}\) over \(\mathbb {F}_q\) is denoted by \(\dim ({\mathcal {C}})\). Further, we let \(\text{ d }({\mathcal {C}}) = \min \{ \text{ rank }(A): A \in {\mathcal {C}}, A \ne 0 \}\) be the minimum distance of a nonzero rank-metric code \({\mathcal {C}}\). In a similar way, the maximum rank is given by \(\text{ maxrk }({\mathcal {C}}) = \max \{ \text{ rank }(A): A \in {\mathcal {C}}\}. \)

Two rank-metric codes are equivalent if there is a linear rank-preserving homomorphism mapping one code into the other.

Definition 2.2

An \(\mathbb {F}_q\)-linear isometry \(\varphi \) of \(\mathbb {F}_q^{ \, n \times m }\) is an \(\mathbb {F}_q\)-linear rank-preserving homomorphism, i.e. \(\text{ rank }(\varphi (A)) = \text{ rank }(A)\) for all \(A \in \mathbb {F}_q^{ \, n \times m }\). Let \(\text{ Isom}_{\mathbb {F}_q}(\mathbb {F}_q^{ \, n \times m })\) be the collection of \(\mathbb {F}_q\)-linear isometries of \(\mathbb {F}_q^{ \, n \times m }\). Two rank-metric codes \({\mathcal {C}}, \mathcal {D} \subseteq \mathbb {F}_q^{ \, n \times m }\) are equivalent if there is \(\varphi \in \text{ Isom}_{\mathbb {F}_q}(\mathbb {F}_q^{ \, n \times m })\) such that \({\mathcal {C}} = \varphi (\mathcal {D})\). We denote the equivalence by \({\mathcal {C}} \sim \mathcal {D}\).

Linear isometries of \(\mathbb {F}_q^{ \, n \times m }\) are classified in [11] for odd characteristic and in [19] for characteristic equal to 2.

Theorem 2.3

Let \(\varphi \in \text{ Isom}_{\mathbb {F}_q}(\mathbb {F}_q^{ \, n \times m })\). Then

  1. (a)

    if \(n \ne m\), there exist \(N \in \text{ GL}_n(\mathbb {F}_q)\) and \(M \in \text{ GL}_m(\mathbb {F}_q)\) such that \(\varphi (A) = NAM\) for all \(A \in \mathbb {F}_q^{ \, n \times m }\).

  2. (b)

    if \(n = m\), there exist \(N,M \in \text{ GL}_n(\mathbb {F}_q)\) such that \(\varphi (A) = NAM\) for all \(A \in \mathbb {F}_q^{ \, n \times m }\), or \(\varphi (A) = NA^tM\) for all \(A \in \mathbb {F}_q^{ \, n \times m }\).

Further we define the dual of a rank-metric code \({\mathcal {C}}\) using the standard scalar product for matrices.

Definition 2.4

Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code and let \(\text{ Tr }(A)\) denote the trace of a square matrix A. The dual of \({\mathcal {C}}\) is defined as

$$\begin{aligned} \mathcal {C}^\perp = \{M \in \mathbb {F}_q^{ \, n \times m }: \text{ Tr }(MN^t) = 0 \text{ for } \text{ all } N \in {\mathcal {C}} \}. \end{aligned}$$

For a matrix \(M\in \mathbb {F}_q^{ \, n \times m }\) \(\text{ colsp }(M)\subseteq \mathbb {F}_q^n\) denotes the \(\mathbb {F}_q\)-linear space generated by the columns of M and \(\text{ rowsp }(M) \subseteq \mathbb {F}_q^m\) the \(\mathbb {F}_q\)-linear space generated by the rows of M.

Definition 2.5

Let \(V \subseteq \mathbb {F}_q^n\) be a subspace. Then

$$\begin{aligned} \text{ Mat }(V) = \{ M \in \mathbb {F}_q^{ \, n \times m }: \text{ colsp }(M) \subseteq V \} \subseteq \mathbb {F}_q^{ \, n \times m }\end{aligned}$$

denotes the matrix space supported by the vector space V. For \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) a rank-metric code, let

$$\begin{aligned} {\mathcal {C}}(V) = \{ M \in {\mathcal {C}}: \text{ colsp }(M) \subseteq V \} \subseteq {\mathcal {C}} \end{aligned}$$

be the subcode of \({\mathcal {C}}\) supported on V.

Notice that whenever we want to refer to the matrix space supported by a certain row space we will consider the transposed version of the support given in Definition 2.5.

An important role in the motivation of this paper is taken by deriving bounds on rank-metric codes. In the sequel we give two of the most relevant inequalities, one relating the minimum distance and one relating the maximum rank to the dimension of a rank-metric code.

Theorem 2.6

(Singleton bound) Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. Then

$$\begin{aligned} \dim ({\mathcal {C}}) \le m (n - \text{ d }({\mathcal {C}}) + 1). \end{aligned}$$
(1)

The Singleton-like bound for rank-metric codes was presented by Delsarte in [6]. It is the rank-metric version of the well-known Singleton bound in the Hamming metric. Codes meeting bound (1) are known as Maximum Rank Distance Codes (MRD codes) and have been extensively studied.

We shall present now an upper bound on the dimension involving the maximum rank, instead of the minimum distance as seen in (1). A classical theorem by Flanders in [8] states that the dimension of a linear space of matrices whose rank is less than or equal to a given \(r \le n\) is upper bounded by mr. The results in [8] are proved under the assumption that the cardinality of the base field is strictly greater than r and that the characteristic differs from 2. Atkinson and Lloyd in [1] obtained the same result with the assumption only on the field size. The square case with \(r = n-1\) for an arbitrary field size was proved by Dieudonné in [7]. Finally, Meshulam in [13] showed that the assumptions on the rank and on the field size are unnecessary for deriving the bound on the dimension. In fact, the next bound was proved in [13] and goes under the name of Anticode bound.

Theorem 2.7

(Anticode bound) Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. Then

$$\begin{aligned} \dim ({\mathcal {C}}) \le m \, \text{ maxrk }({\mathcal {C}}). \end{aligned}$$
(2)

Definition 2.8

An optimal anticode \(\mathcal {A}\subseteq \mathbb {F}_q^{ \, n \times m }\) is a rank-metric code which satisfies

$$\begin{aligned} \dim (\mathcal {A}) = m \, \text{ maxrk }(\mathcal {A}). \end{aligned}$$

The classification of matrix spaces with least possible maximum rank for a given dimension follows the same history as the derivation of the Anticode Bound and is presented in the next theorem.

Theorem 2.9

Let \(\mathcal {A}\subseteq \mathbb {F}_q^{ \, n \times m }\) be an optimal anticode of dimension mr with \(r = \text{ maxrk }(\mathcal {A})\). Then \(\mathcal {A}=\text{ Mat }(V)\) for some \(V \subseteq \mathbb {F}_q^n\) of dimension r, or \(A=\text{ Mat }(V)^t\) and \(m=n\).

Some fundamental properties of optimal anticodes are stated in [15], for instance that \({\mathcal {C}}\) is an optimal anticode if and only if \(\mathcal {C}^\perp \) is an optimal anticode.

In the end we want to introduce q-polymatroids, which are the q-analogue of polymatroids.

Definition 2.10

([10], Definition 4.1) A q-polymatroid is a pair \(P = (\mathbb {F}_q^n, \rho )\) where \(\rho \) is a function from the set of all subspaces of \(\mathbb {F}_q^n\) to \(\mathbb {R}\), such that

  1. (i)

    \(0 \le \rho (A) \le \dim (A)\),

  2. (ii)

    if \(A \subseteq B\), then \(\rho (A) \le \rho (B)\),

  3. (iii)

    \( \rho (A + B) + \rho (A \cap B) \le \rho (A) + \rho (B)\).

for all \(A, B \subseteq \mathbb {F}_q^n\).

Notation 2.11

Let st be positive integers. Throughout the paper we let \(u \in \mathbb {F}_q^s\) denote a row vector of length s with entries in \(\mathbb {F}_q\). The zero matrix of size \(s \times t\) is denoted by \(0_{s\times t}\) and the matrix with only one nonzero entry equal to one at position (ij) of size \(n \times m\) is given by \(E_{i,j}\). Further, \(f_i \in \mathbb {F}_q^m\) is the row vector with the only non zero entry equal 1 at position i, whereas \(e_i \in \mathbb {F}_q^n\) is the column vector whose only non zero entry is a 1 in position i.

3 Quasi optimal and dually quasi optimal anticodes

Definition 3.1

A quasi optimal anticode (qOAC) is a rank-metric code \({\mathcal {C}}\subseteq \mathbb {F}_q^{ \, n \times m }\) such that \(m\not \mid \dim ({\mathcal {C}})\) and

$$\begin{aligned} \text{ maxrk }({\mathcal {C}})=\bigg \lceil \frac{\dim ({\mathcal {C}})}{m}\bigg \rceil . \end{aligned}$$

If \({\mathcal {C}}\) and \(\mathcal {C}^\perp \) are both qOACs, then \({\mathcal {C}}\) is a dually qOAC.

Notation 3.2

For a qOAC \({\mathcal {C}}\), write

$$\begin{aligned} \dim ({\mathcal {C}}) = \alpha m + \rho ,\ \ 0< \rho< m,\ \ 0\le \alpha <n\le m,\ \ \text{ maxrk }({\mathcal {C}})=\alpha +1. \end{aligned}$$

If in addition \({\mathcal {C}}\) is a dually qOAC, write

$$\begin{aligned} \dim ({\mathcal {C}}^\perp ) = (n - \alpha - 1) m + (m - \rho ),\ \ 0< m -\rho < m,\ \text{ maxrk }({\mathcal {C}}^\perp ) = n - \alpha . \end{aligned}$$

It is well-known that the dual of an optimal anticode is an optimal anticode. However, this is not the case for qOACs. In the next example, we produce dually qOACs, as well as qOACs which are not dually qOACs.

Example 3.3

Let \(m\ge \max \{2,n\}\), let \(0< \alpha <n\le m\), \(0<\rho <m\), \(0\le k\le m-\rho \). Let

with dual code

Notice that \(\dim (C_k)=\alpha m+\rho \) and \({\mathcal {C}}_k \sim {\mathcal {C}}_{m-\rho -k}\) for all k. We have \(\text{ maxrk }({\mathcal {C}}_0) = \alpha + 1\) and \(\text{ maxrk }(\mathcal {C}^\perp _0) = n - \alpha \), hence \({\mathcal {C}}_0\sim {\mathcal {C}}_{m-\rho }\) are dually qOACs. If \(\rho \ge m-2\), then \(\text{ maxrk }({\mathcal {C}}_1) = \alpha + 1\) and \(\text{ maxrk }(\mathcal {C}^\perp _1) = n - \alpha \), hence \({\mathcal {C}}_1\sim {\mathcal {C}}_{m-\rho -1}\) are dually qOACs. If \(\rho \le m-3\), then \(\text{ maxrk }({\mathcal {C}}_1)=\alpha +1\) and \(\text{ maxrk }({\mathcal {C}}_1^\perp )=n-\alpha +1\). Hence \({\mathcal {C}}_1\sim {\mathcal {C}}_{m-\rho -1}\) are qOACs, but not dually qOACs. For \(k\ne 0,1,m-\rho -1,m-\rho \), one has \(\text{ maxrk }({\mathcal {C}}_k) = \alpha + 1\) and \(\text{ maxrk }(\mathcal {C}^\perp _k) = n - \alpha + 1\). Therefore \({\mathcal {C}}_k\sim {\mathcal {C}}_{m-\rho -k}\) are qOACs, but not dually qOACs.

The next proposition relates the maximum rank of a code with that of its dual. It also provides us with a simple characterization of dually qOACs.

Proposition 3.4

Let \({\mathcal {C}}\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. Then

$$\begin{aligned} \text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )\ge n. \end{aligned}$$

In addition:

  1. (a)

    \({\mathcal {C}}\) is an optimal anticode if and only if \(\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )=n\).

  2. (b)

    \({\mathcal {C}}\) is a dually qOAC if and only if \(\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )= n + 1\).

Proof

The Anticode Bound on \({\mathcal {C}}\) and \({\mathcal {C}}^\perp \) yields

$$\begin{aligned} mn=\dim ({\mathcal {C}})+\dim ({\mathcal {C}}^\perp )\le m(\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )). \end{aligned}$$
(3)

(a) \({\mathcal {C}}\) is an optimal anticode if and only if \({\mathcal {C}}^\perp \) is an optimal anticode. Hence, if \({\mathcal {C}}\) is an optimal anticode, then equality holds in (3). Conversely, if equality holds in (3), then \({\mathcal {C}}\) and \({\mathcal {C}}^\perp \) meet the Anticode Bound, hence they are optimal anticodes.

(b) If \({\mathcal {C}}\) is a dually qOAC, then \(\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )=n+1\) by direct computation. To prove the converse, first observe that, if \(\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )=n+1\), then \(\mathcal {C}\) and \(\mathcal {C}^\perp \) are not optimal anticodes by part (a). If \(m\mid \dim ({\mathcal {C}})\), then

$$\begin{aligned} \text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )\ge \frac{\dim ({\mathcal {C}})}{m}+1+\frac{\dim ({\mathcal {C}}^\perp )}{m} +1=n+2, \end{aligned}$$

since \(\mathcal {C}\) and \(\mathcal {C}^\perp \) are not optimal anticodes. If instead \(m\not \mid \dim (\mathcal {C})\), then

$$\begin{aligned} n+1=\text{ maxrk }({\mathcal {C}})+\text{ maxrk }({\mathcal {C}}^\perp )\ge \left\lceil \frac{\dim ({\mathcal {C}})}{m}\right\rceil +\left\lceil \frac{\dim ({\mathcal {C}}^\perp )}{m}\right\rceil \ge \alpha +1+n-\alpha , \end{aligned}$$
(4)

where \(\dim (\mathcal {C})=\alpha m+\rho \), \(\dim (\mathcal {C}^\perp )=(n-\alpha -1)m+(m-\rho )\), and \(\rho >0\). Therefore the inequalities in (4) are equalities, which completes the proof. \(\square \)

A first classification of large matrix spaces of bounded rank appears in [1], where Atkinson and Lloyd study linear spaces of dimension close to mr over fields of large cardinality. Their classification was extended to all fields and matrices of arbitrary size by de Seguins Pazzis in [4]. As a direct consequence of the results by de Seguins Pazzis, we can characterize the qOACs whose dimension is at least \(\alpha (m-1)+n\).

Theorem 3.5

([4], Theorems 4, 5, and 6) Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a qOAC of \(\dim ({\mathcal {C}}) = \alpha m + \rho \), \(0<\rho <m\).

  1. (a)

    If \(\rho >n-\alpha \), then \({\mathcal {C}}\) is equivalent to a linear subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1}\rangle )\).

  2. (b)

    If \(\rho = n - \alpha \), then one of the following holds:

    1. (i)

      \({\mathcal {C}}\) is equivalent to a linear subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1}\rangle )\),

    2. (ii)

      \({\mathcal {C}} \sim \text{ Mat }(\langle e_1,\ldots ,e_{\alpha }\rangle )+\text{ Mat }(\langle e_1\rangle )^t\),

    3. (iii)

      \(m = n+1\) and \({\mathcal {C}} \sim \text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1}\rangle )^t\),

    4. (iv)

      \(m=n=3\), \(q=2\), and \({\mathcal {C}}\sim \left\{ \begin{pmatrix} a &{} 0 &{} 0 \\ c &{} b &{} 0 \\ d &{} e &{} a+b \end{pmatrix}: (a,b,c,d,e)\in \mathbb {F}_2^5 \right\} \).

Using Theorem 3.5, we can classify dually qOAs.

Theorem 3.6

Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a dually qOAC with \(\dim ({\mathcal {C}}) = \alpha m + \rho \), \(0<\rho <m\). One of the following holds:

  1. (a)
    $$\begin{aligned} {\mathcal {C}} \sim \left\{ \begin{pmatrix} A &{} B\\ u &{} 0_{1 \times (m-\rho )} \\ 0_{(n-\alpha -1) \times \rho } &{} 0_{(n-\alpha -1) \times (m-\rho )} \\ \end{pmatrix}: A\in \mathbb {F}_q^{\alpha \times \rho }, B\in \mathbb {F}_q^{\alpha \times (m-\rho )}, u\in \mathbb {F}_q^{1\times \rho }\right\} , \end{aligned}$$
  2. (b)

    \(\rho \le n-\alpha \) and

  3. (c)

    \(\rho \ge m-\alpha -1\) and

  4. (d)

    \(m=n+1\), \(\rho =n-\alpha \), and

    $$\begin{aligned} {\mathcal {C}} \sim \left\{ \begin{pmatrix} A &{} 0_{n \times (n-\alpha )} \\ \end{pmatrix}: A \in \mathbb {F}_q^{n \times (\alpha +1)} \right\} . \end{aligned}$$

Proof

It is easy to check that the codes in the statement of the theorem are dually qOACs. We now prove that, up to equivalence, they are the only ones. We start by analyzing the case when \({\mathcal {C}}\supseteq \text{ Mat }(U)\), for some \(U\subseteq \mathbb {F}_q^n\) of \(\dim (U)=\alpha \). Up to equivalence, we may assume that \(U=\langle e_1,\ldots ,e_\alpha \rangle \). Write \({\mathcal {C}}=\text{ Mat }(\langle e_1,\ldots ,e_\alpha \rangle )+\langle M_1,\ldots ,M_\rho \rangle \), where \(M_1,\ldots ,M_\rho \in \text{ Mat }(\langle e_1,\ldots ,e_\alpha \rangle )^\perp =\text{ Mat }(\langle e_{\alpha +1},\ldots ,e_n\rangle )\) are linearly independent. Since \({\mathcal {C}}\) is a qOAC, then \(\text{ maxrk }({\mathcal {C}})=\alpha +1\). We claim that \(\text{ maxrk }(\langle M_1,\ldots ,M_\rho \rangle )=1\). In fact, any \(M\in \langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(\langle e_{\alpha +1},\ldots ,e_n\rangle )\) has

$$\begin{aligned} \dim (\text{ rowsp }(M))=\text{ rank }(M)\le \text{ maxrk }(\text{ Mat }(\langle e_{\alpha +1},\ldots ,e_n\rangle ))=n-\alpha . \end{aligned}$$

Let \(L\in \text{ Mat }(\langle e_1,\ldots ,e_\alpha \rangle )\) be a matrix whose first \(\alpha \) rows are linearly independent vectors in a vector space V such that \(V\oplus \text{ rowsp }(M)=\mathbb {F}_q^m\). Notice that one can always find such an L, since \(\dim (V)=m-\dim (\text{ rowsp }(M))\ge m-(n-\alpha )\ge \alpha \). Then \(\text{ rowsp }(L)\cap \text{ rowsp }(M)=0\), so \(L+M\in {\mathcal {C}}\) has

$$\begin{aligned} \text{ rank }(L + M)=\text{ rank }(M)+\text{ rank }(L)\le \text{ maxrk }({\mathcal {C}})=\alpha + 1, \end{aligned}$$

which proves that \(\text{ rank }(M)\le 1\), since \(\text{ rank }(L)=\alpha \). Since \(\text{ maxrk }(\langle M_1,\ldots ,M_\rho \rangle )=1\), then either \(\langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(w)\) for some \(w\in \langle e_{\alpha +1},\ldots ,e_{n}\rangle \subseteq \mathbb {F}_q^n\), or \(\langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(w)^t\) for some \(w\in \mathbb {F}_q^m\). Since \(\langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(\langle e_{\alpha +1},\ldots ,e_n\rangle )\), the latter is only possible if

$$\begin{aligned} \rho =\dim (\langle M_1,\ldots ,M_\rho \rangle )\le \dim (\text{ Mat }(\langle e_{\alpha +1},\ldots ,e_n\rangle )\cap \text{ Mat }(w)^t)=n-\alpha . \end{aligned}$$

If \(\langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(w)\), then, after suitable invertible operations involving the last \(n-\alpha \) rows, we may suppose that \(w=e_{\alpha +1}\). Moreover, after suitable invertible column operations

$$\begin{aligned} M_i = \begin{pmatrix} 0_{n\times (i-1)} &{} e_{\alpha +1} &{} 0_{n\times (m-i)} \\ \end{pmatrix} \quad \text{ for } 1\le i \le \rho . \end{aligned}$$

Since both types of operations fix \(\text{ Mat }(\langle e_1,\ldots ,e_\alpha \rangle )\), we have shown that

(5)

This yields the codes in part (a) of the statement.

If \(\rho \le n-\alpha \) and \(\langle M_1,\ldots ,M_\rho \rangle \subseteq \text{ Mat }(w)^t\), then, after suitable invertible operations involving the last \(n-\alpha \) rows, we may suppose that \(M_i\) is the matrix whose rows are all zero, except for row \(\alpha +i\), which is equal to w. Up to invertible column operations, we may further suppose that \(w=e_1\in \mathbb {F}_q^m\). Since both types of operations fix \(\text{ Mat }(\langle e_1,\ldots ,e_\alpha \rangle )\), we have that

This yields the codes in part (b) of the statement.

Suppose now that \(\mathcal {C}\subseteq \text{ Mat }(U)\) for some \(U\subseteq \mathbb {F}_q^n\) of \(\dim (U)=\alpha +1\). Up to equivalence, we may assume that \(U=\text{ Mat }(\langle e_{n-\alpha },\ldots ,e_n\rangle )\), that is, \({\mathcal {C}}^\perp \supseteq \text{ Mat }(\langle e_1,\ldots ,e_{n-\alpha -1}\rangle )\). Then the above argument shows that either

$$\begin{aligned} {\mathcal {C}}^\perp \sim \left\{ \begin{pmatrix} A &{} B\\ u &{} 0_{1\times \rho } \\ 0_{\alpha \times (m-\rho )} &{} 0_{\alpha \times \rho }\\ \end{pmatrix}: A \in \mathbb {F}_q^{(n-\alpha -1)\times (m-\rho )}, B \in \mathbb {F}_q^{(n-\alpha -1) \times \rho }, u \in \mathbb {F}_q^{1\times (m-\rho )}\right\} \end{aligned}$$

or

Moreover, the latter is only possible when \(\rho \ge m-\alpha -1\). Taking duals, we obtain that either \({\mathcal {C}}\) has the form (5), or

This yields the codes in part (c) of the statement.

Finally, suppose that \({\mathcal {C}}\not \supseteq \text{ Mat }(U)\) for any \(U\subseteq \mathbb {F}_q^n\) of \(\dim (U)=\alpha \) and \({\mathcal {C}}\not \subseteq \text{ Mat }(U)\) for any \(U\subseteq \mathbb {F}_q^n\) of \(\dim (U)=\alpha +1\). This implies also that \({\mathcal {C}}^\perp \not \subseteq \text{ Mat }(U)\) for any \(U\subseteq \mathbb {F}_q^n\) of \(\dim (U)=n-\alpha \). Since \(n\le m\), then either \(\rho \le m-\alpha -1\) or \(\rho \ge n-\alpha \). This implies that, for any \(0<\rho <m\), Theorem 3.5 applies to either \({\mathcal {C}}\) or \({\mathcal {C}}^\perp \). Because of our assumptions, and since the code of Theorem 3.5 (b) (iv) is not a dually qOAC, \(\mathcal {C}\) or \(\mathcal {C}^\perp \) is a code as in Theorem 3.5 (b) (iii). Therefore \(m=n+1\) and \(\rho =m-\alpha -1=n-\alpha \) and we obtain the codes in part (d) of the statement. \(\square \)

Theorems 3.5 and 3.6 provide us with many examples of codes which are qOACs but not dually qOACs. In fact, any code as in Theorem 3.5 which is not one of the codes in Theorem 3.6 is of this kind. We now give some concrete examples of qOACs which are not dually qOACs. These examples are covered by Theorem 2.5, unless \(m=n\) and \(\rho =n-\alpha -1\).

Example 3.7

Let \(1\le \alpha \le n-1\) and \(m-\alpha -1\le \rho \le m-2\). Let

$$\begin{aligned} \begin{array}{ccl} \mathcal {C}&{}=&{} \Bigg \{ \begin{pmatrix} \mathcal {V} &{} B \\ A &{} C \\ 0_{(n-\alpha -1) \times (m-\rho )} &{} 0_{(n-\alpha -1) \times \rho } \\ \end{pmatrix}: \mathcal {V} \subseteq \mathbb {F}_q^{(m-\rho ) \times (m-\rho )} \text{ the } \text{ set } \text{ of } \text{ matrices } \\ &{} &{} \\ &{} &{} \text{ with } \text{0 } \text{ on } \text{ the } \text{ diagonal }, A \in \mathbb {F}_q^{(\alpha +1-m+\rho ) \times (m-\rho )}, B \in \mathbb {F}_q^{(m-\rho ) \times \rho }, C \in \mathbb {F}_q^{(\alpha + 1 - m +\rho ) \times \rho }\Bigg \}. \end{array} \end{aligned}$$

Then \(\mathcal {C}\subseteq \mathbb {F}_q^{ \, n \times m }\) has dimension \(\alpha m + \rho \) and maximum rank \(\alpha + 1\), hence it is a qOAC. Its dual is given by

$$\begin{aligned} \begin{array}{ccc} \mathcal {C}^\perp &{}=&{} \Bigg \{ \begin{pmatrix} \mathcal {D} &{} 0_{(m-\rho )\times \rho } \\ 0_{(\alpha +1-m+\rho )\times (m-\rho )} &{} 0_{(\alpha +1-m+\rho )\times \rho } \\ A &{} B\\ \end{pmatrix}: A \in \mathbb {F}_q^{(n-\alpha -1) \times (m-\rho )}, B \in \mathbb {F}_q^{(n-\alpha -1) \times \rho }, \\ &{} &{} \\ &{} &{} \mathcal {D} \subseteq \mathbb {F}_q^{(m-\rho ) \times (m-\rho )} \text{ the } \text{ set } \text{ of } \text{ diagonal } \text{ matrices } \Bigg \}.\end{array} \end{aligned}$$

\(\mathcal {C}^\perp \) has dimension \((n-\alpha )m - \rho \) and maximum rank \(m+n-\rho -\alpha -1\ge n-\alpha +1\). Hence \(\mathcal {C}^\perp \) is not a qOAC, that is, \(\mathcal {C}\) is not a dually qOAC.

Another result from [5] provides us with information on qOACs beyond those treated in Theorem 3.5. Below we state the result in our language.

Theorem 3.8

([5], Theorem 1.7) Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a qOAC with \(\dim ({\mathcal {C}}) = \alpha m + \rho \), \(0<\rho <m\). If \(q = 2\) suppose that \(\rho \ge 2(n-\alpha +1) - m\), else suppose that \(\rho \ge 2(n - \alpha ) - m\). Then \({\mathcal {C}}\) is equivalent to a linear subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1-s}\rangle )^t\), for some \(s\in \{0,\ldots ,\alpha +1\}\).

If \(\mathcal {C}\) is a qOAC of dimension \(\dim ({\mathcal {C}}) = \alpha m + \rho \) and \(\text{ maxrk }(\mathcal {C})=\alpha +1\), then \(\mathcal {C}\) cannot be equivalent to a subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\) for any \(s,k\ge 0\) with \(s+k\le \alpha \). Lemma 1 in [8] shows that, up to equivalence, \(\mathcal {C}\) is contained in \(\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1}\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1}\rangle )^t\). Theorems 3.5 and 3.8 prove that, under some assumptions on \(\rho \), \(\mathcal {C}\) is equivalent to a subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1-s}\rangle )^t\). In the next example, we exhibit a code which does not satisfy the assumptions of Theorems 3.5 or 3.8 and which is not equivalent to a subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_{\alpha +1-s}\rangle )^t\) for any \(0\le s\le \alpha +1\). The example is based on [13, Remark on pg. 228].

Example 3.9

Let \(\mathcal {C}\subseteq \mathbb {F}_2^{4 \times 4}\) be a linear code given by

$$\begin{aligned} \mathcal {C}= \left\{ \begin{pmatrix} a_1 &{} a_4 &{} a_5 &{} a_6\\ 0 &{} a_2 &{} a_7 &{} a_8 \\ 0 &{} 0 &{} a_2 + a_3 &{} a_9\\ 0 &{} 0 &{} 0 &{} a_3\\ \end{pmatrix}: a_i \in \mathbb {F}_2 \text{ for } 1 \le i \le 9 \right\} . \end{aligned}$$

Then \(\text{ maxrk }(\mathcal {C}) = 3\) and \(\dim (\mathcal {C}) = 9\), hence \(\mathcal {C}\) is a qOAC. We claim that \(\mathcal {C}\) is not equivalent to a subspace of \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_{3-s}\rangle )^t\) for any \(0\le s\le 3\). To see this, consider the following two elements of \(\mathcal {C}\):

$$\begin{aligned} M_1 = \begin{pmatrix} 1 &{} 0 &{} 0 &{} 0\\ 0 &{} 1 &{} 0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0 \\ 0 &{} 0 &{} 0 &{} 0 \\ \end{pmatrix} \text{ and } M_2 = \begin{pmatrix} 0 &{} 0 &{} 0 &{} 0\\ 0 &{} 0 &{} 0 &{} 0\\ 0 &{} 0 &{} 1 &{} 0\\ 0 &{} 0 &{} 0 &{} 1\\ \end{pmatrix}. \end{aligned}$$

We prove that if \(M_1\) is contained in \(\text{ Mat }(U) + \text{ Mat }(V)^t\) for some \(U,V \subseteq \mathbb {F}_2^4 \) of \(\dim (V) + \dim (U) = 3\), then \(U,V\subseteq \langle e_1, e_2, e_3\rangle \). Notice that this establishes the claim, since \(M_2\) is not contained in such a space.

The only non trivial case, up to transposition, is \(\dim (U) = 2\) and \(\dim (V) = 1\). Let \(U = \langle (x_1, y_1, z_1, 0), (x_2, y_2, z_2, w) \rangle \subseteq \mathbb {F}_2^4 \) and \(V = \langle (a,b,c,d)\rangle \subseteq \mathbb {F}_2^4\). By assumption there are \(A \in \text{ Mat }(\langle (x_1, y_1, z_1, 0), (x_2, y_2, z_2, w) \rangle )\) and \(B \in \text{ Mat }(\langle (a,b,c,d)\rangle )^t\), such that \(M_1 = A + B\). Equating the last column of \(A+B\) to that of \(M_1\) yields the following homogeneous linear system:

$$\begin{aligned} \begin{array}{ccccccc} 0 &{} = &{} \alpha d &{}+&{} t_1 x_1 &{}+&{} t_2 x_2 \\ 0 &{} = &{} \beta d &{}+&{} t_1 y_1 &{}+&{} t_2 y_2 \\ 0 &{} = &{} \gamma d &{}+&{} t_1 z_1 &{}+&{} t_2 z_2 \\ 0 &{} = &{} \delta d &{}+&{} 0 &{}+&{} t_2 w. \\ \end{array} \end{aligned}$$
(6)

Notice that \((\alpha , \beta , \gamma , \delta ) \notin U\), otherwise \(M_1\) would be contained in \(\text{ Mat }(U)\), but this is not possible since \(\text{ maxrk }(\text{ Mat }(U))=2\). Therefore, the only solution of (6) regarded as a system in the variables \(d,t_1,t_2\) is \(d=t_1=t_2=0\).

Applying the same argument to the last row of \(M_1\) yields another homogeneous linear system, which, regarded as system in the variables \(\delta ,w\) only has the trivial solution \(\delta =w=0\). In particular, we have proved that \(d=w=0\), i.e., \(U,V\subseteq \langle e_1, e_2, e_3 \rangle .\)

In the sequel, we concentrate on linear spaces of the form \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\), as well as some of their linear subspaces.

Definition 3.10

Let \(s,h,k\ge 0\) be integers such that \(k\le m\) and \(0<s+h\le n\). Define

$$\begin{aligned} {\mathcal {C}}_{s,h,k}=\left\{ \begin{pmatrix} A &{} B \\ C &{} 0_{h \times (m-k)} \\ 0_{(n-s-h) \times k} &{} 0_{(n-s-h) \times (m-k)} \\ \end{pmatrix}: A \in \mathbb {F}_q^{s \times k}, B \in \mathbb {F}_q^{s \times (m-k)}, C \in \mathbb {F}_q^{h \times k}, \right\} \subseteq \mathbb {F}_q^{ \, n \times m }. \end{aligned}$$

Remark 3.11

Up to equivalence, all the dually qOAC are of the form \({\mathcal {C}}_{s,h,k}\) for some shk by Theorem 3.6. Moreover, one can check that \(C_{s,h,k}\) is a dually qOAC if and only if there are parameters \(0\le \alpha <n\) and \(0<\rho <m\) such that (shk) is among \((\alpha ,\rho ,1), (\alpha ,1,\rho ), (0,n,\alpha +1)\) if \(m=n+1\), or \((\alpha +\rho +1-m,m- \rho ,m-1)\) if \(\rho \ge m-\alpha -1\).

In the rest of the paper, we compute the invariants of the codes from Definition 3.10. In the next proposition, we characterize which codes of the form \({\mathcal {C}}_{s,h,k}\) are qOACs. Together with Theorem 3.6, Proposition 3.12 yields examples of qOACs which are not dually qOACs, beyond those of Example 3.7. Some examples of this kind are given in Example 3.13.

Proposition 3.12

Let shk be non-negative integers such that \(0<s+h \le n\) and \(k<m\). Then \({\mathcal {C}}_{s,h,k}\) is a qOAC if and only if

$$\begin{aligned} 0<\min \{h,k\}\le \left\lfloor \frac{m-1}{m-\max \{h,k\}}\right\rfloor . \end{aligned}$$

Proof

The code \({\mathcal {C}}\) has dimension \(\dim ({\mathcal {C}})=sm+hk\) and maximum rank \(s+\min \{ h,k\}\). Then \({\mathcal {C}}\) is a qOAC iff \(m\not \mid hk\) and

$$\begin{aligned} \left\lceil \frac{sm + hk}{ m}\right\rceil = s+\min \{h,k\} \quad \Longleftrightarrow \quad \left\lceil \frac{hk}{ m} \right\rceil = \min \{h,k\}. \end{aligned}$$

Therefore, \({\mathcal {C}}\) is a qOAC iff \(\min \{h,k\} >0\) and \((\min \{h,k\}-1)m+1 \le hk \le \min \{h,k\}m-1\). A computation shows that \({\mathcal {C}}\) is a qOAC iff

$$\begin{aligned} 0<\min \{h,k\} \le \left\lfloor \frac{m-1}{m-\max \{h,k\}} \right\rfloor . \end{aligned}$$

Notice that \(\max \{h,k\}<m\), since \(m\not \mid hk\). \(\square \)

Example 3.13

Let \(0<k<m\) and let

$$\begin{aligned} {\mathcal {C}}=\left\{ \begin{pmatrix} A &{} 0_{n \times (m-k)} \\ \end{pmatrix}: A\in \mathbb {F}_q^{n\times k}, \right\} \subseteq \mathbb {F}_q^{ \, n \times m }. \end{aligned}$$

By Theorem 3.6, \({\mathcal {C}}\) is a dually qOAC if and only if \(m=n+1\). By Proposition 3.12, \({\mathcal {C}}\) is a qOAC if and only if

$$\begin{aligned} k\le \min \left\{ \left\lfloor \frac{m-1}{m-n}\right\rfloor , n\right\} \ \text{ or } \ n\le \min \left\{ \left\lfloor \frac{m-1}{m-k}\right\rfloor , k\right\} . \end{aligned}$$

In the following sections, we compute the invariants of the codes from Definition 3.10. We always assume that \(n=s+h\), since this does not affect the computation of the invariants. This amounts to considering the codes \(C_{s,k,n-s}=\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\).

4 Generalized weights

In this section we compute the generalized weights of codes of the form \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\). All dually qOACs and almost all qOACs are of this form by Theorems 3.5 and  3.6. We start by recalling the definition of generalized weights.

Definition 4.1

([14], Definition 23) Let \({\mathcal {C}} \subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. For \(1\le i\le \dim (\mathcal {C})\), the ith generalized weight of \({\mathcal {C}}\) is

$$\begin{aligned} a_i({\mathcal {C}}) = \displaystyle \frac{1}{m} \min \{ \dim (\mathcal {A}) : \, \mathcal {A} \subseteq \mathbb {F}_q^{ \, n \times m } \text{ is } \text{ an } \text{ optimal } \text{ anticode } \text{ with } \dim (\mathcal {A} \cap {\mathcal {C}}) \ge i \}. \end{aligned}$$

Generalized weights were defined in [14], where some of their basic properties were also established. A different, but related, definition of generalized weights was given in [12].

We start with a simple result, which will be used in the proof of Theorem 4.3.

Proposition 4.2

Let \({\mathcal {C}}\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code which contains an optimal anticode of dimension sm for some \(1 \le s \le n\). Then

$$\begin{aligned} a_{(i-1)m + 1}({\mathcal {C}})=\cdots =a_{i m}({\mathcal {C}})=i \text{ for } 1 \le i \le s. \end{aligned}$$

Proof

Fix \(0\le i\le s\) and let \(\mathcal {A}\) be an optimal anticode of dimension \(\dim (\mathcal {A})=im\) such that \(\mathcal {A}\subseteq {\mathcal {C}}\). Then \(a_{im}({\mathcal {C}}) = i\), since \(a_{im}({\mathcal {C}}) \ge i\) by [14, Theorem 30] and \(a_{im}(\mathcal {C}) \le i\) since \(\mathcal {C}\supseteq \mathcal {A}\). Using the properties of generalized weights from [14, Theorem 30], one easily obtains that

$$\begin{aligned} a_{(i-1)m + 1}({\mathcal {C}}) = \cdots = a_{im}({\mathcal {C}}) = i. \end{aligned}$$

\(\square \)

We are now ready to state the main theorem of this section. This theorem computes the generalized weights of all dually qOACs and of almost all qOACs.

Theorem 4.3

Let \({\mathcal {C}}=\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\subseteq \mathbb {F}_q^{ \, n \times m }\). Then

$$\begin{aligned} \begin{array}{clcll} a_{(i-1)m + 1}({\mathcal {C}})&{} =\cdots =&{} a_{i m}({\mathcal {C}})&{} =i &{} \text{ for } 1 \le i \le s, \\ a_{sm + (i-1)k+1}({\mathcal {C}})&{} =\cdots =&{} a_{sm + ik}({\mathcal {C}}) &{} =s+i &{} \text{ for } 1 \le i \le n-s. \end{array} \end{aligned}$$

Proof

Since \({\mathcal {C}}\supseteq \text{ Mat }(\langle e_1,\ldots ,e_s\rangle )\), then by Proposition 4.2

$$\begin{aligned} a_{(i-1)m + 1}({\mathcal {C}}) = \cdots = a_{i m }({\mathcal {C}}) = i \quad \text{ for } 1 \le i \le s. \end{aligned}$$

Fix \(1 \le i \le n-s\) and let \(\mathcal {A}=\text{ Mat }(V)\subseteq \mathbb {F}_q^{ \, n \times m }\) be an optimal anticode with \(V\subseteq \mathbb {F}_q^n\) of \(\dim (V)=s+i\). We claim that \(\dim (\mathcal {C}\cap \mathcal {A})\le sm+ik\). Since \(\dim (V)=s+i\), then there exist i linearly independent vectors \(v_1,\ldots ,v_i\in V{\setminus }\langle e_1,\ldots ,e_s\rangle \). Consider the matrices

$$\begin{aligned} M_j^1 = \begin{pmatrix} 0_{n \times k} &{} v_j &{} 0_{n \times m -k-1} \\ \end{pmatrix}, \ M_j^2 = \begin{pmatrix} 0_{n \times k + 1} &{} v_j &{} 0_{n \times m -k-2} \\ \end{pmatrix}, \ \ldots \, M_j^{m-k} = \begin{pmatrix} 0_{n \times m-1} &{} v_j \\ \end{pmatrix} \end{aligned}$$

for \( 1 \le j \le i\). Clearly \(\langle M_1^1,\ldots ,M_i^{1},\cdots ,M_1^{m-k},\ldots ,M_i^{m-k}\rangle \subseteq \mathcal {A}\). Moreover

$$\begin{aligned} {\mathcal {C}} \ \cap \ \langle M_1^1 , \ldots , M_i^{1}, \cdots , M_1^{m-k}, \ldots , M_i^{m-k} \rangle =0. \end{aligned}$$
(7)

Hence

$$\begin{aligned} \begin{array}{ccl} \dim ({\mathcal {C}}) + \dim (\mathcal {A}) - \dim ({\mathcal {C}} \cap \mathcal {A})&{} = &{} \dim ({\mathcal {C}} + \mathcal {A}) \\ &{}\ge &{} \dim ({\mathcal {C}}) + \dim (\langle M_1^1, \ldots , M_i^{1}, \cdots , M_1^{m-k}, \ldots , M_i^{m-k}\rangle ),\\ \end{array} \end{aligned}$$

which proves our claim that

$$\begin{aligned} \dim ({\mathcal {C}} \cap \mathcal {A}) \le sm + ik. \end{aligned}$$

It follows directly that

$$\begin{aligned} a_{sm+ik+1}({\mathcal {C}})\ge s+i+1 \text{ for } 1\le i\le n-s-1. \end{aligned}$$
(8)

The inequality

$$\begin{aligned} a_{sm+1}(\mathcal {C})\ge s+1\end{aligned}$$
(9)

follows from [14, Theorem 30].

In order to prove that all the previous inequalities are in fact equalities, consider \(\mathcal {A}=\text{ Mat }(\langle e_1,\ldots ,e_{s+i}\rangle )\). It is easy to check that \(\dim ({\mathcal {C}}\cap \mathcal {A})=sm+ik \). Therefore \(a_{sm +ik}({\mathcal {C}})\le s+i\) which, together with (8) and (9) yields

$$\begin{aligned} a_{sm+(i-1)k+1}({\mathcal {C}})=\cdots =a_{sm+ik}({\mathcal {C}})=s+i+1, \end{aligned}$$

for \(1\le i\le n-s\). \(\square \)

5 Rank distribution

In this section we compute the rank distribution of codes of the form \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\). All dually qOACs and almost all qOACs are of this form by Theorems 3.5 and  3.6. We start by recalling the definition of Gaussian q-binomial coefficient and its relation to the number of matrices of given size and rank over a finite field. The interested reader can find more detail in [2] or [18, Section 1.10].

Definition 5.1

The Gaussian q -binomial coefficient is the integer

$$\begin{aligned} \left( {\begin{array}{c}n\\ r\end{array}}\right) _q = \frac{(q^n - 1)(q^n-q)\cdots (q^n-q^{r-1})}{(q^r - 1)(q^r-q)\cdots (q^r-q^{r-1})}. \end{aligned}$$

Lemma 5.2

(a):

The number of rank r matrices in \(\mathbb {F}_q^{ \, n \times m }\) is

$$\begin{aligned} \phi _q(n,m,r)=\left( {\begin{array}{c}n\\ r\end{array}}\right) _q (q^m -1)(q^m-q)\cdots (q^m - q^{r-1}). \end{aligned}$$
(b):

The number of r-dimensional vector subspaces of \(\mathbb {F}_q^m\) containing a given i-dimensional subspace is \(\left( {\begin{array}{c}m-i\\ r-i\end{array}}\right) _q.\)

Theorem 5.3

Let \({\mathcal {C}}=\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\). For \(0\le r\le n\) denote by \(A_r\) the number of elements of rank r in \(\mathcal {C}\). Then

$$\begin{aligned} A_r = \phi _q(s,m,r) + \sum _{i=1}^{\min \{n-s,k,r\}} \left( {\begin{array}{c}k\\ i\end{array}}\right) _q \left( {\begin{array}{c}m-i\\ r-i\end{array}}\right) _q\ q^{si}\ \prod _{t=0}^{i-1}(q^{n-s} - q^t)\prod _{j=0}^{r-i-1} (q^{s} - q^j), \end{aligned}$$

for \(1\le r \le \min \{s+k,n\}\).

Proof

The number of \(n\times m\) matrices in \(\mathcal {C}\) of rank \(1\le r\le n\) is the sum of the number of matrices of rank r in \(\mathbb {F}_q^{s\times m}\) and the number of \(n\times m\) matrices of rank r in \(\mathbb {F}_q^{ \, n \times m }\) which have at least one nonzero row among the last \(n-s\). We denote the latter set of matrices by \({\mathcal {C}}_r\).

The first number is \(\phi _q(s,m,r)\) by Lemma 5.2. We now compute the cardinality of \({\mathcal {C}}_r\). Let \(1 \le i \le \min \{n-s,k,r\}\) and let \(V\subseteq \mathbb {F}_q^m\) of \(\dim (V)=i\). Let \(U \subseteq \mathbb {F}_q^m\) be an r-dimensional vector space containing V. By Lemma 5.2, the number of r-dimensional vector spaces U such that of \(\mathbb {F}_q^m\supseteq U\supseteq V\) is

$$\begin{aligned} \left( {\begin{array}{c}m-i\\ r-i\end{array}}\right) _q. \end{aligned}$$
(10)

Next we determine the number of matrices with row space U and such that the row space of the last \(n-s\) rows is V. Complete a basis \(u_1, \ldots , u_i\) of V to a basis \(u_1, \ldots , u_r\) of U. We observe that every such \(M \in {\mathcal {C}}_r\) is of the form

$$\begin{aligned} M = D \cdot \begin{pmatrix} u_1 \\ \vdots \\ u_r \\ \end{pmatrix} \in {\mathcal {C}}_r, \text{ where } D=\begin{pmatrix} A &{} B \\ C &{} 0_{(n-s) \times (r-i)} \\ \end{pmatrix}, \end{aligned}$$

\(A \in \mathbb {F}_q^{s \times i}, B \in \mathbb {F}_q^{s \times (r-i)}, C \in \mathbb {F}_q^{(n-s)\times i}\). Moreover BC, and D must have full rank. Since there is a one-to-one correspondence between M and D, the number of matrices in \({\mathcal {C}}_r\) with row space U and such that the last \(n-s\) rows generate V is

$$\begin{aligned} q^{si} \prod _{t=0}^{i-1} (q^{n-s} - q^t) \prod _{j=0}^{r-i-1} (q^s - q^j). \end{aligned}$$
(11)

The product of (10) and (11) is then the number of matrices in \({\mathcal {C}}_r\), whose last \(n-s\) rows span V.

Finally, observe that for a given \(1 \le i \le \min \{n-s,k,r\}\) there are

$$\begin{aligned} \left( {\begin{array}{c}k\\ i\end{array}}\right) _q \end{aligned}$$

i-dimensional subspaces V in \(\mathbb {F}_q^{k}\). Hence the cardinality of \(\mathcal {C}_r\) is

$$\begin{aligned} \sum _{i=1}^{\min \{n-s,k,r\}} \left( {\begin{array}{c}k\\ i\end{array}}\right) _q \left( {\begin{array}{c}m-i\\ r-i\end{array}}\right) _q \, q^{si} \prod _{t=0}^{i-1} (q^{h} - q^t) \prod _{j=0}^{r-i-1} (q^{s} - q^j). \end{aligned}$$

\(\square \)

6 Associated q-polymatroids

q-polymatroids are the q-analogs of polymatroids. They were introduced indipendently by Shiromoto in [17] and by Gorla, Jurrius, López Valdez, and Ravagnani in [10]. In this section we compute the rank functions of the q-polymatroids associated to codes of the form \(\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\). By Lemma 6.4 this determines the q-polymatroids associated to all dually qOACs and to certain qOACs.

We start by recalling the relevant definitions. The fact that the functions \(\rho _c\) and \(\rho _r\) define q-polymatroids is shown in [10, Theorem 5.3].

Definition 6.1

Let \(\mathcal {C}\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code, and let \(J \subseteq \mathbb {F}_q^n\) and \(K \subseteq \mathbb {F}_q^m\) be linear subspaces. The q -polymatroids associated to \(\mathcal {C}\) are \((\mathbb {F}_q^n,\rho _c)\) and \((\mathbb {F}_q^m,\rho _r)\), where

$$\begin{aligned} \rho _c({\mathcal {C}},J)= \frac{\dim ({\mathcal {C}})-\dim ({\mathcal {C}}\cap \text{ Mat }(J^\perp ))}{m} \end{aligned}$$

and

$$\begin{aligned} \rho _r({\mathcal {C}},K)= \frac{\dim ({\mathcal {C}})-\dim ({\mathcal {C}}\cap \text{ Mat }(K^\perp )^t)}{n}. \end{aligned}$$

The next proposition follows directly from the definition of the rank functions.

Proposition 6.2

Let \({\mathcal {C}}\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code and assume that \(m\not \mid \dim ({\mathcal {C}})\). The following are equivalent:

1:

\({\mathcal {C}}\) is a qOAC,

2:

\(\lceil \rho _c({\mathcal {C}}, \mathbb {F}_q^n) \rceil = \text{ maxrk }({\mathcal {C}})\),

3:

\(m=n\) and \(\lceil \rho _r({\mathcal {C}},\mathbb {F}_q^m)\rceil =\text{ maxrk }({\mathcal {C}})\).

The next lemmas will be used in the proof of Theorem 6.5.

Lemma 6.3

Let \(h\ge 0\), \(0\le k\le m\), and \(0\le s\le m-h\). Let \({\mathcal {C}}=\text{ Mat }(\langle e_1,\ldots ,e_s\rangle )+\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\subseteq \mathbb {F}_q^{(s+h)\times m}\) be a rank-metric code. Let \(J\subseteq \mathbb {F}_q^{s+h}\) and \(K\subseteq \mathbb {F}_q^m\). Then:

  1. (a)

    If \(J\cap \langle e_1,\ldots ,e_s\rangle =0\), then \(\dim ({\mathcal {C}} \cap \text{ Mat }(J))=k\cdot \dim (J).\)

  2. (b)

    If \(K\cap \langle e_1,\ldots ,e_k\rangle =0\), then \(\dim ({\mathcal {C}}\cap \text{ Mat }(K)^t)=s\cdot \dim (K).\)

Proof

We only prove the first statement, as the second is proved similarly. Let \(M\in {\mathcal {C}}\cap \text{ Mat }(J)\). The last \(m-k\) columns of M belong to \(J\cap \langle e_1,\ldots ,e_s\rangle \), hence they are zero. Therefore \({\mathcal {C}}\cap \text{ Mat }(J)\subseteq \text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\cap \text{ Mat }(J)\subseteq {\mathcal {C}}\cap \text{ Mat }(J),\) where the second inclusion follows from \({\mathcal {C}}\supseteq \text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\). It follows that

$$\begin{aligned} {\mathcal {C}}\cap \text{ Mat }(J)=\text{ Mat }(\langle e_1,\ldots ,e_k\rangle )^t\cap \text{ Mat }(J), \end{aligned}$$

in particular \(\dim ({\mathcal {C}} \cap \text{ Mat }(J))=k\cdot \dim (J)\). \(\square \)

The proof of the next lemma is immediate.

Lemma 6.4

Let \(V\subseteq \mathbb {F}_q^n\) and let \(\mathcal {C}\subseteq \text{ Mat }(V)\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. Then

$$\begin{aligned} \mathcal {C}\cap \text{ Mat }(J)=\mathcal {C}\cap \text{ Mat }(J\cap V) \end{aligned}$$

for any \(J\subseteq \mathbb {F}_q^n\). In particular, if \(\mathcal {C}\subseteq \text{ Mat }(\langle e_1,\ldots ,e_\ell \rangle )\) for some \(\ell \le n\), then one can regard \(\mathcal {C}\) as a rank-metric subcode of \(\mathbb {F}_q^{\ell \times m}\) by deleting the last \(n-\ell \) rows of each matrix. Moreover, the q-polymatroid \((\mathbb {F}_q^m,\rho _r)\) is left unchanged by this operation and the q-polymatroid \((\mathbb {F}_q^\ell ,\rho _c)\) determines the q-polymatroid \((\mathbb {F}_q^n,\rho _c)\) according to the formula above.

The next theorem is the main result of this section. We compute the rank functions of the q-polymatroids associated to a quasi-optimal anticode.

Theorem 6.5

Let \(h\ge 0\), \(0\le k\le m\), and \(0\le s\le m-h\). Let \(V=\langle e_1,\ldots ,e_s\rangle , V'=\langle e_1,\ldots ,e_{s+h}\rangle \subseteq \mathbb {F}_q^n\) and let \(U=\langle e_1,\ldots ,e_k\rangle \subseteq \mathbb {F}_q^m\). Let \({\mathcal {C}}=\text{ Mat }(V)+(\text{ Mat }(U)^t\cap \text{ Mat }(V'))\subseteq \mathbb {F}_q^{ \, n \times m }\) be a rank-metric code. Let \(J\subseteq \mathbb {F}_q^n\) and \(K\subseteq \mathbb {F}_q^m\). The rank functions of the q-polymatroids associated to \({\mathcal {C}}\) are

$$\begin{aligned} \rho _r({\mathcal {C}},K)=\frac{h(k-\dim (U\cap K^\perp )) +s\cdot \dim (K)}{n} \end{aligned}$$

and

$$\begin{aligned} \rho _c({\mathcal {C}},J)=s-\dim (V\cap J^\perp )+\frac{k(h+\dim (V\cap J^\perp )-\dim (V'\cap J^\perp ))}{m}. \end{aligned}$$

Proof

For any \(J\subseteq \mathbb {F}_q^n\), one has

$$\begin{aligned} \mathcal {C}\cap \text{ Mat }(J)=\mathcal {C}\cap \text{ Mat }(J\cap V') \end{aligned}$$
(12)

by Lemma 6.4, since \(\mathcal {C}\subseteq \text{ Mat }(V')\). Write \(J\cap V'\) as \((J\cap V)+J'\), where \(J'\cap V=0\). This can always be done by letting \(J'\) be the vector space generated by a set of vectors that, together with a basis of \(J\cap V\), form a basis of \(J\cap V'\). Then

$$\begin{aligned} \mathcal {C}\cap \text{ Mat }(J\cap V'){} & {} =\mathcal {C}\cap \text{ Mat }(J\cap V+J')\nonumber \\ {}{} & {} =\mathcal {C}\cap [\text{ Mat }(J\cap V)+\text{ Mat }(J')]=\text{ Mat }(J\cap V)+\mathcal {C}\cap \text{ Mat }(J'). \end{aligned}$$
(13)

Since \(J'\cap V=0\), then

$$\begin{aligned} dim(\text{ Mat }(J\cap V)+\mathcal {C}\cap \text{ Mat }(J'))=\dim (\text{ Mat }(J\cap V))+\dim (\mathcal {C}\cap \text{ Mat }(J')). \end{aligned}$$
(14)

Moreover \(\dim (\mathcal {C}\cap \text{ Mat }(J'))=k\cdot \dim (J')\) by Lemma 6.3. Combining (12), (13), and (14) one gets

$$\begin{aligned} \dim (\mathcal {C}\cap \text{ Mat }(J))= & {} m\cdot \dim (J\cap V)+k\cdot \dim (J')\\= & {} m\cdot \dim (J\cap V)+k(\dim (J\cap V')-\dim (J\cap V)). \end{aligned}$$

Therefore

$$\begin{aligned} \rho _c({\mathcal {C}},J){} & {} =\frac{\dim (\mathcal {C})-\dim (\mathcal {C}\cap \text{ Mat }(J^\perp ))}{m}\\{} & {} =s-\dim (V\cap J^\perp )+\frac{k(h+\dim (V\cap J^\perp )-\dim (V'\cap J^\perp ))}{m} \end{aligned}$$

as claimed. The other equality is proved similarly. \(\square \)