1 Introduction

Distributed Storage Systems (DSSs) are very popular since large amounts of data are stored in DSSs by modern data centers such as Windows Azure Storage and Hadoop today. Unfortunately, node failures may be encountered in these systems. To provide high data reliability, redundant data are used in large DSSs, e.g. 3-replication. Since replication gives rise to large storage overhead, erasure codes such as Reed-Solomon codes are utilized to reduce the repair cost. However, the repair cost of them is not small. Thus, locally recoverable codes have been introduced to repair the node failures. Since then, they have attracted lots of interest of researches thanks to applications of them in DSSs.

Gopalan et al. (2012) introduced the locality in an erasure code to repair node failures efficiently. An LRC is a code such that every code symbol can be recovered by accessing a small number r of other code symbols. If there exists a punctured subcode of a code \(\mathcal {C}\) with support containing i, whose length is at most \(r +\delta -1\) and minimum distance is at least \(\delta \), then the i-th symbol \(c_i\) of a codeword in \(\mathcal {C}\) is said to have \((r, \delta )\)-locality, where \(\delta \ge 2\). Moreover, an upper bound on minimum distance of an LRC is given [see Eq. (1) below]. This bound is known as Singleton-type bound (Gopalan et al. 2012). If the minimum distance of a code achieves the Singleton-type bound, then the code is called a distance optimal LRC. A bound on dimension of an LRC is given by Cadambe and Mazumdar (2015) [see Eq. (2) below] and this bound is known as C-M bound. A code that its dimension achieves the C-M bound is called a dimension optimal LRC. In Agarwal et al. (2018), combinatorial bounds on LRCs were given. Constructions of distance optimal LRCs have attracted lots of interest of researchers such as Tamo and Barg (2014), Tamo et al. (2016), Prakash et al. (2012), Luo et al. (2018), Hao et al. (2017), Li et al. (2018), Chen et al. (2020), Jin (2019), Guruswami et al. (2019), Micheli (2019), Liu et al. (2020).

Cyclic codes and constacyclic codes have been widely preferred to construct optimal LRCs due to their efficient encoding and decoding performances. Firstly, binary cyclic LRCs that have an optimal dimension for given minimum distances \(d=2,6,10\) and locality \(r=2\) was constructed in Goparaju and Calderban (2014). The locality of many cyclic codes such as Hamming codes, Simplex codes and BCH codes was analyzed in Huang et al. (2015). Cyclic LRCs were constructed by virtue of their zeros in Tamo et al. (2015) and Tamo et al. (2016). Cyclic LRCs were obtained by means of the cyclotomic cosets in Kim and No (2017) and Tan et al. (2018). Perfect cyclic LRCs were constructed in Fang et al. (2021). For a collection of studies about cyclic LRCs see references Chen et al. (2017), Fang and Fu (2020), Luo et al. (2018) and Qiu et al. (2020).

As far as we know, unlike cyclic LRCs there is little works about the construction of constacyclic LRCs so far (Chen et al. 2018, 2019; Sun et al. 2018; Zhao et al. 2020). Constacyclic \((r,\delta )\)-LRCs with length \(n|(q+1)\) were obtained and four classes of distance optimal constacyclic \((r,\delta )\)-LRCs were given in Chen et al. (2018). Distance optimal constacyclic \((r,\delta )\)-LRCs with unbounded length and minimum distance \(\delta + 2\epsilon \) were constructed, where \(1\le \epsilon \le \left\lfloor \frac{\delta }{2}\right\rfloor \) in Sun et al. (2018). All distance optimal \((r,\delta )\)-LRCs with length \(n | (q + 1)\) and \((r + \delta - 1) | n\) were obtained in Chen et al. (2019). The locality of constacyclic codes of length \(p^s\) was characterized and all the distance optimal constacyclic LRCs of prime power lengths were given in Zhao et al. (2020).

The rest of this paper is structured as follows. In the next section, some of the basics about linear codes, constacyclic codes and LRCs are referred. In Sect. 3, six constructions of constacyclic LRCs by means of their duals are given. Specifically, constacyclic LRCs with locality \(r\le 2\) and dimension 2 are obtained from the roots of their parity-check polynomials. Also, a sufficient and necessary condition for these constacyclic codes with locality 1 is given. The construction is generalized for constacyclic codes with any locality and dimension. Constacyclic codes whose locality equal to their dimension and locality 1 are constructed. Moreover, distance optimal constacyclic LRCs are obtained. In Sect. 4, constacyclic LRCs are given by using cyclotomic cosets. The last section concludes this paper.

2 Preliminaries

In this section, we present some of basic facts about linear codes, constacyclic codes and locally recoverable codes. For further and more detailed theory on linear codes readers can refer to Ling and Xing (2004) and Huffman and Pless (2010).

A linear code \(\mathcal {C}\) of length n over \(\mathbb {F}_{q}\) is a vector subspace of \(\mathbb {F}_{q}^{n}\). If the dimension and minimum (Hamming) distance of the code \(\mathcal {C}\) are k and d, respectively, then the code is denoted by the triple [nkd]. Also, the dual code of \(\mathcal {C}\), denoted by \(\mathcal {C}^{\perp }\), is \(\mathcal {C}^{\perp }= \{ \textbf{x}\in \mathbb {F}_{q}^{n} \vert \mathbf {x\cdot y}=0,\text { for all }\textbf{y}\in \mathcal {C} \} \) such that \(\mathbf {x\cdot y=}x_{1}y_{1}+\ldots +x_{n}y_{n}\) for all \(\textbf{x}=\left( x_{1},\ldots ,x_{n}\right) \) and \(\textbf{y} =\left( y_{1},\ldots ,x_{n}\right) \in \mathbb {F}_{q}^{n}\). The support of c is the set of coordinates at which c is nonzero and it is denoted by \(\text {supp}(c)\). The order of a nonzero element \(\eta \in \mathbb {F}_q \), denoted by \(o(\eta )\), is the smallest positive integer s such that \(\eta ^s = 1\). Let \(\text {gcd}(n,q)=1.\) Then

$$\begin{aligned} C_{s}=\{(s\cdot q^{j}(\text {mod } n) | j=0,1,\ldots \} \end{aligned}$$

is the cyclotomic coset of q modulo n containing s.

Definition 1

Let \(\mathcal {C}\) be a q-ary linear code and \(\eta \in \mathbb {F}_q{\setminus } \{0\}\) . If \((\eta c_{n-1}, c_0,\ldots , c_{n-2})\in \mathcal {C}\) whenever \((c_0, c_1,\ldots , c_{n-1})\in \mathcal {C}\), then \(\mathcal {C}\) is called a \(\eta \)-constacyclic code. If \(\eta =1\), then \(\mathcal {C}\) is called a cyclic code. If \(\eta =-1\), then \(\mathcal {C}\) is called a negacyclic code.

There is a one-to-one correspondence between constacyclic codes and ideals of the quotient ring \(\mathbb {F}_q[x]/ \langle x^n-\eta \rangle \). Then a codeword can be considered as a polynomial. For instance, a codeword \((c_0, c_1,\ldots , c_{n-1})\) corresponds to the polynomial \(c_0+ c_1x+\cdots + c_{n-1}x^{n-1}\). The reciprocal polynomial \(h_R(x)\) of h(x) with degree s is \(h_R(x)=x^{s}h(1/x)\). Since \(\mathbb {F}_q[x]/ \langle x^n-\eta \rangle \) is a principal ideal domain, constacyclic codes can be described with a generator polynomial. If g(x) is a generator polynomial of a \(\eta \)-constacyclic code, then \(g(x)|(x^n-\eta )\). Suppose \(x^n-\eta =g(x)h(x)\). Then, monic reciprocal polynomial of h(x) is called a parity-check polynomial of the code.

In the following definitions, the symbol [n] stands for the set of integers from 1 to n.

Definition 2

Let \(\mathcal {C}\) be a linear code of length n over \(\mathbb {F}_q\). Then the code has locality r if for every \(c=(c_1, \ldots ,c_n)\in \mathcal {C}\) and \(i\in [n]\), there exists a subset \(R_i \subset [n] \backslash \{i\}\) such that \(|R_i|\le r\) and \(c_i\) is a function of \(c_j's\), where \(j\in R_i\). The set \(R_i\) is called a recovering set of the i-th coordinate.

A code of length n, dimension k and locality r is denoted by (nkr).

Definition 3

Let \(\mathcal {C}\) be an (nkr) LRC and \(\textbf{x}=(x_1,\ldots ,x_n)\in \mathcal {C}\). Due to the local recovery property, any codeword symbol \(x_i\) can be recovered by using at most r other codeword symbols \( \{x_{t_1}, \ldots , x_{t_{r}} \}\), where \(t_j \ne i\) for any j. The set of these at most \(r+1\) indices in \(\left\{ i, t_1, \ldots , t_{r}\right\} \) form a repair group of the (nkr) LRC.

In Gopalan et al. (2012), gave an upper bound on minimum distance d of an (nkr) LRC as

$$\begin{aligned} d\le n-k-\Bigg \lceil \frac{k}{r}\Bigg \rceil +2. \end{aligned}$$
(1)

This bound is called Singleton-type bound since the bound becomes the classical Singleton bound if \(r=k\).

In Cadambe and Mazumdar (2015), obtained an upper bound on dimension of an (nkr) LRC with distance d over \(\mathbb {F}_q\) as

$$\begin{aligned} k\le \text {min}_{t\in \mathbb {Z}^+} \{tr + k_{\text {opt}}^q(n-t(r+1),d)\}, \end{aligned}$$
(2)

where \(k_{\text {opt}}^q(n-t(r+1),d)\) denotes the largest possible dimension of a code over \(\mathbb {F}_q\) with distance d and length \(n-t(r+1)\).

Proposition 1

Let \(\mathcal {C}\) be an (nkr) LRC. Then,

$$\begin{aligned} \frac{k}{n}\le \frac{r}{r+1}. \end{aligned}$$
(3)

We will give a definition of a q-ary LRC which was given in Goparaju and Calderban (2014) for a binary LRC. Throughout this paper, we will use the definition of an LRC as follows.

Definition 4

Let \(\mathcal {C}\) be a q-ary linear code of length n. If every coordinate in [n] is contained in the support of the parity-check polynomial of weight \(r+1\), then \(\mathcal {C}\) is called an LRC with locality r.

Theorem 2

(Zhao et al. 2020) Let \(\mathcal {C}\) be a constacyclic code with dual distance \(d^{\perp }\ge 2\). Then the minimum locality of \(\mathcal {C}\) is \(d^{\perp }- 1\).

3 Constacyclic LRCs from Their Duals

In this section, we will obtain constacyclic LRCs by means of their parity-check polynomials. In the next theorem, we will get constacyclic codes with locality at most 2 and give a necessary and sufficient condition for constacyclic codes with locality 1. From now on, all computations will be performed using MAGMA, a computer algebra software developed at the University of Sydney [see (Bosma et al. 1997)].

Theorem 3

Let \(n\ge 3\) and q be integers such that \(\text {gcd}(n,q)=1\), \(\lambda \in \mathbb {F}_{q}{\setminus } \{0\}\), \(o(\lambda )=s\) and \(q^2\equiv 1 (\text {mod } sn)\). Assume that \(\alpha \in \mathbb {F}_{q^k}\) is a zero of the polynomial \(x^n-\lambda \in \mathbb {F}_q[x]\). If h(x) is the polynomial with degree k of which \(\alpha \) is a root of it and \( \vert \text {supp}(\bar{h}(x)) \vert =r+1\), where \(\bar{h}(x)\) is the monic reciprocal polynomial of h(x), then there exists a q-ary (nkr) \(\lambda \)-constacyclic LRC \(\mathcal {C}\) with \(k\le 2\) and \(r\le 2\) such that \(\mathcal {C}^\perp =\langle \bar{h}(x) \rangle \). If the distance of the code is and \(k=2\), then the code is distance optimal.

Proof

Let \(\bar{h}(x)\) be the parity-check polynomial of \(\mathcal {C}\). Since \(h(\alpha )=0\) and \(\alpha \) is a root of \(x^n-\lambda \), \(h(x)\mid (x^n-\lambda )\). Then \(\mathcal {C}\) is a \(\lambda \)-constacyclic code. Due to \(q^2\equiv 1 (\text {mod } sn)\), the corresponding cyclotomic coset is \(C_1=\{1,q (\text {mod }sn)\}\) and therefore

$$\begin{aligned} h(x)=(x-\alpha )(x-\alpha ^{q(\text {mod } sn)})=x^2-(\alpha +\alpha ^{q(\text {mod } sn)})x+\alpha ^{q+1(\text {mod } sn)}. \end{aligned}$$

Then \(\left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp} (h(x))\right| =r+1\le \text {deg}(\bar{h}(x))+1=\text {deg}(h(x))+1\le 3\) and so \(r\le 2\). Since \(\text {deg}(\bar{h}(x))=\text {deg}(h(x))=k\le 2\), the dimension of the code \(\mathcal {C}\) is at most 2. Hence, \(\mathcal {C}\) is an (nkr) \(\lambda \)-constacyclic LRC with \(k\le 2\) and \(r\le 2\). Let \(k=2\) and . Then the code is distance optimal since

by the Singleton-type bound (1). Moreover, \(n\ge 3\) by the bound (3). \(\square \)

Corollary 1

The code given in the Theorem 3 has locality 1 if and only if \(\alpha =-\alpha ^{q(\text {mod } sn)}\) or \(q\equiv 1(\text {mod } sn)\).

Proof

Let \(r=1\). Then, the number of elements of the \(\text {supp}(h(x))\) must be 2 by the Theorem 3 and therefore \(\alpha ^{q+1(\text {mod } sn)}=0\), \(\alpha =-\alpha ^{q(\text {mod } sn)}\) or \(q\equiv 1(\text {mod } sn)\). However, \(\alpha ^{q+1(\text {mod } sn)}=0\) is not a case because a finite field has no zero divisors. On the other hand, assume \(\alpha =-\alpha ^{q(\text {mod } sn)}\) or \(q\equiv 1(\text {mod } sn)\). Let \(\alpha =-\alpha ^{q(\text {mod } sn)}\). Then, \(h(x)=x^2-\alpha ^{q+1(\text {mod } sn)}\). Thus, \(\left| \text {supp}(h(x))\right| =2\) and locality is 1. Assume \(q\equiv 1(\text {mod } sn)\). Then \(C_1=\{1,q (\text {mod }sn)\}=\{1\}\) and therefore \(h(x)=x-\alpha \). So \(\left| \text {supp}(h(x))\right| =2\) and locality is 1. Hence, the constacyclic code in the Theorem 3 has locality 1 if \(\alpha ^{q+1(\text {mod } sn)}=0\) or \(q\equiv 1(\text {mod } sn)\). \(\square \)

Example 1

Let \(\mathcal {C}\) be a negacyclic code of length 5 over \(\mathbb {F}_{11}\) and h(x) be the polynomial such that \(\alpha \in \mathbb {F}_{11}\) is a root of it. Then \(o(\lambda )=o(10)=s=2\) and \(11 \equiv 1(\text {mod }10)\). Assume \(\mathcal {C}^\perp =\langle \bar{h}(x) \rangle = \langle x+9 \rangle \). Then \(\mathcal {C}\) is a (5, 1, 1) negacyclic LRC by the Corollary 1.

In Table 1, we showed some distance optimal constacyclic LRCs with \(r,k\le 2\) by the Theorem 3.

Table 1 Some distance optimal (nkr) constacyclic LRCs, where \(r,k\le 2\) g

Remark 1

In order to increase the distance of a constacyclic LRC, it is preferable to get new codes by increasing the locality by one unit. For instance, the distance of optimal (4, 2, 1) ternary cyclic LRC in Table 1 is 2. However, the distance of optimal (4, 2, 2) ternary 2-constacyclic LRC in Table 1 is 3.

Example 2

Assume \(q=5,\) \(n=3\) and \(\lambda =2\). Then, \(o(\lambda )=4\) and there exists a root of unity \(\alpha \) in an extension of \(\mathbb {F}_{5}\) such that \( \alpha ^{3}=2\). The cyclotomic coset for \(j=0\) is \(C_{1}=\{1,5\}\) and therefore \(h(x)=(x-\alpha )(x-\alpha ^{5})=x^{2}+3x+4\). Then \( \vert \text {supp}(\bar{h}(x)) \vert =\vert \text {supp}(h(x)) \vert =3\) and \(r=2\). If \(\mathcal {C}^{\perp }= \langle \bar{h}(x) \rangle \), then it can be seen that \(\mathcal {C}\) is a distance optimal (3, 2, 2) 2-constacyclic LRC with minimum distance 2.

Example 3

Let \(q=11,\) \(n=6\) and \(\lambda =-1\). Then \(o(\lambda )=2\) and there exists a root of unity \(\alpha \) in an extension of \(\mathbb {F}_{5}\) such that \( \alpha ^{6}=-1\). The cyclotomic coset for \(j=0\) is \(C_{1}=\{1,11\}\). So \( h(x)=(x-\alpha )(x-\alpha ^{11})=x^{2}+6x+1\). Thus, \(\left| \text {supp}( \bar{h}(x))\right| =\left| \text {supp}(h(x))\right| =3\) and \(r=2\) . Let \(\mathcal {C}^{\perp }= \langle \bar{h}(x) \rangle \). The minimum distance of the code is \(d=5\). Then \(\mathcal {C}\) is a distance optimal (6, 2, 2) negacyclic LRC with \(d=5\).

By using constacyclic codes rather than cyclic codes, we are able to obtain distance optimal LRC codes like in the following example.

Example 4

Let \(q=5\) and \(n=6\). The minimal polynomial corresponding to the cyclotomic coset \(C_{1}=\{1,5\}\) is \(h_{1}(x)=x^{2}+4x+1\). Then \(\vert \text {supp}( \bar{h_{1}}(x)) \vert = \vert \text {supp}(h_{1}(x)) \vert =3\) and therefore \(r=2\). It can be seen that the code \(\mathcal {C}_{1}\) with parity-check polynomial \(\bar{h_{1}}(x)\) is a 5-ary (6, 2, 2) cyclic LRC with minimum distance 4. Now, let \(\lambda =2\). Then \(o(\lambda )=4\) and there exists a root of unity \(\alpha \) in an extension of \(\mathbb {F}_{5}\) such that \(\alpha ^{6}=2\). The polynomial corresponding to the cyclotomic coset \(C_{1}=\{1,5\}\) is \(h_{2}(x)=(x-\alpha )(x-\alpha ^{5})=x^{2}+4x+2\). So, \( \vert \text {supp}(\bar{h_{2}}(x)) \vert = \vert \text {supp }(h_{2}(x)) \vert =3\) and \(r=2\). The code \(\mathcal {C}_{2}\) with parity-check polynomial \(\bar{h_{2}}(x)\) is a 5-ary (6, 2, 2) 2 -constacyclic LRC code with minimum distance 5. Although \(\mathcal {C}_{1}\) is not distance optimal LRC, \(\mathcal {C}_{2}\) is a distance optimal LRC.

In Table 2, we list some of distance optimal constacyclic LRCs obtained from Theorem 3.

Table 2 Distance optimal constacyclic LRCs with \(r,k\le 2\)

In Table 3, we list some parameters of almost distance optimal constacyclic LRCs by the Theorem 3.

Table 3 Some almost distance optimal (nkr) constacyclic LRCs where \(r,k\le 2\)

Example 5

Let \(q=5,n=6\) and \(\lambda =-1\). Then \(o(\lambda )=2\) and there exists a root of unity \(\alpha \) in an extension of \(\mathbb {F}_{5}\) such that \( \alpha ^{6}=-1\). The cyclotomic coset for \(j=0\) is \(C_{1}=\{1,5\}\) and therefore \(h(x)=(x-\alpha )(x-\alpha ^{5})=x^{2}+2x+4\). Then \(\left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp}(h(x))\right| =3\) and \(r=2\). Let \(\mathcal {C}^{\perp }= \langle \bar{h}(x) \rangle \). The minimum distance of the code \(\mathcal {C}\) is \(d=4\). Then \(\mathcal {C}\) is a negacyclic almost distance optimal LRC with parameters (6, 2, 2).

From Theorem 3, we get below Table 4 of almost distance optimal LRCs.

Table 4 Almost distance optimal constacyclic LRCs where \(r,k\le 2\)

We generalized Theorem 3 for constacyclic LRCs with any dimension and locality as follows.

Theorem 4

Let n, k and q be integers such that \(gcd(n,q)=1\), \(k+1\le n\), \( \lambda \in \mathbb {F}_{q}\backslash \{0\}\) and \(o(\lambda )=s\). Assume that \(\alpha \in \mathbb {F}_{q^{k}}\) is a zero of the polynomial \(x^{n}-\lambda \in \mathbb {F}_{q}[x]\). If \(h(x)|(x^{n}-\lambda )\) is the polynomial with degree k of which \(\alpha \) is a root of it and \(\left| \text {supp}( \bar{h}(x))\right| =r+1\), where \(\bar{h}(x)\) is the monic reciprocal polynomial of h(x), then there exists a q-ary (nkr) \(\lambda \) -constacyclic LRC \(\mathcal {C}\) with locality \(r\le k\) such that \(\mathcal {C }^{\perp }= \langle \bar{h}(x) \rangle \).

Proof

Suppose \(\bar{h}(x)\) is the parity-check polynomial of \(\mathcal {C}\) and \( h(x)|(x^{n}-\lambda )\). Then \(\mathcal {C}\) is a \(\lambda \)-constacyclic code. Since \(\text {deg}(\bar{h}(x))=\text {deg}(h(x))=k\) and \(h(\alpha )=0\), the corresponding cyclotomic coset is \(C_{1}=\{1,q,\ldots ,q^{k}\}(\text {mod } sn)\) and therefore

