1. Introduction
The Fourier-type discrete transforms have various applications [
1], including signal processing, communications, and cryptography. As their special application, we indicate the implementation for digital devices related to spectral logic [
2]. The discrete transformations are also important in studying the cryptographic properties of Boolean functions [
3,
4,
5], and they are used in the study of self-dual bent functions (see [
6]). A description of fast Fourier-type discrete transforms can be found in the popular book by Joux [
3] (Chapter 9).
Fast discrete transforms are widely used in coding theory, especially for computing some important parameters of linear codes over finite fields. The problems for computing the weight distribution, minimum distance, and covering radius of a linear code are NP-complete [
7]. Algorithms that solve these problems are usually based on an exhaustive search [
8,
9,
10]. Connections between discrete Fourier-type transforms, on the one hand, and weight distribution and covering radius, on the other, were established by Karpovsky [
11,
12], but he mainly considered binary codes. The algorithms based on fast discrete transforms are well suited for linear codes with small rates (large length and small dimension). The present study is a continuation of the recent work of the authors on the transforms’ applications in coding theory [
13,
14].
Fast discrete transforms, in most cases, can be represented as a matrix by vector multiplication, where the matrix is recursively defined by a Kronecker product. The transition from discrete to fast discrete transform is based on the fact that the transform matrix defined recursively by a Kronecker product can be factorized into a product of sparse matrices. We prove that the sparse matrices in this product commute, which is important for some implementations [
15]. As a result, this manages to reduce the complexity of computing the discrete transform from
to
, where
n is the size of the transform matrix.
The fast discrete transforms are implemented with butterfly diagrams and algorithms (see, for example, [
16]). These types of algorithms have very efficient natural implementations with the SIMD model of parallelization, especially with the CUDA platform. The speedup of the parallel implementation of Walsh–Hadamard transform in GPU can be seen in [
15].
In addition to the basic properties of the considered discrete transforms, we dwell in more detail on the following cases concerning linear codes over a finite field with q elements:
- (1)
If
, we consider the Walsh–Hadamard (Walsh) transform. This transform is a square-wave analog to the Fourier transform, based on Walsh functions [
17,
18]. The Walsh transform matrices are related to the Hadamard matrices of the Sylvester type. The Hadamard matrix
,
, is the
n-th Kronecker power of the matrix
. This allows us to represent
as a product of rare matrices [
19], which leads to a fast algorithm. As the computations of the transform are addition and subtraction only, it can be implemented by a butterfly algorithm [
3,
16]. Therefore, this transform is best suited for vector spaces over the binary field.
- (2)
If
q is an odd prime, we use the Vilenkin–Chrestenson transform [
20,
21]. This transform is defined over the ring of integers modulo
q. As it is well known,
is a field only when
q is a prime. We consider linear codes over a field, so this transform is suitable for our research for prime
q. The Walsh–Hadamard transform is a special case of the Vilenkin–Chrestenson transform, namely for
. Information about the Vilenkin–Chrestenson transform, as well as other discrete Fourier-type transforms, is given in [
2,
22,
23].
- (3)
If for a prime p and positive integer , we use the trace transform for linear codes over the filed .
The aim of this paper is to present methods for factorization of transform matrices when they are represented as a Kronecker product and their application for faster computation of the weight distribution of linear codes over prime and composite finite fields. We also give specific examples for better understanding. This consideration is essential for the modification of algorithms for computing the weight spectrum and covering radius of a linear code in some cases [
13,
14].
Section 2 presents the information we need about finite fields and linear codes. In
Section 3, we present some useful properties of the Kronecker product. The factorization of the
k-th Kronecker power of a square matrix is also given in this part.
Section 4,
Section 5 and
Section 6 are devoted to the Walsh–Haramard, Vilenkin–Chrestenson, and trace transform, respectively.
2. Finite Fields and Linear Codes
Let
be a finite field, or Galois field, with
q elements and the prime
p be its characteristic. Detailed information about finite field properties is given in [
24]. Any finite extension
over the field
is a linear space over
and a basis of the field
is any basis of this linear space. In particular, the field
, as a finite
m-powered extension of its prime subfield
, is isomorphic to the linear space
. If
is a basis of
over the prime subfield
and
, then
, where
.
Definition 1. Let , and . Trace of the element α over K isIf K is a prime subfield of F, then is called absolute trace of the element α and it is denoted by . If the field is given in advance, the absolute trace is denoted only by and called just trace.
Definition 2. Two bases and of the field F over the subfield K are called dual, iffor any . A basis that is dual of itself is called a self-dual basis. In other words, the trace is equal to the Kronecker of i and j for all . Each basis has exactly one dual basis. The following theorem gives a sufficient and necessary condition for the existence of a self-dual basis.
Theorem 1 ([
25] (Theorem 5.1.18), [
26])
. There exists a self-dual basis of over if and only if either q is even or both q and m are odd. For the purposes of the transforms, the elements of
are ordered, i.e.,
. In most cases, when
q is composite, we use the lexicographic ordering of the elements, depending on the chosen basis. If
is a basis of
,
, over
for the prime
p, then any elements
can be written as
, where
,
. There is one-to-one correspondence
between
and
defined by this basis. For
,
. To order the elements of
, we use the lexicographic ordering of the vectors in
, namely
The position of the zero element is constant, whereas all other elements could change their positions if the basis is changed.
Let be the n-dimensional vector space over the finite field , where q is a power of a prime number. Any k-dimensional linear subspace is called linear code, and it is said to be code with length n and dimension k. A vector is called a codeword of C. The (Hamming) weight of a vector is the number of the nonzero coordinates of v. The weight distribution of the code C is the finite sequence , where is the number of the codewords with weight , and the weight enumerator of the code C is the polynomial .
A linear code can be represented by its generator matrix, i.e., a matrix whose rows form a basis of C as a vector space over . We use another representation of the linear code C that depends on the chosen generator matrix G. We define a characteristic function of the code C with respect to its generator matrix G in the following way.
Definition 3. The value of the characteristic function of the linear code C with respect to the generator matrix G is the number of the columns in G, which are proportional (with non zero coefficients) of x, for . If we say that the code has full length.
Obviously, if and are proportional vectors in , then . Since a linear code has more than one generator matrix (in the general case), it has more than one characteristic function.
3. Factorization of Kronecker Power
Kronecker product of the matrices
and
is the
matrix
We give some elementary properties of the Kronecker product:
Kronecker’s product is not commutative.
The
k-th Kronecker power of a square matrix
M is defined as follows:
If M is a square matrix of size t, then is a square matrix of size .
Good [
19] showed that the Kronecker power could be reduced to the usual row-by-column multiplication of some sparse matrices. This fact stands also for the Kronecker power of a square matrix.
Theorem 2. Let M be a square matrix of size t and k be a positive integer. Thenwhere , , and is the identity matrix of size s. Proof. The proof of the theorem is made by induction. The statement is obvious for
:
Let (
4) be true for all Kronecker powers smaller than
k. Specifically,
where
,
. Because of (
1), (
3) and the inductive hypothesis, we have that
So the theorem holds for all
. □
Another important result is that the order of the factors in (
4) does not matter.
Theorem 3. The factors in (4) commute. Proof. We apply the properties of the Kronecker product.
□
If we take a square
matrix
M without zero elements, then the number of nonzero elements in each row and column in the matrices
is
t.
where
If , then each block has exactly one nonzero element in each row and column. Hence, has the same number of nonzero elements by rows and columns as the matrix M itself. Obviously, this holds for , too.
Let
M be a square
matrix without zero elements and
v be a vector of length
for some integer
k. To compute the product of the
k-th Kronecker power
with the vector
v, one needs
multiplications and
additions. Applying Theorem 2,
is factorized into
k square matrices of size
, such that each one has the same number
t of nonzero elements by rows and columns as
M. We have that
So, calculating consists of k multiplications , where is the vector, obtained in the previous step. Computing consists of multiplications and additions. In the general case, the whole calculation consists of at most operations. Hence, is computed much faster. This is the core of the presented fast discrete transforms.
4. Fast Walsh Transform
Let n be positive integer and be the Galois field of two elements. There is one-to-one correspondence between the non negative integers and the binary vectors of length n, defined by , where is the binary representation of u.
Let be a Boolean function of n variables. Truth Table of the function f is a -dimensional column vector whose -th coordinate is .
Walsh transform of the function
f is defined as follows:
where
and it means the Euclidean inner product of the vectors
x and
y. The column vector of the function
is denoted also by
.
We use a special type of Hadamard matrices, defined recurrently as follows:
Theorem 4. If f is a Boolean function of n variables then .
Proof. We prove the theorem by induction. For
, let
be a Boolean function of one variable. Then
and
Obviously,
.
Let the theorem holds for
,
, and
be a Boolean function of
variables with truth table
. We use the Boolean functions of
k variables
and
. According to the lexicographic ordering, the set of all vectors in
can be split into two subsets, namely
and
. Then
. According to the induction hypothesis
and
. Then
It follows that
These equations and the induction hypothesis show that
Hence, the induction step is proven. □
Thus, the computation of the Walsh transform is reduced to a matrix by vector multiplication. The elements of the matrix are only 1’s and −1’s. Hence, the multiplication of a row of the matrix by the considered vector means only addition and subtraction.
There is a fast algorithm to calculate
. First, the vector
v is partitioned into vectors of two coordinates. For each small vector
Using these results,
is multiplied by 4-length parts of
v. The
k-th step consists of multiplying the matrix
by a part
of
v, where
has length
. Let
and
be
parts of
from the previous step of the algorithm and also
and
are computed. Then
Therefore, we may consequently calculate
.
The presented algorithm consists of
n steps, each one performing only additions and subtractions. Therefore,
arithmetic operations are made, instead of
operations of the ordinary matrix by vector multiplication. An implementation of the Walsh–Hadamard fast transform in CUDA, as well as analysis of the complexity of the algorithm and comparison to other existing algorithms, are given in [
15].
Example 1. Let and . For , it holds that . Each row in the above multipliers consists of only two nonzero elements, namely 1 and −1. So, the row by vector multiplication costs one arithmetic operation (addition or subtraction). Let
be the Truth Table of a function
. The process of computing
is given below in
Figure 1. In the given diagram, the continuous line means addition, and the dotted line means subtraction.
In some cases, especially by parallelization of the algorithm and using shared memory, it is more convenient to rearrange the matrices. Because of Theorem 3, there is another way to compute
.
This leads to another fast algorithm for computing
(
b is a vector of suitable length), whose diagram is given in
Figure 2.
As a factorization of the Kronecker power is made, the Vilenkin–Chrestenson and the trace transforms also have similar fast algorithms.
5. Discrete Transform of Vilenkin–Chrestenson
Let
be a primitive complex
q-th root of unity. The matrices of Vilenkin–Chrestenson of size
k are recurrently defined as follows:
where ⊗ means the Kronecker product. The elements of the matrix
are
, where
are the row labels and
are the column labels, both in lexicographical order,
and
.
Some useful properties directly following the definition are given below:
The first property shows that the matrices
are symmetric.
Definition 4. Let be a function. Transform of Vilenkin–Chrestenson of f is the function , defined as follows: Let
be the vector whose coordinates are all values of the function
f when the elements of
are lexicographically ordered. It is called a truth table, and it is similar to the truth table of a Boolean function but with complex numbers. The value vectors of
f and
are related as follows:
Hence, the Vilenkin–Chrestenson transform can be reduced to a matrix by vector multiplication (see, for example, [
16]).
One very useful application of the presented transform is to calculate the weight distribution of a linear code over a prime field. Let q be a prime and G be a generator matrix of the linear code C. We take a code C of full length, so .
The relation between the Vilenkin–Chrestenson transform and the weight of the codeword is given by the following theorem.
Theorem 5. Let G be a generator matrix of the linear code C with full length. Then, for the weight of the codeword , it holds thatwhere is the Vilenkin–Chrestenson transform of the characteristic function of the code C. Proof. It is known that all codewords of
C are linear combinations of the rows of its generator matrix, so any codeword is generated by multiplication of
G by a vector
. Let us denote the columns of the matrix
G by
. It follows that
, where
is the inner product of
and the vector
. Since
is the number of the nonzero coordinates of the vector, so
is the number of the zeros in
. On the other hand, the summands in (
9) are
only if there exists a proportional to
x column in
G. Furthermore, if
for some
, then
for each
. Hence, for each column
x of the generator matrix
G it holds that
As the code has full length, then
. The summands in (
9) can be rearranged such that exactly one sum of type (
11) corresponds to each column of
G. Then
This proves that in this case
is an integer-valued function. Calculating
, we obtain (
10). □
Example 2. Let C be code and its generator matrix isThe characteristic function of C with respect to G has the following Truth Table:We have that , soApplying Theorem 5, we obtain that the nonzero weights in the code are 3, 4, 5, 6, and the weight enumerator is . The structure of the matrix is given below.where Each of the sparse matrices above has exactly three nonzero elements in its rows and columns. In the general case, a sparse matrix for the Vilenkin–Chrestenson transform has exactly q nonzero elements since is a matrix. That is why the number of the necessary operations is reduced to , approximately, while the same result would be obtained with operations without the factorization. The same conclusion could be drawn for the trace transform as well.
6. Trace Transform
Let
be a composite finite field with
q elements, where
for the prime
p and the integer
. For the trace transform, the absolute trace of the inner product is used instead of the inner product itself, as in the Vilenkin–Chrestenson transform [
27]. Let
be a primitive complex
p-th root of unity, and
for any
. We define the trace transform similarly to the Vilenkin–Chrestenson transform.
Definition 5. Let be a finite field with q elements, for the prime number p, and ζ be a primitive complex p-th root of unity. Trace transform of the function is the function , defined as follows: The transform matrix here is the
matrix
, where the vectors (in our case denoted by
and
x) in
are lexicographically ordered. Then the Truth Tables of
f and
are connected by the equality
Because of the symmetry and linearity of the inner product, the following properties hold:
Lemma 1. For it holds that Proof. The lemma is a modification of [
28] (Chapter 5, Lemma 9), and its proof is by induction on
k. In the base step,
it holds
For
, when
takes all possible values of
, then
takes all the values of
. Moreover, for any element
, there are exactly
elements
with the same trace value
. Thus
Let the equality hold for some integer
k. Consider the vectors in
in the following form:
,
,
. Because of the trace linearity
According to the induction hypothesis and its base step, the sum is
exactly when
and
. In this case, the sum is
.
Hence, the equality holds for each . □
To reduce (
15), it is also taken that
where
,
,
. This means that the matrices
are generated as a Kronecker power, i.e.,
and
for
.
The trace transform also has applications in coding theory, but it is used for linear codes over composite finite fields. In this case, a theorem similar to Theorem 5 is proved.
Theorem 6. Let G be a generator matrix of the linear code C with full length. Then, for the weights of all codewords of C, it holds thatwhere is the trace transform of the characteristic function of the code C. Proof. The proof is similar to the proof of Theorem 5. Each coordinate in
is equal to the inner product of
and the corresponding column of
G. Since
is the number of the nonzero coordinates of
, so
is the number of zeros. On the other hand, the summand
in (
13) is not equal to 0 if and only if there exists a proportional vector of
x as a column in
G. If
, for some
, then
for all
. For each column
x of the matrix
G it holds that
Let
. Then
. The absolute trace
is a linear map onto
with a kernel of
elements. Hence, the sum (
17) has exactly
additives
and exactly
additives
for each
,
. Further
Because the code has full length, then
. The summands in (
13) might be rearranged in such a way that any of the columns of
G corresponds exactly to one sum of the type (
17). Then
which leads to (
16). □
It was proved in [
13] that if the characteristic of the field is 2 and the used basis of
is self-dual, the matrix
is a
Sylvester-Hadamard matrix (this matrix is denoted by
in [
13] (Proposition 2.1)). We give an example with a quaternary code with two characteristic vectors—one of them with respect to a self-dual basis and another one with respect to the ordinary polynomial basis
. Recall that the elements
, where
for a prime
p, form a self-dual basis of the field if
for the Kronecker
.
Example 3. Let and . We consider the quaternary code with a generator matrixIf we take the ordering , then the lexicographic ordering of the quaternary vectors of length 2 isand the characteristic vector of the code isIn this case, the trace transform matrix isThen and after applying (
16),
we obtain that the weight distribution of the given code is . The quaternary field has a self-dual basis, namely , . Then we have the following ordering of the elements , since , , and . In this case, the lexicographic ordering of the quaternary vectors of length 2 isThe new characteristic vector isNow and so has the following structure:After the corresponding calculations, the same weight distribution of the code is obtained, but the algorithm is much faster, as we can use the fast Walsh transform, presented in Section 4. In the general case, if the trace transform could not be reduced to the Walsh–Hadamard transform, the matrix is of size , i.e., . Then the matrix is a matrix, so the computation of requires multiplications and the same number of additions, operations over all. Let be factorized into k sparse matrices. Each of them has at most nonzero elements, so its multiplications by a vector consist of multiplications and additions. The total amount of operations to obtain the same result is at most .
We finish this section with a proposition showing that the trace transform can be reduced to a Vilenkin–Chrestenson transform in some cases. Let
, where
p is an odd prime and
is an odd integer. According to Theorem 1, there exists a self-dual basis
of
over
. Let
, where the elements are ordered lexicographically with respect to the self-dual basis. Therefore,
and
Because of the lexicographic ordering, we have the following representation of the index
s in the
p-ary numeral system
Let be the Vilenkin–Chrestenson matrix for the pth root of unity , considered in this section. Then, the following statement holds.
Proposition 1. For , the matrices and coincides.
Proof. According to the linearity of the trace function, we have
Since the basis is self-dual, it holds that
Then
Hence
and so
where the
is the Vilenkin–Chrestenson transform with the
p-th root of unity
. Transferring this result to the transform matrices, we obtain
. □
7. Conclusions
Computing the weight distribution of a linear code is not an easy problem, especially when the considered finite field is composite. Most algorithms that solve this problem are based on searching in large amounts of generated data. Therefore, other different techniques, such as Fourier-type transforms, are also being investigated and applied.
In this paper, three fast discrete transforms are studied, namely the Walsh–Hadamard, the Vilenkin–Chrestenson, and the trace transform, mainly considering the problem of representing their matrices as a product of sparse matrices. Using these transforms, the weights of a linear code could be computed without generating the codewords themselves. Algorithms for implementing the given fast discrete transforms have not only better complexity but they could also be easily parallelized.