yap-examples-0.1: examples of the algebraic classes in the yap package
Copyright(c) Ross Paterson 2021
LicenseBSD-style (see the file LICENSE)
MaintainerR.Paterson@city.ac.uk
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Data.YAP.DirichletSeries

Description

An example instance of the algebraic classes: formal Dirichlet series.

Synopsis

Formal Dirichlet series

data DirichletSeries a Source #

Formal Dirichlet series: \[ f(s) = \sum_{n=1}^\infty {a_n \over n^s} \]

The series can be viewed as the Dirichlet generating function of the sequence \( \{a_n\} \) for some arithmetic function \(a\) of positive integers \(n\).

  • The arithmetic function \(a\) is multiplicative if \( a_{mn} = a_m a_n \) when \( (m,n) = 1 \). This property is preserved by multiplication.
  • The arithmetic function \(a\) is completely multiplicative if \( a_{mn} = a_m a_n \) for all \(m,n\).

Instances

Instances details
AdditiveFunctor DirichletSeries Source # 
Instance details

Defined in Data.YAP.DirichletSeries

Floating a => Differentiable (DirichletSeries a) Source #

multiplies the \(n\)th coefficient by \( - \log n \)

Instance details

Defined in Data.YAP.DirichletSeries

Floating a => Integrable (DirichletSeries a) Source #

divides the \(n\)th coefficient by \( - \log n \)

Instance details

Defined in Data.YAP.DirichletSeries

AbelianGroup a => AbelianGroup (DirichletSeries a) Source #

pointwise subtraction of coefficients

Instance details

Defined in Data.YAP.DirichletSeries

AdditiveMonoid a => AdditiveMonoid (DirichletSeries a) Source #

pointwise addition of coefficients

Instance details

Defined in Data.YAP.DirichletSeries

FromRational a => FromRational (DirichletSeries a) Source # 
Instance details

Defined in Data.YAP.DirichletSeries

Ring a => Ring (DirichletSeries a) Source # 
Instance details

Defined in Data.YAP.DirichletSeries

Semiring a => Semiring (DirichletSeries a) Source #

Multiplication is Dirichlet convolution (commutative).

Instance details

Defined in Data.YAP.DirichletSeries

constant :: AdditiveMonoid a => a -> DirichletSeries a Source #

Constant series: all coefficients after the first are zero.

fromCoefficients :: AdditiveMonoid a => [a] -> DirichletSeries a Source #

Dirichlet series formed from a list of coefficients. If the list is finite, the remaining coefficients are zero.

Queries

coefficients :: AdditiveMonoid a => DirichletSeries a -> [a] Source #

The infinite list of coefficients of the Dirichlet series.

approximations :: Floating a => DirichletSeries a -> a -> [a] Source #

The infinite list of evaluations of truncations of the series.

Division

reciprocal :: Field a => DirichletSeries a -> DirichletSeries a Source #

Reciprocal of a Dirichlet series whose first coefficient is non-zero.

recipSimple :: Ring a => DirichletSeries a -> DirichletSeries a Source #

Reciprocal of a Dirichlet series whose first coefficient is 1. This includes any series that generates a multiplicative function, in which case the reciprocal also generates a multiplicative function.

divSimple :: Ring a => DirichletSeries a -> DirichletSeries a -> DirichletSeries a infixl 7 Source #

Division by a Dirichlet series whose first coefficient is 1.

Series with integral coefficients

mulInt :: AbelianGroup a => DirichletSeries a -> DirichletSeries Int -> DirichletSeries a Source #

A special case of (*) where the second series has integral coefficients.

divSimpleInt :: AbelianGroup a => DirichletSeries a -> DirichletSeries Int -> DirichletSeries a Source #

A special case of divSimple where the second series has integral coefficients.

Special compositions

(.-) :: AdditiveMonoid a => DirichletSeries a -> Int -> DirichletSeries a infixl 9 Source #

