1 Introduction

The asymptotic performance of error-correcting codes is a classical topic in coding theory, going back to the work of Shannon, where random codes are used to get arbitrarily close to the capacity of a given discrete memoryless channel [21]. As in Shannon’s proof, most of the literature has focused on the case where the field size is fixed and the code length goes to infinity. Recently, increasing attention has been paid to the case where the field size grows and the other code parameters stay fixed, especially in connection with open questions in the theory of rank-metric codes and their related open questions in semifield theory [17]. For example, it was unknown if there are maximum rank distance codes that are not equivalent to a Gabidulin code, until it was shown that maximum rank distance codes are dense in the set of linear codes (for growing field extension degree of the ambient space), whereas Gabidulin codes are not [18]. Furthermore, lower bounds (in particular the Gilbert–Varshamov bound) for the minimum distance of a randomly chosen code (attained by high probability) are needed in several applications in code-based cryptography, see e.g. [3, 8, 23]. Such lower bounds can again be derived by density results about the respective code families.

In this paper, we investigate the proportion, or density, of error correcting codes with good distance properties, distinguishing between different degrees of linearity of the codes. We develop a general framework for determining (upper and lower bounds on) densities of codes in discrete translation-invariant metric spaces, with a focus on the asymptotic behavior of these densities. We then use this framework to determine the asymptotic densities of linear, (sub)linear and nonlinear codes over finite fields with respect to various metrics, namely the Hamming metric, the rank metric, and the sum-rank metric. In particular, we study extremal (or optimal) codes, in the sense that they attain the Singleton-type bound for the respective metric.

Considering codes in \({\mathbb {F}}_{q^{m}}^{n}\) endowed with the Hamming metric it is known that if \(n < q^{m}+1\) there exist linear maximum distance separable (MDS) codes, i.e., codes that achieve the classical Singleton bound, e.g., Reed–Solomon codes [20] and their generalizations. Furthermore, it is folklore knowledge that linear MDS codes are dense as the field size tends to infinity. This follows, for example, by the fact that all the maximal minors of a uniformly random matrix over \({\mathbb {F}}_q\) are nonzero with probability approaching 1 as q goes to infinity. Only few results are known about the nonlinear case, e.g., in [5] it was observed that over a binary field the minimum distance of random nonlinear codes is asymptotically worse than in the linear setting. They even show that for growing n that the order is square (which corresponds to our square in the little-o notation. Nevertheless they neither considered this with respect to the Singleton bound nor asymptotically as the field size tends to infinity. In [15], the sparsity of nonlinear MDS codes over \({\mathbb {F}}_q\) was established for q large. Furthermore, the question of the existence of (sub)linear MDS codes has recently received attention, due to their application in quantum coding. For example in [4] a geometric approach is used to classify all additive codes over \({\mathbb {F}}_{9}\). Then the MDS conjecture for this class of codes could be verified and hence the quantum MDS conjecture over \({\mathbb {F}}_{3}\).

In the rank metric it is also known that linear maximum rank-distance (MRD) codes in \({\mathbb {F}}_{q^m}^n\) exist if \(n \le m\), namely Gabidulin codes [11]. Moreover, several density results of MRD codes are known, depending on whether they are nonlinear, \({\mathbb {F}}_{q}\)-linear or even linear over the extension field \({\mathbb {F}}_{q^m}\). In particular, it has been shown in [18] that \({\mathbb {F}}_{q^m}\)-linear MRD codes are dense as \(m \rightarrow +\infty \). But if the codes belong to the wider class of \({\mathbb {F}}_{q}\)-linear MRD codes they are not dense, neither for \(q \rightarrow +\infty \), nor for \(m \rightarrow + \infty \) (except for trivial parameter choices). In particular, \({\mathbb {F}}_{q}\)-linear MRD codes are sparse as \(q \rightarrow +\infty \) [16].

In the sum-rank metric the asymptotic densities for an arbitrary degree of linearity remained mostly unexplored. Recently, in [19], the Schwartz–Zippel Lemma was used to show that for \(m \rightarrow + \infty \), most \({\mathbb {F}}_{q^{m}}\)-linear codes in \({\mathbb {F}}_{q^{m}}^{n}\) are maximum sum-rank distance (MSRD) codes.

This contrasting behavior with respect to different metrics and different types of linearity motivated us to study the density of codes in general metric spaces, with various degrees of linearity.

For this, we consider codes in \({\mathbb {F}}_{q^m}^n\), equipped with an arbitrary translation-invariant metric D.Footnote 1 For the linearity degree of the code we consider the maximal subfield \({\mathbb {F}}_{q^{\ell }} \subseteq {\mathbb {F}}_{q^m}\) over which the codes are linear. Clearly, \(\ell \) is a divisor of m.

We then classify the asymptotic densities of (possibly) nonlinear codes and codes that are linear over the subfield \({\mathbb {F}}_{q^{\ell }} \subseteq {\mathbb {F}}_{q^m}\) separately. We also treat the asymptotic density with respect to the four parameters \(q,n,\ell \) and \(s:= [{\mathbb {F}}_{q^m} :{\mathbb {F}}_{q^{\ell }}]\) separately.

1.1 Our contribution

We determine upper and lower bounds on the proportion of codes in \({\mathbb {F}}_{q^m}^n\) with a prescribed minimum distance (with respect to an arbitrary translation-invariant distance D) among all codes of a fixed cardinality. For this, we distinguish the case of nonlinear and \({\mathbb {F}}_{q^\ell }\)-linear codes in \({\mathbb {F}}_{q^m}^n\), for any suitable \(\ell \). We then analyze the asymptotic behavior of these bounds and show that this highly depends on the volume of the balls with respect to D. In particular, we give conditions on the volume with respect to the prescribed cardinality and minimum distance, such that the family of codes is dense or sparse (both in the nonlinear or (sub)linear case). With these results we can straightforwardly see that nonlinear random codes achieve the Gilbert-Varshamov bound with probability going to zero, both for growing length or field size, while (sub)linear codes achieve it with probability going to 1, for growing field size or linearity degree (but not for growing length).

In the Hamming metric, we show that independent of the linearity degree, the class of \({\mathbb {F}}_{q^{\ell }}\)-linear MDS codes, as well as the class of nonlinear MDS codes, are both sparse as \(n \rightarrow +\infty \).

When considering the asymptotic densities with respect to the field size, (sub)linear MDS codes are dense as \(q \rightarrow +\infty \) (or \(\ell \rightarrow +\infty \)). On the other hand, the probability that a nonlinear code is MDS tends to zero as \(q \rightarrow +\infty \). Finally, we give an upper bound for the asymptotic density of MDS codes with respect to s which shows that MDS codes are not dense as \(s \rightarrow +\infty \).

In the rank metric we show that nonlinear MRD codes are sparse with respect to both the field size and the code length. Moreover, we recover the previously known results on the sparsity and density of \({\mathbb {F}}_q\)- or \({\mathbb {F}}_{q^m}\)-linear MRD codes. As new contributions we derive more general results for \({\mathbb {F}}_{q^\ell }\)-linear MRD codes with respect to any of the parameters \(q,n,\ell , s\). In particular, we derive bounds on \(\ell \), for which MRD codes are sparse and for which they are dense, for \(q\rightarrow +\infty \). For \(\ell \rightarrow +\infty \) we show that MRD codes are always dense. For growing n or s we derive again upper bounds on the density.

In the sum-rank metric we show that nonlinear MSRD codes are sparse with respect to the field size. For (sub)linear MSRD codes and letting q go to infinity, we derive bounds on \(\ell \) such that the parameters for which MSRD codes are sparse and for which they are dense can be classified.

The outline of this article is as follows: In Sect. 2 we start by introducing the relevant terminology used throughout the article. We define the density functions associated with families of (sub)linear as well as (possibly) nonlinear codes. We also clarify the terms sparsity and density with respect to the parameters qns and \(\ell \). Then we briefly provide the graph theory tools to obtain the upper and lower bounds on the density of a code family within a larger family. For more details on this and the specific bipartite graphs we refer to [16]. In Sect. 3 we consider the asymptotic versions of these bounds with respect to the parameters \(n,s, \ell \) and q. Under certain assumptions we can derive that the codes are sparse or dense with respect to a given parameter. In the second part of this article, covering Sects. 4 to 6, we apply the developed classifiers from Sect. 3 to codes with respect to various distance functions. Particularly, we will focus on three major distance functions, namely the Hamming, rank, and sum-rank distance.

2 Preliminaries

2.1 Finite metric spaces and codes

Throughout this paper we let n and m be integers with \(1 \le m,n\). Moreover, we let q be a prime power, we denote the finite field of order q by \({\mathbb {F}}_q\) and its extension field of degree m by \({\mathbb {F}}_{q^m}\). From now on, unless otherwise stated, we work in \({\mathbb {F}}_{q^m}^n\) and consider a translation-invariant distance \(D: {\mathbb {F}}_{q^m}^n \times {\mathbb {F}}_{q^m}^n \rightarrow {\mathbb {R}}_{\ge 0}\).

Notation 1.1

We will repeatedly use the Bachmann-Landau notation (“Big O”, “Little O”,“\(\sim \)” and “Omega”) to describe the asymptotic growth rate of functions defined on an infinite set of natural numbers; see for example [9]. Since we are often interested in the asymptotics as the field size q tends to infinity, we denote the set of prime powers by Q and we omit “\(q \in Q\)” when writing \(q \rightarrow +\infty \).

Definition 1.2

A subset \({\mathcal {C}} \subseteq {\mathbb {F}}_{q^m}^n\) is called a code. If \(2 \le |{\mathcal {C}}|\) then the minimum distance of a code \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) with respect to D is

$$\begin{aligned} D({\mathcal {C}}) := \min \{D(x,y) : x,y \in {\mathcal {C}}, \, x \ne y\}. \end{aligned}$$

For a divisor \(\ell \) of m, we denote an \({\mathbb {F}}_{q^\ell }\)-linear code \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) of cardinality S and minimum distance at least d by \([{\mathbb {F}}_{q^m}^n,S,\ell ,d]^D\)-code. If on the other hand \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) is nonlinear, of cardinality S and minimum distance at least d, we say \({\mathcal {C}}\) is an \([{\mathbb {F}}_{q^m}^n,S,0,d]^D\)-code.

We will make extensive use of the q-ary binomial coefficient, which is defined as

and counts the number of b-dimensional subspaces of an a-dimensional vector space over \({\mathbb {F}}_{q}\). Note that the number of \({\mathbb {F}}_{q^\ell }\)-linear codes in \({\mathbb {F}}_{q^m}^n\) (for a divisor \(\ell \) of m) of \({\mathbb {F}}_{q^\ell }\)-dimension k is

$$\begin{aligned} |\{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^{m}}^n : |{\mathcal {C}}|=q^{k \ell }, \, {\mathcal {C}}\,{\textrm{is}}\, {\mathbb {F}}_{q^{\ell }}{\hbox {-linear}}\}| = \left[ \begin{matrix} ns \\ k \end{matrix}\right] _{q^\ell }. \end{aligned}$$

This formula will play a crucial role in determining bounds for the proportion of codes with certain distance properties among the set of codes of the same cardinality or dimension.

Definition 1.3

We let

$$\begin{aligned} \delta _q^D({\mathbb {F}}_{q^m}^n,S,0,d):= \frac{|\{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n: |{\mathcal {C}}|=S, \, D({\mathcal {C}}) \ge d\}|}{|\{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n: |{\mathcal {C}}|=S\}|} \end{aligned}$$
(1.1)

denote the density of (possibly) nonlinear codes of minimum distance \(D({\mathcal {C}})\) at least d within the set of (possibly) nonlinear codes of the same cardinality S. Analogously,

we define

