Skip to content

Commit 3c6a36a

Browse files
author
Release Manager
committed
gh-36108: some details in quadratic forms This is fixing a few minor details in quadratic forms, about - unused variables found by pylint - strange re-definitions of ZZ and QQ ### 📝 Checklist - [x] The title is concise, informative, and self-explanatory. - [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 accordingly. URL: #36108 Reported by: Frédéric Chapoton Reviewer(s): Kwankyu Lee
2 parents 34c505e + 1cbabd3 commit 3c6a36a

File tree

7 files changed

+34
-40
lines changed

7 files changed

+34
-40
lines changed

src/sage/combinat/sf/classical.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# https://www.gnu.org/licenses/
1818
# ****************************************************************************
1919
from sage.rings.integer import Integer
20-
from sage.rings.integer_ring import IntegerRing
21-
from sage.rings.rational_field import RationalField
20+
from sage.rings.integer_ring import ZZ
21+
from sage.rings.rational_field import QQ
2222
from sage.combinat.partition import _Partitions
2323

2424

@@ -29,9 +29,6 @@
2929
from . import jack
3030
from . import orthotriang
3131

32-
ZZ = IntegerRing()
33-
QQ = RationalField()
34-
3532
translate = {'monomial':'MONOMIAL', 'homogeneous':'HOMSYM', 'powersum':'POWSYM', 'elementary':'ELMSYM', 'Schur':'SCHUR'}
3633

3734
conversion_functions = {}

