1 Introduction

Let p be an odd prime, \(m(>\)1), e be positive integers and \(q=p^e\). An [nkd] linear code \(\mathcal {C}\) over the finite field \( F_q\) is a k-dimensional subspace of \( F_q^n\) with minimum (Hamming) distance d, which determines the error correcting capability of \(\mathcal {C}\). Let \(A_i\) denote the number of codewords with Hamming weight i in a code \(\mathcal {C}\) of length n. The weight enumerator of \(\mathcal {C}\) is defined by

$$\begin{aligned} 1+A_1z+A_2z^2+\ldots +A_nz^n. \end{aligned}$$

The sequence \((1, A_1,~ A_2, \ldots , A_n)\) is called the weight distribution of \(\mathcal {C}\). The code \(\mathcal {C}\) is said to be t-weight if the number of nonzero \(A_j~(1 \le j \le n)\) in the sequence \((A_1,~ A_2, \ldots , A_n)\) equals t.

The complete weight enumerator of a code \(\mathcal {C}\) over \( F_q\) enumerates the codewords according to the number of symbols of each kind contained in each codeword. Let \(F_q=\{\omega _0, \omega _1, \cdots , \omega _{q-1}\}\) with \(\omega _0=0\) and \(F^*_q= F_q\backslash \{0\}\). For a codeword \(\mathbf {c}=(c_0, c_1, \cdots , c_{n-1})\in F^n_q\), the complete weight enumerator \(\omega [\mathbf {c}]\) of \(\mathbf {c}\) is defined by

$$\begin{aligned} \omega [\mathbf {c}]=\omega ^{k_0}_0\omega ^{k_1}_1\cdots \omega ^{k_{q-1}}_{q-1}, \end{aligned}$$

where \(\sum \nolimits _{j=0}^{q-1}k_j=n\), \(k_j\) is the number of components of \(\mathbf {c}\) that equals \(\omega _j\). The complete weight enumerator of the code \(\mathcal {C}\) is then defined by

$$\begin{aligned} CWE(\mathcal {C})=\sum \limits _{\mathbf {c}\in \mathcal {C}}\omega [\mathbf {c}]. \end{aligned}$$

The weight distribution gives the minimum distance of the code, and hence the error correcting capability. Furthermore, the weight distribution of a code allows the computation of the probability of error detection and correction (see [22] for details). Thus the study of the weight distribution attracts much attention in coding theory and much work is focused on the determination of the weight distributions of linear codes (see [9, 10, 12, 14, 16, 26, 27, 32,33,34] and the references therein). Linear codes can be applied in consumer electronics, communication and data storage system. Linear codes with a few weights are of importance in secret sharing [6, 28], authentication codes [13], association schemes [4] and strongly regular graphs [5].

It is easy to see that the complete weight enumerators of binary linear codes are just their weight enumerators, while for the nonbinary case, the weight enumerators can be obtained from their complete weight enumerators. Furthermore, the complete weight enumerators are closely related to the deception probabilities of certain authentication codes constructed from linear codes [11], and used to compute the Walsh transform of monomial functions over finite fields [17]. Thus, a great deal of research [3, 7, 8, 15, 19, 23, 24, 29, 30] is devoted to the computation of the complete weight enumerators of specific codes over \( F_q\).

Let \(D = \{d_1, d_2, \ldots , d_n\} \subseteq F_{q^m}\). A linear code of length n over \( F_q\) is defined by

$$\begin{aligned} \mathcal {C}_D = \{(Tr_1^m(xd_1),Tr_1^m(xd_2), \ldots , Tr_1^m(xd_n)):~ x\in F_{q^m} \} \end{aligned}$$

where \(Tr^m_1\) is the trace function from \( F_{q^m}\) to \( F_q\). The set D is called the defining set of \(\mathcal {C}_D\). This construction method was used for obtaining linear codes with a few weights [10, 34]. The selection of D directly affects the parameters of the constructed linear code \(\mathcal {C}_D\). How to choose the defining set D for obtaining a good linear code \(\mathcal {C}_D\) is an interesting and important problem.