$$\begin{aligned} h(x)=(x-\alpha )\left( x-\alpha ^{q(\text {mod }sn)}\right) \ldots \left( x-\alpha ^{q^{k}(\text {mod }sn)}\right) . \end{aligned}$$

Then \(\left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp} (h(x))\right| =r+1\le \text {deg}(\bar{h}(x))+1=\text {deg}(h(x))+1=k+1\) and so \(r\le k\). Since \(\text {deg}(\bar{h}(x))=\text {deg}(h(x))=k\), the dimension of the code \(\mathcal {C}\) is k. Hence, \(\mathcal {C}\) is an (nkr) \(\lambda \)-constacyclic LRC with locality \(r\le k\). Moreover, \( k+1\le n\) by the bound (3). \(\square \)

Example 6

Let \(q=3,\) \(n=5\) and \(\lambda =-1\). Then \(o(\lambda )=2\) and there exists a root of unity \(\alpha \) in some extension of \(\mathbb {F}_{3}\) such that \( \alpha ^{5}=-1\). The cyclotomic coset for \(j=0\) modulo 10 is \( C_{1}=\{1,3,9,7\}\) and therefore

$$\begin{aligned} h(x)=(x-\alpha )(x-\alpha ^{3})(x-\alpha ^{7})(x-\alpha ^{9})=x^{4}+2x^{3}+2x^{2}+2x+1. \end{aligned}$$

Then \(\left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp} (h(x))\right| =5\) and \(r=4\). If \(\mathcal {C}^{\perp }= \langle \bar{h}(x) \rangle \), then \(\mathcal {C}\) is a (5, 4, 4) negacyclic ternary LRC.

In Theorem 5, we obtained distance optimal constacyclic LRCs with minimum distance 2 as follows.

Theorem 5

Let u and v be positive integers and \(\lambda \in \mathbb {F}_q{\setminus }\{0\}\) such that \(o(\lambda )=v-1\). Then a code \( \mathcal {C}\) with parity-check polynomial

$$\begin{aligned} h(x)=1+\lambda ^{v-2}x^{u}+\lambda ^{v-3}x^{2u}+\cdots +\lambda ^{2}x^{u(v-3)}+\lambda x^{u(v-2)}+x^{u(v-1)} \end{aligned}$$

is a distance optimal \((uv,u(v-1),v-1)\) \(\lambda \)-constacyclic LRC with minimum distance 2.

Proof

The degree of the parity-check polynomial h(x) is \(u(v-1)\). Thus, the dimension of \(\mathcal {C}\) is \(u(v-1)\). Due to \(h(x)|(x^{uv}-\lambda )\), the length of the code is uv. Also, \(\left| \text {supp}(h(x))\right| =v \). Then locality of the code is \(v-1\) by the definition of LRC. From the Singleton-type bound (1),

$$\begin{aligned} d&\le uv-u(v-1)-\Bigg \lceil \frac{u(v-1)}{v-1}\Bigg \rceil +2 \\&=uv-uv+u-u+2 \\&=2. \end{aligned}$$

On the other hand, if there would be a codeword c with Hamming weight 1 then \(c|(x^{uv}-\lambda )\) which is a contradiction. So the minimum distance of the code \(\mathcal {C}\) is 2. Hence, \(\mathcal {C}\) is a distance optimal \((uv,u(v-1),v-1)\) \(\lambda \)-constacyclic LRC with minimum distance 2. \(\square \)

Example 7

Let \(q=5\), \(u=3\) and \(\lambda =2\). Then \(o(\lambda )=4\) and therefore \(v=5\). Thus, a code \(\mathcal {C}\) with parity-check polynomial

$$\begin{aligned} h(x)&=1+2^{3}x^{3}+2^{2}x^{6}+2x^{9}+x^{12} \\&\equiv 1+3x^{3}+4x^{6}+2x^{9}+x^{12} \end{aligned}$$

is a distance optimal (15, 12, 4) 2-constacyclic LRC with minimum distance 2.

Example 8

Let \(q=3\), \(u=2\) and \(\lambda =2\). Then, \(o(\lambda )=2\) and therefore \(v=3\). Hence, a code \(\mathcal {C}\) with parity-check polynomial

$$\begin{aligned} h(x)&=1+2x^{2}+x^{4} \end{aligned}$$

is a distance optimal ternary (6, 4, 2) 2-constacyclic LRC with minimum distance 2.

In Table 5, we list some of distance optimal q-ary \( (uv,u(v-1),v-1)\) \(\lambda \)-constacyclic LRCs with minimum distance \(d=2\).

