Testing latest pari + WASM + node.js... and it works?! Wow.
License: GPL3
ubuntu2004
rgcd(a,b)=1{2[a,b] = [abs(a), abs(b)];3while (b > 0.01, [a,b] = [b,a%b]);4a;5}67global(nf, km, m, clh, R, areg, re, res, mreg);89f(a,b, nf,v,ind)=10{ my(u, vreg);11my(n = idealnorm(nf, a + b*variable(nf.pol)));12my(mv = vectorv(#v));13forprime (p=2, #ind,14my (l = valuation(n,p));15if (l,16my(cp, j = ind[p]);17n /= p^l; cp = v[j][2];18while((a+b*cp)%p,19j++; cp = v[j][2]20);21mv[j] = l22)23);24if (n!=1, return);25my (r1 = nf.sign[1]);2627/* found a relation */28vreg = vectorv(#re,j,29u = a+b*re[j];30if (j<=r1, abs(u), norm(u))31);32mreg = concat(mreg, log(vreg));33m = concat(m, mv);34areg = concat(areg, a+b*t);35print1("(" res++ ": " a "," b ")");36}3738clareg(pol, plim=19, lima=50, extra=5)=39{ my(coreg,lireg,r1,ind,fa,co,a,b,mh,ms,mhs,mregh);4041nf=nfinit(pol); pol=nf.pol;42re = nf.roots; r1=nf.sign[1];43if (nf.index > 1, /* power basis <==> index = 1 */44error("sorry, the case 'index>1' is not implemented")45);46printf("discriminant = %s, signature = %s\n", nf.disc, nf.sign);4748lireg = sum(i=1,2, nf.sign[i]); /* r1 + r2 */49ind=vector(plim); v=[];50forprime(p=2,plim,51my (w = factormod(pol,p));52my (e = w[,2]);53my (find = 0);54for(l=1,#e,55fa = lift(w[l,1]);56if (poldegree(fa) == 1,57if (!find, find=1; ind[p]=#v+1);58v = concat(v, [[p,-polcoeff(fa,0),e[l]]])59)60)61);62co = #v+extra;63res=0; print("need ", co, " relations");64areg=[]~; mreg = m = [;];65a=1; b=1; f(0,1, nf,v,ind);66while (res<co,67if (gcd(a,b)==1,68f(a,b, nf,v,ind); f(-a,b, nf,v,ind)69);70a++;71if (a*b>lima, b++; a=1)72);73print(" ");74mh=mathnf(m); ms=matsize(mh);75if (ms[1]!=ms[2],76print("not enough relations for class group: matrix size = ",ms);77return78);7980mhs = matsnf(mh,4);81clh = prod(i=1,#mhs, mhs[i]);82printf("class number = %s, class group = %s\n", clh, mhs);83areg=Mat(areg); km=matkerint(m); mregh=mreg*km;84if (lireg==1,85R = 186,87coreg = #mregh;88if (coreg < lireg-1,89print("not enough relations for regulator: matsize = ", matsize(mregh));90R = "(not given)";91,92mreg1 = mregh[1 .. lireg-1, ];93R = 0;94for(j=lireg-1,coreg,95a = matdet(mreg1[, j-lireg+2 .. j]);96R = rgcd(a,R)97)98)99);100print("regulator = " R);101}102103check(lim=200) =104{ my(r1,r2,pol,z,Res,fa);105106[r1,r2] = nf.sign;107pol = nf.pol;108z = 2^r1 * (2*Pi)^r2 / sqrt(abs(nf.disc)) / nfrootsof1(nf)[1];109Res = 1.; \\ Res (Zeta_K,s=1) ~ z * h * R110forprime (q=2,lim,111fa = factormod(pol,q,1)[,1];112Res *= (q-1)/q / prod(i=1, #fa, 1 - q^(-fa[i]))113);114z * clh * R / Res;115}116117fu() = vector(#km, k, factorback(concat(areg, km[,k])));118119120