Skip to content

Commit c93ee11

Browse files
author
Release Manager
committed
gh-39558: cleaning the maximal orders in rational function fields in particular, removing the nonsensical `gen` and `ngens` methods in the maximal infinite order. also general pep8 cleanup of the modified file + some typing annotations ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #39558 Reported by: Frédéric Chapoton Reviewer(s): Frédéric Chapoton, Kwankyu Lee
2 parents 95045c1 + 9cb2a07 commit c93ee11

File tree

1 file changed

+69
-70
lines changed

1 file changed

+69
-70
lines changed

src/sage/rings/function_field/order_rational.py

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Distributed under the terms of the GNU General Public License (GPL)
1313
# as published by the Free Software Foundation; either version 2 of
1414
# the License, or (at your option) any later version.
15-
# http://www.gnu.org/licenses/
15+
# https://www.gnu.org/licenses/
1616
# ****************************************************************************
1717

1818
import sage.rings.abc
@@ -43,7 +43,7 @@ class FunctionFieldMaximalOrder_rational(FunctionFieldMaximalOrder):
4343
sage: R = K.maximal_order(); R
4444
Maximal order of Rational function field in t over Finite Field of size 19
4545
"""
46-
def __init__(self, field):
46+
def __init__(self, field) -> None:
4747
"""
4848
Initialize.
4949
@@ -59,8 +59,8 @@ def __init__(self, field):
5959
self._populate_coercion_lists_(coerce_list=[field._ring])
6060

6161
self._ring = field._ring
62-
self._gen = self(self._ring.gen())
63-
self._basis = (self.one(),)
62+
self._gen = self(self._ring.gen()) # generator as a ring
63+
self._basis = (self.one(),) # basis as a module over itself
6464

6565
def _element_constructor_(self, f):
6666
"""
@@ -72,10 +72,12 @@ def _element_constructor_(self, f):
7272
sage: O = K.maximal_order()
7373
sage: O._element_constructor_(y)
7474
y
75+
7576
sage: O._element_constructor_(1/y)
7677
Traceback (most recent call last):
7778
...
78-
TypeError: 1/y is not an element of Maximal order of Rational function field in y over Rational Field
79+
TypeError: 1/y is not an element of Maximal order of
80+
Rational function field in y over Rational Field
7981
"""
8082
F = self.function_field()
8183
try:
@@ -84,7 +86,7 @@ def _element_constructor_(self, f):
8486
raise TypeError("unable to convert to an element of {}".format(F))
8587

8688
if f.denominator() not in self.function_field().constant_base_field():
87-
raise TypeError("%r is not an element of %r" % (f,self))
89+
raise TypeError("%r is not an element of %r" % (f, self))
8890

8991
return f
9092

@@ -98,10 +100,11 @@ def ideal_with_gens_over_base(self, gens):
98100
99101
EXAMPLES::
100102
103+
sage: # needs sage.rings.function_field
101104
sage: K.<x> = FunctionField(QQ); R.<y> = K[]
102-
sage: L.<y> = K.extension(y^2 - x^3 - 1) # needs sage.rings.function_field
103-
sage: O = L.equation_order() # needs sage.rings.function_field
104-
sage: O.ideal_with_gens_over_base([x^3 + 1, -y]) # needs sage.rings.function_field
105+
sage: L.<y> = K.extension(y^2 - x^3 - 1)
106+
sage: O = L.equation_order()
107+
sage: O.ideal_with_gens_over_base([x^3 + 1, -y])
105108
Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 1
106109
"""
107110
return self.ideal(gens)
@@ -110,8 +113,9 @@ def _residue_field(self, ideal, name=None):
110113
"""
111114
Return a field isomorphic to the residue field at the prime ideal.
112115
113-
The residue field is by definition `k[x]/q` where `q` is the irreducible
114-
polynomial generating the prime ideal and `k` is the constant base field.
116+
The residue field is by definition `k[x]/q` where `q` is the
117+
irreducible polynomial generating the prime ideal and `k` is
118+
the constant base field.
115119
116120
INPUT:
117121
@@ -299,7 +303,7 @@ def _residue_field_global(self, q, name=None):
299303
# extend the base field to a field of degree r*s over the
300304
# prime field
301305
s = q.degree()
302-
K,sigma = k.extension(s, map=True, name=name)
306+
K, sigma = k.extension(s, map=True, name=name)
303307