Let Q(x) be a quadratic form function from \(F_{q^m}\) to \(F_{q}\). Very recently, for \(e=1\) and Q(x) being a quadratic form function of full rank (quadratic Bent function), Zhou et al. constructed some classes of linear codes over \(F_{p}\) with defining set \(D=\{x\in F_{q^m}^*:~Q(x)=0 \}\) and examined their weight distribution [34]. Later, Zhang et al. extended Zhou et al.’s construction to \(F_{q}\) for general quadratic form function Q(x) and examined the complete weight enumerators of the codes [31]. In this paper, for the case of clarity, we will denote the defining set D by \(D_Q^a=\{x\in F_{q^m}^*:~Q(x)=a \}\) for any \(a\in F_q\). Firstly, we construct a class of linear codes over \(F_{q}\) with defining set \(D_Q^a\). Then we examine their complete weight enumerators and discuss their application in secret sharing schemes.

2 Quadratic form functions

Identifying \( F_{q^m}\) with the m-dimensional \( F_q\)-vector space \( F_q^m\), a function Q(x) from \( F_{q^m}\) to \( F_q\) can be regarded as an m-variable polynomial over \( F_q\). The former is called a quadratic form over \( F_q\) if the latter is a homogeneous polynomial of degree two in the form

$$\begin{aligned} Q(x_1,x_2,\ldots , x_m)= \sum \limits _{1\le i\le j \le m} a_{ij}x_ix_j, \end{aligned}$$

where \(a_{ij}\in F_q \). Any choice of a basis \(\{\beta _1, \beta _2, \ldots , \beta _m\}\) from \( F_{q^m}\) as a vector space over \( F_q\) determines an identification \( F_{q}^m \rightarrow F_{q^m}\) by \(\bar{x}=(x_1,x_2,\ldots , x_m)\) \(\mapsto \) \(\sum _{i=1}^m x_i\beta _i=x\). We write \(\bar{x}\) when an element is to be viewed as a vector in \( F_{q}^m\), and we write x when the same vector is to be viewed as an element of \( F_{q^m}\). The rank of the quadratic form Q(x) is defined as the codimension of the \( F_q\) -vector space

$$\begin{aligned} V = \{y\in F_{q^m}:~ Q(x+y)-Q(x)-Q(y) = 0 \mathrm {~for~ all~} x\in F_{q^m} \}. \end{aligned}$$

That is \(|V| = q^{m-r}\) where r is the rank of Q(x).

In the sequel, we shall give some lemmas that are essential in proving our main results. Before doing this, we first fix some notation.

  1. *

    \(B_{2j}(\bar{x}) = x_1x_2 +x_3x_4+\ldots +x_{2j-1}x_{2j}\) where j is an integer with \(0\le 2j \le m\) (we assume that \(B_0 = 0\) when \(j = 0\)).

  2. *

    I(x) is a function over \( F_q\) defined by \(I(x) =-1\) for any \(x \in F_{q}^*\) and \(I(0) = q-1\).

  3. *

    \(\eta (x)\) is the quadratic character of \( F_q\) with \(\eta (0)=0\).

Quadratic forms have been well studied (see [20, 21, 25], for example). Here we follow the treatment in [20] and [21]. It should be noted that the rank of a quadratic form over \( F_q\) is the smallest number of variables required to represent the quadratic form, up to nonsingular coordinate transformations. Mathematically, any quadratic form of rank r can be transferred to three canonical forms described in Table 1.

Lemma 1

([21]) Let Q(x) be a quadratic form over \( F_q\) of rank r in m variables. Under a nonsingular change of coordinates, Q(x) is equivalent to one of the three standard types in Table 1:

Table 1 Standard types of quadratic form over \( F_q\) with rank r and m variables

where \(\mu \in \{1,\gamma \}\) and \(\gamma \) is a fixed nonsquare in \( F_q\) and we denote \(N_a\) by

$$\begin{aligned} N_{a}=| \{\bar{x}\in F_{q}^m:~Q(\bar{x})=a\}| \mathrm {~~~~for~ all}~a \in F_{q}. \end{aligned}$$

Consider a system of equations consisting of a quadratic form and a linear function. The number of solutions depends on the type and rank of the quadratic form. Let \(Q(\bar{x})\) be a quadratic form of rank r in m variables in one of the three standard types. Let \(L_{\bar{b}}(\bar{x})=\bar{b}\bar{x}^T=\sum _{i=1}^m b_ix_i\) be a linear function in m variables with \(\bar{b} = (b_1,b_2, \ldots ,b_m) \in F^m_q \backslash \{\bar{0}\}\), where \( \bar{0}= (0,0, \ldots ,0)\) denotes the all zero vector. For any \(a,~v\in F_q\), we denote by N(av) the number of solutions to the system of equations

