1 Introduction

Let \( {{\mathbb {F}}}_{p^m}\) be a finite field of size \(p^m\), where p is an odd prime. An [nk] linear code \({{\mathcal {C}}}\) over \( {{\mathbb {F}}}_p\) is a k-dimensional linear subspace of \( {{\mathbb {F}}}_p^n\). The Hamming weight of a codeword \((c_0, c_1, \ldots , c_{n-1})\) in \({{\mathcal {C}}}\) is the number of nonzero \(c_i\) for \(0\le i\le n-1\). Let \(A_i\) denote the number of nonzero codewords with Hamming weight i in \({{\mathcal {C}}}\). The weight enumerator of \({{\mathcal {C}}}\) is defined by \(1 + A_1 z + \cdots + A_n z^n\). The sequence \((1, A_1, \ldots , A_n)\) is called the weight distribution of \({{\mathcal {C}}}\). The weight distribution of a code not only gives the error correcting ability of the code, but also allows the computation of the error probability of error detection and correction [17]. Therefore, the research of the weight distribution of a linear code is important in both theory and applications.

Let \(\mathrm{Tr}\) denote the trace function from \( {{\mathbb {F}}}_{p^m}\) to \( {{\mathbb {F}}}_p\). From a subset \(D=\{d_1, d_2, \ldots , d_n\}\subset {{\mathbb {F}}}_{p^m}\), Ding et al. defined a generic class of linear codes of length \(n=|D|\) over \( {{\mathbb {F}}}_p\) as

$$\begin{aligned} {{\mathcal {C}}}_D = \left\{ \left( \mathrm{Tr}( xd_1), \mathrm{Tr}( xd_2), \ldots , \mathrm{Tr}(xd_n) \right) \, |\, x\in {{\mathbb {F}}}_{p^m} \right\} . \end{aligned}$$
(1)

Here D is called the defining set of \({{\mathcal {C}}}_D\). This construction is generic in the sense that many classes of known codes could be produced by selecting the defining set D.

As far as we know, this technique was first employed in [3, 4] for obtaining good linear codes. Recently, Ding in [5, 6] studied linear codes whose defining sets were chosen from some specific classes of 2-designs or (pre)images of certain Boolean functions. In the past three years, many authors worked on this topic. The reader is referred to [5,6,7,8, 14,15,16, 19, 21,22,23, 25,26,28] and the references therein.

Let f be a polynomial over \( {{\mathbb {F}}}_{p^m}\). Define

$$\begin{aligned} D_f = \left\{ x \in {{\mathbb {F}}}_{p^m}^* \, |\, \mathrm{Tr}(f(x)) = 0\right\} . \end{aligned}$$

Using \(D_f\) as a defining set, Zhang et al. in [26] showed the complete weight enumerators of a class of linear codes from a general quadratic polynomial f(x) over \( {{\mathbb {F}}}_{p^m}\). From [26] we know that the parameters of the linear code \({{\mathcal {C}}}_{D_f}\) depend on the rank and determinant of the quadratic form \(\mathrm{Tr}(f)\), which are difficult to determine in general.

In fact, from the point of view of geometry, the weight distribution of \({{\mathcal {C}}}_{D_f}\) is connected to the size of the intersection of the set \(D_f\) and the hyperplane \(H_a=\{x\, |\, \mathrm{Tr}(ax)=0\}\). If f is a DO polynomial, then \(D_f\) is a quadric. When the quadric and hyperplane have the same size, Games in [13] determined the intersection sizes and their corresponding frequencies. In this paper, we will present a class of linear codes from binomial quadratic polynomials over \( {{\mathbb {F}}}_{p^m}\) and determine their weight distributions explicitly by the application of the theory of quadratic forms over finite fields. Second, motivated by the idea of [29, 30], we study a class of linear codes \({{\mathcal {C}}}_{D_f}\) from \(f=x^\ell \) for \(\ell \) satisfying some congruence conditions and derive their weight distributions by converting the exponential sum related to non-quadratic forms to that related to quadratic forms. From the constructed codes, we obtain some optimal linear codes with respect to the Griesmer bound and the Singleton bound.

The remainder of this paper is organized as follows. Section 2 gives some preliminaries on quadratic forms over finite fields. In Sect. 3 we present the weight distributions of a class of linear codes from some special DO polynomials. Section 4 determines the weight distributions of a class of linear codes from some non-quadratic functions. Finally, Sect. 5 concludes this paper.

2 Preliminaries

Let p be an odd prime and \( {{\mathbb {F}}}_{p^m}\) be a finite field of size \(p^m\). A polynomial \(f(x)\in {{\mathbb {F}}}_{p^m}[x]\) called a DO polynomial was defined in [11] with the following shape:

$$\begin{aligned} f(x)=\sum _{i,j=0}^{m-1} a_{ij} x^{p^i+p^j}, \,\, a_{ij}\in {{\mathbb {F}}}_{p^m} . \end{aligned}$$

It is clear that f(x) is also a homogeneous quadratic polynomial. A function \(Q(x_1, x_2, \ldots , x_m)\) from \( {{\mathbb {F}}}_{p}^m\) to \( {{\mathbb {F}}}_p\) is called a quadratic form if it is a homogenous polynomial of degree two as follows:

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

We fix a basis \(\{\alpha _1, \alpha _2, \ldots , \alpha _m\}\) of \({\mathbb {F}}_{p^m}\) over \({\mathbb {F}}_p\) and identify \(x=\sum _{i=1}^mx_i\alpha _i\) with the vector \((x_1,x_2,\ldots ,x_m)\in {\mathbb {F}}_p^m\), then \(\mathrm{Tr} ( f(x))\) is a quadratic form in the coordinates of \( {{\mathbb {F}}}_p^m\). Moreover, every quadratic form Q(x) from \( {{\mathbb {F}}}_{p^m}\) to \( {{\mathbb {F}}}_p\) can be represented as

$$\begin{aligned} Q(x) = \mathrm{Tr} \left( f(x)\right) , \end{aligned}$$

where f(x) is a DO polynomial defined above. The rank of the quadratic form Q(x) is defined as the codimension of \( {{\mathbb {F}}}_p\)-vector space

$$\begin{aligned} V = \{ z\in {{\mathbb {F}}}_{p^m}\, \, |\,\, Q(x+z)-Q(x)-Q(z)=0, \,\, \text{ for } \text{ all }\,\, z\in {{\mathbb {F}}}_{p^m} \} , \end{aligned}$$

which is denoted by rank(Q). Then \(|V| = p^{m-\mathrm{rank}(Q)}\).

