Optimum distance flag codes from spreads via perfect matchings in graphs

In this paper, we study flag codes on the vector space Fqn\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathbb {F}}}_q^n$$\end{document}, being q a prime power and Fq\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathbb {F}}}_q$$\end{document} the finite field of q elements. More precisely, we focus on flag codes that attain the maximum possible distance (optimum distance flag codes) and can be obtained from a spread of Fqn\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\mathbb {F}}}_q^n$$\end{document}. We characterize the set of admissible type vectors for this family of flag codes and also provide a construction of them based on well-known results about perfect matchings in graphs. This construction attains both the maximum distance for its type vector and the largest possible cardinality for that distance.


Introduction
Random network coding is introduced in [  Xaro Soler-Escrivà xaro.soler@ua.es perform random linear combinations of the received vectors instead of simply routing them, as it happens when using classical channels of communication. This process is specially vulnerable to error dissemination, and, as a solution to this problem, in [13], Koetter and Kschischang introduce the concept of subspace codes as adequate errorcorrection codes in random network coding. These codes are families of subspaces of an n-dimensional vector space over the finite field F q endowed with a specific distance. If the dimension of all the subspaces in a code is fixed, we say that it is a constant dimension code.
In coding theory, the distance of a code is closely related to its error-correction capability. More precisely, a code with distance d can detect d − 1 errors and correct up to d− 1 2 . The size of a code is also an important parameter, since it determines the amount of different messages that can be encoded. Hence, one of the main problems in this area is the construction of codes with the largest possible size with a given minimum distance or codes with the largest minimum distance for a given size. In the particular context of network coding, this fact motivates the search for subspace codes having the largest possible distance and the best size for that distance.
Spreads are objects coming from finite geometry, introduced by Segre in [25]. A kdimensional spread (or k-spread) of F n q is just a collection of k-dimensional subspaces that pairwise intersect trivially and cover the space F n q . It is well known that k-spreads exist if, and only if, k divides n. In the network coding setting, k-spread codes are optimal codes in the previous sense: they attain the best distance for their dimension, and their cardinality is as large as possible.
When using subspace codes, every codeword (a subspace) is sent in a single use of the channel. In contrast, in [23,24], Nobrega and Uchôa-Filho present the notion of multishot codes, where codewords are sequences of r subspaces of F n q and need r successive uses of the channel (shots) to be sent. This approach allows to construct codes with good parameters without modifying neither the field size q nor the dimension n. As a particular case of multishot codes, we have the class of flag codes. A flag on F n q is just a sequence F = (F 1 , . . . , F r ) of nested subspaces of F n q . The vector (dim(F 1 ), . . . , dim(F r )) is called type of the flag F. Now, given integers 0 < t 1 < · · · < t r < n, a flag code of type (t 1 , . . . , t r ) on F n q is a nonempty collection of flags of this type. Flag codes in network coding appear for the first time in [19]. Later on, in [2], a study of flag codes attaining the best possible distance (optimum distance flag codes) is undertaken. In that work, these codes are characterized in terms of the constant dimension codes used in different shots (the projected codes). Moreover, it was also shown that the presence of a spread code among the projected codes leads to constructions of optimum distance flag codes that also reach the largest possible size.
In particular, in [2], the authors build optimum distance flag codes with a k-spread as a projected code fixing the full type vector, that is, (1, . . . , n − 1). They conclude that such codes exist just if n = 2k or n = 3 and k = 1. On the other hand, in this paper, we deal with the converse problem: given n and a divisor k of n, we look for conditions on the type vector of an optimum distance flag code on F n q having a k-spread as a projected code. We show that not every type vector (t 1 , . . . , t r ) is allowed for this purpose, only those satisfying Observe that, for n = 2k or n = 3 and k = 1, any full type vector is admissible. In fact, for n = 2k, we have k = n − k. However, this equality does not hold for an arbitrary divisor k of n, and to overcome the gap between dimensions k and n − k, we need to provide suitable nested subspaces of these dimensions. We solve this problem by using classical combinatorial results about the existence of perfect matchings on bipartite regular graphs. Finally, for any given admissible type vector, we get a construction of flag codes with the maximum distance and the largest cardinality among optimum distance flag codes of the corresponding type.
The paper is organized as follows: In Sect. 2, we recall some background on finite fields, constant dimension codes, flag codes and graphs. In Sect. 3, we determine the set of admissible type vectors for a flag code to attain the maximum possible distance and to have a k-spread as a projected code. Then, for those type vectors, we undertake the construction of such codes in several stages. First, we consider the type (1, n − 1) and construct optimum distance flag codes from the spread of lines, exploiting the existence of perfect matchings in bipartite regular graphs. Then, using the field reduction map, we translate the previous construction into the type (k, n − k). Finally, by taking advantage of some properties satisfied by the mentioned map, we finish with the full admissible type (1, . . . , k, n − k, . . . , n − 1) and any other admissible type vector. Our codes have the best size for the given admissible type vector and the associated maximum distance. We complete this section with an example of our construction for the admissible type (2, 4) on F 6 2 having a 2-spread as the subspace code used at the first shot.

Preliminaries
We devote this section to recall some background we will need along this paper. This background involves finite fields, subspace and flag codes and graph theory.

Results on finite fields
Most of the following definitions and results about finite fields as well as the corresponding proofs can be found in [18].
Let q be a prime power and F q the finite field with q elements. Consider f (x) ∈ F q [x] a monic irreducible polynomial of degree k and α ∈ F q k a root of f (x). Then, we have that F q k ∼ = F q [α], which allows us to realize the field F q k as , the following square matrix is a field with q k elements. We also have the natural field isomorphism For any positive integer n, we denote by P q (n) the set of all vector subspaces of F n q . The Grassmann variety G q (k, n) is the set of all k-dimensional subspaces of F n q . Any subspace U ∈ G q (k, n) can be generated by the rows of some full-rank matrix U ∈ F k×n q . In that case, we write U = rowsp(U ) and say that U is a generator matrix of U. By taking the generator matrix in reduced row echelon form (RREF), we get uniqueness in the matrix representation of the subspace U.
Let us take n = ks with k > 1. The field isomorphism φ provided by (1), in turn, naturally induces a map ϕ between P q k (s) and P q (ks) given by: This map is known as field reduction since it maps subspaces over F q k into subspaces over the subfield F q (see [8,17,21,22]). Let us recall some useful properties of the map ϕ pointed out in [17] that we will use in Sect. 3.2.2.

Constant dimension codes
The Grassmannian G q (k, n) can be considered as a metric space with the subspace distance defined as: for all U, V ∈ G q (k, n) (see [13]).
A constant dimension (subspace) code of dimension k and length n is any nonempty subset C ⊆ G q (k, n). The minimum subspace distance of the code C is defined as [26] and references therein, for instance). It follows that the minimum distance of a constant dimension code C is upper-bounded by: Constant dimension codes C ⊆ G q (k, n) in which the distance between any pair of different codewords is d S (C) are said to be equidistant. For such codes, there exists some value c < k such that, given two different subspaces U, V ∈ C, it holds that dim(U ∩ V) = c. Hence, the minimum distance of the code is precisely d S (C) = 2(k − c), and C is also called an equidistant c-intersecting constant dimension code.
In case the value c is the minimum possible dimension of the intersection between k-dimensional subspaces of F n q , that is, equidistant c-intersecting codes attain the bound given in (4). In particular, for dimensions k n 2 , we have that these codes are 0-intersecting codes known as partial spreads. The cardinality of any partial spread C in G q (k, n) always satisfies (see [9,Lemma 7]). Partial spread codes and equidistant codes have been studied in [6,9,10]. Whenever k divides n, the previous bound is attained by the so-called spread codes (or k-spreads) of F n q . Notice that a k-spread S is a subset of G q (k, n) whose elements give a vector space partition of F n q . Spreads are classical objects coming from finite geometry (see [25], for instance). For further information related to spreads in the network coding framework, we refer the reader to [8,21,22,26].
The following spread is due to Segre [25]. In the network coding setting, it was presented for the first time in [21] as a construction of spread code. Denote by G L k (q) the general linear group of degree k over the field F q . Let P ∈ G L k (q) be the companion matrix of a monic irreducible polynomial in F q [x]. We will write I k and 0 k to denote the identity matrix and the zero matrix of size k × k, respectively. Take s ∈ N such that n = sk. Then, the following family of k-dimensional subspaces is a spread code: where is the set of k × ks matrices with the first nonzero block from the left equal to I k .