$$\begin{aligned} \delta _q^D({\mathbb {F}}_{q^m}^n,S,\ell ,d):= \frac{|\{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^{m}}^n: |{\mathcal {C}}|=S, \, D({\mathcal {C}}) \ge d, \, {\mathcal {C}}\,{\textrm{is}}\, {\mathbb {F}}_{q^{\ell }}{\hbox {-linear }}\}|}{|\{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^{m}}^n: |{\mathcal {C}}|=S, \, {\mathcal {C}}\,{\textrm{is}}\, {\mathbb {F}}_{q^{\ell }}{\hbox {-linear}}\}|} \end{aligned}$$
(1.2)

as the density of \({\mathbb {F}}_{q^{\ell }}\)-linear codes of minimum distance \(D({\mathcal {C}})\) at least d within the set of \(\smash {{\mathbb {F}}_{q^{\ell }}}\)-linear codes of the same cardinality S.

Taking the limit in Eqs. (1.1) or (1.2) as qns or \(\ell \) tends to infinity (and the other three parameters are fixed constants) defines the asymptotic density.

If the limit is 0 we say that \({\mathbb {F}}_{q^{\ell }}\)-linear codes of minimum distance at least d and cardinality |S| are sparse as qns or \(\ell \rightarrow +\infty \). If the limit is 1 we say that such codes are dense as qns or \(\ell \rightarrow +\infty \).

Since we assume D to be invariant under translation, the ball with center \(c \in {\mathbb {F}}_{q^m}^n\) of radius \(0 \le r < \infty \) in \({\mathbb {F}}_{q^m}^n\), which is the set \(\{x \in {\mathbb {F}}_{q^m}^n: D(x,c) \le r\}\), has the same size for any center \(c \in {\mathbb {F}}_{q^m}^n\). Thus, when we consider the volume of the ball of radius r in \({\mathbb {F}}_{q^m}^n\), we do not specify the center of the ball. For ease of exhibition, we propose the following notation.

Notation 1.4

We denote the volume of the ball of radius \(0 \le r < + \infty \) in \({\mathbb {F}}_{q^m}^n\) by

$$\begin{aligned} {{\textbf {v}}}_{q}^{D}({\mathbb {F}}_{q^m}^n,r):= |\{x \in {\mathbb {F}}_{q^m}^n: D(x,0) \le r\}|. \end{aligned}$$

2.2 Graph theory tools

In this subsection we briefly recall some graph theory results from [16, Section 3]. As we will show shortly, studying the number of isolated vertices in certain bipartite graphs will give us bounds on the number of codes we are interested in.

Definition 1.5

A (directed) bipartite graph is a 3-tuple \({\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}})\), where \({\mathcal {V}}\) and \({\mathcal {W}}\) are finite non-empty sets and \({\mathcal {E}}\subseteq {\mathcal {V}}\times {\mathcal {W}}\). The elements of \({\mathcal {V}}\cup {\mathcal {W}}\) are the vertices of the graph and the tuples given by relation \({\mathcal {E}}\) are called the edges of \({\mathcal {B}}\). We say that a vertex \(W \in {\mathcal {W}}\) is isolated if there is no \(V \in {\mathcal {V}}\) such that \((V,W) \in {\mathcal {E}}\). We say that the bipartite graph \({\mathcal {B}}\) is left-regular of degree \(0 \le \partial \) if for all \(V \in {\mathcal {V}}\)

$$\begin{aligned} |\{W \in {\mathcal {W}}: (V,W) \in {\mathcal {E}}\}| = \partial . \end{aligned}$$

To derive a lower bound for the number of non-isolated vertices in a left-regular bipartite graph, we introduce the concept of an association. This notion generalizes strong regularity properties on a bipartite graph with respect to certain functions defined on its left-vertices.

Definition 1.6

Let \({\mathcal {V}}\) be a finite non-empty set and let \(0 \le r\) be an integer. An association on \({\mathcal {V}}\) of magnitude r is a function \(\alpha : {\mathcal {V}}\times {\mathcal {V}}\rightarrow \{0,\ldots ,r\}\) satisfying the following:

  1. (i)

    \(\alpha (V,V)=r\) for all \(V\in {\mathcal {V}}\);

  2. (ii)

    \(\alpha (V,V')=\alpha (V',V)\) for all \(V,V' \in {\mathcal {V}}\).

Definition 1.7

Let \({\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}})\) be a finite bipartite graph and let \(\alpha \) be an association on \({\mathcal {V}}\) of magnitude r. We say that \({\mathcal {B}}\) is \(\alpha \)-regular if for all \((V,V') \in {\mathcal {V}}\times {\mathcal {V}}\) the number of vertices \(W \in {\mathcal {W}}\) with \((V,W) \in {\mathcal {E}}\) and \((V',W) \in {\mathcal {E}}\) only depends on \(\alpha (V,V')\). If this is the case, we denote this number by \({\mathcal {W}}_\ell (\alpha )\), where \(\ell =\alpha (V,V') \in \{0, \dots , r \}\).

Remark 1.8

Note that an \(\alpha \)-regular bipartite graph for an association \(\alpha \) is necessarily left-regular of degree \(\partial ={\mathcal {W}}_r(\alpha )\).

We can now bound the number of non-isolated vertices in a left-regular bipartite graph. With these two bounds we will derive a lower and an upper bound for the density function of codes in \({\mathbb {F}}_{q^{\ell }}^{n \times s}\) having certain distance properties.

Lemma 1.9

(see [16, Lemma 3.2]) Let \({\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}})\) be a bipartite and left-regular graph of degree \(0 < \partial \). Let \({\mathcal {F}}\subseteq {\mathcal {W}}\) be the collection of non-isolated vertices of \({\mathcal {W}}\). We have

$$\begin{aligned} |{\mathcal {F}}| \le |{\mathcal {V}}| \, \partial . \end{aligned}$$

The following lemma follows by combining the notion of an association and the Cauchy-Schwarz Inequality.

Lemma 1.10

(see [16, Lemma 3.5]) Let \({\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}})\) be a finite bipartite \(\alpha \)-regular graph, where \(\alpha \) is an association on \({\mathcal {V}}\) of magnitude r. Let \({\mathcal {F}}\subseteq {\mathcal {W}}\) be the collection of non-isolated vertices of \({\mathcal {W}}\). If \(0 < {\mathcal {W}}_r(\alpha )\), then

$$\begin{aligned} \frac{{\mathcal {W}}_r(\alpha )^2 \, |{\mathcal {V}}|^2}{\sum _{\ell =0}^r {\mathcal {W}}_\ell (\alpha ) \, |\alpha ^{-1}(\ell )|} \le |{\mathcal {F}}|. \end{aligned}$$

3 Upper and lower bounds on the density of codes

In this subsection we use the upper bound of Lemma 1.9 and the lower bound of Lemma 1.10 to give bounds on the number of codes in the metric space \(({\mathbb {F}}_{q^m}^n,D)\) that have minimum distance bounded from below by some positive integer d. From these bounds we will later obtain a prediction for the asymptotic behavior of the density of these codes.

3.1 Bounds for nonlinear codes

We first consider nonlinear codes. Since we do not impose any linearity [nor (sub)linearity] on our codes in this subsection, we let \(m=1\), meaning that our ambient space is \({\mathbb {F}}_{q}^n\) and as before, D is a translation-invariant distance on \({\mathbb {F}}_{q}^n\).

Theorem 2.1

Let \(2 \le S\) and \(1 \le d < +\infty \) be integers. Define the quantities