For a quadratic form Q(x) with m variables over \( {{\mathbb {F}}}_p\), there exists a symmetric matrix A such that \(Q(x)=XAX^\prime \), where \(X=(x_1, x_2, \ldots , x_m)\in {{\mathbb {F}}}_p^m\) and \(X^\prime \) denotes the transpose of X. The determinant \(\mathrm{det}(Q)\) of Q(x) is defined to be the determinant of A, and Q(x) is nondegenerate if \(\mathrm{det}(Q)\ne 0\). It is known that there exists a nonsingular matrix T such that \(TAT^\prime \) is a diagonal matrix [18]. Making a nonsingular linear substitution \(X=YT\) with \(Y=(y_1, y_2, \ldots , y_m)\), we have

$$\begin{aligned} Q(x)= Y TAT^\prime Y^\prime = \sum _{i=1}^r a_i y_i^2, \,\, a_i\in {{\mathbb {F}}}_p , \end{aligned}$$

where \(r(\le m)\) is the rank of Q(x). The following lemma gives a general result on an exponential sum of a quadratic function from \( {{\mathbb {F}}}_{p^m}\) to \( {{\mathbb {F}}}_p\).

Lemma 1

(see Theorems 5.15 and 5.33 of [18]) Let Q(x) be a quadratic function from \( {{\mathbb {F}}}_{p^m}\) to \( {{\mathbb {F}}}_p\) with rank r, and \(\eta \) be the quadratic multiplicative character of \( {{\mathbb {F}}}_p\). Then

$$\begin{aligned} \sum _{x\in {{\mathbb {F}}}_{p^m}} \omega _p^{Q(x)}= \eta (\varDelta ) \delta _{p,r} p^{m-\frac{r}{2}}, \end{aligned}$$

where \(\omega _p\) is a pth primitive root of unity, and \(\varDelta \) is the determinant of Q(x), and \(\delta _{p,r} = (-1)^{\frac{r(p-1)^2}{8}}\). Moreover, for any \(z\in {{\mathbb {F}}}_{p}^*\),

$$\begin{aligned} \sum _{x\in {{\mathbb {F}}}_{p^m}} \omega _p^{z Q(x)}=\eta ^r(z)\eta (\varDelta ) \delta _{p,r} p^{m-\frac{r}{2}}. \end{aligned}$$

It is well known that the parameters of an [nkd] linear code \({{\mathcal {C}}}\) over \( {{\mathbb {F}}}_p\) satisfy

$$\begin{aligned} d \le n-k+1, \end{aligned}$$
(2)

and

$$\begin{aligned} n \ge \sum _{i=0}^{k-1} \left\lceil \frac{d}{p^i}\right\rceil , \end{aligned}$$
(3)

where \(\lceil x\rceil \) denotes the smallest integer, which is larger than or equal to x. If the equality in (2) holds, then \({{\mathcal {C}}}\) is called an optimal code with respect to the Singleton bound. If the equality in (3) holds, then \({{\mathcal {C}}}\) is called an optimal code with respect to the Griesmer bound.

Two linear codes \({\mathcal {C}}\) and \(\mathcal {C'}\) of length n over \( {{\mathbb {F}}}_{p^m}\) are equivalent (see Sect. 1 of Chapter 2 in [20]) if there exist n permutations \(\pi _0, \pi _1, \ldots , \pi _{n-1}\) of the \(p^m\) elements in \( {{\mathbb {F}}}_{p^m}\) and a permutation \(\sigma \) of the n coordinate positions such that if \((c_0,c_1,\ldots ,c_{n-1}) \in {\mathcal {C}}\), then \(\sigma (\pi _0(c_0),\pi _1(c_1),\ldots ,\pi _{n-1}(c_{n-1})) \in \mathcal {C'}\). That is to say, let G and \(G^\prime \) be generator matrices of \({{\mathcal {C}}}\) and \({{\mathcal {C}}}^\prime \) respectively. The codes \({\mathcal {C}}\) and \(\mathcal {C'}\) are equivalent if there exists a monomial matrix M such that \(G^\prime = G M\), where M is a square matrix such that in every row (and in every column) there is exactly one nonzero element in \( {{\mathbb {F}}}_{p^m}\).

In order to discuss the existence of the solutions for two congruence equations in Sect. 4, we need the following well known facts.

Lemma 2

Let \(\phi , \varphi , \mu \) be three nonzero elements in \({\mathbb {F}}_{p^m}\). Then for any congruence equation \(\phi x\equiv \varphi \pmod \mu \), the equation has solutions if and only if \(\gcd (\phi ,\mu )\ | \ \varphi \). Moreover, the number of solutions is \(\gcd (\phi ,\mu )\).

Lemma 3

Let h, g be two positive integers. Then

$$\begin{aligned} \gcd (p^h+1, p^g-1)=\left\{ \begin{array}{ll} p^{\gcd (h,g)}+1, &{}\quad \mathrm{if}\; \dfrac{g}{\gcd (h,g)} \, \,\, \mathrm{is\,\, even},\\ 2, &{}\quad \mathrm{if }\; \dfrac{g}{\gcd (h,g)} \,\,\, \mathrm{is\,\, odd}. \end{array} \right. \end{aligned}$$

3 Linear codes from DO polynomials

Let \( {{\mathbb {F}}}_{p^m}\) be a finite field with \(p^m\) elements, where p is an odd prime and m is a positive integer. Let \(\mathrm{Tr}\) denote the trace function from \( {{\mathbb {F}}}_{p^m}\) to \( {{\mathbb {F}}}_p\). Let f(x) be a DO polynomial over \( {{\mathbb {F}}}_{p^m}\). Recall that

$$\begin{aligned} D_f = \{ x\in {{\mathbb {F}}}_{p^m}^* \, |\, \mathrm{Tr}(f(x)) = 0 \}=\{d_1, d_2, \ldots , d_n \} \subset {{\mathbb {F}}}_{p^m}^* . \end{aligned}$$

From this set, we obtain a linear code proposed in [8] as follows:

$$\begin{aligned} {{\mathcal {C}}}_{D_f} = \{ \left( \mathrm{Tr}(xd_1), \mathrm{Tr}(xd_2), \ldots , \mathrm{Tr}(xd_n)\right) \,|\, x\in {{\mathbb {F}}}_{p^m}\}. \end{aligned}$$
(4)

From [10, 26], we can get the following lemmas.

Lemma 4

Let \({{\mathcal {C}}}_{D_f}\) be the linear code defined in (4) and n be the length of the codewords in \({{\mathcal {C}}}_{D_f}\). Let r be the rank of the quadratic form \(Q(x)= \mathrm{Tr}(f(x))\) and its determinant be denoted by \(\varDelta \). Then

$$\begin{aligned} n = \left\{ \begin{array}{ll} p^{m-1} - 1, &{}\quad \mathrm{if} \,\, r \,\, \mathrm{is \,\, odd}, \\ p^{m-1} -1 + (p-1)\eta (\varDelta ) \delta _{p, r} p^{m-1-\frac{r}{2}}, &{}\quad \mathrm{if} \,\, r \,\, \mathrm{is \,\, even}, \end{array}\right. \end{aligned}$$

where \(\eta \) is the quadratic character of \( {{\mathbb {F}}}_p\) and \(\delta _{p,r}\) is defined in Lemma 1.

Lemma 5

Let f be a DO polynomial over \( {{\mathbb {F}}}_{p^m}\) and \(\mathrm{Tr}(f)\) be a quadratic form with rank r. Let \({{\mathcal {C}}}_{D_f}\) be the linear code defined in (4).

  1. (1)

    If r is odd, then \({{\mathcal {C}}}_{D_f}\) is a \([p^{m-1}-1, m, (p-1)(p^{m-2}-p^{\frac{2m-r-3}{2}})]\) code with the weight distribution in Table 1.

  2. (2)

    If r is even, then \({{\mathcal {C}}}_{D_f}\) is a \([p^{m-1}-1+\epsilon (p-1)p^{\frac{2m-r-2}{2}}, m]\) code with the weight distribution in Table 2, where \(\epsilon =\eta (\varDelta )\delta _{p,r}\), \(\varDelta \) is the determinant of \(\mathrm{Tr}(f)\), \(\eta \) is the quadratic character of \( {{\mathbb {F}}}_p\), and \(\delta _{p,r}\) is defined in Lemma 1.

Table 1 Weight distribution of \({{\mathcal {C}}}_{D_f}\) for an odd r
Table 2 Weight distribution of \({{\mathcal {C}}}_{D_f}\) for an even r

It is observed that the Hamming weight of each codeword in the code \({{\mathcal {C}}}_{D_f}\) has a common divisor \(p-1\). This indicates that \({{\mathcal {C}}}_{D_f}\) may be punctured into a shorter one whose weight distribution is derived from that of the original code. To this end, we define a equivalence relation in the set \(D_f\) as follows. For \(\beta ,\gamma \in D_f\), we say that \(\beta \) is equivalent to \(\gamma \) if and only if there exists \(a\in {{\mathbb {F}}}_p^*\) such that \(\beta =a \gamma \). The elements chosen from each equivalent class in \(D_f\) consist of a set \({\bar{D}}_f\). It is obvious that

$$\begin{aligned} D_f = {{\mathbb {F}}}_p^* {\bar{D}}_f = \{ab \,\, :\,\, a\in {{\mathbb {F}}}_p^*,\,\, b \in {\bar{D}}_f\} . \end{aligned}$$
(5)

Then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a punctured version of \({{\mathcal {C}}}_{D_f}\), whose parameters are given in the following proposition.

Proposition 1

Let f be a DO polynomial over \( {{\mathbb {F}}}_{p^m}\) and r be the rank of quadratic form \(\mathrm{Tr}(f)\). Let \({{\mathcal {C}}}_{{\bar{D}}_f}\) be the linear code defined above, where \({\bar{D}}_f\) is defined in (5).

  1. (1)

    If r is odd, then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}, m, p^{m-2}-p^{\frac{2m-r-3}{2}}]\) code with the weight distribution in Table 3.

  2. (2)

    If r is even, then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}+\epsilon p^{\frac{2m-r-2}{2}}, m]\) code with the weight distribution in Table 4, where \(\epsilon =\eta (\varDelta )\delta _{p,r}\), \(\varDelta \) is the determinant of \(\mathrm{Tr}(f)\), \(\eta \) is the quadratic character of \( {{\mathbb {F}}}_p\) and \(\delta _{p,r}\) is defined in Lemma 1.