Remark 2.2
Notice that the matrices in are in reduced row echelon form and it is clear that the field reduction map ϕ defined in (2) gives a bijection between the Grassmannian of lines G q k (1, s) and the spread code S(s, k, P) We will come back to this fact in Sect. 3.2.2.
Given a constant dimension code C ⊆ G q (k, n), the dual code of C is the subset of G q (n − k, n) given by where U ⊥ is the orthogonal of U with respect to the usual inner product in F n q . In [13], it was proved that C and C ⊥ have both the same cardinality and minimum distance. Notice that the dual of a partial spread of dimension k n 2 is an equidistant (n −2k)intersecting code of dimension n − k and conversely.

Flag codes
Subspace codes were introduced for the first time in [13] as error-correction codes in random network coding. In that paper, the authors propose a suitable network channel with a single transmitter and several receivers that is used just once, so that subspace codes can be considered as one-shot codes. The use of the channel more than once was suggested originally in [23] and gave rise to the so-called multishot codes as a generalization of subspace codes. We call any nonempty subset C of P q (n) r a multishot code of length r 1, or just r -shot code. In particular, if codewords in C are sequences of nested subspaces, we say that C is a flag code. Flag codes were first studied as orbits of group actions in [19], and, in [16], the reader can find a study of bounds on the cardinality of full flag codes with a prescribed distance. Let us recall some concepts in the setting of flag codes.
With this notation, F i is said to be the i-th subspace of F. In case the type vector is (1, 2, . . . , n − 1), we say that F is a full flag.
The space of flags of type (t 1 , . . . , t r ) on F n q is denoted by F q ((t 1 , ..., t r ), n) and can be endowed with the flag distance d f that naturally extends the subspace distance defined in (3): given two flags F = (F 1 , . . . , F r ) and F = (F 1 , . . . , F r ) in F q ((t 1 , . . . , t r ), n), the flag distance between them is A flag code of type (t 1 , . . . , t r ) on F n q is defined as any non-empty subset C ⊆ F q ((t 1 , . . . , t r ), n). The minimum distance of a flag code C of type (t 1 , . . . , t r ) on F n q is given by Given a type vector (t 1 , . . . , t r ), for every i = 1, . . . , r , we define the i-projection to be the map The i-projected code of C is the set In particular, if C is a full flag code, we have that (10) becomes for n even, , for n odd.

