FLINT3.7.0-dev
Module · 51 functions

dirichlet.h

#include <flint/dirichlet.h>

This module works with Dirichlet characters modulo a word-size integer qq algebraically. A character χ\chi modulo qq takes the value 0 on integers not coprime to qq and roots of unity on the others; the module represents a value e2πiv/ee^{2\pi i v/e} exactly by the exponent vv modulo the exponent ee of the group, and computes characters, their products and powers, their conductors, parities and orders, and vectors of values, using discrete logarithms from dlog. Characters are labelled in the Conrey numbering of the LMFDB [LMFDB], in which the characters modulo qq are indexed by the residues m∈(Z/qZ)×m \in (\mathbb{Z}/q\mathbb{Z})^\times, written χq(m,⋅)\chi_q(m, \cdot). Numerical values and LL-functions are in acb_dirichlet.

Warning: the interfaces in this module are experimental and may change without notice.

The guide Characters in the Conrey numbering explains the numbering and the representation with an example; Dirichlet characters gives the mathematics and the algorithms.

AlgorithmDirichlet charactersRepresents the Dirichlet characters modulo q through the decomposition of the unit group into cyclic components with Conrey's generators, so that characters, values, conductors, parities and orders are computed from discrete logarithms in each component or directly from the Conrey number.

Guides#

The group modulo qq#

The group (Z/qZ)×(\mathbb{Z}/q\mathbb{Z})^\times is a product of cyclic groups, one for each odd prime power pe∥qp^e \| q and up to two for the power of 2. The structure dirichlet_group_t stores this decomposition with one Conrey generator per component; an element (and the character it labels) is then described by its number m∈(Z/qZ)×m \in (\mathbb{Z}/q\mathbb{Z})^\times or by its log, the vector of exponents of mm on the generators.

The group (Z/qZ)×(\mathbb{Z}/q\mathbb{Z})^\times with its decomposition: the modulus q, the number of components num, the group order phi_q =φ(q)= \varphi(q), the group exponent expo, the generators lifted modulo qq and, per component, the prime power, the order phi of the component and optional discrete logarithm tables. A dirichlet_group_t is an array of length one of dirichlet_group_struct.

The size (16) of some fixed arrays indexed by the components: the largest number of components of a 64-bit modulus, two for the 2-part and 14 for the odd primes, as for q=8⋅3⋅5⋯47q = 8 \cdot 3 \cdot 5 \cdots 47.

Initialises GG as the group of characters modulo q≥1q \ge 1, computing the factorisation of qq, the Conrey generators and the exponent. No discrete logarithm tables are computed, so this is cheap even for large qq. Returns 1 on success, and 0 (without allocating) if a prime factor of qq exceeds 101610^{16}, for which the generator is not implemented.

More

Initialises HH as the group modulo hh, for h∣qh \mid q, sharing the components of GG (in particular its discrete logarithm tables, which must not be cleared while HH is in use).

Frees the memory used by GG, but not its discrete logarithm tables, which may be shared with subgroups; free them first with dirichlet_group_dlog_clear.

Returns the number φ(q)\varphi(q) of elements of GG, which is also the number of characters modulo qq.

Returns the number of primitive characters modulo qq: 0 if q≡2(mod4)q \equiv 2 \pmod 4, and otherwise the product over the components of p−2p - 2 for p1∥qp^1 \| q (pp odd), (p−1)2pe−2(p-1)^2 p^{e-2} for pe∥qp^e \| q (e≥2e \ge 2), 1 for 4∥q4 \| q and 2e−22^{e-2} for 2e∥q2^e \| q, e≥3e \ge 3.

Precomputes discrete logarithm tables in every component for about num subsequent logarithms, with dlog_precomp_modpe_init. This speeds up dirichlet_char_log, dirichlet_chi and dirichlet_pairing when they are called many times. For very large num the whole group may be tabulated.

Frees the discrete logarithm tables of GG. Subgroups sharing them must be cleared first.

Characters#

An element of GG, used as the character χq(m,⋅)\chi_q(m, \cdot): its number n =m= m and its log, an array log of num exponents with m≡∏kgklog[k](modq)m \equiv \prod_k g_k^{\mathit{log}[k]} \pmod q. A dirichlet_char_t is an array of length one of dirichlet_char_struct.

Initialises xx as an element of GG and sets it to the principal character (m=1m = 1).

Frees the memory used by xx.

Prints the log of xx as a list [a_0, a_1, ...].

Sets xx to a copy of yy.

Return 1 if xx and yy are equal, otherwise 0. The first function compares the numbers only; the second also compares the logs and is meant for testing the consistency of the two representations.

Sets xx to the character of number mm, which must be coprime to qq and reduced modulo qq, computing its log by discrete logarithms in each component (with the tables of GG if present).

Return the number of xx. The first function reads the stored number; the second recomputes it from the log, stores it in xx and returns it.

Sets xx to the principal character, with log [0,…,0][0, \ldots, 0] and number 1.