$$\begin{aligned} \beta ^0&= \frac{1}{2}q^n ({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-1) - 2{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) +3, \\ \beta ^1&= 2{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-4, \\ \Theta&= 1 + \beta ^1 \frac{S-2}{q^n-2} \, + \, \beta ^0 \frac{(S-2)(S-3)}{\left( q^n-2\right) \left( q^n-3\right) }, \end{aligned}$$

and let \({\mathcal {F}}:= \{{\mathcal {C}}\subseteq {\mathbb {F}}_{q}^n: |{\mathcal {C}}|=S, \, D({\mathcal {C}}) \le d-1\}\). We have

$$\begin{aligned} \frac{1}{2\Theta } q^n \left( {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-1\right) \left( {\begin{array}{c}q^n-2\\ S-2\end{array}}\right) \le |{\mathcal {F}}| \le \frac{1}{2} q^n \left( {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-1\right) \left( \begin{matrix} q^n-2 \\ S-2 \end{matrix} \right) . \end{aligned}$$

Proof

We work with the bipartite graph \({\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}})\), where

$$\begin{aligned} {\mathcal {V}}=\{\{x,y\} \subseteq {\mathbb {F}}_{q}^n: x \ne y, \, D(x, y) \le d-1 \}, \end{aligned}$$

\({\mathcal {W}}\) is the collection of codes \({\mathcal {C}}\subseteq {\mathbb {F}}_{q}^n\) with \(|{\mathcal {C}}| = S\), and \((\{x,y\},{\mathcal {C}}) \in {\mathcal {E}}\) if and only if \(\{x,y\} \subseteq {\mathcal {C}}\). Note that the set of non-isolated vertices in \({\mathcal {W}}\) is exactly \({\mathcal {F}}\). We have

$$\begin{aligned} |{\mathcal {V}}| = \frac{1}{2} q^n \left( {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-1\right) , \quad |{\mathcal {W}}| = \left( \begin{matrix} q^{n} \\ S \end{matrix} \right) . \end{aligned}$$

Moreover, one easily checks that

$$\begin{aligned} |\{ {\mathcal {C}}\in {\mathcal {W}}: (\{x,y\}, {\mathcal {C}}) \in {\mathcal {E}}\}| = \displaystyle \left( {\begin{array}{c}q^{n}-2\\ S-2\end{array}}\right) . \end{aligned}$$

Hence \({\mathcal {B}}\) is a left-regular graph of degree

$$\begin{aligned} \left( \begin{matrix} q^n-2 \\ S-2 \end{matrix} \right) . \end{aligned}$$

Applying Lemma 1.9 we obtain the upper bound on \(|{\mathcal {F}}|\).

To prove the lower bound, we let \(\alpha : {\mathcal {V}}\times {\mathcal {V}}\rightarrow \{0,1,2\}\) be defined by

$$\begin{aligned} \alpha (\{x,y\},\{z,t\}):= 4-|\{x,y,z,t\}| \end{aligned}$$

for all \(x,y,z,t \in {\mathbb {F}}_{q}^n.\) We have

$$\begin{aligned} |\alpha ^{-1}(2)|&= |{\mathcal {V}}|, \\ |\alpha ^{-1}(1)|&= 2|{\mathcal {V}}|({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-2), \\ |\alpha ^{-1}(0)|&= |{\mathcal {V}}|(|{\mathcal {V}}|-2{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)+3). \end{aligned}$$

It is easy to see that \(|\alpha ^{-1}(2)| = |{\mathcal {V}}|\). The elements of the domain \(\alpha ^{-1}(1)\) can be obtained by choosing \(\{x,y\} \in {\mathcal {V}}\) arbitrary and then \(\{z,t\} \in {\mathcal {V}}\) with either \(z=x\) or \(z=y\) and

$$\begin{aligned} t \in \{v \in {\mathbb {F}}_{q}^n: D(v,z) \le d-1\} \backslash \{x,y\}. \end{aligned}$$

Therefore

$$\begin{aligned} |\alpha ^{-1}(1)|=2|{\mathcal {V}}|({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)-2). \end{aligned}$$

To compute \(|\alpha ^{-1}(0)|\) we simply note that

$$\begin{aligned} |{\mathcal {V}}|^2=|\alpha ^{-1}(0)|+|\alpha ^{-1}(1)|+|\alpha ^{-1}(2)|. \end{aligned}$$

Therefore the value of \(|\alpha ^{-1}(0)|\) follows from the values of \(|\alpha ^{-1}(1)|\) and \(|\alpha ^{-1}(2)|\). Simple counting arguments imply that the bipartite graph \({\mathcal {B}}\) is regular with respect to \(\alpha \). Therefore for \((\{x,y\},\{z,t\}) \in {\mathcal {V}}\times {\mathcal {V}}\) and \(\ell =\alpha (\{x,y\},\{z,t\})\) we define

$$\begin{aligned} {\mathcal {W}}_{\ell }(\alpha ) := |\{W \in {\mathcal {W}}: \{x,y,t,z\} \subseteq W\}| = \left( \begin{matrix} q^{n}-4+\ell \\ S-4+\ell \end{matrix} \right) . \end{aligned}$$

We can now apply Lemma 1.10 obtaining that \(|{\mathcal {F}}|\) is lower bounded by

$$\begin{aligned} \frac{{\mathcal {W}}_{2}(\alpha )^2 \, |{\mathcal {V}}|^2}{|\alpha ^{-1}(2)|{\mathcal {W}}_{2}(\alpha ) + |\alpha ^{-1}(1)|{\mathcal {W}}_{1}(\alpha ) + |\alpha ^{-1}(0)|{\mathcal {W}}_{0}(\alpha )}. \end{aligned}$$

Finally, plugging in the formulas for \(|\alpha ^{-1}(0)|\), \(|\alpha ^{-1}(1)|\) and \(|\alpha ^{-1}(2)|\), and applying the identity

$$\begin{aligned} \left( {\begin{array}{c}a\\ b\end{array}}\right) = \frac{a}{b} \left( {\begin{array}{c}a-1\\ b-1\end{array}}\right) , \end{aligned}$$
(2.1)

for all \(1 \le b \le a\) yields the desired result. \(\square \)

As a corollary we get the following bounds on the proportion of codes in \({\mathbb {F}}_q^{n}\) of minimum distance at least d, again using the identity in (2.1).

Corollary 2.2

Let \(2 \le S\) be an integer and consider \(1 \le d < +\infty \). We have

$$\begin{aligned}&1-\frac{({{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)-1)S(S-1)}{2\left( q^n-1\right) } \le \delta _q^D({\mathbb {F}}_q^n,S,0,d) \\&\le 1-\frac{({{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)-1)S(S-1)}{2\Theta (q^n-1)}, \end{aligned}$$

where \(\Theta \) is the same as in Theorem 2.1.

3.2 Bounds for (sub)linear codes

In this subsection, we fix a divisor \(\ell \) of m and let \(s= [{\mathbb {F}}_{q^{m}}: {\mathbb {F}}_{q^{\ell }}]\). We will consider \({\mathbb {F}}_{q^\ell }\)-linear codes in the metric space \(({\mathbb {F}}_{q^m}^n,D)\).

We start by providing the bounds obtained using the tools from graph theory.

Theorem 2.3

Let \(1 \le k \le ns\) and \(1 \le d < +\infty \) be integers. Let

$$\begin{aligned} {\mathcal {F}}:= \{{\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n : |{\mathcal {C}}|=q^{\ell k}, \, D({\mathcal {C}}) \le d-1, \, {\mathcal {C}}\,{\textrm{is}}\, {\mathbb {F}}_{q^{\ell }}\,{\hbox {-linear}}\}. \end{aligned}$$

We have

Proof

We work with the bipartite graph

$$\begin{aligned} {\mathcal {B}}=({\mathcal {V}},{\mathcal {W}},{\mathcal {E}}), \end{aligned}$$

where \({\mathcal {V}}\) is the set of elements in \({\mathbb {F}}_{q^m}^n\) of minimum distance at most \(d-1\) (up to multiples by elements of \({\mathbb {F}}_{q^\ell }\)) from 0, \({\mathcal {W}}\) is the collection of \({\mathbb {F}}_{q^\ell }\)-linear codes in \({\mathbb {F}}_{q^m}^n\) of \({\mathbb {F}}_{q^\ell }\)-dimension k, and \((M,{\mathcal {C}}) \in {\mathcal {E}}\) if and only if \(M \in {\mathcal {C}}\). Hence \({\mathcal {F}}\) is the family of non-isolated vertices in \({\mathcal {W}}\). Note that we have

Moreover, for \(M \in {\mathcal {V}}\) we have

Hence the bipartite graph \({\mathcal {B}}\) is left-regular of degree With this, the upper bound in the theorem is an easy consequence of Lemma 1.9. For the lower bound, consider the association

$$\begin{aligned} \alpha : {\mathcal {V}}\times {\mathcal {V}}\rightarrow \{0,1\}, \quad (V,V') \mapsto 2-\dim \langle V,V' \rangle . \end{aligned}$$

It is easy to see that

$$\begin{aligned} |\alpha ^{-1}(0)|= |{\mathcal {V}}| (|{\mathcal {V}}|-1),\quad |\alpha ^{-1}(1)|= |{\mathcal {V}}| \end{aligned}$$

and \({\mathcal {B}}\) is \(\alpha \)-regular. Furthermore we have

$$\begin{aligned} {\mathcal {W}}_0(\alpha )= \left[ \begin{matrix} ns-2 \\ k-2 \end{matrix}\right] _{q^\ell }, \; {\mathcal {W}}_1(\alpha )= \left[ \begin{matrix} ns-1 \\ k-1 \end{matrix}\right] _{q^\ell } \end{aligned}$$

which combined with Lemma 1.10 directly implies the second bound in the theorem. \(\square \)

As an immediate consequence of the last theorem we obtain bounds on the density function of \({\mathbb {F}}_{q^\ell }\)-codes with minimum distance bounded from below.

Corollary 2.4

Let \(1 \le k \le ns\) and \(1 \le d < +\infty \) be integers. We have

(2.2)

where

4 Asymptotic results

This section is devoted to general asymptotic results on the density function of codes in \({\mathbb {F}}_{q^m}^n\) endowed with a translation-invariant metric D. More precisely, we are interested in the following question: What is the probability that a uniformly random code in \(({\mathbb {F}}_{q^m}^n,D)\) of a given cardinality has minimum distance (at least) d, as either q, n, or in the (sub)linear case s or \(\ell \) tend to infinity, where \(s:= [{\mathbb {F}}_{q^m} :{\mathbb {F}}_{q^{\ell }}]\). Our results indicate that the answer to this question highly depends on the volume of balls in \(({\mathbb {F}}_{q^m}^n, D)\). We treat the nonlinear and (sub)linear case separately again.

4.1 The nonlinear case

From Corollary 2.2 we obtain asymptotic bounds on the density (as \(q \rightarrow +\infty \) or \(n \rightarrow +\infty \)) of (possibly) nonlinear codes with minimum distance bounded from below.

Theorem 3.1

Let \(2 \le n\) and let \(1 \le d \le n\) be integers. Consider the sequence \(\smash {({\mathbb {F}}_{q}^{n})_{q \in Q}}\) and a sequence of integers \(\smash {(S_q)_{q \in Q}}\) with \(2 \le S_q\) for all \(q \in Q\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{q \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)S_{q}^{2}}{2q^{n} }\right) ,0 \right\} \le \liminf _{q \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q}^n,S_{q},0,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in \Omega \left( q^{n}S_{q}^{-2}\right) \, \text {as} \, \, q \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{q \rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q}^n,S_{q},0,d)\le \limsup _{q \rightarrow +\infty }\left( \frac{1}{1+\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{2q^{n}}}\right) <1. \end{aligned}$$

In particular,

$$\begin{aligned} \lim _{q \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q}^n,S_q,0,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if }}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in o(q^{n}S_{q}^{-2}) \,{\textrm{as}}\, q \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in \omega (q^{n}S_{q}^{-2}) \,{\textrm{as}}\, q \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

Proof

The first statement of the theorem is an easy consequence of Corollary 2.2 and the fact that we always have \(0 \le \delta _q^D({\mathbb {F}}_q^n, S_q, 0, d)\). For the second statement, as in Theorem 2.1 we let

$$\begin{aligned} \beta ^0_q&= \frac{1}{2}q^n ({{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)-1) - 2{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1) +3, \\ \beta ^1_q&= 2{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)-4, \\ \Theta _q&= 1 + \beta ^1_q \frac{S_q-2}{q^n-2} \, + \, \beta ^0_q \frac{(S_q-2)(S_q-3)}{\left( q^n-2\right) \left( q^n-3\right) }. \end{aligned}$$

It is easy to check that we have

$$\begin{aligned} \Theta _q \sim 1+ \frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1) S_q^2}{2q^n} \quad {\textrm{as }}\,q \rightarrow +\infty . \end{aligned}$$

Therefore,

$$\begin{aligned}&\limsup _{q \rightarrow +\infty }\left( 1- \frac{({{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)-1)S_q(S_q-1)}{2\Theta _q(q^n-1)}\right) \nonumber \\&= \limsup _{q \rightarrow +\infty }\left( 1- \frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{2q^n+ {{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}\right) . \end{aligned}$$
(3.1)

In order to prove that the asymptotic upper bound in the theorem is smaller than 1, note that \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in \Omega \left( q^{n}S_{q}^{-2}\right) \, \text {as} \, \, q \rightarrow +\infty \) means that

$$\begin{aligned} 0 < \liminf _{q \rightarrow +\infty } \frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{q^n}. \end{aligned}$$

In particular, rewriting (3.1) gives

$$\begin{aligned} \limsup _{q \rightarrow +\infty } \left( 1-\frac{ {{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{2q^n+{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}\right) = \limsup _{q \rightarrow +\infty } \left( \frac{1}{1+\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{2q^{n}}}\right) < 1, \end{aligned}$$

concluding the proof of the theorem. \(\square \)

We now establish the analogous result to Theorem 3.1 when n tends to infinity. The proof of the following statement is an easy alteration of the proof of Theorem 3.1 and hence we omit it.

Theorem 3.2

Let \(q \in Q\) be a prime power and d be an integer such that \(1 \le d < +\infty \). Consider the sequence \(({\mathbb {F}}_{q}^{n})_{n \ge 1}\) and a sequence of integers \((S_n)_{n \ge 1}\) with \(2 \le S_n\) for all \(1 \le n\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{n \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)S_{n}^{2}}{2q^{n} }\right) ,0 \right\} \le \liminf _{n \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q}^n,S_{n},0,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in \Omega \left( q^{n}S_{n}^{-2}\right) \, \text {as} \, \, n \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{n\rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q}^n,S_{n},0,d)\le \limsup _{n \rightarrow +\infty }\left( \frac{1}{1+\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_q^n,d-1)S_q^2}{2q^{n}}}\right) <1. \end{aligned}$$

In particular,

$$\begin{aligned} \lim _{n \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q}^n,S_n,0,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in o(q^{n}S_{n}^{-2})\,{\textrm{as}}\, n \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1) \in \omega (q^{n}S_{n}^{-2})\,{\textrm{as }}\,n \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

As we applied the bounds given in Corollary 2.2 in a very general way, without having any knowledge about \(\smash {{{\textbf {v}}}_{q}^{D}({\mathbb {F}}_{q}^n,r)}\), the requirements on the asymptotic behavior on the cardinalities in Theorems 3.1 and  3.2 for certain codes to be dense or sparse are the same, even though we send different parameters to infinity. This is something that we will also observe when looking at (sub)linear codes in the next subsection.

Remark 3.3

In [12, 22] Gilbert and Varshamov gave a lower bound that shows the existence of codes of sufficiently large cardinality and minimum distance. More precisely, it says that there exists a code \({\mathcal {C}}\subseteq {\mathbb {F}}_{q}^n\) of minimum distance d with

$$\begin{aligned} \frac{q^{n}}{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q}^n,d-1)} \le |{\mathcal {C}}|. \end{aligned}$$

It is an immediate consequence of Theorems 3.1 and 3.2 that, while such codes exist, the probability that a uniformly random (possibly nonlinear) code, whose cardinality is close to the Gilbert-Varshamov bound, has minimum distance at least d, goes to 0 both as \(q \rightarrow +\infty \) and \(n \rightarrow +\infty \).

