Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify many range(0,n) to range(n) #39306

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sage/calculus/desolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ def desolve_laplace(de, dvar, ics=None, ivar=None):
# maxima("de:"+de._repr_()+"=0;")
# if ics is not None:
# d = len(ics)
# for i in range(0,d-1):
# for i in range(d-1):
# ic = "atvalue(diff("+vars[1]+"("+vars[0]+"),"+str(vars[0])+","+str(i)+"),"+str(vars[0])+"="+str(ics[0])+","+str(ics[1+i])+")"
# maxima(ic)
#
Expand Down
7 changes: 3 additions & 4 deletions src/sage/coding/grs_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,7 +1525,7 @@ def _polynomial_vanishing_at_alphas(self, PolRing):
"""
G = PolRing.one()
x = PolRing.gen()
for i in range(0, self.code().length()):
for i in range(self.code().length()):
G = G*(x-self.code().evaluation_points()[i])
return G

Expand Down Expand Up @@ -1612,11 +1612,10 @@ def _decode_to_code_and_message(self, r):
if n == C.dimension() or r in C:
return r, self.connected_encoder().unencode_nocheck(r)

points = [(alphas[i], r[i]/col_mults[i]) for i in
range(0, n)]
points = [(alphas[i], r[i]/col_mults[i]) for i in range(n)]
R = PolRing.lagrange_polynomial(points)

(Q1, Q0) = self._partial_xgcd(G, R, PolRing)
Q1, Q0 = self._partial_xgcd(G, R, PolRing)

h, rem = Q1.quo_rem(Q0)
if not rem.is_zero():
Expand Down
8 changes: 4 additions & 4 deletions src/sage/coding/guruswami_sudan/gs_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,15 +849,15 @@ def decode_to_code(self, r):
s = self.multiplicity()
l = self.list_size()
tau = self.decoding_radius()
## SETUP INTERPOLATION PROBLEM
# SETUP INTERPOLATION PROBLEM
wy = k-1
points = [(alphas[i], r[i]/colmults[i]) for i in range(0,len(alphas))]
## SOLVE INTERPOLATION
points = [(alphas[i], r[i]/colmults[i]) for i in range(len(alphas))]
# SOLVE INTERPOLATION
try:
Q = self.interpolation_algorithm()(points, tau, (s,l), wy)
except TypeError:
raise ValueError("The provided interpolation algorithm has a wrong signature. See the documentation of `codes.decoders.GRSGuruswamiSudanDecoder.interpolation_algorithm()` for details")
## EXAMINE THE FACTORS AND CONVERT TO CODEWORDS
# EXAMINE THE FACTORS AND CONVERT TO CODEWORDS
try:
polynomials = self.rootfinding_algorithm()(Q, maxd=wy)
except TypeError:
Expand Down
7 changes: 4 additions & 3 deletions src/sage/coding/guruswami_sudan/interpolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,15 @@ def lee_osullivan_module(points, parameters, wy):
PF = F['x']
x = PF.gens()[0]
R = PF.lagrange_polynomial(points)
G = prod(x - points[i][0] for i in range(0, len(points)))
G = prod(x - points[i][0] for i in range(len(points)))
PFy = PF['y']
y = PFy.gens()[0]
ybasis = [(y-R)**i * G**(s-i) for i in range(0, s+1)] \
+ [y**(i-s) * (y-R)**s for i in range(s+1, l+1)]
ybasis = [(y-R)**i * G**(s-i) for i in range(s + 1)] \
+ [y**(i-s) * (y-R)**s for i in range(s + 1, l + 1)]

def pad(lst):
return lst + [0]*(l+1-len(lst))

modbasis = [pad(yb.coefficients(sparse=False)) for yb in ybasis]
return matrix(PF, modbasis)

Expand Down
16 changes: 8 additions & 8 deletions src/sage/crypto/mq/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2248,8 +2248,8 @@ def shift_rows_matrix(self):
bs = r*c*e
shift_rows = matrix(k, bs, bs)
I = MatrixSpace(k, e, e)(1)
for x in range(0, c):
for y in range(0, r):
for x in range(c):
for y in range(r):
_r = ((x*r)+y) * e
_c = (((x*r)+((r+1)*y)) * e) % bs
self._insert_matrix_into_matrix(shift_rows, I, _r, _c)
Expand Down Expand Up @@ -2290,14 +2290,14 @@ def lin_matrix(self, length=None):
if e == 4:
l = [k.from_integer(x) for x in (5, 1, 12, 5)]
for k in range( 0, length ):
for i in range(0, 4):
for j in range(0, 4):
for i in range(4):
for j in range(4):
lin[k*4+j, k*4+i] = l[(i-j) % 4] ** (2**j)
elif e == 8:
l = [k.from_integer(x) for x in (5, 9, 249, 37, 244, 1, 181, 143)]
for k in range( 0, length ):
for i in range(0, 8):
for j in range(0, 8):
for i in range(8):
for j in range(8):
lin[k*8+j, k*8+i] = l[(i-j) % 8] ** (2**j)

return lin
Expand Down Expand Up @@ -2651,8 +2651,8 @@ def shift_rows_matrix(self):
k = self.k
bs = r*c
shift_rows = matrix(k, r*c, r*c)
for x in range(0, c):
for y in range(0, r):
for x in range(c):
for y in range(r):
_r = ((x*r)+y)
_c = ((x*r)+((r+1)*y)) % bs
shift_rows[_r, _c] = 1
Expand Down
8 changes: 4 additions & 4 deletions src/sage/data_structures/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3247,7 +3247,7 @@ def __init__(self, series, shift, minimal_valuation):
true order at initialization::

sage: f = Stream_function(fun, True, 0)
sage: [f[i] for i in range(0, 10)]
sage: [f[i] for i in range(10)]
[0, 1, 1, 0, 1, 0, 0, 0, 1, 0]
sage: f._cache
{1: 1, 2: 1, 3: 0, 4: 1, 5: 0, 6: 0, 7: 0, 8: 1, 9: 0}
Expand All @@ -3257,7 +3257,7 @@ def __init__(self, series, shift, minimal_valuation):
sage: s._approximate_order
3
sage: f = Stream_function(fun, False, 0)
sage: [f[i] for i in range(0, 10)]
sage: [f[i] for i in range(10)]
[0, 1, 1, 0, 1, 0, 0, 0, 1, 0]
sage: f._cache
[1, 1, 0, 1, 0, 0, 0, 1, 0]
Expand Down Expand Up @@ -3432,7 +3432,7 @@ def is_nonzero(self):
sage: from sage.data_structures.stream import Stream_function, Stream_truncated
sage: def fun(n): return 1 if ZZ(n).is_power_of(2) else 0
sage: f = Stream_function(fun, False, 0)
sage: [f[i] for i in range(0, 4)]
sage: [f[i] for i in range(4)]
[0, 1, 1, 0]
sage: f._cache
[1, 1, 0]
Expand All @@ -3445,7 +3445,7 @@ def is_nonzero(self):
True

sage: f = Stream_function(fun, True, 0)
sage: [f[i] for i in range(0, 4)]
sage: [f[i] for i in range(4)]
[0, 1, 1, 0]
sage: f._cache
{1: 1, 2: 1, 3: 0}
Expand Down
2 changes: 1 addition & 1 deletion src/sage/dynamics/arithmetic_dynamics/affine_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ def multiplier(self, P, n, check=True):
l = identity_matrix(FractionField(self.codomain().base_ring()), N, N)
Q = P
J = self.jacobian()
for i in range(0, n):
for i in range(n):
R = self(Q)
l = J(tuple(Q)) * l # chain rule matrix multiplication
Q = R
Expand Down
5 changes: 3 additions & 2 deletions src/sage/dynamics/arithmetic_dynamics/endPN_minimal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ def bCheck(c, v, p, b):
sage: bCheck(11664*b^2 + 70227*b + 76059, 15/2, 3, b)
-1
"""
val = (v+1).floor()
val = (v + 1).floor()
deg = c.degree()
coeffs = c.coefficients(sparse=False)
lcoeff = coeffs[deg]
coeffs.remove(lcoeff)
check1 = [(coeffs[i].valuation(p) - lcoeff.valuation(p))/(deg - i) for i in range(0,len(coeffs)) if coeffs[i] != 0]
check1 = [(coeffs[i].valuation(p) - lcoeff.valuation(p))/(deg - i)
for i in range(len(coeffs)) if coeffs[i] != 0]
check2 = (val - lcoeff.valuation(p))/deg
check1.append(check2)
bval = min(check1)
Expand Down
7 changes: 4 additions & 3 deletions src/sage/dynamics/arithmetic_dynamics/wehlerK3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ def sigmaX(self, P, **kwds):
e = min(maxexp)