Matchings in graphs
Now we introduce some basic concepts and results on graphs in order to use them in the construction of a specific family of flag codes with the maximum distance in Sect. 3. All these definitions and results together with their proofs can be found in [3].
is an incident edge with v and v . Two edges are adjacent if they have a common vertex. Given a vertex v ∈ V we call the degree of v to the number of incident edges with v. A graph G is said to be k-regular, if each vertex in G has degree k.
On the other hand, a set of vertices (or edges) is independent if it does not contain adjacent elements. A set M ⊆ E of independent edges of a graph A graph G is bipartite if the vertex set can be partitioned into two sets V = A ∪ B such that there is no pair of adjacent vertices neither in A nor in B. For this class of graphs, perfect matchings are just bijections between A and B given by a subset of edges of the graph connecting each vertex in A with another vertex in B. The following classic result, whose proof can be found in [3] (pages 37-38), states the existence of perfect matchings in a family of graphs: Theorem 2.3 Any k-regular bipartite graph admits a perfect matching.
The search for maximum matchings in bipartite graphs is a classical problem in graph theory that started in the 1930s with the works of König and of Egerváry (see [5,14]). Later, Kuhn and M. Hall tackled this problem and presented the first formal algorithms to find perfect matchings in bipartite graphs (see [11,15]). This type of algorithms is known as "Hungarian Method". Finding matchings in non-bipartite graphs is a more difficult problem, and the first (efficient) algorithm in this direction was provided by Edmonds in 1965 (see [4]). For further information on matching theory, see [20] and references inside.
We will use the previous Theorem through Sect. 3 in order to give perfect matchings of a particular regular bipartite graph of our interest. Such matchings will allow us to construct disjoint flag codes of a specific type as we will show later.

