Skip to content

Commit c154c72

Browse files
author
Release Manager
committed
gh-41103: some python-style for loops in rings/padics convert some loops in `rings/padics` to the python-style syntax ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: #41103 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents a410a3e + 8b070f0 commit c154c72

File tree

5 files changed

+18
-24
lines changed

5 files changed

+18
-24
lines changed

src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,8 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
332332
x = Rational(x)
333333
elif x.type() == 't_POLMOD' or x.type == 't_POL':
334334
# This code doesn't check to see if the primes are the same.
335-
L = []
336335
x = x.lift().lift()
337-
for i from 0 <= i <= x.poldegree():
338-
L.append(Integer(x.polcoef(i)))
336+
L = [Integer(x.polcoef(i)) for i in range(x.poldegree() + 1)]
339337
x = L
340338
else:
341339
raise TypeError("unsupported coercion from pari: only p-adics, integers, rationals, polynomials and pol_mods allowed")
@@ -1300,7 +1298,7 @@ cdef class pAdicZZpXCAElement(pAdicZZpXElement):
13001298
# checks to see if the residue of self's unit is in the prime field.
13011299
if self.prime_pow.e == 1:
13021300
unit = self.unit_part()
1303-
for i from 1 <= i <= ZZ_pX_deg(unit.value):
1301+
for i in range(1, ZZ_pX_deg(unit.value) + 1):
13041302
if not ZZ_divide_test(ZZ_p_rep(ZZ_pX_coeff(unit.value, i)), self.prime_pow.pow_ZZ_tmp(1)[0]):
13051303
raise ValueError("in order to raise to a p-adic exponent, base must reduce to an element of F_p mod the uniformizer")
13061304
# compute the "level"

src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,8 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
346346
x = Rational(x)
347347
elif x.type() == 't_POLMOD' or x.type == 't_POL':
348348
# This code doesn't check to see if the primes are the same.
349-
L = []
350349
x = x.lift().lift()
351-
for i from 0 <= i <= x.poldegree():
352-
L.append(Integer(x.polcoef(i)))
350+
L = [Integer(x.polcoef(i)) for i in range(x.poldegree() + 1)]
353351
x = L
354352
else:
355353
raise TypeError("unsupported coercion from pari: only p-adics, integers, rationals, polynomials and pol_mods allowed")
@@ -1974,7 +1972,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
19741972
raise NotImplementedError("negative valuation exponents not yet supported")
19751973
# checks to see if the residue of self.unit is in the prime field.
19761974
if self.prime_pow.e == 1:
1977-
for i from 1 <= i <= ZZ_pX_deg(self.unit):
1975+
for i in range(ZZ_pX_deg(self.unit) + 1):
19781976
if not ZZ_divide_test(ZZ_p_rep(ZZ_pX_coeff(self.unit, i)), self.prime_pow.pow_ZZ_tmp(1)[0]):
19791977
raise ValueError("in order to raise to a p-adic exponent, base must reduce to an element of F_p mod the uniformizer")
19801978
# compute the "level"

src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,8 @@ cdef class pAdicZZpXFMElement(pAdicZZpXElement):
225225
x = Rational(x)
226226
elif x.type() == 't_POLMOD' or x.type == 't_POL':
227227
# This code doesn't check to see if the primes are the same.
228-
L = []
229228
x = x.lift().lift()
230-
for i from 0 <= i <= x.poldegree():
231-
L.append(Integer(x.polcoef(i)))
229+
L = [Integer(x.polcoef(i)) for i in range(x.poldegree() + 1)]
232230
x = L
233231
else:
234232
raise TypeError("unsupported coercion from pari: only p-adics, integers, rationals, polynomials and pol_mods allowed")

src/sage/rings/padics/padic_ZZ_pX_element.pyx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,18 +296,18 @@ cdef class pAdicZZpXElement(pAdicExtElement):
296296
#print(printer)
297297

