Skip to content

Commit f24be38

Browse files
author
Release Manager
committed
gh-40331: remove unused variables in rings/ as suggested by cython-lint ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #40331 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents b50b1e3 + 1333d0f commit f24be38

10 files changed

+39
-60
lines changed

src/sage/rings/bernoulli_mod_p.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ def bernoulli_mod_p(int p):
145145
g = primitive_root(p)
146146
gInv = arith_int.c_inverse_mod_int(g, p)
147147
gSqr = ((<llong> g) * g) % p
148-
gInvSqr = ((<llong> gInv) * gInv) % p
149148
isOdd = ((p-1)/2) % 2
150149

151150
# STEP 1: compute the polynomials G(X) and J(X)

src/sage/rings/complex_interval.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,6 @@ cdef class ComplexIntervalFieldElement(FieldElement):
11651165
11661166
- [RL1971]_
11671167
"""
1168-
cdef ComplexIntervalFieldElement result
11691168
x = self._new()
11701169

11711170
if mpfi_nan_p(self.__re) or mpfi_nan_p(self.__im):

src/sage/rings/function_field/khuri_makdisi.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,9 @@ cdef class KhuriMakdisi_base(object):
153153
"""
154154
cdef Matrix mat, perp, vmu
155155
cdef FreeModuleElement v
156-
cdef Py_ssize_t nd, ne, nde, r
156+
cdef Py_ssize_t ne, r
157157

158158
ne = we.ncols()
159-
nde = wde.ncols()
160-
nd = nde - ne
161159

162160
perp = wde.right_kernel_matrix()
163161
mat = matrix(0, mu_mat.nrows())

src/sage/rings/polynomial/multi_polynomial.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2948,7 +2948,7 @@ cdef class MPolynomial(CommutativePolynomial):
29482948
(2*x^2 - 3*x - 5*y, -1)
29492949
"""
29502950
lc = self.leading_coefficient()
2951-
n, u = lc.canonical_associate()
2951+
_, u = lc.canonical_associate()
29522952
return (u.inverse_of_unit() * self, u)
29532953

29542954

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ import sage.rings.fraction_field_element
7474
import sage.rings.infinity as infinity
7575
from sage.misc.latex import latex
7676
from sage.arith.power cimport generic_power
77-
from sage.arith.misc import crt
7877
from sage.arith.long cimport pyobject_to_long
79-
from sage.misc.mrange import cartesian_product_iterator
8078
from sage.structure.factorization import Factorization
8179
from sage.structure.richcmp cimport (richcmp, richcmp_item,
8280
rich_to_bool, rich_to_bool_sgn)
@@ -6299,7 +6297,7 @@ cdef class Polynomial(CommutativePolynomial):
62996297
(2*x^2 - 3*x - 5, -1)
63006298
"""
63016299
lc = self.leading_coefficient()
6302-
n, u = lc.canonical_associate()
6300+
_, u = lc.canonical_associate()
63036301
return (u.inverse_of_unit() * self, u)
63046302

63056303
def lm(self):

src/sage/rings/rational.pyx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,6 @@ cdef class Rational(sage.structure.element.FieldElement):
586586
cdef __set_value(self, x, unsigned int base):
587587
cdef int n
588588
cdef Rational temp_rational
589-
cdef integer.Integer a, b
590589

591590
if isinstance(x, Rational):
592591
set_from_Rational(self, x)
@@ -610,7 +609,6 @@ cdef class Rational(sage.structure.element.FieldElement):
610609
xstr = x.str(base, truncate=(base == 10))
611610
if '.' in xstr:
612611
exp = (len(xstr) - (xstr.index('.') +1))
613-
p = base**exp
614612
pstr = '1'+'0'*exp
615613
s = xstr.replace('.','') +'/'+pstr
616614
n = mpq_set_str(self.value, str_to_bytes(s), base)
@@ -1880,7 +1878,7 @@ cdef class Rational(sage.structure.element.FieldElement):
18801878
return self
18811879
a = self
18821880
for p in S:
1883-
e, a = a.val_unit(p)
1881+
_, a = a.val_unit(p)
18841882
return a
18851883