4.2 The (sub)linear case

From Corollary 2.4 we obtain results for the asymptotic density of (sub)linear codes with minimum distance bounded from below as one of the parameters qns or \(\ell \) tends to infinity and the other three parameters are treated as constants. We will repeatedly use some asymptotic estimates of the q-binomial coefficient. One of these estimates involves the quantity

$$\begin{aligned} \pi (q) := \prod _{i=1}^{\infty } \left( \frac{q^{i}}{q^{i}-1} \right) . \end{aligned}$$

Note that the infinite product \(\pi (q)\) is closely linked to the Euler function \(\phi \); see e.g. [2, Section 14]. The Euler function \(\phi :(-1,1) \rightarrow {\mathbb {R}}\) is defined as

$$\begin{aligned} \phi : x \mapsto \prod _{i=1}^{\infty }(1-x^i). \end{aligned}$$

We have \(\pi (q)=1/\phi (1/q)\) for all \(q \in Q\). We will also need the following asymptotic estimates.

Lemma 3.4

Let \(0 \le b \le a\) be integers and let \(k: {\mathbb {N}} \rightarrow {\mathbb {N}}\) and \({\tilde{k}}: {\mathbb {N}} \rightarrow {\mathbb {N}}\) be linear functions such that \({\tilde{k}}(n) \le k(n)\) for all \(n \in {\mathbb {N}}\). We have

  1. (a)

    .

  2. (b)

Similar asymptotic estimates as in Lemma 3.4 have been proved in [16, Section 6], and thus we omit the proofs.

Theorem 3.5

Let \(1 \le n,\ell ,s\) and \(1 \le d < +\infty \) be integers. We fix \(1 \le k \le ns\) and consider the sequence \(\smash {({\mathbb {F}}_{q^{m}}^n)_{q \in Q}}\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{q \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{\ell (ns+1-k)}} \right) ,0 \right\} \le \liminf _{q \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in \Omega \left( q^{\ell (ns+1-k)}\right) \, \text {as} \, \, q \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{q \rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d)\le \limsup _{q \rightarrow +\infty } \left( \frac{1}{1 + {{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{-\ell (ns+1-k)}}}\right) <1. \end{aligned}$$
    (3.2)

In particular,

$$\begin{aligned} \lim _{q \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in o(q^{\ell (ns+1-k)}) \,{\textrm{as}}\, q \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if}}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in \omega (q^{\ell (ns+1-k)})\,{\textrm{as}}\, q \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

Proof

From Lemma 3.4 we obtain

Now (i) is an easy consequence of Corollary  2.4 and the fact that \(0 \le \delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d)\).

For the second statement we consider the upper bound of Corollary 2.4. Together with Lemma 3.4 we have

and

as \(q \rightarrow +\infty \). Hence we obtain

as \(q \rightarrow +\infty \). Now, taking the limit superior as \(q \rightarrow +\infty \) in the bound of  (2.2) reads

$$\begin{aligned} \limsup _{q \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^m}^n,q^{\ell k},\ell ,d)&\le \limsup _{q \rightarrow +\infty } \left( 1- \frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{\ell (ns-k+1)} + {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)} \right) . \end{aligned}$$

Since \(q^{\ell k} \in \Omega \left( \frac{q^{\ell (ns+1)}}{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}\right) \, \text {as} \, \, q \rightarrow +\infty \), we have

$$\begin{aligned}&\limsup _{q \rightarrow +\infty } \left( 1- \frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{\ell (ns-k+1)} + {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)} \right) \\&\quad = \limsup _{q\rightarrow +\infty }\frac{1}{1+{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)q^{-\ell (ns+1-k)}} <1 , \end{aligned}$$

yielding the statement in (3.2). \(\square \)

Note that the asymptotic estimates for the q-binomial coefficient given in Lemma 3.4 are the same as \(q \rightarrow +\infty \), respectively as \(\ell \rightarrow +\infty \). Hence we can give an analogous result to Theorem 3.5 but with \(\ell \) tending to infinity.

Further note that the parameters of the q-binomial coefficient involved in the upper and lower bound of \(\delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d)\) (see Corollary 2.4) can be written as a linear function in either n or in s such that the assumptions of Lemma 3.4 are fulfilled. This gives us then two asymptotic results regarding \(n \rightarrow +\infty \) (and \(s \rightarrow +\infty \)). Since the proofs of Theorems 3.6, 3.7 and 3.8 follow the same arguments as the proof of Theorem 3.5 we omit them.

Theorem 3.6

Let \(1 \le n,s\) and \(1 \le d < +\infty \) be integers and let \(q \in Q\). We fix \(1 \le k \le ns\) and consider the sequence \(({\mathbb {F}}_{q^{\ell s}}^n)_{\ell \ge 1}\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{\ell \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}{q^{\ell (ns+1-k)}} \right) ,0 \right\} \le \liminf _{\ell \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in \Omega \left( q^{\ell (ns+1-k)}\right) \, \text {as} \, \, \ell \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{\ell \rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d)\le \limsup _{\ell \rightarrow +\infty }\left( \frac{1}{1 + {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1)q^{-\ell (ns+1-k)}}\right) <1. \end{aligned}$$

In particular,

$$\begin{aligned} \lim _{\ell \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in o(q^{\ell (ns+1-k)})\,{\textrm{as}}\, \ell \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in \omega (q^{\ell (ns+1-k)}) \,{\textrm{as}}\, \ell \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

In the next theorem we consider the asymptotic density, where n tends to infinity and the other parameters are treated as constants.

Theorem 3.7

Let \(q \in Q, 1 \le s, \ell \) and \(1 \le d < +\infty \) be integers. Define a linear function \(k: {\mathbb {N}} \rightarrow {\mathbb {N}}\) such that \((k(n))_{n \ge 1}\) describes a sequence of integers where \(1 \le k(n) \le ns\) for all \(1 \le n\) and consider the sequence \(({\mathbb {F}}_{q^{m}}^n)_{n \ge 1}\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{n \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{\ell (ns+1-k)}} \right) ,0 \right\} \le \liminf _{n \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in \Omega \left( q^{\ell (ns+1-k)}\right) \, \text {as} \, \, n \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{n \rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d)\le \limsup _{n \rightarrow +\infty }\left( \frac{1}{1 + {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1)q^{-\ell (ns+1-k)}}\right) <1. \end{aligned}$$

In particular,

$$\begin{aligned} \lim _{n \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in o(q^{\ell (ns+1-k)})\,{\textrm{as}}\, n \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{m}}^n,d-1) \in \omega (q^{\ell (ns+1-k)})\, {\textrm{as}}\, n \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

In the last theorem concerning the asymptotic density of \({\mathbb {F}}_{q^{\ell }}\)-linear codes we let s, go to infinity.

Theorem 3.8

Let \(q \in Q\), \(1 \le n, \ell \) and \(1 \le d < +\infty \) be integers. Define a linear function \(k: {\mathbb {N}} \rightarrow {\mathbb {N}}\) such that \((k(s))_{s \ge 1}\) describes a sequence of integers with \(1 \le k(s) \le ns\) for all \(1 \le s\) and consider the sequence \(({\mathbb {F}}_{q^{\ell s}}^n)_{s \ge 1}\).

  1. (i)

    We have

    $$\begin{aligned} \max \left\{ \liminf _{s \rightarrow +\infty } \left( 1-\frac{{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}{q^{\ell (ns+1-k)}} \right) ,0 \right\} \le \liminf _{s \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d). \end{aligned}$$
  2. (ii)

    If \({{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in \Omega \left( q^{\ell (ns+1-k)}\right) \, \text {as} \, \, s \rightarrow +\infty , \, \text {then}\)

    $$\begin{aligned} \limsup _{s \rightarrow +\infty } \delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d)\le \limsup _{s \rightarrow +\infty }\left( \frac{1}{1 + {{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1)q^{-\ell (ns+1-k)}}\right) <1. \end{aligned}$$

In particular,

$$\begin{aligned} \lim _{s \rightarrow +\infty }\delta _q^D({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in o(q^{\ell (ns+1-k)})\,{\textrm{as}}\, s \rightarrow +\infty , \\ 0 \quad &{}{\textrm{if }}\,{{\textbf {v}}}_q^{D}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in \omega (q^{\ell (ns+1-k)}) \,{\textrm{as}}\, s \rightarrow +\infty . \end{array}\right. } \end{aligned}$$

Remark 3.9

Since the term \({q^{\ell ns}}/{q^{\ell (ns+1)}}\) tends to zero both as \(q \rightarrow +\infty \), respectively \(\ell \rightarrow +\infty \) Theorems 3.5 and 3.6 imply that a uniformly random \({\mathbb {F}}_{q^{\ell }}\)-linear code in \({\mathbb {F}}_{q^m}^n\) of minimum distance at least d, for some integer \(1 \le d < +\infty \), will attain the Gilbert-Varshamov bound with high probability for large q and also for large linearity degree \(\ell \). However, when either n or s tend to infinity (and the other parameters are treated as constants), then it can easily be seen that the probability that \({\mathbb {F}}_{q^\ell }\)-linear codes attain the Gilbert-Varshamov bound is upper bounded by \(q^{\ell }/(q^{\ell }+1)\).

Theorem 3.10

Let \(({\mathbb {F}}_{q^m}^n,D)\) be a metric space where D is a translation-invariant metric on \({\mathbb {F}}_{q^m}^n\) and let \(\ell \) be a divisor of m. The probability that a uniformly random \({\mathbb {F}}_{q^\ell }\)-linear code in \(({\mathbb {F}}_{q^m}^n,D)\) satisfies the Gilbert-Varshamov bound is (infinitesimally close to) 1 if we let q go to infinity.

5 Application I: codes in the hamming metric

In this section we determine the asymptotic density of codes in \({\mathbb {F}}_{q^{m}}^{n}\), equipped with the Hamming metric. In particular, we study the probability that a uniformly random code in \({\mathbb {F}}_{q^{m}}^{n}\) of a given cardinality achieves the Singleton bound with equality as one of the four parameters qns or \(\ell \) tends to infinity (where \(m=s\ell \)) and the other three parameters are treated as constants. We start by introducing the required preliminaries.

Definition 4.1

Let \(x \in {\mathbb {F}}_{q^m}^n\). The Hamming weight of x is \(\omega ^{{\textrm{H}}}(x)\) where \(\omega ^{{\textrm{H}}}\) is the function defined as

$$\begin{aligned} \omega ^{{\textrm{H}}}: {\mathbb {F}}_{q^m}^n \rightarrow {\mathbb {N}}, \, x \mapsto |\{ i \in [n]: x_{i} \ne 0 \}|. \end{aligned}$$

Let \(x,y \in {\mathbb {F}}_{q^m}^n\), then the Hamming distance between x and y is \(D^{{\textrm{H}}}(x,y):= \omega ^{{\textrm{H}}}(x-y)\).

Throughout this section, we are working in the metric space \(({\mathbb {F}}_{q^m}^n,D^{{\textrm{H}}})\). As in Sect. 1, we denote nonlinear codes of cardinality S in \({\mathbb {F}}_{q^m}^n\) and of Hamming distance at least d as \([{\mathbb {F}}_{q^m}^n,S,0,d]^{H}\)-codes. Similarly, we call \({\mathbb {F}}_{q^\ell }\)-linear codes of dimension k and minimum Hamming distance at least d \([{\mathbb {F}}_{q^m}^n,q^{\ell k},\ell ,d]^{H}\)-codes.

It is a desirable property for a code to have large cardinality and large minimum distance at the same time. The trade-off between the cardinality and the minimum distance of a Hamming-metric code is captured by the following famous result.

Theorem 4.2

(Singleton bound; see [10, Theorem 5.4]) Let \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^{m}}^{n}\) be a \([{\mathbb {F}}_{q^m}^n,q^{\ell k},\ell ,d]^{H}\)-code. We have \(q^{\ell k} \le q^{m(n-d+1)}.\)

A code in \(({\mathbb {F}}_{q^m}^n, D^{{\textrm{H}}})\) is called MDS (maximum distance separable) code if its cardinality meets the Singleton bound with equality.

To estimate the asymptotic density of MDS codes we need the size of the Hamming-metric ball and its estimates. It is well-known and easy to see that the volume of the Hamming-metric ball of radius r is

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^m}^n,r):= \sum _{i=0}^r\left( {\begin{array}{c}n\\ i\end{array}}\right) (q^{m}-1)^{i}, \end{aligned}$$
(4.1)

for any \(0 \le r < \infty \). The following lemma states the asymptotic estimates of the Hamming-metric ball as \(q \rightarrow +\infty \), as \(n\rightarrow +\infty \) and as \(m\rightarrow +\infty \). All three statements can easily be derived from Equation (4.1).

Lemma 4.3

The following estimates hold.

  1. (i)

    Let \(0 \le r \le n\). We have \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^m}^n,r) \sim \left( {\begin{array}{c}n\\ r\end{array}}\right) q^{rm}\) as \(q \rightarrow +\infty \).

  2. (ii)

    Let \(0 \le r \le n\). We have \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^m}^n,r) \sim \left( {\begin{array}{c}n\\ r\end{array}}\right) q^{rm}\) as \(m \rightarrow +\infty \).

  3. (iii)

    Let \(0 \le r < +\infty \). We have \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^m}^n,r) \sim \left( {\begin{array}{c}n\\ r\end{array}}\right) (q^{m}-1)^r\) as \(n \rightarrow +\infty \).

