---
title: "Dirichlet Characters"
canonical: "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/dirichlet-characters.html"
source: "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/dirichlet-characters.md"
part: "Basic Rings"
chapter: "Integer Residue Class Rings"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Basic Rings", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/index-basic-rings.md"}
  - {"title": "Integer Residue Class Rings", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/index-residue-class-rings.md"}
prev: {"title": "The Unit Group", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/ResidueClassRings/unit-group.md"}
next: {"title": "Rational Field", "source": "https://docs.magma-maths.org/v2.30-1/BasicRings/Rationals/index-rationals.md"}
intrinsics:
  - {"name": "DirichletGroup", "signature": "DirichletGroup(N): RngIntElt -> GrpDrch"}
  - {"name": "FullDirichletGroup", "signature": "FullDirichletGroup(N): RngIntElt -> GrpDrch"}
  - {"name": "DirichletGroup", "signature": "DirichletGroup(N, R): RngIntElt, Rng -> GrpDrch"}
  - {"name": "DirichletGroup", "signature": "DirichletGroup(N, R, z, r): RngIntElt, Rng, RngElt, RngIntElt -> GrpDrch"}
  - {"name": "BaseExtend", "signature": "BaseExtend(G, R): GrpDrch, Rng -> GrpDrch"}
  - {"name": "BaseExtend", "signature": "BaseExtend(G, R, z): GrpDrch, Rng, RngElt -> GrpDrch"}
  - {"name": "AssignNames", "signature": "AssignNames(~G, S): GrpDrch, [MonStgElt]"}
  - {"name": "Elements", "signature": "Elements(G): GrpDrch -> [GrpDrchElt]"}
  - {"name": "Random", "signature": "Random(G): GrpDrch -> GrpDrchElt"}
  - {"name": ".", "signature": "G . i: GrpDrch, RngIntElt -> GrpDrchElt"}
  - {"name": "!", "signature": "G ! x: GrpDrch, Any -> GrpDrchElt"}
  - {"name": "KroneckerCharacter", "signature": "KroneckerCharacter(D): RngIntElt -> GrpDrchElt"}
  - {"name": "KroneckerCharacter", "signature": "KroneckerCharacter(D, R): RngIntElt, Rng -> GrpDrchElt"}
  - {"name": "BaseRing", "signature": "BaseRing(G): GrpDrch -> Rng"}
  - {"name": "Modulus", "signature": "Modulus(G): GrpDrch -> RngIntElt"}
  - {"name": "Order", "signature": "Order(G): GrpDrch -> RngIntElt"}
  - {"name": "Exponent", "signature": "Exponent(G): GrpDrch -> RngIntElt"}
  - {"name": "NumberOfGenerators", "signature": "NumberOfGenerators(G): GrpDrch -> RngIntElt"}
  - {"name": "Generators", "signature": "Generators(G): GrpDrch -> [GrpDrchElt]"}
  - {"name": "UnitGenerators", "signature": "UnitGenerators(G): GrpDrch -> [RngIntElt]"}
  - {"name": "GaloisConjugacyRepresentatives", "signature": "GaloisConjugacyRepresentatives(G): GrpDrch -> [GrpDrchElt]"}
  - {"name": "GaloisConjugacyRepresentatives", "signature": "GaloisConjugacyRepresentatives(seq): [GrpDrchElt] -> [GrpDrchElt]"}
  - {"name": "AbelianGroup", "signature": "AbelianGroup(G): GrpDrch -> GrpAb, Map"}
  - {"name": "BaseRing", "signature": "BaseRing(chi): GrpDrchElt -> Rng"}
  - {"name": "Modulus", "signature": "Modulus(chi): GrpDrchElt -> RngIntElt"}
  - {"name": "Conductor", "signature": "Conductor(chi): GrpDrchElt -> RngIntElt"}
  - {"name": "ElementToSequence", "signature": "ElementToSequence(chi): GrpDrchElt -> SeqEnum"}
  - {"name": "eq", "signature": "x eq y: GrpDrchElt, GrpDrchElt -> BoolElt"}
  - {"name": "Order", "signature": "Order(chi): GrpDrchElt -> RngIntElt"}
  - {"name": "IsTrivial", "signature": "IsTrivial(chi): GrpDrchElt -> BoolElt"}
  - {"name": "IsPrimitive", "signature": "IsPrimitive(chi): GrpDrchElt -> BoolElt"}
  - {"name": "AssociatedPrimitiveCharacter", "signature": "AssociatedPrimitiveCharacter(chi): GrpDrchElt -> GrpDrchElt"}
  - {"name": "IsEven", "signature": "IsEven(chi): GrpDrchElt -> BoolElt"}
  - {"name": "IsOdd", "signature": "IsOdd(chi): GrpDrchElt -> BoolElt"}
  - {"name": "IsTotallyEven", "signature": "IsTotallyEven(chi): GrpDrchElt -> BoolElt"}
  - {"name": "Decomposition", "signature": "Decomposition(chi): GrpDrchElt -> List"}
  - {"name": "MinimalBaseRingCharacter", "signature": "MinimalBaseRingCharacter(chi): GrpDrchElt -> GrpDrchElt"}
  - {"name": "Evaluate", "signature": "Evaluate(chi, n): GrpDrchElt, RngIntElt -> RngElt"}
  - {"name": "chi", "signature": "chi(n): GrpDrchElt, RngIntElt -> RngElt"}
  - {"name": "ValueList", "signature": "ValueList(chi): GrpDrchElt -> [RngElt]"}
  - {"name": "ValuesOnUnitGenerators", "signature": "ValuesOnUnitGenerators(chi): GrpDrchElt -> [RngElt]"}
  - {"name": "OrderOfRootOfUnity", "signature": "OrderOfRootOfUnity(r, n): RngElt, RngIntElt -> RngIntElt"}
  - {"name": "*", "signature": "x * y: GrpDrchElt, GrpDrchElt -> GrpDrchElt"}
  - {"name": "/", "signature": "x / y: GrpDrchElt, GrpDrchElt -> GrpDrchElt"}
  - {"name": "^", "signature": "x ^ n: GrpDrchElt, RngIntElt -> GrpDrchElt"}
  - {"name": "^", "signature": "x ^ phi: GrpDrchElt, Map -> GrpDrchElt"}
  - {"name": "Sqrt", "signature": "Sqrt(x): GrpDrchElt -> GrpDrchElt"}
examples:
  - "ex-19f11f"
---

<a id="rngint-dirichlet"></a>
<a id="id1"></a>
# Dirichlet Characters

Let $R$ be a ring. Then a *Dirichlet character over* $R$ *of modulus* $N$ is a homomorphism

$$
\varepsilon : ({\mathbb{Z}}/N{\mathbb{Z}})^* \rightarrow R^*,
$$

where $R^*$ is the group of invertible elements of $R$. We extend $\varepsilon$ to a set theoretic map on the whole of ${\mathbb{Z}}$ by defining $\varepsilon(x) = 0$ if $\gcd(x,N)\neq 1$. The *conductor* of $\varepsilon$ is the smallest positive integer $M$ such that the homomorphism $({\mathbb{Z}}/N{\mathbb{Z}})^* \rightarrow R^*$ factors through $({\mathbb{Z}}/M{\mathbb{Z}})^*$ via the natural map $({\mathbb{Z}}/N{\mathbb{Z}})^*\rightarrow ({\mathbb{Z}}/M{\mathbb{Z}})^*$.

## Creation

<a id="function-dirichletgroup-rngintelt"></a>
### `DirichletGroup(N): RngIntElt -> GrpDrch`

The group of Dirichlet characters modulo $N$ with values in `RationalField()`. (Note that this is a group of exponent at most $2$.)

<a id="function-fulldirichletgroup-rngintelt"></a>
### `FullDirichletGroup(N): RngIntElt -> GrpDrch`

The group of Dirichlet characters modulo $N$ taking values in the $m$th cyclotomic field, where $m$ is the exponent of the unit group modulo $N$.

<a id="function-dirichletgroup-rngintelt-rng"></a>
### `DirichletGroup(N, R): RngIntElt, Rng -> GrpDrch`

The group of Dirichlet characters modulo $N$ with values in the ring $R$. Here $R$ can be the integers, rationals, a number field, or a finite field. (Note that this group may be smaller than the full Dirichlet group.)

<a id="function-dirichletgroup-rngintelt-rng-rngelt-rngintelt"></a>
### `DirichletGroup(N, R, z, r): RngIntElt, Rng, RngElt, RngIntElt -> GrpDrch`

The group of Dirichlet characters mod $N$ with values in the cyclic subgroup generated by the root of unity $z$ in the ring $R$. Here $z$ must be an element of $R$ of exact order $r$ (where $r$ may be smaller than the exponent of the full Dirichlet group).

<a id="function-baseextend-grpdrch-rng"></a>
### `BaseExtend(G, R): GrpDrch, Rng -> GrpDrch`

<a id="function-baseextend-grpdrch-rng-rngelt"></a>
### `BaseExtend(G, R, z): GrpDrch, Rng, RngElt -> GrpDrch`

The group of Dirichlet characters corresponding to $G$ with values in the ring $R$. In the second form, the distinguished root of unity of the base ring of $G$ is identified with the given element $z$.

<a id="procedure-assignnames-grpdrch-monstgelt-ref"></a>
### `AssignNames(~G, S): GrpDrch, [MonStgElt]`

Assign names to the generators of the Dirichlet group $G$.

## Element Creation

<a id="function-elements-grpdrch"></a>
### `Elements(G): GrpDrch -> [GrpDrchElt]`

A sequence containing all Dirichlet characters in the Dirichlet group $G$.

<a id="function-random-grpdrch"></a>
### `Random(G): GrpDrch -> GrpDrchElt`

A random element of the Dirichlet group $G$.

<a id="operation-operation-grpdrch-rngintelt-grpdrchelt"></a>
### `G . i: GrpDrch, RngIntElt -> GrpDrchElt`

The $i$th generator of the group $G$.

<a id="operation-op-grpdrch-any"></a>
### `G ! x: GrpDrch, Any -> GrpDrchElt`

This coerces the given element $x$ into the Dirichlet group $G$. Here $x$ may be a Dirichlet character belonging to a different group, or a sequence of integers specifying an element of the `AbelianGroup` of $G$.

<a id="function-kroneckercharacter-rngintelt"></a>
### `KroneckerCharacter(D): RngIntElt -> GrpDrchElt`

<a id="function-kroneckercharacter-rngintelt-rng"></a>
### `KroneckerCharacter(D, R): RngIntElt, Rng -> GrpDrchElt`

The Kronecker character $n\mapsto (d/n)$, where $d$ is the fundamental discriminant associated to the integer $D$.

When a ring $R$ is given, this is returned as a character with values in $R$.

## Attributes of Dirichlet Groups

<a id="function-basering-grpdrch"></a>
### `BaseRing(G): GrpDrch -> Rng`

The ring in which characters in $G$ take values.

<a id="function-modulus-grpdrch"></a>
### `Modulus(G): GrpDrch -> RngIntElt`

The integer $N$ such that G is a group of Dirichlet characters on ${\mathbb{Z}}/N$.

<a id="function-order-grpdrch"></a>
### `Order(G): GrpDrch -> RngIntElt`

The order of the Dirichlet group $G$.

<a id="function-exponent-grpdrch"></a>
### `Exponent(G): GrpDrch -> RngIntElt`

The exponent of the Dirichlet group $G$.

<a id="function-numberofgenerators-grpdrch"></a>
### `NumberOfGenerators(G): GrpDrch -> RngIntElt`

The number of generators of the Dirichlet group $G$.

<a id="function-generators-grpdrch"></a>
### `Generators(G): GrpDrch -> [GrpDrchElt]`

A sequence containing generators for the Dirichlet group $G$.

<a id="function-unitgenerators-grpdrch"></a>
### `UnitGenerators(G): GrpDrch -> [RngIntElt]`

This returns an ordered sequence of integers that reduce to “canonical” generators of the unit group of $Z/N$, where $N$ is the modulus of G.

<a id="function-galoisconjugacyrepresentatives-grpdrch"></a>
### `GaloisConjugacyRepresentatives(G): GrpDrch -> [GrpDrchElt]`

<a id="function-galoisconjugacyrepresentatives-grpdrchelt"></a>
### `GaloisConjugacyRepresentatives(seq): [GrpDrchElt] -> [GrpDrchElt]`

This returns a sequence containing one representative from each Galois conjugacy class (over ${\mathbb{Q}}$) of characters corresponding to a character in the given group or the given sequence.

<a id="function-abeliangroup-grpdrch"></a>
### `AbelianGroup(G): GrpDrch -> GrpAb, Map`

This returns a finite abelian group isomorphic to the given group $G$ of Dirichlet characters (as an abstract group), and secondly returns a map from the abstract group to $G$.

It is necessary to use this function in order to make group theoretic constructions involving $G$.

## Attributes of Elements

<a id="function-basering-grpdrchelt"></a>
### `BaseRing(chi): GrpDrchElt -> Rng`

The ring in which the Dirichlet character $\chi$ takes values.

<a id="function-modulus-grpdrchelt"></a>
### `Modulus(chi): GrpDrchElt -> RngIntElt`

The modulus of the group of Dirichlet characters that contains $\chi$.

<a id="function-conductor-grpdrchelt"></a>
### `Conductor(chi): GrpDrchElt -> RngIntElt`

The minimal conductor of the Dirichlet character $\chi$. (That is, the smallest integer $M$ such that `chi` is well-defined on the unit group of $Z/M$.)

<a id="function-elementtosequence-grpdrchelt"></a>
### `ElementToSequence(chi): GrpDrchElt -> SeqEnum`

A sequence of integers specifying the Dirichlet character $\chi$ (in terms of generators of the group containing $\chi$).

<a id="operation-op-eq-grpdrchelt-grpdrchelt"></a>
### `x eq y: GrpDrchElt, GrpDrchElt -> BoolElt`

Return `true` iff the given characters have the same modulus and values.

<a id="function-order-grpdrchelt"></a>
### `Order(chi): GrpDrchElt -> RngIntElt`

The order of the given element $\chi$ in a group of Dirichlet characters.

<a id="function-istrivial-grpdrchelt"></a>
### `IsTrivial(chi): GrpDrchElt -> BoolElt`

Returns `true` if and only if the Dirichlet character $\chi$ has order $1$.

<a id="function-isprimitive-grpdrchelt"></a>
### `IsPrimitive(chi): GrpDrchElt -> BoolElt`

Returns `true` iff the Dirichlet character $\chi$ is primitive (equivalently, if its conductor equals its modulus).

<a id="function-associatedprimitivecharacter-grpdrchelt"></a>
### `AssociatedPrimitiveCharacter(chi): GrpDrchElt -> GrpDrchElt`

The primitive character modulo the conductor of $\chi$ which takes the same values (on units) as $\chi$.

<a id="function-iseven-grpdrchelt"></a>
### `IsEven(chi): GrpDrchElt -> BoolElt`

Returns `true` if and only if `Evaluate(chi,-1)` is equal to $1$. Note that in characteristic $0$, the space of modular forms of weight $k$ and character $\chi$ is zero if $\chi$ is even and $k$ is odd.

<a id="function-isodd-grpdrchelt"></a>
### `IsOdd(chi): GrpDrchElt -> BoolElt`

Returns `true` if and only if `Evaluate(chi,-1)` is equal to $-1$. Note that in characteristic $0$, the space of modular forms of weight $k$ and character $\chi$ is zero if $\chi$ is odd and $k$ is even.

<a id="function-istotallyeven-grpdrchelt"></a>
### `IsTotallyEven(chi): GrpDrchElt -> BoolElt`

For a Dirichlet character $\chi$, this is `true` if and only if every character in the `Decomposition` of $\chi$ (into prime power components) is even.

<a id="function-decomposition-grpdrchelt"></a>
### `Decomposition(chi): GrpDrchElt -> List`

This decomposes the Dirichlet character $\chi$ as a product of characters with prime power moduli. The function returns a list (not a sequence) containing these characters (which do not belong to the same group).

<a id="function-minimalbaseringcharacter-grpdrchelt"></a>
### `MinimalBaseRingCharacter(chi): GrpDrchElt -> GrpDrchElt`

This returns a character which is the same as $\chi$, except which takes values in the smallest possible subring of the base ring of $\chi$.

## Evaluation

<a id="function-evaluate-grpdrchelt-rngintelt"></a>
### `Evaluate(chi, n): GrpDrchElt, RngIntElt -> RngElt`

<a id="function-chi-grpdrchelt-rngintelt"></a>
### `chi(n): GrpDrchElt, RngIntElt -> RngElt`

The value of the Dirichlet character $\chi$ at the integer $n$.

<a id="function-valuelist-grpdrchelt"></a>
### `ValueList(chi): GrpDrchElt -> [RngElt]`

A sequence containing the values $[\chi(1),..,\chi(N)]$ of the given character $\chi$, where $N$ is the modulus of $\chi$.

The list of values is stored; then in later calls to `Evaluate`, the stored value is returned.

<a id="function-valuesonunitgenerators-grpdrchelt"></a>
### `ValuesOnUnitGenerators(chi): GrpDrchElt -> [RngElt]`

A sequence containing the values of $\chi$ on the ordered sequence of elements of ${\mathbb{Z}}/m$ given by `UnitGenerators(Parent(chi))`, where $m$ is the modulus of $\chi$.

<a id="function-orderofrootofunity-rngelt-rngintelt"></a>
### `OrderOfRootOfUnity(r, n): RngElt, RngIntElt -> RngIntElt`

Given an element $r$ of some ring which is *assumed* to satisfy $r^n = 1$, this returns the smallest integer $m$ such that $r^m = 1$.

(This provides a convenient way to calculate the order of values of non-real characters.)

## Arithmetic

<a id="operation-op-times-grpdrchelt-grpdrchelt"></a>
### `x * y: GrpDrchElt, GrpDrchElt -> GrpDrchElt`

<a id="operation-op-div-grpdrchelt-grpdrchelt"></a>
### `x / y: GrpDrchElt, GrpDrchElt -> GrpDrchElt`

The product or quotient (respectively) of the Dirichlet characters $x$ and $y$. This is a Dirichlet character of modulus equal to the least common multiple of the moduli of $x$ and $y$. The base rings and chosen roots of unity of the parents of $x$ and $y$ are equal.

<a id="operation-op-pow-grpdrchelt-rngintelt"></a>
### `x ^ n: GrpDrchElt, RngIntElt -> GrpDrchElt`

The Dirichlet character $x$ raised to the power of $n$, where $n$ is any integer.

<a id="operation-op-pow-grpdrchelt-map"></a>
### `x ^ phi: GrpDrchElt, Map -> GrpDrchElt`

The image of the Dirichlet character $x$ under the automorphism $\phi$.

<a id="function-sqrt-grpdrchelt"></a>
### `Sqrt(x): GrpDrchElt -> GrpDrchElt`

Given a Dirichlet character $x$ of odd order, this returns a square root of $x$ (in the same group).

## Example

<a id="example-ex-19f11f"></a>
### `Example: Dirichlet Characters Modulo 5 (ex-19f11f)`

We begin by constructing the group of characters $({\mathbb{Z}}/5{\mathbb{Z}})^*\rightarrow{\mathbb{Q}}^*$.

```magma
> G<a> := DirichletGroup(5);  G;  // The default base field is Q.
Group of Dirichlet characters of modulus 5 over Rational Field
> #G;
2
> [Evaluate(a, n) : n in [1..5]];
[ 1, -1, -1, 1, 0 ]
> Eltseq(a);
[ 2 ]
> a eq G![2];
true
> IsEven(a);
true
> IsOdd(a);
false
> IsTrivial(a);
false
```

Next we create a character by building it up “locally”.

```magma
> G1<a4> := DirichletGroup(4);
> Conductor(a4);
4
> G2<a5> := DirichletGroup(25);
> Conductor(a5);
5
> eps := a4*a5;
> Modulus(eps);
100
> Conductor(eps);
20
> Evaluate(eps,7) eq Evaluate(a4,7)*Evaluate(a5,7);
true
```

Characters can be constructed over various fields.

```magma
> G<a> := DirichletGroup(7,GF(7));
> #G;
6
> Evaluate(a,2);
2
>
> G<a3,a5> := DirichletGroup(15,CyclotomicField(EulerPhi(15)));
> G;
Group of Dirichlet characters of modulus 15 over Cyclotomic Field of
order 8 and degree 4
> #G;
8
> Conductor(a3);
3
> Conductor(a5);
5
> Order(a5);
4
> Evaluate(a5,2);
zeta_8^2
```

If $D$ is a fundamental discriminant, then `KroneckerCharacter(D)` is the quadratic Dirichlet character corresponding to the quadratic field ${\mathbb{Q}}(\sqrt{D})$. The following code verifies that `KroneckerCharacter` and `KroneckerSymbol` agree in the case $D=209$.

```magma
> chi := KroneckerCharacter(209);
> for n in [1..209] do
>    assert Evaluate(chi,n) eq KroneckerSymbol(209,n);
> end for;
```

If $E$ is an elliptic curve with newform $f_E$, then the twist $E_D$ corresponds to $f_E$ twisted by this character, as illustrated below.

```magma
> E := EllipticCurve(CremonaDatabase(),"11A");
> f := qEigenform(E,8); f;
q - 2*q^2 - q^3 + 2*q^4 + q^5 + 2*q^6 - 2*q^7 + O(q^8)
> chi := KroneckerCharacter(-7);
> qEigenform(QuadraticTwist(E,-7),8);
q - 2*q^2 + q^3 + 2*q^4 - q^5 - 2*q^6 + O(q^8)
> R<q> := Parent(f);
> &+[Evaluate(chi,n)*Coefficient(f,n)*q^n : n in [1..7]] + O(q^8);
q - 2*q^2 + q^3 + 2*q^4 - q^5 - 2*q^6 + O(q^8)
```
