Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/number_fields/prep.gp
1128 views
1
allocatemem(2^30);
2
default(realprecision,1000);
3
default(new_galois_format, 1);
4
read("generate.gp");
5
6
/* timeouts in seconds */
7
/*shortt = 5;
8
longt = 10;
9
*/
10
shortt = 40;
11
longt = 40;
12
13
savetime=0; /* in milliseconds */
14
15
assoc(entry, lis, bnd=-1) =my(b);b=#lis;if(bnd>-1,b=bnd);for(j=1,b,if(lis[j]==entry,return(j)));return(0);
16
17
/* Needs to be adjusted for higher degree polynomials */
18
galt(pol) = return(polgalois(pol)[3]);
19
galt(pol) = if(poldegree(pol)<8, return(polgalois(pol)[3]), return(galtord(pol)[1]));
20
21
res_degs(nf, p)= return(apply(z->z[4], idealprimedec(nf,p)));
22
23
tors(nf)=
24
{
25
my(rootsof1,gen);
26
rootsof1=nfrootsof1(nf);
27
gen = rootsof1[2];
28
gen = Str(lift(nfbasistoalg(nf,gen)));
29
return([rootsof1[1], gen]);
30
}
31
32
frobs(nf)=
33
{
34
my(D,ans=vector(17),j,dec,vals);
35
D = nf.disc;
36
j=0;
37
forprime(p=2,59,
38
j++;
39
if( (D % p) != 0,
40
dec = res_degs(nf,p);
41
vals = vecsort(mult(dec),[1],4);
42
ans[j] = [p,vals],
43
ans[j] = [p,[0]]);
44
);
45
return(ans);
46
}
47
48
mult(lis) =
49
{
50
my(ans1=[], ans2=[], k);
51
52
for(j=1,length(lis), if((k=assoc(lis[j], ans1)), ans2[k]+=1,
53
ans1=concat(ans1,[lis[j]]);
54
ans2=concat(ans2,[1])));
55
return(vector(length(ans1),h,[ans1[h], ans2[h]]));
56
}
57
58
coeffs(pol) = return(vector(poldegree(pol)+1, h, polcoeff(pol, h-1)));
59
60
getsubs(pol, ramli=[])=
61
{
62
my(sbs);
63
if(#ramli==0, ramli=factor(abs(nfdisc(f)))[,1]~);
64
sbs=nfsubfields(pol);
65
sbs = apply(z->[z[1], poldegree(z[1])], sbs);
66
sbs = vecsort(sbs, [2]);
67
sbs = vector(#sbs-2,h,sbs[h+1]); /* skip Q and the field itself */
68
sbs = apply(z->polredabsx([z[1],ramli]),sbs);
69
sbs = apply(coeffs,sbs);
70
return(mult(sbs));
71
}
72
73
iscm(pol,subs)=
74
{
75
my(deg,s2);
76
deg=poldegree(pol);
77
if(deg % 2 == 1, return(0));
78
if(polsturm(pol) != 0, return(0));
79
if(deg ==2, return(1));
80
subs = apply(z->z[1],subs);
81
subs = apply(Polrev,subs);
82
s2 = select(z->poldegree(z)*2==deg, subs);
83
for(j=1,#s2,
84
if(polsturm(s2[j]) == deg/2, return(1)));
85
return(0);
86
}
87
88
load(p,n)=return(read(Str("/scratch/home/jj/local-fields/file-src/p"p"d"n"all")));
89
90
gpmont(pol,p)=
91
{
92
/* only call if there is a unique prime above p */
93
my(nf,ipd);
94
nf=nfinit([pol,[p]]);
95
ipd = idealprimedec(nf,p)[1];
96
return([ipd.e,ipd.f,valuation(nf.disc, p)]);
97
}
98
99
/* Make a vector with data on the polynomial at p
100
Returns [0,[p,e,f,c]]
101
not [0,[p,e,f,c,n,t,order]] */
102
fake(pol, p)=
103
{
104
if(poldegree(pol)==1, return([0,[p,1,1,0]]));
105
a = gpmont(pol,p);
106
/*a = pmont(pol,p);*/ /* from magma */
107
return([0,concat([p],a)]);
108
}
109
110
newonealg(pol,p)=
111
{
112
my(fp,degs,loc,lpols);
113
if(p>200, /* definitely tame, and not in the db */
114
fp = ef(pol,p);
115
fp = apply(z->[p,z[1],z[2],(z[1]-1)*z[2],z[1]*z[2]], fp);
116
fp = vecsort(fp, [5,2,4]);
117
fp = apply(z->drop(z,-1),fp);
118
lpols = apply(z->[0,z], fp),
119
/* else */
120
fp=lift((factorpadic(pol,p,1000)[,1]~)*Mod(1,p^1000));
121
degs=vecsort(apply(poldegree,fp));
122
lpols=vector(#fp);
123
for(j=1,#fp,
124
loc=iferr(load(p,poldegree(fp[j])),E,0);
125
if(loc==0, lpols[j]=fake(fp[j],p),
126
lpols[j] = findinlistold(fp[j],loc)[1];
127
lpols[j] = [1, Vecrev(lpols[j])])
128
);
129
);
130
return(lpols);
131
}
132
133
onealg(pol,p)=
134
{
135
my(fp,degs,loc,lpols);
136
if(p>200,return([]));
137
fp=lift((factorpadic(pol,p,1000)[,1]~)*Mod(1,p^1000));
138
degs=vecsort(apply(poldegree,fp));
139
lpols=vector(#fp);
140
if(last(degs)>15, return([]));
141
for(j=1,#fp,
142
loc=iferr(load(p,poldegree(fp[j])),E,0);
143
if(loc==0, return([]);lpols[j]=fake(fp[j],p),
144
lpols[j]=findinlistold(fp[j],loc)[1]);
145
);
146
return(vector(#lpols,h,Str(lpols[h])));
147
}
148
149
150
doit(pol)=
151
{
152
my(nf,bnf=0,elapsed=0,nogrh=0,h=-1,clgp=[],reg=0,fu="",extras=0,subs,zk);
153
my(localg,rmps);
154
nf=nfinit(pol);
155
zk=nfbasis(pol);
156
subs = getsubs(nf);
157
a='a;
158
zk=subst(zk,x,a);
159
zk=apply(z->Str(z), zk);
160
rmps=factor(abs(nf.disc))[,1]~;
161
gettime();
162
iferr(alarm(shortt,bnf=bnfinit(nf,1)),E,1);
163
if(bnf,
164
alarm(longt, iferr(if(bnfcertify(bnf)==0,1/0,nogrh=1), E,1));
165
elapsed = gettime();
166
h= bnf.clgp[1];
167
clgp=bnf.clgp[2];
168
if(elapsed>savetime,
169
reg = bnf.reg;
170
fu = lift(bnf.fu);
171
fu = subst(fu,x,a);
172
fu = apply(z->Str(z), fu);
173
extras=1;
174
);
175
);
176
localg = apply(z->onealg(pol,z), rmps);
177
return([Vecrev(pol), galt(pol), nf.disc, nf.r1,h,clgp,extras,reg,fu,nogrh,subs,1,zk,rmps,localg,iscm(pol,subs)]);
178
/* reg and units if slow */
179
/* grh if certify is too slow */
180
}
181
182
doit1(ll)=
183
{
184
my(pol=ll[1],rmps=Set(ll[2]),nf,bnf=0,elapsed=0,nogrh=0,h=-1,clgp=[],reg=0,fu="",extras=0,subs,zk,ramli,thisgalt,tordata,ginf);
185
ramli=getramli(ll);
186
pol=polredabsx(ll);
187
my(pd=poldisc(pol), nps);
188
a='a;
189
nf=nfinit([pol,ramli]);
190
if(#nfcertify(nf)>0, error("Did not certify number field"));
191
zk=nfbasis([pol,ramli]);
192
rmps = vecsort(select(z->valuation(nf.disc,z)>0,ramli));
193
subs = getsubs(nf, ramli);
194
zk=subst(zk,x,a);
195
zk=apply(z->Str(z), zk);
196
gettime();
197
iferr(alarm(shortt,bnf=bnfinit(nf,1)),E,1);
198
if(bnf,
199
alarm(longt, iferr(if(bnfcertify(bnf)==0,1/0,nogrh=1), E,1));
200
elapsed = gettime();
201
h= bnf.clgp[1];
202
clgp=bnf.clgp[2];
203
if(elapsed>savetime,
204
reg = bnf.reg;
205
fu = lift(bnf.fu);
206
fu = subst(fu,x,a);
207
fu = apply(z->Str(z), fu);
208
extras=1;
209
);
210
);
211
localg = apply(z->onealg(pol,z), rmps);
212
thisgalt=galt(pol);
213
tordata= tors(nf);
214
false=0; true=1;
215
ginf= ginfo(poldegree(pol), thisgalt);
216
return([Vecrev(pol), thisgalt, nf.disc, nf.r1,h,clgp,extras,reg,fu,nogrh,subs,1,zk,rmps, localg,iscm(pol,subs),frobs(nf),tordata[1],tordata[2],ginf]);
217
/* reg and units if slow */
218
/* grh if certify is too slow */
219
/* tordata[1] is the order, [2] is the generator */
220
}
221
222
doall(li)=
223
{
224
my(ans=vector(#li),len=length(li));
225
for(j=1,#li,
226
ans[j]=doit(li[j]);
227
print1(".");
228
if(j%50==0, print(" ", j, " ", floor(100*j/len), "%"))
229
);
230
return(ans);
231
}
232
233
doall1(li)=
234
{
235
my(ans=vector(#li));
236
for(j=1,#li,
237
ans[j]=doit1(li[j]);
238
print1(".");
239
if(j%50==0, print(" ", j))
240
);
241
return(ans);
242
}
243
244
dofix(li)=
245
{
246
my(l2);
247
l2 =apply(z->[z[2],z[1][2]], li);
248
l2= doall1(l2);
249
return(vector(#l2,h,[Vecrev(li[h][1][1]),l2[h]]));
250
}
251
252
253