Table 3 Weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) for an odd r
Table 4 Weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) for an even r

From the weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) above, we obtain some optimal linear codes with respect to the Singleton bound or the Griesmer bound as follows.

Corollary 1

Let f be a DO polynomial over \( {{\mathbb {F}}}_{p^m}\) and r be the rank of quadratic form \(\mathrm{Tr}(f)\). Let \({{\mathcal {C}}}_{{\bar{D}}_f}\) be the linear code defined above.

  1. (1)

    If \(r=m=3\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([p+1,3,p-1]\) code. This code is optimal with respect to the Singleton bound and the Griesmer bound.

  2. (2)

    If \(r=m=4\), and the determinant of \(\mathrm{Tr}(f)\) is a non-square element in \( {{\mathbb {F}}}_p^*\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([p^2+1,4,p^2-p]\) code. This code is optimal with respect to the Griesmer bound.

Proof

When \(r=m=3\), from Proposition 1 we know that the length n of \({{\mathcal {C}}}_{{\bar{D}}_f}\) is \(p+1\), the dimension k of \({{\mathcal {C}}}_{{\bar{D}}_f}\) is 3, and the minimal distance d is \(p-1\). It is easy to verify that these parameters of the code \({{\mathcal {C}}}_{{\bar{D}}_f}\) satisfy the equality in (2) and (3), respectively. Therefore, \({{\mathcal {C}}}_{{\bar{D}}_f}\) is optimal with respect to the Singleton bound and the Griesmer bound. The proof of case (2) is similar, and we omit the details here. \(\square \)

Remark 1

Section 5 of Chapter 11 in [20] has proved that there exist \([p+1,3,p-1]\) (cyclic) MDS codes. Corollary 1 only provides a class of MDS code with this parameters by trace representations.

It is well known that an [nk] linear code is called projective if no two columns of a generator matrix G are linearly dependent, i.e., if the columns of G are pairwise different points in a projective \((k-1)\)-dimensional space. A strong regular graph with parameters \((v, K, \lambda , \mu )\) is a finite simple graph with v vertices which is regular of degree K, and any two distinct vertices have \(\lambda \) common neighbours if they are adjacent and \(\mu \) common neighbours if they are non-adjacent. There are strong connections between projective two-weight codes and strong regular graphs.

Let q be a power of a prime and \( {{\mathbb {F}}}_q\) be a finite field with q elements. In 1985, Calderbank and Kantor [9] showed that if an [nk] linear code with weights \(w_1\) and \(w_2\) over \({\mathbb {F}}_q\) is a projective two-weight code, then we can obtain a strong regular graph with the following parameters (Corollary 3.7 in [2]),

$$\begin{aligned} \begin{aligned}&v=q^k,\quad K=n(q-1),\\&\lambda =K^2+3K-q(w_1+w_2)-Kq(w_1+w_2)+q^2w_1w_2,\\&\mu =\frac{q^2w_1w_2}{q^k}=K^2+K-kq(w_1+w_2)+q^2w_1w_2. \end{aligned} \end{aligned}$$

In 2006, Bouyukliev et al. [1] showed that a two-weight code \([q^2+1, 4, q^2-q]\) with weights \(w_1=q^2-q\) and \(w_2=q^2\) is a projective two-weight code. Hence, from the code in Corollary 1, we can obtain a strong regular graph with parameters \((p^4, p^3-p^2+p-1, p-2, p^2-p)\).

Example 1

(1) Let \(p=3\) and \(m=3\). Let \(f(x)=x^2\), \(x^4\), \(x^{10}-x^6-x^2\) or \(x^{10}+x^6-x^2\). Then the code \(C_{{\bar{D}}_f}\) has parameters [4, 3, 2] and the weight enumerator \(1+12x^2+8x^3+6x^4\). This code is an MDS code and is optimal with respect to the Griesmer bound.

(2) Let \(p=7\) and \(m=4\). Let \(f(x)=x^{50}\) or \(\alpha ^{11}x^8+\alpha ^{20}x^2\), where \(\alpha \) is a primitive element of \( {{\mathbb {F}}}_{7^4}\). Then the code \(C_{{\bar{D}}_f}\) has parameters [50, 4, 42] and weight enumerator \(1+2100x^{42}+300x^{49}\). This code is optimal with respect to the Griesmer bound.

3.1 A class of linear codes from some special DO polynomials

From Proposition 1, in order to determine the parameters of the linear code \({{\mathcal {C}}}_{{\bar{D}}_f}\), we need to know the rank and determinant of the quadratic form \(\mathrm{Tr}(f)\), and they are difficult to determine in general. In this subsection, we present a class of linear codes from binomial polynomials and determine their weight distributions explicitly.

Proposition 2

Let \(\nu _2(\cdot )\) denote the 2-adic order function. Let i and j be positive integers with \(i>j\). Let \(f(x)=x^{p^i+1} + x^{p^j+1}\in {{\mathbb {F}}}_{p^m}[x]\) and \({{\mathcal {C}}}_{{\bar{D}}_f}\) be the linear code defined above.

  1. (1)

    If m is odd, then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}, m, p^{m-2}-p^{\frac{m-3}{2}}]\) code with the weight distribution in Table 5.

  2. (2)

    If \(v=\nu _2(i)=\nu _2(j)<\nu _2(m)\) and \(\nu _2(m)\le \mathrm{min}\{ \nu _2(i-j), \nu _2(i+j)\}\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}+(-1)^{\frac{m}{2^{v+1}}}p^{\frac{m-2}{2}}, m]\) code with the weight distribution in Table 6.

  3. (3)

    Let \(v=\nu _2(i)=\nu _2(j)\) and \(d=\gcd (i+j, m)\). If \(v<\nu _2(m)\) and \(\nu _2(i+j)<\nu _2(m)\le \nu _2(i-j)\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}+(-1)^{\frac{m-d}{2^{v+1}}}p^{\frac{m+d-2}{2}}, m]\) code with the weight distribution in Table 7.

  4. (4)

    Let \(v=\nu _2(i)=\nu _2(j)\) and \(d=\gcd (i-j, m)\). If \(v<\nu _2(m)\) and \(\nu _2(i-j)<\nu _2(m)\le \nu _2(i+j)\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1}+(-1)^{\frac{m-d}{2^{v+1}}}p^{\frac{m+d-2}{2}}, m]\) code with the weight distribution in Table 7.