18861884
def sqrt(self, prec=None, extend=True, all=False):
@@ -2044,10 +2042,9 @@ cdef class Rational(sage.structure.element.FieldElement):
20442042
sage: RealField(200)(x) # needs sage.rings.real_mpfr
20452043
3.1415094339622641509433962264150943396226415094339622641509
20462044
"""
2047-
cdef unsigned int alpha, beta
20482045
d = self.denominator()
2049-
alpha, d = d.val_unit(2)
2050-
beta, d = d.val_unit(5)
2046+
d = d.val_unit(2)[1]
2047+
d = d.val_unit(5)[1]
20512048
from sage.rings.finite_rings.integer_mod import Mod
20522049
return Mod(10, d).multiplicative_order()
20532050

@@ -2810,7 +2807,7 @@ cdef class Rational(sage.structure.element.FieldElement):
28102807
...
28112808
ArithmeticError: The inverse of 0 modulo 17 is not defined.
28122809
"""
2813-
cdef unsigned int num, den, a
2810+
cdef unsigned int num, den
28142811

28152812
# Documentation from GMP manual:
28162813
# "For the ui variants the return value is the remainder, and

src/sage/rings/ring_extension.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,16 +479,16 @@ class RingExtensionFactory(UniqueFactory):
479479
sage: RingExtension.create_object((8,9,0), key, **extra_args)
480480
Rational Field over its base
481481
"""
482-
defining_morphism, gens, names = key
482+
defining_morphism = key[0]
483483
constructors = extra_args['constructors']
484484
if len(constructors) == 0:
485485
raise NotImplementedError("no constructor available for this extension")
486-
for (constructor, kwargs) in constructors[:-1]:
486+
for constructor, kwargs in constructors[:-1]:
487487
try:
488488
return constructor(defining_morphism, **kwargs)
489489
except (NotImplementedError, ValueError, TypeError):
490490
pass
491-
(constructor, kwargs) = constructors[-1]
491+
constructor, kwargs = constructors[-1]
492492
return constructor(defining_morphism, **kwargs)
493493

494494

src/sage/rings/ring_extension_morphism.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -835,20 +835,20 @@ cdef class MapRelativeRingToFreeModule(Map):
835835
# We compute the matrix of our isomorphism (over base)
836836
from sage.rings.ring_extension import common_base
837837
base = common_base(K, L, False)
838-
EK, iK, jK = K.free_module(base, map=True)
839-
EL, iL, jL = L.free_module(base, map=True)
838+
EK, iK, _ = K.free_module(base, map=True)
839+
jL = L.free_module(base, map=True)[2]
840840

841841
self._dimK = EK.dimension()
842842
self._iK = iK
843843
self._jL = jL
844844

845-
M = [ ]
845+
M = []
846846
for x in self._basis:
847847
for v in EK.basis():
848848
y = x * f(iK(v))
849849
M.append(jL(y))
850850
from sage.matrix.matrix_space import MatrixSpace
851-
self._matrix = MatrixSpace(base,len(M))(M).inverse_of_unit()
851+
self._matrix = MatrixSpace(base, len(M))(M).inverse_of_unit()
852852

853853
def is_injective(self):
854854
r"""

src/sage/rings/tate_algebra_element.pyx

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,8 +1170,6 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
11701170
sage: A(x + 2*x^2 + x^3, prec=5)
11711171
...00001*x^3 + ...00001*x + ...00010*x^2 + O(2^5 * <x, y>)
11721172
"""
1173-
base = self._parent.base_ring()
1174-
nvars = self._parent.ngens()
11751173
vars = self._parent.variable_names()
11761174
s = ""
11771175
for t in self._terms_c():
@@ -1229,9 +1227,6 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
12291227
sage: f._latex_()
12301228
'...0000000001x^{3} + ...0000000001x + ...00000000010x^{2}'
12311229
"""
1232-
base = self._parent.base_ring()
1233-
nvars = self._parent.ngens()
1234-
vars = self._parent.variable_names()
12351230
s = ""
12361231
for t in self.terms():
12371232
if t.valuation() >= self._prec:
@@ -1246,7 +1241,6 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
12461241
if self._prec is not Infinity:
12471242
if s != "":
12481243
s += " + "
1249-
sv = ",".join(vars)
12501244
if self._prec == 0:
12511245
s += "O\\left(%s\\right)" % self._parent.integer_ring()._latex_()
12521246
elif self._prec == 1:
@@ -1968,16 +1962,15 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
19681962
parent = self._parent
19691963
base = parent.base_ring()
19701964
if base.is_field():
1971-
for (e,c) in self._poly.__repn.items():
1965+
for e, c in self._poly.__repn.items():
19721966
coeffs[e] = c << n
19731967
ans._prec = self._prec + n
19741968
else:
19751969
field = base.fraction_field()
1976-
ngens = parent.ngens()
1977-
for (e,c) in self._poly.__repn.items():
1970+
for e, c in self._poly.__repn.items():
19781971
minval = ZZ(e.dotprod(<ETuple>parent._log_radii)).ceil()
19791972
coeffs[e] = field(base(c) >> (minval-n)) << minval
1980-
ans._prec = max(ZZ(0), self._prec + n)
1973+
ans._prec = max(ZZ.zero(), self._prec + n)
19811974
ans._poly = PolyDict(coeffs, None)
19821975
return ans
19831976