304308
# find a root beta in K satisfying the irreducible q
305309
S = K['X']
@@ -328,20 +332,22 @@ def to_K(f):
328332
coeffs = (f % q).list()
329333
return sum((sigma(c) * beta_pow[i] for i, c in enumerate(coeffs)), K.zero())
330334

331-
if r == 1: # take care of the prime field case
335+
if r == 1: # take care of the prime field case
332336
def fr_K(g):
333337
co = W.coordinates(V(g), check=False)
334338
return R([k(co[j]) for j in range(s)])
335339
else:
336340
def fr_K(g):
337341
co = W.coordinates(V(g), check=False)
338-
return R([k(co[i:i+r]) for i in range(0, r*s, r)])
342+
return R([k(co[i:i + r]) for i in range(0, r * s, r)])
339343

340344
return K, fr_K, to_K
341345

342-
def basis(self):
346+
def basis(self) -> tuple:
343347
"""
344-
Return the basis (=1) of the order as a module over the polynomial ring.
348+
Return the basis of the order as a module over the polynomial ring.
349+
350+
This is the tuple (1,).
345351
346352
EXAMPLES::
347353
@@ -354,13 +360,18 @@ def basis(self):
354360

355361
def gen(self, n=0):
356362
"""
357-
Return the ``n``-th generator of the order. Since there is only one generator ``n`` must be 0.
363+
Return the ``n``-th generator of the order.
364+
365+
Since there is only one generator ``n`` must be 0.
358366
359367
EXAMPLES::
360368
361369
sage: O = FunctionField(QQ,'y').maximal_order()
362370
sage: O.gen()
363371
y
372+
373+
TESTS::
374+
364375
sage: O.gen(1)
365376
Traceback (most recent call last):
366377
...
@@ -370,9 +381,11 @@ def gen(self, n=0):
370381
raise IndexError("there is only one generator")
371382
return self._gen
372383

