FLINT3.7.0-dev
Algorithm

Dirichlet characters

Cost
One discrete logarithm per prime power component for a value; O(φ(q))O(\varphi(q)) or a sieve with O(π(n))O(\pi(n)) logarithms for all values up to nn; conductor, parity and order from the number in O(log⁡2q)O(\log^2 q).

A Dirichlet character modulo qq is a group homomorphism χ:(Z/qZ)×→C×\chi : (\mathbb{Z}/q\mathbb{Z})^\times \to \mathbb{C}^\times, extended to Z\mathbb{Z} by periodicity and by χ(n)=0\chi(n) = 0 for gcd⁡(n,q)>1\gcd(n, q) > 1. For the theory see [Apo1976, Chapter 6] and [IR1990, Chapter 4]; the numbering is that of Conrey, used by the LMFDB [LMFDB].

The unit group#

By the Chinese remainder theorem (Z/qZ)×≅∏pe∥q(Z/peZ)×(\mathbb{Z}/q\mathbb{Z})^\times \cong \prod_{p^e \| q} (\mathbb{Z}/p^e\mathbb{Z})^\times, and the factors have the following structure [IR1990, Theorem 2 of Chapter 4].

Theorem 1. For an odd prime pp, (Z/peZ)×(\mathbb{Z}/p^e\mathbb{Z})^\times is cyclic of order pe−1(p−1)p^{e-1}(p - 1), and an integer gg generates it for every e≥1e \ge 1 if and only if gg generates (Z/p2Z)×(\mathbb{Z}/p^2\mathbb{Z})^\times. For e≥3e \ge 3, (Z/2eZ)×(\mathbb{Z}/2^e\mathbb{Z})^\times is the direct product of the subgroup {±1}\{\pm 1\} and the cyclic subgroup of order 2e−22^{e-2} generated by 5; (Z/4Z)×={±1}(\mathbb{Z}/4\mathbb{Z})^\times = \{\pm 1\} and (Z/2Z)×(\mathbb{Z}/2\mathbb{Z})^\times is trivial.

The Conrey generators are: for odd pp, the smallest positive integer that is a primitive root modulo p2p^2; for 8∣q8 \mid q, the two generators −1-1 and 55 of the 2-part; for 4∥q4 \| q, the generator −1-1. For all primes up to 101610^{16} except p=40487p = 40487 and p=6692367337p = 6692367337, the smallest primitive root modulo pp is also a primitive root modulo p2p^2, so FLINT computes it with n_primitive_root_prime and treats the two exceptions separately (the generators are 10 and 7); larger prime factors are not supported. Each generator gkg_k of order φk\varphi_k is lifted to g~k≡gk(modpe)\tilde g_k \equiv g_k \pmod{p^e}, g~k≡1(modq/pe)\tilde g_k \equiv 1 \pmod{q/p^e}, so that every m∈(Z/qZ)×m \in (\mathbb{Z}/q\mathbb{Z})^\times is uniquely

m=∏kg~k ak,0≤ak<φk.m = \prod_k \tilde g_k^{\,a_k}, \qquad 0 \le a_k < \varphi_k.

The vector (ak)(a_k) is the log of mm. The exponent of the group is e=lcm⁡kφke = \operatorname{lcm}_k \varphi_k.

Characters and the Conrey pairing#

A character is determined by its values on the generators, which are φk\varphi_k-th roots of unity. Conrey's choice is

χq(m,n)=exp⁡(2πi∑kakbkφk)\chi_q(m, n) = \exp\left(2 \pi i \sum_k \frac{a_k b_k}{\varphi_k}\right)

for m,nm, n with logs (ak)(a_k) and (bk)(b_k). This is a nondegenerate symmetric bilinear pairing on (Z/qZ)×(\mathbb{Z}/q\mathbb{Z})^\times, so m↦χq(m,⋅)m \mapsto \chi_q(m, \cdot) is an isomorphism from the group onto its dual. As a consequence, the character group operations are those of the numbers (χq(m,⋅)χq(m′,⋅)=χq(mm′,⋅)\chi_q(m, \cdot)\chi_q(m', \cdot) = \chi_q(mm', \cdot)), the order of χq(m,⋅)\chi_q(m, \cdot) is the multiplicative order of mm, and by symmetry χq(m,−1)=χq(−1,m)\chi_q(m, -1) = \chi_q(-1, m). Values are exact roots of unity ζev\zeta_e^v with v=∑kakbk(e/φk) mod ev = \sum_k a_k b_k (e/\varphi_k) \bmod e, which the module returns as the exponent vv.

Conductor, parity and primitivity#

A character modulo qq is induced by a character modulo f∣qf \mid q if it is the composition with the reduction (Z/qZ)×→(Z/fZ)×(\mathbb{Z}/q\mathbb{Z})^\times \to (\mathbb{Z}/f\mathbb{Z})^\times. The conductor is the smallest such ff, and χ\chi is primitive if its conductor is qq.

