-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.m
executable file
·454 lines (407 loc) · 13.2 KB
/
examples.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
QQ := Rationals();
ZZ := Integers();
import "./src/diagres.m" : diagonal_restriction_derivative;
function overwriteLine(fileName, Str, newStr)
/* Replace in file Filename the first line containing string str
with string newStr, otherwise append at end
*/
fileStr := Read(fileName);
lineStart := Position(fileStr, Str);
if lineStart eq 0 then
Write(fileName, newStr);
return "appended line";
end if;
preStr := Substring(fileStr, 1, lineStart-1);
postStr := Substring(fileStr,lineStart, #fileStr - lineStart);
lineStop := Position(postStr,"\n");
if lineStop eq 0 then
print("hit end of file");
Write(fileName, preStr * newStr: Overwrite := true);
else
postStr := Substring(postStr,lineStop, #postStr - lineStop+1);
Write(fileName, preStr * newStr* postStr: Overwrite := true);
end if;
return "rewrote line";
end function;
function IsGSDisc(D,p)
flag := true;
/* flag := flag and IsSquarefree(D); */
flag := flag and IsFundamentalDiscriminant(D);
flag := flag and KroneckerSymbol(D,p) eq -1;
flag := flag and Norm(FundamentalUnit(QuadraticField(D))) eq 1;
flag := flag and #ReducedOrbits(QuadraticForms(D)) gt 1;
return flag;
end function;
function batch_compute_D(disc_bd, p : m := 50, pprec := m, disc_start := 5, overwrite := false)
PolQ<x> := PolynomialRing(QQ);
Filename := "data/D" * IntegerToString(disc_bd) * "p" *IntegerToString(p) *".csv";
try
tmp := Read(Filename);
tmp := 0;
catch err
/* if not specified, start new file */
Write(Filename, "D,p, Pol");
end try;
for D in [disc_start..disc_bd] do
/*if D fund disc and p inert in Q(sqrt(D)) */
found_flag := false;
computed_flag := false;
if IsGSDisc(D,p) then
/* now check if we added it already */
if not overwrite then
file := Read(Filename);
pos := Position(file, Sprint(D)* ", "* Sprint(p));
if pos gt 0 then /* pos eq 0 iff not found */
/* print pos; */
while file[pos] ne "\n" do
if file[pos] eq "x" then
print "already computed for D,p =", D, ",", p;
computed_flag := true;
break;
end if;
pos +:= 1;
end while;
end if;
end if;
if not computed_flag then
Orbs := Reverse(ReducedOrbits(QuadraticForms(D)));
lprec := pprec;
LvalVec := [Abs(Meyer2(Q[1])) : Q in Orbs];
MinLval := Minimum(LvalVec);
while not found_flag do
for Q in Orbs do
if #Orbs lt 4
or Abs(Meyer2(Q[1])) ne Maximum(LvalVec) then /* The biggest Lvalue usually fails bc p-adic algo */
P := GSUnit(Q[1],p,m : pprec:=lprec); /* if this fails, print message and continue */
/* now test if it generates HCF */
if P ne 0 then
found_flag := true;
newStr := Sprint(D)* ", "* Sprint(p) *", "*Sprint(P);
overwriteLine(Filename,Sprint(D)* ", "* Sprint(p),newStr);
break;
end if;
else
print "Skipped quadratic form with unit of high valuation, = ", Maximum(LvalVec);
end if;
/* now test if it generates HCF */
/* if P ne 0 and IsHCF(P,D) then */
/* found_flag := true; */
/* newStr := Sprint(D)* ", "* Sprint(p) *", "*Sprint(P); */
/* overwriteLine(Filename,Sprint(D)* ", "* Sprint(p),newStr); */
/* break; */
/* end if; */
end for;
/* if this didn't work, reset */
lprec +:= 20; /* bump precision if we can't find any */
if lprec gt 4*m then /* give up at a certain point */
break;
end if;
end while;
if not found_flag then
print "could not find GS unit for discriminant", D;
if Position(Read(Filename), Sprint(D)* ", "* Sprint(p)) eq 0 then
String := Sprint(D)* ", "* Sprint(p) *", 0";
Write(Filename, String);
end if;
end if;
end if;
end if;
end for;
return 0;
/* if P eq 0 then */
/* a := Exp(Coefficient(Diagonal_Restriction_Derivative(Q[1],p,m),0)); */
/* if -Meyer2(Q[1])*2 in ZZ then */
/* P := algdep(a*p^ZZ!(-Meyer2(Q[1])*2), #Orbs); */
/* else */
/* expt := (-Meyer2(Q[1])*6); */
/* assert expt in ZZ; */
/* P := algdep(a*p^ZZ!expt, #Orbs); */
/* end if; */
/* recip_flag := false; */
/* for k in [-10..10] do */
/* Pdash := Evaluate(P,p^k*x); */
/* if Coefficients(Pdash) eq Reverse(Coefficients(Pdash)) then */
/* P := Pdash*p^-Min([Valuation(c,p) : c in Coefficients(Pdash)]); */
/* recip_flag := true; */
/* break; */
/* end if; */
/* end for; */
/* if recip_flag then */
/* if not IsHCF(P,D) then */
/* P := 0; */
/* end if; */
/* else */
/* P := 0; */
/* end if; */
/* end if; */
/* /\* sometimes it's helpful to test u^3 instead *\/ */
/* if P eq 0 then */
/* print "trying to algdep Exp_p(log_p(u))^3"; */
/* P := algdep(a^3, #Orbs); */
/* if Coefficient(P,0) lt 0 then */
/* P := -P; */
/* end if; */
/* cubedFlag := true; */
/* for k in [-10..10] do */
/* Pdash := Evaluate(P,p^k*x); */
/* if Coefficients(Pdash) eq Reverse(Coefficients(Pdash)) then */
/* P := Pdash*p^-Min([Valuation(c,p) : c in Coefficients(Pdash)]); */
/* break; */
/* end if; */
/* end for; */
/* /\* not gonna test any odd boy *\/ */
/* P := 0; */
/* end if; */
end function;
function batch_compute_p(prime_bd, D : m:=50, pprec:=m, overwrite:=false)
PolQ<x> := PolynomialRing(QQ);
/* certain sanity checks */
Orbs := ReducedOrbits(QuadraticForms(D));
h := #Orbs;
assert h gt 1;
/* assert IsSquarefree(D); /\* make sure discriminant is squarefree *\/ */
assert IsFundamentalDiscriminant(D);
Filename := "data/p" * IntegerToString(prime_bd) * "D" *IntegerToString(D) *".csv";
try
tmp := Read(Filename);
tmp := 0;
catch err
/* if not specified, start new file */
Write(Filename, "D,p, Pol");
end try;
/* Compute arithmetic data including valuation vector of min polys */
e := GenusFieldRootsOf1(D);
Lvals := [];
for orb in ReducedOrbits(QuadraticForms(D)) do
Q := orb[1];
print Q, "has Meyer special value equal to ", Meyer2(Q);
ord := ZZ!(Meyer2(Q)*e);
Append(~Lvals,ord);
end for;
LGCD := GCD(Lvals);
for l in [1..#Lvals] do
Lvals[l] := Lvals[l]/LGCD;
end for;
/* Compute quadratic forms data; indep of p */
Fs_list := [**];
Forms_list := [**];
for i in [1..h] do
Fs, Forms := Diagonal_Restriction_data(Orbs[i][1],m);
Append(~Fs_list,Fs);
Append(~Forms_list,Forms);
end for;
/* main loop */
for p in [3..prime_bd] do
/* cubed_flag := false; */
computed_flag := false;
if not overwrite then
file := Read(Filename);
pos := Position(file, Sprint(D)* ", "* Sprint(p));
if pos gt 0 then /* pos eq 0 iff not found */
print pos;
while file[pos] ne "\n" do
if file[pos] eq "x" then
print "already computed for D,p =", D, ",", p;
computed_flag := true;
break;
end if;
pos +:= 1;
end while;
end if;
end if;
if not computed_flag and IsPrime(p) and KroneckerSymbol(D,p) eq -1 then
cubedFlag := false;
found_flag := false;
for i in [1..h] do
Q := Orbs[i][1];
try
/* print ZZ!(+Floor(p/3)); */
drd := diagonal_restriction_derivative(Q,p,m,Fs_list[i],Forms_list[i]);
a := Exp(Coefficient(drd,0));
P := GSAlgdep(a*QQ!(p^Lvals[i]), h,Lvals,D);
catch e1
print "could not find GS unit for discriminant", D;
print e1;
break;
end try;
if P eq 0 then
print "trying to algdep Exp_p(log_p(u))^3";
try
P := algdep(a^3, h);
cubedFlag := true;
for k in [-10..10] do
Pdash := Evaluate(P,p^k*x);
if Coefficients(Pdash) eq Reverse(Coefficients(Pdash)) then
P := Pdash*p^-Min([Valuation(c,p) : c in Coefficients(Pdash)]);
break;
end if;
end for;
if not IsHCF(P,D) then
P := 0;
end if;
catch e2
print "that didn't work either";
end try;
end if;
if P ne 0 then
found_flag := true;
newStr := Sprint(D)* ", "* Sprint(p) *", "*Sprint(P);
if cubedFlag then
/* newStr *:= " (Rmk. char poly of u^3)"; */
cubedFlag := false;
end if;
overwriteLine(Filename,Sprint(D)* ", "* Sprint(p),newStr);
break;
else
print "could not find GS unit for prime", p;
end if;
end for;
if not found_flag then
print "could not find GS unit for discriminant", D;
String := Sprint(D)* ", "* Sprint(p) *", 0";
Write(Filename, String);
end if;
end if;
end for;
return 0;
end function;
function batch_compute_D_and_p(prime_bd, disc_bd : m:= 100, pprec := m, disc_start := 5)
for D in [disc_start..disc_bd] do
/* if square-free discriminant */
if IsFundamentalDiscriminant(D) and SquareFreeFactorization(D) eq D then
try
batch_compute_p(prime_bd,D : m := m, pprec:= pprec);
catch e
print "trying with higher precision";
try
batch_compute_p(prime_bd,D : m := 2*m, pprec:= 2*pprec);
catch e2
print "could not find GS unit for discriminant", D;
end try;
end try;
end if;
end for;
return 0;
end function;
function GS_red_mod_p(D,p,P)
F<a> := QuadraticField(D);
H := AbsoluteField(ext<F | P>);
O := MaximalOrder(H);
/* pick an arbitrary prime above p */
frakP := Factorisation(p*O)[1][1];
Fp, phi := Completion(H,frakP);
/* zeta := Roots(CyclotomicPolynomial(p^2-1),Fp)[1][1]; */
FFp := ResidueClassField(IntegerRing(Fp));
for r in Roots(P,H) do
u := phi(r[1]);
v := u*p^-Valuation(u);
FFp!v;
end for;
return FFp;
end function;
function GSHigherLevel (Q,p,m : pprec := m)
nterms := m;
/* p := 5; */
/* D := 48; */
D := Discriminant(Q);
f := Conductor(QuadraticForms(D));
print "conductor = ", f;
print "quadratic form", Q;
print "Diagonal restriction of this equals:";
Diagonal_Restriction(Q,1,nterms : Stabilisation := p);
F := QuadraticField(D);
Drd := Diagonal_Restriction_Derivative(Q,p,nterms);
G := OrdinaryProjection(Drd : f := f);
/* CT := Coefficient(Drd,0); */
return G;
M := ModularForms(p*f);
Eis := [qExpansion(e,nterms) : e in EisensteinSeries(M)];
Cusp := Basis(CuspidalSubspace(M),nterms);
assert #Cusp le 1; /* makes life easier */
B := Eis cat Cusp;
CT, Combo := basis_coordinates(G,B : int := false);
for i in [1..#B] do
if Coefficient(B[i],0) eq (p-1)/24 then
c := Combo[i]/Combo[#B+1];
assert B[i] eq qExpansion(EisensteinSeries(ModularForms(p))[1],nterms);
print "Detected coefficient in direction of Eisenstein series", B[i];
print c;
end if;
end for;
print "algdepping";
/* can't be bothered to compute LValVec, so just guessing */
e := GenusFieldRootsOf1(D);
h := #ReducedOrbits(QuadraticForms(D));
for n in [-10..10] do
LValVec := [-n,n];
P := GSAlgdep(Exp(e*c)*QQ!(p^n),h,LValVec,ZZ!(D/f^2));
if P ne 0 then
return P;
end if;
end for;
return 0;
end function;
function batch_compute_SH(disc_bd, p : m := 25, pprec := m, disc_start := 5, overwrite := false, E := EllCurvesData(p)[1])
PolQ<x> := PolynomialRing(QQ);
Filename := "SHdata/D" * IntegerToString(disc_bd) * "p" *IntegerToString(p) *".csv";
try
tmp := Read(Filename);
tmp := 0;
catch err
/* if not specified, start new file */
Write(Filename, "D,p,X,Y,coefficients");
end try;
for D in [disc_start..disc_bd] do
/*if D fund disc and p inert in Q(sqrt(D)) */
found_flag := false;
computed_flag := false;
if IsGSDisc(D,p) then
/* now check if we added it already */
if not overwrite then
file := Read(Filename);
pos := Position(file, Sprint(D)* ", "* Sprint(p));
if pos gt 0 then /* pos eq 0 iff not found */
/* print pos; */
while file[pos] ne "\n" do
if file[pos] eq "x" then
print "already computed for D,p =", D, ",", p;
computed_flag := true;
break;
end if;
pos +:= 1;
end while;
end if;
end if;
if not computed_flag then
Orbs := Reverse(ReducedOrbits(QuadraticForms(D)));
lprec := pprec;
while not found_flag do
for O in Orbs do
Q, L := SHPoints(O[1], p,lprec : E := E, pprec:=pprec);
/* returns E!0, [] if it doesn't find anything */
if Q ne Parent(Q)!0 then
X := MinimalPolynomial(Q[1]);
Y := MinimalPolynomial(Q[2]);
found_flag := true;
newStr := Sprint(D)* ", "* Sprint(p) *", "*Sprint(X)*", "*Sprint(Y)*", "*Sprint(L);
overwriteLine(Filename,Sprint(D)* ", "* Sprint(p),newStr);
end if;
end for;
/* if this didn't work, reset */
lprec +:= 20; /* bump precision if we can't find any */
if lprec gt 4*m then /* give up at a certain point */
break;
end if;
end while;
if not found_flag then
print "could not find SH point for discriminant", D;
if Position(Read(Filename), Sprint(D)* ", "* Sprint(p)) eq 0 then
String := Sprint(D)* ", "* Sprint(p) *", NA,NA,NA";
Write(Filename, String);
end if;
end if;
end if;
end if;
end for;
return 0;
end function;