373-
def ngens(self):
384+
def ngens(self) -> int:
374385
"""
375-
Return 1 the number of generators of the order.
386+
Return the number of generators of the order.
387+
388+
This is 1.
376389
377390
EXAMPLES::
378391
@@ -413,12 +426,12 @@ def ideal(self, *gens):
413426
gens = (gens,)
414427
K = self.function_field()
415428
gens = [K(e) for e in gens if e != 0]
416-
if len(gens) == 0:
417-
gen = K(0)
429+
if not gens:
430+
gen = K.zero()
418431
else:
419432
d = lcm([c.denominator() for c in gens]).monic()
420-
g = gcd([(d*c).numerator() for c in gens]).monic()
421-
gen = K(g/d)
433+
g = gcd([(d * c).numerator() for c in gens]).monic()
434+
gen = K(g / d)
422435

423436
return self.ideal_monoid().element_class(self, gen)
424437

@@ -438,7 +451,7 @@ class FunctionFieldMaximalOrderInfinite_rational(FunctionFieldMaximalOrderInfini
438451
sage: R = K.maximal_order_infinite(); R
439452
Maximal infinite order of Rational function field in t over Finite Field of size 19
440453
"""
441-
def __init__(self, field, category=None):
454+
def __init__(self, field, category=None) -> None:
442455
"""
443456
Initialize.
444457
@@ -447,6 +460,10 @@ def __init__(self, field, category=None):
447460
sage: K.<t> = FunctionField(GF(19))
448461
sage: O = K.maximal_order_infinite()
449462
sage: TestSuite(O).run(skip='_test_gcd_vs_xgcd')
463+
464+
sage: K.<t> = FunctionField(QQ)
465+
sage: O = K.maximal_order_infinite()
466+
sage: TestSuite(O).run(skip='_test_gcd_vs_xgcd')
450467
"""
451468
FunctionFieldMaximalOrderInfinite.__init__(self, field, ideal_class=FunctionFieldIdealInfinite_rational,
452469
category=PrincipalIdealDomains().or_subcategory(category))
@@ -458,14 +475,16 @@ def _element_constructor_(self, f):
458475
459476
EXAMPLES::
460477
461-
sage: K.<y> = FunctionField(QQ)
462-
sage: O = K.maximal_order()
463-
sage: O._element_constructor_(y)
464-
y
478+
sage: K.<y> = FunctionField(GF(7))
479+
sage: O = K.maximal_order_infinite()
465480
sage: O._element_constructor_(1/y)
481+
1/y
482+
483+
sage: O._element_constructor_(y)
466484
Traceback (most recent call last):
467485
...
468-
TypeError: 1/y is not an element of Maximal order of Rational function field in y over Rational Field
486+
TypeError: y is not an element of Maximal infinite order of
487+
Rational function field in y over Finite Field of size 7
469488
"""
470489
F = self.function_field()
471490
try:
@@ -478,48 +497,23 @@ def _element_constructor_(self, f):
478497

479498
return f
480499

481-
def basis(self):
500+
def basis(self) -> tuple:
482501
"""
483-
Return the basis (=1) of the order as a module over the polynomial ring.
502+
Return the basis of the maximal infinite order as a module over itself.
484503
485504
EXAMPLES::
486505
487506
sage: K.<t> = FunctionField(GF(19))
488-
sage: O = K.maximal_order()
507+
sage: O = K.maximal_order_infinite()
489508
sage: O.basis()
490509
(1,)
491-
"""
492-
return 1/self.function_field().gen()
493-
494-
def gen(self, n=0):
495-
"""
496-
Return the `n`-th generator of ``self``. Since there is only one
497-
generator `n` must be `0`.
498510
499-
EXAMPLES::
500-
501-
sage: O = FunctionField(QQ,'y').maximal_order()
502-
sage: O.gen()
503-
y
504-
sage: O.gen(1)
505-
Traceback (most recent call last):
506-
...
507-
IndexError: there is only one generator
508-
"""
509-
if n != 0:
510-
raise IndexError("there is only one generator")
511-
return self._gen
512-
513-
def ngens(self):
514-
"""
515-
Return 1 the number of generators of the order.
516-
517-
EXAMPLES::
518-
519-
sage: FunctionField(QQ,'y').maximal_order().ngens()
520-
1
511+
sage: K.<t> = FunctionField(QQ)
512+
sage: O = K.maximal_order_infinite()
513+
sage: O.basis()
514+
(1,)
521515
"""
522-
return 1
516+
return (1,)
523517

524518
def prime_ideal(self):
525519
"""
@@ -533,7 +527,7 @@ def prime_ideal(self):
533527
Ideal (1/t) of Maximal infinite order of Rational function field in t
534528
over Finite Field of size 19
535529
"""
536-
return self.ideal( 1/self.function_field().gen() )
530+
return self.ideal(1 / self.function_field().gen())
537531

538532
def ideal(self, *gens):
539533
"""
@@ -548,15 +542,19 @@ def ideal(self, *gens):
548542
sage: K.<x> = FunctionField(QQ)
549543
sage: O = K.maximal_order_infinite()
550544
sage: O.ideal(x)
551-
Ideal (x) of Maximal infinite order of Rational function field in x over Rational Field
545+
Ideal (x) of Maximal infinite order of Rational function field in x
546+
over Rational Field
552547
sage: O.ideal([x, 1/x]) == O.ideal(x ,1/x) # multiple generators may be given as a list
553548
True
554549
sage: O.ideal(x^3 + 1, x^3 + 6)
555-
Ideal (x^3) of Maximal infinite order of Rational function field in x over Rational Field
550+
Ideal (x^3) of Maximal infinite order of Rational function field in x
551+
over Rational Field
556552
sage: I = O.ideal((x^2+1)*(x^3+1), (x^3+6)*(x^2+1)); I
557-
Ideal (x^5) of Maximal infinite order of Rational function field in x over Rational Field
553+
Ideal (x^5) of Maximal infinite order of Rational function field in x
554+
over Rational Field
558555
sage: O.ideal(I)
559-
Ideal (x^5) of Maximal infinite order of Rational function field in x over Rational Field
556+
Ideal (x^5) of Maximal infinite order of Rational function field in x
557+
over Rational Field
560558
"""
561559
if len(gens) == 1:
562560
gens = gens[0]
@@ -568,9 +566,10 @@ def ideal(self, *gens):
568566
K = self.function_field()
569567
gens = [K(g) for g in gens]
570568
try:
571-
d = max(g.numerator().degree() - g.denominator().degree() for g in gens if g != 0)
569+
d = max(g.numerator().degree() - g.denominator().degree()
570+
for g in gens if g != 0)
572571
gen = K.gen() ** d
573-
except ValueError: # all gens are zero
574-
gen = K(0)
572+
except ValueError: # all gens are zero
573+
gen = K.zero()
575574

576575
return self.ideal_monoid().element_class(self, gen)

0 commit comments

Comments
 (0)