diff --git a/src/sage/combinat/designs/evenly_distributed_sets.pyx b/src/sage/combinat/designs/evenly_distributed_sets.pyx index 744cb4e3513..1d1a7acb8ec 100644 --- a/src/sage/combinat/designs/evenly_distributed_sets.pyx +++ b/src/sage/combinat/designs/evenly_distributed_sets.pyx @@ -218,24 +218,24 @@ cdef class EvenlyDistributedSetsBacktracker: raise ValueError(f"{K} is not a field") cdef unsigned int q = K.cardinality() cdef unsigned int e = k*(k-1)/2 - if (q-1) % (2*e) != 0: + if (q-1) % (2*e): raise ValueError("k(k-1)={} does not divide q-1={}".format(k*(k-1),q-1)) - cdef unsigned int m = (q-1)/e + cdef unsigned int m = (q - 1) // e self.q = q self.e = e self.k = k - self.m = (q-1) / e + self.m = (q - 1) // e self.K = K self.diff = check_calloc(q, sizeof(unsigned int *)) self.diff[0] = check_malloc(q*q*sizeof(unsigned int)) - for i in range(1,self.q): + for i in range(1, self.q): self.diff[i] = self.diff[i-1] + q self.ratio = check_calloc(q, sizeof(unsigned int *)) self.ratio[0] = check_malloc(q*q*sizeof(unsigned int)) - for i in range(1,self.q): + for i in range(1, self.q): self.ratio[i] = self.ratio[i-1] + q self.B = check_malloc(k*sizeof(unsigned int)) diff --git a/src/sage/combinat/designs/subhypergraph_search.pyx b/src/sage/combinat/designs/subhypergraph_search.pyx index b7a71a17b86..8de300efe2a 100644 --- a/src/sage/combinat/designs/subhypergraph_search.pyx +++ b/src/sage/combinat/designs/subhypergraph_search.pyx @@ -133,7 +133,7 @@ cdef inline int bs_get(uint64_t * bitset, int index) noexcept: r""" Return a bit of a bitset """ - return (bitset[index/64]>>(index%64))&1 + return (bitset[index//64]>>(index%64))&1 cdef inline void bs_set(uint64_t * bitset, int index, int bit) noexcept: r""" @@ -142,8 +142,8 @@ cdef inline void bs_set(uint64_t * bitset, int index, int bit) noexcept: "bit" *MUST* be equal to either 0 or to 1. The code does not involve any "if". """ - bitset[index/64] &= ~(( 1)< bit)< 1)< bit)< sig_malloc(sizeof(int)*n) h.sets = sig_malloc(h.m*sizeof(uint64_t *)) h.set_space = sig_calloc(h.m*(h.limbs+1),sizeof(uint64_t)) diff --git a/src/sage/matroids/matroid.pyx b/src/sage/matroids/matroid.pyx index 9fb3ef581b9..0384ff81a22 100644 --- a/src/sage/matroids/matroid.pyx +++ b/src/sage/matroids/matroid.pyx @@ -5394,7 +5394,7 @@ cdef class Matroid(SageObject): E = set(self.groundset()) Q = set(list(E)[:m]) E = E-Q - for r in range(len(Q)/2 + 1): + for r in range(len(Q) // 2 + 1): R = set(list(E)[:r]) for Q1 in map(set, combinations(Q, r)): Q2 = Q-Q1 diff --git a/src/sage/modular/arithgroup/congroup.pyx b/src/sage/modular/arithgroup/congroup.pyx index ee988672a4f..d55c0c0ce7c 100644 --- a/src/sage/modular/arithgroup/congroup.pyx +++ b/src/sage/modular/arithgroup/congroup.pyx @@ -116,7 +116,7 @@ def degeneracy_coset_representatives_gamma0(int N, int M, int t): # total number of coset representatives that we'll find n = Gamma0(N).index() / Gamma0(M).index() k = 0 # number found so far - Ndivt = N / t + Ndivt = N // t R = check_allocarray(4 * n, sizeof(int)) halfmax = 2*(n+10) while k < n: @@ -126,10 +126,10 @@ def degeneracy_coset_representatives_gamma0(int N, int M, int t): g = arith_int.c_xgcd_int(-cc,dd,&bb,&aa) if g == 0: continue - cc = cc / g + cc = cc // g if cc % M != 0: continue - dd = dd / g + dd = dd // g # Test if we've found a new coset representative. is_new = 1 for i in range(k): @@ -217,7 +217,7 @@ def degeneracy_coset_representatives_gamma1(int N, int M, int t): # total number of coset representatives that we'll find n = Gamma1(N).index() / Gamma1(M).index() d = arith_int.c_gcd_int(t, N // t) - n = n / d + n = n // d k = 0 # number found so far Ndivt = N // t R = check_allocarray(4 * n, sizeof(int)) @@ -229,10 +229,10 @@ def degeneracy_coset_representatives_gamma1(int N, int M, int t): g = arith_int.c_xgcd_int(-cc, dd, &bb, &aa) if g == 0: continue - cc = cc / g + cc = cc // g if cc % M != 0: continue - dd = dd / g + dd = dd // g if M != 1 and dd % M != 1: continue # Test if we've found a new coset representative. diff --git a/src/sage/modular/hypergeometric_misc.pxd b/src/sage/modular/hypergeometric_misc.pxd index 00bf9a97e9a..ccd013ca2ee 100644 --- a/src/sage/modular/hypergeometric_misc.pxd +++ b/src/sage/modular/hypergeometric_misc.pxd @@ -1,2 +1,3 @@ -cpdef hgm_coeffs(long long p, int f, int prec, gamma, m, int D, +cpdef hgm_coeffs(long long p, unsigned int f, + int prec, gamma, m, int D, gtable, int gtable_prec, bint use_longs) diff --git a/src/sage/modular/hypergeometric_misc.pyx b/src/sage/modular/hypergeometric_misc.pyx index 3be8e4dd545..f3e37b515d9 100644 --- a/src/sage/modular/hypergeometric_misc.pyx +++ b/src/sage/modular/hypergeometric_misc.pyx @@ -6,7 +6,8 @@ from cpython cimport array from cysignals.signals cimport sig_check from sage.rings.integer cimport Integer -cpdef hgm_coeffs(long long p, int f, int prec, gamma, m, int D, +cpdef hgm_coeffs(long long p, unsigned int f, + int prec, gamma, m, int D, gtable, int gtable_prec, bint use_longs): r""" Compute coefficients for the hypergeometric trace formula. @@ -35,8 +36,8 @@ cpdef hgm_coeffs(long long p, int f, int prec, gamma, m, int D, """ from sage.rings.padics.factory import Zp - cdef int gl, j, k, l, v, gv - cdef long long i, q1, w, w1, w2, q2, r, r1 + cdef int gl, j, k, v, gv + cdef long long i, l, q1, w, w1, w2, q2, r, r1 cdef bint flip, use_longlongs q1 = p ** f - 1 diff --git a/src/sage/modular/modform/eis_series_cython.pyx b/src/sage/modular/modform/eis_series_cython.pyx index 8126d1f8135..73ffdfab324 100644 --- a/src/sage/modular/modform/eis_series_cython.pyx +++ b/src/sage/modular/modform/eis_series_cython.pyx @@ -107,12 +107,12 @@ cpdef Ek_ZZ(int k, int prec=10): # compute the valuation of n at p additional_p_powers = 0 - temp_index = ind / p + temp_index = ind // p remainder = 0 while not remainder: additional_p_powers += 1 prev_index = temp_index - temp_index = temp_index / p + temp_index = temp_index // p remainder = prev_index - p*temp_index # if we need a new sum, it has to be the next uncomputed one. diff --git a/src/sage/modular/modsym/heilbronn.pyx b/src/sage/modular/modsym/heilbronn.pyx index a14f2e6ccac..82adf9efa20 100644 --- a/src/sage/modular/modsym/heilbronn.pyx +++ b/src/sage/modular/modsym/heilbronn.pyx @@ -383,7 +383,7 @@ cdef class HeilbronnCremona(Heilbronn): # NOTE: In C, -p/2 means "round toward 0", but in Python it # means "round down." sig_on() - for r in range(-p/2, p/2+1): + for r in range(-p // 2, p // 2 + 1): x1 = p x2 = -r y1 = 0 @@ -394,7 +394,7 @@ cdef class HeilbronnCremona(Heilbronn): x3 = 0 y3 = 0 q = 0 - list_append4(L, x1,x2,y1,y2) + list_append4(L, x1, x2, y1, y2) while b: q = roundf(a / b) c = a - b*q @@ -406,8 +406,8 @@ cdef class HeilbronnCremona(Heilbronn): y3 = q*y2 - y1 y1 = y2 y2 = y3 - list_append4(L, x1,x2, y1,y2) - self.length = L.i/4 + list_append4(L, x1, x2, y1, y2) + self.length = L.i // 4 sig_off() @@ -491,7 +491,7 @@ cdef class HeilbronnMerel(Heilbronn): for a in range(1, n+1): ## We have ad-bc=n so c=0 and ad=n, or b=(ad-n)/c ## Must have ad - n >= 0, so d must be >= Ceiling(n/a). - q = n/a + q = n // a if q*a == n: d = q for b in range(a): @@ -503,10 +503,10 @@ cdef class HeilbronnMerel(Heilbronn): ## Divisor c of bc must satisfy Floor(bc/c) lt a and c lt d. ## c ge (bc div a + 1) <=> Floor(bc/c) lt a (for integers) ## c le d - 1 <=> c lt d - for c in range(bc/a + 1, d): + for c in range(bc // a + 1, d): if bc % c == 0: - list_append4(L,a,bc/c,c,d) - self.length = L.i/4 + list_append4(L, a, bc // c, c, d) + self.length = L.i // 4 sig_off() diff --git a/src/sage/modular/modsym/p1list.pyx b/src/sage/modular/modsym/p1list.pyx index 5e48d6b1369..7ceda12d5c8 100644 --- a/src/sage/modular/modsym/p1list.pyx +++ b/src/sage/modular/modsym/p1list.pyx @@ -94,8 +94,8 @@ cdef int c_p1_normalize_int(int N, int u, int v, # Now g = s*u + t*N, so s is a "pseudo-inverse" of u mod N # Adjust s modulo N/g so it is coprime to N. - if g!=1: - d = N/g + if g != 1: + d = N // g while arith_int.c_gcd_int(s,N) != 1: s = (s+d) % N @@ -105,8 +105,8 @@ cdef int c_p1_normalize_int(int N, int u, int v, min_v = v min_t = 1 - if g!=1: - Ng = N/g + if g != 1: + Ng = N // g vNg = (v*Ng) % N t = 1 for k in range(2, g + 1): @@ -355,8 +355,8 @@ cdef int c_p1_normalize_llong(int N, int u, int v, # Now g = s*u + t*N, so s is a "pseudo-inverse" of u mod N # Adjust s modulo N/g so it is coprime to N. - if g!=1: - d = N/g + if g != 1: + d = N // g while arith_int.c_gcd_int(s,N) != 1: s = (s+d) % N @@ -367,8 +367,8 @@ cdef int c_p1_normalize_llong(int N, int u, int v, min_v = v min_t = 1 - if g!=1: - Ng = N/g + if g != 1: + Ng = N // g vNg = ((v * Ng) % ll_N) t = 1 for k in range(2, g + 1): @@ -640,8 +640,8 @@ cdef int p1_normalize_xgcdtable(int N, int u, int v, # Now g = s*u + t*N, so s is a "pseudo-inverse" of u mod N # Adjust s modulo N/g so it is coprime to N. - if g!=1: - d = N/g + if g != 1: + d = N // g while t_g[s] != 1: # while arith_int.c_gcd_int(s,N) != 1: s = (s+d) % N @@ -651,8 +651,8 @@ cdef int p1_normalize_xgcdtable(int N, int u, int v, min_v = v min_t = 1 - if g!=1: - Ng = N/g + if g != 1: + Ng = N // g vNg = (v*Ng) % N t = 1 for k in range(2, g + 1): @@ -1237,17 +1237,17 @@ def lift_to_sl2z_int(int c, int d, int N): # compute prime-to-d part of m. while True: - g = arith_int.c_gcd_int(m,d) + g = arith_int.c_gcd_int(m, d) if g == 1: break - m = m / g + m = m // g # compute prime-to-N part of m. while True: - g = arith_int.c_gcd_int(m,N) + g = arith_int.c_gcd_int(m, N) if g == 1: break - m = m / g + m = m // g d += N * m g = arith_int.c_xgcd_int(c, d, &z1, &z2) @@ -1299,7 +1299,7 @@ def lift_to_sl2z_llong(llong c, llong d, int N): g = arith_llong.c_xgcd_longlong(c, d, &z1, &z2) # We're lucky: z1*c + z2*d = 1. - if g==1: + if g == 1: return [z2, -z1, c, d] # Have to try harder. @@ -1307,17 +1307,17 @@ def lift_to_sl2z_llong(llong c, llong d, int N): # compute prime-to-d part of m. while True: - g = arith_llong.c_gcd_longlong(m,d) + g = arith_llong.c_gcd_longlong(m, d) if g == 1: break - m = m / g + m = m // g # compute prime-to-N part of m. while True: - g = arith_llong.c_gcd_longlong(m,N) + g = arith_llong.c_gcd_longlong(m, N) if g == 1: break - m = m / g + m = m // g d += N * m g = arith_llong.c_xgcd_longlong(c, d, &z1, &z2) diff --git a/src/sage/schemes/elliptic_curves/mod_sym_num.pyx b/src/sage/schemes/elliptic_curves/mod_sym_num.pyx index 927df5e5a42..e55500f0d0f 100755 --- a/src/sage/schemes/elliptic_curves/mod_sym_num.pyx +++ b/src/sage/schemes/elliptic_curves/mod_sym_num.pyx @@ -256,9 +256,9 @@ cdef llong llxgcd(llong a, llong b, llong *ss, llong *tt) except -1: q = 0 r = 0 s = 1 - while (b): + while b: c = a % b - quot = a/b + quot = a // b a = b b = c new_r = p - quot*r @@ -365,9 +365,9 @@ cdef int proj_normalise(llong N, llong u, llong v, # Now g = s*u + t*N, so s is a "pseudo-inverse" of u mod N # Adjust s modulo N/g so it is coprime to N. if g != 1: - d = N / g + d = N // g while llgcd(s, N) != 1: - s = (s+d) % N + s = (s + d) % N # verbose(" now g=%s, s=%s, t=%s" % (g,s,t), level=5) # Multiply [u,v] by s; then [s*u,s*v] = [g,s*v] (mod N) @@ -376,7 +376,7 @@ cdef int proj_normalise(llong N, llong u, llong v, min_v = v min_t = 1 if g != 1: - Ng = N / g + Ng = N // g vNg = (v * Ng) % N t = 1 k = 2 @@ -456,24 +456,24 @@ cdef int best_proj_point(llong u, llong v, llong N, else: # cases like (p:q) mod p*q drop here p = llgcd(u, N) q = llgcd(v, N) - Nnew = N / p / q - w = ((u/p) * llinvmod(v/q, Nnew)) % Nnew - y0 = N/q + Nnew = (N // p) // q + w = ((u // p) * llinvmod(v // q, Nnew)) % Nnew + y0 = N // q y1 = 0 x0 = w*p x1 = q # y will always be the longer and x the shorter - while llabs(x0) + llabs(x1) < llabs(y0)+llabs(y1): + while llabs(x0) + llabs(x1) < llabs(y0) + llabs(y1): if llsign(x0) == llsign(x1): - r = (y0+y1) / (x0+x1) + r = (y0+y1) // (x0+x1) else: - r = (y0-y1) / (x0-x1) + r = (y0-y1) // (x0-x1) t0 = y0 - r * x0 t1 = y1 - r * x1 s0 = t0 - x0 s1 = t1 - x1 - if llabs(s0)+llabs(s1) < llabs(t0)+llabs(t1): + if llabs(s0) + llabs(s1) < llabs(t0) + llabs(t1): t0 = s0 t1 = s1 # t is now the shortest vector on the line y + RR x @@ -593,7 +593,7 @@ cdef class _CuspsForModularSymbolNumerical: a -= m self._r = Rational((a, m)) B = llgcd(m, N) - self._width = N / B + self._width = N // B self._a = a self._m = m self._N_level = N @@ -625,7 +625,7 @@ cdef class _CuspsForModularSymbolNumerical: # verbose(" enter atkin_lehner for cusp r=%s" % self._r, level=5) Q = self._width B = llgcd(self._m, self._N_level) - c = self._m / B + c = self._m // B if llgcd(Q, B) != 1: raise ValueError("This cusp is not in the Atkin-Lehner " "orbit of oo.") @@ -2125,12 +2125,12 @@ cdef class ModularSymbolNumerical: verbose(" yields %s " % int2c, level=3) ans = int2c + int1c else: # use_partials - g = llgcd(Q,QQ) + g = llgcd(Q, QQ) D = Q * QQ D /= g D *= llabs(a*mm-aa*m) - xi = (Q*aa*u+v*mm) * QQ /g * llsign(a*mm-aa*m) - xixi = (QQ*a*uu+vv*m) * Q /g * llsign(aa*m-a*mm) + xi = (Q*aa*u+v*mm) * (QQ // g) * llsign(a*mm-aa*m) + xixi = (QQ*a*uu+vv*m) * (Q // g) * llsign(aa*m-a*mm) z = Q * QQ * (a*mm-aa*m)**2 ka = self._kappa(D, z, eps/2) twopii = TWOPI * complex("j") @@ -2787,33 +2787,33 @@ cdef class ModularSymbolNumerical: else: # (c:d) = (u:v) but c and d are fairly small # in absolute value - Mu = llgcd(u,N) - Qu = N/Mu - Mv = llgcd(v,N) - Qv = N/Mv - isunitary = (llgcd(Qu,Mu) == 1 and llgcd(Qv,Mv) == 1) + Mu = llgcd(u, N) + Qu = N // Mu + Mv = llgcd(v, N) + Qv = N // Mv + isunitary = (llgcd(Qu, Mu) == 1 and llgcd(Qv, Mv) == 1) if isunitary: # unitary case _ = best_proj_point(u, v, self._N_E, &c, &d) else: # at least one of the two cusps is not unitary du = llgcd(Qu,Mu) - dv = llgcd(Qv,Mv) - NMM = N/Mv/Mu + dv = llgcd(Qv, Mv) + NMM = N // Mv // Mu if dv == 1: c = Mu - d = llinvmod(u/Mu, NMM) + d = llinvmod(u // Mu, NMM) d *= v - d = d % (N/Mu) + d = d % (N // Mu) while llgcd(c,d) != 1: - d += N/Mu + d += N // Mu d = d % N # now (u:v) = (c:d) with c as small as possible. else: d = Mv - c = llinvmod(v/Mv, NMM) + c = llinvmod(v // Mv, NMM) c *= u - c = c % (N/Mv) - while llgcd(c,d) != 1: - c += N/Mv + c = c % (N // Mv) + while llgcd(c, d) != 1: + c += N // Mv c = c % N # now (u:v) = (c:d) with d as small as possible. # verbose(" better representant on P^1: " @@ -3170,8 +3170,8 @@ cdef class ModularSymbolNumerical: RR = RealField(53) N = self._N_E - Q = N / llgcd(m,N) - if llgcd(m,Q) > 1: + Q = N // llgcd(m, N) + if llgcd(m, Q) > 1: raise NotImplementedError("Only implemented for cusps that are " "in the Atkin-Lehner orbit of oo") # verbose(" compute all partial sums with denominator m=%s" % m, diff --git a/src/sage/structure/sage_object.pyx b/src/sage/structure/sage_object.pyx index fb6d4d0f686..7102316be70 100644 --- a/src/sage/structure/sage_object.pyx +++ b/src/sage/structure/sage_object.pyx @@ -719,7 +719,7 @@ cdef class SageObject: try: s = self._interface_init_(I) except Exception: - raise NotImplementedError("coercion of object %s to %s not implemented:\n%s\n%s" % (repr(self), I)) + raise NotImplementedError("coercion of object %s to %s not implemented" % (repr(self), I)) X = I(s) if c: try: