diff --git a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx index 6913bbc26fc..e9c70c9de29 100644 --- a/src/sage/algebras/letterplace/free_algebra_letterplace.pyx +++ b/src/sage/algebras/letterplace/free_algebra_letterplace.pyx @@ -176,7 +176,6 @@ cdef MPolynomialRing_libsingular make_letterplace_ring(base_ring, blocks): (Lexicographic term order of length 3, Lexicographic term order of length 3) """ - n = base_ring.ngens() T0 = base_ring.term_order() T = T0 cdef i @@ -680,7 +679,6 @@ cdef class FreeAlgebra_letterplace(Algebra): C = self.current_ring() cdef FreeAlgebraElement_letterplace x ngens = self.__ngens - degbound = self._degbound cdef list G = [C(x._poly) for x in g] from sage.groups.perm_gps.permgroup_named import CyclicPermutationGroup CG = CyclicPermutationGroup(C.ngens()) diff --git a/src/sage/arith/constants.pxd b/src/sage/arith/constants.pxd index 6e5e713707f..371960ec3bc 100644 --- a/src/sage/arith/constants.pxd +++ b/src/sage/arith/constants.pxd @@ -13,14 +13,14 @@ # cdef extern from *: - double M_PI "0x3.243f6a8885a3p+0" # π - double M_EULER "0x9.3c467e37db0c8p-4" # γ - double M_LN2 "0xb.17217f7d1cf78p-4" # log(2) - double M_LN10 "0x2.4d763776aaa2cp+0" # log(10) - double M_LNPI "0x1.250d048e7a1bdp+0" # log(π) - double M_1_LN2 "0x1.71547652b82fep+0" # 1/log(2) - double M_1_LN10 "0x6.f2dec549b9438p-4" # 1/log(10) - double M_1_LNPI "0xd.fa22fdd8cfd98p-4" # 1/log(π) - double M_LN2_LN10 "0x4.d104d427de7fcp-4" # log(2)/log(10) + double M_PI "0x3.243f6a8885a3p+0" # π + double M_EULER "0x9.3c467e37db0c8p-4" # γ + double M_LN2 "0xb.17217f7d1cf78p-4" # log(2) + double M_LN10 "0x2.4d763776aaa2cp+0" # log(10) + double M_LNPI "0x1.250d048e7a1bdp+0" # log(π) + double M_1_LN2 "0x1.71547652b82fep+0" # 1/log(2) + double M_1_LN10 "0x6.f2dec549b9438p-4" # 1/log(10) + double M_1_LNPI "0xd.fa22fdd8cfd98p-4" # 1/log(π) + double M_LN2_LN10 "0x4.d104d427de7fcp-4" # log(2)/log(10) double LOG_TEN_TWO_PLUS_EPSILON "0x3.5269e12f346e4p+0" # log(10,2) rounded up diff --git a/src/sage/arith/multi_modular.pyx b/src/sage/arith/multi_modular.pyx index 50b79b016c1..83f9df2a7c7 100644 --- a/src/sage/arith/multi_modular.pyx +++ b/src/sage/arith/multi_modular.pyx @@ -391,7 +391,7 @@ cdef class MultiModularBasis_base(): new_partial_products.append(M) mpz_clear(height) return self.extend_with_primes(new_moduli, new_partial_products, - check=False) + check=False) def _extend_moduli_to_count(self, int count): r""" @@ -470,7 +470,7 @@ cdef class MultiModularBasis_base(): Compute and store `\prod_j=1^{i-1} m_j^{-1} (mod m_i)` for i >= start. """ if start == 0: - start = 1 # first one is trivial, never used + start = 1 # first one is trivial, never used self.C[0] = 1 for i in range(start, self.n): self.C[i] = ai.c_inverse_mod_longlong(mpz_fdiv_ui(self.partial_products[i-1], self.moduli[i]), self.moduli[i]) @@ -483,7 +483,7 @@ cdef class MultiModularBasis_base(): self._extend_moduli_to_height_c(height) cdef int count - count = self.n * mpz_sizeinbase(height, 2) / mpz_sizeinbase(self.partial_products[self.n-1], 2) # an estimate + count = self.n * mpz_sizeinbase(height, 2) / mpz_sizeinbase(self.partial_products[self.n-1], 2) # an estimate count = max(min(count, self.n), 1) while count > 1 and mpz_cmp(height, self.partial_products[count-1]) < 0: count -= 1 @@ -568,7 +568,7 @@ cdef class MultiModularBasis_base(): s = 1 mpz_init_set_si(z, b[0]) if b[0] == 0: - while s < len and b[s] == 0: # fast forward to first non-zero + while s < len and b[s] == 0: # fast forward to first non-zero s += 1 else: s = 0 @@ -619,10 +619,10 @@ cdef class MultiModularBasis_base(): if offset == 0: mpz_set_si(z[j], b[0][j]) if b[0][j] == 0: - while i < len and b[i][j] == 0: # fast forward to first non-zero + while i < len and b[i][j] == 0: # fast forward to first non-zero i += 1 while i < len: - mpz_set_si(u, ((b[i][j] + m[i] - mpz_fdiv_ui(z[j], m[i])) * self.C[i]) % m[i]) # u = ((b_i - z) * C_i) % m_i + mpz_set_si(u, ((b[i][j] + m[i] - mpz_fdiv_ui(z[j], m[i])) * self.C[i]) % m[i]) # u = ((b_i - z) * C_i) % m_i mpz_mul(u, u, self.partial_products[i-1]) mpz_add(z[j], z[j], u) i += 1 @@ -831,7 +831,7 @@ cdef class MultiModularBasis_base(): """ if isinstance(ix, slice): return self.__class__(self.list()[ix], l_bound = self._l_bound, - u_bound = self._u_bound) + u_bound = self._u_bound) cdef Py_ssize_t i = ix if i != ix: @@ -850,7 +850,7 @@ cdef class MultiModularBasis_base(): sage: MultiModularBasis_base([10007]) MultiModularBasis with moduli [10007] """ - return "MultiModularBasis with moduli "+str(self.list()) + return "MultiModularBasis with moduli " + str(self.list()) cdef class MultiModularBasis(MultiModularBasis_base): diff --git a/src/sage/arith/numerical_approx.pyx b/src/sage/arith/numerical_approx.pyx index 005b88621c4..37a78833e61 100644 --- a/src/sage/arith/numerical_approx.pyx +++ b/src/sage/arith/numerical_approx.pyx @@ -2,15 +2,15 @@ r""" Generic numerical approximation function """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2016 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from sage.structure.parent cimport Parent from sage.structure.element cimport parent diff --git a/src/sage/arith/power.pyx b/src/sage/arith/power.pyx index 2900d9f2a45..acd5f885e85 100644 --- a/src/sage/arith/power.pyx +++ b/src/sage/arith/power.pyx @@ -5,15 +5,15 @@ This implements powering of arbitrary objects using a square-and-multiply algorithm. """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2017 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from cysignals.signals cimport sig_check diff --git a/src/sage/arith/rational_reconstruction.pyx b/src/sage/arith/rational_reconstruction.pyx index 6d2a4886bb3..8342f672cc2 100644 --- a/src/sage/arith/rational_reconstruction.pyx +++ b/src/sage/arith/rational_reconstruction.pyx @@ -11,7 +11,7 @@ AUTHORS: - Jeroen Demeyer (2014-10-20): move this function from ``gmp.pxi``, simplify and fix some bugs, see :trac:`17180` """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2006 ??? # Copyright (C) 2014 Jeroen Demeyer # @@ -19,8 +19,8 @@ AUTHORS: # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from cysignals.signals cimport sig_on, sig_off diff --git a/src/sage/crypto/boolean_function.pxd b/src/sage/crypto/boolean_function.pxd index 2821fb0d1b0..8a97eb875aa 100644 --- a/src/sage/crypto/boolean_function.pxd +++ b/src/sage/crypto/boolean_function.pxd @@ -1,8 +1,8 @@ cdef inline unsigned int hamming_weight(unsigned int x): # valid for 32bits - x -= (x>>1) & 0x55555555UL # 0-2 in 2 bits - x = ((x>>2) & 0x33333333UL) + (x & 0x33333333UL) # 0-4 in 4 bits - x = ((x>>4) + x) & 0x0f0f0f0fUL # 0-8 in 8 bits + x -= (x>>1) & 0x55555555UL # 0-2 in 2 bits + x = ((x>>2) & 0x33333333UL) + (x & 0x33333333UL) # 0-4 in 4 bits + x = ((x>>4) + x) & 0x0f0f0f0fUL # 0-8 in 8 bits x *= 0x01010101UL return x>>24 diff --git a/src/sage/crypto/boolean_function.pyx b/src/sage/crypto/boolean_function.pyx index 05ec9cfc065..13d0a043ff8 100644 --- a/src/sage/crypto/boolean_function.pyx +++ b/src/sage/crypto/boolean_function.pyx @@ -67,7 +67,7 @@ cdef walsh_hadamard(long *f, int ldn): cdef long n, ldm, m, mh, t1, t2, r, j, u, v n = 1 << ldn for ldm in range(1, ldn+1): - m = (1 << ldm) + m = (1 << ldm) mh = m // 2 # If this is ``for r in range(0, n, m):``, then Cython generates horrible C code for 0 <= r < n by m: @@ -101,7 +101,7 @@ cdef long yellow_code(unsigned long a): cdef unsigned long r = a while(s): sig_check() - r ^= ( (r&m) << s ) + r ^= (r&m) << s s >>= 1 m ^= (m< L) for i in range(L): - bitset_set_to(self._truth_table, i, x[i])#int(x[i])&1) + bitset_set_to(self._truth_table, i, x[i]) # int(x[i])&1) elif isinstance(x, BooleanPolynomial): - # initialisation from a Boolean polynomial + # initialisation from a Boolean polynomial self._nvariables = ZZ(x.parent().ngens()) bitset_init(self._truth_table, (1< (1< (1<>k)&1: m *= G[k] - P+=m + P += m bitset_free(anf) return P @@ -710,7 +712,7 @@ cdef class BooleanFunction(SageObject): cdef mp_bitcnt_t i,n if self._walsh_hadamard_transform is None: - n = self._truth_table.size + n = self._truth_table.size temp = sig_malloc(sizeof(long)*n) for i in range(n): @@ -748,7 +750,7 @@ cdef class BooleanFunction(SageObject): def is_balanced(self): """ - Return True if the function takes the value True half of the time. + Return ``True`` if the function takes the value ``True`` half of the time. EXAMPLES:: @@ -764,8 +766,10 @@ cdef class BooleanFunction(SageObject): def is_symmetric(self): """ - Return True if the function is symmetric, i.e. invariant under - permutation of its input bits. Another way to see it is that the + Return ``True`` if the function is symmetric, i.e. invariant under + permutation of its input bits. + + Another way to see it is that the output depends only on the Hamming weight of the input. EXAMPLES:: @@ -781,18 +785,19 @@ cdef class BooleanFunction(SageObject): True """ cdef mp_bitcnt_t i - cdef list T = [ self(2**i-1) for i in range(self._nvariables+1) ] + cdef list T = [self(2**i-1) for i in range(self._nvariables+1)] for i in range(1 << self._nvariables): sig_check() - if T[ hamming_weight(i) ] != bitset_in(self._truth_table, i): + if T[hamming_weight(i)] != bitset_in(self._truth_table, i): return False return True def nonlinearity(self): """ - Return the nonlinearity of the function. This is the distance - to the linear functions, or the number of output ones need to - change to obtain a linear function. + Return the nonlinearity of the function. + + This is the distance to the linear functions, or the number of + output ones need to change to obtain a linear function. EXAMPLES:: @@ -808,12 +813,12 @@ cdef class BooleanFunction(SageObject): cdef long w if self._nonlinearity is None: self._nonlinearity = \ - ( (1<> 1 + ((1<> 1 return self._nonlinearity def is_bent(self): """ - Return True if the function is bent. + Return ``True`` if the function is bent. EXAMPLES:: @@ -832,7 +837,7 @@ cdef class BooleanFunction(SageObject): correlation immune of order `m`. A Boolean function is said to be correlation immune of order - `m` , if the output of the function is statistically + `m`, if the output of the function is statistically independent of the combination of any m of its inputs. EXAMPLES:: @@ -849,7 +854,7 @@ cdef class BooleanFunction(SageObject): for i in range(len(W)): sig_check() if W[i]: - c = min( c , hamming_weight(i) ) + c = min(c, hamming_weight(i)) self._correlation_immunity = ZZ(c-1) return self._correlation_immunity @@ -891,7 +896,7 @@ cdef class BooleanFunction(SageObject): cdef long i if self._autocorrelation is None: - n = self._truth_table.size + n = self._truth_table.size temp = sig_malloc(sizeof(long)*n) W = self.walsh_hadamard_transform() @@ -952,7 +957,7 @@ cdef class BooleanFunction(SageObject): cdef long a if self._absolute_indicator is None: D = self.autocorrelation() - self._absolute_indicator = max([ abs(a) for a in D[1:] ]) + self._absolute_indicator = max([abs(a) for a in D[1:]]) return self._absolute_indicator absolut_indicator = deprecated_function_alias(28001, absolute_indicator) @@ -1315,9 +1320,9 @@ cdef class BooleanFunction(SageObject): EXAMPLES:: sage: from sage.crypto.boolean_function import BooleanFunction - sage: B=BooleanFunction([0,0,1,1]) - sage: B[0]=1 - sage: B[2]=(3**17 == 9) + sage: B = BooleanFunction([0,0,1,1]) + sage: B[0] = 1 + sage: B[2] = (3**17 == 9) sage: [b for b in B] [True, False, False, True] @@ -1338,7 +1343,7 @@ cdef class BooleanFunction(SageObject): EXAMPLES:: sage: from sage.crypto.boolean_function import BooleanFunction - sage: B=BooleanFunction([0,1,1,1]) + sage: B = BooleanFunction([0,1,1,1]) sage: [ int(B[i]) for i in range(len(B)) ] [0, 1, 1, 1] """ @@ -1377,6 +1382,7 @@ cdef class BooleanFunction(SageObject): """ return unpickle_BooleanFunction, (self.truth_table(format='hex'),) + def unpickle_BooleanFunction(bool_list): """ Specific function to unpickle Boolean functions. @@ -1390,6 +1396,7 @@ def unpickle_BooleanFunction(bool_list): """ return BooleanFunction(bool_list) + cdef class BooleanFunctionIterator: cdef long index, last cdef BooleanFunction f diff --git a/src/sage/crypto/sbox.pyx b/src/sage/crypto/sbox.pyx index 8f830240844..453ac488a88 100644 --- a/src/sage/crypto/sbox.pyx +++ b/src/sage/crypto/sbox.pyx @@ -435,7 +435,7 @@ cdef class SBox(SageObject): return self._S_list[ X] # Handle non-integer inputs: vectors, finite field elements to-integer-coercible elements - #cdef int i + # cdef int i if isinstance(X, Element): K = X.parent() if K.base_ring().characteristic() != 2: @@ -948,8 +948,6 @@ cdef class SBox(SageObject): cdef Py_ssize_t m = self.m cdef Py_ssize_t n = self.n - F = GF(2) - if X is None and Y is None: P = self.ring() X = P.gens()[:m] @@ -1056,7 +1054,7 @@ cdef class SBox(SageObject): cdef int i for i in range(2**m): x = k(vector(self.to_bits(i, m))) - l.append( (x, self(x)) ) + l.append((x, self(x))) P = PolynomialRing(k, 'x') return P.lagrange_polynomial(l)