@@ -2453,12 +2446,10 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
24532446
sage: f.valuation()
24542447
-4
24552448
"""
2456-
cdef TateAlgebraTerm t
24572449
cdef list terms = self._terms_c()
24582450
if terms:
24592451
return min(terms[0].valuation(), self._prec)
2460-
else:
2461-
return self._prec
2452+
return self._prec
24622453

24632454
def precision_relative(self):
24642455
"""
@@ -3244,7 +3235,6 @@ cdef class TateAlgebraElement(CommutativeAlgebraElement):
32443235
divisors = [divisors]
32453236
onedivisor = True
32463237
A = _pushout_family(divisors, self._parent)
3247-
f = A(self)
32483238
divisors = [A(d) for d in divisors]
32493239
q, r = (<TateAlgebraElement>self)._quo_rem_c(divisors, quo, rem, False)
32503240
if quo and onedivisor:

src/sage/rings/tate_algebra_ideal.pyx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class TateAlgebraIdeal(Ideal_generic):
390390
if self.ring().base_ring().is_field():
391391
return self
392392
gb = self.groebner_basis()
393-
gens = [ g.monic() for g in gb ]
393+
gens = [g.monic() for g in gb]
394394
return self.ring().ideal(gens)
395395

396396

@@ -432,14 +432,14 @@ def groebner_basis_buchberger(I, prec, py_integral):
432432
...0000000001*x^2*y + ...1210121020 + O(3^10 * <x, y>),
433433
...000000001*y^2 + ...210121020*x + O(3^9 * <x, y>)]
434434
"""
435-
cdef list gb, rgb, indices, ts, S = [ ]
435+
cdef list gb, rgb, indices, S = []
436436
cdef int i, j, l
437437
cdef TateAlgebraTerm ti, tj, t
438438
cdef TateAlgebraElement f, g, r, s
439439
cdef bint do_reduce = True
440440
cdef bint integral = py_integral
441441

442-
gb = [ ]
442+
gb = []
443443
l = 0
444444
for f in I.gens():
445445
if not f:
@@ -550,9 +550,10 @@ def groebner_basis_buchberger(I, prec, py_integral):
550550
rgb[i] = g._positive_lshift_c(1)
551551
_, rgb[i] = g._quo_rem_c(rgb, False, True, True)
552552
else:
553-
rgb = [ g.monic() for g in rgb ]
553+
rgb = [g.monic() for g in rgb]
554554
else:
555-
rgb = [ g * base(g.leading_coefficient().unit_part()).inverse_of_unit() for g in rgb ]
555+
rgb = [g * base(g.leading_coefficient().unit_part()).inverse_of_unit()
556+
for g in rgb]
556557

557558
rgb.sort(reverse=True)
558559
return rgb
@@ -638,11 +639,10 @@ cdef TateAlgebraElement regular_reduce(sgb, TateAlgebraTerm s, TateAlgebraElemen
638639
cdef dict coeffs = { }
639640
cdef TateAlgebraElement f
640641
cdef TateAlgebraTerm lt, factor
641-
cdef list ltds = [ (<TateAlgebraElement>(d[1]))._terms_c()[0] for d in sgb ]
642+
cdef list ltds = [(<TateAlgebraElement>(d[1]))._terms_c()[0] for d in sgb]
642643
cdef list terms = v._terms_c()
643644
cdef int index = 0
644645
cdef int i
645-
cdef bint in_rem
646646

647647
f = v._new_c()
648648
f._poly = PolyDict(v._poly.__repn, None)
@@ -712,7 +712,7 @@ cdef TateAlgebraElement reduce(gb, TateAlgebraElement v, stopval):
712712
cdef dict coeffs = { }
713713
cdef TateAlgebraElement f
714714
cdef TateAlgebraTerm lt, factor
715-
cdef list ltds = [ (<TateAlgebraElement>d)._terms_c()[0] for d in gb ]
715+
cdef list ltds = [(<TateAlgebraElement>d)._terms_c()[0] for d in gb]
716716
cdef list terms = v._terms_c()
717717
cdef int index = 0
718718
cdef int i
@@ -855,7 +855,7 @@ def groebner_basis_pote(I, prec, verbose=0):
855855
cdef TateAlgebraTerm term_one = I.ring().monoid_of_terms().one()
856856
cdef bint integral = not I.ring().base_ring().is_field()
857857

858-
gb = [ ]
858+
gb = []
859859

860860
for f in sorted(I.gens()):
861861
sig_check()
@@ -870,11 +870,10 @@ def groebner_basis_pote(I, prec, verbose=0):
870870
print("new generator: %s + ..." % f.leading_term())
871871
# Initial strong Grobner basis:
872872
# we add signatures
873-
sgb = [ (None, g) for g in gb if g ]
873+
sgb = [(None, g) for g in gb if g]
874874
# We compute initial J-pairs
875-
l = len(sgb)
876875
p = (term_one, f.add_bigoh(prec))
877-
Jpairs = [ ]
876+
Jpairs = []
878877
for P in sgb:
879878
sig_check()
880879
J = Jpair(p, P)
@@ -883,7 +882,7 @@ def groebner_basis_pote(I, prec, verbose=0):
883882
sgb.append(p)
884883

885884
# For the syzygy criterium
886-
gb0 = [ g.leading_term() for g in gb ]
885+
gb0 = [g.leading_term() for g in gb]
887886

888887
if verbose > 1:
889888
print("%s initial J-pairs" % len(Jpairs))
@@ -1005,7 +1004,7 @@ def groebner_basis_pote(I, prec, verbose=0):
10051004
print("| %s" % g)
10061005

10071006
if not integral:
1008-
gb = [ f.monic() for f in gb ]
1007+
gb = [f.monic() for f in gb]
10091008
gb.sort(reverse=True)
10101009
return gb
10111010

@@ -1100,9 +1099,9 @@ def groebner_basis_vapote(I, prec, verbose=0, interrupt_red_with_val=False, inte
11001099
cdef list terms
11011100
cdef bint do_reduce, integral
11021101
term_one = I.ring().monoid_of_terms().one()
1103-
gb = [ ]
1102+
gb = []
11041103

1105-
gens = [ ]
1104+
gens = []
11061105
for f in I.gens():
11071106
if f:
11081107
val = f.valuation()
@@ -1157,19 +1156,18 @@ def groebner_basis_vapote(I, prec, verbose=0, interrupt_red_with_val=False, inte
11571156

11581157
# Initial strong Grobner basis:
11591158
# we add signatures
1160-
sgb = [ (None, g) for g in gb if g ]
1159+
sgb = [(None, g) for g in gb if g]
11611160
# We compute initial J-pairs
1162-
l = len(sgb)
11631161
p = (term_one, f.add_bigoh(prec))
1164-
Jpairs = [ ]
1162+
Jpairs = []
11651163
for P in sgb:
11661164
J = Jpair(p, P)
11671165
if J is not None:
11681166
heappush(Jpairs, J)
11691167
sgb.append(p)
11701168

11711169
# For the syzygy criterium
1172-
gb0 = [ g.leading_term() for g in gb ]
1170+
gb0 = [g.leading_term() for g in gb]
11731171

11741172
if verbose > 1:
11751173
print("%s initial J-pairs" % len(Jpairs))
@@ -1257,8 +1255,8 @@ def groebner_basis_vapote(I, prec, verbose=0, interrupt_red_with_val=False, inte
12571255
sgb.append(p)
12581256

12591257
# We forget signatures
1260-
# gb = [ v.monic() for (s,v) in sgb ]
1261-
gb = [ v for (s,v) in sgb ]
1258+
# gb = [v.monic() for s, v in sgb]
1259+
gb = [v for s, v in sgb]
12621260
if verbose > 1:
12631261
print("%s elements in GB before minimization" % len(gb))
12641262
if verbose > 3:
@@ -1300,7 +1298,7 @@ def groebner_basis_vapote(I, prec, verbose=0, interrupt_red_with_val=False, inte
13001298
for g in gb:
13011299
print("| %s" % g)
13021300
if not integral:
1303-
gb = [ f.monic() for f in gb ]
1301+
gb = [f.monic() for f in gb]
13041302
gb.sort(reverse=True)
13051303

13061304
return gb

0 commit comments

Comments
 (0)