Table 5 Weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) for an odd m
Table 6 Weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\)
Table 7 Weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\)

In order to prove Proposition 2, we need the following lemma.

Lemma 6

(see Theorem 7.3 of [12]) Let \(\nu _2(\cdot )\) denote the 2-adic order function. Let \(f\in {{\mathbb {F}}}_{p^m}[x]\) be a DO polynomial given in Proposition 2 with \(\nu _2(i)=\nu _2(j)<\nu _2(m)\). Then

$$\begin{aligned} \eta (\varDelta ) = \left\{ \begin{array}{ll} (-1)^{\left( \frac{1}{4}(p-1)^2 +1\right) \frac{r}{2}},&{} \quad v =0, \\ (-1)^{\frac{r}{2^{v+1}}} ,&{} \quad v >0, \end{array} \right. \end{aligned}$$

where \(v=\nu _2(i)\), \(\varDelta \) and r are the determinant and the rank of \(\mathrm{Tr}(f)\), respectively.

Proof of Proposition 2

It is known that the weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) is related to the determinant and rank of \(\mathrm{Tr}(f)\), and they have a connection given in Lemma 6. So, we may obtain the weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) if we can determine the rank of \(\mathrm{Tr}(f)\).

Note that the rank of \(\mathrm{Tr}(f)\) equals the codimension of \( {{\mathbb {F}}}_p\)- vector space

$$\begin{aligned} \left\{ x\in {{\mathbb {F}}}_{p^m} \,|\, \mathrm{Tr}(f(x+y)-f(x)-f(y)) = \mathrm{Tr}(yL(x)) = 0,\,\, \mathrm{for \,\,all}\,\, y\in {{\mathbb {F}}}_{p^m} \right\} , \end{aligned}$$

where

$$\begin{aligned} L(x) = x^{p^{2i}} + x^{p^{i+j}} + x^{p^{i-j}}+x. \end{aligned}$$
(6)

So, the rank of \(\mathrm{Tr}(f)\) is equal to the codimension of the null space of L(x).

Cases (1) and (2): From (6) we have

$$\begin{aligned} (x^{p^{i-j}} +x)^{p^{i+j}} + (x^{p^{i-j}}+x) = 0. \end{aligned}$$
(7)

Set \(z= x^{p^{i-j}}+x\). (7) is reduced to

$$\begin{aligned} z^{p^{i+j}} +z =0. \end{aligned}$$
(8)

Obviously, \(z=0\) is a solution of (8). If \(z\ne 0\), then we obtain \(z^{p^{i+j}-1}=-1\). Let \(\alpha \) be a primitive element of \( {{\mathbb {F}}}_{p^m}\) and \(z=\alpha ^s \) for some positive integer s. Then \(z^{p^{i+j}-1}=-1\) is reduced to

$$\begin{aligned} \alpha ^{(p^{i+j}-1)s} = \alpha ^{\frac{p^m-1}{2}}, \end{aligned}$$

which is equivalent to

$$\begin{aligned} (p^{i+j}-1)s \equiv \frac{p^m-1}{2} \,\, (\mathrm{mod }\,\, p^m-1). \end{aligned}$$
(9)

In Cases (1) and (2), it is easy to see that \(\gcd (p^{i+j}-1, p^m-1) \not \mid \frac{p^m-1}{2}\) since \(\nu _2(m)\le \nu _2(i+j)\). By Lemma 2, (9) has no solution for s. It follows that (8) has only one solution \(z=0\). Similarly, one can verify that \(x^{p^{i-j}} + x =0\) has also only one solution \(x=0\) since \(\nu _2(m)\le \nu _2(i-j)\). That is to say, the rank of \(\mathrm{Tr}(f)\) is m. In the case of m being odd, from Table 3 we get the weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\), which is given in Table 5. In the case of \(\nu _2(m)>0\), from Lemma 6 we have

