Maple code for Dedekind zeta function of quadratic number field of discriminant D. N. J. A. Sloane, March 22 2022 The Dedekind zeta function DZ_K(s) for a quadratic field K of discriminant D is as follows. Here m is defined by K = Q(sqrt(m)) (so m=D/4 if D is a multiple of 4, otherwise m=D). DZ_K(s) is the product of three terms: (a) Product_{odd primes p | D} 1/(1-1/p^s) (b) Product_{odd primes p such that (D|p) = -1} 1/(1-1/p^(2s)) (c) Product_{odd primes p such that (D|p) = 1} 1/(1-1/p^s)^2 and if m is 0,1,2,3,4,5,6,7 mod 8, the prime 2 is to be included in the term -,c,a,a,-,b,a,a, respectively. Warning: many web pages give this formula incorrectly. Maple code: # Dirichlet product of Dirichlet generating functions f and g # f and g are represented as Arrays in Maple, # f is [f[1],...,f[Lf]] # g is [g[1],...,g[Lg]] # and you must specify Lf and Lg by hand # The Maple declaration of f and g can have lengths greater than Lf and Lg # Output will be an Array of length min(Lf,Lg) dirmulA:=proc(f,Lf,g,Lg) local fA,gA,ct,a,L,i,n,d; L := min(Lf,Lg); a:=Array(1..L,0); # if f and g were given as lists, convert them to arrays fA:=convert(f,Array); gA:=convert(g,Array); for n from 1 to L do ct:=0; for d from 1 to n do if (n mod d) = 0 then ct:=ct+fA[d]*gA[n/d]; fi; od: # od d a[n]:=ct; od: # od d a; end; # Make a Dirichlet generating function with 1's at powers of p up to length L (p need not be prime) pp:=proc(p,L) local t1,n,i; t1:=Array(1..L,0); n:=1/p; for i from 1 to L do n:=n*p; if n>L then break; fi; t1[n]:=1; od: t1; end; # myDZ Dedekind zeta function for quadratic number field K of discriminant D # where K = Q(sqrt(m)). with(NumberTheory); LS:=LegendreSymbol; myDZ:=proc(D,L) local m,a,t1,t2,i,j,k,p; # we build up the answer in t1 as (the coefficients of) a Dirichlet generating function. # start with the multiplicative unit of Dirichlet gfs t1:=Array(1..L,0); t1[1]:=1; # contribution from odd p | D for p from 3 to abs(D) by 2 do if isprime(p) and (D mod p) = 0 then t2:=pp(p,L); t1:=dirmulA(t1,L,t2,L); fi; od: # contribution from odd p with (D|p)=-1: for p from 3 to L by 2 do if isprime(p) and LS(D,p) = -1 then t2:=pp(p^2,L); t1:=dirmulA(t1,L,t2,L); fi: od: # contribution from odd p with (D|p)= 1: for p from 3 to L by 2 do if isprime(p) and LS(D,p) = 1 then t2:=pp(p,L); t1:=dirmulA(t1,L,t2,L); t1:=dirmulA(t1,L,t2,L); fi: od: # contribution from p = 2 # field is Q(sqrt(m)) if (D mod 4) = 0 then m:=D/4; else m:=D; fi; if (D mod 8) = 1 then t2 := pp(2,L); t1:=dirmulA(t1,L,t2,L); t1:=dirmulA(t1,L,t2,L); elif (D mod 8) = 5 then t2 := pp(4,L); t1:=dirmulA(t1,L,t2,L); else t2:=pp(2,L); t1:=dirmulA(t1,L,t2,L); fi; t1; end; Example: This is for D = -3, A002324: > myDZ(-3,100); [1, 0, 1, 1, 0, 0, 2, 0, 1, 0, 0, 1, 2, 0, 0, 1, 0, 0, 2, 0, 2, 0, 0, 0, 1, 0, 1, 2, 0, 0, 2, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 1, 3, 0, 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 1, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 1, 2, 0, 0, 2, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 4, 0, 2, 0, 0, 0, 2, 0, 0, 1] To confirm this with PARI/GP: D=-3 myfd=nfinit(x^2-D) dirzetak(myfd,100) OEIS ENTRIES: Dedekind zeta functions for imaginary quadratic number fields of discriminants -3, -4, -7, -8, -11, -15, -19, -20 are A002324, A002654, A035182, A002325, A035179, A035175, A035171, A035170, respectively. Dedekind zeta functions for real quadratic number fields of discriminants 5, 8, 12, 13, 17, 21, 24, 28, 29, 33, 37, 40 are A035187, A035185, A035194, A035195, A035203, A035188, A035210, A035211, A035215, A035219, A035192, respectively.