January 01, 1970
Flag-rank-metric codes arise as a natural generalization of rank-metric codes in the context of network communication. While recent research has mainly focused on algebraic and structural properties of these codes, the combinatorial geometry underlying the flag-rank metric remains largely unexplored. In this paper, we initiate a detailed investigation of this geometry. We explicitly determine the size of spheres of small flag-rank radius in the space \(\mathrm{U}(n,\mathbb{F}_q)\) of upper triangular matrices over the finite field \(\mathbb{F}_q\), and consequently obtain formulas for the size of balls of radius at most \(3\). Using these enumerative results, we derive a sphere-packing bound for flag-rank-metric codes and introduce the notion of perfect codes with respect to the flag-rank metric. We observe that no non-trivial perfect flag-rank-metric codes exist in \(\mathrm{U}(n,\mathbb{F}_q)\) for \(n\in\{2,3\}\). We then investigate the possible parameters of perfect codes in higher dimensions. For minimum distance \(3\), we obtain a characterization in terms of the codimension of the code, and show that suitable maximum flag-rank distance codes with minimum distance \(3\) yield non-trivial perfect codes. For minimum distances \(5\) and \(7\), we derive explicit quadratic and cubic conditions, respectively, that any perfect code must satisfy. Finally, using asymptotic estimates for balls of fixed radius, we prove that for fixed length \(n\) and \(\delta\in\{3,5,7,9,11\}\), perfect linear flag-rank-metric codes with minimum distance \(\delta\) do not exist over \(\mathbb{F}_q\) for all sufficiently large \(q\).
Keywords: Flag-rank metric; perfect code; sphere-packing bound.
MSC2020: Primary 94B65; Secondary 94B05, 94B25, 94B60, 05B25.
Network coding as a communication technique was introduced in the seminal work of Ahlswede, Cai, Li and Yeung [1], where intermediate nodes are allowed to combine incoming messages before forwarding them. This paradigm can substantially improve throughput, robustness, and latency in multicast networks. A major algebraic model for this framework was developed by Kötter and Kschischang [2], who proposed to encode information as vector subspaces of a finite-dimensional vector space. In this setting, a subspace code is a set of subspaces of \(\mathbb{F}^n\) equipped with the subspace distance, defined for every pair of subspaces \(U,V\subseteq \mathbb{F}^n\) as \[\mathrm{d}_{\mathrm S}(U,V)=\dim(U+V)-\dim(U\cap V).\] This metric models errors and erasures in random network coding. Subspace codes, and in particular constant-dimension codes, have been extensively studied; see, for instance, [3], [4] and the references therein.
A fruitful approach to the study of constant-dimension codes arises from the representation of the Grassmannian \(\mathrm{Gr}_k(\mathbb{F}^n)\) by reduced row echelon \(k\times n\) matrices of rank \(k\), modulo the natural action of \(\mathrm{GL}(k,\mathbb{F})\). This gives rise to a decomposition of the Grassmannian into Schubert cells. The largest cell consists of subspaces \(U_A\subseteq \mathbb{F}^n\) that admit a generator matrix of the form \((I_k\mid A)\), where \(A\in \mathrm{Mat}(k,n-k,\mathbb{F})\). On this cell, the subspace distance is twice the rank distance, namely \[\mathrm{d}_{\mathrm S}(U_A,U_B)=2\textrm{rk}(A-B).\] This observation creates a direct link between subspace coding and the theory of rank-metric codes, which has become a central topic in coding theory.
To overcome the restrictions imposed by constant-dimension codes, Liebhold, Nebe and Vázquez-Castro proposed the use of flag codes, whose codewords are chains of nested subspaces; see [5]. This idea has generated an active research area; see, for instance, [6]–[13]. Algebraically, full flags live in the flag variety \[\mathrm{Fl}(\mathbb{F}^{n+1}) = \{(U_1,\ldots,U_n)\mid U_1\subseteq\cdots\subseteq U_n,\;\dim(U_i)=i\},\] which admits a cell decomposition analogous to that of the Grassmannian. A degenerate version of the flag variety, denoted by \(\mathrm{Fl}^{(a)}(\mathbb{F}^{n+1})\), was introduced from a geometric perspective in [14] and studied from a linear algebraic viewpoint in [15]. Its relevance to coding theory was recognized in [16], where it was shown that the largest cell of \(\mathrm{Fl}^{(a)}(\mathbb{F}^{n+1})\) is isometric to the space \(\mathrm{U}(n,\mathbb{F})\) of \(n\times n\) upper triangular matrices over \(\mathbb{F}\), endowed with the flag-rank metric. This observation naturally leads to the notion of flag-rank-metric codes, which may be regarded as the flag analogue of rank-metric codes.
The study of flag-rank-metric codes was initiated by Fourier and Nebe in [16], where the first structural results and optimal constructions were obtained for specific parameter ranges. In [17], a general Singleton-like bound relating the codimension and the minimum flag-rank distance of codes was established, extending the result of Fourier and Nebe. Motivated by this bound, the authors introduced and studied maximum flag-rank-distance codes, or MFRD codes, that is, codes whose parameters attain equality in the Singleton-like bound. They also provided new constructions and classifications for small distance values, as well as general constructions based on MRD codes, MDS codes, and finite-geometric techniques.
In this paper, we focus on the combinatorial aspects of the flag-rank metric over the finite field \(\mathbb{F}_q\). More precisely, we study the sizes of spheres and balls in the metric space \(\mathrm{U}(n,\mathbb{F}_q)\). We denote by \(s_q(n,t)\) the size of the sphere of radius \(t\) centered at the zero matrix \(\boldsymbol{0}\) with respect to the flag-rank metric and by \(b_q(n,t)\) the size of the corresponding ball. We explicitly determine \(s_q(n,t)\) for \(t=0,1,2,3\), and consequently obtain closed formulas for \(b_q(n,t)\) for \(t\le3\).
Using these results, we derive a sphere-packing bound for flag-rank-metric codes. This allows us to introduce the notion of perfect codes in the flag-rank metric. We first prove that no non-trivial perfect flag-rank-metric codes exist in \(\mathrm{U}(n,\mathbb{F}_q)\) for \(n\in\{2,3\}\). We then investigate the numerical conditions imposed by the existence of perfect codes for larger parameters, and show, in particular, that no perfect codes exist for even minimum distance \(\delta\). For minimum distance \(\delta=3\), we obtain an exact characterization in terms of the codimension of the code. This condition also shows that MFRD codes of minimum distance \(3\) and length \(n=q^2+q+1\), when they exist, are perfect.
We further analyze perfect codes with larger minimum distance. For \(\delta=5\), we derive an explicit quadratic condition on the parameters, while for \(\delta=7\) we obtain an explicit cubic condition. These equations provide strong arithmetic restrictions on the possible existence of perfect flag-rank-metric codes. In particular, they yield obstructions and computational evidence excluding many possible parameter sets. We also obtain an asymptotic obstruction for perfect codes of fixed length. More precisely, for fixed \(n\) and fixed odd minimum distance \(\delta=2t+1\), we compare the asymptotic growth of the ball size with the codimension forced by the Singleton-like bound. This excludes perfect codes of fixed length for \(\delta\in\{3,5,7,9,11\}\) and all sufficiently large \(q\).
The paper is organized as follows. In Section 2, we recall the basic definitions and notation concerning flag-rank-metric codes. In Section 3, we compute the sizes of spheres and balls of small radius in \(\mathrm{U}(n,\mathbb{F}_q)\) and derive some general upper bounds. In Section 4, we prove the sphere-packing bound and introduce perfect flag-rank-metric codes. Finally, in Section 5, we study perfect codes, proving non-existence results in small dimensions, deriving necessary numerical conditions for larger minimum distances, and establishing an asymptotic nonexistence result for fixed length and growing field size. We draw some conclusions in Section 6.
This research was partially supported by Università Italo Francese (UIF/UFI) via PHC Galileo 2024 – G24-216. G. N. Alfarano is supported by the Agence Nationale de la Recherche through grant number ANR-24-CPJ1-0075-01. F. Zullo was partially supported by the Italian National Group for Algebraic and Geometric Structures and their Applications (GNSAGA - INdAM).
In this section, we recall the basic definitions and notation concerning flag-rank-metric codes. For a detailed treatment, we refer the interested reader to [5], [17].
Throughout the paper, we will use the following notation.
Let \(\mathbb{F}_q\) be the finite field with \(q\) elements. We denote by \(Mat(l,m,\mathbb{F}_q)\) the space of \(l\times m\) matrices with entries in \(\mathbb{F}_q\). Moreover, we denote by \(\mathrm{U}(n,\mathbb{F}_q)\) the space of upper triangular matrices in \(Mat(n,n,\mathbb{F}_q)\), that is, \[\mathrm{U}(n,\mathbb{F}_q)= \left\{ M=(m_{i,j})\in Mat(n,n,\mathbb{F}_q) \;:\; m_{i,j}=0 \text{ whenever } i>j \right\}.\] Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) and let \(1\le i\le n\). We denote by \(M_{[i]}\) the \(i\times(n-i+1)\) submatrix of \(M\) obtained by deleting the first \(i-1\) columns and the last \(n-i\) rows. Finally, we denote by \(\boldsymbol{0}\) the zero matrix.
We recall that \(\mathrm{U}(n,\mathbb{F}_q)\) is an \(\mathbb{F}_q\)-vector space of dimension \(\frac{n(n+1)}{2}\). We endow \(\mathrm{U}(n,\mathbb{F}_q)\) with the flag-rank distance, which is the metric induced by the flag-rank weight.
Definition 1. The flag-rank weight of a matrix \(M\in \mathrm{U}(n,\mathbb{F}_q)\) is defined as \[\mathrm{fr}(M):=\sum_{i=1}^{n}\textrm{rk}(M_{[i]}).\] The flag-rank distance on \(\mathrm{U}(n,\mathbb{F}_q)\) is the map \[\begin{array}{rccc} \mathrm{d}_{\mathrm{fr}}:& \mathrm{U}(n,\mathbb{F}_q)\times \mathrm{U}(n,\mathbb{F}_q) & \longrightarrow & \mathbb{N}_0 \\ & (A,B) & \longmapsto & \mathrm{fr}(A-B). \end{array}\]
Example 1. Let \[A= \begin{pmatrix} a & b\\ 0 & c \end{pmatrix} \in \mathrm{U}(2,\mathbb{F}_q).\] Then \[\mathrm{fr}(A)= \textrm{rk} \begin{pmatrix} a & b \end{pmatrix} + \textrm{rk} \begin{pmatrix} b\\ c \end{pmatrix}.\] Similarly, if \[B= \begin{pmatrix} a & b & c\\ 0 & d & e\\ 0 & 0 & f \end{pmatrix} \in \mathrm{U}(3,\mathbb{F}_q),\] then \[\mathrm{fr}(B) = \textrm{rk} \begin{pmatrix} a & b & c \end{pmatrix} + \textrm{rk} \begin{pmatrix} b & c\\ d & e \end{pmatrix} + \textrm{rk} \begin{pmatrix} c\\ e\\ f \end{pmatrix}.\]
Definition 2. A linear flag-rank-metric code \(\mathcal{C}\) is an \(\mathbb{F}_q\)-subspace of \(\mathrm{U}(n,\mathbb{F}_q)\) endowed with the flag-rank distance. The minimum flag-rank distance of \(\mathcal{C}\) is defined as \[\mathrm{d}_{\mathrm{fr}}(\mathcal{C}) := \min\{\mathrm{fr}(M) : M\in \mathcal{C}\setminus\{\boldsymbol{0}\}\}.\] If \(\dim_{\mathbb{F}_q}(\mathcal{C})=k\) and \(\mathrm{d}_{\mathrm{fr}}(\mathcal{C})=\delta\), then we say that \(\mathcal{C}\) is an \(\{n,k,\delta\}_{\mathbb{F}_q}\) flag-rank-metric code.
In [17] a Singleton-like bound for flag-rank-metric codes was proved. We recall it in terms of the codimension of the code.
Theorem 1 (Singleton-like bound). Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta\). Then \[\label{eq:sing-bound} \mathrm{codim}_{\mathbb{F}_q}(\mathcal{C}) \ge \delta-1 + \left\lfloor\sqrt{\delta-1}\right\rfloor \left\lfloor \frac{\sqrt{4(\delta-1)+1}-1}{2} \right\rfloor.\tag{1}\]
Definition 3. A linear flag-rank-metric code is called a maximum flag-rank-distance code, or simply an MFRD code, if its parameters attain the Singleton-like bound of Eq. 1 with equality.
The first examples of MFRD codes were obtained by Fourier and Nebe in [16], who constructed MFRD codes for \(\delta=\left\lceil \frac{n}{2} \right\rceil\cdot \left\lceil \frac{n+1}{2} \right\rceil\) when \(n\) is odd. In [17], this construction was extended to the case where \(n\) is even. Moreover, in [17], further families of MFRD codes were obtained for \(\delta=\left\lceil \frac{n}{2} \right\rceil\cdot \left\lceil \frac{n+1}{2} \right\rceil -1\) when \(n\) is odd. The same work also contains a classification of MFRD codes with \(\delta=2\), a characterization of MFRD codes with \(\delta=3\) via the notion of support-avoiding codes in the Hamming metric, and a construction of MFRD codes with \(\delta=4\) using auxiliary MDS codes in the Hamming metric and MRD codes in the rank metric. In particular, MFRD codes are known to exist for several values of the minimum flag-rank distance, but a complete existence theory is still not available.
We dedicate this section to the study of balls and spheres centered at matrices in \(\mathrm{U}(n,\mathbb{F}_q)\), with respect to the flag-rank metric. For a matrix \(M\in \mathrm{U}(n,\mathbb{F}_q)\), we define the flag-rank sphere of radius \(t\in\mathbb{N}_0\) centered at \(M\) as \[S(M,t)=\{N\in \mathrm{U}(n,\mathbb{F}_q): \mathrm{d}_{\mathrm{fr}}(N,M)=t\},\] and the flag-rank ball of radius \(t\in\mathbb{N}_0\) centered at \(M\) as \[B(M,t)=\{N\in \mathrm{U}(n,\mathbb{F}_q): \mathrm{d}_{\mathrm{fr}}(N,M)\le t\}.\] Clearly, \[B(M,t)=\bigcup_{i=0}^{t}S(M,i).\] Since \(\mathrm{d}_{\mathrm{fr}}(N,M)=\mathrm{fr}(N-M)\), the size of balls and spheres does not depend on their center. Hence, throughout this section, we use the following notation: \[s_q(n,t):=|S(\boldsymbol{0},t)| = \left|\{A\in \mathrm{U}(n,\mathbb{F}_q):\mathrm{fr}(A)=t\}\right|,\] and \[b_q(n,t):=|B(\boldsymbol{0},t)| = \left|\{A\in \mathrm{U}(n,\mathbb{F}_q):\mathrm{fr}(A)\le t\}\right|.\] Thus \[b_q(n,t)=\sum_{i=0}^{t}s_q(n,i).\] In particular, determining the sizes of balls amounts to determining the values of \(s_q(n,i)\).
We first observe that, for every \(n\in\mathbb{N}\), the only matrix in \(\mathrm{U}(n,\mathbb{F}_q)\) having flag-rank weight equal to zero is the zero matrix \(\boldsymbol{0}\). Therefore, \(s_q(n,0)=1\).
In the following, we determine the number of matrices of flag-rank weight \(1\), \(2\), and \(3\).
Proposition 2. Let \(M=(a_{i,j})\in \mathrm{U}(n,\mathbb{F}_q)\). Then \(\mathrm{fr}(M)=1\) if and only if \(M\) is diagonal and has exactly one nonzero diagonal entry. In particular, \(s_q(n,1)=n(q-1)\).
Proof. Assume first that \(\mathrm{fr}(M)=1\). Suppose that \(a_{i,j}\neq0\) for some \(i<j\). Then the entry \(a_{i,j}\) appears in each of the submatrices \(M_{[i]},M_{[i+1]},\ldots,M_{[j]}\). In particular, both \(M_{[i]}\) and \(M_{[j]}\) are nonzero, and hence \(\textrm{rk}(M_{[i]})\ge1\), and \(\textrm{rk}(M_{[j]})\ge 1\). This gives \(\mathrm{fr}(M)\ge 2\), a contradiction. Therefore all entries of \(M\) outside the main diagonal are zero.
Now suppose that two distinct diagonal entries, say \(a_{i,i}\) and \(a_{j,j}\) with \(i\neq j\), are nonzero. Then \(M_{[i]}\) and \(M_{[j]}\) both have rank at least one, again implying \(\mathrm{fr}(M)\ge2\). Hence exactly one diagonal entry of \(M\) is nonzero.
Conversely, if \(M\) is diagonal and has exactly one nonzero diagonal entry, then exactly one of the submatrices \(M_{[i]}\) has rank one, while all the others have rank zero. Thus \(\mathrm{fr}(M)=1\).
There are \(n\) choices for the position of the nonzero diagonal entry and \(q-1\) choices for its value. Therefore, \(s_q(n,1)=n(q-1)\). ◻
Proposition 3. Let \(n\ge2\). Then \[s_q(n,2) = (n-1)q^2(q-1)+\binom{n}{2}(q-1)^2.\]
Proof. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) with \(\mathrm{fr}(M)=2\). Since the flag-rank weight is the sum of the ranks of the submatrices \(M_{[i]}\), exactly two of these submatrices have rank one and all the others have rank zero. We distinguish two cases.
First, suppose that all the entries of \(M\) outside the main diagonal are zero. Then \(\mathrm{fr}(M)=2\) if and only if exactly two diagonal entries are nonzero. This gives \[\binom{n}{2}(q-1)^2\] matrices.
Now suppose that \(M\) has a nonzero entry outside the main diagonal. If \(m_{i,j}\neq0\) with \(j-i\ge2\), then this entry belongs to at least three submatrices, namely \(M_{[i]},M_{[i+1]},\ldots,M_{[j]}\). Hence \(\mathrm{fr}(M)\ge3\), a contradiction. Thus the only possible nonzero entries outside the main diagonal lie on the first superdiagonal. Let \(m_{i,i+1}\neq0\) for some \(i\in\{1,\ldots,n-1\}\). This entry belongs exactly to the two submatrices \(M_{[i]}\) and \(M_{[i+1]}\). Since \(\mathrm{fr}(M)=2\), these must be the only nonzero submatrices, and both must have rank one. Therefore all entries of \(M\) are zero except possibly \(m_{i,i}, m_{i,i+1}, m_{i+1,i+1}\), with \(m_{i,i+1}\neq0\). For each fixed \(i\), there are \(q^2(q-1)\) such matrices. Since there are \(n-1\) choices for \(i\), this case contributes \[(n-1)q^2(q-1)\] matrices. The two cases are disjoint, and the formula follows by summing them. ◻
Proposition 4. Let \(n\ge3\). Then \[s_q(n,3) = (n-2)q^4(q-1) + (n-1)(n-2)q^2(q-1)^2 + \binom{n}{3}(q-1)^3.\]
Proof. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) with \(\mathrm{fr}(M)=3\). We classify the possible matrices according to the highest nonzero diagonal of \(M\); see Figure 1 for a visual explanation.
Only the main diagonal is involved. Suppose first that all entries outside the main diagonal of \(M\) are zero. Then \(\mathrm{fr}(M)=3\) if and only if exactly three diagonal entries are nonzero. This gives \[\binom{n}{3}(q-1)^3\] matrices.
The first superdiagonal is involved, but the second superdiagonal is not. Assume that \(m_{i,i+1}\neq0\) for some \(i\in\{1,\ldots,n-1\}\) and that all entries on higher superdiagonals are zero. The entry \(m_{i,i+1}\) belongs exactly to \(M_{[i]}\) and \(M_{[i+1]}\). No other first-superdiagonal entry can be nonzero. Indeed, if an adjacent entry, say \(m_{i+1,i+2}\), were nonzero, then \(M_{[i+1]}\) would contain two independent nonzero positions, forcing \(\textrm{rk}(M_{[i+1]})\ge2\). Together with the nonzero blocks \(M_{[i]}\) and \(M_{[i+2]}\), this would imply \(\mathrm{fr}(M)\ge4\). If a non-adjacent first-superdiagonal entry were nonzero, then at least four submatrices \(M_{[j]}\) would be nonzero, again giving \(\mathrm{fr}(M)\ge4\). Thus there is exactly one nonzero entry on the first superdiagonal.
To obtain flag-rank weight \(3\), we must add exactly one nonzero diagonal entry outside the positions \(i\) and \(i+1\). The entries \(m_{i,i}\) and \(m_{i+1,i+1}\) may be chosen arbitrarily, since they do not increase the ranks of \(M_{[i]}\) and \(M_{[i+1]}\) beyond one.
Hence, for each fixed pair \((i,j)\), with \(i\in\{1,\ldots,n-1\}\) and \(j\in\{1,\ldots,n\}\setminus\{i,i+1\}\), there are \(q^2(q-1)^2\) matrices. Therefore this case contributes \[(n-1)(n-2)q^2(q-1)^2\] matrices.
The second superdiagonal is involved. Assume that \(m_{i,i+2}\neq0\) for some \(i\in\{1,\ldots,n-2\}\). This entry belongs exactly to the three submatrices \(M_{[i]}, M_{[i+1]}, M_{[i+2]}\). Since \(\mathrm{fr}(M)=3\), these must be the only nonzero submatrices, and each of them must have rank one. Therefore all entries outside the rows and columns indexed by \(i,i+1,i+2\) must be zero. Equivalently, the only entries that may be nonzero are those in the upper triangular \(3\times 3\) block supported on the consecutive indices \(i,i+1,i+2\), namely \[\begin{pmatrix} m_{i,i} & m_{i,i+1} & m_{i,i+2}\\ 0 & m_{i+1,i+1} & m_{i+1,i+2}\\ 0 & 0 & m_{i+2,i+2} \end{pmatrix},\] with \(m_{i,i+2}\neq0\).
The condition that \(M_{[i+1]}\) has rank one is equivalent to requiring \[(m_{i+1,i+1},m_{i+1,i+2}) = \lambda(m_{i,i+1},m_{i,i+2})\] for some \(\lambda\in\mathbb{F}_q\). Thus, for each fixed \(i\), we may choose \(m_{i,i+2}\in\mathbb{F}_q^*\), and \(m_{i,i}\), \(m_{i,i+1}\), \(m_{i+2,i+2}\), \(\lambda\in\mathbb{F}_q\). This gives \(q^4(q-1)\) matrices for each \(i\). Since there are \(n-2\) choices for \(i\), this case contributes \[(n-2)q^4(q-1)\] matrices.
The three cases are disjoint and exhaustive, so the formula follows. ◻
None
Figure 1: The three configurations contributing to \(s_q(n,3)\). Here \(\ast\) denotes a nonzero entry, \(\circ\) denotes an arbitrary element of \(\mathbb{F}_q\), and blank entries are zero..
We then get the following immediate size for the flag-rank balls of radius at most \(3\).
Corollary 1. For \(n\ge3\), the sizes of the balls of flag-rank radius \(0\), \(1\), \(2\), and \(3\) in \(\mathrm{U}(n,\mathbb{F}_q)\) are given by \[b_q(n,0)=1,\] \[b_q(n,1)=1+n(q-1),\] \[b_q(n,2) = 1+n(q-1) + (n-1)q^2(q-1) + \binom{n}{2}(q-1)^2,\] and \[\begin{align} b_q(n,3) ={}& 1+n(q-1) + (n-1)q^2(q-1) + \binom{n}{2}(q-1)^2 \\ &+ (n-2)q^4(q-1) + (n-1)(n-2)q^2(q-1)^2 + \binom{n}{3}(q-1)^3. \end{align}\]
We now derive some general bounds on \(s_q(n,t)\). The key observation is that matrices of small flag-rank weight cannot have nonzero entries too far from the main diagonal. We shall use the following result.
Proposition 5. [17]Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) and let \(\delta=\mathrm{fr}(M)\). If \(\delta<n\), then all nonzero entries of \(M\) lie on the first \(\delta\) diagonals.
Proposition 6. Let \(\delta\) be an integer with \(1\le \delta\le n\). Then \[s_q(n,\delta) \le q^{\frac{\delta(2n-\delta+1)}{2}}.\]
Proof. If \(\delta<n\), then Proposition 5 implies that every matrix \(M\in \mathrm{U}(n,\mathbb{F}_q)\) with \(\mathrm{fr}(M)=\delta\) is zero on all diagonals strictly above the \(\delta\)-th diagonal. Hence such a matrix is determined by its entries on the first \(\delta\) diagonals. The total number of entries on the first \(\delta\) diagonals is \[N_\delta = n+(n-1)+\cdots+(n-\delta+1) = \frac{\delta(2n-\delta+1)}{2}.\] Therefore, \[s_q(n,\delta)\le q^{N_\delta} = q^{\frac{\delta(2n-\delta+1)}{2}}.\] ◻
Note that if \(\delta=n\), this bound is trivial, since the right-hand side is \(q^{\frac{n(n+1)}{2}}=|\mathrm{U}(n,\mathbb{F}_q)|\).
As a consequence of Proposition 5, we obtain the following lower bound on the number of zero entries of a matrix of given flag-rank weight.
Corollary 2. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) and suppose that \(\mathrm{fr}(M)=\delta< n\). Then \(M\) has at least \[\sum_{i=1}^{n-\delta}i = \frac{(n-\delta)(n-\delta+1)}{2}\] zero entries.
Proof. By Proposition 5, all entries strictly above the \(\delta\)-th diagonal are zero. The number of such entries is \[1+2+\cdots+(n-\delta) = \frac{(n-\delta)(n-\delta+1)}{2}.\] ◻
We next obtain another simple restriction on the number of zero entries. We first have the following elementary fact.
Lemma 1. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\). For every \(i\in\{1,\ldots,n\}\), the submatrix \(M_{[i]}\) contains at least \(n\) entries.
Proof. By definition, \(M_{[i]}\) has size \(i\times(n-i+1)\), and therefore it contains \(i(n-i+1)\) entries. Moreover, \(i(n-i+1)-n =(i-1)(n-i) \ge0\) for every \(1\le i\le n\). Hence \(i(n-i+1)\ge n\). ◻
Lemma 2. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\). If \(\mathrm{fr}(M)<n\), then there exists \(i\in\{1,\ldots,n\}\) such that \(M_{[i]}=\boldsymbol{0}\).
Proof. Suppose, by contradiction, that \(M_{[i]}\neq\boldsymbol{0}\) for every \(i\in\{1,\ldots,n\}\). Then \(\textrm{rk}(M_{[i]})\ge1\) for every \(i\), and hence \[\mathrm{fr}(M) = \sum_{i=1}^{n}\textrm{rk}(M_{[i]}) \ge n,\] contrary to the assumption. ◻
Proposition 7. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\). If \(\mathrm{fr}(M)<n\), then \(M\) has at least \(n\) zero entries.
Proof. By Lemma 2, there exists \(i\in\{1,\ldots,n\}\) such that \(M_{[i]}=\boldsymbol{0}\). By Lemma 1, the submatrix \(M_{[i]}\) contains at least \(n\) entries of \(M\). Therefore \(M\) has at least \(n\) zero entries. ◻
We give a bound on the number of nonzero entries on each diagonal.
Proposition 8. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) with \(\mathrm{fr}(M)=\delta\leq n\). Then, for every \(i\in\{1,\ldots,\delta\}\), the \(i\)-th diagonal of \(M\) contains at most \(\delta-i+1\) nonzero entries.
Proof. Fix \(i\in\{1,\ldots,\delta\}\). Suppose that the \(i\)-th diagonal contains at least \(\delta-i+2\) nonzero entries. Then there exist distinct indices \(j_1<j_2<\cdots<j_{\delta-i+2}\) such that \(m_{j_t,j_t+i-1}\neq0\), for every \(t=1,\ldots,\delta-i+2\). The entry \(m_{j_t,j_t+i-1}\) belongs to each of the consecutive submatrices \(M_{[j_t]},M_{[j_t+1]},\ldots,M_{[j_t+i-1]}\). Since the starting indices \(j_t\) are strictly increasing, the union of these intervals of indices has size at least \(i+(\delta-i+2)-1=\delta+1\). Thus at least \(\delta+1\) of the submatrices \(M_{[h]}\) are nonzero. Each of them has rank at least one, and so \(\mathrm{fr}(M)\ge\delta+1\), which contradicts the assumption \(\mathrm{fr}(M)\leq\delta\). ◻
Corollary 3. Let \(1\le \delta\le n\). Then \[s_q(n,\delta) \le \prod_{i=1}^{\delta} \left( \sum_{j=0}^{\delta-i+1} \binom{n-i+1}{j}(q-1)^j \right).\]
Proof. Let \(M\in \mathrm{U}(n,\mathbb{F}_q)\) be such that \(\mathrm{fr}(M)=\delta\). By Proposition 8, for every \(i\in\{1,\ldots,\delta\}\), the \(i\)-th diagonal of \(M\) contains at most \(\delta-i+1\) nonzero entries. Moreover, by Proposition 5, there are no nonzero entries strictly above the \(\delta\)-th diagonal when \(\delta<n\).
The \(i\)-th diagonal contains exactly \(n-i+1\) entries. If exactly \(j\) of them are nonzero, where \(0\le j\le \delta-i+1\), then their positions can be chosen in \[\binom{n-i+1}{j}\] ways, and their values can be chosen in \((q-1)^j\) ways. Hence the number of possible choices for the \(i\)-th diagonal is at most \[\sum_{j=0}^{\delta-i+1} \binom{n-i+1}{j}(q-1)^j.\] Multiplying over \(i=1,\ldots,\delta\) gives the desired bound. ◻
We conclude this section with an asymptotic upper bound for spheres of fixed radius. The estimate follows directly from Corollary 3 and will be used in Section 5.
Proposition 9. Let \(n\) and \(t\) be fixed positive integers with \(t\le n\). Then, as \(q\to\infty\), \[s_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right),\] were the notation \(O_{n,t}\) means that the implicit constant depends only on \(n\) and \(t\). Consequently, \[b_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right).\]
Proof. By Corollary 3, we have \[s_q(n,t)\le \prod_{i=1}^t \left( \sum_{j=0}^{t-i+1} \binom{n-i+1}{j}(q-1)^j \right).\] For fixed \(n\) and \(t\), the \(i\)-th factor is a polynomial in \(q\) of degree at most \(t-i+1\). Hence the whole product has degree at most \[\sum_{i=1}^t (t-i+1)=1+2+\cdots+t=\frac{t(t+1)}{2}.\] Therefore we get \[s_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right).\] Since we have \[b_q(n,t)=\sum_{r=0}^t s_q(n,r),\] and the same estimate applied with \(r\) in place of \(t\) gives \[s_q(n,r)=O_{n,r}\left(q^{r(r+1)/2}\right) =O_{n,t}\left(q^{t(t+1)/2}\right)\] for every \(0\le r\le t\), we obtain \[b_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right).\] ◻
In this section, we prove a sphere-packing bound for the flag-rank metric. This bound naturally leads to the definition of perfect codes in this setting. As in the classical Hamming and rank-metric frameworks, the proof relies on the fact that balls of suitable radius centered at distinct codewords are pairwise disjoint.
Theorem 10 (Sphere-packing bound). Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a flag-rank-metric code with minimum distance \(\delta\), and let \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor\). Then \[|\mathcal{C}|\, b_q(n,t)\le q^{\frac{n(n+1)}{2}}.\]
Proof. Let \(\mathcal{C}=\{M_1,\ldots,M_s\}\). We first show that the balls \(B(M_i,t)\) are pairwise disjoint. Suppose, by contradiction, that there exist \(i\neq j\) and \(N\in B(M_i,t)\cap B(M_j,t)\). Then, by the triangle inequality, \[\mathrm{d}_{\mathrm{fr}}(M_i,M_j) \le \mathrm{d}_{\mathrm{fr}}(M_i,N)+\mathrm{d}_{\mathrm{fr}}(N,M_j) \le 2t.\] Since \(2t\le \delta-1\), this contradicts the fact that the minimum distance of \(\mathcal{C}\) is \(\delta\). Hence the balls \(B(M_i,t)\) are pairwise disjoint. Therefore, we also have \[\left|\bigcup_{i=1}^{s} B(M_i,t)\right| = \sum_{i=1}^{s}|B(M_i,t)|.\] Since the size of a ball does not depend on its center, we have \(|B(M_i,t)|=b_q(n,t)\) for every \(i\). Hence \[\left|\bigcup_{i=1}^{s} B(M_i,t)\right| = s\,b_q(n,t) = |\mathcal{C}|\,b_q(n,t).\] On the other hand, the union is contained in \(\mathrm{U}(n,\mathbb{F}_q)\), and therefore \[|\mathcal{C}|\,b_q(n,t) \le |\mathrm{U}(n,\mathbb{F}_q)| = q^{\frac{n(n+1)}{2}}.\] This proves the claim. ◻
Remark 11. The previous result holds for arbitrary, not necessarily linear, subsets \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\). However, unless otherwise stated, we restrict our attention to linear flag-rank-metric codes, that is, \(\mathbb{F}_q\)-subspaces of \(\mathrm{U}(n,\mathbb{F}_q)\).
As in the classical theory of error-correcting codes, we define perfect codes as those attaining equality in the sphere-packing bound.
Definition 4. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a flag-rank-metric code with minimum distance \(\delta\), and let \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor\). We say that \(\mathcal{C}\) is perfect if \[|\mathcal{C}|\,b_q(n,t)=q^{\frac{n(n+1)}{2}}.\]
Example 2. A trivial example of a perfect flag-rank-metric code is obtained by taking \(\mathcal{C}=\mathrm{U}(n,\mathbb{F}_q)\). Indeed, in this case the minimum flag-rank distance is \(\delta=1\), so that \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor=0\) and \(b_q(n,0)=1\). Hence \[|\mathcal{C}|\,b_q(n,0) = |\mathrm{U}(n,\mathbb{F}_q)| = q^{\frac{n(n+1)}{2}}.\]
Proposition 12. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta\). If \(\mathcal{C}\) is perfect, then \(\delta\) is odd.
Proof. Suppose, by contradiction, that \(\delta\) is even. Then \(\delta=2e\) for some integer \(e\geq 1\). Hence the radius \(t=\left\lfloor \frac{\delta-1}{2}\right\rfloor =\left\lfloor \frac{2e-1}{2}\right\rfloor =e-1\). Let \(C_0\in\mathcal{C}\) and choose \(M\in \mathrm{U}(n,\mathbb{F}_q)\) such that \(\mathrm{fr}(M)=e\). Set \(X=C_0+M\). Then, \(\mathrm{d}_{\mathrm{fr}}(X,C_0)=\operatorname{fr}(M)=e\), and therefore \(X\notin B_{e-1}(C_0)\). Since \(\mathcal{C}\) is perfect, the balls of radius \(e-1\) centered at the codewords of \(\mathcal{C}\) cover the whole space. Hence there exists \(C_1\in\mathcal{C}\), with \(C_1\neq C_0\), such that \(X\in B_{e-1}(C_1)\). Thus, \(\mathrm{d}_{\mathrm{fr}}(X,C_1)\leq e-1.\) By the triangle inequality, we obtain \[\mathrm{d}_{\mathrm{fr}}(C_0,C_1) \leq \mathrm{d}_{\mathrm{fr}}(C_0,X)+\mathrm{d}_{\mathrm{fr}}(X,C_1) \leq e+(e-1)=2e-1.\] On the other hand, since \(C_0\) and \(C_1\) are distinct codewords and \(\mathcal{C}\) has minimum distance \(\delta=2e\), we must have \(\mathrm{d}_{\mathrm{fr}}(C_0,C_1)\geq \delta=2e\). This is a contradiction. Therefore, \(\delta\) cannot be even, and so \(\delta\) is odd. ◻
In this section, we study perfect flag-rank-metric codes. We first prove a necessary divisibility condition for the size of the ball appearing in the sphere-packing bound. We then use this condition to prove the non-existence of non-trivial perfect flag-rank-metric codes in \(\mathrm{U}(2,\mathbb{F}_q)\) and \(\mathrm{U}(3,\mathbb{F}_q)\).
Proposition 13. Let \(\mathcal{C}\subsetneq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta\), and let \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor\). If \(\mathcal{C}\) is perfect, then \(b_q(n,t)\equiv0\pmod q\).
Proof. Since \(\mathcal{C}\) is linear and perfect, equality holds in the sphere-packing bound. Hence \[\label{eq:condcor} q^{\dim_{\mathbb{F}_q}(\mathcal{C})}\, b_q(n,t) = q^{\frac{n(n+1)}{2}}.\tag{2}\] Therefore \[b_q(n,t) = q^{\frac{n(n+1)}{2}-\dim_{\mathbb{F}_q}(\mathcal{C})} = q^{\mathrm{codim}_{\mathbb{F}_q}(\mathcal{C})}.\] Since \(\mathcal{C}\subsetneq \mathrm{U}(n,\mathbb{F}_q)\), its codimension is positive. Thus \(b_q(n,t)\) is divisible by \(q\). ◻
Combining Proposition 13 with the explicit formula for \(b_q(n,1)\) and with the Singleton-like bound, we obtain the following non-existence result.
Corollary 4. There are no non-trivial perfect flag-rank-metric codes in \(\mathrm{U}(n,\mathbb{F}_q)\) for \(n\in\{2,3\}\).
Proof. Let \(\mathcal{C}\subsetneq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta\), and set \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor\). For \(n=2\), the maximum possible flag-rank distance is \(2\), while for \(n=3\) it is \(4\). Hence \(t\le 1\). If \(t=0\), then equality in the sphere-packing bound gives \(|\mathcal{C}|=|\mathrm{U}(n,\mathbb{F}_q)|\), which contradicts the assumption \(\mathcal{C}\subsetneq \mathrm{U}(n,\mathbb{F}_q)\). Therefore, if \(\mathcal{C}\) is perfect and non-trivial, we must have \(t=1\). By Proposition 13, since \(\mathcal{C}\) is perfect then \(b_q(n,1)\equiv0\pmod q\). Moreover, from Corollary 1 \(b_q(n,1)=1+n(q-1)\), we get \(1+n(q-1)\equiv 1-n \pmod q\). Thus \(q\) must divide \(n-1\). For \(n=2\), this is impossible. For \(n=3\), it is possible only when \(q=2\).
It remains to consider the exceptional case \((n,q)=(3,2)\). In this case, \[b_q(3,1)=1+3(2-1)=4.\] If \(\mathcal{C}\) were perfect, then 2 would imply \[|\mathcal{C}| = \frac{|\mathrm{U}(3,\mathbb{F}_2)|}{b_2(3,1)} = \frac{2^6}{4} = 2^4.\] Thus \(\dim_{\mathbb{F}_2}(\mathcal{C})=4\). Since \(t=1\), we have \(\delta\in\{3,4\}\). The Singleton-like bound gives \(\mathrm{codim}_{\mathbb{F}_2}(\mathcal{C})\ge3\), and hence \(\dim_{\mathbb{F}_2}(\mathcal{C})\le 6-3=3\), yielding a contradiction. ◻
The previous corollary shows that the first ambient spaces are too small to contain non-trivial perfect flag-rank-metric codes. In the next results, we derive necessary numerical conditions for perfect codes with larger minimum distance.
Proposition 14. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a perfect linear flag-rank-metric code with minimum distance \(\delta\le n\), and let \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor\). Then \[\dim_{\mathbb{F}_q}(\mathcal{C}) \ge \frac{n(n+1)}{2}-\frac{t(2n-t+1)}{2}.\] In particular, \[\dim_{\mathbb{F}_q}(\mathcal{C}) \ge \frac{n(n+1)}{2}-\frac{\delta(2n-\delta+1)}{2}.\]
Proof. Since \(\mathcal{C}\) is perfect, we have \[|\mathcal{C}| = \frac{|\mathrm{U}(n,\mathbb{F}_q)|}{b_q(n,t)} = \frac{q^{\frac{n(n+1)}{2}}}{b_q(n,t)}.\] Since \(t<\delta\le n\), every matrix of flag-rank weight at most \(t\) has all its nonzero entries on the first \(t\) diagonals. Thus by Proposition 6, we have \[b_q(n,t) \le q^{\frac{t(2n-t+1)}{2}}.\] It follows that \[|\mathcal{C}| \ge q^{\frac{n(n+1)}{2}-\frac{t(2n-t+1)}{2}}.\] Taking logarithms in base \(q\) gives \[\dim_{\mathbb{F}_q}(\mathcal{C}) \ge \frac{n(n+1)}{2}-\frac{t(2n-t+1)}{2}.\] ◻
Theorem 15. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta=3\), and let \(\alpha\) be its codimension. Then \(\mathcal{C}\) is perfect if and only if \[n=\frac{q^\alpha-1}{q-1}.\] Moreover, necessarily \(\alpha\ge \delta\).
Proof. Since \(\delta=3\), we have \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor=1\). Thus \(\mathcal{C}\) is perfect if and only if \[b_q(n,1)=\frac{|\mathrm{U}(n,\mathbb{F}_q)|}{|\mathcal{C}|}.\] Since \(b_q(n,1)=1+n(q-1)\) and \(\frac{|\mathrm{U}(n,\mathbb{F}_q)|}{|\mathcal{C}|} = q^{\mathrm{codim}_{\mathbb{F}_q}(\mathcal{C})} = q^\alpha\), this is equivalent to \(1+n(q-1)=q^\alpha\). Solving the identity for \(n\), we obtain \(n=\frac{q^\alpha-1}{q-1}\). Finally, the inequality \(\alpha\ge\delta\) follows from the Singleton-like bound in Theorem 1. ◻
Corollary 5. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be an MFRD code with minimum distance \(\delta=3\). If \[n=\frac{q^3-1}{q-1},\] then \(\mathcal{C}\) is perfect.
Proof. Let \(\alpha\) be the codimension of \(\mathcal{C}\). Since \(\mathcal{C}\) is MFRD, it attains the Singleton-like bound. For \(\delta=3\) the bound gives \(\alpha=3\). Hence, \(\alpha=\delta\). Therefore, if \[n=\frac{q^3-1}{q-1},\] then \[n=\frac{q^\alpha-1}{q-1}.\] The claim follows from Theorem 15. ◻
Corollary 6. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a perfect linear flag-rank-metric code with minimum distance \(\delta=3\). Then \(n\equiv 1 \pmod q\). In particular, if \(n\not\equiv 1\pmod q\), then no perfect linear flag-rank-metric code with minimum distance \(\delta=3\) exists in \(\mathrm{U}(n,\mathbb{F}_q)\).
Proof. Let \(\alpha\) be the codimension of \(\mathcal{C}\). By Theorem 15, \[n=\frac{q^\alpha-1}{q-1}=1+q+\cdots+q^{\alpha-1}.\] Reducing modulo \(q\), we obtain \(n\equiv 1\pmod q\). ◻
We now recall the construction of MFRD codes with minimum distance \(3\) from [17], and we show that, for a suitable choice of the length, it yields perfect flag-rank-metric codes.
Let \[D_2(n,\mathbb{F}_q)=\{A\in \mathrm{U}(n,\mathbb{F}_q): a_{i,j}=0 \text{ whenever } j-i\ge 2\}.\] We identify \(D_2(n,\mathbb{F}_q)\) with \(\mathbb{F}_q^{2n-1}\) via \[\rho\left(\sum_{i=1}^{n}\lambda_iE_i+\sum_{i=1}^{n-1}\mu_iF_i\right) = (\lambda_1,\mu_1,\lambda_2,\ldots,\mu_{n-1},\lambda_n),\] where \(E_i\) and \(F_i\) are supported in positions \((i,i)\) and \((i,i+1)\), respectively. Denote by \(\mathop{\mathrm{PG}}(2,q)\) the projective plane with underlying vector space \(\mathbb{F}_q^3\).
Assume that \(3\le n\le q^2+q+1\). Choose distinct points \(P_i=[u_i]\in\mathop{\mathrm{PG}}(2,q)\), \(i\in[n]\), and points \(Q_i=[v_i]\notin\langle P_i,P_{i+1}\rangle\), \(i\in[n-1]\). Let \[H=(u_1\mid v_1\mid u_2\mid v_2\mid\cdots\mid v_{n-1}\mid u_n) \in Mat(3,2n-1,\mathbb{F}_q),\] set \(D=\ker(H)\), and define \[\mathcal{D}:= \rho^{-1}(D)\oplus \overline{U}(n-2,\mathbb{F}_q) \subseteq \mathrm{U}(n,\mathbb{F}_q),\] where \(\overline{U}(n-2,\mathbb{F}_q)\) denotes the embedded copy of \(\mathrm{U}(n-2,\mathbb{F}_q)\) supported on the diagonals strictly above the first superdiagonal.
Lemma 3. [17]The code \(\mathcal{D}\) is an \(\left\{n,\frac{n(n+1)}{2}-3,3\right\}_{\mathbb{F}_q}\) MFRD code. Furthermore, an \(\left\{n,\frac{n(n+1)}{2}-3,3\right\}_{\mathbb{F}_q}\) MFRD code exists if and only if \(n \leq |\mathrm{PG}(2,q)|=q^2+q+1\).
Theorem 16. Let \(n=q^2+q+1\). Then the code \(\mathcal{C}\) from [17] is a non-trivial perfect linear flag-rank-metric code with minimum distance \(3\) and codimension \(3\).
Proof. By Lemma 3, the code \(\mathcal{D}\) from [17] is an MFRD code with minimum distance \(3\) whenever \(3\le n\le q^2+q+1\). Hence, for \(n=q^2+q+1\), the code \(\mathcal{D}\) is an MFRD code with minimum distance \(3\). Since the Singleton-like bound gives codimension \(3\) for minimum distance \(3\), we have \(\mathrm{codim}_{\mathbb{F}_q}(\mathcal{D})=3\). Moreover, \[n=q^2+q+1=\frac{q^3-1}{q-1}.\] Therefore the numerical condition in Theorem 15 is satisfied with \(\alpha=3\). Hence \(\mathcal{D}\) is perfect. ◻
Theorem 17. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta=5\), and let \(\alpha\) be its codimension. Then \(\mathcal{C}\) is perfect if and only if \[n= \frac{-(2q^2-q+3)+\sqrt{(2q^2+q+1)^2+8(q^\alpha-q)}}{2(q-1)}.\] Moreover, necessarily \(\alpha>\delta\).
Proof. Since \(\delta=5\), we have \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor=2\). Thus \(\mathcal{C}\) is perfect if and only if \[b_q(n,2)=\frac{|\mathrm{U}(n,\mathbb{F}_q)|}{|\mathcal{C}|}=q^\alpha.\] By Corollary 1, \[b_q(n,2) = 1+n(q-1)+(n-1)q^2(q-1)+\binom{n}{2}(q-1)^2.\] Therefore being perfect is equivalent to \[1+n(q-1)+(n-1)q^2(q-1)+\binom{n}{2}(q-1)^2 = q^\alpha.\] Expanding and collecting the terms in \(n\), we obtain \[\frac{(q-1)^2}{2}n^2 + \frac{(q-1)(2q^2-q+3)}{2}n + 1-q^\alpha-q^3+q^2 = 0.\] Solving this quadratic equation gives \[n= \frac{-(2q^2-q+3)\pm\sqrt{(2q^2+q+1)^2+8(q^\alpha-q)}}{2(q-1)}.\] Since \(n\) is positive, only the positive sign is possible. Hence \[n= \frac{-(2q^2-q+3)+\sqrt{(2q^2+q+1)^2+8(q^\alpha-q)}}{2(q-1)}.\] Finally, the condition \(\alpha>\delta\) follows from the Singleton-like bound. ◻
Corollary 7. Let \(p\) be an odd prime. If \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_p)\) is a perfect flag-rank-metric code with minimum distance \(\delta=5\), then \(n\equiv1\) or \(n\equiv2 \pmod p\).
Proof. If \(\mathcal{C}\) is perfect, then by Theorem 17, \[1+n(p-1)+(n-1)p^2(p-1)+\binom{n}{2}(p-1)^2 = p^\alpha.\] Reducing modulo \(p\), we obtain \[1-n+\binom{n}{2}\equiv0\pmod p.\] Since \(p\) is odd, this is equivalent to \[2-2n+n(n-1)\equiv0\pmod p,\] that is, \[(n-1)(n-2)\equiv0\pmod p.\] Therefore, \(n\equiv1\) or \(n\equiv2 \pmod p\). ◻
Remark 18. For \(p=2\), the same reduction has to be handled separately, since one cannot divide by \(2\) modulo \(2\). In this case the condition becomes \[1+n+\binom{n}{2}\equiv0\pmod 2,\] which is equivalent to \(n\equiv1\) or \(n\equiv2 \pmod 4\).
Proposition 19. Assume that \(q=2\) and let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_2)\) be a linear flag-rank-metric code with minimum distance \(\delta=5\) and codimension \(\alpha\). If \(\alpha\) is odd and \(\alpha\ge11\), then \(\mathcal{C}\) is not perfect.
Proof. For \(q=2\), Theorem 17 gives \(n=\frac{-9+\sqrt{\Delta}}{2}\), where \(\Delta=105+2^{\alpha+3}\). Since \(\alpha\) is odd, \(\alpha+3\) is even. Let \(\zeta=2^{\frac{\alpha+3}{2}}\). Then, \(\zeta^2=2^{\alpha+3}\). Clearly, \(\zeta^2<\Delta\). Moreover, since \(\alpha\ge 11\), we have \(105<2^{\frac{\alpha+5}{2}}+1\), and hence \(\Delta = 2^{\alpha+3}+105 < 2^{\alpha+3}+2^{\frac{\alpha+5}{2}}+1 = (\zeta+1)^2\). Therefore \(\Delta\) lies strictly between the two consecutive squares \(\zeta^2\) and \((\zeta+1)^2\). Hence \(\Delta\) is not a perfect square, so \(n\) is not an integer. Consequently, \(\mathcal{C}\) cannot be perfect. ◻
Remark 20. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_3)\) be a flag-rank-metric code of codimension \(\alpha=7\) and minimum distance \(\delta=5\). If such a code satisfies the numerical condition of Theorem 17, then necessarily \[[n,k,\delta]=[29,428,5].\] Indeed, for \(q=3\) and \(\alpha=7\), the formula in Theorem 17 gives \(n=29\), and therefore \[k=\frac{29\cdot30}{2}-7=428.\] We also performed computations in Magma for all integers \(\alpha\) and all prime powers \(q\) satisfying \(6\le \alpha\le100\), and \(2\le q\le97\). In all cases, the value of \(n\) given by Theorem 17 was not an integer, except for the case \(q=3\) and \(\alpha=7\). Hence, within this range, no other candidate parameter set occurs.
Theorem 21. Let \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) be a linear flag-rank-metric code with minimum distance \(\delta=7\), and let \(\alpha\) be its codimension. Then \(\mathcal{C}\) is perfect if and only if \(n\ge3\) satisfies \[\label{eq:cubic-perfect} \begin{align} &(q-1)^3n^3 +3(q-1)^2(2q^2-q+2)n^2 \\ &\quad +(q-1)(6q^4-18q^3+26q^2-7q+11)n \\ &\quad +6\bigl(-2q^5+4q^4-5q^3+3q^2+1-q^\alpha\bigr) =0. \end{align}\tag{3}\] Moreover, necessarily \(\alpha\ge10\).
Proof. Since \(\delta=7\), we have \(t=\left\lfloor\frac{\delta-1}{2}\right\rfloor=3\). Thus \(\mathcal{C}\) is perfect if and only if \[b_q(n,3)=\frac{|\mathrm{U}(n,\mathbb{F}_q)|}{|\mathcal{C}|}=q^\alpha.\] By Corollary 1, \[\begin{align} b_q(n,3) ={}& 1+n(q-1) + (n-1)q^2(q-1) + \binom{n}{2}(q-1)^2\\ &+ (n-2)q^4(q-1) + (n-1)(n-2)q^2(q-1)^2 + \binom{n}{3}(q-1)^3. \end{align}\] Hence being perfect is equivalent to \[\begin{align} &1+n(q-1) + (n-1)q^2(q-1) + \binom{n}{2}(q-1)^2\\ &\quad+ (n-2)q^4(q-1) + (n-1)(n-2)q^2(q-1)^2 + \binom{n}{3}(q-1)^3 = q^\alpha. \end{align}\] Multiplying by \(6\) and simplifying yields precisely Equation 3 . Finally, the condition \(\alpha\ge10\) follows from the Singleton-like bound. ◻
Remark 22. Using Magma, we checked equation 3 for all integers \(\alpha\) and all prime powers \(q\) satisfying \(10\le \alpha\le100\), and \(2\le q\le97\). In all cases, the corresponding value of \(n\) was not an integer. Hence, within this range, Equation 3 gives no candidate values of \(n\) for a perfect flag-rank-metric code with minimum distance \(\delta=7\).
We conclude with an asymptotic nonexistence result for perfect codes of fixed length and small distance values.
Proposition 23. Fix \(n\) and let \(\delta=2t+1\) with \(t<n\). Suppose that \[\delta-1+ \left\lfloor\sqrt{\delta-1}\right\rfloor \left\lfloor \frac{\sqrt{4(\delta-1)+1}-1}{2} \right\rfloor > \frac{t(t+1)}{2}.\] Then perfect linear flag-rank-metric codes in \(\mathrm{U}(n,\mathbb{F}_q)\) with minimum distance \(\delta\) do not exist for all sufficiently large prime powers \(q\).
Proof. Suppose that there exists a perfect linear flag-rank-metric code \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) with minimum distance \(\delta=2t+1\), and let \(\alpha=\mathrm{codim}_{\mathbb{F}_q}(\mathcal{C})\). Since \(\mathcal{C}\) is perfect and has packing radius \(t\), we have \[|\mathcal{C}|b_q(n,t)=q^{n(n+1)/2}.\] As \(\mathcal{C}\) is linear, this is equivalent to \(b_q(n,t)=q^\alpha\). On the other hand, by Proposition 9, we have \[b_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right)\] as \(q\to\infty\). By the Singleton-like bound, applied to a code of minimum distance \(\delta\), we have \[\alpha\ge \delta-1+ \left\lfloor\sqrt{\delta-1}\right\rfloor \left\lfloor \frac{\sqrt{4(\delta-1)+1}-1}{2} \right\rfloor.\] By assumption, this lower bound is strictly larger than \(t(t+1)/2\). Hence there exists an integer \(\beta>t(t+1)/2\) such that \(\alpha\ge \beta\). Therefore, \(q^\alpha\ge q^\beta\). Thus \(\mathcal{C}\) perfect implies \[q^\beta\le q^\alpha=b_q(n,t) =O_{n,t}\left(q^{t(t+1)/2}\right),\] which is impossible as \(q\to\infty\). Hence such perfect codes do not exist for all sufficiently large prime powers \(q\). ◻
Corollary 8. Fix \(n\). For each \(\delta\in\{3,5,7,9,11\},\) perfect linear flag-rank-metric codes in \(\mathrm{U}(n,\mathbb{F}_q)\) with minimum distance \(\delta\) do not exist for all sufficiently large prime powers \(q\).
Proof. Write \(\delta=2t+1\). For \(\delta=3,5,7,9,11\), we have respectively \(t=1,2,3,4,5\). By Proposition 9, \[b_q(n,t)=O_{n,t}\left(q^{t(t+1)/2}\right).\] If \(\mathcal{C}\subseteq \mathrm{U}(n,\mathbb{F}_q)\) is a perfect linear flag-rank-metric code with minimum distance \(\delta\) and codimension \(\alpha\), then \(b_q(n,t)=q^\alpha\). On the other hand, the Singleton-like bound gives respectively \(\alpha\ge 3\), \(\alpha\ge 6\), \(\alpha\ge 10\), \(\alpha\ge 12\), and \(\alpha\ge 16\). Moreover, \(\frac{t(t+1)}{2}\in \{1,3,6,10,15\}\) for \(t=1,2,3,4,5\), respectively. Thus, in each case, the exponent forced by the Singleton-like bound is strictly larger than the exponent in the asymptotic upper bound for \(b_q(n,t)\). Hence the equality \(b_q(n,t)=q^\alpha\) is impossible for all sufficiently large \(q\). Therefore no such perfect codes exist for all sufficiently large prime powers \(q\). ◻
Remark 24. The previous corollary does not contradict the perfect codes with minimum distance \(3\) constructed in Theorem 16. Indeed, in that family one has \(n=q^2+q+1\), so the length is not fixed as \(q\) tends to infinity.
In this work, we initiated the study of the combinatorial structure induced by the flag-rank metric on the space \(\mathrm{U}(n,\mathbb{F}_q)\) of upper triangular matrices over a finite field. We explicitly determined the sizes of spheres of flag-rank radius \(0\), \(1\), \(2\), and \(3\), and consequently obtained closed formulas for the sizes of balls of radius at most \(3\). In particular, these results give a complete description of balls and spheres in \(\mathrm{U}(n,\mathbb{F}_q)\) for \(n\in\{2,3\}\). We further provide an asymptotic estimate for the sizes of balls of larger radius.
Using these results, we derived a sphere-packing bound for flag-rank-metric codes and introduced the notion of perfect codes in this setting. We proved that no non-trivial perfect flag-rank-metric codes exist in \(\mathrm{U}(n,\mathbb{F}_q)\) for \(n\in\{2,3\}\). We then investigated necessary numerical conditions for the existence of perfect codes in higher dimensions. For minimum distance \(\delta=3\), we obtained an exact characterization in terms of the codimension \(\alpha\), namely \[n=\frac{q^\alpha-1}{q-1}.\] For minimum distances \(\delta=5\) and \(\delta=7\), we derived explicit quadratic and cubic conditions, respectively, that the parameters of a perfect code must satisfy. These conditions provide arithmetic obstructions to the existence of perfect flag-rank-metric codes and exclude many possible parameter sets. Finally, using the asymptotic upper bound for the sizes of balls of fixed radius, we show that, for fixed length \(n\) and \(\delta\in\{3,5,7,9,11\}\), perfect linear flag-rank-metric codes with minimum distance \(\delta\) do not exist over \(\mathbb{F}_q\) for all sufficiently large \(q\).
The results presented here show that, even in small radius, the flag-rank metric exhibits a rich and rigid combinatorial behavior. Several natural questions remain open. In particular, it would be interesting to determine the sizes of balls and spheres of arbitrary radius, to refine the arithmetic obstructions for perfect codes, and to understand whether non-trivial perfect flag-rank-metric codes exist beyond the cases constructed or ruled out in this paper.