Optimum distance flag codes from spreads
Flag codes attaining the bound in (10) are called optimum distance flag codes and can be characterized in terms of their projected codes in the following way: Theorem 3.1 (see [2]) Let C be a flag code of type (t 1 , . . . , t r ). The following statements are equivalent: (i) C is an optimum distance flag code.
(ii) C is disjoint, and every projected code C i attains the maximum possible subspace distance.
As a consequence, the i-projected codes of an optimum distance flag code have to be partial spreads if t i n 2 and equidistant (2t i − n)-intersecting subspace codes for dimensions t i > n 2 . As mentioned in Sect. 2.2, whenever k divides n, k-spread codes are partial spread codes (constant dimension codes with maximum distance) with the best size. This good property of spreads naturally gives rise to the question of finding optimum distance flag codes having a spread as their i-projected code when the dimension t i is a divisor of n. Note that, due to the disjointness property, we could have at most one spread among the projected codes. In [2], it was proved that having a spread as a projected code makes optimum distance flag codes attain the maximum possible size as well.
Theorem 3.2 [2, Theorem 3.12] Let k be a divisor of n and assume that C is an optimum distance flag code of type (t 1 , . . . , t r ) on F n q . If some t i = k, then |C| q n −1 q k −1 and equality holds if, and only if, the i-projected code C i is a k-spread of F n q .
In the same paper, it is shown that, for the full type vector (1, . . . , n − 1), it is possible to find optimum distance full flag codes having a spread as a k-projected code only if either n = 2k or n = 3 and k = 1. Observe that there, the authors always work with full flag codes (the full type vector is fixed) and then provide conditions on n and k. Now, we deal with the inverse problem: given n and a divisor k of n, we look for conditions on the type vector of an optimum distance flag code on F n q having a k-spread as a projected code. We conclude that not all the type vectors are allowed. Let us describe the admissible ones and provide a construction of optimum distance flag codes for them, based on the existence of perfect matchings in a specific graph.

Admissible type vectors
This paper is devoted to explore the existence of optimum distance flag codes of a general type vector (t 1 , . . . , t r ), not necessarily the full type, having a spread as their iprojected code when t i is a divisor of n. The next result states the necessary conditions that the type vector (t 1 , . . . , t r ) must satisfy. Theorem 3.3 Let C be an optimum distance flag code of type (t 1 , . . . , t r )on F n q . Assume that some dimension t i = k divides n and the associated projected code C i is a kspread. Then, for each j ∈ {1, . . . , r }, either t j k or t j n − k.
Proof Notice that in case i = r , clearly t j t r = k, for every j = 1, . . . , r . Suppose that i < r . Let us show that t i+1 n − k.
Since t i = k divides n, we can write n = sk, for some s 2. If s = 2, we have that n − k = k and the result trivially holds. In case s > 2, then s < 2(s − 1) and we have that 2k < n < 2(s − 1)k = 2(n − k). We deduce that k n 2 < n − k. Now, by contradiction, assume that t i+1 < n − k. We distinguish two possibilities: (1) If k < t i+1 n 2 , since C is an optimum distance flag code, by Theorem 3.1, its projected code C i+1 must be a partial spread of dimension t i+1 and cardinality |C i+1 | = |C i | = q n −1 q k −1 . Contradiction with (5). (2) If n 2 < t i+1 < n −k, the projected code C i+1 has to be an equidistant (2t i+1 −n)intersecting constant dimension code. In other words, the subspace distance of C i+1 is 2(n − t i+1 ). Hence, its dual code C ⊥ i+1 is a partial spread of dimension n − t i+1 > n − k > k and cardinality |C i+1 | = |C i | = q n −1 q k −1 , which again contradicts (5).
We conclude that t i+1 n − k.

