Manuscript Offprint
arXiv:2611.03578Uniform Sampling of Linear Codes with Prescribed Hull Dimension
Abstract
We give exactly uniform samplers for linear codes with prescribed hull dimension, for the Euclidean, Hermitian, and symplectic inner products and over finite fields of every characteristic. Except for the Euclidean form over fields of odd characteristic, these are the first uniform samplers for arbitrary prescribed hull dimension. Each sample costs an expected field operations for codes of dimension in a space of dimension over or .
Keywords— Linear codes, hull dimension, uniform sampling, classical groups, Witt's theorem, LCD codes, self-orthogonal codes, entanglement-assisted quantum codes, code-based cryptography.
1 Introduction
Up to a scalar, a non-degenerate reflexive form on a finite-dimensional vector space is symmetric, alternating, or Hermitian [30, Thm. 7.1]. On codes these give the Euclidean, symplectic, and Hermitian inner products, and for each of them the hull Hull() := of a code plays an important role in coding theory, cryptography, and quantum error correction. Binary Euclidean LCD codes (Hull() = 0) are used in countermeasures against side-channel and fault-injection attacks [9]. Euclidean self-orthogonal codes (Hull() = ) are needed for instance generation in the code-based signature scheme SPECK [4], and codes with a prescribed Euclidean hull dimension
*K. Ishizuka is with the Information Technology R&D Center, Mitsubishi Electric Corporation, Kamakura, Japan (e-mail: keitaishizuka1994@gmail.com).
†This work was supported by JSPS KAKENHI Grant Number JP25K17290.
are the central primitive of the Hollow LWE encryption scheme [1]. Codes in with symplectic hull dimension are the check spaces of entanglement-assisted (EA) stabilizer codes on qudits that consume ebits, and codes in with Hermitian hull dimension give EA stabilizer codes consuming ebits [7, 33] for qubits and [16] for all ; the self-orthogonal case is that of ordinary stabilizer codes [3, 8, 20]. Uniform sampling of such codes is useful in each of these settings: it offers a complementary approach to the classification of codes, it drives Monte Carlo simulation of quantum codes, and in Hollow LWE and SPECK the uniform sampling of codes with prescribed Euclidean hull dimension is part of the scheme itself.
For the Euclidean inner product, Albrecht, Benčina, and Lai gave a partial result in Hollow LWE [1]: their sampler grows the hull one dimension at a time and is proved uniform when , where is the dimension and the hull dimension. The same authors later gave a sampler for odd that, for and polynomial in , aborts with negligible probability and is otherwise exactly uniform for a prescribed hull dimension and square class of the discriminant of [2, Thm. 28], with the mass formula of Li, Shi, and Ling [22] used in the analysis; for a prescribed hull dimension alone, it picks the square class uniformly at random and is within total variation distance of uniform [2, Cor. 30]. The case of even was left open. For self-orthogonal codes and odd , an -uniform sampler was given in the conference version of the present paper [19]. For the Hermitian and symplectic inner products, uniform samplers are known only for special hull dimensions. Uniformly random symplectic self-orthogonal codes, that is, stabilizer codes, are obtained by applying a uniformly random Clifford operator to a fixed stabilizer code, and the -qubit Clifford group can be sampled exactly [6, 21]. No uniform sampler was available for a prescribed Hermitian or symplectic hull dimension, that is, for EA codes with a prescribed number of ebits. Table 1 summarizes the situation.
Table 1: Exactly uniform samplers of codes with prescribed hull dimension and dimension .
| inner product | previous work | this work |
|---|---|---|
| symplectic | [6, 21] | all , all |
| Hermitian | none | all , all |
| Euclidean, odd | all , per square class [2] | all |
| Euclidean, even | none | all |
The algorithm is simple and general: a single framework covers all three inner products and every . For each inner product, the isometry group (the orthogonal, pseudo-symplectic, unitary, or symplectic group) acts on the codes of given length, dimension, and hull dimension with at most four orbits. Once a simple representative of each orbit is fixed, the problem therefore reduces to the uniform sampling of an element of , and any sampler of can be used for this step. By making the subgroup algorithm of Diaconis and Shahshahani [13] explicit for our groups and accelerating it, we obtain exactly uniform samplers that take an expected operations, where is the dimension of the code and the dimension of the ambient space ( for the Euclidean and Hermitian forms and for the symplectic form).
Compared with previous work, the samplers have three advantages. They cover the Hermitian and symplectic forms and the Euclidean form with even, which were left open. For the Euclidean form with odd, their expected cost is proved for all , and , whereas the bounds on the abort probability and running time of the sampler of [2] assume that and are polynomial in . They are faster: the sampler of [2] is proved to run in time for its LCD part and for each hull vector, where is the exponent of matrix multiplication [2, Lems. 17, 24], whereas ours costs an expected operations in total (Corollary 32).
The rest of the paper is organized as follows. Section 2 recalls the three inner products, Witt's theorem, the Anzahl theorems and their relation to the mass formulas of coding theory together with the two counts we use, facts on finite fields, and the facts on uniform sampling that we use. Section 3 presents the framework: Algorithm 1 reduces the uniform sampling of codes to (i) the orbits of the isometry group and their sizes, (ii) a representative of each orbit with a simple generator matrix, and (iii) a uniform sampler of the isometry group. Sections 4–7 provide these items for the symplectic form (one orbit), the Hermitian form (one orbit), the Euclidean form with odd (at most two orbits), and the Euclidean form with even (at most four orbits); we begin with the symplectic form, since it is the easiest case and the case of even builds on it. Section 8 discusses applications and Section 9 concludes.
2 Preliminaries
2.1 Three inner products and their hulls
We consider three spaces , each with a non-degenerate form :
-
Euclidean: and , symmetric and bilinear.
-
Hermitian: and with , sesquilinear with .
-
Symplectic: and for , bilinear and alternating, .
A (linear) code is a subspace : codes are -linear in the Euclidean and symplectic cases and -linear in the Hermitian case; we write for the field of scalars and , so respectively. We write for the standard basis of ; in the symplectic case and () are the -th unit vectors of the -part and of the -part of , so that and . A code of dimension is given by a generator matrix with .
In all three cases if and only if , so the dual code is well defined, of dimension , and the hull is . The code is LCD if and self-orthogonal if .
Remark 1. The hull is the radical of the restricted form, , and is LCD or self-orthogonal exactly when is non-degenerate or zero. From here on we use the terms of the theory of forms (radical, non-degenerate, totally isotropic) when we work with , and keep the terms of coding theory for statements about codes.
Our object is the family
written , , when the inner product has to be named. The Euclidean family contains the LCD and self-orthogonal codes used in side-channel countermeasures and code-based cryptography, and the Hermitian and symplectic families are the check spaces of EA stabilizer codes with and ebits (Section 8). The Gram matrix of vectors is .
Lemma 2 (Hull dimension and admissibility). Let have basis and hull dimension .
(1) .
(2) induces a non-degenerate form on the quotient , of the same kind as ; in particular is even in the symplectic case.
(3) .
Proof. (1) The vector lies in exactly when for all , so corresponds to the left kernel of the Gram matrix. (2) For and we have , so is well defined, and forces ; a non-degenerate alternating form exists only in even dimension. (3) , and .
We call the non-degenerate quotient of ; it has dimension . For every complement of in , , the space is non-degenerate and isometric to via , by Lemma 2(2).
2.2 Isometry groups and Witt's theorem
An injective linear map between subspaces is an isometry if for all . The isometry group of is : the orthogonal group , the unitary group , and the symplectic group in the three cases; for even the Euclidean case is special and is treated in Section 7. We let act on row vectors from the right and write , so that . Since , we have and , so acts on .
Theorem 3 (Witt's extension theorem [30, Thm. 7.4]). Let be a non-degenerate space whose form is alternating, Hermitian, or symmetric over a field of odd characteristic. Every isometry between two subspaces of extends to an element of the isometry group of .
Theorem 3 fails for symmetric forms in characteristic 2 that are not alternating, which is why the Euclidean form with even is treated separately. Together with the well-known fact that a degenerate form is the orthogonal sum of its radical and a non-degenerate form [30, Ch. 7], it reduces transitivity on to the classification of non-degenerate forms of dimension ; we record this standard consequence in the form we use.
Lemma 4 (Transitivity criterion). In the setting of Theorem 3, let . If the non-degenerate quotients and are isometric, then for some .
Proof. Choose complements of in and of in ; they are isometric to the non-degenerate quotients, hence to each other. Let be an isometry and any linear bijection. Then is an isometry: vanishes on and on , so only the -block contributes. Theorem 3 extends to some , and .
For a totally isotropic subspace of dimension , a Witt decomposition is , where is totally isotropic of dimension with bases of and of satisfying , and ; such exists by [30, Lemma 7.5], and is non-degenerate and isometric to because .
2.3 Anzahl theorems and mass formulas
A code is a -dimensional subspace whose restricted form has a radical of dimension and induces on the form of Lemma 2(2), so its isometry type is determined by and the isometry class of . Counting the subspaces of a finite non-degenerate space by the isometry type of the restricted form is a classical problem of finite geometry [32, §3]. Segre counted the totally singular subspaces of a quadric, and Pless counted the totally isotropic subspaces of a symplectic space. In 1964–1966 Wan and his students Dai, Feng, and Yang determined the sizes of all orbits of subspaces under the symplectic, unitary, and orthogonal groups, and called these results the Anzahl theorems; Liu and Wan later did the same for the pseudo-symplectic group [25]. The results are compiled in [31] and surveyed in [32]. For the inner products of this paper, they give the number of codes of each dimension, hull dimension, and isometry type.
In coding theory, the same numbers were later obtained independently, under the name of mass formulas and in different terminology and notation.
Sendrier [28] expressed the number of codes with a given hull dimension through the numbers of self-orthogonal codes, Carlet et al. [10] counted LCD codes for and for odd through the action of the orthogonal group, and Li, Shi, and Ling [22, 24] counted codes with arbitrary prescribed hull dimension for the Euclidean, Hermitian, and symplectic forms. In this paper, orbit sizes are needed only for the weights of Algorithm 1 when there is more than one orbit. We take them from the mass formulas of coding theory where these give the counts we need, since their notation is closer to ours; for even, the split of into the four orbits of Section 7 is not stated there for , and we use the Anzahl numbers. The history above is recalled to acknowledge the Anzahl theorems.
The counts we use are stated where they are needed: the symplectic Anzahl theorem in Section 4, the mass formula of Li, Shi, and Ling for odd in Section 6, and the pseudo-symplectic Anzahl numbers in Section 7.
2.4 Finite fields
We collect the facts about finite fields used in Sections 5 and 6. The group is cyclic of order [18, Ch. 7, §1, Thm. 1]. For odd, let be the quadratic character of , extended by , and the subgroup of non-zero squares. Since is cyclic, for odd is its unique subgroup of index 2, and is a square if and only if (Euler's criterion), so is computed in operations by repeated squaring.
Lemma 5. For an odd prime power , the element is a square in if and only if .
Proof. By Euler's criterion, is a square if and only if , that is, .
Lemma 6. For any odd prime power and any , there exist such that .
Proof. The sets
each have size . Since , the two sets intersect by pigeonhole, yielding with , i.e., .
For the field with conjugation , the norm maps onto [30, Lemma 10.1(v)], so each value is taken by exactly
elements. Moreover, maps onto ker N, and every element of ker N is the image of exactly elements: , and in the cyclic group of order the image of the -th power map has order .
Lemma 7 (Cipolla's method [17, §2]). Let be odd and . If is such that is a non-square, then is irreducible over , and is a square root of . Drawing uniformly from gives such a after an expected draws, so a square root costs an expected operations in .
2.5 Uniform sampling
All sets in this paper are finite. For a finite set we write for the uniform distribution on , and for distributions on we use the total variation distance . A randomized algorithm with output distribution on is an exactly uniform sampler of if , and an -uniform sampler if . For a map , the push-forward is the distribution of for , that is, .
Lemma 8 (Push-forward and mixtures). Let be distributions on .
(1) For every map , .
(2) For distributions on and weights with , .
(3) If a finite group acts transitively on and , then the orbit map , , satisfies ; hence if is an -uniform distribution on , then is -uniform on , and in particular if .
(4) If with non-empty and , then .
Proof. (1) for every . (2) . (3) The elements with form the coset , so every element of is the image of exactly elements of ; and by (1). (4) For the left-hand side takes the value .
Algorithm 1 Uniform sampler for
Require: an inner product, parameters with
Ensure: exactly uniform
1: Preprocessing (once): for each non-empty orbit , construct and
2: draw an orbit with probability
3: draw from the sampler of
4: return
3 The Framework
Let be the decomposition into -orbits, and suppose that we have (i) the orbit sizes, (ii) a generator matrix of a representative of each non-empty orbit, and (iii) a sampler of . Algorithm 1 combines them.
Theorem 9 (Uniformity). Given (i) and (ii), if the sampler of in (iii) is -uniform, then the output of Algorithm 1 is -uniform on ; in particular, an exactly uniform sampler of gives an exactly uniform sampler of . Each call costs one draw of plus operations in .
Proof. Let be the distribution of and , , the orbit map of the representative of . By Lemma 8(3), is the uniform distribution on , so by Lemma 8(4) and the choice of the uniform distribution on is . The output has distribution , so by Lemma 8(2) and (1),
The product costs .
When there is a single orbit, item (i) is not needed and line 2 disappears. In the rest of this paper we provide, for each inner product, (i) the orbits and their sizes, (ii) a standard representative of each orbit, and (iii) a uniform sampler of ; for (iii) we use the subgroup algorithm of Diaconis and Shahshahani, which we now recall.
3.1 Uniform sampling of the isometry group
By Theorem 9, any sampler of can be used in line 3, and uniform sampling of group elements can be done in several ways. For a group given only by generators, black-box methods such as Babai's algorithm [5] and the Cooperman–Dixon cube construction [12,15] return approximately uniform elements, and the product replacement algorithm [11] is a practical method for the same purpose. For the classical groups over , the subgroup algorithm of Diaconis and Shahshahani [13], which they work out for along the chain of stabilizers of the successive basis vectors [13, §2], gives exact samplers tailored to the group, which are used in Sections 4–7. We state the subgroup algorithm in the form we use; Witt's theorem is what makes each step uniform.
Lemma 10 (Uniform isometry, one vector at a time; cf. [13, §2]). In the setting of Theorem 3, let be the isometry group of and linearly independent vectors of , . Draw successively, uniformly from
(1)
Then each is non-empty with depending only on , and is distributed as for a uniform . In particular, for the map with is an exactly uniform element of .
Proof. Suppose that () is an isometry, which holds for . By Theorem 3 it extends to some , and maps the set (1) computed for bijectively onto the set computed for ; the former contains , so is non-empty and depends only on . Any extends the isometry to . Hence the procedure produces exactly the tuples , , each with probability . The elements giving the same tuple form a coset of the pointwise stabilizer of , so the map pushes forward to the uniform distribution on these tuples, as in Lemma 8(3).
The only step of Lemma 10 that depends on the group is the uniform draw from , which Sections 4–7 carry out explicitly. Each is cut out by a linear system and at most one further condition on , which we meet by rejection and rescaling; the linear part is handled by the following lemma.
Lemma 11 (Cost of the draws). Let and , and keep the system () in reduced row echelon form. A uniform solution costs operations, and adding the equation of a further vector costs . Hence, if each is obtained from an expected uniform solutions of the system for and further operations, then cost an expected operations.
Proof. The map is linear, and in the Hermitian case is linear, so the conditions form a linear system of equations in unknowns. In reduced row echelon form, a uniform solution is obtained by choosing the non-pivot coordinates uniformly and solving for each of the at most pivot coordinates with operations. A new equation is reduced against the existing rows in operations and, if it has a new pivot, eliminated from them in operations.
In particular, the whole of costs an expected operations in all our cases.
3.2 Truncation
With the group samplers of Sections 4–7, a call of Algorithm 1 costs , dominated by line 3. Line 4, however, uses only a few rows of .
Proposition 12 (Truncation). Let be a basis of , and suppose that the sampler of in line 3 draws vectors in this order and returns the map with , and that is exactly uniform on . Write with and the matrix with rows , and let be the matrix with rows . Then is distributed as for a uniform ; so the sampler can be stopped after without changing the output distribution of Algorithm 1.
Proof. The first draws are made before the others, so stopping after does not change their distribution, which is that of for a uniform . The code is a function of , and it equals when ; push forward by Lemma 8.
In Sections 4–7 the representatives involve basis vectors, and the group samplers draw the images of the basis vectors in an order that starts with them. Since the -th draw costs an expected by Lemma 11, stopping there costs an expected operations for (Corollaries 18, 23, 32, and 41).
4 Symplectic Form
Throughout this section is arbitrary, with the symplectic form, and .
4.1 Orbits
Theorem 13 (Classification of alternating forms [30, p. 69]). Every non-degenerate alternating form over a field has a symplectic basis; in particular its dimension is even, and two such forms of the same dimension are isometric.
Together with Lemma 4 this gives a single orbit.
Theorem 14 (Orbits, symplectic form). if and only if , is even, and . In that case acts transitively on .
Proof. The conditions are necessary by Lemma 2(2)–(3), and sufficient by Proposition 16 below. For , the non-degenerate quotients are non-degenerate alternating of dimension , hence isometric by Theorem 13, and Lemma 4 gives transitivity.
The size of this orbit is the symplectic Anzahl number. The sampler does not need it, but Section 7 uses it.
Theorem 15 (Symplectic count [31, Thm. 3.18]). Let with even and . Then
4.2 Standard representative
Proposition 16 (Symplectic representative). For admissible put . The matrix
in coordinates , with column blocks of widths on each side, generates a code in whose hull is spanned by the first rows.
Proof. The blocks fit, since is equivalent to , and the rows are distinct standard basis vectors, hence independent. Write for the rows. For , the row has its only non-zero entry in column of the -part, and column of the -part is zero in every row, so is orthogonal to all rows. For , the rows and have their non-zero entries in column of the -part and of the -part, respectively, so , and all other pairs among these rows are orthogonal. The Gram matrix is therefore , of rank ; Lemma 2(1) gives hull dimension , and the hull is spanned by .
4.3 Uniform sampling of the symplectic group
A uniform element of is obtained by drawing a uniform symplectic basis.
Proposition 17 (Uniform symplectic transformation). Draw vectors of successively: with , let be uniform on and uniform on . Then the map with and is exactly uniform on , and it is obtained in an expected operations in .
Proof. Uniformity. We apply Lemma 10 to the basis of Section 2.1 in the order , so that and are the images of and . In this basis and all other pairs are orthogonal, and for all . So the conditions of Lemma 10 say that is orthogonal to , and that is orthogonal to these vectors with . By induction the span of is non-degenerate, so it meets only in 0, and
By Lemma 10, is therefore uniform on once each and has the stated distribution. We draw by drawing a uniform element of and redrawing the zero vector, which gives a uniform non-zero vector of . For , draw uniformly from until and put . Every with equals for exactly the vectors , , so is uniform on the required set.
Cost. The subspace is the solution space of the linear system for the vectors drawn so far, so by Lemma 11 it suffices that and need an expected uniform elements of each. The zero vector has probability . Since is non-degenerate and , is a non-zero linear functional on , so has probability . Both loops therefore end after at most two rounds in expectation, so the -th pair costs an expected , and summing over gives .
For the samplers of [6,21] can be used instead. The sampler of Koenig and Smolin [21] also builds from successive symplectic pairs, as above, at the same cost ; that of Bravyi and Maslov [6] samples a canonical decomposition of the Clifford group in time with the least possible number of random bits. Both are specific to , while Proposition 17 applies to every .
Corollary 18 (Symplectic sampler). For every and every admissible , Algorithm 1 with Theorem 14, Proposition 16, and Proposition 17 returns an exactly uniform element of in an expected operations in .
Proof. Uniformity follows from Theorem 9 and Proposition 17. The rows of are () and (), with ; they are among the images of the first pairs. By Proposition 12 the sampler of Proposition 17 can be stopped after these pairs, which by its proof cost an expected operations.
5 Hermitian Form
Throughout this section is arbitrary, with the Hermitian form, , and N is the norm of Section 2.4.
5.1 Orbits
Theorem 19 (Hermitian forms [30, p. 117, Lemma 10.1(v)]). Every non-degenerate Hermitian form over has an orthonormal basis; in particular two such forms of the same dimension are isometric.
Indeed, such a form has an orthogonal basis of non-isotropic vectors [30, p. 117], and as the norm is onto (Section 2.4), these can be rescaled to unit vectors. Together with Lemma 4 this gives a single orbit.
Theorem 20 (Orbits, Hermitian form). if and only if and . In that case acts transitively on .
Proof. Necessity is Lemma 2(3) and sufficiency is Proposition 21. The non-degenerate quotients have the same dimension , hence are isometric by Theorem 19, and Lemma 4 gives transitivity.
5.2 Standard representative
Proposition 21 (Hermitian representative). Fix with : for even take , and for odd take for any non-square of , so that . For admissible the matrix
generates a code in .
Proof. The first rows of have the entries in the disjoint column pairs , and the last rows are the unit vectors in columns . The supports are disjoint, so the rows are independent and pairwise orthogonal. Each of the first rows has , and each of the others has . The Gram matrix is , and Lemma 2(1) gives hull dimension .
5.3 Uniform sampling of the unitary group
A non-degenerate Hermitian space of dimension contains
isotropic vectors, the zero vector included [30, Lemma 10.4]; we use this to bound the rejection rate below.
Proposition 22 (Uniform unitary transformation). Draw successively: with , let be uniform on the anisotropic vectors of , let be uniform on , and put . Then the map with is exactly uniform on , and it is obtained in an expected operations in .
Proof. Uniformity. We apply Lemma 10 to the standard basis , which is orthonormal: for and . So the conditions of Lemma 10 say that is orthogonal to and that . Since is non-degenerate, it meets only in 0, so is the set of unit vectors of , and it suffices that is uniform on this set. Let be the set of anisotropic vectors of ; drawing uniformly from until the vector is anisotropic gives uniform on . For , take any solution of and put with uniform on ; since maps onto ker and every element of ker is the image of exactly elements (Section 2.4), is uniform on the solutions. A unit vector arises exactly from the pairs , , each of probability , so every unit vector has the same probability.
Cost. A round of the rejection for is accepted with probability at least 3/8 by (3), so by Lemma 11 all together cost an expected . One solution of a norm equation is computed for each , at an expected operations (for even ; for odd, with , draw until is a square and take by Lemma 7), and costs .
Corollary 23 (Hermitian sampler). For every and every admissible , Algorithm 1 with Theorem 20, Proposition 21, and Proposition 22 returns an exactly uniform element of in an expected operations in .
Proof. Uniformity follows from Theorem 9 and Proposition 22. Since uses only its first columns, Proposition 12 stops the sampler of Proposition 22 after ; by its proof this costs an expected operations and solutions of norm equations, each costing an expected .
6 Euclidean Form, Odd
Throughout this section is odd, with the Euclidean form, and .
6.1 Orbits
The discriminant of a non-degenerate symmetric form is the determinant of a Gram matrix modulo , an element of that does not depend on the basis; the standard form has Gram matrix and discriminant 1. The Witt type of a code is the discriminant of its non-degenerate quotient,
with when ; equivalently, for any complement of in . We write for the codes of Witt type ; in the notation of [22], and are the sets and of codes of Type and Type , since the Type is defined by whether the discriminant of is a square [22, Prop. 3].
Theorem 24 (Classification of symmetric forms [26, Lemma 6]). Two non-degenerate symmetric bilinear forms over of the same dimension are isometric if and only if they have the same discriminant.
Lemma 25 (Witt type is invariant). For and every code , .
Proof. Since maps onto , it induces a linear bijection , and ; so the induced forms are isometric and have the same discriminant.
Theorem 26 (Orbits, Euclidean form, odd). Each non-empty is a single -orbit, so consists of at most two orbits.
Proof. Different Witt types lie in different orbits by Lemma 25. If , the non-degenerate quotients of and have the same dimension and the same discriminant, so they are isometric by Theorem 24, and Lemma 4 gives with .
The largest dimension of a totally isotropic subspace is the Witt index of the standard form, which is , except that it is when is even and the form has minus type [30, pp. 138–139], that is, since the standard form has discriminant 1; see also [27, §3.2]. Hence
The next lemma records exactly which Witt types occur.
Lemma 27 (Non-empty orbits). if and only if
where if , if and , and otherwise.
Proof. The first two conditions are necessary by Lemma 2, and the third holds because is totally isotropic. Let and choose a Witt decomposition . Then is the orthogonal sum of and the space , whose Gram matrix has discriminant . Since discriminants multiply on orthogonal sums and , writing with gives
If then and ; if then and (5) gives . Conversely, Proposition 29 constructs a code in for every tuple satisfying (4).
The orbit sizes are given by the mass formula of Li, Shi, and Ling. Write and for the Gaussian binomial coefficient.
Theorem 28 (Euclidean count, odd [22, Thms. 4, 5]). Let be odd, , and with . For [10, Thm. 31], equals, in the four cases (i) odd and even, (ii) and odd, (iii) even and odd, (iv) and even,
(i)
(ii)
(iii)
(iv)
and for
For there is a single orbit, and for the only code is ; in these cases no weights are needed.
6.2 Standard representatives
By Lemmas 5 and 6 we can fix with if , and with if , and put
so that and . Fix also with a non-square (take if ). We distinguish three cases: (a) ; (b) and is even; (c) and is odd. The representatives are built from a totally isotropic block for the radical and a non-degenerate block for a complement:
-
hull block : in case (a); in case (b); in case (c). Here in (a) and (b) and in (c), and .
-
LCD block , with : , and , so that is diagonal with discriminant .
Proposition 29 (Euclidean representatives, q odd). Let satisfy (4).
(1) Except in case (c) with , the matrix , padded with zero columns, generates a code in .
(2) In case (c) with , the matrix
with copies of and , generates a code in .
Proof. (1) The rows are independent, and the Gram matrix is with diagonal, non-singular, of discriminant . By Lemma 2(1) the hull dimension is ; the radical is the row space of and the rows of span a complement of discriminant . It remains to check that the blocks fit in columns. Their width is in cases (a) and (b) with , and in cases (a) and (b) with and in case
(c) with . The first is at most by (4). For the second we need . If and , then by Lemma 27, which is +1 in cases (a) and (b) and -1 in case (c), opposite to the cases at hand. If , only occurs, and in case (c) would give with and .
(2) The construction of (1) would need columns, two more than may be available. Instead, the last hull row and the first LCD row share three columns in the block ; they are orthogonal, since , and is a non-square. The Gram matrix is , so the hull dimension is and the Witt type is . The last non-zero column is .
6.3 Uniform sampling of the orthogonal group
As for the unitary group, we draw an orthonormal basis by rejection and rescaling, which now needs a square root. Squares are recognized by Euler's criterion and square roots are computed by Lemma 7.
The rejection rate of the orthogonal sampler is bounded with the numbers of solutions of diagonal quadratic equations.
Lemma 30 (Solution counts [23, Thms. 6.26–6.27]). Let , , and . The number of with is for even, where and for , and for odd.
Proposition 31 (Uniform orthogonal transformation). Draw successively: with , draw uniformly from until is a non-zero square, compute a square root of by Lemma 7, and put . Then the map with is exactly uniform on , and it is obtained in an expected operations in .
Proof. Uniformity. We apply Lemma 10 to the standard basis , which is orthonormal; as in the proof of Proposition 22, is the set of unit vectors of , and it suffices that is uniform on this set. Let be the set of with a non-zero square, so that is uniform on , and let be the probability that the square-root computation returns on input ; it depends only on , and for . A unit vector arises exactly from the pairs with , so it is returned with probability , the same for every unit vector.
Cost. We bound the success probability of a round. The space is non-degenerate of dimension and contains a unit vector, since . If , then with , and is a non-zero square unless , with probability . If , Lemma 30 in an orthogonal basis of shows that each is taken by at least vectors for even and at least for odd, so a round succeeds with probability at least . By Lemma 11 the rounds cost an expected operations in total. Each round also evaluates once, at operations, and each vector needs one square root, at an expected operations by Lemma 7, which adds .
Corollary 32 (Euclidean sampler, odd). For every admissible , Algorithm 1 with the orbits of Theorem 26, the weights from (6) (with for ), the representatives of Proposition 29, and the group sampler of Proposition 31 returns an exactly uniform element of in an expected operations in .
Proof. Uniformity follows from Theorem 9, Theorem 26, and Proposition 31. Since uses only its first columns (proof of Proposition 29), Proposition 12 stops the sampler after ; by its proof this costs an expected operations. The weights are computed once from Theorem 28: the factors that do not involve are common to both signs, and the factor of (6) cancels against the same factor of , so is a ratio of two products of at most two factors of the form .
7 Euclidean Form, Even
Throughout this section is even, with the Euclidean form, and is defined below. Put , so that , and ; then . The form is symmetric with Gram matrix but not alternating: it vanishes on the diagonal exactly on the hyperplane , the even-weight subspace when . Theorem 3 is therefore not available, and the isometry group
is the pseudo-symplectic group [25]. We use three known results: Theorem 33 below, due to Dieudonné [14] (see [32, p. 370]), and Theorems 34 and 35 in
Section 7.1, due to Liu and Wan [25] (see also [32, (19)–(25)]). The first reduces to a symplectic group.
Theorem 33 (The group, cf. [14,26]). (1) If is odd, then with symplectic of dimension , and is an isomorphism , so .
(2) If is even, then for every with , with symplectic of dimension . For any with , the map is a bijection from onto the symplectic isomorphisms . Hence acts transitively on the vectors with , with stabilizers isomorphic to , and .
In both cases every element of fixes and preserves .
So the geometry of reduces to that of the symplectic space for odd, and of for even.
7.1 Orbits
For a code put if and otherwise, and if and otherwise. Thus says that is alternating.
Theorem 34 (Orbits, Euclidean form, q even [25]). Let and .
(1) Two codes of lie in the same -orbit if and only if they have the same pair . Hence consists of at most four orbits .
(2) if and only if
(0,0): is even and ;
(1,0): and ;
(1,1): , and is odd (n odd) or even (n even);
(0,1): n is even, , is even, and .
In the rest of this section , so that for odd and for even.
Theorem 35 (Orbit sizes, even [25], [32, (25)]). If is odd, then ,
and if n is even, then
Remark 36. In the notation of Liu and Wan [25] (see [32, pp. 370–371]), is the set of subspaces of type with , where if , if and is odd, and if and is even. In this notation Theorem 34(2) is [32, (22)–(23)], and Theorem 35 is the orbit length of [32, (25)], written in terms of the symplectic counts, with for odd (the value printed there for is a misprint).
7.2 Standard representatives
As for odd, the representatives are assembled from a few small blocks, now with entries in , so the construction is the same for every even :
-
hull block , whose rows are isotropic, of even weight, and pairwise orthogonal;
-
alternating block for even , with rows ( ), and the empty matrix;
• anisotropic block
The rows of have even weight, and their Gram matrix is the tridiagonal matrix with zero diagonal and ones next to it, the adjacency matrix of a path on m vertices. Block-diagonal matrices are padded with zero columns to width n.
Lemma 37 (Path matrix). The determinant of satisfies for , with and (and ); so is non-singular for even and singular for odd .
Proof. Expanding along the first row, the only non-zero entry is the 1 in position , and its minor has first column , so it equals ; hence .
Proposition 38 (Representatives, even). If satisfies the condition of Theorem 34(2), then the matrix of Table 2 generates a code in .
Table 2: Representatives of the Ps-orbits for even. Rows separated by a semicolon are stacked; diag() is padded with zero columns to width , and diag() is diag() with added to its row .
| condition | generator matrix | ||
|---|---|---|---|
| any | even, | diag | |
| odd | even, | diag | |
| odd | odd, | diag | |
| even | odd, | ; diag | |
| even | even, | ; diag | |
| odd | odd, | ; diag | |
| even | even, | ; ; diag | |
| even | , even, | ; diag |
Proof. The block diag occupies columns if and columns if , hence at most columns in every row of the table. Under the conditions of Theorem 34(2) this is at most for even and at most for odd, since (e.g., for even, , and even); in particular column of the block is zero for even. We use , , and ; blocks with disjoint supports are orthogonal. We give the Gram matrix and the invariants in each case.
Case . The Gram matrix is with the non-singular path matrix of size , so ; all rows have even weight, so ; and , since for odd and column is zero for even.
Case , odd. Write for the block rows, which have even weight, so that . The Gram matrix is that of the block plus a 1 in position : for even it is , where is the path matrix with an extra 1 in its first diagonal entry; expanding along the first row, by Lemma 37, since ; for odd it is . So ; row has , so ; and : if , where is the coefficient of row , then applying , which vanishes on the , gives , so with , contradicting the independence of the block rows; so .
Case , even. The vector is orthogonal to the block rows, , and is isotropic and orthogonal to the other block rows; so the Gram matrix is for odd and for even, and . gives . All rows other than lie in , and , so is spanned by them; as , would give , with the coefficient of row ( for odd). Since column of the block is zero, column gives , which is impossible for odd; for even it gives with , contradicting the independence of the block rows; so .
Case , odd. The Gram matrix is , because is anisotropic and orthogonal to the even-weight rows, so ; gives . The rows are independent because .
Case , even. The Gram matrix is , so , and . For independence, the other rows lie in and vanish in column ; a relation forces , hence since is odd, and then .
Case , even. The vector is isotropic and orthogonal to every even-weight row, so the Gram matrix is and ; all rows lie in , so , and . The rows are independent because only is non-zero in column .
In each case , and Lemma 2(1) gives the hull dimension.
7.3 Uniform sampling of the pseudo-symplectic group
Theorem 3 fails in , so Lemma 10 cannot be applied in itself. Instead, by Theorem 33 an isometry fixes , and for even it is determined by the image of a vector with together with a symplectic isomorphism ; for odd it is determined by its restriction to the symplectic space . The symplectic part is drawn by Lemma 10 exactly as in Proposition 17, with the orthogonal complement, inside (or ), of the vectors drawn so far. The group sampler thus maps a fixed basis adapted to this decomposition onto a random one; we fix the following explicit basis. Write for .
Lemma 39 (An explicit symplectic basis). Let , and for put and . Then and , so these vectors form a symplectic basis of a non-degenerate subspace of dimension , and for odd and for even.
Proof. All have even weight, so they lie in . Since , we get , for , and . Hence is non-degenerate of dimension and ; because , and for even because the supports lie in .
Proposition 40 (Uniform pseudo-symplectic transformation). Let be the basis of Lemma 39. For even, draw uniformly from , put , and draw a symplectic basis of by the recursion of Proposition 17 started from ; for odd, draw such a basis of , started from . Then the map with , ( even), , and is exactly uniform on , and it is obtained in an expected operations in .
Proof. Uniformity. By Lemma 39, for even and for odd, with symplectic basis . Since is linear and , is uniform on the vectors with . Given , Proposition 17 gives a uniform symplectic basis of , so the map , is uniform on the symplectic isomorphisms . By Theorem 33(2) with , is uniform on ; for odd, Theorem 33(1) and Proposition 17 give the same.
Cost. Drawing costs , since it needs one uniform vector and the sum ; the symplectic basis costs an expected by Proposition 17. In matrices, , where the rows of are (without for odd) and those of their images; is computed once, and costs .
Corollary 41 (Euclidean sampler, even). For every admissible , Algorithm 1 with the orbits of Theorem 34, their sizes from Theorem 35, the representatives of Proposition 38, and the group sampler of Proposition 40 returns an exactly uniform element of in an expected operations in .
Proof. Uniformity follows from Theorem 9, Theorem 34, and Proposition 40. The sampler draws the images of the basis in this order (without for odd). In this basis (with ) and , so every row of a block or with is a combination of with . The representatives of Table 2 consist of such rows, , and , with block width . By Proposition 12 the sampler can therefore be stopped after the first pairs, which cost an expected operations as in the proof of Proposition 17.
8 Applications
8.1 Code classification
Classification of codes up to permutation equivalence usually proceeds by systematic enumeration, in which candidate generator matrices are visited in a fixed order and compared with a growing list of inequivalent representatives; equivalence classes that lie late in the order may never be reached in practice. The samplers supply a complementary approach. A permutation of acts on by permuting coordinates, in the symplectic case simultaneously on both halves of ; it preserves , hence . For a code let be the group of such permutations fixing .
Proposition 42 (Coverage). Let be the permutation-equivalence classes in , and . A uniform draw from lies in with probability , and independent draws, , meet every class with probability at least .
Proof. The class is the orbit of under these permutations, so it has elements. A fixed class is missed by all draws with probability , and the union bound over the classes gives the claim.
Completeness of a list of representatives is certified exactly by the mass formula: the list is complete if and only if , with the right-hand side given by the Anzahl theorems [31, 32]. The two approaches complement each other: the classes hit least often are those with large automorphism groups, and once these highly symmetric codes have been classified by algebraic constructions, most of the remaining classes have trivial automorphism group and are hit with the largest probability
; with taken over the remaining classes, Proposition 42 then requires far fewer draws than for all classes.
8.2 Public-key cryptography
The Support Splitting Algorithm of Sendrier [29] solves the Permutation Equivalence Problem in time growing as in the hull dimension , so code-based schemes whose security reduces to this problem prefer self-orthogonal codes, for which is largest. The SPECK signature scheme [4] samples a uniformly random self-orthogonal code for its key generation ( [4, Sec. 6, Def. 3]), and the Hollow LWE scheme [1] samples uniformly random codes with prescribed hull dimension. SPECK points to the sampler of [1], which is proved uniform only for . The sampler of [2] covers odd ; for and polynomial in it aborts with negligible probability and is otherwise exactly uniform for a prescribed hull dimension and square class [2, Thm. 28], and for a prescribed hull dimension alone it is within total variation distance of uniform [2, Cor. 30], and weighting the square classes by their sizes makes it exactly uniform (Section 1). Corollaries 32 and 41 give exact uniformity in every characteristic; in particular, schemes over with a prescribed hull dimension obtain a uniformity guarantee only from Corollary 41. For odd , our sampler costs an expected operations for all , and , against the bounds of [2] recalled in Section 1.
8.3 Quantum error correction
Under the standard correspondence between Pauli operators on qudits modulo phases and vectors of , two operators commute if and only if their vectors are orthogonal for the trace-symplectic form [3], [20, Lemma 5]; for -linear subspaces, the dual for this form coincides with the symplectic dual [16, proof of Thm. 2]. A subspace of dimension and symplectic hull dimension is therefore the check space of an EA stabilizer code on qudits [7, 16] that consumes ebits and encodes qudits, and is the least number of ebits with which can be realized [33], [16, Thm. 2]. Through an -linear coordinatewise bijection that carries the trace-alternating form of [20, Sec. IV] to the trace-symplectic form [20, Lemma 14], an -linear code in likewise gives an EA stabilizer code that consumes ebits and encodes qudits [16]; for this is the construction of [8] for , extended to all in [3], [20, Cor. 19]. Through these correspondences, Corollaries 18 and 23 are, without change, exactly uniform samplers of EA stabilizer codes with a prescribed number of encoded qudits and a prescribed number of ebits: take and in the symplectic case. Previous exact samplers cover only , where a uniformly random Clifford operator applied to a fixed stabilizer code gives a uniform stabilizer code [6, 21]. Our samplers cover every , and every , in an expected operations (Corollaries 18 and 23), so EA codes with a prescribed number of ebits can be drawn in practice, for instance for Monte Carlo estimates of their properties, such as the minimum distance, the weight enumerator, or the automorphism group.
9 Conclusion
We have given exactly uniform samplers for linear codes with prescribed hull dimension, for the Euclidean, Hermitian, and symplectic inner products and over finite fields of every characteristic. All samplers follow one framework: the orbits of the isometry group with their sizes, a simple representative of each orbit, and an exactly uniform isometry. The samplers cost an expected field operations per sample for codes of dimension in a space of dimension , for all , and . Future directions include applying the samplers to the classification of codes, to the key generation of code-based schemes, and to the study of typical quantum error-correcting codes with a prescribed number of ebits.
References
[1] M. R. Albrecht, B. Benčina, and R. W. F. Lai, “Hollow LWE: A new spin, unbounded updatable encryption from LWE and PCE,” in Advances in Cryptology, EUROCRYPT 2025, LNCS, vol. 15608, Springer, 2025, pp. 363–392. Cryptology ePrint Archive, Paper 2025/340.
[2] M. R. Albrecht, B. Benčina, and R. W. F. Lai, “Algorithms for sampling self-orthogonal and totally self-orthogonal codes in odd characteristic,” arXiv:2610.08664 [cs.IT], Oct. 2026.
[3] A. Ashikhmin and E. Knill, “Nonbinary quantum stabilizer codes,” IEEE Trans. Inf. Theory, vol. 47, no. 7, pp. 3065–3072, 2001.
[4] M. Baldi, M. Battagliola, R. El Mechri, P. Santini, R. Schiavoni, and D. De Zuane, “SPECK: Signatures from permutation equivalence of codes and kernels,” Cryptology ePrint Archive, Paper 2025/923, 2025.
[5] L. Babai, “Local expansion of vertex-transitive graphs and random generation in finite groups,” in Proc. 23rd Annu. ACM Symp. Theory Comput. (STOC), 1991, pp. 164–174.
[6] S. Bravyi and D. Maslov, “Hadamard-free circuits expose the structure of the Clifford group,” IEEE Trans. Inf. Theory, vol. 67, no. 7, pp. 4546–4563, 2021.
[7] T. Brun, I. Devetak, and M.-H. Hsieh, “Correcting quantum errors with entanglement,” Science, vol. 314, no. 5798, pp. 436–439, 2006.
[8] A. R. Calderbank, E. M. Rains, P. W. Shor, and N. J. A. Sloane, “Quantum error correction via codes over GF(4),” IEEE Trans. Inf. Theory, vol. 44, no. 4, pp. 1369–1387, 1998.
[9] C. Carlet and S. Guilley, “Complementary dual codes for countermeasures to side-channel attacks,” Adv. Math. Commun., vol. 10, no. 1, pp. 131–150, 2016.
[10] C. Carlet, S. Mesnager, C. Tang, and Y. Qi, “New characterization and parametrization of LCD codes,” IEEE Trans. Inf. Theory, vol. 65, no. 1, pp. 39–49, 2019.
[11] F. Celler, C. R. Leedham-Green, S. H. Murray, A. C. Niemeyer, and E. A. O’Brien, “Generating random elements of a finite group,” Comm. Algebra, vol. 23, no. 13, pp. 4931–4948, 1995.
[12] G. Cooperman, “Towards a practical, theoretically sound algorithm for random generation in finite groups,” arXiv:math/0205203, 2002.
[13] P. Diaconis and M. Shahshahani, “The subgroup algorithm for generating uniform random variables,” Probab. Eng. Inform. Sci., vol. 1, no. 1, pp. 15–32, 1987.
[14] J. Dieudonné, Sur les groupes classiques (Actualités Sci. Ind. 1040). Paris, France: Hermann, 1948.
[15] J. D. Dixon, “Generating random elements in finite groups,” Electron. J. Combin., vol. 15, no. 1, R94, 2008.
[16] C. Galindo, F. Hernando, R. Matsumoto, and D. Ruano, “Entanglement-assisted quantum error-correcting codes over arbitrary finite fields,” Quantum Inf. Process., vol. 18, no. 4, art. 116, 2019.
[17] J. Doliskani and É. Schost, “Taking roots over high extensions of finite fields,” Math. Comp., vol. 83, no. 285, pp. 435–446, 2014.
[18] K. Ireland and M. Rosen, A Classical Introduction to Modern Number Theory, 2nd ed., Graduate Texts in Mathematics, vol. 84. New York: Springer, 1990.
[19] K. Ishizuka, “Uniform sampling of self-orthogonal codes via orthogonal group actions,” in Proc. IEEE Inf. Theory Workshop (ITW), Tempe, AZ, USA, Nov. 2026, to appear.
[20] A. Ketkar, A. Klappenecker, S. Kumar, and P. K. Sarvepalli, “Nonbinary stabilizer codes over finite fields,” IEEE Trans. Inf. Theory, vol. 52, no. 11, pp. 4892–4914, 2006.
[21] R. Koenig and J. A. Smolin, “How to efficiently select an arbitrary Clifford group element,” J. Math. Phys., vol. 55, no. 12, art. 122202, 2014.
[22] S. Li, M. Shi, and S. Ling, “A mass formula for linear codes with prescribed hull dimension and related classification,” IEEE Trans. Inf. Theory, vol. 71, no. 1, pp. 273–286, 2025.
[23] R. Lidl and H. Niederreiter, Finite Fields, 2nd ed., Encyclopedia of Mathematics and its Applications, vol. 20. Cambridge, U.K.: Cambridge Univ. Press, 1997.
[24] S. Li, M. Shi, Y. Li, and S. Ling, “A further study on the mass formula for linear codes with prescribed hull dimension,” arXiv:2410.13578, 2024.
[25] Y. Liu and Z. Wan, “Pseudo-symplectic geometries over finite fields of characteristic two,” in Advances in Finite Geometries and Designs (Proc. Third Isle of Thorns Conf., 1990), J. W. P. Hirschfeld, D. R. Hughes, and J. A. Thas, Eds. Oxford, U.K.: Oxford Univ. Press, 1991, pp. 265–288.
[26] F. J. MacWilliams, “Orthogonal matrices over finite fields,” Amer. Math. Monthly, vol. 76, no. 2, pp. 152–164, 1969.
[27] E. M. Rains and N. J. A. Sloane, “Self-dual codes,” in Handbook of Coding Theory, V. S. Pless and W. C. Huffman, Eds. Amsterdam: Elsevier, 1998, pp. 177–294.
[28] N. Sendrier, “On the dimension of the hull,” SIAM J. Discrete Math., vol. 10, no. 2, pp. 282–293, 1997.
[29] N. Sendrier, “Finding the permutation between equivalent linear codes: The support splitting algorithm,” IEEE Trans. Inf. Theory, vol. 46, no. 4, pp. 1193–1203, 2000.
[30] D. E. Taylor, The Geometry of the Classical Groups, Heldermann, 1992.
[31] Z.-X. Wan, Geometry of Classical Groups over Finite Fields. Lund: Studentlitteratur; Bromley: Chartwell-Bratt, 1993.
[32] Z.-X. Wan, “Geometry of classical groups over finite fields and its applications,” Discrete Math., vol. 174, no. 1–3, pp. 365–381, 1997.
[33] M. M. Wilde and T. A. Brun, “Optimal entanglement formulas for entanglement-assisted quantum coding,” Phys. Rev. A, vol. 77, art. 064302, 2008.