# Cyclotomic polynomial

In mathematics, the nth cyclotomic polynomial, for any positive integer n, is the unique irreducible polynomial with integer coefficients that is a divisor of $x^{n}-1$ and is not a divisor of $x^{k}-1$ for any k < n. Its roots are all nth primitive roots of unity $e^{2i\pi {\frac {k}{n}}}$, where k runs over the positive integers less than n and coprime to n (and i is the imaginary unit). In other words, the nth cyclotomic polynomial is equal to
    $\Phi _{n}(x)=\prod _{\stackrel {1\leq k\leq n}{\gcd(k,n)=1}}\left(x-e^{2i\pi {\frac {k}{n}}}\right).$
It may also be defined as the monic polynomial with integer coefficients that is the minimal polynomial over the field of the rational numbers of any primitive nth-root of unity ($e^{2i\pi /n}$ is an example of such a root).
An important relation linking cyclotomic polynomials and primitive roots of unity is
    $\prod _{d\mid n}\Phi _{d}(x)=x^{n}-1,$
showing that $x$ is a root of $x^{n}-1$ if and only if it is a d th primitive root of unity for some d that divides n.

## Examples

If n is a prime number, then
    $\Phi _{n}(x)=1+x+x^{2}+\cdots +x^{n-1}=\sum _{k=0}^{n-1}x^{k}.$
If n = 2p where p is a prime number other than 2, then
    $\Phi _{2p}(x)=1-x+x^{2}-\cdots +x^{p-1}=\sum _{k=0}^{p-1}(-x)^{k}.$
For n up to 30, the cyclotomic polynomials are:
    ${\begin{aligned}\Phi _{1}(x)&=x-1\\\Phi _{2}(x)&=x+1\\\Phi _{3}(x)&=x^{2}+x+1\\\Phi _{4}(x)&=x^{2}+1\\\Phi _{5}(x)&=x^{4}+x^{3}+x^{2}+x+1\\\Phi _{6}(x)&=x^{2}-x+1\\\Phi _{7}(x)&=x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x+1\\\Phi _{8}(x)&=x^{4}+1\\\Phi _{9}(x)&=x^{6}+x^{3}+1\\\Phi _{10}(x)&=x^{4}-x^{3}+x^{2}-x+1\\\Phi _{11}(x)&=x^{10}+x^{9}+x^{8}+x^{7}+x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x+1\\\Phi _{12}(x)&=x^{4}-x^{2}+1\\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(x)&=x^{28}+x^{27}+x^{26}+x^{25}+x^{24}+x^{23}+x^{22}+x^{21}+x^{20}+x^{19}+x^{18}+x^{17}+x^{16}+x^{15}\\&\qquad \quad +x^{14}+x^{13}+x^{12}+x^{11}+x^{10}+x^{9}+x^{8}+x^{7}+x^{6}+x^{5}+x^{4}+x^{3}+x^{2}+x+1\\\Phi _{30}(x)&=x^{8}+x^{7}-x^{5}-x^{4}-x^{3}+x+1.\end{aligned}}$
The case of the 105th cyclotomic polynomial is interesting because 105 is the least positive integer that is the product of three distinct odd prime numbers (3×5×7) and this polynomial is the first one that has a coefficient other than 1, 0, or −1:
    ${\begin{aligned}\Phi _{105}(x)=&x^{48}+x^{47}+x^{46}-x^{43}-x^{42}-2x^{41}-x^{40}-x^{39}+x^{36}+x^{35}+x^{34}\\&+x^{33}+x^{32}+x^{31}-x^{28}-x^{26}-x^{24}-x^{22}-x^{20}+x^{17}+x^{16}+x^{15}\\&+x^{14}+x^{13}+x^{12}-x^{9}-x^{8}-2x^{7}-x^{6}-x^{5}+x^{2}+x+1.\end{aligned}}$

## Properties
### Fundamental tools