$$\begin{aligned}\begin{aligned} \epsilon&= \eta (\varDelta ) \delta _{p,m} = \left\{ \begin{array}{ll} (-1)^{\left( \frac{1}{4}(p-1)^2 +1\right) \frac{m}{2}}(-1)^{\frac{(p-1)^2m}{8}},&{} \quad v =0 \\ (-1)^{\frac{m}{2^{v+1}}}(-1)^{\frac{(p-1)^2m}{8}},&{} \quad v >0 \end{array} \right. \\&= (-1)^{\frac{m}{2^{v+1}}} . \end{aligned} \end{aligned}$$

Substituting this \(\epsilon \) and \(r=m\) into Table 4, we get Table 6.

Case (3): From (6) we get

$$\begin{aligned} (x^{p^{i+j}} +x)^{p^{i-j}} + (x^{p^{i+j}}+x) = 0. \end{aligned}$$
(10)

Set \(y= x^{p^{i+j}}+x\). (10) is reduced to

$$\begin{aligned} y^{p^{i-j}} + y =0 . \end{aligned}$$
(11)

Then using similar techniques as we prove the number of solutions in (8), we obtain that (11) has only one solution \(y=0\), and \(x^{p^{i+j}} + x =0\) has \(p^d\) solutions since \(\nu _2(i+j)<\nu _2(m)\le \nu _2(i-j)\), where \(d=\gcd (i+j, m)\). So, the rank of \(\mathrm{Tr}(f)\) is equal to \(m-d\). In this case, from Lemma 6 we have

$$\begin{aligned}\begin{aligned} \epsilon&= \eta (\varDelta ) \delta _{p,m-d} = \left\{ \begin{array}{ll} (-1)^{\left( \frac{1}{4}(p-1)^2 +1\right) \frac{m-d}{2}}(-1)^{\frac{(p-1)^2(m-d)}{8}},&{} \quad v =0 \\ (-1)^{\frac{m-d}{2^{v+1}}}(-1)^{\frac{(p-1)^2(m-d)}{8}},&{} \quad v >0 \end{array} \right. \\&= (-1)^{\frac{m-d}{2^{v+1}}}. \end{aligned} \end{aligned}$$

Substituting this \(\epsilon \) and \(r=m-d\) into Table 4, we get Table 7.

The proof of Case (4) is similar to that of Case (3). \(\square \)

Example 2

(1) Let \(p=3, m=3\) and \(f(x)=x^{10}+x^4\) or \(x^{28}+x^4\). Then the code \(C_{{\bar{D}}_f}\) has parameters [4, 3, 2] and the weight enumerator \(1+12x^2+8x^3+6x^4\). This code is an MDS code and optimal with respect to the Griesmer bound.

(2) Let \(p=3, m=6\) and \(f(x)=x^{28}+x^4\). Then the code \(C_{{\bar{D}}_f}\) has parameters [224, 6, 72] and the weight enumerator \(1+504x^{72}+224x^{81}\).

(3) Let \(p=3, m=12\) and \(f(x)=x^{3^9+1}+x^{4}\) or \(x^{3^7+1}+x^{4}\). Then the code \(C_{{\bar{D}}_f}\) has parameters [87844, 12, 58320] or [82012, 12, 52488] and the weight enumerators \(1+39528x^{58320}+ 472392x^{58563} + 19520x^{59049}\) or \(1+504x^{52488}+ 224x^{59049}+472392x^{54675}\), respectively.

4 Linear codes from \(f=x^\ell \) for \(\ell \) satisfying some congruence conditions

Let \( {{\mathbb {F}}}_{p^m}\) be a finite field of size \(p^m\), where m is odd and p is an odd prime with \(p \equiv 3 \pmod 4\). Let \(\ell \) be an even integer satisfying one of the following conditions:

$$\begin{aligned} \begin{aligned} \bullet \quad&( p^k+1) \ell \equiv \frac{p^m+1}{2}\pmod {p^m-1};\\ \bullet \quad&\frac{p^m+1}{2} \ell \equiv p^k+1 \pmod {p^m-1}, \end{aligned} \end{aligned}$$
(12)

where k is a nonnegative integer. Next, we show that there exists an even integer satisfying one of congruence equations in (12). Since m is odd, by Lemma 3 we have \(2=\gcd (p^k+1, p^m-1)\ |\ \frac{p^m+1}{2}\) and \(2=\gcd (\frac{p^m+1}{2}, p^m-1)\ | \ p^k+1\). Then the congruence equations in (12) have solutions for any integer k by Lemma 2. On the other hand, let b be an integer satisfying the first congruence equation. Then \((p^k+1)(b+\frac{p^m-1}{2}) \equiv (p^k+1)b \equiv \frac{p^m+1}{2} \pmod {p^m-1}\). Similarly, if an integer b satisfies the second congruence equation, then \(\frac{p^m+1}{2}(b+\frac{p^m-1}{2}) \equiv \frac{p^m+1}{2}b \equiv p^k+1\pmod {p^m-1}\). These show that if an integer b satisfies one of the congruence equations in (12), then \(b+\frac{p^m-1}{2}\) satisfies the corresponding congruence equation. Since \(p \equiv 3 \pmod 4\) and m is odd, the number \(\frac{p^m-1}{2}\) is odd. Hence, there exists an even integer satisfying each congruence equation in (12).

In this section, we will investigate the weight distribution of a linear code defined by

$$\begin{aligned} {{\mathcal {C}}}_{D_f} = \left\{ (\mathrm{Tr}(xd_1), \mathrm{Tr}(xd_2), \ldots , \mathrm{Tr}(xd_n) )\, |\, x\in {{\mathbb {F}}}_{p^m} \right\} , \end{aligned}$$
(13)

where the defining set \(D_f\) is as follows:

$$\begin{aligned} D_f = \{ x\in {{\mathbb {F}}}_{p^m}^* \, |\, \mathrm{Tr}(x^\ell ) = 0 \} = \{d_1, d_2, \ldots , d_n \}. \end{aligned}$$

The following lemma presents the length of the linear code \({{\mathcal {C}}}_{D_f}\).

Lemma 7

Let p be an odd prime with \(p\equiv 3 \pmod 4\). Let m be an odd number and \(\ell \) be an even number satisfying one of the conditions in (12). Let \({{\mathcal {C}}}_{D_f}\) be the linear code defined in (13). Then the length of the codewords in \({{\mathcal {C}}}_{D_f}\) is \(p^{m-1}-1\).

Proof

We only prove the case of \(\ell \) satisfying the first condition of (12), i.e., \(( p^k+1) \ell \equiv \frac{p^m+1}{2} \pmod {p^m-1}\), and the proof of the case of \(\ell \) satisfying the second condition of (12) is similar.

Let SQ and NSQ denote the set of all square elements and non-square elements in \( {{\mathbb {F}}}_{p^m}^*\), respectively. Let n be the length of a codeword in \({{\mathcal {C}}}_{D_f}\).

$$\begin{aligned} \begin{aligned} n&= \sharp \{x \in {{\mathbb {F}}}_{p^m}^*|\mathrm{Tr}(x^\ell )=0\} =\frac{p^m-1}{p}+\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\sum _{x \in {{\mathbb {F}}}_{p^m}^{*}}\omega _p^{u\mathrm{Tr}(x^\ell )}\\&=\frac{p^m-1}{p}+\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\left( \sum _{x \in \mathrm{SQ}}\omega _p^{u\mathrm{Tr}(x^\ell )}+\sum _{x \in \mathrm{NSQ}}\omega _p^{u\mathrm{Tr}(x^\ell )}\right) \\&=\frac{p^m-1}{p}+\frac{1}{2p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\sum _{x \in {{\mathbb {F}}}_{p^m}^{*}}\left( \omega _p^{u\mathrm{Tr}(x^{\ell (p^k+1)})}+\omega _p^{u\mathrm{Tr}((-1)^\ell x^{\ell (p^k+1)})}\right) \\&=\frac{p^m-1}{p}+\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\sum _{x \in {{\mathbb {F}}}_{p^m}^{*}}\omega _p^{u\mathrm{Tr}\left( x^{\frac{p^m+1}{2}}\right) }, \end{aligned} \end{aligned}$$
(14)

where in the fourth equality, we used the fact that \(\{ x^{p^k+1} \, |\, x\in {{\mathbb {F}}}_{p^m}^* \}= \{ x^2 \, |\, x\in {{\mathbb {F}}}_{p^m}^* \}\) since \(\gcd (p^k+1, p^m-1) =2\).

It is easy to see that \(\gcd (\frac{p^m+1}{2}, p^m-1)=2\) since \(p\equiv 3 \pmod 4\) and m is odd. So, \(\{ x^\frac{p^m+1}{2} \, |\, x\in {{\mathbb {F}}}_{p^m}^* \} = \{ x^2 \, |\, x\in {{\mathbb {F}}}_{p^m}^* \}\). From Lemma 1, we have

$$\begin{aligned} \begin{aligned} n&=\frac{p^m-1}{p}+\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\sum _{x \in {{\mathbb {F}}}_{p^m}^{*}}\omega _p^{u\mathrm{Tr}(x^2)}\\&=p^{m-1}-1+\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^{*}}\eta ^m(u)\sum _{x \in {{\mathbb {F}}}_{p^m}^*}\omega _p^{\mathrm{Tr}(x^2)}\\&=p^{m-1}-1. \end{aligned} \end{aligned}$$

\(\square \)

To determine the weight distribution of \({{\mathcal {C}}}_{D_f}\), we need to show the value distribution of the set

$$\begin{aligned} N_{\ell }(b) = \sharp \{ x \in {{\mathbb {F}}}_{p^m} \, |\, \mathrm{Tr}(x^\ell + bx ) = 0 \} \end{aligned}$$

for b running over \( {{\mathbb {F}}}_{p^m}^*\). To this end, we will investigate the relation of the value distribution between \(N_\ell (b)\) and the following two sets

$$\begin{aligned} N_{k}(b,1)=\sharp \{ x \in {{\mathbb {F}}}_{p^m} \, |\, \mathrm{Tr}\left( bx^{p^k+1} + x \right) = 0 \} \end{aligned}$$

and

$$\begin{aligned} N_{k}(1,b)=\sharp \{ x \in {{\mathbb {F}}}_{p^m} \, |\, \mathrm{Tr}\left( x^{p^k+1} + bx \right) = 0 \} \end{aligned}$$

for b running through \( {{\mathbb {F}}}_{p^m}^*\).

Lemma 8

Let p be a prime with \(p\equiv 3 \pmod 4\). Let m be an odd number and \(\ell \) be an even number satisfying one of the conditions in (12). When b runs over \( {{\mathbb {F}}}_{p^m}^*\), the sets \(N_\ell (b), N_k(b, 1)\) and \(N_{k}(1,b)\) have the same value distribution as follows:

$$\begin{aligned} \left\{ \begin{array}{lll} p^{m-1}, &{} p^{m-1}-1 \,\, &{}\mathrm{times}, \\ p^{m-1}-p^{\frac{m-1}{2}}, &{}\frac{p-1}{2}\left( p^{m-1}-p^{\frac{m-1}{2}}\right) \,\, &{}\mathrm{times},\\ p^{m-1}+p^{\frac{m-1}{2}}, &{}\frac{p-1}{2}\left( p^{m-1}+p^{\frac{m-1}{2}}\right) \,\, &{}\mathrm{times}. \end{array} \right. \end{aligned}$$
(15)

Proof

Let \(\mathrm{SQ}\) and \(\mathrm{NSQ}\) denote all square elements and non-square elements in \( {{\mathbb {F}}}_{p^m}^*\), respectively. It is easy to verify that \( \{ x^{p^k+1} \,|\, x \in {{\mathbb {F}}}_{p^m}\}= \{ x^2 \,|\, x\in {{\mathbb {F}}}_{p^m} \}\) for m being odd. If \(\ell \) satisfies the first condition of (12), then

$$\begin{aligned} \begin{aligned} N_\ell (b) =&\sharp \left\{ x\in {{\mathbb {F}}}_{p^m}\,|\, \mathrm{Tr}(x^\ell +bx)=0 \right\} \\ =&1+\sharp \left\{ x \in \mathrm{SQ} \,| \,\mathrm{Tr}(x^\ell +bx)=0\right\} + \sharp \left\{ x \in \mathrm{NSQ}\, | \,\mathrm{Tr}(x^\ell + bx )=0\right\} \\ =&1+\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}^*\, |\,\mathrm{Tr}\left( x^{\frac{p^m+1}{2}}+bx^{p^k+1}\right) =0\right\} \\&+\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}^*\, | \,\mathrm{Tr}\left( (-1)^\ell x^{\frac{p^m+1}{2}}-bx^{(p^k+1)}\right) =0\right\} . \end{aligned} \end{aligned}$$

