Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
get rid of some range(O,*)
Browse files Browse the repository at this point in the history
  • Loading branch information
fchapoton committed May 24, 2022
1 parent 6f4efb0 commit 3b88284
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/sage/coding/binary_code.pyx
Expand Up @@ -3927,7 +3927,7 @@ cdef class BinaryCodeClassifier:
sage: soc_iter = codes.databases.self_orthogonal_binary_codes(12, 6, 4)
sage: L = list(soc_iter)
sage: for n in range(0, 13):
sage: for n in range(13):
....: s = 'n=%2d : '%n
....: for k in range(1,7):
....: s += '%3d '%len([C for C in L if C.length() == n and C.dimension() == k])
Expand Down
24 changes: 12 additions & 12 deletions src/sage/geometry/integral_points.pyx
Expand Up @@ -49,12 +49,12 @@ from sage.matrix.matrix_integer_dense cimport Matrix_integer_dense
## # R*Rinv == diagonal_matrix([d]*D.ncols() + [0]*(D.nrows()-D.ncols()))
## # If R is full rank, this is Rinv = matrix(ZZ, R.inverse() * d)
## Dinv = D.transpose()
## for i in range(0,D.ncols()):
## for i in range(D.ncols()):
## Dinv[i,i] = d/D[i,i]
## Rinv = V * Dinv * U
##
## gens = []
## for b in CartesianProduct(*[ range(0,i) for i in e ]):
## for b in CartesianProduct(*[ range(i) for i in e ]):
## # this is our generator modulo the lattice spanned by the rays
## gen_mod_rays = sum( b_i*u_i for b_i, u_i in zip(b,u) )
## q_times_d = Rinv * gen_mod_rays
Expand Down Expand Up @@ -175,7 +175,7 @@ cpdef tuple ray_matrix_normal_form(R):
if d == ZZ.zero():
raise ValueError('The spanning points are not linearly independent!')
cdef int i
Dinv = diagonal_matrix(ZZ, [ d // e[i] for i in range(0,D.ncols()) ])
Dinv = diagonal_matrix(ZZ, [ d // e[i] for i in range(D.ncols()) ])
VDinv = V * Dinv
return (e, d, VDinv)

Expand Down Expand Up @@ -224,20 +224,20 @@ cpdef tuple loop_over_parallelotope_points(e, d, Matrix_integer_dense VDinv,
cdef list gens = []
gen = lattice(ZZ.zero())
cdef Vector_integer_dense q_times_d = vector(ZZ, dim)
for base in itertools.product(*[ range(0,i) for i in e ]):
for i in range(0, dim):
for base in itertools.product(*[ range(i) for i in e ]):
for i in range(dim):
s = ZZ.zero()
for j in range(0, dim):
for j in range(dim):
s += VDinv.get_unsafe(i,j) * base[j]
q_times_d.set_unsafe(i, s % d)
for i in range(0, ambient_dim):
for i in range(ambient_dim):
s = ZZ.zero()
for j in range(0, dim):
for j in range(dim):
s += R.get_unsafe(i,j) * q_times_d.get_unsafe(j)
gen[i] = s / d
if A is not None:
s = ZZ.zero()
for i in range(0, ambient_dim):
for i in range(ambient_dim):
s += A[i] * gen[i]
if s > b:
continue
Expand Down Expand Up @@ -341,7 +341,7 @@ cdef translate_points(v_list, Vector_integer_dense delta):
cdef int dim = delta.degree()
cdef int i
for v in v_list:
for i in range(0,dim):
for i in range(dim):
v[i] -= delta.get_unsafe(i)


Expand Down Expand Up @@ -549,7 +549,7 @@ cpdef rectangular_box_points(list box_min, list box_max,
assert not (count_only and return_saturated)
cdef int d = len(box_min)
cdef int i, j
cdef list diameter = sorted([ (box_max[i]-box_min[i], i) for i in range(0,d) ],
cdef list diameter = sorted([ (box_max[i]-box_min[i], i) for i in range(d) ],
reverse=True)
cdef list diameter_value = [x[0] for x in diameter]
cdef list diameter_index = [x[1] for x in diameter]
Expand Down Expand Up @@ -790,7 +790,7 @@ cdef class Inequality_generic:
'generic: (2, 3, 7) x + -5 >= 0'
"""
s = 'generic: ('
s += ', '.join([str(self.A[i]) for i in range(0,len(self.A))])
s += ', '.join(str(self.A[i]) for i in range(len(self.A)))
s += ') x + ' + str(self.b) + ' >= 0'
return s
Expand Down
2 changes: 1 addition & 1 deletion src/sage/libs/mpmath/ext_impl.pyx
Expand Up @@ -2036,7 +2036,7 @@ cdef MPF_hypsum(MPF *a, MPF *b, int p, int q, param_types, str ztype, coeffs, z,
mpz_set_complex_tuple_fixed(ZRE, ZIM, z, wp)
else:
mpz_set_tuple_fixed(ZRE, z, wp)
for i in range(0,p):
for i in range(p):
sig_check()
if param_types[i] == 'Z':
mpz_init(AINT[aint])
Expand Down
2 changes: 1 addition & 1 deletion src/sage/matroids/matroid.pyx
Expand Up @@ -2351,7 +2351,7 @@ cdef class Matroid(SageObject):
False
"""
E = list(self.groundset())
for i in xrange(0, len(E) + 1):
for i in range(len(E) + 1):
for X in combinations(E, i):
XX = frozenset(X)
rX = self._rank(XX)
Expand Down
8 changes: 4 additions & 4 deletions src/sage/rings/polynomial/multi_polynomial_ring_base.pyx
Expand Up @@ -1238,7 +1238,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
sage: R._macaulay_resultant_is_reduced([1,3,2],[2,3,3]) # the monomial x*y^3*z^2 is not reduced w.r.t. degrees vector [2,3,3]
True
"""
diff = [mon_degs[i] - dlist[i] for i in xrange(0,len(dlist))]
diff = [mon_degs[i] - dlist[i] for i in range(len(dlist))]
return len([1 for d in diff if d >= 0]) == 1

def _macaulay_resultant_universal_polynomials(self, dlist):
Expand Down Expand Up @@ -1276,11 +1276,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing):
for d in dlist:
xlist = R.gens()
degs = IntegerVectors(d, n+1)
mon_d = [prod([xlist[i]**(deg[i]) for i in xrange(0,len(deg))])
mon_d = [prod([xlist[i]**(deg[i]) for i in range(len(deg))])
for deg in degs]

f = sum([mon_d[i]*ulist[i] for i in xrange(0,len(mon_d))])
flist.append (f)
f = sum([mon_d[i]*ulist[i] for i in range(len(mon_d))])
flist.append(f)
ulist = ulist[len(mon_d):]
return flist, R

Expand Down
15 changes: 7 additions & 8 deletions src/sage/rings/polynomial/real_roots.pyx
Expand Up @@ -2109,14 +2109,14 @@ def bernstein_up(d1, d2, s=None):
MS = MatrixSpace(QQ, s, d1+1, sparse=False)
m = MS()
scale = factorial(d2)/factorial(d2-d1)
for b in range(0, d1+1):
for b in range(d1 + 1):
scale2 = scale / binomial(d1, b)
if (d1 - b) & 1 == 1:
scale2 = -scale2
scale2 = ~scale2
for a in range(0, s):
for a in range(s):
ra = ZZ(subsample_vec(a, s, d2 + 1))
m[a, b] = prod([ra-i for i in range(0, b)]) * prod([ra-i for i in range(d2-d1+b+1, d2+1)]) * scale2
m[a, b] = prod([ra-i for i in range(b)]) * prod([ra-i for i in range(d2-d1+b+1, d2+1)]) * scale2

return m

Expand Down Expand Up @@ -4369,7 +4369,7 @@ def to_bernstein(p, low=0, high=1, degree=None):
raise ValueError('Bernstein degree must be at least polynomial degree')
vs = ZZ ** (degree + 1)
c = vs(0)
for i in range(0, p.degree() + 1):
for i in range(p.degree() + 1):
c[i] = p[i]
scale = ZZ(1)
if low == 0:
Expand All @@ -4385,7 +4385,8 @@ def to_bernstein(p, low=0, high=1, degree=None):
reverse_intvec(c)
taylor_shift1_intvec(c)
reverse_intvec(c)
return ([c[k] / binomial(degree, k) for k in range(0, degree+1)], scale)
return ([c[k] / binomial(degree, k) for k in range(degree + 1)], scale)


def to_bernstein_warp(p):
"""
Expand All @@ -4399,14 +4400,12 @@ def to_bernstein_warp(p):
sage: to_bernstein_warp(1 + x + x^2 + x^3 + x^4 + x^5)
[1, 1/5, 1/10, 1/10, 1/5, 1]
"""

c = p.list()

for i in range(len(c)):
c[i] = c[i] / binomial(len(c) - 1, i)

return c


def bernstein_expand(Vector_integer_dense c, int d2):
"""
Given an integer vector representing a Bernstein polynomial p, and
Expand Down
2 changes: 1 addition & 1 deletion src/sage/sets/recursively_enumerated_set.pyx
Expand Up @@ -273,7 +273,7 @@ convention is that the generated elements are the ``s := f(n)``, except when
....: st = set(st) # make a copy
....: if st:
....: el = st.pop()
....: for i in range(0, len(lst)+1):
....: for i in range(len(lst)+1):
....: yield (lst[0:i]+[el]+lst[i:], st)
sage: list(children(([1,2], {3,7,9})))
[([9, 1, 2], {3, 7}), ([1, 9, 2], {3, 7}), ([1, 2, 9], {3, 7})]
Expand Down
4 changes: 2 additions & 2 deletions src/sage/structure/element.pyx
Expand Up @@ -823,8 +823,8 @@ cdef class Element(SageObject):
variables=[]
# use "gen" instead of "gens" as a ParentWithGens is not
# required to have the latter
for i in xrange(0,ngens):
gen=parent.gen(i)
for i in range(ngens):
gen = parent.gen(i)
if str(gen) in kwds:
variables.append(kwds[str(gen)])
elif in_dict and gen in in_dict:
Expand Down

0 comments on commit 3b88284

Please sign in to comment.