The cyclotomic polynomials are monic polynomials with integer coefficients that are irreducible over the field of the rational numbers. Except for n equal to 1 or 2, they are palindromes of even degree.
The degree of $\Phi _{n}$, or in other words the number of nth primitive roots of unity, is $\varphi (n)$, where $\varphi$ is Euler's totient function.
The fact that $\Phi _{n}$ is an irreducible polynomial of degree $\varphi (n)$ in the ring $\mathbb {Z} [x]$ is a nontrivial result due to Gauss. Depending on the chosen definition, it is either the value of the degree or the irreducibility which is a nontrivial result. The case of prime n is easier to prove than the general case, thanks to Eisenstein's criterion.
A fundamental relation involving cyclotomic polynomials is
    ${\begin{aligned}x^{n}-1&=\prod _{1\leqslant k\leqslant n}\left(x-e^{2i\pi {\frac {k}{n}}}\right)\\&=\prod _{d\mid n}\prod _{1\leqslant k\leqslant n \atop \gcd(k,n)=d}\left(x-e^{2i\pi {\frac {k}{n}}}\right)\\&=\prod _{d\mid n}\Phi _{\frac {n}{d}}(x)=\prod _{d\mid n}\Phi _{d}(x).\end{aligned}}$
which means that each n-th root of unity is a primitive d-th root of unity for a unique d dividing n.
The Möbius inversion formula allows $\Phi _{n}(x)$ to be expressed as an explicit rational fraction:
    $\Phi _{n}(x)=\prod _{d\mid n}(x^{d}-1)^{\mu \left({\frac {n}{d}}\right)},$
where $\mu$ is the Möbius function.
This provides a recursive formula for the cyclotomic polynomial $\Phi _{n}(x)$, which may be computed by dividing $x^{n}-1$ by the cyclotomic polynomials $\Phi _{d}(x)$ for the proper divisors d dividing n, starting from $\Phi _{1}(x)=x-1$:
    $\Phi _{n}(x)={\frac {x^{n}-1}{\prod _{\stackrel {d|n}{_{d<n}}}\Phi _{d}(x)}}.$
This gives an algorithm for computing any $\Phi _{n}(x)$, provided integer factorization and division of polynomials are available. Many computer algebra systems, such as SageMath, Maple, Mathematica, and PARI/GP, have a built-in function to compute the cyclotomic polynomials.

### Easy cases for computation

As noted above, if n = p is a prime number, then
    $\Phi _{p}(x)=1+x+x^{2}+\cdots +x^{p-1}=\sum _{k=0}^{p-1}x^{k}\;.$
If n is an odd integer greater than one, then
    $\Phi _{2n}(x)=\Phi _{n}(-x)\;.$
In particular, if n = 2p is twice an odd prime, then (as noted above)
    $\Phi _{2p}(x)=1-x+x^{2}-\cdots +x^{p-1}=\sum _{k=0}^{p-1}(-x)^{k}\;.$
If n = p$^m$ is a prime power (where p is prime), then
    $\Phi _{p^{m}}(x)=\Phi _{p}(x^{p^{m-1}})=\sum _{k=0}^{p-1}x^{kp^{m-1}}\;.$
More generally, if n = p$^m$r with r relatively prime to p, then
    $\Phi _{p^{m}r}(x)=\Phi _{pr}(x^{p^{m-1}})\;.$
These formulas may be applied repeatedly to get a simple expression for any cyclotomic polynomial $\Phi _{n}(x)$ in terms of a cyclotomic polynomial of square free index: If q is the product of the prime divisors of n (its radical), then
    $\Phi _{n}(x)=\Phi _{q}(x^{n/q})\;.$
This allows formulas to be given for the nth cyclotomic polynomial when n has at most one odd prime factor: If p is an odd prime number, and h and k are positive integers, then
    $\Phi _{2^{m}}(x)=x^{2^{m-1}}+1\;,$
    $\Phi _{p^{m}}(x)=\sum _{j=0}^{p-1}x^{jp^{m-1}}\;,$
    $\Phi _{2^{\ell }p^{m}}(x)=\sum _{j=0}^{p-1}(-1)^{j}x^{j2^{\ell -1}p^{m-1}}\;.$