Observe that \(x^{\frac{p^m+1}{2}}=x\) or \(-x\) for x in \(\mathrm{SQ}\) or \(\mathrm{NSQ}\), respectively. Since \(\ell \) is even and m is odd, we have

$$\begin{aligned} \begin{aligned} N_\ell (b)=&1+\frac{1}{2}\sharp \left\{ x \in \mathrm{SQ}\,|\,\mathrm{Tr}\left( x+bx^{p^k+1}\right) =0\right\} \\&+\frac{1}{2} \sharp \left\{ x \in \mathrm{NSQ}\,| \, \mathrm{Tr}\left( -x+bx^{p^k+1}\right) =0\right\} \\ +&\frac{1}{2}\sharp \left\{ x \in \mathrm{SQ}\,| \,\mathrm{Tr}\left( x-bx^{p^k+1}\right) =0\right\} \\&+\frac{1}{2}\sharp \left\{ x \in \mathrm{NSQ} \,| \,\mathrm{Tr}\left( -x-bx^{p^k+1}\right) =0\right\} \\ =&1+\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}^* | \,\mathrm{Tr}\left( x+bx^{p^k+1}\right) =0\right\} \\&+\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}^*| \,\mathrm{Tr}\left( x-bx^{p^k+1}\right) =0\right\} \\ =&\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}| \,\mathrm{Tr}\left( x+bx^{p^k+1}\right) =0\right\} \\&+\frac{1}{2}\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}| \,\mathrm{Tr}\left( -x-b(-x)^{p^k+1}\right) =0\right\} \\ =&\sharp \left\{ x \in {{\mathbb {F}}}_{p^m}\,| \,\mathrm{Tr}\left( bx^{p^k+1}+ x\right) =0\right\} \\ =&N_k(b, 1) . \end{aligned} \end{aligned}$$
(16)

