This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
function_field.py
1689 lines (1324 loc) · 55.9 KB
/
function_field.py
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
"""
Function Fields
AUTHORS:
- William Stein (2010): initial version
- Robert Bradshaw (2010-05-30): added is_finite()
- Julian Rueth (2011-06-08, 2011-09-14, 2014-06-23): fixed hom(), extension();
use @cached_method; added derivation()
- Maarten Derickx (2011-09-11): added doctests
- Syed Ahmad Lavasani (2011-12-16): added genus(), is_RationalFunctionField()
- Simon King (2014-10-29): Use the same generator names for a function field
extension and the underlying polynomial ring.
EXAMPLES:
We create an extension of a rational function fields, and do some
simple arithmetic in it::
sage: K.<x> = FunctionField(GF(5^2,'a')); K
Rational function field in x over Finite Field in a of size 5^2
sage: R.<y> = K[]
sage: L.<y> = K.extension(y^3 - (x^3 + 2*x*y + 1/x)); L
Function field in y defined by y^3 + 3*x*y + (4*x^4 + 4)/x
sage: y^2
y^2
sage: y^3
2*x*y + (x^4 + 1)/x
sage: a = 1/y; a
(4*x/(4*x^4 + 4))*y^2 + 2*x^2/(4*x^4 + 4)
sage: a * y
1
We next make an extension of the above function field, illustrating
that arithmetic with a tower of 3 fields is fully supported::
sage: S.<t> = L[]
sage: M.<t> = L.extension(t^2 - x*y)
sage: M
Function field in t defined by t^2 + 4*x*y
sage: t^2
x*y
sage: 1/t
((1/(x^4 + 1))*y^2 + 2*x/(4*x^4 + 4))*t
sage: M.base_field()
Function field in y defined by y^3 + 3*x*y + (4*x^4 + 4)/x
sage: M.base_field().base_field()
Rational function field in x over Finite Field in a of size 5^2
It is also possible to work with function fields over an imperfect base field::
sage: N.<u> = FunctionField(K)
Function field extensions can be inseparable::
sage: R.<v> = K[]
sage: O.<v> = K.extension(v^5 - x)
TESTS::
sage: TestSuite(K).run()
sage: TestSuite(L).run() # long time (8s on sage.math, 2012)
sage: TestSuite(M).run() # long time (52s on sage.math, 2012)
sage: TestSuite(N).run() # long time
sage: TestSuite(O).run() # long time
The following two test suites do not pass ``_test_elements`` yet since
``R.an_element()`` has a ``_test_category`` method wich it should not have.
It is not the fault of the function field code so this will
be fixed in another ticket::
sage: TestSuite(R).run(skip = '_test_elements')
sage: TestSuite(S).run(skip = '_test_elements')
"""
#*****************************************************************************
# Copyright (C) 2010 William Stein <wstein@gmail.com>
# Copyright (C) 2010 Robert Bradshaw <robertwb@math.washington.edu>
# Copyright (C) 2011-2014 Julian Rueth <julian.rueth@gmail.com>
# Copyright (C) 2011 Maarten Derickx <m.derickx.student@gmail.com>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# http://www.gnu.org/licenses/
#*****************************************************************************
from sage.rings.ring import Field
from function_field_element import FunctionFieldElement, FunctionFieldElement_rational, FunctionFieldElement_polymod
from sage.misc.cachefunc import cached_method
#is needed for genus computation
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.interfaces.all import singular
from sage.categories.function_fields import FunctionFields
CAT = FunctionFields()
def is_FunctionField(x):
"""
Return True if ``x`` is of function field type.
EXAMPLES::
sage: from sage.rings.function_field.function_field import is_FunctionField
sage: is_FunctionField(QQ)
False
sage: is_FunctionField(FunctionField(QQ,'t'))
True
"""
if isinstance(x, FunctionField): return True
return x in FunctionFields()
class FunctionField(Field):
"""
The abstract base class for all function fields.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: isinstance(K, sage.rings.function_field.function_field.FunctionField)
True
"""
def is_perfect(self):
r"""
Return whether this field is perfect, i.e., its characteristic is `p=0`
or every element has a `p`-th root.
EXAMPLES::
sage: FunctionField(QQ, 'x').is_perfect()
True
sage: FunctionField(GF(2), 'x').is_perfect()
False
"""
return self.characteristic() == 0
def some_elements(self):
"""
Return a list of elements in the function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: elements = K.some_elements()
sage: elements # random output
[(x - 3/2)/(x^2 - 12/5*x + 1/18)]
sage: False in [e in K for e in elements]
False
"""
return [self.random_element(), self.random_element(), self.random_element()]
def characteristic(self):
"""
Return the characteristic of this function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: K.characteristic()
0
sage: K.<x> = FunctionField(GF(7))
sage: K.characteristic()
7
sage: R.<y> = K[]
sage: L.<y> = K.extension(y^2 - x)
sage: L.characteristic()
7
"""
return self.constant_base_field().characteristic()
def is_finite(self):
"""
Return whether this function field is finite, which it is not.
EXAMPLES::
sage: R.<t> = FunctionField(QQ)
sage: R.is_finite()
False
sage: R.<t> = FunctionField(GF(7))
sage: R.is_finite()
False
"""
return False
def extension(self, f, names=None):
"""
Create an extension L = K[y]/(f(y)) of a function field,
defined by a univariate polynomial in one variable over this
function field K.
INPUT:
- ``f`` -- a univariate polynomial over self
- ``names`` -- None or string or length-1 tuple
OUTPUT:
- a function field
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: K.extension(y^5 - x^3 - 3*x + x*y)
Function field in y defined by y^5 + x*y - x^3 - 3*x
A nonintegral defining polynomial::
sage: K.<t> = FunctionField(QQ); R.<y> = K[]
sage: K.extension(y^3 + (1/t)*y + t^3/(t+1))
Function field in y defined by y^3 + 1/t*y + t^3/(t + 1)
The defining polynomial need not be monic or integral::
sage: K.extension(t*y^3 + (1/t)*y + t^3/(t+1))
Function field in y defined by t*y^3 + 1/t*y + t^3/(t + 1)
"""
from constructor import FunctionField_polymod as FunctionField_polymod_Constructor
return FunctionField_polymod_Constructor(f, names)
def order_with_basis(self, basis, check=True):
"""
Return the order with given basis over the maximal order of
the base field.
INPUT:
- ``basis`` -- a list of elements of self
- ``check`` -- bool (default: True); if True, check that
the basis is really linearly independent and that the
module it spans is closed under multiplication, and
contains the identity element.
OUTPUT:
- an order in this function field
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1)
sage: O = L.order_with_basis([1, y, y^2]); O
Order in Function field in y defined by y^3 + x^3 + 4*x + 1
sage: O.basis()
(1, y, y^2)
Note that 1 does not need to be an element of the basis, as long it is in the module spanned by it::
sage: O = L.order_with_basis([1+y, y, y^2]); O
Order in Function field in y defined by y^3 + x^3 + 4*x + 1
sage: O.basis()
(y + 1, y, y^2)
The following error is raised when the module spanned by the basis is not closed under multiplication::
sage: O = L.order_with_basis([1, x^2 + x*y, (2/3)*y^2]); O
Traceback (most recent call last):
...
ValueError: The module generated by basis [1, x*y + x^2, 2/3*y^2] must be closed under multiplication
and this happens when the identity is not in the module spanned by the basis::
sage: O = L.order_with_basis([x, x^2 + x*y, (2/3)*y^2])
Traceback (most recent call last):
...
ValueError: The identity element must be in the module spanned by basis [x, x*y + x^2, 2/3*y^2]
"""
from function_field_order import FunctionFieldOrder_basis
return FunctionFieldOrder_basis([self(a) for a in basis], check=check)
def order(self, x, check=True):
"""
Return the order in this function field generated over the
maximal order by x or the elements of x if x is a list.
INPUT:
- ``x`` -- element of self, or a list of elements of self
- ``check`` -- bool (default: True); if True, check that
x really generates an order
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1)
sage: O = L.order(y); O
Order in Function field in y defined by y^3 + x^3 + 4*x + 1
sage: O.basis()
(1, y, y^2)
sage: Z = K.order(x); Z
Order in Rational function field in x over Rational Field
sage: Z.basis()
(1,)
Orders with multiple generators, not yet supported::
sage: Z = K.order([x,x^2]); Z
Traceback (most recent call last):
...
NotImplementedError
"""
if not isinstance(x, (list, tuple)):
x = [x]
if len(x) == 1:
g = x[0]
basis = [self(1)]
for i in range(self.degree()-1):
basis.append(basis[-1]*g)
else:
raise NotImplementedError
return self.order_with_basis(basis, check=check)
def _coerce_map_from_(self, R):
"""
Return True if there is a coerce map from R to self.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<y> = K.extension(y^3 + x^3 + 4*x + 1)
sage: L.equation_order()
Order in Function field in y defined by y^3 + x^3 + 4*x + 1
sage: L._coerce_map_from_(L.equation_order())
True
sage: L._coerce_map_from_(GF(7))
False
"""
from function_field_order import FunctionFieldOrder
if isinstance(R, FunctionFieldOrder) and R.fraction_field() == self:
return True
return False
def _test_derivation(self, **options):
r"""
Test the correctness of the derivations of this function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: TestSuite(K).run() # indirect doctest
"""
tester = self._tester(**options)
S = tester.some_elements()
K = self.constant_base_field().some_elements()
try:
d = self.derivation()
except NotImplementedError:
return # some function fields no not implement derivation() yet
from sage.combinat.cartesian_product import CartesianProduct
# Leibniz's law
for x,y in tester.some_elements(CartesianProduct(S, S)):
tester.assert_(d(x*y) == x*d(y) + d(x)*y)
# Linearity
for x,y in tester.some_elements(CartesianProduct(S, S)):
tester.assert_(d(x+y) == d(x) + d(y))
for c,x in tester.some_elements(CartesianProduct(K, S)):
tester.assert_(d(c*x) == c*d(x))
# Constants map to zero
for c in tester.some_elements(K):
tester.assert_(d(c) == 0)
class FunctionField_polymod(FunctionField):
"""
A function field defined by a univariate polynomial, as an
extension of the base field.
EXAMPLES:
We make a function field defined by a degree 5 polynomial over the
rational function field over the rational numbers::
sage: K.<x> = FunctionField(QQ)
sage: R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x)); L
Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
We next make a function field over the above nontrivial function
field L::
sage: S.<z> = L[]
sage: M.<z> = L.extension(z^2 + y*z + y); M
Function field in z defined by z^2 + y*z + y
sage: 1/z
((x/(-x^4 - 1))*y^4 - 2*x^2/(-x^4 - 1))*z - 1
sage: z * (1/z)
1
We drill down the tower of function fields::
sage: M.base_field()
Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
sage: M.base_field().base_field()
Rational function field in x over Rational Field
sage: M.base_field().base_field().constant_field()
Rational Field
sage: M.constant_base_field()
Rational Field
.. WARNING::
It is not checked if the polynomial used to define this function field is irreducible
Hence it is not guaranteed that this object really is a field!
This is illustrated below.
::
sage: K.<x>=FunctionField(QQ)
sage: R.<y> = K[]
sage: L.<y>=K.extension(x^2-y^2)
sage: (y-x)*(y+x)
0
sage: 1/(y-x)
1
sage: y-x==0; y+x==0
False
False
"""
def __init__(self, polynomial, names,
element_class = FunctionFieldElement_polymod,
category=CAT):
"""
Create a function field defined as an extension of another
function field by adjoining a root of a univariate polynomial.
INPUT:
- ``polynomial`` -- a univariate polynomial over a function field
- ``names`` -- variable names (as a tuple of length 1 or string)
- ``category`` -- a category (defaults to category of function fields)
EXAMPLES:
We create an extension of a function field::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L = K.extension(y^5 - x^3 - 3*x + x*y); L
Function field in y defined by y^5 + x*y - x^3 - 3*x
Note the type::
sage: type(L)
<class 'sage.rings.function_field.function_field.FunctionField_polymod_with_category'>
We can set the variable name, which doesn't have to be y::
sage: L.<w> = K.extension(y^5 - x^3 - 3*x + x*y); L
Function field in w defined by w^5 + x*w - x^3 - 3*x
TESTS:
Test that :trac:`17033` is fixed::
sage: K.<t> = FunctionField(QQ)
sage: R.<x> = QQ[]
sage: M.<z> = K.extension(x^7-x-t)
sage: M(x)
z
sage: M('z')
z
sage: M('x')
Traceback (most recent call last):
...
TypeError: unable to evaluate 'x' in Fraction Field of Univariate Polynomial Ring in t over Rational Field
"""
from sage.rings.polynomial.polynomial_element import is_Polynomial
if polynomial.parent().ngens()>1 or not is_Polynomial(polynomial):
raise TypeError("polynomial must be univariate a polynomial")
if names is None:
names = (polynomial.variable_name(), )
elif names != polynomial.variable_name():
polynomial = polynomial.change_variable_name(names)
if polynomial.degree() <= 0:
raise ValueError("polynomial must have positive degree")
base_field = polynomial.base_ring()
if not isinstance(base_field, FunctionField):
raise TypeError("polynomial must be over a FunctionField")
self._element_class = element_class
self._element_init_pass_parent = False
self._base_field = base_field
self._polynomial = polynomial
Field.__init__(self, base_field,
names=names, category = category)
self._hash = hash(polynomial)
self._ring = self._polynomial.parent()
self._populate_coercion_lists_(coerce_list=[base_field, self._ring])
self._gen = self(self._ring.gen())
def __reduce__(self):
"""
Returns the arguments which were used to create this instance. The rationale for this is explained in the documentation of ``UniqueRepresentation``.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L = K.extension(y^2 - x)
sage: clazz,args = L.__reduce__()
sage: clazz(*args)
Function field in y defined by y^2 - x
"""
from constructor import FunctionField_polymod as FunctionField_polymod_Constructor
return FunctionField_polymod_Constructor, (self._polynomial, self._names)
def __hash__(self):
"""
Return hash of this function field.
The hash value is equal to the hash of the defining polynomial.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L = K.extension(y^5 - x^3 - 3*x + x*y)
sage: hash(L) == hash(L.polynomial())
True
"""
return self._hash
def monic_integral_model(self, names):
"""
Return a function field isomorphic to self, but with defining
polynomial that is monic and integral over the base field.
INPUT:
- ``names`` -- name of the generator of the new field this function constructs
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(x^2*y^5 - 1/x); L
Function field in y defined by x^2*y^5 - 1/x
sage: A, from_A, to_A = L.monic_integral_model('z')
sage: A
Function field in z defined by z^5 - x^12
sage: from_A
Function Field morphism:
From: Function field in z defined by z^5 - x^12
To: Function field in y defined by x^2*y^5 - 1/x
Defn: z |--> x^3*y
sage: to_A
Function Field morphism:
From: Function field in y defined by x^2*y^5 - 1/x
To: Function field in z defined by z^5 - x^12
Defn: y |--> 1/x^3*z
sage: to_A(y)
1/x^3*z
sage: from_A(to_A(y))
y
sage: from_A(to_A(1/y))
x^3*y^4
sage: from_A(to_A(1/y)) == 1/y
True
"""
g, d = self._make_monic_integral(self.polynomial())
R = self.base_field()
K = R.extension(g, names=names)
to_K = self.hom(K.gen() / d)
from_K = K.hom(self.gen() * d)
return K, from_K, to_K
def _make_monic_integral(self, f):
r"""
Let y be a root of ``f``. This function returns a monic
integral polynomial g and an element d of the base field such
that g(y*d)=0.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[];
sage: L.<y> = K.extension(x^2*y^5 - 1/x)
sage: g, d = L._make_monic_integral(L.polynomial()); g,d
(y^5 - x^12, x^3)
sage: (y*d).is_integral()
True
sage: g.is_monic()
True
sage: g(y*d)
0
"""
R = f.base_ring()
if not isinstance(R, RationalFunctionField):
raise NotImplementedError
# make f monic
n = f.degree()
c = f.leading_coefficient()
if c != 1:
f = f / c
# find lcm of denominators
from sage.rings.arith import lcm
# would be good to replace this by minimal...
d = lcm([b.denominator() for b in f.list() if b])
if d != 1:
x = f.parent().gen()
g = (d**n) * f(x/d)
else:
g = f
return g, d
def constant_field(self):
"""
Return the algebraic closure of the constant field of the base
field in this function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.constant_field()
Traceback (most recent call last):
...
NotImplementedError
"""
raise NotImplementedError
def constant_base_field(self):
"""
Return the constant field of the base rational function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x)); L
Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
sage: L.constant_base_field()
Rational Field
sage: S.<z> = L[]
sage: M.<z> = L.extension(z^2 - y)
sage: M.constant_base_field()
Rational Field
"""
return self.base_field().constant_base_field()
def degree(self):
"""
Return the degree of this function field over its base
function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ)
sage: R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x)); L
Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
sage: L.degree()
5
"""
return self._polynomial.degree()
def _repr_(self):
"""
Return string representation of this function field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L._repr_()
'Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x'
"""
return "Function field in %s defined by %s"%(self.variable_name(), self._polynomial)
def base_field(self):
"""
Return the base field of this function field. This function
field is presented as L = K[y]/(f(y)), and the base field is
by definition the field K.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.base_field()
Rational function field in x over Rational Field
"""
return self._base_field
def random_element(self, *args, **kwds):
"""
Create a random element of this function field. Parameters
are passed onto the random_element method of the base_field.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^2 - (x^2 + x))
sage: L.random_element() # random
((x^2 - x + 2/3)/(x^2 + 1/3*x - 1))*y^2 + ((-1/4*x^2 + 1/2*x - 1)/(-5/2*x + 2/3))*y + (-1/2*x^2 - 4)/(-12*x^2 + 1/2*x - 1/95)
"""
return self(self._ring.random_element(degree=self.degree(), *args, **kwds))
def polynomial(self):
"""
Return the univariate polynomial that defines this function
field, i.e., the polynomial f(y) so that this function field
is of the form K[y]/(f(y)).
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.polynomial()
y^5 - 2*x*y + (-x^4 - 1)/x
"""
return self._polynomial
def polynomial_ring(self):
"""
Return the polynomial ring used to represent elements of this
function field. If we view this function field as being presented
as K[y]/(f(y)), then this function returns the ring K[y].
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.polynomial_ring()
Univariate Polynomial Ring in y over Rational function field in x over Rational Field
"""
return self._ring
@cached_method
def vector_space(self):
"""
Return a vector space V and isomorphisms self --> V and V --> self.
This function allows us to identify the elements of self with
elements of a vector space over the base field, which is
useful for representation and arithmetic with orders, ideals,
etc.
OUTPUT:
- ``V`` -- a vector space over base field
- ``from_V`` -- an isomorphism from V to self
- ``to_V`` -- an isomorphism from self to V
EXAMPLES:
We define a function field::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x)); L
Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
We get the vector spaces, and maps back and forth::
sage: V, from_V, to_V = L.vector_space()
sage: V
Vector space of dimension 5 over Rational function field in x over Rational Field
sage: from_V
Isomorphism morphism:
From: Vector space of dimension 5 over Rational function field in x over Rational Field
To: Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
sage: to_V
Isomorphism morphism:
From: Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
To: Vector space of dimension 5 over Rational function field in x over Rational Field
We convert an element of the vector space back to the function field::
sage: from_V(V.1)
y
We define an interesting element of the function field::
sage: a = 1/L.0; a
(-x/(-x^4 - 1))*y^4 + 2*x^2/(-x^4 - 1)
We convert it to the vector space, and get a vector over the base field::
sage: to_V(a)
(2*x^2/(-x^4 - 1), 0, 0, 0, -x/(-x^4 - 1))
We convert to and back, and get the same element::
sage: from_V(to_V(a)) == a
True
In the other direction::
sage: v = x*V.0 + (1/x)*V.1
sage: to_V(from_V(v)) == v
True
And we show how it works over an extension of an extension field::
sage: R2.<z> = L[]; M.<z> = L.extension(z^2 -y)
sage: M.vector_space()
(Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x, Isomorphism morphism:
From: Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x
To: Function field in z defined by z^2 - y, Isomorphism morphism:
From: Function field in z defined by z^2 - y
To: Vector space of dimension 2 over Function field in y defined by y^5 - 2*x*y + (-x^4 - 1)/x)
"""
V = self.base_field()**self.degree()
from maps import MapVectorSpaceToFunctionField, MapFunctionFieldToVectorSpace
from_V = MapVectorSpaceToFunctionField(V, self)
to_V = MapFunctionFieldToVectorSpace(self, V)
return (V, from_V, to_V)
def maximal_order(self):
"""
Return the maximal_order of self. If we view self as L =
K[y]/(f(y)), then this is the ring of elements of L that are
integral over K.
EXAMPLES:
This is not yet implemented...::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.maximal_order()
Traceback (most recent call last):
...
NotImplementedError
"""
raise NotImplementedError
def _element_constructor_(self, x):
r"""
Make ``x`` into an element of this function field, possibly not canonically.
INPUT:
- ``x`` -- the element
OUTPUT:
``x``, as an element of this function field
TESTS::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L._element_constructor_(L.polynomial_ring().gen())
y
"""
if isinstance(x, FunctionFieldElement):
return FunctionFieldElement_polymod(self, self._ring(x.element()))
return FunctionFieldElement_polymod(self, self._ring(x))
def gen(self, n=0):
"""
Return the ``n``-th generator of this function field. By default ``n`` is 0; any other
value of ``n`` leads to an error. The generator is the class of y, if we view
self as being presented as K[y]/(f(y)).
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.gen()
y
sage: L.gen(1)
Traceback (most recent call last):
...
IndexError: Only one generator.
"""
if n != 0: raise IndexError("Only one generator.")
return self._gen
def ngens(self):
"""
Return the number of generators of this function field over
its base field. This is by definition 1.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: L.ngens()
1
"""
return 1
def equation_order(self):
"""
If we view self as being presented as K[y]/(f(y)), then this
function returns the order generated by the class of y. If f
is not monic, then :meth:`_make_monic_integral` is called, and instead we
get the order generated by some integral multiple of a root of f.
EXAMPLES::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
sage: O = L.equation_order()
sage: O.basis()
(1, x*y, x^2*y^2, x^3*y^3, x^4*y^4)
We try an example, in which the defining polynomial is not
monic and is not integral::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(x^2*y^5 - 1/x); L
Function field in y defined by x^2*y^5 - 1/x
sage: O = L.equation_order()
sage: O.basis()
(1, x^3*y, x^6*y^2, x^9*y^3, x^12*y^4)
"""
d = self._make_monic_integral(self.polynomial())[1]
return self.order(d*self.gen(), check=False)
def hom(self, im_gens, base_morphism=None):
"""
Create a homomorphism from self to another function field.
INPUT:
- ``im_gens`` -- a list of images of the generators of self
and of successive base rings.
- ``base_morphism`` -- (default: None) a homomorphism of
the base ring, after the im_gens are used. Thus if
im_gens has length 2, then base_morphism should be a morphism
from self.base_ring().base_ring().
EXAMPLES:
We create a rational function field, and a quadratic extension of it::
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
sage: L.<y> = K.extension(y^2 - x^3 - 1)
We make the field automorphism that sends y to -y::
sage: f = L.hom(-y); f
Function Field endomorphism of Function field in y defined by y^2 - x^3 - 1
Defn: y |--> -y
Evaluation works::
sage: f(y*x - 1/x)
-x*y - 1/x
We try to define an invalid morphism::
sage: f = L.hom(y+1)
Traceback (most recent call last):
...
ValueError: invalid morphism
We make a morphism of the base rational function field::
sage: phi = K.hom(x+1); phi
Function Field endomorphism of Rational function field in x over Rational Field
Defn: x |--> x + 1
sage: phi(x^3 - 3)
x^3 + 3*x^2 + 3*x - 2
sage: (x+1)^3-3
x^3 + 3*x^2 + 3*x - 2
We make a morphism by specifying where the generators and the
base generators go::
sage: L.hom([-y, x])
Function Field endomorphism of Function field in y defined by y^2 - x^3 - 1
Defn: y |--> -y
x |--> x
The usage of the keyword base_morphism is not implemented yet::
sage: L.hom([-y, x-1], base_morphism=phi)
Traceback (most recent call last):
...
NotImplementedError: Function field homorphisms with optional argument base_morphism are not implemented yet. Please specify the images of the generators of the base fields manually.
We make another extension of a rational function field::
sage: K2.<t> = FunctionField(QQ); R2.<w> = K2[]
sage: L2.<w> = K2.extension((4*w)^2 - (t+1)^3 - 1)
We define a morphism, by giving the images of generators::
sage: f = L.hom([4*w, t+1]); f
Function Field morphism:
From: Function field in y defined by y^2 - x^3 - 1
To: Function field in w defined by 16*w^2 - t^3 - 3*t^2 - 3*t - 2
Defn: y |--> 4*w
x |--> t + 1
Evaluation works, as expected::
sage: f(y+x)
4*w + t + 1
sage: f(x*y + x/(x^2+1))
(4*t + 4)*w + (t + 1)/(t^2 + 2*t + 2)