Sets xx to the first primitive character in the order of dirichlet_char_next_primitive, with log [1,…,1][1, \ldots, 1], or [0,1,…,1][0, 1, \ldots, 1] if 8∣q8 \mid q. Throws if q≡2(mod4)q \equiv 2 \pmod 4, where no primitive character exists.

Sets xx to the next element of GG in the lexicographic order of the logs (the last component varying fastest), updating the number with one multiplication. Returns the index of the most significant component that changed, or −1-1 after the last element (when xx wraps around to the principal character).

More

As dirichlet_char_next, but skips to the next primitive character, in the same order. Start from dirichlet_char_first_primitive.

Convert between an element and its index j∈[0,φ(q))j \in [0, \varphi(q)) in the lexicographic order of the logs, the mixed-radix number with digits log[k]\mathit{log}[k] in base φk\varphi_k.

Properties#

In the Conrey numbering the conductor, parity and order of χq(m,⋅)\chi_q(m, \cdot) can be computed either from the number mm (the _ui functions) or from the log (the _char functions); neither needs a discrete logarithm.

Returns 1 if χ\chi is the principal character (m=1m = 1).

Return the conductor of χq(a,⋅)\chi_q(a, \cdot), the smallest f∣qf \mid q such that the character is induced by a character modulo ff.

Return the parity λ∈{0,1}\lambda \in \{0, 1\} of χq(a,⋅)\chi_q(a, \cdot), defined by χ(−1)=(−1)λ\chi(-1) = (-1)^\lambda: 0 for even and 1 for odd characters.

Return the order of χq(a,⋅)\chi_q(a, \cdot) in the character group, which is the multiplicative order of aa modulo qq.

Returns 1 if χ\chi is real, that is, has order at most 2 (its number satisfies m2≡1(modq)m^2 \equiv 1 \pmod q).

Returns 1 if χ\chi is primitive, that is, its conductor is qq.

Values#

A value χ(n)\chi(n) is returned as an exponent vv with χ(n)=e2πiv/e\chi(n) = e^{2\pi i v/e}, where ee is the exponent G->expo of the group (or a given order), and the value 0 is encoded by the special exponent DIRICHLET_CHI_NULL. See Values as exponents.

The exponent UWORD_MAX that encodes the value χ(n)=0\chi(n) = 0, for nn not coprime to qq.

Return the exponent of χq(m,n)\chi_q(m, n) modulo G->expo, or DIRICHLET_CHI_NULL if mm or nn is not coprime to qq. The pairing is symmetric: χq(m,n)=χq(n,m)\chi_q(m, n) = \chi_q(n, m). The _char version takes both arguments as elements with their logs and needs no discrete logarithm; the other computes two.

Returns the exponent of χ(n)\chi(n) modulo G->expo, or DIRICHLET_CHI_NULL if gcd⁡(n,q)>1\gcd(n, q) > 1. Costs one discrete logarithm per component of GG.

Set v[k]v[k] to the exponent of χ(k)\chi(k) for 0≤k<nv0 \le k < \mathit{nv}, modulo G->expo or modulo order, which must be a multiple of the order of χ\chi; entries with gcd⁡(k,q)>1\gcd(k, q) > 1 are set to DIRICHLET_CHI_NULL. The functions call the loop versions if 2 nv>φ(q)2\,\mathit{nv} > \varphi(q) and the primeloop versions otherwise. v[0]v[0] is DIRICHLET_CHI_NULL for q>1q > 1, and for q=1q = 1, where the trivial character is 1 everywhere, every entry is 0.

As dirichlet_chi_vec, by enumerating the whole group with dirichlet_char_next and updating the value by one addition per step; entries k≥qk \ge q are copied by periodicity. Costs O(φ(q)+nv)O(\varphi(q) + \mathit{nv}) and needs no discrete logarithm. Requires nv≥2\mathit{nv} \ge 2: the function writes v[1]v[1].

As dirichlet_chi_vec, by adding the contributions of the components: the 2-part directly, and each odd prime power with dlog_vec_add, which computes the discrete logarithms of all k<nvk < \mathit{nv} by sieving (using the tables of GG if present). See the warning about v[0]v[0] at dirichlet_chi_vec.

Sets v[k]v[k] to DIRICHLET_CHI_NULL for 0<k<nv0 < k < \mathit{nv} divisible by a prime factor of qq (except v[0]v[0], which is not changed).

Operations on characters#

Sets cc to the product abab: the logs are added and the numbers multiplied.

Sets cc to ana^n.

Given a character χH\chi_H modulo h∣qh \mid q (with HH a subgroup of GG created by dirichlet_subgroup_init), sets χG\chi_G to the character modulo qq that it induces. Throws if h∤qh \nmid q.

Given a character χG\chi_G modulo qq whose conductor divides hh, with h∣qh \mid q the modulus of HH, sets χH\chi_H to the character modulo hh that induces it. Throws if h∤qh \nmid q or the conductor does not divide hh.

References#

Cite this page

The FLINT team, “dirichlet.h (module overview),” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/dirichlet/index.html (generated 2026-11-02).