For other values of n, the computation of the nth cyclotomic polynomial is similarly reduced to that of $\Phi _{q}(x),$ where q is the product of the distinct odd prime divisors of n. To deal with this case, one has that, for p prime and not dividing n,
    $\Phi _{np}(x)=\Phi _{n}(x^{p})/\Phi _{n}(x)\;.$

### Integers appearing as coefficients

The problem of bounding the magnitude of the coefficients of the cyclotomic polynomials has been the object of a number of research papers.
If n has at most two distinct odd prime factors, then Migotti showed that the coefficients of $\Phi _{n}$ are all in the set {1, −1, 0}.
The first cyclotomic polynomial for a product of three different odd prime factors is $\Phi _{105}(x);$ it has a coefficient −2 (see above). The converse is not true: $\Phi _{231}(x)=\Phi _{3\times 7\times 11}(x)$ only has coefficients in {1, −1, 0}.
If n is a product of more different odd prime factors, the coefficients may increase to very high values. E.g., $\Phi _{15015}(x)=\Phi _{3\times 5\times 7\times 11\times 13}(x)$ has coefficients running from −22 to 23; also $\Phi _{255255}(x)=\Phi _{3\times 5\times 7\times 11\times 13\times 17}(x)$, the smallest n with 6 different odd primes, has coefficients of magnitude up to 532.
Let A(n) denote the maximum absolute value of the coefficients of $\Phi _{n}(x)$. It is known that for any positive k, the number of n up to x with A(n) > n$^k$ is at least c(k)⋅x for a positive c(k) depending on k and x sufficiently large. In the opposite direction, for any function ψ(n) tending to infinity with n we have A(n) bounded above by n$^{ψ(n)}$ for almost all n.
A combination of theorems of Bateman and Vaughan states that$^{:10}$ on the one hand, for every $\varepsilon >0$, we have
    $A(n)<e^{\left(n^{(\log 2+\varepsilon )/(\log \log n)}\right)}$
for all sufficiently large positive integers $n$, and on the other hand, we have
    $A(n)>e^{\left(n^{(\log 2)/(\log \log n)}\right)}$
for infinitely many positive integers $n$. This implies in particular that univariate polynomials (concretely $x^{n}-1$ for infinitely many positive integers $n$) can have factors (like $\Phi _{n}$) whose coefficients are superpolynomially larger than the original coefficients. This is not too far from the general Landau-Mignotte bound.

### Gauss's formula

Let n be odd, square-free, and greater than 3. Then:
    $4\Phi _{n}(z)=A_{n}^{2}(z)-(-1)^{\frac {n-1}{2}}nz^{2}B_{n}^{2}(z)$
for certain polynomials A$_n$(z) and B$_n$(z) with integer coefficients, A$_n$(z) of degree φ(n)/2, and B$_n$(z) of degree φ(n)/2 − 2. Furthermore, A$_n$(z) is palindromic when its degree is even; if its degree is odd it is antipalindromic. Similarly, B$_n$(z) is palindromic unless n is composite and n ≡ 3 (mod 4), in which case it is antipalindromic.
The first few cases are
    ${\begin{aligned}4\Phi _{5}(z)&=4(z^{4}+z^{3}+z^{2}+z+1)\\&=(2z^{2}+z+2)^{2}-5z^{2}\\[6pt]4\Phi _{7}(z)&=4(z^{6}+z^{5}+z^{4}+z^{3}+z^{2}+z+1)\\&=(2z^{3}+z^{2}-z-2)^{2}+7z^{2}(z+1)^{2}\\[6pt]4\Phi _{11}(z)&=4(z^{10}+z^{9}+z^{8}+z^{7}+z^{6}+z^{5}+z^{4}+z^{3}+z^{2}+z+1)\\&=(2z^{5}+z^{4}-2z^{3}+2z^{2}-z-2)^{2}+11z^{2}(z^{3}+1)^{2}\end{aligned}}$

### Lucas's formula