Table 5 Distance optimal constacyclic LRCs with \(d=2\)

We get constacyclic codes with locality 1 in the next theorem.

Theorem 6

Let u and v be positive integers and \(\lambda \) be a nonzero element of \(\mathbb {F}_q\) such that \(o(\lambda )=v-1\). Then a code \( \mathcal {C}\) with parity-check polynomial \(h(x)=x^{u}-\lambda \) is a (uvu, 1) \(\lambda \)-constacyclic LRC. If minimum distance of \(\mathcal {C}\) is \( u(v-2)+2\), then the code is distance optimal.

Proof

Since the degree of the parity-check polynomial h(x) is u, the dimension of \(\mathcal {C}\) is u. The length of the code is uv due to \( h(x)|(x^{uv}-\lambda )\). Also, \(\left| \text {supp}(h(x))\right| =2\). Then locality of the code is 1 by the definition of LRC. Thus, \(\mathcal {C} \) is a (uvu, 1) \(\lambda \)-constacyclic LRC. Assume the minimum distance of \(\mathcal {C}\) is \(u(v-2)+2\). Then,

$$\begin{aligned} d&\le uv-u-\Bigg \lceil \frac{u}{1}\Bigg \rceil +2 \\&=u(v-2)+2 \end{aligned}$$

by the Singleton-type bound (1). So \(\mathcal {C}\) is distance optimal. \(\square \)

Example 9

Let \(q=5\), \(u=3\) and \(\lambda =2\). Then, \(o(\lambda )=4\) and therefore \(v=5\). Hence, the code \(\mathcal {C}\) with parity-check polynomial \(h(x)=x^{3}-2\) is a (15, 3, 1) 2-constacyclic LRC.

Example 10

Let \(q=3\), \(u=2\) and \(\lambda =2\). Then, \(o(\lambda )=4\) and thus \(v=3\). Therefore, the code \(\mathcal {C}\) with parity-check polynomial \(h(x)=x^{2}-2\) is a (6, 2, 1) 2-constacyclic LRC.

In Table 6, we list some q-ary (uvu, 1) \(\lambda \) -constacyclic LRCs.

Table 6 Constacyclic LRCs with locality 1

In the next theorem, constacyclic codes with locality which is equal to their dimension are obtained.

Theorem 7

Let \(\lambda \) be a nonzero element of \(\mathbb {F}_{q}\) such that \( q|(\lambda 2^{k-1}-1)\). Then, the code \(\mathcal {C}\) with parity-check polynomial

$$\begin{aligned} h(x)=1+x+2x^{2}+2^{2}x^{3}+2^{3}x^{4}+\cdots +2^{k-1}x^{k} \end{aligned}$$

is an (nkk) \(\lambda \)-constacyclic LRC.

Proof

The degree of the parity-check polynomial h(x) is k. Therefore, the dimension of \(\mathcal {C}\) is k. Due to \(h(x)|(x^{n}-\lambda )\), the length of the code is n. Also, \(\left| \text {supp}\left( h(x)\right) \right| =k+1\). Then, locality of the code is k by the definition of LRC. Hence, \(\mathcal {C}\) is an (nkk) \(\lambda \)-constacyclic LRC. \(\square \)

Example 11

Let \(q=3\), \(n=6\) and \(\lambda =2\). Suppose \(3|(2^{k}-1)\) and choose \(k=4\). Then locality is 4 and therefore the code with parity-check polynomial \( h(x)=2x^{4}+x^{3}+2x^{2}+x+1\) is a ternary (6, 4, 4) 2-constacyclic LRC.

Example 12

Let \(q=5\), \(n=7\) and \(\lambda =3\). Assume \(5|(3^{k}-1)\) and take \(k=2\). So locality is 2 and therefore the code with parity-check polynomial \( h(x)=2x^{2}+x+1\) is a (7, 2, 2) 3-constacyclic LRC.

Theorem 8

Let \(\lambda \) be a nonzero element of \(\mathbb {F}_{q}\) such that \(q|(\lambda 2^{k-1}-1)\). Then the code \(\mathcal {C}\) with parity-check polynomial

$$\begin{aligned} h(x)=-\lambda +\lambda x+\lambda x^{2}+\lambda x^{3}+\dots +\lambda x^{n-k} \end{aligned}$$

is a \((n,n-k,n-k)\) \(\lambda \)-constacyclic LRC.

Proof

The degree of the parity-check polynomial h(x) is \(n-k\). So the dimension of \(\mathcal {C}\) is \(n-k\). Owing to \(h(x)|(x^{n}-\lambda )\), the length of the code is n. Since \(\text {supp}(h(x))=n-k+1\), locality of the code is \( n-k\) by the definition of LRC. Therefore, \(\mathcal {C}\) is an \((n,n-k,n-k)\) \( \lambda \)-constacyclic LRC. \(\square \)

Example 13

Let \(q=3\), \(n=6\) and \(\lambda =2\). Assume \(3|(2^{k}-1)\) and choose \(k=4\). Then locality is 2 and, therefore, the code with parity-check polynomial \( h(x)=2x^{2}+2x-2\) is a ternary (6, 2, 2) 2-constacyclic LRC.

Example 14