Remark 3.4
This result provides a necessary condition on the type vector of any optimum distance flag code on F n q having a k-spread as a projected code. According to this, we say that a type vector is admissible if it satisfies the conditions in Theorem 3.3. In other words, if k ∈ {t 1 , . . . , t r } ⊆ {1, . . . , k, n − k, . . . , n − 1}.
Notice that every type vector containing the dimension k is admissible when n = 2k since, in that case, it holds k = n − k. This particular case has been already studied in [2], where it was proved that optimum distance flag codes of any type vector containing the dimension k can be constructed from a k-spread (planar spread). Moreover, those codes were shown to attain the maximum possible cardinality as well. In the next subsection, we tackle the problem of constructing flag codes attaining the maximum distance and having a k-spread as their projected code for any admissible type vector in the general case n = ks, for s 3.

A construction based on perfect matchings
This part is devoted to describe a specific construction of optimum distance flag codes on F n q from a k-spread of a given admissible type vector (t 1 , . . . , t r ). By means of Theorem 3.3, if such codes exist, their type vector must satisfy k ∈ {t 1 , . . . , t r } ⊆ {1, . . . , k, n − k, . . . , n − 1}. For the sake of simplicity, we undertake this construction in several phases: we consider first the admissible type vector (1, n − 1), that is, the construction of optimum distance flag codes from the spread of lines. Secondly, by using the field reduction map defined in Sect. 2.1, we properly translate the construction in the first step to get optimum distance flag codes of type vector (k, n − k) having the k-spread S introduced in (6) as its first projected code. Then, taking advantage of certain properties of the k-spread S, we extend the construction in the second step to obtain optimum distance flag codes of the full admissible type, that is, (1, . . . , k, n − k, . . . , n − 1). Finally, this last construction gives optimum distance flag codes of any admissible type vector after a suitable puncturing process. Let us explain in detail all these stages.

The type vector (1, n − 1): starting from the spread of lines
Take n 3. In this section, we provide a construction of optimum distance flag codes on F n q from the spread of lines, that is, having the Grassmannian G q (1, n) as a projected code. By Theorem 3.3, the only admissible type vector in this case is (1, n − 1). In other words, to give an optimum distance flag code from the spread of lines of F n q , we have to provide a family of |G q (1, n)| pairwise disjoint flags of length two, all of them consisting of a line contained in a hyperplane. To do so, we translate this problem to the one of finding perfect matchings in bipartite regular graphs, using the results given in Sect. 2.4. Let us precise this.
Consider the graph G = (V , E), with set of vertices V = G q (1, n) ∪ G q (n − 1, n) and set of edges E defined by Notice that the set of vertices in G consists of the lines and hyperplanes of F n q . An  edge (l, H ) of G exists if, and only if, the line l is contained in the hyperplane H . With this notation, the next result holds.

Proposition 3.5 The graph G = (V , E) is bipartite and q (n−1) −1
q−1 -regular. Proof It is clear that G is a bipartite graph by definition. Moreover, the number of hyperplanes containing a fixed line coincides with the number of lines lying on a given hyperplane. This number is precisely q (n−1) −1 q−1 . Then, the degree of any vertex in G coincides with this value, and then, G is q (n−1) −1 q−1 -regular. Note that the problem of giving a family of flags with the desired conditions can be seen as the combinatorial problem of giving a perfect matching in G. Since G is a regular bipartite graph, we can use Theorem 2.3 to conclude that there exist perfect matchings in G. More precisely, there exists a subset M ⊂ E that matches V , that is, each edge in M has an extremity in G q (1, n) and the other one in G q (n − 1, n). In particular, the set M has a number of edges equal to |G q (1, n)|. This matching M induces naturally a bijection, also denoted by M, between the set of lines and the set of hyperplanes in F n q . Moreover, by the definition of E, we have that the map M : G q (1, n) → G q (n − 1, n) satisfies that l ⊂ M(l) for any l ∈ G q (1, n). This fact allows us to construct a family of flags of type (1, n − 1) on F n q in the following way: Let us see that the family C is a flag code with projected codes C 1 = G q (1, n) and C 2 = G q (n − 1, n) satisfying the desired conditions. Theorem 3.6 Given n 3, the code C defined in (11) is an optimum distance flag code of type (1, n − 1) on F n q with the spread of lines as a projected code.
Proof Since the map M defined above is bijective, the code C must be a disjoint flag code with projected codes C 1 = G q (1, n) and C 2 = G q (n − 1, n). In particular, as d S ( C 1 ) = d S ( C 2 ) = 2 is the maximum possible distance for constant dimension codes of dimension 1 and n −1 in F n q , by Theorem 3.1, we have that C is an optimum distance flag code with G q (1, n) as a projected code.