Let n be odd, square-free and greater than 3. Then
    $\Phi _{n}(z)=U_{n}^{2}(z)-(-1)^{\frac {n-1}{2}}nzV_{n}^{2}(z)$
for certain polynomials U$_n$(z) and V$_n$(z) with integer coefficients, U$_n$(z) of degree φ(n)/2, and V$_n$(z) of degree φ(n)/2 − 1. This can also be written
    $\Phi _{n}\left((-1)^{\frac {n-1}{2}}z\right)=C_{n}^{2}(z)-nzD_{n}^{2}(z).$
If n is even, square-free and greater than 2 (this forces n/2 to be odd),
    $\Phi _{\frac {n}{2}}(-z^{2})=\Phi _{2n}(z)=C_{n}^{2}(z)-nzD_{n}^{2}(z)$
for C$_n$(z) and D$_n$(z) with integer coefficients, C$_n$(z) of degree φ(n), and D$_n$(z) of degree φ(n) − 1. C$_n$(z) and D$_n$(z) are both palindromic.
The first few cases are:
    ${\begin{aligned}\Phi _{3}(-z)&=\Phi _{6}(z)=z^{2}-z+1\\&=(z+1)^{2}-3z\\[6pt]\Phi _{5}(z)&=z^{4}+z^{3}+z^{2}+z+1\\&=(z^{2}+3z+1)^{2}-5z(z+1)^{2}\\[6pt]\Phi _{6/2}(-z^{2})&=\Phi _{12}(z)=z^{4}-z^{2}+1\\&=(z^{2}+3z+1)^{2}-6z(z+1)^{2}\end{aligned}}$

### Sister Beiter conjecture

The Sister Beiter conjecture is concerned with the maximal size (in absolute value) $A(pqr)$ of coefficients of ternary cyclotomic polynomials $\Phi _{pqr}(x)$ where $p\leq q\leq r$ are three odd primes.

## Cyclotomic polynomials over a finite field and over the p-adic integers

Over a finite field with a prime number p of elements, for any integer n that is not a multiple of p, the cyclotomic polynomial $\Phi _{n}$ factorizes into ${\frac {\varphi (n)}{d}}$ irreducible polynomials of degree d, where $\varphi (n)$ is Euler's totient function and d is the multiplicative order of p modulo n. In particular, $\Phi _{n}$ is irreducible if and only if p is a primitive root modulo n, that is, p does not divide n, and its multiplicative order modulo n is $\varphi (n)$, the degree of $\Phi _{n}$.
These results are also true over the p-adic integers, since Hensel's lemma allows lifting a factorization over the field with p elements to a factorization over the p-adic integers.

## Polynomial values

If x takes any real value, then $\Phi _{n}(x)>0$ for every n ≥ 3 (this follows from the fact that the roots of a cyclotomic polynomial are all non-real, for n ≥ 3).
For studying the values that a cyclotomic polynomial may take when x is given an integer value, it suffices to consider only the case n ≥ 3, as the cases n = 1 and n = 2 are trivial (one has $\Phi _{1}(x)=x-1$ and $\Phi _{2}(x)=x+1$).
For n ≥ 2, one has
    $\Phi _{n}(0)=1,$
    $\Phi _{n}(1)=1$ if n is not a prime power,
    $\Phi _{n}(1)=p$ if $n=p^{k}$ is a prime power with k ≥ 1.
The values that a cyclotomic polynomial $\Phi _{n}(x)$ may take for other integer values of x is strongly related with the multiplicative order modulo a prime number.
More precisely, given a prime number p and an integer b coprime with p, the multiplicative order of b modulo p, is the smallest positive integer n such that p is a divisor of $b^{n}-1.$ For b > 1, the multiplicative order of b modulo p is also the shortest period of the representation of 1/p in the numeral base b (see Unique prime; this explains the notation choice).
The definition of the multiplicative order implies that, if n is the multiplicative order of b modulo p, then p is a divisor of $\Phi _{n}(b).$ The converse is not true, but one has the following.
If n > 0 is a positive integer and b > 1 is an integer, then (see below for a proof)
    $\Phi _{n}(b)=2^{k}gh,$
