-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFldPad.mag
1918 lines (1744 loc) · 59.8 KB
/
FldPad.mag
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
// This file is part of ExactpAdics
// Copyright (C) 2018 Christopher Doris
//
// ExactpAdics is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ExactpAdics is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with ExactpAdics. If not, see <http://www.gnu.org/licenses/>.
///# Exact p-adic fields
///toc
import "Utils.mag": Z, Q, OO, TRIM_PR, CAP_PR, CAP_APR, ISEXTOF, ELTSEQ, isDefinitelyUnique1, CHANGE_APR;
import "Promotion.mag": do_binop;
// extension types
PRIME := 0;
INERT := 1;
EISEN := 2;
function fldpad_to_fldpadexact(xF)
assert Precision(xF) eq OO;
e := AbsoluteRamificationDegree(xF);
// initialize the new field
F := New(FldPadExact);
if IsPrimeField(xF) then
F`xtype := PRIME;
elif IsUnramified(xF) then
F`xtype := INERT;
elif IsTotallyRamified(xF) then
F`xtype := EISEN;
else
assert false;
end if;
F`prime := Prime(xF);
F`infinite_precision_approximation := xF;
F`dependencies := [**];
F`get_approximation := func<n, xds | ChangePrecision(F`infinite_precision_approximation, e * EpochPrecision(F, n))>;
Init(F);
return F;
end function;
function fldpad_to_fldpadexact_ext(xE, F)
xF := F`infinite_precision_approximation;
if xE eq xF then
return F;
end if;
assert ISEXTOF(xE, xF);
E := fldpad_to_fldpadexact(xE);
E`base_field := fldpad_to_fldpadexact_ext(BaseField(xE), F);
return E;
end function;
function _elt_from_rational(F, X)
e := AbsoluteRamificationDegree(F);
FUDGE := e eq 1 select 0 else 2*e;
x := New(FldPadExactElt);
x`parent := F;
x`dependencies := [* F *];
x`get_approximation := FUDGE eq 0 select func<n, xds | xds[1] ! X> else func<n, xds | TRIM_PR(xds[1] ! X, FUDGE)>;
Init(x);
return x;
end function;
function elt_from_rational(F, X)
if X eq 0 then
return Zero(F);
elif X eq 1 then
return One(F);
elif IsPrimeField(F) and X eq Prime(F) then
return UniformizingElement(F);
else
return _elt_from_rational(F, X);
end if;
end function;
declare type FldPadExact[FldPadExactElt]: StrPadExact;
declare attributes FldPadExact
: infinite_precision_approximation
, xtype
// cache
, prime // required when xtype is PRIME
, defining_polynomial // required when defined as an extension
, base_field // implied by defining_polynomial
, prime_field
, degree
, inertia_degree
, ramification_degree
, absolute_degree
, absolute_ramification_degree
, absolute_inertia_degree
, zero
, one
, uniformizing_element
, residue_generator
, generator
, absolute_generator
, polynomial_ring
, mvar_polynomial_ring
, residue_class_field
, residue_class_map
, approximate_residue_class_maps
, completion_map
, approximate_completion_map
, varname
, is_extension_of
;
declare type FldPadExactElt: PadExactElt;
declare attributes FldPadExactElt
// cache
: valuation
, negation
, nonzero_epoch
, min_nonzero_epoch
, eltseq
;
// an extension of p-adic fields
declare type ExtFldPadExact;
declare attributes ExtFldPadExact
: base_field
, top_field
, tower
// cache
, description
, degree
, inertia_degree
, ramification_degree
, defining_polynomial
, standard_form
, vector_space_map
, generator
;
///## Creation of p-adic fields
///### Prime fields
intrinsic ExactpAdicField(p :: RngIntElt) -> FldPadExact
{The p-adic field.}
require p gt 0 and IsPrime(p): "p must be prime";
F := New(FldPadExact);
F`infinite_precision_approximation := pAdicField(p);
F`prime := p;
F`xtype := PRIME;
F`dependencies := [**];
F`get_approximation := func<n, xds | ChangePrecision(F`infinite_precision_approximation, EpochPrecision(F, n))>;
Init(F);
return F;
end intrinsic;
///hide
intrinsic Print(F :: FldPadExact, lvl :: MonStgElt)
{Print.}
printf "%o", Description(F / PrimeField(F) : BaseName:=Sprintf("Exact %o-adic field", Prime(F)));
end intrinsic;
///hide
intrinsic Print(x :: FldPadExactElt, lvl :: MonStgElt)
{Print.}
case lvl:
when "Maximal":
printf "%o", BestApproximation(x);
else
printf "%o", CAP_PR(BestApproximation(x), 1);
end case;
end intrinsic;
///hide
intrinsic EpochPrecision(F :: AnyPadExact, n :: RngIntElt) -> RngIntElt
{The precision of epoch F.}
// magma doesn't like making totally ramified extensions of pAdicField(2,1), so this should be at least 2 (until the bug is fixed)
return 2^n;
end intrinsic;
///hide
intrinsic InterpolateEpochs(x :: FldPadExactElt, n1 :: RngIntElt, n2 :: RngIntElt, xx2 :: FldPadElt) -> List
{Interpolates between the given epochs.}
return [* EpochApproximation(Parent(x), n) ! xx2 : n in [n1+1..n2-1] *];
end intrinsic;
///hide
intrinsic InterpolateEpochs(F :: FldPadExact, n1 :: RngIntElt, n2 :: RngIntElt, xF2 :: FldPad) -> List
{"}
e := AbsoluteRamificationDegree(F);
return [* ChangePrecision(xF2, Min(EpochPrecision(F, n) * e, Precision(xF2))) : n in [n1+1..n2-1] *];
end intrinsic;
///### Extensions
/// Constructs an extension of F.
///
/// Its arguments must be either:
/// - A positive integer: constructs an unramified extension of this degree.
/// - Coercible to a inertial polynomial over F: constructs an unramified extension.
/// - Coercible to an Eisenstein polynomial over F: constructs a totally ramified extension.
/// - Two `FldPad`s, forming an extension `xE/xF`: constructs an extension `E/F` isomorphic to `xE/xF`.
intrinsic ExtConstructor(F :: FldPadExact, t :: Tup) -> FldPadExact
{Constructs an extension of F.}
if #t eq 1 then
if Type(t[1]) eq RngIntElt then
return UnramifiedExtension(F, t[1]);
end if;
ok, f := IsCoercible(PolynomialRing(F), t[1]);
if ok then
if IsInertial(f) then
return UnramifiedExtension(f);
elif IsEisenstein(f) then
return TotallyRamifiedExtension(f);
else
error "defining polynomial must be inertial or Eisenstein";
end if;
end if;
if Type(t[1]) eq RngIntElt then
if t[1] ge 1 then
error "not implemented: unramified extension of given degree";
else
error "degree must be positive";
end if;
end if;
elif #t eq 2 then
if Type(t[1]) eq FldPad and Type(t[2]) eq FldPad then
return ExactpAdicField(t[1], t[2], F);
end if;
end if;
error "invalid constructor";
end intrinsic;
intrinsic UnramifiedExtension(F :: FldPadExact, f) -> FldPadExact
{An unramified extension of F defined by f.}
return UnramifiedExtension(PolynomialRing(F) ! f);
end intrinsic;
intrinsic UnramifiedExtension(f :: RngUPolElt_FldPadExact) -> FldPadExact
{An unramified extension defined by f.}
F := BaseRing(f);
d := Degree(f);
require IsInertial(f): "f must be inertial";
function get_pr(f)
return Z ! Min([AbsolutePrecision(c) : c in Coefficients(f)]);
end function;
function get_pol(k,f)
xf := BestApproximation(f);
pr := get_pr(xf);
if pr lt k then
ExactpAdics_Warn("get_approx", Sprintf("need to increase precision of defining polynomial (%o -> %o) for unknown reasons", pr, k));
while pr lt k do
xf := EpochApproximation(f, #f`approximations+1);
pr := get_pr(xf);
end while;
end if;
assert pr ge k;
// xf := CAP_APR(xf, k);
return xf;
end function;
F`infinite_precision_approximation`DefaultPrecision := 2;
E := New(FldPadExact);
E`xtype := INERT;
E`defining_polynomial := f;
E`dependencies := [* f *];
// E`get_approximation := func<n, xf | ext<xF | ChangeRing(xf[1], xF)>
// where xF := ChangePrecision(BaseRing(xf[1]), pr)
// where pr := get_pr(xf[1])
// >;
E`get_approximation := func<n, xf | ChangePrecision(E`infinite_precision_approximation, get_pr(xf[1]))>;
E`min_epoch := InterpolateUpToFirstEpochWithApproximation(f, func<xf | get_pr(xf) ge 2>);
E`infinite_precision_approximation := ext<F`infinite_precision_approximation | map<Z -> PolynomialRing(F`infinite_precision_approximation) | k :-> get_pol(k,f)>>;
Init(E);
return E;
end intrinsic;
intrinsic UnramifiedExtension(F :: FldPadExact, d :: RngIntElt) -> FldPadExact
{An unramified extension of F of degree d.}
xF := F`infinite_precision_approximation;
xE := ext<xF | d>;
return ExactpAdicField(xE, xF, F);
end intrinsic;
intrinsic TotallyRamifiedExtension(F :: FldPadExact, f) -> FldPadExact
{A totally ramified extension of F defined by f.}
return TotallyRamifiedExtension(PolynomialRing(F) ! f);
end intrinsic;
intrinsic TotallyRamifiedExtension(f :: RngUPolElt_FldPadExact) -> FldPadExact
{A totally ramified extension defined by f.}
F := BaseRing(f);
d := Degree(f);
e := AbsoluteRamificationDegree(F);
FUDGE := d*e eq 1 select 0 else 2*e;
require IsEisenstein(f): "f must be Eisenstein";
function get_pr(f)
return Z ! Min([AbsolutePrecision(c) : c in Coefficients(f)]);
end function;
function get_pol(k,f)
k2 := k + FUDGE;
xf := BestApproximation(f);
pr := get_pr(xf);
if pr lt k2 then
ExactpAdics_Warn("get_approx", Sprintf("need to increase precision of defining polynomial (%o -> %o) for unknown reasons", pr, k2));
while pr lt k2 do
xf := EpochApproximation(f, #f`approximations+1);
pr := get_pr(xf);
end while;
end if;
assert pr ge k2;
// xf := CAP_APR(xf, k);
return xf;
end function;
F`infinite_precision_approximation`DefaultPrecision := 2;
E := New(FldPadExact);
E`xtype := EISEN;
E`defining_polynomial := f;
E`dependencies := [* f *];
// E`get_approximation := func<n, xf | ext<xF | ChangeRing(xf[1], xF)>
// where xF := ChangePrecision(BaseRing(xf[1]), pr)
// where pr := get_pr(xf[1])
// >;
E`get_approximation := func<n, xf | ChangePrecision(E`infinite_precision_approximation, d*(get_pr(xf[1]) - FUDGE))>;
E`min_epoch := InterpolateUpToFirstEpochWithApproximation(f, func<xf | get_pr(xf) ge 2 + FUDGE>);
E`infinite_precision_approximation := ext<F`infinite_precision_approximation | map<Z -> PolynomialRing(F`infinite_precision_approximation) | k :-> get_pol(k,f)>>;
Init(E);
return E;
end intrinsic;
///### Completions
function completion(F, p)
// the completion, as a FldPad
xC, xm := Completion(F, p);
// the completion, as a FldPadExact
C := fldpad_to_fldpadexact(xC);
C`approximate_completion_map := xm;
function FtoC(x)
cx := New(FldPadExactElt);
cx`parent := C;
cx`dependencies := [* C *];
cx`get_approximation := function (n, xds)
locxC := xC;
locxC`DefaultPrecision := Precision(xds[1]);
return xds[1] ! locxC ! (x @ xm);
end function;
Init(cx);
return cx;
end function;
function CtoF(y)
xy := BestApproximation(y);
locxC := xC;
locxC`DefaultPrecision := Precision(Parent(xy));
return (locxC ! xy) @@ xm;
end function;
m := map<F -> C | x :-> FtoC(x), y :-> CtoF(y)>;
C`completion_map := m;
return C, m;
end function;
intrinsic ExactCompletion(F :: FldRat, p) -> FldPadExact, Map
{The completion of F at p as an exact p-adic field. Also returns the embedding of F. The inverse of the embedding takes a p-adic number to its best current approximation, and therefore depends on the current precision of the element.}
return completion(F, p);
end intrinsic;
intrinsic ExactCompletion(F :: FldNum, p) -> FldPadExact, Map
{"}
return completion(F, p);
end intrinsic;
///### From approximate fields
///param CheckUnique:=true When `true`, checks that the input is precise enough to determine the field up to isomorphism.
intrinsic ExactpAdicField(xF :: FldPad : CheckUnique:=true) -> FldPadExact
{An exact p-adic field isomorphic to xF.}
if Precision(xF) eq OO then
return fldpad_to_fldpadexact(xF);
elif IsPrimeField(xF) then
return ExactpAdicField(Prime(xF));
else
return ExactpAdicField(xF, PrimeField(xF), ExactpAdicField(Prime(xF)) : CheckUnique:=CheckUnique);
end if;
end intrinsic;
///param CheckUnique:=true When `true`, checks that the input is precise enough to determine the field up to isomorphism.
intrinsic ExactpAdicField(xE :: FldPad, xF :: FldPad, F :: FldPadExact : CheckUnique:=true) -> FldPadExact
{Given an extension `xE/xF`, such that xF is parallel-coercible to and from any approximation field of F, returns E such that `E/F` is isomorphic to `xE/xF`. Note that `ext<F | xE, xF>` is shorthand for this.}
require ISEXTOF(xE, xF): "xE must be an extension of xF";
require AbsoluteDegree(xF) eq AbsoluteDegree(F): "Domain of xF must be isomorphic to F";
// base case
if xE eq xF then
return F;
end if;
// simple case
if xF eq F`infinite_precision_approximation then
return fldpad_to_fldpadexact_ext(xE, F);
end if;
// check xE is ok
assert not IsPrimeField(xE);
if CheckUnique then
require isDefinitelyUnique1(xE): "xE is not precise enough to uniquely determine its isomorphism class";
end if;
// recurse on the base field
xE0 := BaseField(xE);
E0 := ExactpAdicField(xE0, xF, F : CheckUnique:=CheckUnique);
// make the defining polynomial
if Precision(xE) eq OO then
e := AbsoluteRamificationDegree(xE);
e0 := AbsoluteRamificationDegree(xE0);
pol := New(RngUPolElt_FldPadExact);
pol`parent := PolynomialRing(E0);
pol`dependencies := [* pol`parent *];
pol`get_approximation := function (n, xR)
locxE0 := xE0;
locxE := xE;
pr := Precision(BaseRing(xR[1]));
locxE0`DefaultPrecision := pr * e0;
locxE`DefaultPrecision := pr * e;
return xR[1] ! DefiningPolynomial(locxE);
end function;
Init(pol);
else
pol := WeakApproximation(PolynomialRing(E0) ! DefiningPolynomial(xE));
end if;
// make the extension
E := ext<E0 | pol>;
return E;
end intrinsic;
///## Creation of p-adic numbers
///### Distinguished elements
/// Zero and one.
intrinsic Zero(F :: FldPadExact) -> FldPadExactElt
{The zero element of F.}
if not assigned F`zero then
z := New(FldPadExactElt);
z`parent := F;
z`dependencies := [* F *];
z`get_approximation := func<n, xds | xds[1] ! 0>;
Init(z);
F`zero := z;
end if;
return F`zero;
end intrinsic;
///ditto
intrinsic One(F :: FldPadExact) -> FldPadExactElt
{The one element of F.}
if not assigned F`one then
F`one := _elt_from_rational(F, 1);
end if;
return F`one;
end intrinsic;
intrinsic Generator(F :: FldPadExact) -> FldPadExactElt
{A generator of F.}
if not assigned F`generator then
g := New(FldPadExactElt);
g`parent := F;
g`dependencies := [* F *];
g`get_approximation := func<n,xF | xF[1].1>;
Init(g);
F`generator := g;
end if;
return F`generator;
end intrinsic;
/// A generator for `E/F`.
///
/// If `E/F` is trivial, this is 0. If unramified, this is a residue generator. If totally ramified, this is a uniformizing element. Otherwise it is the sum of the two.
intrinsic Generator(E :: FldPadExact, F :: FldPadExact) -> FldPadExactElt
{A generator for E/F.}
return Generator(E/F);
end intrinsic;
///hide
intrinsic Generator(X :: ExtFldPadExact) -> FldPadExactElt
{A generator for X.}
if not assigned X`generator then
case #Tower(X):
when 1:
g := Zero(TopField(X));
when 2:
g := Generator(TopField(X));
else
if IsUnramified(X) then
g := ResidueGenerator(TopField(X));
elif IsTotallyRamified(X) then
g := UniformizingElement(TopField(X));
else
g := ResidueGenerator(TopField(X)) + UniformizingElement(TopField(X));
end if;
end case;
X`generator := g;
end if;
return X`generator;
end intrinsic;
intrinsic UniformizingElement(F :: FldPadExact) -> FldPadExactElt
{A uniformizing element of F.}
if not assigned F`uniformizing_element then
case F`xtype:
when PRIME:
pi := _elt_from_rational(F, Prime(F));
when INERT:
pi := F ! UniformizingElement(BaseField(F));
when EISEN:
pi := Generator(F);
else
assert false;
end case;
F`uniformizing_element := pi;
end if;
return F`uniformizing_element;
end intrinsic;
intrinsic ResidueGenerator(F :: FldPadExact) -> FldPadExactElt
{A residue generator of F. That is, an element whose residue class generates the residue class field over its prime subfield.}
if not assigned F`residue_generator then
case F`xtype:
when PRIME:
g := F ! 1;
when INERT:
g := Generator(F);
when EISEN:
g := F ! ResidueGenerator(BaseField(F));
else
assert false;
end case;
F`residue_generator := g;
end if;
return F`residue_generator;
end intrinsic;
/// A generator of F over its prime subfield. Equivalent to `Generator(F, PrimeField(F))`.
intrinsic AbsoluteGenerator(F :: FldPadExact) -> FldPadExactElt
{A generator of F over its prime subfield.}
if not assigned F`absolute_generator then
F`absolute_generator := Generator(F, PrimeField(F));
end if;
return F`absolute_generator;
end intrinsic;
///hide
intrinsic Name(F :: FldPadExact, i :: RngIntElt) -> FldPadExactElt
{The ith generator of F.}
require i eq 1: "i must be 1";
return Generator(F);
end intrinsic;
///hide
intrinsic '.'(F :: FldPadExact, i :: RngIntElt) -> FldPadExactElt
{"}
require i eq 1: "i must be 1";
return Generator(F);
end intrinsic;
///hide
intrinsic NumberOfNames(F :: FldPadExact) -> RngIntElt
{The number of generators of F.}
return 1;
end intrinsic;
///hide
intrinsic AssignNames(~F :: FldPadExact, names :: [MonStgElt])
{Assigns the names to the generators of F.}
case F`xtype:
when INERT, EISEN:
require #names le 1: "names must have length at most 1";
if #names eq 0 then
if assigned F`varname then
delete F`varname;
end if;
else
F`varname := names[1];
end if;
AssignNames(~F`infinite_precision_approximation, F);
for i in [1..#F`approximations] do
AssignNames(~F`approximations[i], F);
end for;
when PRIME:
error "F must be an extension";
else
assert false;
end case;
end intrinsic;
///hide
intrinsic AssignNames(~xF :: FldPad, F :: FldPadExact)
{Assigns the names of xF from F.}
if assigned F`varname then
AssignNames(~xF, [F`varname]);
end if;
end intrinsic;
///hide
intrinsic SetApproximationHook(F :: FldPadExact, n :: RngIntElt, ~xF :: FldPad)
{Called by SetApproximation.}
AssignNames(~xF, F);
end intrinsic;
///### From coefficients
/// *Not implemented.*
///### Coercion
///
/// We can coerce the following to an element of `F`:
/// - An element of `F`
/// - An integer or rational
/// - Anything coercible to the base field of `F`
/// - Anything coercible to a number field that `F` is a completion of
intrinsic IsCoercible(F :: FldPadExact, X) -> BoolElt, .
{True if X is coercible to F. If so, also returns the coerced element.}
if assigned F`completion_map then
ok, Y := IsCoercible(Domain(F`completion_map), X);
if ok then
return true, Y @ F`completion_map;
end if;
end if;
if not IsPrimeField(F) then
ok, Y := IsCoercible(BaseField(F), X);
if ok then
return true, F ! Y;
end if;
end if;
return false, "wrong type";
end intrinsic;
///hide
intrinsic IsCoercible(F :: FldPadExact, X :: FldPadExactElt) -> BoolElt, .
{"}
if Parent(X) eq F then
return true, X;
elif IsExtensionOf(F, Parent(X)) then
e := AbsoluteRamificationDegree(F);
FUDGE := e eq 1 select 0 else 2*e;
x := New(FldPadExactElt);
x`parent := F;
x`dependencies := [* F, X *];
x`get_approximation := func<n, xds | TRIM_PR(xds[1] ! xds[2], FUDGE)>;
Init(x);
return true, x;
else
return false, "not in an extension";
end if;
end intrinsic;
///hide
intrinsic IsCoercible(F :: FldPadExact, X :: RngIntElt) -> BoolElt, .
{"}
return true, elt_from_rational(F, X);
end intrinsic;
///hide
intrinsic IsCoercible(F :: FldPadExact, X :: FldRatElt) -> BoolElt, .
{"}
return true, elt_from_rational(F, X);
end intrinsic;
///hide
intrinsic IsCoercible(F :: FldPadExact, X :: FldPadElt) -> BoolElt, .
{"}
xF := F`infinite_precision_approximation;
ok, xE := ExistsCoveringStructure(xF, Parent(X));
if ok
and AbsoluteDegree(xF) eq AbsoluteDegree(xE)
and AbsoluteDegree(Parent(X)) eq AbsoluteDegree(xE)
and X in xF
then
x := New(FldPadExactElt);
x`parent := F;
x`dependencies := [* F *];
x`get_approximation := func<n, xds | xds[1] ! X>;
Init(x);
IncreaseAbsolutePrecision(x, AbsolutePrecision(X));
return true, x;
else
return false, "not an approximation of an element of F";
end if;
end intrinsic;
///hide
intrinsic IsCoercible(F :: FldPadExact, X :: []) -> BoolElt, .
{"}
if IsPrimeField(F) then
return false, "not an extension";
end if;
ok, cs := CanChangeUniverse(X, BaseField(F));
if not ok then
return false, "not coercible to base field";
end if;
if #cs ne Degree(F) then
return false, "wrong length";
end if;
e := RamificationDegree(F);
FUDGE := e eq 1 select 0 else e;
x := New(FldPadExactElt);
x`parent := F;
x`dependencies := [* F *] cat [* c : c in cs *];
x`get_approximation := func<n, xds | TRIM_PR(xds[1] ! [xds[i] : i in [2..#xds]], FUDGE)>;
Init(x);
return true, x;
end intrinsic;
///### Random
intrinsic RandomInteger(F :: FldPadExact) -> FldPadExactElt
{A random integer of F.}
x := New(FldPadExactElt);
x`parent := F;
x`dependencies := [* F *];
x`get_approximation := function (n, xds)
xF := xds[1];
if #x`approximations eq 0 then
return xF ! Random(Integers(xF));
else
xx := xF ! x`approximations[#x`approximations];
prx := AbsolutePrecision(xx);
assert prx ge 0;
pr := Precision(xF);
prd := pr - prx;
assert prd ge 0;
return CHANGE_APR(xx, pr) + ShiftValuation(xF!Random(Integers(ChangePrecision(xF, prd))), prx);
end if;
end function;
Init(x);
return x;
end intrinsic;
intrinsic RandomUnit(F :: FldPadExact) -> FldPadExactElt
{A random unit of F.}
repeat
x := RandomInteger(F);
until ValuationEq(x, 0);
return x;
end intrinsic;
///## Basic operations
intrinsic Prime(F :: FldPadExact) -> RngIntElt
{The prime of F.}
if not assigned F`prime then
F`prime := Prime(BaseField(F));
end if;
return F`prime;
end intrinsic;
intrinsic DefiningPolynomial(F :: FldPadExact) -> RngUPolElt_FldPadExact
{The defining polynomial of F.}
if not assigned F`defining_polynomial then
case F`xtype:
when INERT, EISEN:
pol := New(RngUPolElt_FldPadExact);
pol`parent := PolynomialRing(BaseField(F));
pol`dependencies := [* F, pol`parent *];
pol`get_approximation := func<n, xds | xds[2] ! DefiningPolynomial(xds[1])>;
Init(pol);
when PRIME:
error "F must be an extension";
else
assert false;
end case;
F`defining_polynomial := pol;
end if;
return F`defining_polynomial;
end intrinsic;
/// A defining polynomial for `E/F`.
///
/// Specifically, it is the minimal polynomial for `Generator(E,F)`. In particular, if the extension is trivial then this is x and if F is the base field of E, then this is `DefiningPolynomial(E)`.
intrinsic DefiningPolynomial(E :: FldPadExact, F :: FldPadExact) -> RngUPolElt_FldPadExact
{A defining polynomial for E/F.}
return DefiningPolynomial(E / F);
end intrinsic;
///hide
intrinsic DefiningPolynomial(X :: ExtFldPadExact) -> RngUPolElt_FldPadExact
{A defining polynomial for X.}
if not assigned X`defining_polynomial then
case #Tower(X):
when 1:
f := PolynomialRing(BaseField(X)) ! [0,1];
when 2:
f := DefiningPolynomial(TopField(X));
else
f := MinimalPolynomialAssumingDegree(AbsoluteGenerator(TopField(X)), BaseField(X), Degree(X));
end case;
X`defining_polynomial := f;
end if;
return X`defining_polynomial;
end intrinsic;
intrinsic Valuation(x :: FldPadExactElt) -> ValFldPadExactElt
{The valuation of x. If x is zero, this will hang.}
if not assigned x`valuation then
if WeakValuation(x) eq OO then
x`valuation := OO;
else
ok := IsDefinitelyNonzero(x);
require ok: "weakly zero";
x`valuation := WeakValuation(x);
end if;
end if;
return x`valuation;
end intrinsic;
///param Minimize:=false When `true`, the returned epoch is minimal.
intrinsic IsDefinitelyNonzero(x :: FldPadExactElt : Minimize:=false) -> BoolElt, RngIntElt
{True if x is nonzero. If so, returns an epoch in which the approximation is nonzero.}
if Minimize then
if not assigned x`min_nonzero_epoch then
ok, n := ExistsEpochWithApproximation(x, func<xx | not IsWeaklyZero(xx)> : Minimize, FromTop);
if ok then
x`min_nonzero_epoch := n;
x`nonzero_epoch := n;
else
return false, _;
end if;
end if;
return true, x`min_nonzero_epoch;
else
if not assigned x`nonzero_epoch then
ok, n := ExistsEpochWithApproximation(x, func<xx | not IsWeaklyZero(xx)> : FromTop);
if ok then
x`nonzero_epoch := n;
else
return false, _;
end if;
end if;
return true, x`nonzero_epoch;
end if;
end intrinsic;
intrinsic Eltseq(x :: FldPadExactElt) -> []
{The coefficients of x as a vector over the base field.}
if not assigned x`eltseq then
E := Parent(x);
if IsPrimeField(E) then
error "x must be in an extension";
end if;
F := BaseField(E);
cs := New(Tup_PadExact);
cs`parent := CartesianPower(F, Degree(E));
cs`dependencies := [* x, F *];
cs`get_approximation := func<n, xds | <xds[2] ! c : c in ELTSEQ(xds[1])>>;
Init(cs);
x`eltseq := cs;
end if;
return ToSequence(x`eltseq);
end intrinsic;
///## Arithmetic
/// Negate, add, subtract, multiply, divide, power, sum and product.
intrinsic '-'(x :: FldPadExactElt) -> FldPadExactElt
{Negation.}
if not assigned x`negation then
y := New(FldPadExactElt);
y`parent := Parent(x);
y`dependencies := [* x *];
y`get_approximation := func<n, xds | -xds[1]>;
Init(y);
x`negation := y;
y`negation := x;
end if;
return x`negation;
end intrinsic;
///ditto
intrinsic '+'(x :: FldPadExactElt, y :: FldPadExactElt) -> FldPadExactElt
{Add.}
ok, F := ExistsCoveringStructure(Parent(x), Parent(y));
require ok: "different fields";
return &+[F|x,y];
end intrinsic;
///hide
intrinsic '+'(x :: FldPadExactElt, y) -> .
{"}
return do_binop('+', x, y);
end intrinsic;
///hide
intrinsic '+'(x, y :: FldPadExactElt) -> .
{"}
return do_binop('+', x, y);
end intrinsic;
///ditto
intrinsic '-'(x :: FldPadExactElt, y :: FldPadExactElt) -> FldPadExactElt
{Subtract.}
ok, F := ExistsCoveringStructure(Parent(x), Parent(y));
require ok: "different fields";
r := New(FldPadExactElt);
r`parent := F;
r`dependencies := [* F!x, F!y *];
r`get_approximation := func<n, xds | xds[1] - xds[2]>;
Init(r);
return r;
end intrinsic;
///hide
intrinsic '-'(x :: FldPadExactElt, y) -> .
{"}
return do_binop('-', x, y);
end intrinsic;
///hide
intrinsic '-'(x, y :: FldPadExactElt) -> .
{"}
return do_binop('-', x, y);
end intrinsic;
///ditto
intrinsic '*'(x :: FldPadExactElt, y :: FldPadExactElt) -> FldPadExactElt
{Multiply.}
ok, F := ExistsCoveringStructure(Parent(x), Parent(y));
require ok: "different fields";
return &*[F|x,y];
end intrinsic;
///hide
intrinsic '*'(x :: FldPadExactElt, y) -> .
{"}
return do_binop('*', x, y);
end intrinsic;
///hide
intrinsic '*'(x, y :: FldPadExactElt) -> .
{"}
return do_binop('*', x, y);
end intrinsic;
///ditto
///param Safe:=false (Divide and power only.) When true, this may be used as an intermediate variable in [`WithDependencies`]({{site.baseurl}}/internals#WithDependencies) with the `Fast` option.
intrinsic '/'(x :: FldPadExactElt, y :: FldPadExactElt : Safe:=false) -> FldPadExactElt
{Divide.}
ok, F := ExistsCoveringStructure(Parent(x), Parent(y));
require ok: "different fields";
x2 := F ! x;
y2 := F ! y;
r := New(FldPadExactElt);
if Safe then
ok, n := IsDefinitelyNonzero(y : Minimize);
require ok: "y is weakly zero";
r`min_epoch := n;
else
EnsureAllApproximationsNonzero(y2);
end if;
r`parent := F;
r`dependencies := [* x2, y2 *];
r`get_approximation := func<n, xds | xds[1] / xds[2]>;
Init(r);
return r;
end intrinsic;
///hide
intrinsic '/'(x :: FldPadExactElt, y) -> .
{"}
return do_binop('/', x, y);
end intrinsic;
///hide
intrinsic '/'(x, y :: FldPadExactElt) -> .
{"}
return do_binop('/', x, y);
end intrinsic;
///ditto
intrinsic '^'(x :: FldPadExactElt, m :: RngIntElt : Safe:=false) -> FldPadExactElt
{Power.}
F := Parent(x);
if m eq 0 then
return One(F);
end if;
r := New(FldPadExactElt);
if m lt 0 then
if Safe then
ok, n := IsDefinitelyNonzero(x);
require ok: "x is weakly zero";
r`min_epoch := n;
else
EnsureAllApproximationsNonzero(x);
end if;
end if;
r`parent := F;
r`dependencies := [* x *];
r`get_approximation := func<n, xds | xds[1]^m>;
Init(r);
return r;
end intrinsic;
///ditto