Remark 3.7
Observe that, by means of Theorem 3.2, our code C defined as above attains the maximum possible cardinality for flag codes of type (1, n − 1) and distance 4, which is For the particular case n = 3, the previous bound was given in [16], where the author studied bounds for the cardinality of full flag codes with a given distance. Observe that this is the only case in which optimum distance full flag codes with a spread as a projected code can be constructed, apart from the case n = 2k, as it was explained in [2].
Note that, despite the fact that Theorem 2.3 guarantees the existence of perfect matchings in regular bipartite graphs, in order to provide a concrete construction of optimum distance flag codes of type (1, n −1) on F n q , we need to get a precise matching in G. As said in Sect. 2, this can be done by using known algorithms (see [7,11,12,15], for instance). In Sect. 3.3, we exhibit an optimum distance flag code of type (2,4) constructed as a perfect matching obtained with GAP.

The type vector (k, n − k)
Take n = ks a natural number with k 2 and s 3. In order to construct optimum distance flag codes of type (k, n − k) on F n q , we will use the construction of optimum distance flag codes of type (1, s − 1) on F s q k given in Sect. 3.2.1 together with the field reduction map defined in Sect. 2.1. Let us explain this construction.
Let M : 1, s) be a bijection such that l ⊂ M(l) for any l ∈ G q k (1, s). By Theorem 3.6, we know that the code is an optimum distance flag of type (1, s − 1) on F s q k . In particular, the code C is disjoint. On the other hand, given P ∈ G L k (q) the companion matrix of a monic irreducible polynomial of degree k in F q [x], the associated field isomorphism φ : F q k → F q [P] induces the field reduction ϕ : P q k (s) −→ P q (ks) as in (2). Notice that, by Proposition 2.1, we have that for any m ∈ {1, . . . , s − 1}, it holds that ϕ (G q k (m, s)) ⊆ G q (mk, sk). Moreover, given U, V subspaces of F s q k with U ⊆ V, then ϕ(U) ⊆ ϕ(V). As a consequence, if (l, M(l)) ∈ C, then (ϕ(l), ϕ(M(l))) is a flag of type (k, n − k) on F n q . This fact allows us to define a family of flags over F n q as follows C = {(ϕ(l), ϕ(M(l))) | l ∈ G q k (1, s)}.
By Remark 2.2, we know that ϕ gives a bijection between G q k (1, s) and the k-spread S = S(s, k, P) defined in (6). Hence, the family C is a flag code with projected codes and the following result holds: Theorem 3.8 The code C defined in (12) is an optimum distance flag code of type (k, n − k) on F n q having the spread S as a projected code.
Furthermore, by the injectivity of ϕ (see Proposition 2.1), we also have that | C 2 | = |ϕ(G q k (s − 1, s))| = |G q k (s − 1, s)|. As |G q k (1, s)| = |G q k (s − 1, s)|, we conclude that | C| = | C 1 | = | C 2 | and C is disjoint. Let us now prove that the projected codes of C are constant dimension codes with the maximum possible distance. Since the projected code C 1 is a spread, it is enough to check this property for C 2 . Given any two different subspaces ϕ(H ), ϕ(H ) ∈ C 2 = ϕ(G q k (s − 1, s)), by means of Proposition 2.1, we have that H , H are different hyperplanes. Moreover, since the intersection of any two hyperplanes in F s q k is a (s − 2)-dimensional subspace of F s q k we have that Notice that n − 2k = 2(n − k) − n is the minimum among the possible dimensions of the intersection of subspaces in G q (n − k, n). Hence, C 2 is an equidistant (n − 2k)intersecting constant dimension code and, by applying Theorem 3.1, we are done.