5.1 Nonlinear MDS codes

In this short subsection we determine the density of nonlinear MDS codes in \({\mathbb {F}}_q^n\) (i.e., we set \(m=1\), as before) as either q or n tends to infinity. We summarize the obtained results in the following theorem.

Theorem 4.4

Let \(2 \le d\) be an integer.

  1. (i)

    Let \(2 \le n\) be an integer. Then we have

    $$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q}^n,q^{n-d+1},0,d)= 0. \end{aligned}$$
  2. (ii)

    We have

    $$\begin{aligned} \lim _{n \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q}^n,q^{n-d+1},0,d)= 0. \end{aligned}$$

In particular, nonlinear MDS codes in \({\mathbb {F}}_q^n\) are sparse both as \(q \rightarrow +\infty \), respectively as \(n \rightarrow +\infty \).

Proof

From the estimates given in Lemma 4.3 we get

$$\begin{aligned} \lim _{q \rightarrow +\infty }\frac{q^{n}}{{{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q}^{n},d-1)q^{2(n-d+1)}} = \lim _{q \rightarrow +\infty }\frac{1}{\left( {\begin{array}{c}n\\ d-1\end{array}}\right) q^{n-d+1}} =0 \end{aligned}$$

which, by Theorem 3.1, gives the first result.

Similarly, we have

$$\begin{aligned} \lim _{n \rightarrow +\infty }\frac{q^{n}}{{{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q}^{n},d-1)q^{2(n-d+1)}} = \lim _{n \rightarrow +\infty }\frac{1}{\left( {\begin{array}{c}n\\ d-1\end{array}}\right) q^{n}}\left( \frac{q^{2}}{q-1}\right) ^{d-1} =0 \end{aligned}$$

which, together with Theorem 3.2, implies the second result. \(\square \)

5.2 (Sub)linear MDS codes

Since we are now in the (sub)linear case, we fix a divisor \(\ell \) of m such that \({\mathbb {F}}_{q^{\ell }}\) is a subfield of \({\mathbb {F}}_{q^{m}}\) and let \(s:= [{\mathbb {F}}_{q^{m}} :{\mathbb {F}}_{q^{\ell }}]\). We then apply the results of Sect. 3.2 to derive density results of \([{\mathbb {F}}_{q^m}^n,q^{m(n-d+1)},\ell ,d]^{H}\)-codes when one of the four parameters \(q, \ell , n\) or s tends to infinity.

First we consider the asymptotic density of \({\mathbb {F}}_{q^{\ell }}\)-linear MDS codes as the field size q tends to infinity.

Theorem 4.5

Let \(1 \le n, \ell , s,d\) be integers such that \(1 \le d \le n\). Then we have

$$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d)= 1, \end{aligned}$$

i.e., MDS codes in \({\mathbb {F}}_{q^m}^n\) are dense as \(q \rightarrow +\infty .\)

Proof

From the estimate of the volume given in Lemma 4.3 we have

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{q^{m(n-d+1)} \, {{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{m}}^n,d-1)}{q^{\ell (ns+1)}} = \lim _{q \rightarrow +\infty } \frac{\left( {\begin{array}{c}n\\ d-1\end{array}}\right) }{q^{\ell }}=0 \end{aligned}$$

which, by Theorem 3.5, gives the statement of the theorem. \(\square \)

Analogously, by the asymptotic formulas given in Theorems 3.6, 4.5 reads as follows for increasing field extension degree \(\ell \).

Theorem 4.6

Let \(q \in Q\) and \(1 \le n, s,d\) be integers such that \(1 \le d \le n\). Then

$$\begin{aligned} \lim _{\ell \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d)= 1. \end{aligned}$$

If we let the code length n tend to infinity, we obtain the following sparsity result. We state this result for completeness, even though it is well known that MDS codes do not exist at all for large n; see Remark 4.9.

Theorem 4.7

Let \(q \in Q\) and \(1 \le \ell , s\), \(2 \le d < \infty \) be integers. We have

$$\begin{aligned} \lim _{n \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d)= 0. \end{aligned}$$

Proof

By Lemma 4.3 we have

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{m}}^n,d-1) \sim \left( {\begin{array}{c}n\\ d-1\end{array}}\right) (q^{m}-1)^{d-1} \quad {\textrm{as}} \, n \rightarrow + \infty . \end{aligned}$$

One easily checks that \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{m}}^n,d-1) \in \omega (q^{\ell (s(d-1)+ 1)}).\) This combined with Theorem 3.7 gives the statement of the theorem. \(\square \)

The last parameter we consider is the degree s of the field extension \({\mathbb {F}}_{q^{m}}/ {\mathbb {F}}_{q^{\ell }}\). For this parameter we will only upper bound the asymptotic density \(\lim _{s \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d)\).

Theorem 4.8

Let \(q \in Q\) and \(2 \le n\), \(1 \le \ell \), \(2 \le d \le n\) be integers. Then

$$\begin{aligned} \limsup _{s \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d)\le \frac{1}{1+ \left( {\begin{array}{c}n\\ d-1\end{array}}\right) q^{-\ell }} <1. \end{aligned}$$

Proof

From the estimate of \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)\) given in Lemma 4.3 we get

