-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTorsion.m
1785 lines (1645 loc) · 53.9 KB
/
Torsion.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
MyFrobCommand := "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/sage/sage-9.5/local/lib/; /home/bommel/cap/controlledreduction-torsion/build/examples/myfrob";
// ANALYTIC RECONSTRUCTION
function FromMumfordRepresentation(J, MumRep : MaxDegree := 12, Debug := false)
while MumRep[1] eq [] do
Remove(~MumRep, 1);
end while;
CC := Parent(MumRep[1][1][2]);
eps := 10^-Floor(Precision(CC)/2);
K := Rationals();
phi := hom< K->CC | >;
R<x, y, z> := PolynomialRing(K, 3);
RC<xC, yC, zC> := PolynomialRing(CC, 3);
phiR := hom< R->RC | phi, [xC, yC, zC] >;
Pols := [];
// Find algebraic x-polynomial
for i0 in [1..#MumRep] do
Mf := MumRep[i0];
Append(~Pols, R!0);
for i in [1..#Mf] do
C := Mf[i];
FactorFound := false;
for f in Factorisation(ChangeRing(C[1], K)) do
fC := phiR(Evaluate(f[1], R.1));
if Abs(Evaluate(fC, [C[2], 0, 0])) lt eps^(1/4) then
if Degree(f[1])*AbsoluteDegree(K) gt MaxDegree then
print "Field extension becoming too big";
continue f;
end if;
FactorFound := true;
if Degree(f[1]) eq 1 then
L := K;
rho := IdentityFieldMorphism(K);
rhoR := hom< R->R | rho, [R.i : i in [1..Rank(R)]] >;
a := Roots(f[1])[1][1];
else
L := Polredabs(AbsoluteField(ext< K | f[1] >) : Best := true);
R1L := PolynomialRing(L);
if K eq Rationals() then
b := 1;
rho := hom< K->L |>;
rhof1 := hom< Parent(f[1])->R1L | rho, R1L.1 >;
else
for rt in Roots(DefiningPolynomial(K), L) do
rho := hom< K->L | rt[1] >;
rhof1 := hom< Parent(f[1])->R1L | rho, R1L.1 >;
if #Roots(rhof1(f[1])) gt 0 then
b := rt[1];
break rt;
end if;
end for;
end if;
Rnew := ChangeRing(R, L);
rhoR := hom< R->Rnew | rho, [Rnew.i : i in [1..Rank(Rnew)]] >;
R := Rnew;
a := Roots(rhof1(f[1]))[1][1];
FoundComplexMap := false;
for x in Roots(DefiningPolynomial(L), CC) do
newphi := hom< L->CC | x[1] >;
newphiR := hom< R->RC | newphi, [RC.i : i in [1..Rank(RC)]] >;
if Abs(newphi(b) - phi(K.1)) lt eps^(1/4) then
if Abs(newphi(a) - C[2]) lt eps^(1/4) then
FoundComplexMap := true;
break x;
end if;
end if;
end for;
if not(FoundComplexMap) then
return Zero(J);
end if;
phi := newphi;
phiR := newphiR;
end if;
Pols := [rhoR(Pol) : Pol in Pols];
Pols[i0] +:= a * &*[(R.k)^(C[3][k]) : k in [1..#C[3]]];
K := L;
break f;
end if;
end for; // f
if not(FactorFound) then
return Zero(J);
end if;
end for; // i
end for; // i0
// Check polynomials
for i0 in [1..#MumRep] do
Mf := MumRep[i0];
PolxR := phiR(Pols[i0]);
assert(#Monomials(PolxR) le #Mf);
ZeroIndices := {1..#Mf};
for i in [1..#Monomials(PolxR)] do
k := [j : j in [1..#Mf] | Mf[j][3] eq Exponents(Monomials(PolxR)[i])][1];
assert( Abs( Coefficients(PolxR)[i] - Mf[k][2]) lt eps^(1/4) );
Exclude(~ZeroIndices, k);
end for;
for i in ZeroIndices do
assert( Abs(Mf[i][2]) lt eps^(1/10) );
end for;
end for;
// Construct point on J
JK := BaseChange(J, hom<Rationals()->K |>);
CK := JK`C;
RK<x, y, z> := CoordinateRing(Ambient(CK));
I := ideal< RK | [Evaluate(p, [x,y,z]) : p in Pols] >;
D := Divisor(CK, Saturation(I));
Pt := Point(JK, D);
assert(Debug eq false);
return Pt;
end function;
function AnalyticPoint(P, CC)
K := Parent(P[1]);
AnP := [];
for z in Roots(DefiningPolynomial(K), CC) do
if K eq Rationals() then
phi := hom<K -> CC | >;
else
phi := hom<K -> CC | z[1]>;
end if;
Append(~AnP, [phi(x) : x in P]);
end for;
return AnP;
end function;
function AnalyticDivision(C, J, Pt, l, lTorsion : PotMumfordReps := [], Precision := 200)
// Find chart where the canonical point lies.
I := Ideal(J`D_can);
R<x,y,z> := CoordinateRing(Ambient(C));
if (z in I) then
if (y in I) then
phi := hom< R->R | [y,z,x]>;
phi_inv := [3,1,2];
else
phi := hom< R->R | [z,x,y]>;
phi_inv := [2,3,1];
end if;
else
phi := hom< R->R | [x,y,z] >;
phi_inv := [1,2,3];
end if;
C2 := Curve(Ambient(C), phi(Equation(C)));
I2 := ideal<R | [phi(x) : x in Generators(I)]>;
D2 := Divisor(C2, I2);
assert(IsEffective(D2));
assert(Degree(D2) eq 1);
J2 := GenericJacobian(C2, D2);
BaseI := ideal<R | [phi(x) : x in Generators(Ideal(Pt))] >;
BasePt := Point(J2, Divisor(C2, BaseI));
// Construct Riemann surface
_<v,w> := PolynomialRing(Rationals(), 2);
f := Evaluate(Equation(C2), [v,w,1]);
RS := RiemannSurface(f : Precision := Precision);
BasePt_RS := RS!Coordinates(RepresentativePoint(Decomposition(D2)[1][1]));
B := [BasePt_RS : i in [1..3]];
if Pt`D eq 0 then
v := AbelJacobi(BasePt_RS, BasePt_RS);
else
v := &+[w[2]*&+[AbelJacobi(BasePt_RS, RS!q) : q in AnalyticPoint(Coordinates(RepresentativePoint(w[1]))[phi_inv], ComplexField(Precision))] : w in Decomposition(Pt`D)];
end if;
// Construct analytic version of the lTorsion
AnalyticTorsion := [];
for Qt in lTorsion do
if Qt`D eq 0 then
v2 := AbelJacobi(BasePt_RS, BasePt_RS);
else
v2 := &+[w[2]*&+[AbelJacobi(BasePt_RS, RS!q) : q in AnalyticPoint(Coordinates(RepresentativePoint(w[1]))[phi_inv], ComplexField(Precision))] : w in Decomposition(Qt`D)];
end if;
Append(~AnalyticTorsion, v2);
end for;
print("Found analytic element, now try to divide by using Newton-Raphson");
// Search for points
if #PotMumfordReps eq 0 then
PotMumfordReps, MumfordSucceeded := AnalyticTorsionSearch(C2, RS, B, v, l, AnalyticTorsion);
end if;
PotPts := [FromMumfordRepresentation(J2, MumRep) : MumRep in PotMumfordReps];
// Translate results back to original Jacobian
PotPtsOrig := [];
for x in PotPts do
if x eq 0 then
continue x;
end if;
K := BaseField(x`J`C);
JK := BaseChange(J, hom<Rationals()->K |>);
CK := JK`C;
I := Ideal(x);
R := CoordinateRing(Ambient(CK));
rho := hom< R->R | [R.(phi_inv[s]) : s in [1..3]]>;
IK := ideal< R | [rho(s) : s in Generators(I)] >;
D := Divisor(CK, IK);
assert(Degree(D) eq Degree(x`D));
Append(~PotPtsOrig, Point(JK, D));
end for;
// Check result
for x in PotPtsOrig do
assert(PointOverSmallestField(J, l*x) eq Pt);
end for;
assert(#PotPtsOrig gt 0);
return PotPtsOrig;
end function;
// ALGEBRAIC RECONSTRUCTION
function ReductionsToIdeal(L)
n := LCM([Integers()!x[1] : x in L]);
RZn<x> := PolynomialRing(Integers(n), 1);
phi := hom< Parent(L[1][1])->RZn | x >;
IdealList := [ideal< RZn | phi(P) > : P in L];
return &meet(IdealList);
end function;
function FindSmallElement(I, maxDegree)
Groebner(I);
RZ<x> := PolynomialRing(Integers());
phi := hom<I^0->RZ | x >;
Mat := Matrix(&cat[ [ Coefficients(x^(maxDegree+1) + x^j * q)[1..maxDegree+1] : j in [0..maxDegree-Degree(q)] ] : q in [phi(x) : x in Generators(I)] cat [RZ!#BaseRing(I)] ]);
MatSh := LLL(Mat : Proof := false, EarlyReduction := true, Fast := 1); // Weight... TimeLimit := 5.0?
v := MatSh[1];
return RZ![v[i] : i in [1..maxDegree+1]];
end function;
function AlgebraicReconstruction(L : maxDegree := 30, Verbose := false)
I := ReductionsToIdeal(L);
n := LCM([Integers()!x[1] : x in L]);
for d in [1..maxDegree] do
Pol := FindSmallElement(I, d);
if 1000.0*(RealField()!MaxNorm(Pol)*2.0 + 1.0)^(1.1*(d+1)) gt n then
if Verbose then
print d;
print Pol;
print "Continue based on MaxNorm criterion";
end if;
continue d;
end if;
for x in L do
p := Integers()!x[1];
Pol_modp := ChangeRing(Pol, GF(p));
Orig_modp := ChangeRing(x[2], GF(p));
if (Pol_modp eq 0) or (Pol_modp mod Orig_modp ne 0) then
if Verbose then
print d;
print Pol;
print "Continue based on Pol_mod criterion";
end if;
continue d;
end if;
end for;
return Pol;
end for;
return 0;
end function;
// GROUP STRUCTURE IN JACOBIAN
function FrobeniusPolynomial(f, pList)
s := GetSeed();
if Type(pList) ne SeqEnum then // For backwards compatibility
return FrobeniusPolynomial(f, [pList])[1];
end if;
R := PolynomialRing(Integers());
d := TotalDegree(f);
_<x,y,z> := Parent(f);
Coeffs_x := Coefficients(f + x^(d+1), 1)[1..d+1];
Coeffs_xy := [Evaluate(Coefficients(Coeffs_x[i] + y^(d+2-i),2)[1..(d+2-i)],[0,0,1]) : i in [1..d+1]];
Coeffs := &cat(Coeffs_xy);
FrobPolyList := [];
TimeInControlledReduction := 0;
for p in pList do
F := Open("inputfile" cat Sprint(s), "w");
Write(F, IntegerToString(p));
Write(F, "\n[");
// coefficients
for i in [1..#Coeffs] do
Write(F, IntegerToString(Integers()!GF(p)!Coeffs[i]));
if i ne #Coeffs then
Write(F, " ");
end if;
end for;
// end coefficients
Write(F, "]\n");
delete F;
// /home/sage/sage-8.8/local/lib/
// /home/bommel/sage-8.8-lib/
TimeInControlledReduction -:= Cputime();
System(MyFrobCommand cat " 1 inputfile" cat Sprint(s) cat " outputfile" cat Sprint(s) cat " > erroroutput" cat Sprint(s));
TimeInControlledReduction +:= Cputime();
EvalOutput := Read("outputfile" cat Sprint(s));
Append(~FrobPolyList, R!StringToIntegerSequence(EvalOutput[2..#EvalOutput-2]));
System("rm inputfile" cat Sprint(s) cat " outputfile" cat Sprint(s) cat " erroroutput" cat Sprint(s));
end for;
print TimeInControlledReduction, "seconds spent in controlled_reduction computing Frobenius polynomials";
return FrobPolyList;
end function;
function lDivisors(Jq, l, Pt)
return [g : g in pSylowSubgroup(Jq, l) | (l*g eq Pt) and not(g eq Pt)];
end function;
// HELPER FUNCTIONS
function MyNormalisation(Pt)
P := [Pt[i] : i in [1..3]];
d := LCM([Denominator(x) : x in P]);
P := [d*x : x in P];
d := GCD([Numerator(x) : x in P]);
P := [x/d : x in P];
return P;
end function;
function IsSimpler(a, b)
A := MyNormalisation(a);
B := MyNormalisation(b);
hA := Max([Abs(x) : x in A]);
hB := Max([Abs(x) : x in B]);
qA := &+[x^2 : x in A];
qB := &+[x^2 : x in B];
if hA ne hB then
return hA - hB;
elif qA ne qB then
return qA - qB;
elif A[1] ne B[1] then
return A[1] - B[1];
elif A[2] ne B[2] then
return A[2] - B[2];
else
return A[3] - B[3];
end if;
end function;
function UniqueElement(S)
assert(#S eq 1);
return Random(S);
end function;
procedure AddToPriorityQueue(~PriorityQueue, ~Total, S, k)
if not(k in Keys(PriorityQueue)) then
PriorityQueue[k] := {};
end if;
if not(S in PriorityQueue[k]) then
Include(~PriorityQueue[k], S);
Total +:= Max(k,1);
end if;
end procedure;
procedure RemoveFromPriorityQueue(~PriorityQueue, ~Total)
s := Max(Keys(PriorityQueue));
S := Random(PriorityQueue[s]);
if #PriorityQueue[s] eq 1 then
Remove(~PriorityQueue, s);
else
Exclude(~PriorityQueue[s], S);
end if;
Total -:= Max(s,1);
end procedure;
function nfisincl(f,g) // Thanks to Andrew Sutherland
assert (BaseRing(f) eq Rationals() or BaseRing(f) eq Integers()); //: "The polynomial f must have coefficients in Q.";
assert (BaseRing(g) eq Rationals() or BaseRing(g) eq Integers()); //: "The polynomial g must have coefficients in Q.";
f := ChangeRing(f, Rationals());
g := ChangeRing(g, Rationals());
R<x> := Parent(g);
f := Evaluate(f,x);
cmd:=Sprintf("{print(nfisincl(%o,%o))}",f,g);
s := Pipe("gp -q", cmd);
s := eval(s);
if Type(s) ne SeqEnum then return [Parent(g)|]; end if;
return [Parent(g)|Evaluate(R!h,x):h in s];
end function;
function MyCompositeFields(K,L : MaxDegree := 12)
if IsPrimeField(K) then
if IsFinite(L) then
Lopt := L;
phiL := IdentityFieldMorphism(L);
else
Lopt, phiL := Polredabs(L : Best := true);
end if;
return [* < hom<K->Lopt|>, phiL > *];
elif IsPrimeField(L) then
if IsFinite(K) then
Kopt := K;
phiK := IdentityFieldMorphism(K);
else
Kopt, phiK := Polredabs(K : Best := true);
end if;
return [* < phiK, hom<L->Kopt|> > *];
elif IsFinite(K) then
M := K+L;
phi1 := hom<K->M | K.1>;
phi2 := hom<L->M | L.1>;
return [* <phi1, phi2> *];
end if;
f := DefiningPolynomial(K);
g := DefiningPolynomial(L);
RelevantPairs := [* *];
for M2 in CompositeFields(K,L) do
if AbsoluteDegree(M2) gt MaxDegree then
continue M2;
end if;
for x in RelevantPairs do
if IsIsomorphic(x[1], M2) then
continue M2;
end if;
end for;
M := Polredabs(M2 : Best := true);
AutM := Automorphisms(M);
h := DefiningPolynomial(M);
ImagesK := [ Evaluate(phi, M.1) : phi in nfisincl(f,h)];
ImagesL := [ Evaluate(phi, M.1) : phi in nfisincl(g,h)];
for a in ImagesK do
for b in ImagesL do
for N in Subfields(M) do
if (AbsoluteDegree(N[1]) lt AbsoluteDegree(M)) and (a in N[1]) and (b in N[1]) then
continue b; // N is not a composite field in this case
end if;
end for; // N
for x in RelevantPairs do
if x[1] ne M then
continue x;
end if;
for sigma in AutM do
if (sigma(x[2]) eq a) and (sigma(x[3]) eq b) then
continue b;
end if;
end for; // sigma
end for; // x
Append(~RelevantPairs, < M, a, b >);
end for; // b
end for; // a
end for; // M2
return [* < hom<K->x[1] | x[2]>, hom<L->x[1] | x[3]> > : x in RelevantPairs *];
end function;
function MyPlus(J, P, Q : MaxFieldDegree := 12)
K := BaseField(P`J`C);
L := BaseField(Q`J`C);
PointList := {};
for phi in MyCompositeFields(K,L : MaxDegree := MaxFieldDegree) do
if not(IsFinite(K)) and (AbsoluteDegree(Codomain(phi[1])) gt MaxFieldDegree) then
continue phi;
end if;
if IsFinite(K) then
M := Codomain(phi[1]);
if not(#M in Keys(J`ReductionObj)) then
b, p := IsPrimePower(#M);
J`ReductionObj[#M] := BaseChange(Reduction(J,p), hom<GF(p)->M|>);
end if;
JM_K := J`ReductionObj[#M];
JM_L := JM_K;
M := BaseField(JM_K`C);
if IsPrimeField(K) then
phiK := FieldMorphism(hom<K->M|>);
else
try
if K eq M then
phiK := IdentityFieldMorphism(K);
else
phiK := FieldMorphism(hom<K->M|Roots(MinimalPolynomial(K.1), M)[1][1]>);
end if;
catch e
phiK := FieldMorphism(hom<K->M|Roots(MinimalPolynomial(K.1), M)[1][1]>);
end try;
end if;
if IsPrimeField(L) then
phiL := FieldMorphism(hom<L->M|>);
else
try
if L eq M then
phiL := IdentityFieldMorphism(L);
else
phiL := FieldMorphism(hom<L->M|Roots(MinimalPolynomial(L.1), M)[1][1]>);
end if;
catch e
phiL := FieldMorphism(hom<L->M|Roots(MinimalPolynomial(L.1), M)[1][1]>);
end try;
end if;
RM := CoordinateRing(Ambient(JM_K`C));
rhoK := hom<CoordinateRing(Ambient(P`J`C))->RM | phiK, [RM.i : i in [1..Rank(RM)]]>;
rhoL := hom<CoordinateRing(Ambient(Q`J`C))->RM | phiL, [RM.i : i in [1..Rank(RM)]]>;
else
phiK := FieldMorphism(phi[1]);
if IsIdentity(phiK) then
phiL := FieldMorphism(phi[2]);
else
phiL := FieldMorphism(phi[1]);
end if;
JM_K, rhoK := BaseChange(P`J, phi[1]);
JM_L, psiL := BaseChange(Q`J, phi[2]);
if IsIdentity(phi[1]) then
rhoL := psiL;
else
rhoL := hom<Domain(psiL)->Codomain(rhoK) | phi[2], [ Codomain(rhoK)!psiL(Domain(psiL).i) : i in [1..Rank(Domain(psiL))]]>;
end if;
end if;
if IsIdentity(phiK) then
PM := P;
else
PM := BaseChange(P, JM_K, rhoK);
end if;
if IsIdentity(phiL) then
QM := Q;
else
QM := BaseChange(Q, JM_K, rhoL);
end if;
Include(~PointList, PointOverSmallestField(J, PM+QM));
end for;
return PointList;
end function;
function MyConjugates(P)
K := BaseField(P`J`C);
A := Automorphisms(K);
R := CoordinateRing(Ambient(P`J`C));
rho := [hom<R->R | phi, [R.i : i in [1..Rank(R)]]> : phi in A];
return [ BaseChange(P, P`J, r) : r in rho ];
end function;
function MyEq(P, Q)
K := BaseField(P`J`C);
L := BaseField(Q`J`C);
M := CompositeFields(K, L)[1];
for x in Roots(ChangeRing(DefiningPolynomial(K),M)) do
for y in Roots(ChangeRing(DefiningPolynomial(L),M)) do
if K eq Rationals() then
phiK := hom<K->M |>;
else
phiK := hom<K->M | x[1]>;
end if;
if L eq Rationals() then
phiL := hom<L->M |>;
else
phiL := hom<L->M | y[1]>;
end if;
JM_K, rhoK := BaseChange(P`J, phiK);
JM_L, rhoL := BaseChange(Q`J, phiL);
rhoL := hom<Domain(rhoL)->Codomain(rhoK) | [ Codomain(rhoK)!rhoL(Domain(rhoL).i) : i in [1..Rank(Domain(rhoL))]]>;
PM := BaseChange(P, JM_K, rhoK);
QM := BaseChange(Q, JM_K, rhoL);
if PM eq QM then
return true;
end if;
end for;
end for;
return false;
end function;
function MyIn(P, S)
for s in S do
if MyEq(P, s) then
return true;
end if;
end for;
return false;
end function;
procedure MyAddElementToSubgroup(~S, x)
assert(false);
n := 1;
nx := x;
T := {};
while not(MyIn(nx, S)) do
Include(~T, nx);
nx +:= x;
end while;
Snew := S;
for s in S do
for t in T do
Include(~S, MyPlus(s,t));
end for;
end for;
end procedure;
procedure AddElementToSubgroup(~S, x)
n := 1;
nx := x;
T := {};
while not(nx in S) do
Include(~T, nx);
nx +:= x;
end while;
Snew := S;
for s in S do
for t in T do
Include(~S, s+t);
end for;
end for;
end procedure;
procedure AddElementToSubgroup2(~S, x, ~V)
n := 1;
nx := x;
T := {};
while not(nx in S) do
Include(~T, nx);
nx +:= x;
end while;
Snew := S;
for s in S do
for t in T do
Include(~S, s+t);
Include(~V, s+t);
end for;
end for;
end procedure;
function xPolynomial(E, RZ, p)
xPoly := RZ!1;
for D in Decomposition(E) do
I := Ideal(D[1]);
Idehom := ideal< I^0 | [Evaluate(g, [I.1, I.2, 1]) : g in Generators(I)] cat [I.3]>;
if Idehom ne Idehom^0 then
xPoly *:= Evaluate(UnivariateEliminationIdealGenerator(Idehom, 1), [RZ.1, 0, 0]);
if p ne 0 then
xPoly mod:= p;
end if;
end if;
end for;
return xPoly;
end function;
function yPolynomial(E, RZ, p)
yPoly := RZ!1;
for D in Decomposition(E) do
I := Ideal(D[1]);
Idehom := ideal< I^0 | [Evaluate(g, [I.1, I.2, 1]) : g in Generators(I)] cat [I.3]>;
if Idehom ne Idehom^0 then
yPoly *:= Evaluate(UnivariateEliminationIdealGenerator(Idehom, 2), [0, RZ.1, 0]);
if p ne 0 then
yPoly mod:= p;
end if;
end if;
end for;
return yPoly;
end function;
function PolynomialRadical(f)
if Degree(f) le 0 then
return f;
end if;
return &*[g[1] : g in Factorisation(f)];
end function;
function DefinesActualJacobianPoint(J, Lx, Ly : MaxDegree := 1, ExpectedNumberOfPoints := 1)
K := BaseField(J`C);
R<x> := PolynomialRing(K);
Pts := [* *];
print "Lx = ", Lx;
print "Ly = ", Ly;
// First construct all possible polynomials from Lx, Ly and K
Possibilities := [* [* R!0, R!0, K *] *];
for i in [1..#Lx] do
NewPossibilities := [* *];
for p in Possibilities do
L := p[3];
for f in Factorisation(ChangeRing(Lx[i], L)) do
if IsFinite(L) then
AbsDeg := Degree(L);
else
AbsDeg := AbsoluteDegree(L);
end if;
if Degree(f[1])*AbsDeg gt MaxDegree then
continue f;
elif Degree(f[1]) eq 1 then
Lnew := L;
a := Roots(f[1])[1][1];
else
Lnew<a> := AbsoluteField(ext< L | f[1] >);
end if;
Polxnew := p[1] + a*ChangeRing(x, Lnew)^(i-1);
Lnew_opt, phi_L := Polredabs(Lnew : Best := true);
RL_opt := ChangeRing(Parent(Polxnew), Lnew_opt);
rho_L := hom< Parent(Polxnew)->RL_opt | phi_L, [RL_opt.i : i in [1..Rank(RL_opt)]] >;
Append(~NewPossibilities, [* rho_L(Polxnew), p[2], Lnew_opt *]);
end for;
end for;
Possibilities := NewPossibilities;
end for;
for i in [1..#Ly] do
NewPossibilities := [* *];
for p in Possibilities do
L := p[3];
for f in Factorisation(ChangeRing(Ly[i], L)) do
if IsFinite(L) then
AbsDeg := Degree(L);
else
AbsDeg := AbsoluteDegree(L);
end if;
if Degree(f[1])*AbsDeg gt MaxDegree then
continue f;
elif Degree(f[1]) eq 1 then
Lnew := L;
a := Roots(f[1])[1][1];
else
Lnew<a> := AbsoluteField(ext< L | f[1] >);
end if;
Polynew := p[2] + a*ChangeRing(x, Lnew)^(i-1);
Lnew_opt, phi_L := Polredabs(Lnew : Best := true);
RL_opt := ChangeRing(Parent(Polynew), Lnew_opt);
rho_L := hom< Parent(Polynew)->RL_opt | phi_L, [RL_opt.i : i in [1..Rank(RL_opt)]] >;
Append(~NewPossibilities, [* rho_L(ChangeRing(p[1], Lnew)), rho_L(Polynew), Lnew_opt *]);
end for;
end for;
Possibilities := NewPossibilities;
end for;
print #Possibilities, "possibilities found";
// Then construct all possible points on J
for p in Possibilities do
print "Try possibility", p;
PotPts := {};
assert(K eq PrimeField(K)); // NotImplementedError
//print "Degree number field:", AbsoluteDegree(K);
//L := SplittingField([f[1] : f in Factorisation(p[1])]);
L := p[3];
CL := BaseChange(J`C, L);
_<xL, yL> := FunctionField(CL);
MaxInfinityDegree := (ExpectedNumberOfPoints*Genus(CL) - Degree(p[1])) / ExpectedNumberOfPoints;
//print "All rings constructed";
Dx := Numerator(Divisor(CL, Evaluate(p[1], xL)));
//print "Dx computed";
Dy := Numerator(Divisor(CL, Evaluate(p[2], yL)));
//print "Dy computed";
D := GCD(Dx, Dy);
if (D eq 0) and (L ne Rationals()) and (p[1] ne ConstantCoefficient(p[1])) and (p[2] ne ConstantCoefficient(p[2])) then
continue p;
end if;
//print "D constructed";
Dnum := Numerator(D);
//Inum := Ideal(Dnum);
Dnum_decomp := Decomposition(Dnum);
//print "Dnum constructed";
Dden := Denominator(Divisor(CL, xL)) + Denominator(Divisor(CL, yL));
//Iden := Ideal(Dden);
Dden_decomp := Decomposition(Dden);
//print "Dden constructed";
//print "Divisors found, Dnum has", #Decomposition(Dnum), "components and Dden has", #Decomposition(Dden), "components";
if Dnum ne 0 then
print Decomposition(Dnum);
end if;
L1 := L;
for K0 in [* (ResidueClassField(E[1])) : E in Dnum_decomp cat Dden_decomp *] do
print "K0 =", K0;
K1 := AbsoluteField(K0);
print "K1 =", K1;
L1 := CompositeFields(L1, K1)[1];
if L1 ne Rationals() then
print "Gal =", GaloisGroup(L1);
end if;
end for;
if L1 ne Rationals() then
G := GaloisGroup(L1);
Subgrps := [H`subgroup : H in Subgroups(G) | H`order ge Order(G)/MaxDegree];
Subf := [* NumberField(GaloisSubgroup(L1, H)) : H in Subgrps *];
else
Subf := [* Rationals() *];
end if;
PolynomialsSeen := {};
for F in Subf do
M := Polredabs(F : Best := true);
if DefiningPolynomial(M) in PolynomialsSeen then
continue F;
end if;
Include(~PolynomialsSeen, DefiningPolynomial(M));
if AbsoluteDegree(M) gt MaxDegree or (Type(M) eq FldRat and L ne Rationals()) or not(L subset M) then
continue F;
end if;
for rt in [ Evaluate(phi, M.1) : phi in nfisincl(DefiningPolynomial(L),DefiningPolynomial(M))] do
print "Trying field", M, "root", rt;
JM, rhoM := BaseChange(J, hom< K->M | >);
CM := JM`C;
RL := CoordinateRing(Ambient(CL));
RM := CoordinateRing(Ambient(CM));
PM := PolynomialRing(M);
if Type(L) eq FldRat then
phi := hom<L->M | >;
rho := hom<RL->RM | [RM.i : i in [1..Rank(RM)]]>;
psi := hom<Parent(p[1])->PM | PM.1 >;
else
phi := hom<L->M | rt>;
rho := hom<RL->RM | phi, [RM.i : i in [1..Rank(RM)]]>;
psi := hom<Parent(p[1])->PM | phi, PM.1 >;
end if;
p1M := psi(p[1]);
DnumM_decomp := [];
for E in Dnum_decomp do
IM := ideal< RM | [rho(x) : x in Generators(Ideal(E[1])) ]>;
EM := Divisor(CM, IM);
for F in Decomposition(EM) do
Append(~DnumM_decomp, < F[1], E[2]*F[2], xPolynomial(Divisor(F[1]), PM, 0) >);
end for;
end for;
//InumM := ideal< RM | [rho(x) : x in Generators(Inum)]>;
//DnumM := Divisor(CM, InumM);
print "DnumM constructed";
for D in DnumM_decomp do
print D[1], Degree(D[1]);
end for;
DdenM_decomp := [];
for E in Dden_decomp do
IM := ideal< RM | [rho(x) : x in Generators(Ideal(E[1])) ]>;
EM := Divisor(CM, IM);
for F in Decomposition(EM) do
Append(~DdenM_decomp, < F[1], E[2]*F[2], xPolynomial(Divisor(F[1]), PM, 0) >);
end for;
end for;
//IdenM := ideal< RM | [rho(x) : x in Generators(Iden)]>;
//DdenM := Divisor(CM, IdenM);
//print "Base change done";
NumeratorDivisors := [ { <DivisorGroup(CM)!0, PM!1 > } ];
for i in [1..Genus(CL)] do
Append(~NumeratorDivisors, {});
for D in DnumM_decomp do
k := Degree(D[1]);
if k le i then
for E in NumeratorDivisors[i+1-k] do
if IsDivisibleBy(p1M, PolynomialRadical(D[3]*E[2])) then
Include(~NumeratorDivisors[i+1], < D[1]+E[1], D[3]*E[2] >);
end if;
end for;
end if;
end for;
end for;
print "p1M =", p1M;
print "NumeratorDivisors finished", [#NumeratorDivisors[i] : i in [1..Genus(CL)+1]];
DenominatorDivisors := [ {<DivisorGroup(CM)!0, PM!1 >} ];
for i in [1..Genus(CL)] do
Append(~DenominatorDivisors, {});
if i gt MaxInfinityDegree then
continue i;
end if;
for D in DdenM_decomp do
k := Degree(D[1]);
if k le i then
for E in DenominatorDivisors[i+1-k] do
if IsDivisibleBy(p1M, PolynomialRadical(D[3]*E[2])) then
Include(~DenominatorDivisors[i+1], < D[1]+E[1], D[3]*E[2] >);
end if;
end for;
end if;
end for;
end for;
print "DenominatorDivisors finished", [#DenominatorDivisors[i] : i in [1..Genus(CL)+1]];
for i in [0..Genus(CL)] do
for D in NumeratorDivisors[i+1] do
for j in [0..Genus(CL)-i] do
for E in DenominatorDivisors[j+1] do
xPol := D[2]*E[2];
if IsDivisibleBy(p1M, PolynomialRadical(xPol)) then
Pt_sm := PointOverSmallestField(J, Point(JM, D[1]+E[1]));
if AbsoluteDegree(BaseField(Pt_sm`J`C)) ne AbsoluteDegree(M) then
continue E;
end if;
R_sm := CoordinateRing(Ambient(Pt_sm`J`C));
rho_sm := hom< CoordinateRing(Ambient(J`C))->R_sm | [R_sm.i : i in [1..Rank(R_sm)]] >;
Append(~Pts, [* Pt_sm, Pt_sm`J, rho_sm *]);
end if;
end for; // end for E
end for; // end for j
end for; // end for D
end for; // end for i
end for; // end for rt
end for; // end for F
end for; // end for p
return Pts;
end function;
// DIVISION BY ALGEBRAIC RECONSTRUCTION
function DivisionByRationalReconstruction(J, Pt, l, PrimeList : BaseDegree := 1, MaxNumberOfReconstructions := 2*10^3, MaxDegree := 4, JpList := [], MaxSubgroupSize := 5000, lTorsion := {}, ExtraPrimes := [])
// Preparation: assertions
assert IsPrime(l);
n := l*Order(Pt);
assert n gt 0;
Include(~lTorsion, Zero(J));
Pt_red := AssociativeArray();
for p in PrimeList do
Pt_red[p] := UniqueElement(PrimeReduction(J, Pt, p));
end for;
// Step 1: finding the relevant points
RQ := PolynomialRing(Rationals());
RZ := PolynomialRing(Integers());
Lx := [];
Ly := [];
IndexList := [i : i in [1..#PrimeList] | l^Valuation(Order(JpList[i]), l) lt MaxSubgroupSize];
for i in IndexList do
p := PrimeList[i];
if JpList ne [] then
Jp := JpList[i];
else
Jp := BaseChange(J, GF(p^BaseDegree));
end if;
PotElems := lDivisors(Jp, l, Pt_red[p]);
if #PotElems eq 0 then
return {};
end if;
xList := [];
yList := [];
for i in [1..#PotElems] do
x := PotElems[i];
if InputRepresentations(x) ne [] then
if n gt l then
InputRepsList := [InputRepresentations(x+UniqueElement(PrimeReduction(J, t, p)))[1] : t in lTorsion];
ExpectedNumberOfPoints := #lTorsion;
else
InputRepsList := [InputRepresentations(x)[1]];
ExpectedNumberOfPoints := 1;
end if;
xPoly := &*[xPolynomial(D, RZ, p) : D in InputRepsList] mod p;
xPoly +:= RZ.1^(&+[Degree(D) : D in InputRepsList]+1);
if not([xPoly, Degree(xPoly)-1] in xList) then
yPoly := &*[yPolynomial(D, RZ, p) : D in InputRepsList] mod p;
yPoly +:= RZ.1^(&+[Degree(D) : D in InputRepsList]+1);
Append(~xList, [xPoly, Degree(xPoly)-1]);
Append(~yList, [yPoly, Degree(yPoly)-1]);
end if;
end if;
end for;
Append(~Lx, xList);
Append(~Ly, yList);
end for;
print "Step 1 finished - Found list of points modulo primes";
// Step 2: finding the subsets of PrimeList to consider
CopyLx := Lx;
while #IndexList gt 15 do
m, i := Max([#Lx[i] : i in [1..#Lx]]);
Remove(~Lx, i);
Remove(~Ly, i);
Remove(~IndexList, i);
end while;
assert(#Lx eq #IndexList);
TotalToConsider := 0;
sizeL := [#Lx[i] : i in [1..#Lx]];
PriorityQueue := AssociativeArray();
for i in [1..#Lx] do
for S in Subsets({1..#Lx},i) do
if S ne {} then
AddToPriorityQueue(~PriorityQueue, ~TotalToConsider, S, &*[sizeL[i]: i in S] + #S/ MaxNumberOfReconstructions^2);
if TotalToConsider gt 10*MaxNumberOfReconstructions then
break i;
end if;
//print "Added", S, "to priority queue";
end if;
end for;
end for;
while TotalToConsider gt MaxNumberOfReconstructions do
RemoveFromPriorityQueue(~PriorityQueue, ~TotalToConsider);
end while;
SubsetsToConsider := {};
print "Step 2 finished - Found appropriate subsets of primes";
RemovalList := [];
PointsFound := {};
LcxTried := {};
LcxTriedSuccess := {};
TotalNrOfPointsFound := 0;
for s in Sort([x : x in Keys(PriorityQueue)]) do
for S in PriorityQueue[s] do
//print S;
LxS := Lx[ [x : x in S] ];
LyS := Ly[ [x : x in S] ];
LpS := PrimeList[ [IndexList[x] : x in S] ];
IndicesS := [ [1..#x] : x in LxS ];
for i in CartesianProduct(IndicesS) do
Degx := {LxS[j][i[j]][2] : j in [1..#S]};
Degy := {LyS[j][i[j]][2] : j in [1..#S]};
if (#Degx gt 1) or (#Degy gt 1) then
continue i; // Only try the reconstruction step is the degree of the polynomials is the same for all points modulo primes.
end if;
Degx := Random(Degx);
Degy := Random(Degy);
// Constructing minimal polynomials for coefficients
Lcx := [];
for k in [1..Degx+1] do
MinimalPolynomials := [* MinimalPolynomial(Coefficients(LxS[j][i[j]][1])[k]) : j in [1..#S] *];