where
* k is a non-negative integer, always equal to 0 when b is even. (In fact, if n is neither 1 nor 2, then k is either 0 or 1. Besides, if n is not a power of 2, then k is always equal to 0)
* g is 1 or the largest odd prime factor of n.
* h is odd, coprime with n, and its prime factors are exactly the odd primes p such that n is the multiplicative order of b modulo p.
This implies that, if p is an odd prime divisor of $\Phi _{n}(b),$ then either n is a divisor of p − 1 or p is a divisor of n. In the latter case, $p^{2}$ does not divide $\Phi _{n}(b).$
Zsigmondy's theorem implies that the only cases where b > 1 and h = 1 are
    ${\begin{aligned}\Phi _{1}(2)&=1\\\Phi _{2}\left(2^{k}-1\right)&=2^{k}&&k>0\\\Phi _{6}(2)&=3\end{aligned}}$
It follows from above factorization that the odd prime factors of
    ${\frac {\Phi _{n}(b)}{\gcd(n,\Phi _{n}(b))}}$
are exactly the odd primes p such that n is the multiplicative order of b modulo p. This fraction may be even only when b is odd. In this case, the multiplicative order of b modulo 2 is always 1.
There are many pairs (n, b) with b > 1 such that $\Phi _{n}(b)$ is prime. In fact, Bunyakovsky conjecture implies that, for every n, there are infinitely many b > 1 such that $\Phi _{n}(b)$ is prime. See OEIS: A085398 for the list of the smallest b > 1 such that $\Phi _{n}(b)$ is prime (the smallest b > 1 such that $\Phi _{n}(b)$ is prime is about $\gamma \cdot \varphi (n)$, where $\gamma$ is Euler–Mascheroni constant, and $\varphi$ is Euler's totient function). See also OEIS: A206864 for the list of the smallest primes of the form $\Phi _{n}(b)$ with n > 2 and b > 1, and, more generally, OEIS: A206942, for the smallest positive integers of this form.

## Applications

Using $\Phi _{n}$, one can give an elementary proof for the infinitude of primes congruent to 1 modulo n, which is a special case of Dirichlet's theorem on arithmetic progressions.

### Periodic recursive sequences

The constant-coefficient linear recurrences which are periodic are precisely the power series coefficients of rational functions whose denominators are products of cyclotomic polynomials.
In the theory of combinatorial generating functions, the denominator of a rational function determines a linear recurrence for its power series coefficients. For example, the Fibonacci sequence has generating function
   $F(x)=F_{1}x+F_{2}x^{2}+F_{3}x^{3}+\cdots ={\frac {x}{1-x-x^{2}}},$
and equating coefficients on both sides of $F(x)(1-x-x^{2})=x$ gives $F_{n}-F_{n-1}-F_{n-2}=0$ for $n\geq 2$.
Any rational function whose denominator is a divisor of $x^{n}-1$ has a recursive sequence of coefficients which is periodic with period at most n. For example,
   $P(x)=-{\frac {1+2x}{\Phi _{6}(x)}}={\frac {1+2x}{1-x+x^{2}}}=\sum _{n\geq 0}P_{n}x^{n}=1+3x+2x^{2}-x^{3}-3x^{4}-2x^{5}+x^{6}+3x^{7}+2x^{8}+\cdots$
has coefficients defined by the recurrence $P_{n}-P_{n-1}+P_{n-2}=0$ for $n\geq 2$, starting from $P_{0}=1,P_{1}=3$. But $1-x^{6}=\Phi _{6}(x)\Phi _{3}(x)\Phi _{2}(x)\Phi _{1}(x)$, so we may write
   $P(x)={\frac {(1+2x)\Phi _{3}(x)\Phi _{2}(x)\Phi _{1}(x)}{1-x^{6}}}={\frac {1+3x+2x^{2}-x^{3}-3x^{4}-2x^{5}}{1-x^{6}}},$
which means $P_{n}-P_{n-6}=0$ for $n\geq 6$, and the sequence has period 6 with initial values given by the coefficients of the numerator.