$$\begin{aligned} \lim _{s \rightarrow +\infty } \frac{q^{\ell s(n-d+1)} \cdot {{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}{q^{\ell (ns+1)}} = \frac{\left( {\begin{array}{c}n\\ d-1\end{array}}\right) }{q^{\ell }}. \end{aligned}$$
(4.2)

Hence \({{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \in \Omega (q^{\ell (s(d-1)+ 1)})\) as \(s\rightarrow + \infty \) and applying Theorem 3.8 gives

$$\begin{aligned} \limsup _{s \rightarrow +\infty } \delta _q^{H}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d) \le \limsup _{s \rightarrow +\infty }\left( \frac{1}{1+{{\textbf {v}}}_{q}^{{\textrm{H}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)q^{-\ell (s(d-1)+1)}}\right) . \end{aligned}$$
(4.3)

Now the desired upper bound follows from (4.2) and (4.3). \(\square \)

Remark 4.9

Note that fixing the linearity degree of the code and studying the asymptotic density of MDS codes for the parameters \(q,n, \ell \) and s leads to different results. For growing field size, i.e., \(q\rightarrow + \infty \) (or \(\ell \rightarrow + \infty \)), \([{\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d]^{H}\)-codes are dense. On the contrary, if we let n grow, then MDS codes are sparse. This is in line with the MDS conjecture, which implies that no non-trivial \([{\mathbb {F}}_{q^m}^{n}, q^{m(n-d+1)}, \ell , d]\)-codes exist if \(n>q^m+2\). Considering the asymptotic density for \(s \rightarrow +\infty \), one can see that \([{\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d]^{H}\)-codes are not dense, but the question whether MDS codes are sparse or not for large s remains open.

6 Application II: codes in the rank metric

In this section we apply the results of Sects. 2 and 3 to codes in the rank metric. We start by quickly recalling the required preliminaries on rank-metric codes.

Definition 5.1

Let \(x \in {\mathbb {F}}_{q^m}^n\). The rank weight of x is defined as the dimension of the \({\mathbb {F}}_{q}\)-span of its entries. More formally, for \(x \in {\mathbb {F}}_{q^m}^n\) we define \(\omega ^{{\textrm{rk}}}(x)\) as

$$\begin{aligned} \omega ^{{\textrm{rk}}}: {\mathbb {F}}_{q^m}^n \rightarrow {\mathbb {N}}, \, x \mapsto \dim _{{\mathbb {F}}_{q}}\langle x_{1}, \dots , x_{n} \rangle . \end{aligned}$$

The rank distance between \(x,y \in {\mathbb {F}}_{q^m}^n\) is then defined as \(D^{{\textrm{rk}}}(x,y):=\omega ^{{\textrm{rk}}}(x-y)\).

One can show that \(D^{{\textrm{rk}}}\) is a translation-invariant metric on \({\mathbb {F}}_{q^m}^n\) and throughout this section we always work with the metric space \(({\mathbb {F}}_{q^m}^n, D^{{\textrm{rk}}})\). At times we will take advantage of the following observation.

Remark 5.2

When we equip the matrix space \({\mathbb {F}}_q^{m\times n}\) with the metric \({\tilde{D}}^{{\textrm{rk}}}(X,Y):={\textrm{rk}}(X-Y)\), for all \(X,Y \in {\mathbb {F}}_q^{m\times n}\), then a suitable vector space isomorphism from \(({\mathbb {F}}_{q^m}^n, D^{\textrm{rk}})\) to \(({\mathbb {F}}_q^{m\times n}, {\tilde{D}}^{{\textrm{rk}}})\) is also an isometry, see e.g. [14]. However, the linearity degree of a code is generally not preserved. In particular, the image of an \({\mathbb {F}}_{q^\ell }\)-linear code in \({\mathbb {F}}_{q^m}^{n}\) is “only” \({\mathbb {F}}_q\)-linear in \({\mathbb {F}}_q^{m\times n}\), for any \(1\le \ell \le m\). Nonetheless, for \(\ell \in \{0,1\}\), the set of \([{\mathbb {F}}_{q^m}^n, S, \ell , d]^{\textrm{rk}}\)-codes is in one-to-one-correspondence with the set of \([{\mathbb {F}}_{q^n}^m, S, \ell , d]^{\textrm{rk}}\)-codes.Footnote 2

As usual, we denote a nonlinear code in \(({\mathbb {F}}_{q^m}^n, D^{{\textrm{rk}}})\) of cardinality S and minimum distance at least d as a \([{\mathbb {F}}_{q^m}^n,S,0,d]^{{\textrm{rk}}}\)-code. If the code is also \({\mathbb {F}}_{q^\ell }\)-linear and then we say it is a \([{\mathbb {F}}_{q^m}^n,S,\ell ,d]^{{\textrm{rk}}}\)-code.

A rank-metric code cannot both have large dimension and minimum distance. The following result by Delsarte shows the relation between these two quantities.

Theorem 5.3

(Singleton-like bound; see [10, Theorem 5.4]) Let \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) be a rank-metric code. We have \(|{\mathcal {C}}| \le q^{\max \{n,m\}(\min \{n,m\}-D^{{\textrm{rk}}}({\mathcal {C}})+1)}.\)

We call a rank-metric code meeting the bound in Theorem 5.3 with equality an MRD (maximum rank distance) code.

Remark 5.4

Let \(\ell \) be a divisor of m and let \(s=[{\mathbb {F}}_{q^{m}}:{\mathbb {F}}_{q^{\ell }}]\). The dimension over \({\mathbb {F}}_q\) of any \({\mathbb {F}}_{q^\ell }\)-linear rank-metric code \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^{\ell s}}^n\) has to be divisible by \(\ell \). In particular, if the dimension of \({\mathcal {C}}\) is k over \({\mathbb {F}}_{q^\ell }\) where \(0 \le k \le ns\) and \(d=D^{{\textrm{rk}}}({\mathcal {C}})\), then from the bound in Theorem 5.3, it follows

$$\begin{aligned} \ell k \le \max \{n,\ell s\}(\min \{n,\ell s\}-d+1). \end{aligned}$$
(5.1)

If \(\ell s \le n\), then the largest integer k that satisfies (5.1) is

$$\begin{aligned} k^{*}=\left\lfloor \frac{n(\ell s -d+1)}{\ell }\right\rfloor . \end{aligned}$$
(5.2)

Clearly, codes attaining the largest possible dimension \(k^*\) in (5.2) are not necessarily MRD (it depends on whether or not the fraction on the RHS of (5.2) evaluated for the parameters of the considered code is an integer or not). If a code attains this bound with equality but is not MRD, then it is called a quasi-MRD code.

In order to make use of the results in Sects. 2 and 3 we need the volume of the ball in the rank metric and its asymptotic estimates. The volume of the rank-metric ball of radius r is given by

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,r):= \sum _{i=0}^r \left[ \begin{matrix} n \\ i \end{matrix}\right] _{q} \prod _{j=0}^{i-1}(q^{m}-q^{j}) \end{aligned}$$
(5.3)

for any \(0 \le r \le \min \{n,m\}\); see for example [11].

As we are mainly interested in asymptotic results we need the following lemma, which states the well-known asymptotic estimates of the rank-metric ball as \(q \rightarrow +\infty \), as \(m \rightarrow +\infty \) and as \(n \rightarrow +\infty \).

Lemma 5.5

The following estimates hold.

  1. (i)

    Let \(0 \le r \le \min \{n,m\}\). We have \({{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,r) \sim q^{r(m+n-r)}\) as \(q \rightarrow +\infty \).

  2. (ii)

    Let \(0 \le r \le n\). We have \({{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,r) \sim \left[ \begin{matrix} n \\ r \end{matrix}\right] _{q}q^{rm}\) as \(m \rightarrow +\infty \).

  3. (iii)

    Let \(0 \le r \le m\). We have \({{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,r) \sim \left[ \begin{matrix} m \\ r \end{matrix}\right] _{q}q^{rn}\) as \(n \rightarrow +\infty \).

6.1 Nonlinear MRD codes

In this short subsection we investigate the density of (possibly nonlinear) MRD codes both as \(q \rightarrow +\infty \) and \(n \rightarrow +\infty \).

Note that by Remark 5.2 computing the asymptotic densities for \(n \rightarrow +\infty \) and \(m \rightarrow +\infty \) for nonlinear MRD codes in \({\mathbb {F}}_{q^m}^n\) are the same (up to transposition) and thus we will only treat the case where \(n \rightarrow +\infty \) in this subsection.

In the following theorem we provide asymptotic results on the density function of nonlinear MRD codes both as \(q \rightarrow +\infty \) and \(n \rightarrow +\infty \).

Theorem 5.6

Let \(2 \le d\) be an integer.

  1. (i)

    Let \(2 \le m\) and \(2 \le n\) be integers. We have

    $$\begin{aligned} \lim _{q \rightarrow +\infty }\delta _q^{{\textrm{rk}}} ({\mathbb {F}}_{q^m}^n, q^{\max \{n,m\}(\min \{n,m\}-d+1)},0,d) =0. \end{aligned}$$
  2. (ii)

    Let \(2 \le m\) be an integer and suppose that \(d \le m\). We have

    $$\begin{aligned} \lim _{n \rightarrow +\infty }\delta _q^{{\textrm{rk}}} ({\mathbb {F}}_{q^m}^n, q^{n(m-d+1)},0,d) =0. \end{aligned}$$

Thus, nonlinear MRD codes are sparse both as \(q \rightarrow +\infty \) and as \(n \rightarrow +\infty \).

Proof

From the estimate given in Lemma 5.5 we get

$$\begin{aligned}&\lim _{q \rightarrow +\infty } \frac{q^{mn}}{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,d-1)q^{2\max \{n,m\}(\min \{n,m\}-d+1)}}\\&\quad = \lim _{q \rightarrow +\infty } \frac{1}{q^{(d-1)(m+n+2\max \{n,m\}-d+1)+mn}} = 0 \end{aligned}$$

which by Theorem 3.1 proves the first result.

Similarly, we have

$$\begin{aligned} \lim _{n \rightarrow +\infty } \frac{q^{mn}}{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^m}^n,d-1)q^{2n(m-d+1)}} = \lim _{n \rightarrow +\infty } \frac{1}{\left[ \begin{matrix} m \\ d-1 \end{matrix}\right] _{q}q^{n(m-d+1)}} =0 \end{aligned}$$

where we used the asymptotic estimate for \(n \rightarrow +\infty \) in Lemma 5.5. The second statement in the theorem is then a consequence of Theorem 3.2. \(\square \)

6.2 (Sub)linear MRD codes

The problem of determining whether (\({\mathbb {F}}_q\)-linear and \({\mathbb {F}}_{q^m}\)-linear) MRD codes are dense or sparse has been studied before and we start this subsection by revisiting the results and their approaches that have been developed so far (see e.g. [1, 6, 13, 16,17,18]), one of which is the application of the results presented in Sect. 2. We give a short recap of some of the results obtained with the other approaches in the language of this paper.

In [16] it was shown that \([{\mathbb {F}}_{q^m}^n,q^{m(n-d+1)},1,d]\)-MRD codes are sparse as \(q \rightarrow +\infty \) unless \(d=1\) or \(n=d=2\). Together with a result from [1], where they computed the exact asymptotic density for when \(n=d=2\) using the theory of spectrum-free matrices, the density question for \({\mathbb {F}}_q\)-linear MRD codes as \(q\rightarrow +\infty \) is fully solved. Moreover, in [13], for the case where \(m=n=d=3\), an exact asymptotic estimate as for the density function of \([{\mathbb {F}}_{q^m}^n,q^{m(n-d+1)},1,d]\)-MRD codes \(q \rightarrow +\infty \) was provided. This result was later generalized in [17] for any \(m=n=d\) that are prime.

Both the approach of [13] and the one of [17] are based on the connection between full-rank MRD codes and semifields.

Finally, using the Schwartz–Zippel Lemma, in [18] it was shown that \({\mathbb {F}}_{q^m}\)-linear MRD codes are dense as \(m \rightarrow +\infty \). For \({\mathbb {F}}_q\)-linear MRD codes it has only been shown that they are not dense as \(m \rightarrow +\infty \) (see [1, 6, 16]). Whether they are sparse or not is to this day still an open question.

As the density of MRD codes has already been investigated rather thoroughly, in this subsection we will just close the gap by discussing the remaining asymptotic density results. We start by looking at the (sub)linear case for the field size q tending to infinity. As explained in Remark 5.4, when \(\ell s < n\), then the codes of maximum possible dimension are not necessarily MRD codes. For this reason, the following theorem is split into two parts.

Theorem 5.7

Let n, \(\ell \) and s be positive integers and let \(2 \le d \le n\).

  1. (i)

    If \(n \le \ell s\) then we have

    $$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, (d-1)(n-d+1)< \ell , \\ 0 \quad &{}{\textrm{if}}\, \ell < (d-1)(n-d+1). \end{array}\right. } \end{aligned}$$

    Moreover, if \(\ell = (d-1)(n-d+1)\) then \(\lim _{q \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d) \le 1/2\).

  2. (ii)

    If \(\ell s < n\) then we have

    $$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, (d-1)(\ell s -d+1)+r< \ell , \\ 0 \quad &{}{\textrm{if}}\, \ell < (d-1)(\ell s -d+1)+r. \end{array}\right. } \end{aligned}$$

    where \(k:=\lfloor n(\ell s-d+1)/\ell \rfloor \) and \(r:=n(d-1)-\ell \lceil n(d-1)/\ell \rceil \). Moreover, if \(\ell = (d-1)(\ell s -d+1)+r\) then \(\lim _{q \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k},\ell ,d) \le 1/2\).

Proof

For the first part of the theorem, note that we have

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)q^{\ell s (n-d+1)}}{q^{\ell (ns+1)}}= \lim _{q \rightarrow +\infty } q^{(d-1)(n-d+1)-\ell } = 0 \end{aligned}$$

if and only if \((d-1)(n-d+1) < \ell \). On the other hand,

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{q^{\ell (ns+1)}}{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)q^{\ell s (n-d+1)}}= \lim _{q \rightarrow +\infty } \frac{1}{q^{(d-1)(n-d+1)-\ell }} = 0 \end{aligned}$$

if and only if \(\ell < (d-1)(n-d+1)\). Finally, the case \(\ell = (d-1)(n-d+1)\) is another easy application of Theorem 3.5.

To prove the second part of the theorem, we proceed analogously to the arguments for the first part, where we additionally use the fact that \(k = \lfloor { n(\ell s-d+1)}/{\ell }\rfloor = ns-\lceil n(d-1)/\ell \rceil \). \(\square \)

We now turn to the question if \({\mathbb {F}}_{q^{\ell }}\)-linear MRD codes in \({\mathbb {F}}_{q^{\ell s}}^n\) are dense or sparse as \(\ell \), s and n tend to infinity.

Recall that in [18] it was shown that \({\mathbb {F}}_{q^m}\)-linear MRD codes are dense as \(m \rightarrow +\infty \). The following result generalizes this fact, and shows that also \({\mathbb {F}}_{q^\ell }\)-linear MRD codes in \({\mathbb {F}}_{q^{\ell s }}^n\) are dense as \(\ell \rightarrow +\infty \).

Theorem 5.8

Let \(q \in Q\) and suppose that \(3 \le n\) and \(1 \le \ell ,d\) are integers with \(1 \le d \le n\). Then

$$\begin{aligned} \lim _{\ell \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{ \ell s(n-d+1)},\ell ,d)= 1, \end{aligned}$$

i.e., \({\mathbb {F}}_{q^\ell }\)-linear MRD codes in \({\mathbb {F}}_{q^{\ell s }}^n\) are dense as \(\ell \rightarrow +\infty \).

Proof

By (5.3) we have

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \sim \left[ \begin{matrix} n \\ d-1 \end{matrix}\right] _{q}q^{(d-1)\ell s} \quad {\textrm{as}}\, \ell \rightarrow +\infty . \end{aligned}$$

Therefore \(q^{\ell s(n-d+1)} \in o\left( {q^{\ell (ns-1)}}/{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}\right) \) as \(\ell \rightarrow +\infty \), and Theorem 3.6 concludes the proof. \(\square \)

Theorem 5.9

Let \(q \in Q\) and suppose that \(3 \le n\) and \(1 \le \ell ,d\) are integers with \(2 \le d \le n\). Then

$$\begin{aligned} \limsup _{s \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell s(n-d+1)},\ell ,d) \le \frac{q^\ell }{q^\ell +\left[ \begin{matrix} n \\ d-1 \end{matrix}\right] _{q}} < 1. \end{aligned}$$

Proof