Let \(q=5\), \(n=7\) and \(\lambda =3\). Suppose \(5|(3^{k}-1)\) and take \(k=2\). So locality is 5 and therefore the code with parity-check polynomial \( h(x)=3x^{5}+3x^{4}+3x^{3}+3x^{2}+3x-3\) is a (7, 5, 5) 3-constacyclic LRC.

4 Constacyclic LRCs derived from the cyclotomic cosets

In this section, we will obtain constacyclic LRCs by using the cyclotomic cosets composed of elements that are relatively prime.

Theorem 9

Let \(\text {gcd}(n,q)=1,\) \(q\le n\), \(\lambda \in \mathbb {F} _{q}-\left\{ 0\right\} \) and \(o(\lambda )=s\). If \(q^{2}\equiv 1(\text {mod } sn)\), \(q^{2}\equiv q(\text {mod }sn)\) or \((1+sj)q\equiv 1+sj(\text {mod }sn)\) for some \(0\le j\le n-1\), then there exists cyclotomic cosets which the elements of them are relatively prime. Let \(C_{1+sj_{1}},\) \(C_{1+sj_{2}},\) \( \ldots ,\) \(C_{1+sj_{v}}\) be the distinct q-cyclotomic cosets whose elements are relatively prime for \(0\le j\le n-1\). Assume that \(k_{t}\) is the smallest positive integer such that \((1+sj)q^{k_{t}}\equiv 1+sj(\text {mod } sn)\) in the cyclotomic coset \(C_{1+sj_{t}}\), where \(1\le t\le v\) and \( k = \sum _{t = 1}^v {k_t } \). Suppose that \( m_{j_{1}}(x),\) \(m_{j_{2}}(x),\ldots ,\) \(m_{j_{v}}(x)\) are distinct minimal polynomials corresponding to these q-cyclotomic cosets. If \(\mathcal {C} ^{\perp }=\langle \bar{h}(x) \rangle \), where \(h(x)= \prod _{i=1}^v m_{j_{i}}(x) \) is a polynomial with support cardinality \(r+1\), then there exists a q-ary (nkr) \(\lambda \)-constacyclic locally recoverable code \(\mathcal {C}\) with locality r, where \(r\le k\).

Proof

If \(q\equiv 1\) (mod sn), then \(|C_{1}|=1\). If \(q^{2}\equiv 1\) (mod sn) or \(q^{2}\equiv q\) (mod sn), then \(|C_{1}|=2\). Then the elements of cyclotomic cosets are relatively prime since \(C_{1}=\{1,q\}\) (mod sn). Let \(|C_{1}|\ge 3\). If \((1+sj)q\equiv 1+sj\) (mod sn) for some \(0\le j\le n-1 \), then there is at least one cyclotomic coset which has one element. Thus the elements of the cyclotomic cosets \(C_{1+sj_{1}},\) \(C_{1+sj_{2}},\) \(\ldots ,\) \(C_{1+sj_{v}}\) are relatively prime in each case. By the Definition 4, the locality of the code \(\mathcal {C}\) is r. Since \(k_{t}\) is the smallest positive integer such that \((1+sj)q^{k_{t}}\equiv 1\) (mod sn) in the cyclotomic coset \(C_{1+sj_{t}}\), where \(1\le t\le v\), \( |C_{1+sj_{t}}|=k_{t}\). Then, the dimension of the code \(\mathcal {C}\) is

$$\begin{aligned} \text {deg}(\bar{h}(x))=\text {deg}(h(x))=\text {deg}(m_{j_{i}}(x))=\overset{t}{ \underset{i=1}{{\displaystyle \sum }}}|C_{j_{i}}|=\overset{v}{\underset{t=1}{{ \displaystyle \sum }}}k_{t}=k \end{aligned}$$

since \(m_{j_{1}}(x),\) \(m_{j_{2}}(x),\) \(\ldots ,\) \(m_{j_{v}}(x)\) are monic. Then,

$$\begin{aligned} \left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp} (h(x))\right| =r+1\le \text {deg}(\bar{h}(x))+1=\text {deg}(h(x))+1=k+1 \end{aligned}$$

and so \(r\le k\). \(\square \)

Example 15

Let \(q=5,\) \(n=6\) and \(\lambda =2\). All 5-cyclotomic cosets are

$$\begin{aligned} C_{1}&=\{1,5\}=C_{5}, \\ C_{9}&=\{9,21\}=C_{21}, \\ C_{13}&=\{13,17\}=C_{17}. \end{aligned}$$

The 5-cyclotomic cosets whose elements are relatively prime are \(C_{1}\) and \(C_{13}\) and therefore the distinct minimal polynomials corresponding to these 5-cyclotomic cosets are

$$\begin{aligned} m_{1}(x)&=(x-\alpha )(x-\alpha ^{9})=x^{2}+4x+2, \\ m_{13}(x)&=(x-\alpha ^{13})(x-\alpha ^{17})=x^{2}+x+2. \end{aligned}$$

Then \(h(x)=m_{1}(x)m_{5}(x)=(x^{2}+4x+2)(x^{2}+x+2)=x^{4}+3x^{2}+4\). Since \( \text {deg}(\bar{h}(x))=\text {deg}(h(x))=4\) and \(\left| \text {supp}(\bar{h }(x))\right| =\left| \text {supp}(h(x))\right| =3\), the dimension of \(\mathcal {C}\) is 4 and locality of \(\mathcal {C}\) is \(r=2\le k=4\). If \( \mathcal {C}^{\perp }= \langle \bar{h}(x) \rangle \), then \(\mathcal {C}\) is a 5-ary (6, 4, 2) 2-constacyclic LRC.

