Skip to content

Commit 1bd6ba7

Browse files
author
Release Manager
committed
gh-40464: some details in binary quadratic forms / class groups - using "indirect doctest" - add some typing annotations - remove unused imports - break very long lines ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40464 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 84cc006 + 09b6f0e commit 1bd6ba7

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

src/sage/quadratic_forms/bqf_class_group.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
sage: cl2 * cl2.order() == Cl.zero()
5757
True
5858
sage: Cl.abelian_group()
59-
Additive abelian group isomorphic to Z/21 embedded in Form Class Group of Discriminant -431
59+
Additive abelian group isomorphic to Z/21 embedded in
60+
Form Class Group of Discriminant -431
6061
sage: Cl.gens() # random
6162
[Class of 5*x^2 + 3*x*y + 22*y^2]
6263
sage: Cl.gens()[0].order()
@@ -86,11 +87,8 @@
8687

8788
from sage.misc.prandom import randrange
8889
from sage.rings.integer_ring import ZZ
89-
from sage.rings.finite_rings.integer_mod_ring import Zmod
9090
from sage.rings.finite_rings.integer_mod import Mod
91-
from sage.rings.polynomial.polynomial_ring import polygen
9291
from sage.arith.misc import random_prime
93-
from sage.matrix.constructor import matrix
9492
from sage.groups.generic import order_from_multiple, multiple
9593
from sage.groups.additive_abelian.additive_abelian_wrapper import AdditiveAbelianGroupWrapper
9694
from sage.quadratic_forms.binary_qf import BinaryQF
@@ -124,7 +122,7 @@ class BQFClassGroup(Parent, UniqueRepresentation):
124122
Form Class Group of Discriminant -484
125123
"""
126124

127-
def __init__(self, D, *, check=True):
125+
def __init__(self, D, *, check=True) -> None:
128126
r"""
129127
Construct the class group for a given discriminant `D`.
130128
@@ -159,7 +157,8 @@ def _element_constructor_(self, F, *, check=True):
159157
Class of 16*x^2 + 5*x*y + 16*y^2
160158
"""
161159
if isinstance(F, BQFClassGroup_element):
162-
if check and F.parent() is not self: # class group is unique parent
160+
if check and F.parent() is not self:
161+
# class group is unique parent
163162
raise ValueError('quadratic form has incorrect discriminant')
164163
return F
165164
if F == 0:
@@ -170,8 +169,10 @@ def _element_constructor_(self, F, *, check=True):
170169

171170
def zero(self):
172171
r"""
173-
Return the neutral element of this group, i.e., the class of the
174-
principal binary quadratic form of the respective discriminant.
172+
Return the neutral element of this group.
173+
174+
This is the class of the principal binary quadratic form of
175+
the respective discriminant.
175176
176177
EXAMPLES::
177178
@@ -219,7 +220,7 @@ def random_element(self):
219220
b = -b
220221
return self(BinaryQF([a, b, c]))
221222

222-
def __hash__(self):
223+
def __hash__(self) -> int:
223224
r"""
224225
Return a hash value for this form class group.
225226
@@ -230,7 +231,7 @@ def __hash__(self):
230231
"""
231232
return hash(('BQFClassGroup', self._disc))
232233