We will apply Theorem 3.8 for proving the statement. First note that by (5.3) we have

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1) \sim \left[ \begin{matrix} n \\ d-1 \end{matrix}\right] _{q}q^{(d-1)\ell s} \quad {\textrm{as}}\, s \rightarrow +\infty . \end{aligned}$$

In particular, we have

$$\begin{aligned} 1- \frac{{{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}{q^{\ell (ns-s(n-d+1)+1)} + {{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}&= \frac{q^{\ell (s(d-1)+1)}}{q^{\ell (s(d-1)+1)} + {{\textbf {v}}}_{q}^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,d-1)}\\ {}&\sim \frac{q^\ell }{q^\ell +\left[ \begin{matrix} n \\ d-1 \end{matrix}\right] _{q}} \end{aligned}$$

as \(s \rightarrow +\infty \), which proves the theorem. \(\square \)

We now investigate the density of codes in \({\mathbb {F}}_{q^{\ell s}}^n\) as their vector length n tends to infinity. Recall again that by Remark 5.4, in this setting, codes of the largest possible dimension are not necessarily MRD.

Theorem 5.10

Let \(q \in Q\), let \(1 \le \ell ,s\) be integers and fix \(2 \le d \le \ell s\). We have

$$\begin{aligned} \limsup _{n \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k(n)},\ell ,d) \le \frac{1}{1+\left[ \begin{matrix} m \\ d-1 \end{matrix}\right] _{q}q^{-2\ell }} < 1, \end{aligned}$$

where \(k(n):=\lfloor { n(\ell s-d+1)}/{\ell }\rfloor \) for all \(2 \le n\).

Proof

Applying Theorem 3.7 and the asymptotic estimate as \(n \rightarrow +\infty \) we get

$$\begin{aligned} \limsup _{n \rightarrow +\infty } \delta _q^{{\textrm{rk}}}({\mathbb {F}}_{q^{\ell s}}^n,q^{\ell k(n)},\ell ,d) \le \limsup _{n \rightarrow +\infty } \frac{1}{1+\left[ \begin{matrix} m \\ d-1 \end{matrix}\right] _{q}q^{n(d-1)-\ell \lceil n(d-1)/\ell \rceil -\ell }}, \end{aligned}$$
(5.4)

where we used that \(k(n) = \lfloor { n(\ell s-d+1)}/{\ell }\rfloor = ns-\lceil n(d-1)/\ell \rceil \). Since \(0 \le \ell \lceil n(d-1)/\ell \rceil -n(d-1) \le \ell \) we infer the statement in the theorem. \(\square \)

Recall that by Remark 5.2 there is a one-to-one correspondence between \({\mathbb {F}}_q\)-linear MRD codes in \({\mathbb {F}}_{q^m}^n\), and \({\mathbb {F}}_q\)-linear MRD codes in \({\mathbb {F}}_{q^n}^m\). Therefore, for \(\ell =1\), the upper bound for the density as \(m \rightarrow +\infty \) in Theorem 5.9 and the upper bound for the density as \(n \rightarrow +\infty \) in (5.4) are the same (up to exchanging n and m).Footnote 3

7 Application III: codes in the sum-rank metric

In the scope of this paper, we only investigate sum-rank-metric codes \({\mathcal {C}}\) in \({\mathbb {F}}_{q^m}^n\) that consist of block vectors \([x_1 | \dots | x_t]^\top \in {\mathbb {F}}_{q^m}^n\), where all blocks have equal size such that \(x_i \in {\mathbb {F}}_{q^m}^{\eta }\) for all \(i \in [t]\) and \(n=\eta t\). We define the sum-rank weight and sum-rank distance as follows.

Definition 6.1

Let \(x = [x_1 | \dots | x_t]^\top \in {\mathbb {F}}_{q^m}^n\). The (t-)sum-rank weight of x is \( \omega ^{sr,t}(x)\) where \( \omega ^{{\textrm{sr,t}}}\) is the function defined as

$$\begin{aligned} \omega ^{{\textrm{sr,t}}}: {\mathbb {F}}_{q^m}^n \rightarrow {\mathbb {N}}, \, x \mapsto \sum _{i=1}^{t}\omega ^{{\textrm{rk}}}(x_{i}), \end{aligned}$$

where \(\omega ^{{\textrm{rk}}}(x_{i}):= \dim _{{\mathbb {F}}_{q}}\langle x_{i,1}, \dots ,x_{i,\eta } \rangle \) denotes the dimension of the \({\mathbb {F}}_{q}\)-span of the entries of \(x_{i}\). For vectors \(x,y \in {\mathbb {F}}_{q^m}^n\) the (t-)sum-rank distance is \(D^{{\textrm{sr,t}}}(x,y):=\omega ^{{\textrm{sr,t}}}(x-y)\).

Note that we clearly have that \(\omega ^{{\textrm{rk}}}(x_{i}) \le \min \{m,\eta \}\) for \(x_i \in {\mathbb {F}}_{q^m}^{\eta }\). As usual, if \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) is an \({\mathbb {F}}_{q^{\ell }}\)-linear subspace of dimension k and minimum distance at least d we say that \({\mathcal {C}}\) is a \([{\mathbb {F}}_{q^m}^n,q^{\ell k},\ell ,d]^{{\textrm{sr,t}}}\)-code, and if it is (possibly) nonlinear and has cardinality S, we say it is a \([{\mathbb {F}}_{q^m}^n,S,0,d]^{{\textrm{sr,t}}}\)-code.

Remark 6.2

Note that if we set \(\eta =1\) in Definition 6.1, then the sum-rank weight of a vector \(x \in {\mathbb {F}}_{q^m}^n\) is the number of nonzero entries of x, and thus it reduces to the Hamming metric. On the other hand, if \(t=1\) then it is easy to see that the sum-rank weight of a vector is the standard rank weight. Therefore, codes in the Hamming metric and codes in the rank metric can be seen as special instances of codes in the sum-rank metric.

Theorem 6.3

(Singleton-type bound; see [7, Theorem 3.2]) Let \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^m}^n\) be a code in the sum-rank metric. Then the cardinality of \({\mathcal {C}}\) is upper bounded by

$$\begin{aligned} |{\mathcal {C}}| \le q^{\max \{m, \eta \}(t\min \{m,\eta \}-d+1)}. \end{aligned}$$
(6.1)

A sum-rank-metric code is called MSRD (maximum sum-rank distance) code if its cardinality meets the Singleton-type bound in Theorem 6.3 with equality.

Remark 6.4

Let \(\ell \) be a divisor of m and let \(s=[{\mathbb {F}}_{q^{m}}:{\mathbb {F}}_{q^{\ell }}]\). The \({\mathbb {F}}_q\)-dimension of any \({\mathbb {F}}_{q^\ell }\)-linear sum-rank-metric code \({\mathcal {C}}\subseteq {\mathbb {F}}_{q^{\ell s}}^n\) has to be divisible by \(\ell \). In particular, if \(\dim _{{\mathbb {F}}_{q^{\ell }}}({\mathcal {C}})=k\), where \(0 \le k \le ns\), then from the bound in Equation (6.1), we have

$$\begin{aligned} \ell k \le \max \{\ell s, \eta \}(t\min \{\ell s ,\eta \}-d+1), \end{aligned}$$
(6.2)

where \(d=D^{{\textrm{rk}}}({\mathcal {C}})\). If \(\ell s \le \eta \), then the largest integer k that satisfies (6.2) is

$$\begin{aligned} k^{*}:=\left\lfloor \frac{\eta (\ell s t -d+1)}{\ell }\right\rfloor . \end{aligned}$$

Clearly, a code \({\mathcal {C}}\) with \(\dim _{{\mathbb {F}}_{q^{\ell }}}({\mathcal {C}})= k^{*}\) is not necessarily MSRD. A code \({\mathcal {C}}\) with \(\dim _{{\mathbb {F}}_{q^{\ell }}}({\mathcal {C}})= k^{*}\) that does not attain the Singleton bound with equality is called a quasi-MSRD code.

In what follows, we define the set of all possible partitions of a number r into exactly t parts by \(U_{r}\), where each part is upper bounded by \(\min \{m,\eta \}\). This set of partitions will be needed for giving the volume of the sum-rank-metric ball.

Notation 6.5

Let \(2 \le n\) and \(0 \le r \le t \min \{m,\eta \}\). Suppose that \(1 \le t\) is an integer and let \(n = \eta t\). We define

$$\begin{aligned} U_{r}:= \left\{ u=(u_{1}, \dots , u_{t}) \in {\mathbb {N}}_{0}^{t} \bigm |\, \sum _{i=1}^{t}u_{i}=r, u_{i} \le \min \{m,\eta \} \,{\textrm{for all }}\, i \in [t] \right\} . \end{aligned}$$

The following lemma gives a closed formula for the volume of the sum-rank-metric ball of a given radius.

Lemma 6.6

[7] Let \(0 \le r \le t\min \{m,\eta \}\). We have

The following lemma gives the asymptotic estimates of the volume of the sum-rank-metric ball as q goes to infinity (and the other parameters are treated as constants).

Lemma 6.7

Let t be a divisor of n, let \(\eta = \frac{n}{t}\) and let \(0 \le r \le t\min \{m,\eta \}\). We have

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^m}^n, r) \sim \left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) q^{\frac{{\tilde{z}}^2}{t}-{\tilde{z}}+r(m+\eta -\frac{r}{t})} \quad {\textrm{as}}\, q \rightarrow +\infty , \end{aligned}$$

where \({\tilde{z}} \equiv r \pmod t\).

Proof

Note that for any \(u = (u_1,\dots ,u_t) \in U_{h}\) we have

$$\begin{aligned} \prod _{i=1}^t \left[ \begin{matrix} \eta \\ u_i \end{matrix}\right] _{q} \prod _{j=0}^{u_i-1} (q^m-q^j) \sim q^{\sum _{i=1}^t u_i(m+\eta -u_i)} = q^{h(\eta +m)-\sum _{i=1}^t u_{i}^{2}} \quad {\textrm{as }} q \rightarrow +\infty . \end{aligned}$$

Let \(z \equiv h \pmod t\). Using Lagrange multipliers one sees that the maximum of the real-valued function \(f:{\mathbb {R}}^t \rightarrow {\mathbb {R}}, \, f: (x_1, \dots , x_t) \mapsto -\sum _{i=1}^t x_{i}^{2}\) in the region of \({\mathbb {R}}^t\) constrained by

$$\begin{aligned} \sum _{i=1}^t x_i = h, \quad 0 \le x_i \le \eta \,{\textrm{for all }}\, i \in \{1, \dots , t\} \end{aligned}$$

is attained for \(x^{*} \in {\mathbb {R}}^t\) with \(x^{*}_{1} = \dots = x^{*}_{t}= \frac{h}{t}\). Note that f is concave in all t variables, hence the integer partition \(u \in U_{h}\) where f reaches its maximum is \(u^{*}= (u^{*}_{1},\dots ,u^{*}_{t})\) with \(u^{*}_{1} = \dots = u^{*}_{i_{z}}= \lfloor \frac{h}{t} \rfloor +1\) and \(u^{*}_{k}=\lfloor \frac{h}{t} \rfloor \) where \(k \in [t]{\setminus } \{i_{1}, \dots ,i_{z} \}\). This gives

$$\begin{aligned} \max _{u \in U_{h}}\left( -\sum _{i=1}^t u_{i}^{2} \right)&= -z\left( \left\lfloor \frac{h}{t} \right\rfloor +1\right) ^{2}-(t-z)\left\lfloor \frac{h}{t} \right\rfloor ^{2}\\&=- 2\left\lfloor \frac{h}{t} \right\rfloor z- \left\lfloor \frac{h}{t} \right\rfloor ^{2}t-z \\&= -\left\lfloor \frac{h}{t} \right\rfloor (z+h)-z\\&= -\frac{(h-z)(h+z)}{t}-z = -\frac{h^{2}-z^{2}}{t}-z. \end{aligned}$$