This shows that the sets \(N_\ell (b)\) and \(N_k(b,1)\) have the same value distribution for b running over \( {{\mathbb {F}}}_{p^m}^*\). Similarly, if \(\ell \) satisfies the second condition of (12), then the sets \(N_\ell (b)\) and \(N_k(1,b)\) have the same value distribution for b running over \( {{\mathbb {F}}}_{p^m}^*\).

Next, we show that the sets \(N_k(1, b)\) and \(N_k(b, 1)\) have the same value distribution given in (15). Let

$$\begin{aligned} N(a,c) = \sharp \{ x\in {{\mathbb {F}}}_{p^m}\, |\, \mathrm{Tr}(a x^{p^k+1} + cx) = 0 \}. \end{aligned}$$

Note that m is odd, by Theorem 2 in [24], for ac running over \( {{\mathbb {F}}}_{p^m}^*\), the set N(ac) has the following value distribution,

$$\begin{aligned} \left\{ \begin{array}{lll} p^{m-1}+p^{\frac{m-1}{2}},&{}\frac{p-1}{2}(p^m-1)\left( p^{m-1}+p^{\frac{m-1}{2}}\right) &{} \mathrm{times},\\ p^{m-1}, &{}(p^m-1)(p^{m-1}-1)&{} \mathrm{times},\\ p^{m-1}-p^{\frac{m-1}{2}},&{}\frac{p-1}{2}(p^m-1)\left( p^{m-1}-p^{\frac{m-1}{2}}\right) &{} \mathrm{times}. \end{array} \right. \end{aligned}$$
(17)

For a fixed \(a\in {{\mathbb {F}}}_{p^m}^*\), if a is a square element in \( {{\mathbb {F}}}_{p^m}^*\), then there exists \(\beta \in {{\mathbb {F}}}_{p^m}\) such that \(a=\beta ^{p^k+1}\), and

$$\begin{aligned} N(a,c) =\sharp \{ x\in {{\mathbb {F}}}_{p^m}\, |\, \mathrm{Tr}(x^{p^k+1} + c\beta ^{-1}x ) = 0 \}. \end{aligned}$$
(18)

If a is a non-square element in \( {{\mathbb {F}}}_{p^m}^*\), then there exists \(\beta \in {{\mathbb {F}}}_{p^m}\) such that \(-a=\beta ^{p^k+1}\), and

$$\begin{aligned} N(a,c) =\sharp \{ x\in {{\mathbb {F}}}_{p^m}\, |\, \mathrm{Tr}(x^{p^k+1} - c\beta ^{-1}x ) = 0 \}. \end{aligned}$$
(19)

From (18) and (19), we know that for a fixed \(a\in {{\mathbb {F}}}_{p^m}^*\) and c running over \( {{\mathbb {F}}}_{p^m}^*\), N(ac) has the same value distribution as that of \(N_k(1, b)\) for b running over \( {{\mathbb {F}}}_{p^m}^*\). Hence, from (17) we obtain that \(N_k(1, b)\) has the value distribution given in (15) for b running over \( {{\mathbb {F}}}_{p^m}^*\). Similarly, \(N_k(b, 1)\) has the value distribution given in (15) for b running over \( {{\mathbb {F}}}_{p^m}^*\). By (16), the result follows. \(\square \)

Now, we give the weight distribution of the linear code \({{\mathcal {C}}}_{D_f}\) defined in (13).

Theorem 1

Let p be an odd prime with \(p\equiv 3 \pmod 4\). Let m be an odd number and \(\ell \) be an even number satisfying one of the conditions in (12). Then \({{\mathcal {C}}}_{D_f}\) in (13) is a \([p^{m-1}-1,m,(p-1)(p^{m-2}-p^{\frac{m-3}{2}})]\) code with the weight distribution in Table 8.

Table 8 Weight distribution of \({{\mathcal {C}}}_{D_f}\)

Proof

We only prove the case of \(\ell \) satisfying the first condition of (12), i.e., \(( p^k+1) \ell \equiv \frac{p^m+1}{2} \pmod {p^m-1}\), and the proof of the second case is similar.

Let \({{\mathcal {C}}}_{D_f}\) be the linear code defined in (13), and its length n is determined in Lemma 7. For \(b \in {{\mathbb {F}}}_{p^m}^*\), a codeword in \({{\mathcal {C}}}_{D_f}\) is

$$\begin{aligned} \mathbf {c}_b=(\mathrm{Tr}(bd_1),\mathrm{Tr}(bd_2),\ldots ,\mathrm{Tr}(bd_n)), \end{aligned}$$

where \(d_1,d_2,\ldots ,d_n\) are the elements of \(D_f\). Its Hamming weight is as follows:

$$\begin{aligned} \begin{aligned} wt(\mathbf {c}_b)&=p^{m-1}-1-\sharp \{x \in {{\mathbb {F}}}_{p^m}^*\,|\,\mathrm{Tr}(x^\ell )=0\,\,\text{ and }\,\,\mathrm{Tr}(bx)=0\}\\&=p^{m-1}-\frac{1}{p^2}\sum _{x \in {{\mathbb {F}}}_{p^m}}\sum _{y \in {{\mathbb {F}}}_p}\omega _p^{y\mathrm{Tr}(x^\ell )}\sum _{z \in {{\mathbb {F}}}_p}\omega _p^{z\mathrm{Tr}(bx)}. \end{aligned} \end{aligned}$$

Since \(\sum _{x \in {{\mathbb {F}}}_{p^m}}\sum _{y \in {{\mathbb {F}}}_p}\omega _p^{y\mathrm{Tr}(x^\ell )}=p^m\) and \(\sum _{x \in {{\mathbb {F}}}_{p^m}}\sum _{z \in {{\mathbb {F}}}_p}\omega _p^{z\mathrm{Tr}(bx)}=0\), then

$$\begin{aligned} \begin{aligned} wt(\mathbf {c}_b)&=(p-1)p^{m-2}-\frac{1}{p^2}\sum _{x \in {{\mathbb {F}}}_{p^m}}\sum _{y \in {{\mathbb {F}}}_p^*}\omega _p^{y\mathrm{Tr}(x^\ell )}\sum _{z \in {{\mathbb {F}}}_p^*}\omega _p^{z\mathrm{Tr}(bx)}. \end{aligned} \end{aligned}$$

Set \(z=uy\). It is clear that when (yz) runs through \( {{\mathbb {F}}}_{p^m}^*\times {{\mathbb {F}}}_{p^m}^*\), (uy) also runs through \( {{\mathbb {F}}}_{p^m}^*\times {{\mathbb {F}}}_{p^m}^*\). It is easy to verify that \(N_k(b, 1) = N_k(ub, 1)\) for any \(u\in {{\mathbb {F}}}_p^*\). We have

$$\begin{aligned} \begin{aligned} wt(\mathbf {c}_b)&=(p-1)p^{m-2}-\frac{1}{p^2}\sum _{y \in {{\mathbb {F}}}_p^*}\sum _{u \in {{\mathbb {F}}}_p^*}\sum _{x \in {{\mathbb {F}}}_{p^m}}\omega _p^{y\mathrm{Tr}(x^\ell +ubx)}\\&=2(p-1)p^{m-2}-\frac{1}{p^2}\sum _{u \in {{\mathbb {F}}}_p^*}\sum _{x \in {{\mathbb {F}}}_{p^m}}\sum _{y \in {{\mathbb {F}}}_p}\omega _p^{y\mathrm{Tr}(x^\ell +ubx)}\\&=2(p-1)p^{m-2}-\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^*}\sharp \{x \in {{\mathbb {F}}}_{p^m}\,|\,\mathrm{Tr}(x^\ell +ubx)=0\}\\&=2(p-1)p^{m-2}-\frac{1}{p}\sum _{u \in {{\mathbb {F}}}_p^*}\sharp \{x \in {{\mathbb {F}}}_{p^m}\,|\,\mathrm{Tr}(ubx^{p^k+1}+x)=0\}\\&=\frac{(p-1)}{p}(2p^{m-1}-N_k(b,1))\\&=\frac{(p-1)}{p}(2p^{m-1}-N_\ell (b)). \end{aligned} \end{aligned}$$
(20)