$$\begin{aligned} \left\{ \begin{array}{ll} Q(\bar{x})=a,\\ L_{\bar{b}}(\bar{x})=v. \end{array} \right. \end{aligned}$$

The following lemmas will be used to determine the complete weight enumerators of linear codes constructed from general quadratic forms over \( F_q\). Before introducing them, we give some notations for the standard quadratic form \(Q(\bar{x})\) defined above. For any vector \(\bar{x} = (x_1, x_2, \ldots , x_m),\) denote \(\bar{x}' = (x_1, x_2,\ldots , x_r)\) and \(\bar{x}^{''} = (x_{r+1}, x_{r+2}, \ldots , x_m),\) where r is the rank of \(Q(\bar{x}).\) Thus \(Q(\bar{x}) = Q(\bar{x'}).\) Let

$$\begin{aligned} \hat{Q}(\bar{x})=\left\{ \begin{array}{ll} Q(\bar{x}), &{} \mathrm {~if~} Q(\bar{x})=B_r(\bar{x}),\\ B_{r-1}(\bar{x})+\frac{x_r^2}{4 \mu }, &{} \mathrm {~if~} Q(\bar{x})=B_{r-1}(\bar{x})+\mu x_r^2,\\ B_{r-2}(\bar{x})+\frac{x_{r-1}^2}{4}-\frac{x_{r}^2}{4 \gamma }, &{} \mathrm {~if~} Q(\bar{x})=B_{r-1}(\bar{x})+x_{r-1}^2-\gamma x_r^2,\\ \end{array} \right. \end{aligned}$$

where \(\mu \in \{1,\gamma \}\) and \(\gamma \) is a fixed nonsquare in \( F_q\). Note that \(\hat{Q}(\bar{x})\) is equivalent to \(Q(\bar{x})\) under a change of coordinates.

Lemma 2

([21]) Let \(Q(\bar{x})\) be a quadratic form over \( F_q\) of rank r in m variables. Let the notation be the same as before and \(\bar{b}^{''}=0\).

  1. (1)

    When Q is of Type I or Type III,

    $$\begin{aligned} N(a,v)=\left\{ \begin{array}{ll} q^{m-2}+\epsilon I(a)q^{m-\frac{r}{2}-1}, &{} \mathrm {~if~} Q(\bar{b})=0 \mathrm {~and~} v=0, \\ q^{m-2}, &{} \mathrm {~if~} Q(\bar{b})=0 \mathrm {~and~} v\not =0, \\ q^{m-2}+\epsilon \eta \Big ( v^2-4a\hat{Q}(\bar{b}) \Big )q^{m-\frac{r}{2}-1}, &{} \mathrm {~if~} Q(\bar{b})\not =0. \end{array} \right. \end{aligned}$$
  2. (2)

    When Q is of Type II,

    $$\begin{aligned} N(a,v)=\left\{ \begin{array}{ll} q^{m-2}+\eta ( \mu a)q^{m-\frac{r+1}{2}}, &{} \mathrm {~if~} Q(\bar{b})=0 \mathrm {~and~} v=0, \\ q^{m-2}, &{} \mathrm {~if~} Q(\bar{b})=0 \mathrm {~and~} v\not =0, \\ q^{m-2}+ I\Big (v^2-4a\hat{Q}(\bar{b}) \Big ) \eta \Big ( \mu \hat{Q}(\bar{b}) \Big )q^{m-\frac{r+3}{2}}, &{} \mathrm {~if~} Q(\bar{b})\not =0, \end{array} \right. \end{aligned}$$

where \(\epsilon = 1\) if Q(x) is equivalent to Type I and \(\epsilon = -1\) if Q(x) is equivalent to Type III.

Lemma 3

([21]) Let \(Q(\bar{x})\) be a quadratic form over \( F_q\) of rank r in m variables. Let the notation be the same as before and \(\bar{b}^{''} \not =0\).

  1. (1)

    When Q is of Type I or Type III,

    $$\begin{aligned} N(a,v)=q^{m-2}+\epsilon I(a) q^{m-\frac{r}{2}-2}. \end{aligned}$$
  2. (2)

    When Q is of Type II,

    $$\begin{aligned} N(a,v)=q^{m-2}+\eta ( \mu a) q^{m-\frac{r+3}{2}}. \end{aligned}$$

3 Linear codes from quadratic forms

In this paper, for any \(a\in F_q\), the defining set is defined by

$$\begin{aligned} D_Q^a =\{ x\in F_{q^m}: Q(x) = a\}=\{d_1,d_2,\ldots ,d_n\}. \end{aligned}$$
(1)

A linear code of length n over \( F_q\) is defined by

$$\begin{aligned} \mathcal {C}_{D_Q^a} =\{(Tr(xd_1),Tr(xd_2),\ldots ,Tr(xd_n)):x\in F_{q^m}\}. \end{aligned}$$
(2)

Note that for the case of \(a=0\), the weight distribution of the linear codes has been discussed in [34] for Q(x) over \( F_p\) with \(r=m\) and later in [31] for general quadratic form Q(x) over \( F_q\). Thus we consider the complete weight enumerator of the linear code \(\mathcal {C}_{D_Q^a}\) only for \(a \in F_q^*.\)

Theorem 1

Let g be a generator of \( F_q^*\). If r is even, then the code \(\mathcal {C}_{D_Q^a}\) is a \([q^{m-1}-\epsilon q^{m-\frac{r}{2}-1}, m]\) linear code with the weight distribution given in Table 2 and its complete weight enumerator is

$$\begin{aligned}&CWE(\mathcal {C}_{D_Q^a})=\omega _0^{q^{m-1}-\epsilon q^{m-\frac{r}{2}-1}}+(q^m-q^r)\prod \limits _{\rho =0}^{q-1}\omega _\rho ^{q^{m-2}-\epsilon q^{m-\frac{r}{2}-2}}\\&\qquad +\,\Big (q^{r-1}+\epsilon (q-1)q^{\frac{r}{2}-1}-1\Big )\omega _0^{q^{m-2}-\epsilon q^{m-\frac{r}{2}-1}}\prod \limits _{\rho =1}^{q-1}\omega _\rho ^{q^{m-2}}\\&\qquad +\,(q^{r-1}-\epsilon q^{\frac{r}{2}-1})\sum \limits _{\beta =1}^{\frac{q-1}{2}}\omega _{0}^{q^{m-2}+(\frac{-1}{q})\epsilon q^{m-\frac{r}{2}-1}} \omega _{2g^\beta }^{q^{m-2}}\omega _{q-2g^\beta }^{q^{m-2}} \\&\qquad \cdot \prod \limits _{\rho \ne 0, \pm 2g^\beta } \omega _\rho ^{q^{m-2}+(\frac{\rho ^2-4g^{2\beta }}{q})\epsilon q^{m-\frac{r}{2}-1}}\\&\qquad +\,(q^{r-1}-\epsilon q^{\frac{r}{2}-1})\sum \limits _{\beta =1}^{\frac{q-1}{2}}\omega _{0}^{q^{m-2}-(\frac{-1}{q})\epsilon q^{m-\frac{r}{2}-1}} \prod \limits _{\rho =1}^{q-1} \omega _\rho ^{q^{m-2}+(\frac{\rho ^2-4g^{2\beta +1}}{q})\epsilon q^{m-\frac{r}{2}-1}}. \end{aligned}$$
Table 2 Weight distribution of the codes \(\mathcal {C}_{D_Q^a}\) with r even

Proof

By Lemma 1, it is obvious that the code \(\mathcal {C}_{D_Q^a}\) has length \(n=N_a=q^{m-1} -\epsilon q^{m-\frac{r}{2}-1}\) and dimension m. For any codeword \(\mathbf {c}_b\) in \(\mathcal {C}_{D_Q^a}\), according to the definition, the Hamming weight is equal to

$$\begin{aligned} WT(\mathbf {c}_b)=N_a-N(a,0). \end{aligned}$$

Then, the weight distribution of \(\mathcal {C}_{D_Q^a}\) follows from Lemmas 1, 2 and 3.

To obtain the complete weight enumerator of \(C_{D_Q^a}\), we need to determine the value distribution of \(\mathcal {N}_b(a,v)\) for each \(v\in F_q\) when b runs through all the elements in \( F_{q^m}\). Let \(\{\alpha _1, \alpha _2,\dots , \alpha _m\} \) and \(\{\beta _1, \beta _2,\dots , \beta _m\}\) be the dual basis of \( F_{q^m}\) over \( F_q\). Using the dual bases, we write \(x = x_1\beta _1 +x_2\beta _2 +\ldots +x_m\beta _m\) and \(b= b_1\alpha _1 +b_2\alpha _2 +\ldots +b_m\alpha _m\) for \(x,~b \in F_{q^m}\) and we write corresponding vectors as \(\bar{x} = (x_1, x_2, \ldots , x_m ) \in F_q^m\) and \(\bar{b} = (b_1, b_2, \ldots , b_m ) \in F_q^m\). So, the linear function \(Tr^m_1(bx)=v \) is equivalent to \(L_{\bar{b}}(\bar{x})=v\). Let \(\mathcal {N}_b(a,v)\) be equal to the number of solutions \(\bar{x} \in F_q^m {\setminus } \{ \bar{0} \}\) of the following system of equations:

$$\begin{aligned} \left\{ \begin{array}{ll} \hat{Q}(\bar{x})=a,\\ L_{\bar{b}}(\bar{x})=v, \end{array} \right. \end{aligned}$$

after nonsigular transformation for the quadratic form Q(x) (for simplicity, we still use symbol \(\bar{x}\)).

Observe that \(b=0\) gives the zero codeword and the contribution to the complete weight enumerator is \(\omega _0^n\), so below we assume that \(b\in F_q^*\). Note that \(\bar{b}\) runs through all the elements in \( F_q^m {\setminus } \{\bar{0}\}\) if and only if b runs though all the elements in \( F_{q^m}^*.\)

Note that g is a generator of \( F_q^*\), i.e., each element of \( F_q^*\) can be represented by \(g^\beta \) for some \(1\le \beta \le q-1\). When \(\beta \) runs over all the elements of the set \(\{1,2, \ldots , \frac{q-1}{2} \}\), \(g^{2\beta }\) and \(g^{2\beta +1}\) will run over all the quadratic residues and quadratic nonresidues of \(F_q^*\), respectively.

The desired conclusions then follow from Lemmas 2 and 3. \(\square \)

Table 3 Weight distribution of the codes \(\mathcal {C}_{D_Q^a}\) with r odd
Table 4 Weight distribution of the codes \(\mathcal {C}_{D_Q^a}\) with \(r=\eta (\mu a)=1\)

Theorem 2

Let g be a generator of \( F_q^*\). If r is odd, then the code \(\mathcal {C}_{D_Q^a}\) is a \([q^{m-1}+\eta (\mu a) q^{m-\frac{r+1}{2}}, m]\) linear code with the weight distribution given in Table 3 and its complete weight enumerator is

$$\begin{aligned}&CWE(\mathcal {C}_{D_Q^a})=\omega _0^{q^{m-1}+\eta (\mu a) q^{m-\frac{r+1}{2}}}+(q^m-q^r)\prod \limits _{\rho =0}^{q-1}\omega _\rho ^{q^{m-2}+\eta (\mu a)q^{m-\frac{r+3}{2}}}\\&\qquad +\,(q^{r-1}-1)\omega _0^{q^{m-2}+\eta (\mu a)q^{m-\frac{r+1}{2}}}\prod \limits _{\rho =1}^{q-1}\omega _\rho ^{q^{m-2}}\\&\qquad +\,\Big (q^{r-1}+\eta (\mu a)q^{\frac{r-1}{2}}\Big ) \sum \limits _{\beta =1}^{\frac{q-1}{2}} \omega _{0}^{q^{m-2}-\eta (\mu a)q^{m-\frac{r+3}{2}}} \omega _{2g^\beta }^{q^{m-2}+(q-1)\eta (\mu a)q^{m-\frac{r+3}{2}}} \\&\qquad \cdot \,\omega _{q-2g^\beta }^{q^{m-2}+(q-1)\eta (\mu a)q^{m-\frac{r+3}{2}}} \prod \limits _{\rho \ne 0, \pm 2g^\beta } \omega _\rho ^{q^{m-2}-\eta (\mu a)q^{m-\frac{r+3}{2}}}\\&\qquad +\,\frac{q-1}{2}\Big (q^{r-1}-\eta (\mu a)q^{\frac{r-1}{2}}\Big ) \prod \limits _{\rho =0}^{q-1} \omega _\rho ^{q^{m-2}+\eta (\mu a)q^{m-\frac{r+3}{2}}}. \end{aligned}$$

The proof is very similar to that of Theorem 1, so we omitted it here.

Remark

As a special case of Theorem 2, if Q(x) is a quadratic form of rank \(r=1\), then the code \(\mathcal {C}_{D_Q^a}\) does not exist since the length of \(\mathcal {C}_{D_Q^a}\) equals zero when \(\eta (\mu a)=-1\). While for the case of \(\eta (\mu a)=1\), we have that \(\mathcal {C}_{D_Q^a}\) is a \([2q^{m-1}, m]\) linear code with the weight distribution given in Table 4 and its complete weight enumerator is

$$\begin{aligned} CWE(\mathcal {C}_{D_Q^a})=\omega _0^{2q^{m-1}}+(q^m-q)\prod \limits _{\rho =0}^{q-1}\omega _\rho ^{2q^{m-2}}+2 \sum \limits _{\beta =1}^{\frac{q-1}{2}} \omega _{2g^\beta }^{q^{m-1}} \omega _{q-2g^\beta }^{q^{m-1}}. \end{aligned}$$
Table 5 Weight distribution of the codes \(\mathcal {C}_{D_Q^a}\) with full rank m even

For the quadratic form Q(x) over \( F_q\) with full rank \(r=m\), we have following two corollaries corresponding to Theorems 1 and 2, respectively.

Corollary 1

Let Q(x) be a quadratic form of full rank from \( F_{q^m}\) to \( F_q\). If m is even, then \(\mathcal {C}_{D_Q^a}\) is a two-weight \([q^{m-1}-\epsilon q^{\frac{m}{2}-1}, m]\) code over \( F_q\) with the weight distribution given in Table 5 and its complete weight enumerator is

$$\begin{aligned}&{CWE(\mathcal {C}_{D_Q^a})} \\&\quad =\omega _0^{q^{m-1}-\epsilon q^{\frac{m}{2}-1}}+\Big (q^{m-1}+\epsilon (q-1)q^{\frac{m}{2}-1}-1\Big )\omega _0^{q^{m-2}-\epsilon q^{\frac{m}{2}-1}}\prod \limits _{\rho =1}^{q-1}\omega _\rho ^{q^{m-2}}\\&\qquad +\,(q^{m-1}-\epsilon q^{\frac{m}{2}-1})\sum \limits _{\beta =1}^{\frac{q-1}{2}}\omega _{0}^{q^{m-2}+(\frac{-1}{q})\epsilon q^{\frac{m}{2}-1}} \omega _{2g^\beta }^{q^{m-2}}\omega _{q-2g^\beta }^{q^{m-2}} \\&\qquad \cdot \prod \limits _{\rho \ne 0, \pm 2g^\beta } \omega _\rho ^{q^{m-2}+(\frac{\rho ^2-4g^{2\beta }}{q})\epsilon q^{\frac{m}{2}-1}}\\&\qquad +\,(q^{m-1}-\epsilon q^{\frac{m}{2}-1})\sum \limits _{\beta =1}^{\frac{q-1}{2}}\omega _{0}^{q^{m-2}-(\frac{-1}{q})\epsilon q^{\frac{m}{2}-1}} \prod \limits _{\rho =1}^{q-1} \omega _\rho ^{q^{m-2}+(\frac{\rho ^2-4g^{2\beta +1}}{q})\epsilon q^{\frac{m}{2}-1}}. \end{aligned}$$
Table 6 Weight distribution of the codes \(\mathcal {C}_{D_Q^a}\) with full rank m odd

Corollary 2

Let Q(x) be a quadratic form of full rank from \( F_{q^m}\) to \( F_q\). If m is odd, then \(\mathcal {C}_{D_Q^a}\) is a three-weight \([q^{m-1}+\eta (\mu a) q^{\frac{m-1}{2}}, m]\) code over \( F_q\) with the weight distribution given in Table 6 and its complete weight enumerator is

$$\begin{aligned}&CWE(\mathcal {C}_{D_Q^a})=\omega _0^{q^{m-1}+\eta (\mu a) q^{\frac{m-1}{2}}}+(q^{m-1}-1)\omega _0^{q^{m-2}+\eta (\mu a)q^{\frac{m-1}{2}}}\prod \limits _{\rho =1}^{q-1}\omega _\rho ^{q^{m-2}}\\&\qquad +\Big (q^{m-1}+\eta (\mu a)q^{\frac{m-1}{2}}\Big ) \sum \limits _{\beta =1}^{\frac{q-1}{2}} \omega _{0}^{q^{m-2}-\eta (\mu a)q^{\frac{m-3}{2}}} \omega _{2g^\beta }^{q^{m-2}+(q-1)\eta (\mu a)q^{\frac{m-3}{2}}} \\&\qquad \cdot \,\omega _{q-2g^\beta }^{q^{m-2}+(q-1)\eta (\mu a)q^{\frac{m-3}{2}}} \prod \limits _{\rho \ne 0, \pm 2g^\beta } \omega _\rho ^{q^{m-2}-\eta (\mu a)q^{\frac{m-3}{2}}}\\&\qquad +\frac{q-1}{2}\Big (q^{m-1}-\eta (\mu a)q^{\frac{m-1}{2}}\Big ) \prod \limits _{\rho =0}^{q-1} \omega _\rho ^{q^{m-2}+\eta (\mu a)q^{\frac{m-3}{2}}}. \end{aligned}$$

We conclude this section by providing some examples as an indication of the validity of our results.

Example 1

Let \(q=p=3\), \(m=6\), \(a=1\), and \(Q(x)=Tr_{q^6/q}(2x^4+x^2)\), which is a Type I quadratic form with rank 4. Our Magma program shows that \(\mathcal {C}_{D_Q^a}\) has parameters [216, 6, 108] and the complete weight enumerator

$$\begin{aligned} \omega _0^{216}+24\omega _0^{108} \omega _1^{54} \omega _2^{54}+648\omega _0^{72} \omega _1^{72} \omega _2^{72}+56\omega _0^{54} \omega _1^{81} \omega _2^{81}. \end{aligned}$$

This agrees with the conclusion of Theorem 1.

Example 2

Let \(q=p=3\), \(m=5\), \(a=1\), and \(Q(x)=Tr_{q^5/q}(2x^{10}+x^2)\), which is a Type III quadratic form with rank 4. Our Magma program shows that \(\mathcal {C}_{D_Q^a}\) has parameters [90, 5, 54] and the complete weight enumerator

$$\begin{aligned} \omega _0^{90}+50\omega _0^{36} \omega _1^{27} \omega _2^{27}+162\omega _0^{30} \omega _1^{30} \omega _2^{30}+30\omega _0^{18} \omega _1^{36} \omega _2^{36}. \end{aligned}$$

This is consistent with the statement of Theorem 1.

Example 3

Let \(q=p=3\), \(m=3\), \(a=1\), and \(Q(x)=Tr_{q^3/q}(2x^4+x^2)\), which is a Type II quadratic form with rank 1 and \(\eta (\mu )=1\), the Magma program shows that \(\mathcal {C}_{D_Q^a}\) has parameters [18, 3, 12] and the complete weight enumerator

$$\begin{aligned} \omega _0^{18}+24\omega _0^6 \omega _1^6 \omega _2^6+2\omega _1^9 \omega _2^9. \end{aligned}$$

This agrees with the conclusion of Theorem 2.

Example 4

Let \(p=3\), \(e=2\), \(q=9\), \(m=4\), \(a\in \{1,2,4,5,7,8\}\), and \(Q(x)=Tr_{q^4/q}(x^{q^2+1})\) be a Type III quadratic form with full rank. The Magma program shows that \(\mathcal {C}_{D_Q^a}\) has parameters [738, 4, 648] and the weight enumerator

$$\begin{aligned} 1+3608z^{648}+2952z^{666}. \end{aligned}$$

The complete weight enumerator is very cumbersome, limited by the length of the space is no longer listed. This agrees with the conclusion of Corollary 1.

4 Optimal codes

An [nkd] code over \(F_q\) is called optimal if there is no \([n, k, d+1]\) or \([n, k+1, d]\) code over \(F_q\). An [nkd] code over \(F_q\) is called almost optimal if the \([n, k, d + 1]\) or \([n, k+1, d]\) code is optimal [18]. Below, we prove that some of the codes in the paper are optimal or almost optimal with respect to the Griesmer bound.

Lemma 4

[18] (Griesmer Bound) Let \(\mathcal {C}\) be an [nkd] code over \(F_q\) with \(k\ge 1\). Then

$$\begin{aligned} n\ge \sum \limits _{i=0}^{k-1}\left\lceil \frac{d}{q^i}\right\rceil . \end{aligned}$$

Theorem 3

Let the notation be the same as before. Then we have

  1. (1)

    If Q(x) is a Type II quadratic form with rank \(r=\eta (\mu a)=1\), \(\mathcal {C}_{D_Q^a}\) is optimal.

  2. (2)

    If Q(x) is a Type III quadratic form with rank \(r=m=2\), \(\mathcal {C}_{D_Q^a}\) is almost optimal.

  3. (3)

    For the other cases, the gap between the length of codes and the Griesmer bound increases together with the dimension.

Proof

  1. (1)

    If Q(x) be a Type II quadratic form with \(r=\eta (\mu a)=1\), then \(\mathcal {C}_{D_Q^a}\) has parameters \([2q^{m-1}, m, 2q^{m-2}(q-1)]\). So it follows from Lemma 4 that

    $$\begin{aligned} n-\sum \limits _{i=0}^{k-1}\left\lceil \frac{d}{q^i}\right\rceil= & {} 2q^{m-1}-\left\lceil 2q^{m-2}(q-1)\right\rceil -\ldots -\left\lceil 2(q-1)\right\rceil -\left\lceil 2(1-\frac{1}{q})\right\rceil \\= & {} 2q^{m-1}-( 2q^{m-2}(q-1))-\ldots -( 2(q-1))-2\\= & {} 0. \end{aligned}$$

    This completes the proof of (1).

  2. (2)

    The proof is very similar to that of (1), so we omit it here.

  3. (3)

    We only prove the case that Q(x) be a Type II quadratic form with \(\eta (\mu a)=1\) and \(r\ne 1\), since the other cases can be proved with the similar idea. Theorem 2 means that the code \(\mathcal {C}_{D_Q^a}\) has parameters \([q^{m-1}+q^{m-\frac{r+1}{2}}, m, q^{m-1}-q^{m-2}]\). Then it follows from Lemma 4 that

    $$\begin{aligned} n-\sum \limits _{i=0}^{k-1}\left\lceil \frac{d}{q^i}\right\rceil= & {} q^{m-1}+q^{m-\frac{r+1}{2}}-\left\lceil q^{m-1}-q^{m-2}\right\rceil \\&-\ldots -\left\lceil q-1\right\rceil -\left\lceil 1-\frac{1}{q}\right\rceil \\= & {} q^{m-1}+q^{m-\frac{r+1}{2}}-( q^{m-1}-q^{m-2})-\ldots -( q-1)-1\\= & {} q^{m-\frac{r+1}{2}}. \end{aligned}$$

This completes the proof of (3). \(\square \)

5 Minimal codewords in \(\mathcal {C}_{D_Q^a}\)

The support of a vector \(\mathbf {c }= (c_0,\ldots , c_{n-1}) \in F_q^n\) is defined as

$$\begin{aligned} \{0 \le i \le n-1 : c_i \not = 0\}. \end{aligned}$$

We say that a vector \(\mathbf {x}\) covers a vector \(\mathbf {y}\) if the support of \(\mathbf {x}\) contains that of \(\mathbf {y}\) as a proper subset.

A minimal codeword of a linear code \(\mathcal {C}\) is a nonzero codeword that does not cover any other nonzero codeword of \(\mathcal {C}\). It is an interesting problem to construct codes whose nonzero codewords are all minimal since such linear codes can be employed to construct secret sharing schemes with interesting access structures [28]. For minimal codewords, we have following results [1, 2]:

Lemma 5

In an [nkd] code \(\mathcal {C}\), let \(w_{min}\) and \(w_{max}\) be the minimum and maximum nonzero weights, respectively. If

$$\begin{aligned} \frac{w_{min}}{w_{max}} >\frac{q-1}{q}, \end{aligned}$$

then all nonzero codewords of \(\mathcal {C}\) are minimal.

In this section, we will show that for most of quadratic forms Q(x) and q and a, each of codewords of \(\mathcal {C}_{D_Q^a}\) given by (2) is minimal.

If Q(x) is equivalent to Type I, then for \(\mathcal {C}_{D_Q^a}\) we have

$$\begin{aligned} \frac{w_{min}}{w_{max}}=\frac{q^{m-1}-q^{m-2}-2q^{m-\frac{r}{2}-1}}{q^{m-1}-q^{m-2}}>\frac{q-1}{q} \end{aligned}$$

if \(r=4\) and \(q\ge 5,\) or if \(r\ge 6\). When Q(x) is equivalent to Type III, we have

$$\begin{aligned} \frac{w_{min}}{w_{max}}=\frac{q^{m-1}-q^{m-2}}{q^{m-1}-q^{m-2}+2q^{m-\frac{r}{2}-1}}>\frac{q-1}{q} \end{aligned}$$

for all even \(r\ge 4\).

Similarly, if \(r\ge 5\) is odd, we have \(\frac{w_{min}}{w_{max}}>\frac{q-1}{q}\).

By Lemma 5, for certain smaller r and if \(m \ge r \ge 5\) for all odd prime power q, the linear codes \(\mathcal {C}_{D_Q^a}\) we constructed satisfy the condition \(\frac{w_{min}}{w_{max}}>\frac{q-1}{q}\), and can be employed to obtain secret sharing schemes with nice access structures. We omit the details here since it is similar to that of [10].

6 Conclusion

In this paper, we presented a family of linear codes with defining set \(D_Q^a\), where \(a\in F_q\) and Q(x) is any quadratic form, and determined their complete weight enumerators. Our results are extensions of earlier related works and some of the code we derived are optimal or almost optimal codes. We also discussed the application of the linear codes in secret sharing.