The full admissible type vector
In this subsection, we finally tackle the construction of optimum distance flag codes of the full admissible type, that is, of type (1, . . . , k, n − k, . . . , n − 1) on F n q having the k-spread S defined in (6) as a projected code. To do this, we start from the optimum distance flag code C of type (k, n − k) defined in (12). Recall that the construction of this code depends on the choice of a bijection M : Let us fix an order in the set of lines of F s q k and write G q k (1, s) = {l 1 , l 2 , . . . , l L }, where L = |G q k (1, s)|. This order in G q k (1, s) naturally induces respective orders in the sets G q k (s − 1, s), S and H = ϕ(G q k (s − 1, s)) as follows: where is the set defined in (7), and q k is the RREF matrix generating the line l i . Now, given a hyperplane H i = M(l i ) of F s q k , we can write for l i 2 , . . . , l i s−1 some lines of F s q k . By the properties of the field reduction ϕ described in Proposition 2.1, we have that So, any subspace H i ∈ H can be decomposed as a direct sum of subspaces in S. This representation is not unique since H i can be written as direct sum of different collections of lines. Moreover, given that for any line l i s in F s q k \ H i , it holds that H i ⊕ l i s = F s q k , by using Proposition 2.1 again, we conclude that H i ⊕ S i s = F n q . As a consequence, the rows of the matrix form a basis of F n q . Moreover, any collection of j n rows of W i generates a jdimensional subspace of F n q . Denote by W ( j) i the submatrix of W i given by its first j rows. We also denote by W In addition, for any 1 . This fact allows us to define F W i the flag of type (1, . . . , k, n − k, . . . , n − 1) associated with W i in the following way: Finally, given the family of matrices {W i } L i=1 , we define the family of associated flags of type (1, . . . , k, n − k, . . . , n − 1): Let us see that C is an optimum distance flag code. To do so, we analyze the structure of its projected codes: and for all j = 1, . . . , k.

Proposition 3.9
Given the flag code C defined as above, for each j = 1, . . . , k the following is satisfied: (1) The code C j is a partial spread in G q ( j, n) with cardinality L = q n −1 q k −1 . (2) The code C k+ j is an equidistant (n−2k+2( j −1))-intersecting constant dimension code in G q (n − k + j − 1, n) with cardinality L = q n −1 q k −1 . As a consequence, C k+ j is a constant dimension code of maximum distance.
In particular, we have that C k = S and C k+1 = H.
Proof By construction, it is clear that C k = S and C k+1 = H. Now, for any 1 j k, given two different indices i 1 , i 2 ∈ {1, . . . , L}, we have that Hence, C j is a partial spread in the Grassmannian G q ( j, n) with |C j | = L.
To prove (2), consider subspaces W We know that dim(H i 1 ∩ H i 2 ) = (s − 2)k = n − 2k, and then, the subspace sum H i 1 + H i 2 is the whole space F n q . As a consequence, and then it follows that which is the minimum possible dimension of the intersection between subspaces of dimension n −k + j −1 of F n q . Thus, we conclude that C k+ j is an equidistant (n −2k + 2( j − 1))-intersecting constant dimension code with exactly L elements. In particular, we have that d S (C k+ j ) = 2(k − ( j − 1)) and C k+ j is a constant dimension code with the maximum distance.

Theorem 3.10
The flag code C defined in (15) is an optimum distance flag code of type (1, . . . , k, n − k, . . . , n − 1) on F n q with the k-spread S as a k-projected code. This code has cardinality |C| = L = q n −1 q k −1 and distance d f (C) = 2k(k + 1). Proof By means of Proposition 3.9, we conclude that C is a disjoint flag code of cardinality L with projected codes attaining the maximum distance for their corresponding dimensions. Then, by Theorem 3.1, C is an optimum distance flag code, that is, d f (C) = 2k(k + 1).