#Fix L and Q
for i in range(0,2):
for i in range(2):
while T[i].subs({w1:t1}) == 0:
T[i] = T[i]/t
T[i] = T[i].subs({w1:t1})
Expand Down Expand Up @@ -1435,7 +1435,8 @@ def sigmaY(self, P, **kwds):
-phi(self.Hpoly(0, 1, 2))]
maxexp = []

#Find highest exponent that we can divide out by to get a nonzero answer
# Find highest exponent that we can divide out by to get a
# nonzero answer
for i in range(2, len(T)):
e = 0
while (T[i]/t**e).subs({w1:t1}) == 0:
Expand All @@ -1444,7 +1445,7 @@ def sigmaY(self, P, **kwds):

e = min(maxexp)

for i in range(0, 2):
for i in range(2):
while T[i].subs({w1:t1}) == 0:
T[i] = T[i]/t
T[i] = T[i].subs({w1:t1})
Expand Down
3 changes: 2 additions & 1 deletion src/sage/geometry/hyperplane_arrangement/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,8 @@ def Ish(self, n, K=QQ, names=None):
A = H(*hyperplanes)
x = polygen(QQ, 'x')
charpoly = x * sum([(-1)**k * stirling_number2(n, n-k) *
prod([(x - 1 - j) for j in range(k, n-1)]) for k in range(0, n)])
prod([(x - 1 - j) for j in range(k, n-1)])
for k in range(n)])
A.characteristic_polynomial.set_cache(charpoly)
return A

Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedral_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def cell_iterator(self, increasing=True):
11
"""
cells = self.cells()
dim_index = range(0, self.dimension() + 1)
dim_index = range(self.dimension() + 1)
if not increasing:
dim_index = reversed(dim_index)
for d in dim_index:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ class ParametrizedSurface3D(SageObject):
sage: cc_array = [(ccc - K_min)/(K_max - K_min) for ccc in K_array]
sage: points_array = [ellipsoid_equation(u_array[counter][0],
....: u_array[counter][1])
....: for counter in range(0,len(u_array))]
....: for counter in range(len(u_array))]
sage: curvature_ellipsoid_plot = sum(point([xx # needs sage.plot
....: for xx in points_array[counter]],
....: color=hue(cc_array[counter]/2))
....: for counter in range(0,len(u_array)))
....: for counter in range(len(u_array)))
sage: curvature_ellipsoid_plot.show(aspect_ratio=1) # needs sage.plot

We can find the principal curvatures and principal directions of the
Expand Down
4 changes: 2 additions & 2 deletions src/sage/geometry/triangulation/base.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,13 @@ cdef class PointConfiguration_base(Parent):
EXAMPLES::

sage: p = PointConfiguration([[1,0], [2,3], [3,2]])
sage: [ p[i] for i in range(0,p.n_points()) ]
sage: [p[i] for i in range(p.n_points())]
[P(1, 0), P(2, 3), P(3, 2)]
sage: list(p)
[P(1, 0), P(2, 3), P(3, 2)]
sage: list(p.points())
[P(1, 0), P(2, 3), P(3, 2)]
sage: [ p.point(i) for i in range(0,p.n_points()) ]
sage: [p.point(i) for i in range(p.n_points())]
[P(1, 0), P(2, 3), P(3, 2)]
"""
return self._pts[i]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/phc.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@
t_val = CC(m.group(2), m.group(3))
temp_dict = {}
temp_dict["t"] = t_val
for i in range(0, count):
for i in range(count):