Maps a function \(f(s)\) to \(f(s - k)\) for non-negative \(k\), by multiplying the \(n\)th coefficient by \(n^k\).

If \(f(s)\) generates a (completely) multiplicative function, so does \(f(s - k)\).

Example

Expand

zeta .- k produces the series whose coefficients are kth powers:

>>> coefficients $ zeta .- 1
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,...
>>> coefficients $ zeta .- 2
[1,4,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,...

(.*) :: AdditiveMonoid a => DirichletSeries a -> Int -> DirichletSeries a infixl 9 Source #

Maps a function \(f(s)\) to \(f(k s)\) for positive \(k\), by moving the \(n\)th coefficient to position \(n^k\), with zeros in between.

If \(f(s)\) generates a multiplicative function, so does \(f(k s)\).

Example

Expand

zeta .* k produces the series whose coefficients are 1 if n is an exact kth power and 0 otherwise:

>>> coefficients $ zeta .* 2
[1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,...
>>> coefficients $ zeta .* 3
[1,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,...

Special series

Generating multiplicative functions

zeta :: Semiring a => DirichletSeries a Source #

Riemann zeta function: \[ \zeta(s) = \sum_{n=1}^\infty {1 \over n^s} \] All coefficients are 1, and thus trivially completely multiplicative.

beta :: Ring a => DirichletSeries a Source #

The Dirichlet \(\beta\) function, with coefficients \(1, 0, -1, 0, 1, 0, -1, 0, \ldots\), is completely multiplicative. It is equal to lSeries primitive4.

Generating characteristic functions

primeZeta :: Semiring a => DirichletSeries a Source #

The prime zeta function, whose the \(n\)th coefficient is 1 if \(n\) is prime and 0 otherwise (OEIS A010051). The arithmetic function is not multiplicative.

primePowerZeta :: Semiring a => DirichletSeries a Source #

The prime power zeta function, whose the \(n\)th coefficient is 1 if \(n = p^k\) for prime \(p\) and positive \(k\) and 0 otherwise (OEIS A069513). The arithmetic function is not multiplicative.

Polylogarithms

polylogarithm :: Semiring a => a -> DirichletSeries a Source #

The polylogarithm function \[ Li_s(z) = \sum_{n=1}^\infty {z^n \over n^s} \] applied to a given value of \(z\). Some special cases:

  • \( Li_s(1) = \zeta(s) \)
  • \( Li_s(- 1) = - \eta(s) \) where \(\eta\) is the Dirichlet eta function

Dirichlet characters

newtype Character a Source #

A Dirichlet character of modulus n is a completely multiplicative function from integers that repeats with period n and is equal to 0 if and only if the argument is not coprime with n. Because it is periodic, we can represent a Dirichlet character as a list of the values for 1 to n.

Constructors

Character [a] 

Instances

Instances details
Semiring a => Monoid (Character a) Source #

The identity is the unique Dirichlet character of modulus 1.

Instance details

Defined in Data.YAP.DirichletSeries

Semiring a => Semigroup (Character a) Source #

Pointwise multiplication of Dirichlet characters of moduli m and n, yielding a character of modulus m*n.

Instance details

Defined in Data.YAP.DirichletSeries

Methods

(<>) :: Character a -> Character a -> Character a #

sconcat :: NonEmpty (Character a) -> Character a #

stimes :: Integral b => b -> Character a -> Character a #

Show a => Show (Character a) Source # 
Instance details

Defined in Data.YAP.DirichletSeries

Eq a => Eq (Character a) Source # 
Instance details

Defined in Data.YAP.DirichletSeries

Methods

(==) :: Character a -> Character a -> Bool #

(/=) :: Character a -> Character a -> Bool #

Ord a => Ord (Character a) Source # 
Instance details

Defined in Data.YAP.DirichletSeries

modulus :: Character a -> Int Source #

The modulus of a Dirichlet character

multCharacter :: Int -> Character a -> Character a Source #

Make a new Dirichlet character with modulus n times as large defining the same function of the integers. A non-principal Dirichlet character is called primitive if it is not such a repetition of a Dirichlet character with a smaller modulus.

lSeries :: AdditiveMonoid a => Character a -> DirichletSeries a Source #

The Dirichlet L-series for a Dirichlet character \(\chi\) is \[ L(s,\chi) = \sum_{n=1}^\infty \frac{\chi(n)}{n^s} \]

Particular real Dirichlet characters

principal :: Semiring a => Int -> Character a Source #

The principal character of modulus n, taking the value 1 for numbers coprime with n and 0 otherwise.

primePrincipal :: Semiring a => Int -> Character a Source #

A simpler implementation of the principal character, assuming that the parameter is prime.

legendreSymbol :: Ring a => Int -> Character a Source #

Given an odd prime \(p\), the Legendre symbol \((n|p)\) defines the unique quadratic Dirichlet character of modulus \(p\) (and also a primitive character): for non-zero \(n\), 1 if \(n\) is a quadratic residue of \(p\) and -1 otherwise.

primitive4 :: Ring a => Character a Source #

The unique primitive character of modulus 4

primitive8s :: Ring a => [Character a] Source #

The two primitive characters of modulus 8

Bell series and Euler product

A multiplicative arithmetic function (which can be generated by a Dirichlet series) is determined by its values on powers of primes. These values can be represented by a family of power series, each with constant term 1, for each prime (the Bell series of the arithmetic function). The Dirichlet series of the multiplicative function can be conveniently constructed using the Euler product of this family of power series.

bellSeries :: AdditiveMonoid a => DirichletSeries a -> Int -> PowerSeries a Source #

The Bell series modulo \(p\) (usually assumed to be prime) of an arithmetic function \( a_n \) is the formal power series

\[ g_p(x) = a_1 + a_p x + a_{p^2} x^2 + \cdots \]

If the arithmetic function \(a\) is multiplicative, then \(a_1 = 1\). If it is completely multiplicative (and \(p\) is prime), then \(a_{p^k} = a_p^k\), so that the series simplifies to

\[ g_p(x) = {1 \over 1 - {a_p x}} \]

eulerProduct :: (Eq a, Semiring a) => (Int -> PowerSeries a) -> DirichletSeries a Source #

If \(g_p\) is a family of power series for each prime \(p\), such that each constant term is 1, then the Euler product

\[ f(s) = \prod_{p\text{ prime}} g_p({1 \over p^s}) \]

yields a Dirichlet series generating a multiplicative function.

If \(g_p\) is the Bell series of a multiplicative function \(a\), then \(f\) is the Dirichlet generating function of \(a\):

\[ f(s) = \prod_{p\text{ prime}} g_p({1 \over p^s}) = \prod_{p\text{ prime}} \left( 1 + {a_p \over p^s} + {a_{p^2} \over p^{2s}} + {a_{p^3} \over p^{3s}} + \cdots \right) = \sum_{n=1}^\infty {a_n \over n^s} \]

Thus eulerProduct and bellSeries define an isomorphism between Dirichlet series generating multiplicative functions and prime-indexed families of power series with constant term 1.

This isomorphism preserves multiplication (but not addition):

one = eulerProduct $ \ p -> one
eulerProduct g * eulerProduct h = eulerProduct $ \ p -> g p * h p

The Euler product also satisfies:

eulerProduct g .* k = eulerProduct $ \ p -> g p .^ k
eulerProduct g .- k = eulerProduct $ \ p -> g p .* p^k

Examples

See also

Dirichlet series generating multiplicative functions can also be expressed as products of Bell series. For convenience, define:

>>> import qualified Data.YAP.PowerSeries as PS
>>> let x = PS.identity

Sum-of-divisors transform

Multiplication of zeta with a Dirichlet series with coefficients \( \{b_n\} \) yields a series with coefficients

\[ a_n = \sum_{d \mid n} b_d \]

The same transformation on sequences from ordinary generating functions is performed by lambertTransform.

As the zeta function is completely multiplicative, it can be expressed as the product of the Bell series \( g_p(x) = {1 \over 1 - x} \):

>>> coefficients $ eulerProduct $ const $ PS.recipSimple (1-x)
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,...

The number of divisors of \(n\), i.e. \(\tau(n)\), \(d(n)\) or \(\sigma_0(n)\) (OEIS A000005) is generated by \( \zeta^2(s) \), the Euler product of the Bell series \( g_p(x) = {1 \over (1-x)^2} \):

>>> coefficients $ zeta^2
[1,2,2,3,2,4,2,4,3,4,2,6,2,4,4,5,2,6,2,6,...
>>> coefficients $ eulerProduct $ const $ PS.recipSimple ((1-x)^2)
[1,2,2,3,2,4,2,4,3,4,2,6,2,4,4,5,2,6,2,6,...

In general, zeta^k is the number of factorizations of \(n\) as \(k\) factors.

The sum of the divisors of \(n\), i.e. \(\sigma(n)\) (OEIS A000203) is generated by \( \zeta(s)\zeta(s-1) \), the Euler product of the Bell series \( g_p(x) = {1 \over (1-x)(1-px)} \):

>>> coefficients $ zeta*(zeta .- 1)
[1,3,4,7,6,12,8,15,13,18,12,28,14,24,24,31,18,39,20,42,...
>>> coefficients $ eulerProduct $ \ p -> PS.recipSimple ((1-x)*(1 - atimes p x))
[1,3,4,7,6,12,8,15,13,18,12,28,14,24,24,31,18,39,20,42,...

The sum of squares of the divisors of \(n\), i.e. \(\sigma_2(n)\) (OEIS A001157) is generated by \( \zeta(s)\zeta(s-2) \), the Euler product of the Bell series \( g_p(x) = {1 \over (1-x)(1-p^2 x)} \):

>>> coefficients $ zeta*(zeta .- 2)
[1,5,10,21,26,50,50,85,91,130,122,210,170,250,260,341,290,455,362,546,...
>>> coefficients $ eulerProduct $ \ p -> PS.recipSimple ((1-x)*(1 - atimes (p^2) x))
[1,5,10,21,26,50,50,85,91,130,122,210,170,250,260,341,290,455,362,546,...

and so on for the divisor function \(\sigma_k(n) = \sum_{d \mid n} d^k\) for any power \(k\).

The number of ways of writing \(n\) as the sum of at most two nonzero squares (OEIS A002654):

>>> coefficients $ zeta*beta
[1,1,0,1,2,0,0,1,1,2,0,0,2,0,0,1,2,1,0,2,...

In the special case where \(\{b_n\}\) is a characteristic sequence of some property (consisting of 0s and 1s), \(a_n\) is the number of divisors of \(n\) having that property.

The number of distinct prime divisors of \(n\), i.e. \(\omega(n)\) (OEIS A001221):

>>> coefficients $ zeta*primeZeta
[0,1,1,1,1,2,1,1,1,2,1,2,1,2,2,1,1,2,1,2,...

The number of prime divisors of \(n\) counted with multiplicity, i.e. \(\Omega(n)\) (OEIS A001222):

>>> coefficients $ zeta*primePowerZeta
[0,1,1,2,1,2,1,3,2,2,1,3,1,2,2,4,1,3,1,3,...

Möbius transform

The zeta function has a multiplicative inverse, whose coefficients are given by the Möbius function \( \mu(n) \) (OEIS A008683):

  • 0 if \(n\) is divisible by the square of a prime, and otherwise
  • 1 if \(n\) has an even number of prime factors, or
  • \(-1\) if \(n\) has an odd number of prime factors.
>>> coefficients $ recipSimple zeta
[1,-1,-1,0,-1,1,-1,0,0,1,-1,0,-1,1,1,0,-1,0,-1,0,...

Thus division by zeta performs the inverse of the sum-of-divisors transform, i.e. the Möbius transform. The same transformation on sequences from ordinary generating functions is performed by inverseLambertTransform.

The Möbius function is multiplicative (but not completely multiplicative), and expressed by the product of the reciprocal Bell series \( g_p(x) = 1 - x \):

>>> coefficients $ eulerProduct $ const $ 1-x
[1,-1,-1,0,-1,1,-1,0,0,1,-1,0,-1,1,1,0,-1,0,-1,0,...

The number of numbers less than \(n\) and coprime with \(n\) (OEIS A000010) is the Euler totient function \( \varphi(n) \), which satisfies

\[ \sum_{d \mid n}\varphi(d) = n \]

i.e. phi*zeta = zeta .- 1. Hence the generating function for phi can be obtained by dividing the righthand side of this equation by zeta (Möbius inversion), i.e. \( {\zeta(s-1) \over \zeta(s)} \), the Euler product of the Bell series \( g_p(x) = {1-x \over 1-px} \):

>>> coefficients $ zeta .- 1 `divSimple` zeta
[1,1,2,2,4,2,6,4,6,4,10,4,12,6,8,8,16,6,18,8,...
>>> coefficients $ eulerProduct $ \ p -> (1-x) `PS.divSimple` (1 - atimes p x)
[1,1,2,2,4,2,6,4,6,4,10,4,12,6,8,8,16,6,18,8,...

The generalization from 1 to arbitrary \(k\) is the Jordan totient function \(J_k(n)\), which satisfies

\[ \sum_{d \mid n} J_k(d) = n^k \]

The Liouville function \( \lambda(n) = (-1)^{\Omega(n)} \) (OEIS A008836) has the property that \( \sum_{d|n}\lambda(d) \) is 1 if \(n\) is a perfect square and 0 otherwise, i.e. liouville*zeta = zeta .* 2. Hence the Liouville function can be obtained by dividing the righthand side of this equation by zeta, i.e. \( {\zeta(2s) \over \zeta(s)} \), the Euler product of the Bell series \( g_p(x) = {1-x \over 1-x^2} = {1 \over 1+x} \):

>>> coefficients $ zeta .* 2 `divSimple` zeta
[1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,1,1,1,-1,-1,-1,-1,...
>>> coefficients $ eulerProduct $ const $ PS.recipSimple $ 1+x
[1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,-1,1,1,1,-1,-1,-1,-1,...

The von Mangoldt function \( \Lambda(n) \) (log of OEIS A014963):

  • \( \log p \) if \(n=p^k\) for prime \(p\) and positive integer \(k\)
  • 0 otherwise

This function satisfies

\[ \sum_{d \mid n} \Lambda(d) = \log~n \]

so its Dirichlet generating function \( - {\zeta'(s) \over \zeta(s)} \) can be obtained by Möbius inversion:

>>> coefficients $ - derivative zeta `divSimple` zeta
[0.0,0.6931472,1.0986123,0.6931472,1.609438,-0.0,1.9459101,0.6931472,...

If \(a(n)\) is the number of aperiodic binary strings of length \(n\) (OEIS A027375), then \( 2^n = \sum_{d \mid n} a(n) \), so \(a(n)\) can be obtained by Möbius inversion of the sequence of powers of 2:

>>> coefficients $ polylogarithm 2 `divSimple` zeta
[2,2,6,12,30,54,126,240,504,990,2046,4020,8190,16254,...

More integer sequences

The reciprocal of the series generating the Liouville function generates \(\mu(n)^2\), which is 1 if \(n\) is squarefree, and otherwise 0 (OEIS A008966). Its generating function is \( {\zeta(s) \over \zeta(2s)} \), the Euler product of the Bell series \( g_p(x) = {1-x^2 \over 1-x} = 1+x \):

>>> coefficients $ zeta `divSimple` zeta .* 2
[1,1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,1,0,1,0,...
>>> coefficients $ eulerProduct $ const $ 1+x
[1,1,1,0,1,1,1,0,0,1,1,0,1,1,1,0,1,0,1,0,...

Applying the sum-of-divisors transform to that, by multiplying by zeta, yields a series generating the number of squarefree divisors of \(n\), or equivalently the number of divisors of \(n\) that are coprime with the complementary divisor, i.e. \( \theta(n) = 2^{\omega(n)}\) (OEIS A034444). Its generating function is \( {\zeta^2(s) \over \zeta(2s)} \), the Euler product of the Bell series \( g_p(x) = {1 - x^2 \over (1-x)^2} = {1+x \over 1-x} \):

>>> coefficients $ zeta^2 `divSimple` zeta .* 2
[1,2,2,2,2,4,2,2,2,4,2,4,2,4,4,2,2,4,2,4,...
>>> coefficients $ eulerProduct $ const $ (1+x) `PS.divSimple` (1-x)
[1,2,2,2,2,4,2,2,2,4,2,4,2,4,4,2,2,4,2,4,...

The Dedekind \(\psi\) function (OEIS A001615) has generating function \( {\zeta(s)\zeta(s-1) \over \zeta(2s)} \), the Euler product of the Bell series \( g_p(x) = {1-x^2 \over (1-x)(1-px)} = {1+x \over 1-px} \):

>>> coefficients $ zeta*(zeta .- 1) `divSimple` zeta .* 2
[1,3,4,6,6,12,8,12,12,18,12,24,14,24,24,24,18,36,20,36,...
>>> coefficients $ eulerProduct $ \ p -> (1+x) `PS.divSimple` (1 - atimes p x)
[1,3,4,6,6,12,8,12,12,18,12,24,14,24,24,24,18,36,20,36,...

The squarefree part of \(n\) (OEIS A007913) has generating function \( {\zeta(s-1)\zeta(2s) \over \zeta(2s - 2)} \), the Euler product of the Bell series \( g_p(x) = {1 - (p x)^2 \over (1-p x)(1-x^2)} \):

>>> coefficients $ (zeta .- 1)*(zeta .* 2) `divSimple` zeta .- 2 .* 2
[1,2,3,1,5,6,7,2,1,10,11,3,13,14,15,1,17,2,19,5,...
>>> coefficients $ eulerProduct $ \ p -> (1 - atimes p x^2) `PS.divSimple` ((1-x^2)*(1 - atimes p x))
[1,2,3,1,5,6,7,2,1,10,11,3,13,14,15,1,17,2,19,5,...

The cubefree part of \(n\) (OEIS A050985) has generating function \( {\zeta(s-1)\zeta(3s) \over \zeta(3s - 3)} \), the Euler product of the Bell series \( g_p(x) = {1 - (p x)^3 \over (1-p x)(1-x^3)} \):

>>> coefficients $ (zeta .- 1)*(zeta .* 3) `divSimple` zeta .- 3 .* 3
[1,2,3,4,5,6,7,1,9,10,11,12,13,14,15,2,17,18,19,20,...
>>> coefficients $ eulerProduct $ \ p -> (1 - atimes p x^3) `PS.divSimple` ((1-x^3)*(1 - atimes p x))
[1,2,3,4,5,6,7,1,9,10,11,12,13,14,15,2,17,18,19,20,...

The number of perfect partitions of \(n\) (OEIS A002033) has generating function \( {1 \over 2 -\zeta(s)} \):

>>> coefficients $ recipSimple (2 - zeta)
[1,1,1,2,1,3,1,4,2,3,1,8,1,3,3,8,1,8,1,8,3,3,1,20,2,3,4,8,1,13,...

Enumerating real Dirichlet characters

The number of real Dirichlet characters modulo \(n\) is the number of square roots of unity modulo \(n\) (OEIS A060594), whose series is generated by \((1 - {1 \over 2^s} + {2 \over 4^s}) {\zeta(s)^2 \over \zeta(2s)}\):

>>> coefficients $ fromCoefficients [1, -1, 0, 2] * zeta^2 `divSimple` zeta .* 2
[1,1,2,2,2,2,2,4,2,2,2,4,2,2,4,4,2,2,2,4,4,2,2,8,2,2,2,4,2,4,...

We can list these characters by defining series over the semiring FiniteSet Character using the Euler product.

>>> import Data.YAP.FiniteSet

First, we define a Bell series of principal characters for prime \(p\) as powers of the principal character modulo \(p\):

>>> principals p = PS.recipOneMinus `PS.compose` PS.fromCoefficients [zero, singleton (primePrincipal p)]
>>> PS.coefficients $ principals 3
[fromList [Character [1]],
 fromList [Character [1,1,0]],
 fromList [Character [1,1,0,1,1,0,1,1,0]],
 fromList [Character [1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0,1,1,0]],...

The Euler product of this Bell series yields a series of singleton sets, each containing the principal character of each number \(n\):

>>> coefficients $ eulerProduct principals
[fromList [Character [1]],
 fromList [Character [1,0]],
 fromList [Character [1,1,0]],
 fromList [Character [1,0,1,0]],
 fromList [Character [1,1,1,1,0]],
 fromList [Character [1,0,0,0,1,0]],...

The Bell series of (non-principal) primitive real Dirichlet characters for each prime \(p\) is finite:

>>> primitives p = PS.fromCoefficients $ if p == 2 then [one, zero, singleton primitive4, fromList primitive8s] else [one, fromList [primePrincipal p, legendreSymbol p]]

The Euler product of the product of these two series yields the set of real Dirichlet characters modulo each \(n\):

>>> coefficients $ eulerProduct $ \ p -> principals p * primitives p
[fromList [Character [1]],
 fromList [Character [1,0]],
 fromList [Character [1,-1,0],Character [1,1,0]],
 fromList [Character [1,0,-1,0],Character [1,0,1,0]],
 fromList [Character [1,-1,-1,1,0],Character [1,1,1,1,0]],
 fromList [Character [1,0,0,0,-1,0],Character [1,0,0,0,1,0]],
 fromList [Character [1,1,-1,1,-1,-1,0],Character [1,1,1,1,1,1,0]],
 fromList [Character [1,0,-1,0,-1,0,1,0],Character [1,0,-1,0,1,0,-1,0],Character [1,0,1,0,-1,0,-1,0],Character [1,0,1,0,1,0,1,0]],
 fromList [Character [1,-1,0,1,-1,0,1,-1,0],Character [1,1,0,1,1,0,1,1,0]],
 fromList [Character [1,0,-1,0,0,0,-1,0,1,0],Character [1,0,1,0,0,0,1,0,1,0]],...

Cyclotomic polynomials

The sequence of cyclotomic polynomials \( \Phi_n(x) \) (OEIS A076699) satisfies

\[ x^n - 1 = \prod_{d \mid n} \Phi_d(x) \]

The list of left hand sides can be defined by

>>> import qualified Data.YAP.Polynomial as Poly
>>> let x = Poly.identity
>>> let xnm1s = [xn - 1 | xn <- iterate (*x) x]

Applying the Logarithm adaptor yields a summation:

\[ \log(x^n - 1) = \sum_{d \mid n} \log(\Phi_d(x)) \]

From this, the cyclotomic polynomials can be obtained using Möbius inversion in the field of rational polynomials. The denominators will all be 1, and can be discarded.

>>> import Data.YAP.Logarithm
>>> import Data.YAP.Ratio
>>> map (mapAdditive numerator . numerator . exponential) $ coefficients $ fromCoefficients (map (logarithm . (% 1)) xnm1s) `divSimpleInt` zeta
[fromCoefficients [-1,1],
 fromCoefficients [1,1],
 fromCoefficients [1,1,1],
 fromCoefficients [1,0,1],
 fromCoefficients [1,1,1,1,1],
 fromCoefficients [1,-1,1],
 fromCoefficients [1,1,1,1,1,1,1],...

The numerators are always 0, 1 or -1, and the denominators are always 1.