Hence

Write \(p(h) = h(mt+n-h)\) as a polynomial in h with roots at \(h=0\), \(h=mt+n\) and a maximum at \(h^{*}= \frac{mt+n}{2}\). Note that p is monotonically increasing on \(\left[ 0, \frac{mt+n}{2}\right) \). For \(h \le r \le t\min \{\eta ,m\}\) we have

$$\begin{aligned} h \le r \le \frac{mt+n}{2}, \end{aligned}$$

from which we can conclude that

$$\begin{aligned} {{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^m}^n, r) \sim \left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) q^{\frac{{\tilde{z}}}{t}-{\tilde{z}}+r(m+\eta -\frac{r}{t}) }, \end{aligned}$$

where \({\tilde{z}} \equiv r \pmod t\). \(\square \)

As we saw in Remark 6.2, both the Hamming and the rank metric are special instances of the sum-rank metric. By analyzing the asymptotic densities of (sub)linear codes in these two metrics, we can infer that their behavior differs, especially when looking at \(q \rightarrow +\infty \). This interesting fact motivates us to generalize and to analyze the asymptotic density as q tends to infinity in the sum-rank metric.

7.1 Nonlinear MSRD codes

We determine the sparsity of (possibly) nonlinear MSRD codes as \(q \rightarrow +\infty \).

Theorem 6.8

Let \(2 \le d\) and \(1 \le m,\eta \) be integers, let t be the number of blocks in the sum-rank metric and let \(n=\eta t\). Then we have

$$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n,q^{\max \{m,\eta \}(t\min \{m,\eta \}-d+1)},0,d)= 0, \end{aligned}$$

i.e., nonlinear MSRD codes are sparse as \(q \rightarrow +\infty \).

Proof

By Lemma 6.7 we have

$$\begin{aligned} 0 \le \lim _{q \rightarrow +\infty } \frac{q^{mn}}{{{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^m}^n,d-1)q^{2\max \{m,\eta \}(t\min \{m,\eta \}-d+1)}}\le \lim _{q \rightarrow +\infty } \frac{1}{q^{(d-1)(3\max \{m,\eta \})}}=0 \end{aligned}$$

and Theorem 3.1 proves the statement. \(\square \)

7.2 (Sub)linear MSRD codes

Note that if \(\ell s < \eta \), then the codes of maximum possible dimension are not necessarily MSRD codes (see also Remark 6.4). Due to this reason we consider the two cases \(\ell s < \eta \) and \(\eta \le \ell s\) separately.

Theorem 6.9

Let \(\eta , \ell , s, t,d\) be positive integers such that \(1<t<n\) and \(2 \le d \le t\min \{m,\eta \}\). Let \(n = \eta t\) and \({\tilde{z}} \equiv d-1 \pmod t\). Then define \(\theta := (d-1)\left( \min \{m, \eta \} - \frac{d-1}{t} \right) +\frac{{\tilde{z}}^{2}}{t}-{\tilde{z}}\).

  1. (i)

    If \(\eta \le m\) then we have

    $$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if }}\, \theta< \ell , \\ 0 \quad &{}{\textrm{if }}\, \ell < \theta . \end{array}\right. } \end{aligned}$$

    Moreover if \(\theta = \ell \) then \( \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n,q^{m(n-d+1)},\ell ,d) \le \frac{1}{1+\left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) }.\)

  2. (ii)

    If \(m < \eta \) then we have

    $$\begin{aligned} \lim _{q \rightarrow +\infty } \delta _q^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if }}\, \theta -r< \ell , \\ 0 \quad &{}{\textrm{if }}\, \ell < \theta -r. \end{array}\right. } \end{aligned}$$

    Moreover, if \(\theta -r = \ell \) then \(\lim _{q \rightarrow +\infty } \delta _q^{\textrm{sr,t}}({\mathbb {F}}_{q^{m}}^n,q^{\ell k},\ell ,d) \le \frac{1}{1+\left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) }\),

    where \(k= \left\lfloor \frac{\eta (m t -d+1)}{\ell } \right\rfloor \) and \(r = \ell \left( \left\lceil \llceil \frac{\eta (d-1)}{\ell } \right\rceil \rrceil - \frac{\eta (d-1)}{\ell }\right) \).

Proof

By Lemma 6.7 we have for the first part of the theorem

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{ {{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n, d-1)q^{m(\eta t -d+1)}}{q^{\ell (ns+1)}} = \lim _{q \rightarrow + \infty }\frac{\left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) q^{(d-1)(\eta -\frac{d-1}{t})+\frac{{\tilde{z}}^{2}}{t}-{\tilde{z}}}}{q^{\ell }} =0, \end{aligned}$$

if and only if \(\theta < \ell \). On the other hand

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{q^{\ell (ns+1)}}{{{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n, d-1)q^{m(\eta t -d+1)}} = \lim _{q \rightarrow + \infty }\frac{1}{\left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) q^{(d-1)(\eta -\frac{d-1}{t})+\frac{{\tilde{z}}^{2}}{t}-{\tilde{z}}-\ell }} =0, \end{aligned}$$

if and only if \(\ell < \theta \). Finally, for \(\ell = \theta \) we obtain

$$\begin{aligned} \lim _{q \rightarrow +\infty } \frac{ {{\textbf {v}}}_{q}^{{\textrm{sr,t}}}({\mathbb {F}}_{q^{m}}^n, d-1)q^{m(\eta t -d+1)}}{q^{\ell (ns+1)}} = \left( {\begin{array}{c}t\\ {\tilde{z}}\end{array}}\right) , \end{aligned}$$

and the third case is another easy consequence of Theorem 3.5.

To prove the second part of the theorem, we proceed analogously to the arguments for the first part, where we additionally use the fact that \(k = \lfloor { \eta (\ell s t-d+1)}/{\ell }\rfloor = ns-\lceil \eta (d-1)/\ell \rceil \). \(\square \)

As the density of \({\mathbb {F}}_{q}\)-linear codes in the Hamming metric and rank metric has been studied pretty thoroughly, we will conclude this section by taking a closer look at their counterparts in the sum-rank metric.

Theorem 6.10

Let \(\eta \le m\) and \(2 \le d \le n\) be integers. We have

$$\begin{aligned} \lim _{q \rightarrow +\infty }\delta _q^{\textrm{sr,t}}({\mathbb {F}}_{q^{m}}^n,q^{m( n-d+1)},1,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, (d-1)(n-d+1)< t, \\ 0 \quad &{}{\textrm{if}}\, t+t^2/4 < (d-1)(n-d+1). \end{array}\right. } \end{aligned}$$

Proof

Note that, using simple methods from Calculus, one can show that

$$\begin{aligned} -t/4 \le \frac{({\tilde{z}})^2}{t}-{\tilde{z}} \le 0, \end{aligned}$$

where \({\tilde{z}} \equiv d-1 \pmod t\). Combining this with Theorem 6.9, where we set \(\ell =1\) and use the fact that \(\eta \le m\) concludes the proof. \(\square \)

From the assumption \(2 \le d \le n\) in Theorem 6.10 we get

$$\begin{aligned} (d-1)(n-d+1) \in \left\{ (n-1), \dots , \left\lfloor \frac{n^{2}}{4}\right\rfloor \right\} . \end{aligned}$$

This gives us a further characterization (see Corollary 6.11 and Fig. 1 below) of sum-rank-metric codes from which we can extract all values of block length \(\eta \), where we observe a sparse behaviour as \(q \rightarrow +\infty \).

Corollary 6.11

Let \(\eta \le m\) and \(2 \le d \le n\) be integers. We have

$$\begin{aligned} \lim _{q \rightarrow +\infty }\delta _q^{\textrm{sr,t}}({\mathbb {F}}_{q^{m}}^n,q^{m( n-d+1)},1,d) = {\left\{ \begin{array}{ll} 1 \quad &{}{\textrm{if}}\, \eta< 2/\sqrt{t}\\ 0 \quad &{}{\textrm{if}}\, \frac{(t+2)^{2}}{4t} < \eta . \end{array}\right. } \end{aligned}$$
Fig. 1
figure 1

Block size \(\eta \) depending on t to fully characterize the asymptotic density of \({\mathbb {F}}_{q}\)-linear MSRD codes as \(q \rightarrow +\infty \). The green dots above the red line represent sets of parameters for which MSRD codes are sparse in \({\mathbb {F}}_{q^{m}}^{\eta t}\), whereas those below the blue line indicate a dense behaviour. The black dots represent sets of parameters for which the asymptotic behaviour of the density is unknown, or as in the case of \(t=1\) and \(\eta =2\) can not be classified as asymptotically dense or sparse

Remark 6.12

Recall from Remark 6.2 that codes in the Hamming metric and codes in the rank metric are subfamilies of sum-rank-metric codes. It is interesting to observe that these two classes of codes behave very differently with respect to density considerations as \(q \rightarrow +\infty \). More explicitly, in Sect. 4 we saw that \({\mathbb {F}}_q\)-linear MDS codes are dense as \(q \rightarrow +\infty \). This is in stark contrast with the behavior of \({\mathbb {F}}_q\)-linear MRD codes: they are sparse as \(q \rightarrow +\infty \) (see Sect. 5). Even though there does not seem to be an obvious way to fully characterize for which values of \(\eta , t\) and d we have sparsity or density (or non-density) of the corresponding codes, experimental results strongly indicate that, in general, sum-rank-metric codes behave similarly to standard rank-metric codes, with an exception when \(\eta =1\) (which is the case of Hamming-metric codes). Therefore MDS codes behave rather atypical with respect to density considerations. We collect some examples of the asymptotic behavior of the density of sum-rank-metric codes in Table 1.

Table 1 Examples illustrating the asymptotic behavior of the density of \({\mathbb {F}}_q\)-linear sum-rank-metric codes as \(q \rightarrow +\infty \)

7.3 Conclusion and outlook

We developed a general framework for determining densities of codes over finite fields, equipped with an arbitrary translation-invariant metric, with any linearity degree. This unifies several previous results (which were mostly derived with different mathematical tools) on densities of linear and nonlinear codes in the Hamming, rank and sum-rank metric. Moreover, we established new results for codes in these three metrics, answering many of the open question in this field.

One general observation is that nonlinear codes achieving the Gilbert-Varshamov bound in any metric, or the Singleton-type bound in the sum-rank metric (including the Hamming and rank metric as special cases), are always sparse, for both the field size or the length going to infinity. However, in the (sub)linear case, the metric, the linearity degree and the parameter going to infinity make a difference. In some cases we get sparsity, in some density and in some cases we can only derive an upper bound on the asymptotic density, showing that the code family is not dense (but we do not know if they are sparse).

As a particular case of interest we studied the asymptotic behavior of MSRD codes for \(q\rightarrow +\infty \), since MSRD codes generalize both the Hamming, as well as the rank metric. We derived bounds on the number of blocks for \({\mathbb {F}}_{q}\)-linear MSRD codes to be dense or sparse. As explained in Remark 6.12, the only case where MSRD codes are dense is when they are MDS codes. In all other cases we either get sparsity or an upper bound below 1 for the density.

There are still many open questions for future work. E.g., in all cases where we obtained upper bounds below 1 for the density, it is not clear if this bound is sharp or if there are sharper bounds, or if these code families are even sparse. Furthermore, we only presented the asymptotic densities of MSRD codes as the field size q tends to infinity. With similar techniques we can derive results for the other parameters going to infinity, however, it was out of the scope of this paper to include them here; in particular, since they become more difficult due to the vast number of variable parameters. Moreover, we restricted ourselves to MSRD codes where each block has the same length, and it remains an open problem to study the densities of such codes with different block lengths. Lastly, we will extend our framework to other metric spaces and study the densities of codes over finite rings, equipped with the Hamming or the Lee metric.