Proposition 2. The conductor of χq(m,⋅)\chi_q(m, \cdot) is the product over the components of the following factors. For an odd pe∥qp^e \| q with log entry aa: 1 if a=0a = 0, and pe−vp(a)p^{e - v_p(a)} otherwise. For the 2-part: 1 if both log entries are zero; 4 if only the entry of −1-1 is nonzero; 2e−v2(a)2^{e - v_2(a)} if the entry aa of 55 is nonzero.

Proof. The character is induced modulo ff if and only if it is trivial on the kernel of the reduction modulo ff, which is a product over the components. For a cyclic component generated by gg of order φ=φ(pe)\varphi = \varphi(p^e), the kernel of the reduction to pfp^f is generated by gφ(pf)g^{\varphi(p^f)}, and χ(gφ(pf))=exp⁡(2πi aφ(pf)/φ(pe))\chi(g^{\varphi(p^f)}) = \exp(2\pi i\, a \varphi(p^f)/\varphi(p^e)) is 1 if and only if pe−f∣ap^{e-f} \mid a. The smallest such ff is e−vp(a)e - v_p(a). The 2-part is analogous, with the kernel of the reduction from 2e2^e to 2f2^f, f≥3f \ge 3, generated by 52f−25^{2^{f-2}}, and to 44 by 55.

From the number mm instead of the log, the pp-part of the conductor is p1+tp^{1 + t}, where t≥0t \ge 0 is the least integer with m(p−1)pt≡1(modpe)m^{(p-1)p^t} \equiv 1 \pmod{p^e} (and 1 if m≡1(modpe)m \equiv 1 \pmod {p^e}), since the order of mm in the component determines vp(a)v_p(a). The parity follows from the symmetry of the pairing:

Proposition 3. χq(m,−1)=ϵ⋅(mq′)\chi_q(m, -1) = \epsilon \cdot \left(\frac{m}{q'}\right), where q′q' is the product of the distinct odd primes dividing qq, (⋅/⋅)(\cdot/\cdot) is the Jacobi symbol, and ϵ=−1\epsilon = -1 if 4∣q4 \mid q and m≡3(mod4)m \equiv 3 \pmod 4, otherwise ϵ=1\epsilon = 1.

Proof. χq(m,−1)=χq(−1,m)\chi_q(m, -1) = \chi_q(-1, m). In an odd component, −1=gφ/2-1 = g^{\varphi/2} has log entry φ/2\varphi/2, contributing exp⁡(πib)=(−1)b\exp(\pi i b) = (-1)^b where bb is the log entry of mm; bb is even exactly when mm is a square modulo pp, so the contribution is the Legendre symbol (m/p)(m/p). In the 2-part, −1-1 has entry 1 on the generator −1-1 and 0 on 55, contributing (−1)a0(-1)^{a_0} with a0=1a_0 = 1 exactly when m≡3(mod4)m \equiv 3 \pmod 4.

Counting the logs that give conductor qq in each component, the number of primitive characters is multiplicative: p−2p - 2 for p∥qp \| q, (p−1)2pe−2(p - 1)^2 p^{e-2} for pe∥qp^e \| q with e≥2e \ge 2, and for the 2-part 0, 1 and 2e−22^{e-2} for 2∥q2 \| q, 4∥q4 \| q and 2e∥q2^e \| q with e≥3e \ge 3.

Computing values#

The value χq(m,n)\chi_q(m, n) requires the log of nn, hence a discrete logarithm in each odd component; the 2-part needs only n mod 4n \bmod 4 and a 2-adic logarithm. These are computed with the dlog module (Discrete logarithm tables): a single logarithm with dlog_once, or with tables precomputed for many calls.

For the vector of values χ(0),…,χ(N−1)\chi(0), \ldots, \chi(N-1) there are two strategies.

  • Loop over the group. Enumerating the logs in lexicographic order (dirichlet_char_next), each step multiplies the number by one generator and adds a constant to the value exponent, so all φ(q)\varphi(q) values cost O(φ(q))O(\varphi(q)) operations without any discrete logarithm. This is best when NN is comparable with qq.
  • Sieve. Since χ\chi is completely multiplicative, it suffices to know χ(p)\chi(p) for the primes p<Np < N; dlog_vec_add computes the discrete logarithms of the small primes directly and obtains those of the larger primes cheaply from relations found by a partial extended Euclidean algorithm, then fills in all k<Nk < N by multiplicativity. Each odd component contributes its part of the exponent, and the 2-part is added directly. This is best for NN much smaller than qq.

Use in FLINT#

Referenced from#

References#

Cite this page

The FLINT team, “Dirichlet characters,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/number-theory/dirichlet-characters.html (generated 2026-11-02).