233-
def _repr_(self):
234+
def _repr_(self) -> str:
234235
r"""
235236
Return a string describing this form class group.
236237
@@ -299,7 +300,8 @@ def abelian_group(self):
299300
sage: Cl.order()
300301
16
301302
sage: G = Cl.abelian_group(); G
302-
Additive abelian group isomorphic to Z/4 + Z/2 + Z/2 embedded in Form Class Group of Discriminant -3108
303+
Additive abelian group isomorphic to Z/4 + Z/2 + Z/2 embedded in
304+
Form Class Group of Discriminant -3108
303305
sage: G.gens() # random
304306
(Class of 11*x^2 + 4*x*y + 71*y^2,
305307
Class of 6*x^2 + 6*x*y + 131*y^2,
@@ -314,25 +316,25 @@ def abelian_group(self):
314316
gens = [BinaryQF(g) for g in gens]
315317
return AdditiveAbelianGroupWrapper(self, gens, ords)
316318

317-
def gens(self) -> list:
319+
def gens(self) -> tuple:
318320
r"""
319321
Return a generating set of this form class group.
320322
321323
EXAMPLES::
322324
323325
sage: Cl = BQFClassGroup(-4*419)
324326
sage: Cl.gens()
325-
[Class of 3*x^2 + 2*x*y + 140*y^2]
327+
(Class of 3*x^2 + 2*x*y + 140*y^2,)
326328
327329
::
328330
329331
sage: Cl = BQFClassGroup(-4*777)
330332
sage: Cl.gens() # random
331-
[Class of 11*x^2 + 4*x*y + 71*y^2,
333+
(Class of 11*x^2 + 4*x*y + 71*y^2,
332334
Class of 6*x^2 + 6*x*y + 131*y^2,
333-
Class of 2*x^2 + 2*x*y + 389*y^2]
335+
Class of 2*x^2 + 2*x*y + 389*y^2)
334336
"""
335-
return [g.element() for g in self.abelian_group().gens()]
337+
return tuple(g.element() for g in self.abelian_group().gens())
336338

337339
def _coerce_map_from_(self, other):
338340
r"""
@@ -345,7 +347,7 @@ def _coerce_map_from_(self, other):
345347
346348
sage: G = BQFClassGroup(-4*117117)
347349
sage: H = BQFClassGroup(-4*77)
348-
sage: proj = G.hom(H); proj # implicit doctest
350+
sage: proj = G.hom(H); proj # indirect doctest
349351
Coercion morphism:
350352
From: Form Class Group of Discriminant -468468
351353
To: Form Class Group of Discriminant -308
@@ -376,19 +378,19 @@ class BQFClassGroup_element(AdditiveGroupElement):
376378
EXAMPLES::
377379
378380
sage: F = BinaryQF([22, 91, 99])
379-
sage: F.form_class() # implicit doctest
381+
sage: F.form_class() # indirect doctest
380382
Class of 5*x^2 - 3*x*y + 22*y^2
381383
382384
::
383385
384386
sage: Cl = BQFClassGroup(-4*419)
385387
sage: Cl.zero()
386388
Class of x^2 + 419*y^2
387-
sage: Cl.gens()[0] # implicit doctest
389+
sage: Cl.gens()[0] # indirect doctest
388390
Class of 3*x^2 + 2*x*y + 140*y^2
389391
"""
390392

391-
def __init__(self, F, parent, *, check=True, reduce=True):
393+
def __init__(self, F, parent, *, check=True, reduce=True) -> None:
392394
r"""
393395
Constructor for classes of binary quadratic forms.
394396
@@ -515,7 +517,7 @@ def __mul__(self, other):
515517

516518
__rmul__ = __mul__
517519

518-
def __eq__(self, other):
520+
def __eq__(self, other) -> bool:
519521
r"""
520522
Test two form classes for equality.
521523
@@ -535,7 +537,7 @@ def __eq__(self, other):
535537
# as well as hashing.
536538
return self._form == other._form
537539

538-
def __ne__(self, other):
540+
def __ne__(self, other) -> bool:
539541
r"""
540542
Test two form classes for inequality.
541543
@@ -551,7 +553,7 @@ def __ne__(self, other):
551553
"""
552554
return self._form != other._form
553555

554-
def __lt__(self, other):
556+
def __lt__(self, other) -> bool:
555557
r"""
556558
Compare two form classes according to the lexicographic ordering
557559
on their coefficient lists.
@@ -599,7 +601,7 @@ def is_zero(self) -> bool:
599601
"""
600602
return not self
601603

602-
def __repr__(self) -> str:
604+
def _repr_(self) -> str:
603605
r"""
604606
Return a string representation of this form class.
605607
@@ -611,7 +613,7 @@ def __repr__(self) -> str:
611613
"""
612614
return f'Class of {self._form}'
613615

614-
def __hash__(self):
616+
def __hash__(self) -> int:
615617
r"""
616618
Return a hash value for this form class.
617619
@@ -698,7 +700,7 @@ class representative `[a,b,c]` satisfying `f^2 \mid a` and `f \mid b`
698700
sage: proj(elt) == proj2(proj1(elt))
699701
True
700702
"""
701-
def __init__(self, G, H):
703+
def __init__(self, G, H) -> None:
702704
r"""
703705
Initialize this morphism between class groups of binary
704706
quadratic forms.

0 commit comments

Comments
 (0)