src/sage/crypto/lattice.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def gen_lattice(type='modular', n=4, m=8, q=11, seed=None,
228228
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing
229229
from sage.matrix.constructor import identity_matrix, block_matrix
230230
from sage.matrix.matrix_space import MatrixSpace
231-
from sage.rings.integer_ring import IntegerRing
231+
from sage.rings.integer_ring import ZZ
232232
if seed is not None:
233233
from sage.misc.randstate import set_random_seed
234234
set_random_seed(seed)
@@ -237,7 +237,6 @@ def gen_lattice(type='modular', n=4, m=8, q=11, seed=None,
237237
if n != 1:
238238
raise ValueError('random bases require n = 1')
239239

240-
ZZ = IntegerRing()
241240
ZZ_q = IntegerModRing(q)
242241
A = identity_matrix(ZZ_q, n)
243242

src/sage/quadratic_forms/binary_qf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ def solve_integer(self, n, *, algorithm="general"):
16631663
w = self.discriminant().sqrt()
16641664
r = (-self._b + (w if w != self._b else -w)) / (2*self._a)
16651665
p, q = r.as_integer_ratio()
1666-
g, u, v = p.xgcd(q)
1666+
_, u, v = p.xgcd(q)
16671667
M = Matrix(ZZ, [[v, p], [-u, q]])
16681668
elif self._c:
16691669
M = Matrix(ZZ, [[0, 1], [1, 0]])

src/sage/quadratic_forms/genera/genus.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
r"""
33
Genus
44
5-
65
AUTHORS:
76
87
- David Kohel & Gabriele Nebe (2007): First created
@@ -20,17 +19,18 @@
2019
# https://www.gnu.org/licenses/
2120
# ****************************************************************************
2221

22+
from copy import copy, deepcopy
23+
2324
from sage.misc.lazy_import import lazy_import
2425
from sage.misc.misc_c import prod
2526
from sage.misc.cachefunc import cached_method
2627
from sage.arith.functions import lcm as LCM
2728
from sage.arith.misc import fundamental_discriminant
2829
from sage.matrix.matrix_space import MatrixSpace
2930
from sage.matrix.constructor import matrix
30-
from sage.rings.integer_ring import IntegerRing, ZZ
31-
from sage.rings.rational_field import RationalField, QQ
31+
from sage.rings.integer_ring import ZZ
32+
from sage.rings.rational_field import QQ
3233
from sage.rings.integer import Integer
33-
from copy import copy, deepcopy
3434
from sage.misc.verbose import verbose
3535
from sage.quadratic_forms.special_values import quadratic_L_function__exact
3636
lazy_import('sage.quadratic_forms.genera.normal_form', '_min_nonsquare')
@@ -81,7 +81,6 @@ def genera(sig_pair, determinant, max_scale=None, even=False):
8181
"""
8282
from sage.misc.mrange import mrange_iter
8383
# input checks
84-
ZZ = IntegerRing()
8584
determinant = ZZ(determinant)
8685
sig_pair = (ZZ(sig_pair[0]), ZZ(sig_pair[1]))
8786
even = bool(even)
@@ -440,7 +439,7 @@ def is_GlobalGenus(G):
440439
sym = loc._symbol
441440
v = sum([ss[0] * ss[1] for ss in sym])
442441
a = D // (p**v)
443-
b = Integer(prod([ss[2] for ss in sym]))
442+
b = ZZ.prod(ss[2] for ss in sym)
444443
if p == 2:
445444
if not is_2_adic_genus(sym):
446445
verbose(mesg="False in is_2_adic_genus(sym)", level=2)
@@ -906,10 +905,10 @@ def p_adic_symbol(A, p, val):
906905

907906
from sage.rings.finite_rings.finite_field_constructor import FiniteField
908907

909-
m0 = min([ c.valuation(p) for c in A.list() ])
908+
m0 = min(c.valuation(p) for c in A.list())
910909
q = p**m0
911910
n = A.nrows()
912-
A = MatrixSpace(IntegerRing(), n, n)([ c // q for c in A.list() ])
911+
A = MatrixSpace(ZZ, n, n)([ c // q for c in A.list() ])
913912
A_p = MatrixSpace(FiniteField(p), n, n)(A)
914913
B_p = A_p.kernel().echelonized_basis_matrix()
915914
if B_p.nrows() == 0:
@@ -922,16 +921,16 @@ def p_adic_symbol(A, p, val):
922921
n0 = C_p.nrows()
923922
sym = [ [0, n0, e0] ]
924923
r = B_p.nrows()
925-
B = MatrixSpace(IntegerRing(), r, n)(B_p)
926-
C = MatrixSpace(IntegerRing(), n - r, n)(C_p)
924+
B = MatrixSpace(ZZ, r, n)(B_p)
925+
C = MatrixSpace(ZZ, n - r, n)(C_p)
927926
# Construct the blocks for the Jordan decomposition [F,X;X,A_new]
928-
F = MatrixSpace(RationalField(), n - r, n - r)(C * A * C.transpose())
927+
F = MatrixSpace(QQ, n - r, n - r)(C * A * C.transpose())
929928
U = F**-1
930929
d = LCM([ c.denominator() for c in U.list() ])
931-
R = IntegerRing().quotient_ring(Integer(p)**(val + 3))
930+
R = ZZ.quotient_ring(Integer(p)**(val + 3))
932931
u = R(d)**-1
933932
MatR = MatrixSpace(R, n - r , n - r)
934-
MatZ = MatrixSpace(IntegerRing(), n - r, n - r)
933+
MatZ = MatrixSpace(ZZ, n - r, n - r)
935934
U = MatZ(MatR(MatZ(U * d)) * u)
936935
# X = C*A*B.transpose()
937936
# A = B*A*B.transpose() - X.transpose()*U*X
@@ -1017,7 +1016,7 @@ def split_odd(A):
10171016
"""
10181017
n0 = A.nrows()
10191018
if n0 == 1:
1020-
return A[0, 0], MatrixSpace(IntegerRing(), 0, A.ncols())([])
1019+
return A[0, 0], MatrixSpace(ZZ, 0, A.ncols())([])
10211020
even, i = is_even_matrix(A)
10221021
R = A.parent().base_ring()
10231022
C = MatrixSpace(R, n0 - 1, n0)(0)
@@ -1098,7 +1097,7 @@ def trace_diag_mod_8(A):
10981097
while A.nrows():
10991098
u, A = split_odd(A)
11001099
tr += u
1101-
return IntegerRing()(tr)
1100+
return ZZ(tr)
11021101

11031102

11041103
def two_adic_symbol(A, val):
@@ -1141,7 +1140,6 @@ def two_adic_symbol(A, val):
11411140
m0 = min([ c.valuation(2) for c in A.list() ])
11421141
q = 2**m0
11431142
A = A.parent()([ c // q for c in A.list() ])
1144-
ZZ = IntegerRing()
11451143
A_2 = MatrixSpace(FiniteField(2), n, n)(A)
11461144
K_2 = A_2.kernel()
11471145
R_8 = ZZ.quotient_ring(Integer(8))
@@ -1156,7 +1154,7 @@ def two_adic_symbol(A, val):
11561154
print("A:")
11571155
print(A)
11581156
assert False
1159-
even, i = is_even_matrix(A_2) # Determine whether the matrix is even or odd.
1157+
even, _ = is_even_matrix(A_2) # Determine whether the matrix is even or odd.
11601158
if even:
11611159
return [[m0, n0, d0, 0, 0]]
11621160
else:
@@ -1178,22 +1176,22 @@ def two_adic_symbol(A, val):
11781176
print("A:")
11791177
print(A_new)
11801178
assert False
1181-
even, i = is_even_matrix(A_new)
1179+
even, _ = is_even_matrix(A_new)
11821180
if even:
11831181
sym = [[0, n0, d0, 0, 0]]
11841182
else:
11851183
tr8 = trace_diag_mod_8(A_8)
11861184
sym = [[0, n0, d0, 1, tr8]]
11871185
r = B_2.nrows()
11881186
B = MatrixSpace(ZZ,r,n)(B_2)
1189-
C = MatrixSpace(IntegerRing(), n - r, n)(C_2)
1190-
F = MatrixSpace(RationalField(), n - r, n - r)(C * A * C.transpose())
1187+
C = MatrixSpace(ZZ, n - r, n)(C_2)
1188+
F = MatrixSpace(QQ, n - r, n - r)(C * A * C.transpose())
11911189
U = F**-1
11921190
d = LCM([ c.denominator() for c in U.list() ])
1193-
R = IntegerRing().quotient_ring(Integer(2)**(val + 3))
1191+
R = ZZ.quotient_ring(Integer(2)**(val + 3))
11941192
u = R(d)**-1
11951193
MatR = MatrixSpace(R, n - r, n - r)
1196-
MatZ = MatrixSpace(IntegerRing(), n - r, n - r)
1194+
MatZ = MatrixSpace(ZZ, n - r, n - r)
11971195
U = MatZ(MatR(MatZ(U * d)) * u)
11981196
X = C * A
11991197
A = B * (A - X.transpose()*U*X) * B.transpose()
@@ -2757,10 +2755,11 @@ def signature(self):
27572755

27582756
def determinant(self):
27592757
r"""
2760-
Return the determinant of this genus, where the determinant
2761-
is the Hessian determinant of the quadratic form whose Gram
2762-
matrix is the Gram matrix giving rise to this global genus
2763-
symbol.
2758+
Return the determinant of this genus.
2759+
2760+
The determinant is the Hessian determinant of the quadratic
2761+
form whose Gram matrix is the Gram matrix giving rise to this
2762+
global genus symbol.
27642763
27652764
OUTPUT: an integer
27662765
@@ -2771,8 +2770,8 @@ def determinant(self):
27712770
sage: GS.determinant()
27722771
-24
27732772
"""
2774-
p, n = self.signature_pair()
2775-
return (-1)**n*prod([ G.determinant() for G in self._local_symbols ])
2773+
_, n = self.signature_pair()
2774+
return (-1)**n * ZZ.prod(G.determinant() for G in self._local_symbols)
27762775

27772776
det = determinant
27782777

src/sage/quadratic_forms/genera/normal_form.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ def _relations(G, n):
13741374
e1 = G[0, 0].unit_part()
13751375
e2 = G[1, 1].unit_part()
13761376
B = Matrix(R, 2, 2, [1, 1, -4 * e2, e1])
1377-
D, B1 = _normalize(B * G * B.T)
1377+
_, B1 = _normalize(B * G * B.T)
13781378
return B1 * B
13791379

13801380

src/sage/quadratic_forms/quadratic_form__local_field_invariants.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,8 @@ def signature(self):
367367
[ * * * 9 ]
368368
sage: Q.signature()
369369
2
370-
371370
"""
372-
(p, n, z) = self.signature_vector()
371+
p, n, _ = self.signature_vector()
373372
return p - n
374373

375374

src/sage/quadratic_forms/quadratic_form__ternary_Tornaria.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def representation_vector_list(self, B, maxvectors=10**8):
574574
...
575575
PariError: domain error in minim0: form is not positive definite
576576
"""
577-
n, m, vs = self.__pari__().qfminim(2 * (B - 1), maxvectors)
577+
n, _, vs = self.__pari__().qfminim(2 * (B - 1), maxvectors)
578578

579579
if n != 2 * len(vs):
580580
raise RuntimeError("insufficient number of vectors")

0 commit comments

Comments
 (0)