-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsingleintegrals.m
2123 lines (1654 loc) · 52.5 KB
/
singleintegrals.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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
max_prec:=function(Q,p,N,g,W0,Winf,e0,einf);
// Compute the p-adic precision required for provable correctness
d:=Degree(Q);
W:=Winf*W0^(-1);
Nmax:=N+Floor(log(p,-p*(ord_0_mat(W)+1)*einf));
while (Nmax-Floor(log(p,p*(Nmax-1)*e0))-Floor(log(p,-(ord_inf_mat(W^(-1))+1)*einf)) lt N) do
Nmax:=Nmax+1;
end while;
Nmax:=Maximum(Nmax,2);
return Nmax; // precision to be used in the computations
end function;
frobmatrix:=function(Q,p,N,Nmax,g,r,W0,Winf,G0,Ginf,frobmatb0r,red_list_fin,red_list_inf,basis,integrals,quo_map);
// Compute the matrix of F_p on H^1(X) mod p^N with respect to 'basis'.
F:=ZeroMatrix(Rationals(),#basis,#basis);
f0list:=[];
finflist:=[];
fendlist:=[];
for i:=1 to #basis do
dif:=frobenius(basis[i],Q,p,Nmax,r,frobmatb0r);
dif:=convert_to_Qxzzinvd(dif,Q);
coefs,f0,finf,fend:=reduce_with_fs(dif,Q,p,N,Nmax,r,W0,Winf,G0,Ginf,red_list_fin,red_list_inf,basis,integrals,quo_map);
for j:=1 to #basis do
F[i,j]:=coefs[j];
end for;
f0list:=Append(f0list,f0);
finflist:=Append(finflist,finf);
fendlist:=Append(fendlist,fend);
end for;
return F,f0list,finflist,fendlist;
end function;
function h1_basis(Q,p,N)
// Compute a basis for H^1(X).
if not IsIrreducible(Q) then
error "Curve is not irreducible";
end if;
d:=Degree(Q);
g:=genus(Q,p);
r,Delta,s:=auxpolys(Q);
W0:=mat_W0(Q);
W0inv:=W0^(-1);
Winf:=mat_Winf(Q);
Winfinv:=Winf^(-1);
W:=Winf*W0^(-1);
if (FiniteField(p)!LeadingCoefficient(Delta) eq 0) or (Degree(r) lt 1) or (not smooth(r,p)) or (not (is_integral(W0,p) and is_integral(W0inv,p) and is_integral(Winf,p) and is_integral(Winfinv,p))) then
error "bad prime";
end if;
G:=con_mat(Q,Delta,s);
G0:=W0*Evaluate(G,Parent(W0[1,1]).1)*W0^(-1)+ddx_mat(W0)*W0^(-1);
Ginf:=Winf*Evaluate(G,Parent(Winf[1,1]).1)*Winf^(-1)+ddx_mat(Winf)*Winf^(-1);
Jinf,Tinf,Tinfinv:=jordan_inf(Ginf);
J0,T0,T0inv:=jordan_0(r,G0);
e0,einf:=ram(J0,Jinf);
delta:=Floor(log(p,-(ord_0_mat(W)+1)*einf))+Floor(log(p,(Floor((2*g-2)/d)+1)*einf));
basis:=basis_coho(Q,p,r,W0,Winf,G0,Ginf,J0,Jinf,T0inv,Tinfinv,false,[],[],[]);
return basis,g,r,W0;
end function;
coleman_data:=function(Q,p,N:useU:=false,basis0:=[],basis1:=[],basis2:=[],heights:=false)
// Takes a polynomial Q in two variables x,y over the rationals which is monic in y.
// Returns the Coleman data of (the projective nonsingular model of) the curve defined
// by Q at p to p-adic precision N.
if not IsIrreducible(Q) then
error "Curve is not irreducible";
end if;
d:=Degree(Q);
g:=genus(Q,p);
r,Delta,s:=auxpolys(Q);
W0:=mat_W0(Q);
W0inv:=W0^(-1);
Winf:=mat_Winf(Q);
Winfinv:=Winf^(-1);
W:=Winf*W0^(-1);
if (FiniteField(p)!LeadingCoefficient(Delta) eq 0) or (Degree(r) lt 1) or (not smooth(r,p)) or (not (is_integral(W0,p) and is_integral(W0inv,p) and is_integral(Winf,p) and is_integral(Winfinv,p))) then
error "bad prime";
end if;
G:=con_mat(Q,Delta,s);
G0:=W0*Evaluate(G,Parent(W0[1,1]).1)*W0^(-1)+ddx_mat(W0)*W0^(-1);
Ginf:=Winf*Evaluate(G,Parent(Winf[1,1]).1)*Winf^(-1)+ddx_mat(Winf)*Winf^(-1);
Jinf,Tinf,Tinfinv:=jordan_inf(Ginf);
J0,T0,T0inv:=jordan_0(r,G0);
e0,einf:=ram(J0,Jinf);
delta:=Floor(log(p,-(ord_0_mat(W)+1)*einf))+Floor(log(p,(Floor((2*g-2)/d)+1)*einf));
basis,integrals,quo_map:=basis_coho(Q,p,r,W0,Winf,G0,Ginf,J0,Jinf,T0inv,Tinfinv,useU,basis0,basis1,basis2);
Nmax:=max_prec(Q,p,N,g,W0,Winf,e0,einf);
frobmatb0r:=froblift(Q,p,Nmax-1,r,Delta,s,W0);
red_list_fin,red_list_inf:=red_lists(Q,p,Nmax,r,W0,Winf,G0,Ginf,e0,einf,J0,Jinf,T0,Tinf,T0inv,Tinfinv);
F,f0list,finflist,fendlist:=frobmatrix(Q,p,N,Nmax,g,r,W0,Winf,G0,Ginf,frobmatb0r,red_list_fin,red_list_inf,basis,integrals,quo_map);
// formatting the output into a record:
format:=recformat<Q,p,N,g,W0,Winf,r,Delta,s,G0,Ginf,e0,einf,delta,basis,quo_map,integrals,F,f0list,finflist,fendlist,Nmax,red_list_fin,red_list_inf,minpolys,cpm,subspace,ordinary,frobmatb0r>;
out:=rec<format|>;
out`Q:=Q; out`p:=p; out`N:=N; out`g:=g; out`W0:=W0; out`Winf:=Winf; out`r:=r; out`Delta:=Delta; out`s:=s; out`G0:=G0; out`Ginf:=Ginf;
out`e0:=e0; out`einf:=einf; out`delta:=delta; out`basis:=basis; out`quo_map:=quo_map; out`integrals:=integrals; out`F:=F; out`f0list:=f0list;
out`finflist:=finflist; out`fendlist:=fendlist; out`Nmax:=Nmax; out`red_list_fin:=red_list_fin; out`red_list_inf:=red_list_inf;
out`frobmatb0r:=frobmatb0r;
return out;
end function;
function xy_coordinates(P, data)
// returns the affine xy-coordinates of a point record
if P`inf then
error "Point is not affine";
end if;
W0 := data`W0;
d := Degree(data`Q);
x0 := P`x;
W0invx0 := Evaluate(W0^(-1), x0);
K := Universe(P`b);
b_vector := Matrix(K, d, 1, P`b);
ypowers := W0invx0*ChangeRing(b_vector,Parent(W0invx0[1,1]));
y0 := ypowers[2,1];
return [x0,y0];
end function;
set_point:=function(x0,y0,data)
// Constructs a point from affine coordinates x0,y0.
Q:=data`Q; p:=data`p; N:=data`N; W0:=data`W0;
d:=Degree(Q);
if x0 in RationalField() then
K:=pAdicField(p,N);
else
K:=Parent(x0);
end if;
x0:=K!x0; y0:=K!y0;
if Valuation(x0) lt 0 then
error "x0 has negative valuation";
end if;
if (not(W0 eq IdentityMatrix(BaseRing(W0),d))) and (Valuation(Evaluate(data`r,x0)) gt 0) then
error "W0 is not the identity and r(x0) is zero mod p";
end if;
format:=recformat<x,b,inf,xt,bt,index>;
P:=rec<format|>;
P`inf:=false;
P`x:=x0;
y0powers:=[];
y0powers[1]:=K!1;
for i:=2 to d do
y0powers[i]:=(y0)^(i-1);
end for;
y0powers:=Vector(y0powers);
W0x0:=Transpose(Evaluate(W0,x0));
// the values of the b_i^0 at P
P`b := Eltseq(y0powers*ChangeRing(W0x0, BaseRing(y0powers)));
return P;
end function;
set_bad_point:=function(x,b,inf,data)
Q:=data`Q; p:=data`p; N:=data`N;
Qp:=pAdicField(p,N); d:=Degree(Q);
format:=recformat<x,b,inf,xt,bt,index>;
P:=rec<format|>;
P`inf:=inf;
P`x:=Qp!x;
P`b:=[Qp!b[i]:i in [1..d]];
return P;
end function;
is_bad:=function(P,data)
// check whether the point P is bad
x0:=P`x; r:=data`r;
if P`inf then // infinite point
return true;
end if;
if Valuation(Evaluate(r,x0)) gt 0 then // finite bad point
return true;
end if;
return false;
end function;
is_very_bad:=function(P,data)
// check whether the point P is very bad
x0:=P`x; r:=data`r; N:=data`N;
if P`inf then // infinite point
if Valuation(x0) ge N then // infinite very bad point
return true;
end if;
else // finite point
if Valuation(Evaluate(r,x0)) ge N then // finite very bad point
return true;
end if;
end if;
return false;
end function;
lie_in_same_disk:=function(P1,P2,data)
// check whether two points P1,P2 lie in the same residue disk
x1:=P1`x; b1:=P1`b; x2:=P2`x; b2:=P2`b; Q:=data`Q;
d:=Degree(Q);
if P1`inf ne P2`inf then // one point infinite, other not
return false;
elif Valuation(x1-x2) lt 1 then
return false;
else
for i:=1 to d do
if Valuation(b1[i]-b2[i]) lt 1 then
return false;
end if;
end for;
return true;
end if;
end function;
minpoly:=function(f1,f2)
// computes the minimum polynomial of f2 over Q(f1), where
// f1,f2 are elements of a 1 dimensional function field over Q
FF:=Parent(f1);
d:=5;
done:=false;
while not done do
S:=[];
for i:=0 to d do
for j:=0 to d do
S:=Append(S,f1^j*f2^i);
end for;
end for;
denom:=1;
for i:=1 to #S do
E:=Eltseq(S[i]);
for j:=1 to #E do
denom:=LCM(denom,Denominator(E[j]));
end for;
end for;
maxdeg:=0;
for i:=1 to #S do
E:=Eltseq(S[i]);
for j:=1 to #E do
deg:=Degree(Numerator(denom*E[j]));
if deg gt maxdeg then
maxdeg:=deg;
end if;
end for;
end for;
T:=[];
for i:=1 to #S do
E:=Eltseq(S[i]);
v:=[];
for j:=1 to #E do
for k:=0 to maxdeg do
v[(j-1)*(maxdeg+1)+k+1]:=Coefficient(Numerator(denom*E[j]),k);
end for;
end for;
T:=Append(T,v);
end for;
b:=Basis(NullSpace(Matrix(T)));
if #b gt 0 then
done:=true;
R:=b[1];
else
d:=d+3;
end if;
end while;
poly:=Qxy!0;
for i:=0 to d do
for j:=0 to d do
poly:=poly+R[i*(d+1)+j+1]*Qx.1^j*Qxy.1^i;
end for;
end for;
fac:=Factorisation(poly);
for i:=1 to #fac do
factor:=fac[i][1];
test:=FF!0;
for j:=0 to Degree(factor) do
test:=test+Evaluate(Coefficient(factor,j),f1)*f2^j;
end for;
if test eq 0 then
poly:=factor;
end if;
end for;
return poly;
end function;
update_minpolys:=function(data,inf,index);
// TODO comment
Q:=data`Q; W0:=data`W0; Winf:=data`Winf;
d:=Degree(Q);
if not assigned data`minpolys then
data`minpolys:=[ZeroMatrix(Qxy,d+2,d+2),ZeroMatrix(Qxy,d+2,d+2)];
end if;
minpolys:=data`minpolys;
Qt:=RationalFunctionField(RationalField()); Qty:=PolynomialRing(Qt);
f:=Qty!0;
for i:=0 to d do
for j:=0 to Degree(Coefficient(Q,i)) do
f:=f+Coefficient(Coefficient(Q,i),j)*Qty.1^i*Qt.1^j;
end for;
end for;
FF:=FunctionField(f); // function field of curve
if inf then
W:=Winf;
else
W:=W0;
end if;
bfun:=[];
for i:=1 to d do
bi:=FF!0;
for j:=1 to d do
bi:=bi+W[i,j]*FF.1^(j-1);
end for;
bfun[i]:=bi;
end for;
if inf then // b=b^{infty}
if index eq 0 then
for i:=1 to d do
if minpolys[2][1,i+1] eq 0 then
minpolys[2][1,i+1]:=minpoly(FF!(1/Qt.1),bfun[i]);
end if;
end for;
else
if minpolys[2][index+1,1] eq 0 then
minpolys[2][index+1,1]:=minpoly(bfun[index],FF!(1/Qt.1));
end if;
for i:=1 to d do
if minpolys[2][index+1,i+1] eq 0 then
minpolys[2][index+1,i+1]:=minpoly(bfun[index],bfun[i]);
end if;
end for;
end if;
else // b=b^0
if index eq 0 then
for i:=1 to d do
if minpolys[1][1,i+1] eq 0 then
minpolys[1][1,i+1]:=minpoly(FF!Qt.1,bfun[i]);
end if;
end for;
else
if minpolys[1][index+1,1] eq 0 then
minpolys[1][index+1,1]:=minpoly(bfun[index],FF!Qt.1);
end if;
for i:=1 to d do
if minpolys[1][index+1,i+1] eq 0 then
minpolys[1][index+1,i+1]:=minpoly(bfun[index],bfun[i]);
end if;
end for;
end if;
end if;
data`minpolys:=minpolys;
return data;
end function;
frobenius_pt:=function(P,data);
// Computes the image of P under Frobenius
x0:=P`x; Q:=data`Q; p:=data`p; N:=data`N; W0:=data`W0; Winf:=data`Winf;
d:=Degree(Q); K:=Parent(x0); Ky:=PolynomialRing(K);
x0p:=x0^p;
b:=P`b;
Qt:=RationalFunctionField(RationalField()); Qty:=PolynomialRing(Qt);
f:=Qty!0;
for i:=0 to d do
for j:=0 to Degree(Coefficient(Q,i)) do
f:=f+Coefficient(Coefficient(Q,i),j)*Qty.1^i*Qt.1^j;
end for;
end for;
FF:=FunctionField(f); // function field of curve
if not is_bad(P,data) then // finite good point
W0invx0:=Transpose(Evaluate(W0^(-1),x0));
ypowers:=Vector(b)*ChangeRing(W0invx0,Parent(b[1]));
y0:=ypowers[2];
C:=Coefficients(Q);
D:=[];
for i:=1 to #C do
D[i]:=Evaluate(C[i],x0p);
end for;
fy:=Ky!D;
y0p:=HenselLift(fy,y0^p); // Hensel lifting
y0ppowers:=[];
y0ppowers[1]:=K!1;
for i:=2 to d do
y0ppowers[i]:=y0p^(i-1);
end for;
y0ppowers:=Vector(y0ppowers);
W0x0:=Transpose(Evaluate(W0,x0));
b := Eltseq(y0ppowers*ChangeRing(W0x0, BaseRing(y0ppowers)));
elif P`inf then // infinite point
for i:=1 to d do
bi:=FF!0;
for j:=1 to d do
bi:=bi+Winf[i,j]*FF.1^(j-1);
end for;
if assigned data`minpolys and data`minpolys[2][1,i+1] ne 0 then
poly:=data`minpolys[2][1,i+1];
else
poly:=minpoly(FF!(1/Qt.1),bi);
end if;
C:=Coefficients(poly);
D:=[];
for i:=1 to #C do
D[i]:=Evaluate(C[i],x0p);
end for;
fy:=Ky!D;
fac:=Factorisation(fy); // Roots has some problems that Factorisation does not
zeros:=[];
for j:=1 to #fac do
if Degree(fac[j][1]) eq 1 then
zeros:=Append(zeros,-Coefficient(fac[j][1],0)/Coefficient(fac[j][1],1));
end if;
end for;
done:=false;
j:=1;
while not done and j le #zeros do
if Valuation(zeros[j]-b[i]^p) gt Min(N, p) then // was gt 0 before
done:=true;
b[i]:=zeros[j];
end if;
j:=j+1;
end while;
if not done then
error "Frobenius does not converge at P";
end if;
end for;
else // finite bad point
for i:=1 to d do
bi:=FF!0;
for j:=1 to d do
bi:=bi+W0[i,j]*FF.1^(j-1);
end for;
if assigned data`minpolys and data`minpolys[1][1,i+1] ne 0 then
poly:=data`minpolys[1][1,i+1];
else
poly:=minpoly(FF!Qt.1,bi);
end if;
C:=Coefficients(poly);
D:=[];
for i:=1 to #C do
D[i]:=Evaluate(C[i],x0p);
end for;
fy:=Ky!D;
fac:=Factorisation(fy); // Roots has some problems that Factorisation does not
zeros:=[];
for j:=1 to #fac do
if Degree(fac[j][1]) eq 1 then
zeros:=Append(zeros,-Coefficient(fac[j][1],0)/Coefficient(fac[j][1],1));
end if;
end for;
done:=false;
j:=1;
while not done and j le #zeros do
if Valuation(zeros[j]-b[i]^p) gt p then
done:=true;
b[i]:=zeros[j];
end if;
j:=j+1;
end while;
if not done then
error "Frobenius does not converge at P";
end if;
end for;
end if;
P`x:=x0p;
P`b:=b;
delete P`xt;
delete P`bt;
delete P`index;
return P;
end function;
teichmueller_pt:=function(P,data : N :=0)
// Compute the Teichmueller point in the residue disk at a good point P
x0:=P`x; Q:=data`Q; p:=data`p; W0:=data`W0; Winf:=data`Winf;
d:=Degree(Q); K:=Parent(x0); Ky:=PolynomialRing(K);
if is_bad(P,data) then
error "Point is bad";
end if;
if IsZero(N) then N := data`N; end if;
x0new:=K!TeichmuellerLift(FiniteField(p)!x0,pAdicQuotientRing(p,N));
b:=P`b;
W0invx0:=Transpose(Evaluate(W0^(-1),x0));
ypowers:=Vector(b)*ChangeRing(W0invx0,Parent(b[1]));
y0:=ypowers[2];
C:=Coefficients(Q);
D:=[];
for i:=1 to #C do
D[i]:=Evaluate(C[i],x0new);
end for;
fy:=Ky!D;
y0new:=HenselLift(fy,y0); // Hensel lifting
y0newpowers:=[];
y0newpowers[1]:=K!1;
for i:=2 to d do
y0newpowers[i]:=y0newpowers[i-1]*y0new;
end for;
y0newpowers:=Vector(y0newpowers);
W0x0new:=Transpose(Evaluate(W0,x0new));
b:=Eltseq(y0newpowers*ChangeRing(W0x0new,K));
P`x:=x0new;
P`b:=b;
delete P`xt;
delete P`bt;
delete P`index;
return P;
end function;
local_data:=function(P,data)
// For a point P, returns the ramification index of the map x on the residue disk at P
Q:=data`Q; p:=data`p; W0:=data`W0; Winf:=data`Winf; x0:=P`x; b:=P`b; d:=Degree(Q);
if not is_bad(P,data) then
eP:=1;
index:=0;
return eP,index;
else
Fp:=FiniteField(p); Fpx:=RationalFunctionField(Fp); Fpxy:=PolynomialRing(Fpx);
f:=Fpxy!0;
for i:=0 to d do
for j:=0 to Degree(Coefficient(Q,i)) do
f:=f+(Fp!Coefficient(Coefficient(Q,i),j))*Fpxy.1^i*Fpx.1^j;
end for;
end for;
FFp:=FunctionField(f); // function field of curve mod p
if P`inf then
places:=InfinitePlaces(FFp); // infinite places of function field of curve mod p
W:=Winf;
else
Px0:=Zeros(Fpx.1-Fp!x0)[1];
places:=Decomposition(FFp,Px0); // places of function field of curve mod p lying over x0 mod p
W:=W0;
end if;
bmodp:=[]; // elements of b mod p, where b is either b^0 or b^inf
for i:=1 to d do
f:=FFp!0;
for j:=1 to d do
f:=f+(Fpx!W[i,j])*FFp.1^(j-1);
end for;
bmodp[i]:=f;
end for;
done:=false;
for i:=1 to #places do
same:=true;
for j:=1 to d do
if Evaluate(bmodp[j],places[i]) ne Fp!b[j] then
same:=false;
end if;
end for;
if same then
place:=places[i];
done:=true;
end if;
end for;
if not done then
error "Point does not lie on curve";
end if;
eP:=RamificationIndex(place);
if eP eq 1 then
index:=0;
else
done:=false;
i:=1;
while not done do
ord:=Valuation(bmodp[i]-Evaluate(bmodp[i],place),place);
if ord eq 1 then
index:=i;
done:=true;
end if;
i:=i+1;
end while;
end if;
return eP,index,place,bmodp;
end if;
end function;
hensel_lift:=function(fy,root);
// Finds a root of the polynomial fy over Qp[[t]]
// by Hensel lifting from an approximate root.
//
// Assumes that the starting criterion for Hensel's
// lemma is satisfied
Kty:=Parent(fy);
Kt:=BaseRing(Kty);
K:=BaseRing(Kt);
tprec:=Precision(Kt); // t-adic precision
Qt:=PowerSeriesRing(RationalField(),tprec);
Qty:=PolynomialRing(Qt);
p:=Prime(K);
pprec:=Precision(K); // p-adic precision
Zp:=pAdicRing(p,pprec);
Zpt:=PowerSeriesRing(Zp,tprec);
fy:=Qty!fy;
derfy:=Derivative(fy);
if not Valuation(LeadingCoefficient(Qt!Evaluate(derfy,root)),p) eq 0 then
error "In Hensel lift of power series, derivative has leading term divisible by p";
end if;
v1:=Valuation(Qt!Zpt!Evaluate(fy,root));
v2:=Valuation(Qt!Zpt!Evaluate(derfy,root));
if not v1 gt 2*v2 then
error "Condition Hensel's Lemma not satisfied";
end if;
prec_seq:=[];
k:=tprec;
while k gt v1 do
prec_seq:=Append(prec_seq,k);
k:=Ceiling(k/2+v2);
end while;
prec_seq:=Reverse(prec_seq);
for j:=1 to #prec_seq do
root:=Qt!root;
root:=ChangePrecision(root,prec_seq[j]);
root:=root-(Qt!Zpt!Evaluate(fy,root))/(Qt!Zpt!Evaluate(derfy,root));
root:=Zpt!root;
end for;
return root;
end function;
mod_p_prec:=function(fy);
// Finds the t-adic precision necessary to separate the roots
// of the polynomial fy over Qp[[t]] modulo p and start Hensel lift.
//
// Temporarily uses intrinsic Factorisation instead of
// intrinsic Roots because of multiple problems with Roots.
Kty:=Parent(fy);
Kt:=BaseRing(Kty);
tprec:=Precision(Kt);
K:=BaseRing(Kt);
p:=Prime(K);
Fp:=FiniteField(p);
Fpt:=PowerSeriesRing(Fp,tprec);
Fpty:=PolynomialRing(Fpt);
fymodp:=Fpty!fy;
derfymodp:=Derivative(fymodp);
zeros:=[];
fac:=Factorisation(fymodp); // can be slow...
for i:=1 to #fac do
if fac[i][2] gt 1 then
error "t-adic precision not high enough";
end if;
factor:=fac[i][1];
if Degree(factor) eq 1 and LeadingCoefficient(factor) eq 1 then
zeros:=Append(zeros,-Coefficient(factor,0));
end if;
end for;
modpprec:=1;
for i:=1 to #zeros do
done:=false;
prec:=1;
while not done do
v1:=Valuation(Evaluate(fymodp,ChangePrecision(zeros[i],prec)));
v2:=Valuation(Evaluate(derfymodp,ChangePrecision(zeros[i],prec)));
if Minimum(prec,v1) gt 2*v2 then
done:=true;
end if;
prec:=prec+1;
end while;
modpprec:=Maximum(modpprec,prec);
end for;
for i:=1 to #zeros do
for j:=i+1 to #zeros do
modpprec:=Maximum(modpprec,Valuation(zeros[i]-zeros[j]));
end for;
end for;
return modpprec;
end function;
approx_root:=function(fy,y0,modpprec,expamodp)
// Computes an approximation to t-adic precision modpprec of
// a root of the polynomial fy over Qp[[t]] which is congruent to:
//
// y0 modulo t
// expamodp modulo p
//
// This approximation is then used as root in hensel_lift.
Kty:=Parent(fy);
Kt:=BaseRing(Kty);
tprec:=Precision(Kt); // t-adic precision
K:=BaseRing(Kt);
p:=Prime(K);
Fp:=FiniteField(p);
pprec:=Precision(K); // p-adic precision
Zp:=pAdicRing(p,pprec);
Zpt:=PowerSeriesRing(Zp,tprec);
Zpz:=PolynomialRing(Zp);
Qt:=PowerSeriesRing(RationalField(),tprec);
Qty:=PolynomialRing(Qt);
Qz:=PolynomialRing(RationalField());
Qzt:=PowerSeriesRing(Qz,tprec);
roots:=[[*Kt!y0,1*]];
i:=1;
while i le #roots do
root:=roots[i][1];
Nroot:=roots[i][2];
if Nroot lt modpprec then
roots:=Remove(roots,i);
newroot:=root+Kty.1*Kt.1^Nroot;
C:=Coefficients(fy);
fynewroot:=Kty!0;
for j:=1 to #C do
fynewroot:=fynewroot+(Kt!C[j])*newroot^(j-1);
end for;
fynewroot:=Qty!Kty!fynewroot;
fznewroot:=Qzt!0;
for j:=0 to Degree(fynewroot) do
for k:=0 to tprec-1 do
fznewroot:=fznewroot+Coefficient(Coefficient(fynewroot,j),k)*(Qz.1)^j*(Qzt.1)^k;
end for;
end for;
fac:=Factorisation(Zpz!Coefficient(fznewroot,Valuation(fznewroot)));
for j:=1 to #fac do
if (Degree(fac[j][1]) eq 1) and (Coefficient(fac[j][1],1) eq 1) then
sol:=-Coefficient(fac[j][1],0);
if Fp!sol eq Coefficient(expamodp,Nroot) then
roots:=Insert(roots,i,[*Evaluate(newroot,sol),Nroot+1*]);
end if;
end if;
end for;
else
i:=i+1;
end if;
end while;
if #roots ne 1 then
error "something is wrong, number of approximate roots is different from 1";
end if;
root:=roots[1][1];
root:=Zpt!Qt!root;
v1:=Valuation(Zpt!Qt!Evaluate(fy,root));
v2:=Valuation(Zpt!Qt!Evaluate(Derivative(fy),root));
if v1 le 2*v2 then
error "something is wrong, approximate root not good enough for Hensel lift";
end if;
return root;
end function;
mod_p_expansion:=function(f,place,tmodp,modpprec);
// Finds the power series expansion of f in the function field
// modulo p at place with respect to local parameter tmodp to
// absolute precision modpprec.
FFp:=Parent(f);
Fpx:=BaseRing(FFp);
Fp:=BaseRing(Fpx);
Fpt:=PowerSeriesRing(Fp,modpprec);
expamodp:=Fpt!0;
for i:=0 to modpprec-1 do
val:=Evaluate(f,place);
expamodp:=expamodp+val*Fpt.1^i;
f:=(f-val)/tmodp;
end for;
return expamodp;
end function;
local_coord:=function(P,prec,data);
// Computes powerseries expansions of x and
// the b^0_i or b^infty_i (depending on whether
// P is infinite or not) in terms of the local
// coordinate computed by local_data.
if assigned P`xt and Precision(Parent(P`xt)) ge prec then
xt:=P`xt;
bt:=P`bt;
index:=P`index;
return xt,bt,index;
end if;
if is_bad(P,data) and not is_very_bad(P,data) then
error "Cannot compute local parameter at a bad point which is not very bad";
end if;
x0:=P`x; Q:=data`Q; p:=data`p; N:=data`N; W0:=data`W0; Winf:=data`Winf; d:=Degree(Q); b:=P`b;
K:=Parent(x0); Kt<t>:=PowerSeriesRing(K,prec); Kty:=PolynomialRing(Kt);
Qt:=RationalFunctionField(RationalField()); Qty:=PolynomialRing(Qt);
Fp:=FiniteField(p);
f:=Qty!0;
for i:=0 to d do
for j:=0 to Degree(Coefficient(Q,i)) do
f:=f+Coefficient(Coefficient(Q,i),j)*Qty.1^i*Qt.1^j;
end for;
end for;
FF:=FunctionField(f); // function field of curve
if not is_bad(P,data) then // finite good point
xt:=t+x0;
W0invx0:=Transpose(Evaluate(W0^(-1),x0));
ypowers:=Vector(b)*ChangeRing(W0invx0,Parent(b[1]));
y0:=ypowers[2];
C:=Coefficients(Q);
D:=[];
for i:=1 to #C do
D[i]:=Evaluate(C[i],xt);
end for;
fy:=Kty!D;
derfy:=Derivative(fy);
yt:=hensel_lift(fy,Kt!y0);
ypowerst:=[];
ypowerst[1]:=FieldOfFractions(Kt)!1;
ypowerst[2]:=yt;
for i:=3 to d do
ypowerst[i]:=ypowerst[i-1]*yt;
end for;
bt:=Eltseq(Vector(ypowerst)*Transpose(Evaluate(W0,xt)));
btnew:=[];
for i:=1 to d do
btnew[i]:=Kt!bt[i];
end for;
bt:=btnew;