By Lemma 8 and (20), we get the weight distribution of \({{\mathcal {C}}}_{D_f}\). From the fact that \(wt(\mathbf {c}_b)>0\) for any \(b \in {{\mathbb {F}}}_{p^m}^*\), we deduce that the dimension of \({{\mathcal {C}}}_{D_f}\) is m. \(\square \)

Remark 2

When \(k=0\), it is easy to see that \(\ell =2\) is a solution of the second congruence equation in (12). So, in this case, the linear codes in Theorem 1 and those in [8] are the same.

One can verify that when \(p=m=3\), \(\ell =10\) is a solution of the first and the second congruence equation in (12) for the case \(k=1\) and \(k=2\), respectively. Magma shows that when \(p=m=3\), the linear code in [8] has a generator matrix

$$\begin{aligned} G_1=\left( \begin{array}{c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c} 1&{}0&{}0&{}1&{}2&{}0&{}0&{}2\\ 0&{}1&{}0&{}2&{}0&{}2&{}0&{}1\\ 0&{}0&{}1&{}1&{}0&{}0&{}2&{}2\\ \end{array} \right) . \end{aligned}$$

Accordingly, when \(p=m=3\) and \(\ell =10\), the linear code in Theorem 1 has a generator matrix

$$\begin{aligned} G_2 =\left( \begin{array}{c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c@{\quad }c} 1&{}0&{}0&{}1&{}2&{}0&{}0&{}2\\ 0&{}1&{}0&{}1&{}0&{}2&{}0&{}2\\ 0&{}0&{}1&{}1&{}0&{}0&{}2&{}2\\ \end{array} \right) . \end{aligned}$$

From the connection between linear transformations and multiplication of monomial matrices, we have that there is no monomial matrix M in \( {{\mathbb {F}}}_{3^3}\) such that \(G_2 = G_1 M\). This means that there exists \(\ell \) in (12) such that the linear codes in Theorem 1 and those in [8] are not equivalent.

Let \({\bar{D}}_f\) be a defining set as in (5). The weight distribution of the punctured version of \({{\mathcal {C}}}_{D_f}\) is as follows.

Proposition 3

Let p be an odd prime with \(p\equiv 3 \pmod 4\). Let m be an odd number and \(\ell \) be an even number satisfying one of the conditions in (12). Then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([\frac{p^{m-1}-1}{p-1},m,p^{m-2}-p^{\frac{m-3}{2}}]\) code with the weight distribution in Table 5.

From the weight distribution of \({{\mathcal {C}}}_{{\bar{D}}_f}\) above, we have the following corollary.

Corollary 2

Let \({{\mathcal {C}}}_{{\bar{D}}_f}\) be the linear code defined above. If \(m=3\), then \({{\mathcal {C}}}_{{\bar{D}}_f}\) is a \([p+1,3,p-1]\) code. This code is optimal with respect to the Singleton bound and the Griesmer bound.

Example 3

(1) Let \(p=3\) and \(m=3\). Let \(\ell =4\) or 10. Then the code \({{\mathcal {C}}}_{{\bar{D}}_f}\) has parameters [4, 3, 2] and the weight enumerator \(1+12x^2+8x^3+6x^4\). This code is optimal with respect to the Griesmer bound and the Singleton bound.

(2) Let \(p=7\) and \(m=3\). Let \(\ell =8\) or 278. Then the code \({{\mathcal {C}}}_{{\bar{D}}_f}\) has parameters [8, 3, 6] and the weight enumerator \(1+126x^6+48x^7+168x^8\). This code is optimal with respect to the Griesmer bound and the Singleton bound.

5 Concluding remarks

In this paper, we presented several classes of linear codes with two or three weights and determined their weight distributions. From the punctured version of the constructed linear codes, we obtained some optimal linear codes with respect to the Singleton bound or the Griesmer bound.

Let \(w_{min}\) and \(w_{max}\) denote the minimum and maximum nonzero weights of a linear code \({\mathcal {C}}\). Ding and Ding in [8] showed that if the linear code \({\mathcal {C}}\) with \(w_{min}/w_{max}>(p-1)/p\), then the secret sharing scheme based on the dual code \({\mathcal {C}}^{\perp }\) has the nice access structure. Using similar techniques as in [8], one can verify that when \(m\ge 12\) and \(r\ge 6\), the codes constructed in the paper satisfy \(w_{min}/w_{max}>(p-1)/p\). It then follows that the dual codes \({\mathcal {C}}_{D_f}^{\perp }\) and \({\mathcal {C}}_{{\bar{D}}_f}^{\perp }\) can be employed to obtain secret sharing schemes with interesting access structures.