Example 16

Let \(q=5,\) \(n=7\) and \(\lambda =3\). All 5-cyclotomic cosets are

$$\begin{aligned} C_{1}&=\{1,5,25,13,9,17\}, \\ C_{3}&=\{3,15,19,11,27,23\}, \\ C_{21}&=\{21\}. \end{aligned}$$

The 5-cyclotomic coset whose elements are relatively prime is \(C_{21}\) and, therefore, the minimal polynomial corresponding to this 5-cyclotomic coset is

$$\begin{aligned} m_{21}(x)=(x-\alpha ^{21})=x+3. \end{aligned}$$

Then \(h(x)=m_{21}(x)=x+3\). Since \(\text {deg}(\bar{h}(x))=\text {deg}(h(x))=1\) and \(\left| \text {supp}(\bar{h}(x))\right| =\left| \text {supp} (h(x))\right| =2\), the dimension of \(\mathcal {C}\) is 1 and locality of \(\mathcal {C}\) is \(r=1\le k=1\). If \(\mathcal {C}^{\perp }=\langle \bar{h}(x) \rangle \), then \(\mathcal {C}\) is a 5-ary (7, 1, 1) 3-constacyclic LRC.

Example 17

Let \(q=11,\) \(n=6\) and \(\lambda =-1\). All 11-cyclotomic cosets are

$$\begin{aligned} C_{1}&=\{1,11\}=C_{11}, \\ C_{3}&=\{3,9\}=C_{9}, \\ C_{5}&=\{5,7\}=C_{7}. \end{aligned}$$

The 11-cyclotomic cosets whose elements are relatively prime are \(C_{1}\) and \(C_{5}\) and therefore the distinct minimal polynomials corresponding to these 11-cyclotomic cosets are

$$\begin{aligned} m_{1}(x)&=(x-\alpha )(x-\alpha ^{11})=x^{2}+6x+1, \\ m_{5}(x)&=(x-\alpha ^{5})(x-\alpha ^{7})=x^{2}+5x+1. \end{aligned}$$

Then \(h(x)=m_{1}(x)m_{5}(x)=(x^{2}+6x+1)(x^{2}+5x+1)=x^{4}+9x^{2}+1\). Since \( \text {deg}(\bar{h}(x))=\text {deg}(h(x))=4\) and \(\left| \text {supp}(\bar{h }(x))\right| =\left| \text {supp}(h(x))\right| =3\), the dimension of \(\mathcal {C}\) is 4 and locality of \(\mathcal {C}\) is \(r=2\le k=4\). If \( \mathcal {C}^{\perp }=\langle \bar{h}(x) \rangle \), then \(\mathcal {C}\) is a 11-ary (6, 4, 2) negacyclic LRC.

Next example shows that the Theorem 9 may not be hold if \(n<q\).

Example 18

Let \(q=5,\) \(n=3\) and \(\lambda =2\). All 11-cyclotomic cosets are

$$\begin{aligned} C_{1}&=\{1,5\}=C_{5}, \\ C_{3}&=\{3\}, \\ C_{7}&=\{7,11\}=C_{11}, \\ C_{9}&=\{9\} \end{aligned}$$

and all of the elements of these cyclotomic cosets are relatively prime. Therefore, the distinct minimal polynomials corresponding to these 11 -cyclotomic cosets are

$$\begin{aligned} m_{1}(x)&=(x-\alpha )(x-\alpha ^{5})=x^{2}+3x+4, \\ m_{3}(x)&=(x-\alpha ^{3})=x+3, \\ m_{7}(x)&=(x-\alpha ^{7})(x-\alpha ^{11})=x^{2}+2x+1, \\ m_{9}(x)&=(x-\alpha ^{9})=x+2. \end{aligned}$$

Then

$$\begin{aligned} h(x)&=m_{1}(x)m_{3}(x)m_{7}(x)m_{9}(x) \\&=(x^{2}+3x+4)(x+3)(x^{2}+2x+1)(x+2) \\&=x^{6}+2x^{4}+x^{3}+6x+4. \end{aligned}$$

Since \(\text {deg}(\bar{h}(x))=\text {deg}(h(x))=6\) and \(\vert \text {supp} (\bar{h}(x)) \vert = \vert \text {supp}(h(x)) \vert =5\), the dimension of \(\mathcal {C}\) is 6 and locality of \(\mathcal {C}\) is \(r=4\le k=6\). If \(\mathcal {C}^{\perp }=\langle \bar{h}(x) \rangle \), then \(\mathcal {C}\) is a 5 -ary (3, 6, 4) 2-constacyclic LRC which is impossible since \(n=3<k=6\).

5 Conclusion

In this paper, we constructed constacyclic LRCs from their duals. We firstly obtained constacyclic codes with locality at most 2 and dimension 2 and gave a necessary and sufficient condition for constacyclic codes with locality 1. Then, we generalized this construction. Moreover, we obtained distance optimal constacyclic LRCs. We get constacyclic codes whose locality equals to their dimension. Lastly, we obtained constacyclic LRCs by means of cyclotomic cosets. These codes may be used in DSSs because of their small locality or optimality. LRCs with good parameters especially locality can be obtained by means of new parity-check polynomials.