Check warning on line 570 in src/sage/interfaces/phc.py

View check run for this annotation

Codecov / codecov/patch

src/sage/interfaces/phc.py#L570

Added line #L570 was not covered by tests
a_line = fh.readline()
m = sols_regex.match(a_line)
if m:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/interfaces/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ def available_packages(self):
# The following was more structural, but breaks on my machine. (stein)
# p = p._sage_()
# s = p['_Dim'][0]
# l = [[p['DATA'][i],p['DATA'][s+1+i]] for i in range(0,s)]
# l = [[p['DATA'][i],p['DATA'][s+1+i]] for i in range(s)]
# return l

def _object_class(self):
Expand Down
2 changes: 1 addition & 1 deletion src/sage/knots/knot.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def dt_code(self):
crossing = i
break
if not string_found:
for i in range(0, crossing):
for i in range(crossing):
if abs(b[i]) == string or abs(b[i]) == string - 1:
string_found = True
crossing = i
Expand Down
4 changes: 2 additions & 2 deletions src/sage/libs/mpmath/ext_impl.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2116,7 +2116,7 @@ cdef MPF_hypsum(MPF *a, MPF *b, int p, int q, param_types, str ztype, coeffs, z,
raise ZeroDivisionError

# Multiply real factors
for k in range(0, cancellable_real):
for k in range(cancellable_real):
sig_check()
mpz_mul(PRE, PRE, AREAL[k])
mpz_fdiv_q(PRE, PRE, BREAL[k])
Expand All @@ -2129,7 +2129,7 @@ cdef MPF_hypsum(MPF *a, MPF *b, int p, int q, param_types, str ztype, coeffs, z,
mpz_mul_2exp(PRE, PRE, wp)
mpz_fdiv_q(PRE, PRE, BREAL[k])
if have_complex:
for k in range(0, cancellable_real):
for k in range(cancellable_real):
sig_check()
mpz_mul(PIM, PIM, AREAL[k])
mpz_fdiv_q(PIM, PIM, BREAL[k])
Expand Down
4 changes: 2 additions & 2 deletions src/sage/schemes/elliptic_curves/ell_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -4604,8 +4604,8 @@ def padic_elliptic_logarithm(self, Q, p):
if Q.is_zero():
k = 0
else:
for k in range(0,p):
Eqp = EllipticCurve(Qp(p, 2), [ ZZ(t) + k * p for t in E.a_invariants() ])
for k in range(p):
Eqp = EllipticCurve(Qp(p, 2), [ZZ(t) + k * p for t in E.a_invariants()])

P_Qps = Eqp.lift_x(ZZ(self.x()), all=True)
for P_Qp in P_Qps:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/structure/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
....: cake='waist begins again',
....: cream='fluffy, white stuff'))
....: tip = dict(default=10, description='Reward for good service',
....: checker = lambda tip: tip in range(0,20))
....: checker = lambda tip: tip in range(20))
sage: Menu.options
Current options for menu
- dessert: espresso
Expand Down Expand Up @@ -409,7 +409,7 @@ class options(GlobalOptions):
....: cake='waist begins again',
....: cream='fluffy, white stuff')),
....: tip=dict(default=10, description='Reward for good service',
....: checker=lambda tip: tip in range(0,20))
....: checker=lambda tip: tip in range(20))
....: )
sage: Menu.options
Current options for menu
Expand Down Expand Up @@ -908,7 +908,7 @@ class GlobalOptions(metaclass=GlobalOptionsMeta):
....: cake='waist begins again',
....: cream='fluffy white stuff'))
....: tip = dict(default=10, description='Reward for good service',
....: checker=lambda tip: tip in range(0,20))
....: checker=lambda tip: tip in range(20))
sage: Menu.options
Current options for menu
- dessert: espresso
Expand Down Expand Up @@ -1013,7 +1013,7 @@ def __init__(self, NAME=None, module='', option_class='', doc='', end_doc='', **
....: cake='waist begins again',
....: cream='fluffy white stuff'))
....: tip = dict(default=10, description='Reward for good service',
....: checker=lambda tip: tip in range(0,20))
....: checker=lambda tip: tip in range(20))
sage: menu._name # Default name is class name
'menu'
sage: class specials(GlobalOptions):
Expand Down
4 changes: 2 additions & 2 deletions src/sage/tensor/modules/free_module_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2801,12 +2801,12 @@ def contract(self, *args):
#
nb_cov_s = 0 # Number of covariant indices of self not involved in the
# contraction
for pos in range(k1,k1+l1):
for pos in range(k1, k1 + l1):
if pos not in pos1:
nb_cov_s += 1
nb_con_o = 0 # Number of contravariant indices of other not involved
# in the contraction
for pos in range(0,k2):
for pos in range(k2):
if pos not in pos2:
nb_con_o += 1
if nb_cov_s != 0 and nb_con_o != 0:
Expand Down
8 changes: 4 additions & 4 deletions src/sage/topology/delta_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def store_bdry(simplex, faces):
# else a dictionary indexed by simplices
dimension = max([f.dimension() for f in data])
old_data_by_dim = {}
for dim in range(0, dimension+1):
for dim in range(dimension + 1):
old_data_by_dim[dim] = []
new_data[dim] = []
for x in data:
Expand Down Expand Up @@ -466,7 +466,7 @@ def subcomplex(self, data):
new_dict[d+1].append(tuple([translate[n] for n in f]))
new_dict[d].append(cells[d][x])
cells_to_add.update(cells[d][x])
new_cells = [new_dict[n] for n in range(0, max_dim+1)]
new_cells = [new_dict[n] for n in range(max_dim + 1)]
sub = DeltaComplex(new_cells)
sub._is_subcomplex_of = {self: new_data}
return sub
Expand Down Expand Up @@ -564,7 +564,7 @@ def cells(self, subcomplex=None):
raise ValueError("this is not a subcomplex of self")
else:
subcomplex_cells = subcomplex._is_subcomplex_of[self]
for d in range(0, max(subcomplex_cells.keys())+1):
for d in range(max(subcomplex_cells.keys()) + 1):
L = list(cells[d])
for c in subcomplex_cells[d]:
L[c] = None
Expand Down Expand Up @@ -1303,7 +1303,7 @@ def elementary_subdivision(self, idx=-1):
# added_cells: dict indexed by (n-1)-cells, with value the
# corresponding new n-cell.
added_cells = {(): len(cells_dict[0])-1}
for n in range(0, dim):
for n in range(dim):
new_cells = {}
# for each n-cell in the standard simplex, add an
# (n+1)-cell to the subdivided complex.
Expand Down
Loading
Loading