Remark 3.11
The code C defined in (15) attains the maximum possible distance for flag codes of type (1, . . . , k, n − k, . . . , n − 1) on F n q . Furthermore, by means of Theorem 3.2, it also has the best possible size among the optimum distance flag codes of the full admissible type vector on F n q .

The general case
Finally, in order to get an optimum distance flag code of any admissible type vector with a k-spread as a projected code, we apply a puncturing process to the code C defined in (15). This process was already used in [2] to get optimum distance flag codes having a planar spread as a projected code. Let us recall it. Fix an admissible type vector (t 1 , . . . , t r ), that is, a type vector such that k ∈ {t 1 , . . . , t r } ⊆ {1, . . . , k, n− k, . . . , n − 1}. Consider a flag F W i in the code C in (15). The punctured flag of type (t 1 , . . . , t r ) associated with F W i is the sequence The punctured flag code of type (t 1 , . . . , t r ) associated with C is the code given by Observe that the projected codes of C (t 1 ,...,t r ) are, in particular, projected codes of C. Hence, the next result follows straightforwardly from this fact, together with Theorem 3.2. (t 1 , . . . , t r ), the code C (t 1 ,...,t r ) defined as above is an optimum distance flag code on F n q with the spread S as a projected code. Its cardinality, which is L = q n −1 q k −1 , is maximum for optimum distance flag codes of this type.

Example
We conclude the paper with an example of our construction of an optimum distance flag code of type (2, 4) on F 6 2 having a 2-spread as its first projected code. To do this, we follow the steps given in Sect. 3.2.
Consider the bipartite graph Then, we have that F 4 = {0, 1, α, α 2 }. By using the package GRAPE of GAP and following the process described in [3], we have obtained the next perfect matching of Observe that every line l ∈ G 4 (1, 3) is a subspace of the (hyper)plane M(l). Even more, we have expressed every subspace M(l) as the rowspace of a 2×3 matrix whose the first row is precisely a generator of the line l. In this way, we obtain the optimum distance flag code of type (1, 2) on F 3 Now, let f (x) = x 2 + x + 1 be the minimal polynomial of α and consider its companion matrix P = 0 1 1 1 . If φ is the field isomorphism in (1), we have that φ(0) = 0 2 , φ(1) = I 2 and φ(α) = P. Taking the previous matching M and the field reduction ϕ induced by φ (2), we define the following optimum distance flag code of type (2, 4) on F 6 2 C = {(ϕ(l), ϕ(M(l))) | l ∈ G 4 (1, 3)}.

Conclusions and future work
In this paper, we have addressed the problem of obtaining flag codes of general type (t 1 , . . . , t r ) on a space F n q with the maximum possible distance and the property of having a k-spread as a projected code whenever k divides n. Firstly, we have showed that the existence of such codes might be not possible for an arbitrary type vector and have characterized the admissible ones. They have to satisfy the condition: k ∈ {t 1 , . . . , t r } ⊆ {1, . . . , k, n − k, . . . , n − 1}.
Given an admissible type vector, we have proved the existence of optimum distance flag codes of such a type with a spread as a projected code by describing a gradual construction starting from type (1, n − 1), following with type (k, n − k), to finish with the full admissible type {1, . . . , k, n − k, . . . , n − 1}. This construction is mainly based on two ideas: on the one side, we exploit the existence of perfect matchings in the bipartite graph with set of vertices given by the lines and the hyperplanes of F n q and edges given by the containment relation. On the other hand, we use the properties of the field reduction map that allow us to translate the spread of lines to a k-spread and to build our code from it. Our construction provides codes with the best possible size among optimum distance flag codes of any arbitrary admissible type vector.
In future work, we investigate the algebraic structure and features of this family of codes and explore other possible constructions. We also study the family of flag codes from spreads not necessarily having the maximum distance as well as the existence and performance of decoding algorithms for them.
Funding Open Access funding provided thanks to the CRUE-CSIC agreement with Springer Nature.

Data availability
The datasets generated during and/or analyzed during the current study are available from the corresponding author on reasonable request.