298298
if self.prime_pow.e == 1:
299-
for j from 0 <= j < self.prime_pow.prec_cap:
299+
for j in range(self.prime_pow.prec_cap):
300300
ans.append([])
301-
for i from 0 <= i < self.prime_pow.deg:
301+
for i in range(self.prime_pow.deg):
302302
ZZ_coeff.x = ZZ_p_rep(ZZ_pX_coeff(shifter, i))
303303
ZZ_to_mpz(coeff.value, &ZZ_coeff.x)
304304
L = printer.base_p_list(coeff, pos)
305-
for j from 0 <= j < prec:
305+
for j in range(prec):
306306
if j < len(L):
307307
ans[j].append(L[j])
308308
else:
309309
ans[j].append(zero)
310-
for j from 0 <= j < prec:
310+
for j in range(prec):
311311
while ans[j]:
312312
if ans[j][-1] == 0:
313313
ans[j].pop()
@@ -322,7 +322,7 @@ cdef class pAdicZZpXElement(pAdicExtElement):
322322
# It's important that one doesn't normalize in between shifting (for capped relative elements):
323323
# _const_term doesn't normalize and thus we pick up the zeros
324324
# since we're throwing away leading zeros, it doesn't matter if we start normalized or not.
325-
for j from 0 <= j < self.prime_pow.e:
325+
for j in range(self.prime_pow.e):
326326
list_elt = PY_NEW(Integer)
327327
if i + j == prec:
328328
break
@@ -655,7 +655,7 @@ cdef preprocess_list(pAdicZZpXElement elt, L):
655655
pshift_z = ntl_ZZ.__new__(ntl_ZZ)
656656
pshift_z.x = elt.prime_pow.pow_ZZ_tmp(-mpz_get_si((<Integer>min_val).value))[0]
657657
pshift_m = elt.prime_pow.pow_Integer(-mpz_get_si((<Integer>min_val).value))
658-
for i from 0 <= i < len(L):
658+
for i in range(len(L)):
659659
if isinstance(L[i], ntl_ZZ):
660660
L[i] = ntl_ZZ_p(L[i]*pshift_z, ctx)
661661
elif isinstance(L[i], (Integer, Rational, int)):
@@ -670,7 +670,7 @@ cdef preprocess_list(pAdicZZpXElement elt, L):
670670
pshift_z = ntl_ZZ.__new__(ntl_ZZ)
671671
pshift_z.x = elt.prime_pow.pow_ZZ_tmp(mpz_get_ui((<Integer>min_val).value))[0]
672672
pshift_m = elt.prime_pow.pow_Integer(mpz_get_ui((<Integer>min_val).value))
673-
for i from 0 <= i < len(L):
673+
for i in range(len(L)):
674674
if isinstance(L[i], ntl_ZZ):
675675
ZZ_div(tmp, (<ntl_ZZ>L[i]).x, pshift_z.x)
676676
py_tmp = ntl_ZZ.__new__(ntl_ZZ)
@@ -688,7 +688,7 @@ cdef preprocess_list(pAdicZZpXElement elt, L):
688688
py_tmp.x = tmp
689689
L[i] = ntl_ZZ_p(py_tmp, ctx)
690690
else:
691-
for i from 0 <= i < len(L):
691+
for i in range(len(L)):
692692
if isinstance(L[i], (ntl_ZZ, Integer, Rational, int)):
693693
L[i] = ntl_ZZ_p(L[i], ctx)
694694
elif (isinstance(L[i], pAdicGenericElement) and L[i]._is_base_elt(elt.prime_pow.prime)) or isinstance(L[i], IntegerMod_abstract) or (L[i].modulus_context() is not ctx):
@@ -754,7 +754,7 @@ cdef find_val_aprec(PowComputer_ext pp, L):
754754
min_val = big
755755
min_aprec = big
756756
total_type = two # we begin by defaulting to the list elements being integers
757-
for i from 0 <= i < len(L):
757+
for i in range(len(L)):
758758
cur_val, cur_aprec, cur_type = get_val_prec(pp, L[i])
759759
#return "a","b","c"
760760
# proc_type == 0 indicates something with finite precision

src/sage/rings/padics/padic_printing.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ cdef class pAdicPrinter_class(SageObject):
11731173
else:
11741174
pk = Integer(1)
11751175
integral = True
1176-
for i from 0 <= i < len(L):
1176+
for i in range(len(L)):
11771177
if L[i] != "":
11781178
a = Integer(L[i])
11791179
if not pos and 2*a > pn:
@@ -1220,7 +1220,7 @@ cdef class pAdicPrinter_class(SageObject):
12201220
if self.unram_name is None:
12211221
raise RuntimeError("need to have specified a name for the unramified variable")
12221222
L, ellipsis = self._truncate_list(L, self.max_ram_terms, [])
1223-
for i from 0 <= i < len(L):
1223+
for i in range(len(L)):
12241224
unram_name = self.latex_unram_name if do_latex else self.unram_name
12251225
term = self._print_unram_term(L[i], do_latex, unram_name, self.max_unram_terms, 0, 0)
12261226
if len(term) > 0:
@@ -1393,7 +1393,7 @@ cdef class pAdicPrinter_class(SageObject):
13931393
cdef Py_ssize_t j, newj
13941394
cdef long exp, count = 0
13951395
if increasing:
1396-
for j from 0 <= j < len(L):
1396+
for j in range(len(L)):
13971397
exp = j + expshift
13981398
if L[j] != 0:
13991399
if max_unram_terms == 0:
@@ -1480,7 +1480,7 @@ cdef class pAdicPrinter_class(SageObject):
14801480
cdef Py_ssize_t j
14811481
cdef long exp
14821482
if increasing:
1483-
for j from 0 <= j < len(L):
1483+
for j in range(len(L)):
14841484
exp = j + expshift
14851485
s = self._print_term_of_poly(s, L[j], do_latex, polyname, exp)
14861486
else:

0 commit comments

Comments
 (0)