diff --git a/src/sage/combinat/combinat_cython.pyx b/src/sage/combinat/combinat_cython.pyx index c0905491ac2..95ce7a6af96 100644 --- a/src/sage/combinat/combinat_cython.pyx +++ b/src/sage/combinat/combinat_cython.pyx @@ -134,6 +134,7 @@ cdef mpz_stirling_s2(mpz_t s, unsigned long n, unsigned long k): mpz_clear(t) mpz_clear(u) + def _stirling_number2(n, k): """ Python wrapper of mpz_stirling_s2. @@ -148,8 +149,9 @@ def _stirling_number2(n, k): mpz_stirling_s2(s.value, n, k) return s + ##################################################################### -## Lyndon word iterator +# Lyndon word iterator def lyndon_word_iterator(Py_ssize_t n, Py_ssize_t k): r""" @@ -204,7 +206,8 @@ def lyndon_word_iterator(Py_ssize_t n, Py_ssize_t k): while a[i] == n - 1: i -= 1 -## Perfect matchings iterator + +# Perfect matchings iterator def perfect_matchings_iterator(Py_ssize_t n): r""" @@ -276,6 +279,7 @@ def perfect_matchings_iterator(Py_ssize_t n): sig_free(e) sig_free(f) + cdef list convert(Py_ssize_t* f, Py_ssize_t n): """ Convert a list ``f`` representing a fixed-point free involution @@ -288,8 +292,9 @@ cdef list convert(Py_ssize_t* f, Py_ssize_t n): ret.append((i, f[i])) return ret + ##################################################################### -## Set partition composition +# Set partition composition def set_partition_composition(tuple sp1, tuple sp2): r""" diff --git a/src/sage/combinat/debruijn_sequence.pyx b/src/sage/combinat/debruijn_sequence.pyx index d98a3e66c87..02e224283c2 100644 --- a/src/sage/combinat/debruijn_sequence.pyx +++ b/src/sage/combinat/debruijn_sequence.pyx @@ -57,15 +57,16 @@ AUTHOR: """ -#******************************************************************************* +# ****************************************************************************** # Copyright (C) 2011 Eviatar Bach # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#******************************************************************************* +# https://www.gnu.org/licenses/ +# ****************************************************************************** from sage.data_structures.bitset_base cimport * + def debruijn_sequence(int k, int n): """ The generating function for De Bruijn sequences. This avoids the object @@ -93,6 +94,7 @@ def debruijn_sequence(int k, int n): gen(1, 1, k, n) return sequence + cdef gen(int t, int p, k, n): """ The internal generation function. This should not be accessed by the @@ -183,6 +185,7 @@ def is_debruijn_sequence(seq, k, n): return answer + from sage.categories.finite_sets import FiniteSets from sage.structure.unique_representation import UniqueRepresentation from sage.structure.parent import Parent @@ -190,6 +193,7 @@ from sage.structure.parent import Parent from sage.rings.integer cimport Integer from sage.rings.integer_ring import ZZ + class DeBruijnSequences(UniqueRepresentation, Parent): """ Represents the De Bruijn sequences of given parameters `k` and `n`. @@ -256,35 +260,32 @@ class DeBruijnSequences(UniqueRepresentation, Parent): """ Constructor. - Checks the consistency of the given arguments. + This checks the consistency of the given arguments. TESTS: - Setting ``n`` orr ``k`` to anything under 1 will return a ValueError: - - :: + Setting ``n`` or ``k`` to anything under 1 will return + a :class:`ValueError`:: sage: DeBruijnSequences(3, 0).an_element() Traceback (most recent call last): ... - ValueError: k and n cannot be under 1. + ValueError: k and n cannot be under 1 Setting ``n`` or ``k`` to any type except an integer will return a - TypeError: - - :: + :class:`TypeError`:: sage: DeBruijnSequences(2.5, 3).an_element() Traceback (most recent call last): ... - TypeError: k and n must be integers. + TypeError: k and n must be integers """ Parent.__init__(self, category=FiniteSets()) if n < 1 or k < 1: - raise ValueError('k and n cannot be under 1.') + raise ValueError('k and n cannot be under 1') if (not isinstance(n, (Integer, int)) or - not isinstance(k, (Integer,int))): - raise TypeError('k and n must be integers.') + not isinstance(k, (Integer, int))): + raise TypeError('k and n must be integers') self.k = k self.n = n diff --git a/src/sage/combinat/degree_sequences.pyx b/src/sage/combinat/degree_sequences.pyx index 0ccc2377f2c..63d41b9e5d4 100644 --- a/src/sage/combinat/degree_sequences.pyx +++ b/src/sage/combinat/degree_sequences.pyx @@ -57,9 +57,9 @@ An integer sequence need not necessarily be a degree sequence. Indeed, in a degree sequence of length `n` no integer can be larger than `n-1` -- the degree of a vertex is at most `n-1` -- and the sum of them is at most `n(n-1)`. -Degree sequences are completely characterized by a result from Erdos and Gallai: +Degree sequences are completely characterized by a result from Erdős and Gallai: -**Erdos and Gallai:** *The sequence of integers* `d_1 \geq \cdots \geq d_n` +**Erdős and Gallai:** *The sequence of integers* `d_1 \geq \cdots \geq d_n` *is a degree sequence if and only if* `\sum_i d_i` is even and `\forall i` .. MATH:: @@ -281,6 +281,7 @@ from cysignals.signals cimport sig_on, sig_off cdef unsigned char * seq cdef list sequences + class DegreeSequences: def __init__(self, n): @@ -307,16 +308,16 @@ class DegreeSequences: sage: DegreeSequences(-1) Traceback (most recent call last): ... - ValueError: The input parameter must be >= 0. + ValueError: the input parameter must be >= 0 """ if n < 0: - raise ValueError("The input parameter must be >= 0.") + raise ValueError("the input parameter must be >= 0") self._n = n def __contains__(self, seq): """ - Checks whether a given integer sequence is the degree sequence - of a graph on `n` elements + Check whether a given integer sequence is the degree sequence + of a graph on `n` elements. EXAMPLES:: @@ -342,7 +343,7 @@ class DegreeSequences: [[0]] """ cdef int n = self._n - if len(seq)!=n: + if len(seq) != n: return False # Is the sum even ? @@ -352,13 +353,13 @@ class DegreeSequences: # Partial represents the left side of Erdos and Gallai's inequality, # i.e. the sum of the i first integers. cdef int partial = 0 - cdef int i,d,dd, right + cdef int i, d, dd, right # Temporary variable to ensure that the sequence is indeed # non-increasing - cdef int prev = n-1 + cdef int prev = n - 1 - for i,d in enumerate(seq): + for i, d in enumerate(seq): # Non-increasing ? if d > prev: @@ -370,9 +371,9 @@ class DegreeSequences: partial += d # Evaluating the right hand side - right = i*(i+1) - for dd in seq[i+1:]: - right += min(dd,i+1) + right = i * (i + 1) + for dd in seq[i + 1:]: + right += min(dd, i + 1) # Comparing the two if partial > right: @@ -404,7 +405,7 @@ class DegreeSequences: sage: all(seq in DS for seq in DS) True """ - return iter( init(self._n) ) + yield from init(self._n) def __dealloc__(): """ @@ -412,6 +413,7 @@ class DegreeSequences: """ sig_free(seq) + cdef init(int n): """ Initializes the memory and starts the enumeration algorithm. @@ -432,7 +434,7 @@ cdef init(int n): N = n sequences = [] - enum(1,0) + enum(1, 0) sig_free(seq) return sequences @@ -467,7 +469,7 @@ cdef void enum(int k, int M): - ``k`` -- depth of the partial degree sequence - ``M`` -- value of a maximum element in the partial degree sequence """ - cdef int i,j + cdef int i, j global seq cdef int taken = 0 cdef int current_box @@ -491,21 +493,21 @@ cdef void enum(int k, int M): if M == 0: seq[0] += 1 - enum(k+1, M) + enum(k + 1, M) seq[0] -= 1 # We need not automatically increase the degree at each step. In this case, # we have no other choice but to link the new vertex of degree M to vertices # of degree M-1, which will become vertices of degree M too. - elif seq[M-1] >= M: + elif seq[M - 1] >= M: - seq[M] += M+1 - seq[M-1] -= M + seq[M] += M + 1 + seq[M - 1] -= M - enum(k+1, M) + enum(k + 1, M) - seq[M] -= M+1 - seq[M-1] += M + seq[M] -= M + 1 + seq[M - 1] += M ############################################### # Creating vertices of Vertices of degree > M # @@ -542,13 +544,13 @@ cdef void enum(int k, int M): seq[current_box] -= i seq[current_box+1] += i - for max(0,((M+1)-taken-i)) <= j <= n_previous_box: + for max(0, ((M+1)-taken-i)) <= j <= n_previous_box: seq[current_box-1] -= j seq[current_box] += j new_vertex = taken + i + j seq[new_vertex] += 1 - enum(k+1,new_vertex) + enum(k+1, new_vertex) seq[new_vertex] -= 1 seq[current_box-1] += j @@ -566,7 +568,7 @@ cdef void enum(int k, int M): # Now current_box = 0. All the vertices of nonzero degree are taken, we just # want to know how many vertices of degree 0 will be neighbors of the new # vertex. - for max(0,((M+1)-taken)) <= i <= seq[0]: + for max(0, ((M+1)-taken)) <= i <= seq[0]: seq[1] += i seq[0] -= i diff --git a/src/sage/combinat/designs/designs_pyx.pyx b/src/sage/combinat/designs/designs_pyx.pyx index 4b6638634f6..59b73431a18 100644 --- a/src/sage/combinat/designs/designs_pyx.pyx +++ b/src/sage/combinat/designs/designs_pyx.pyx @@ -15,6 +15,7 @@ from cysignals.memory cimport sig_malloc, sig_calloc, sig_realloc, sig_free from sage.misc.unknown import Unknown + def is_covering_array(array, strength=None, levels=None, verbose=False, parameters=False): r""" Check if the input is a covering array with given strength. @@ -349,6 +350,7 @@ def is_orthogonal_array(OA, int k, int n, int t=2, verbose=False, terminology="O bitset_free(seen) return True + def is_group_divisible_design(groups,blocks,v,G=None,K=None,lambd=1,verbose=False): r""" Checks that input is a Group Divisible Design on `\{0,...,v-1\}` @@ -588,6 +590,7 @@ def is_pairwise_balanced_design(blocks,v,K=None,lambd=1,verbose=False): lambd=lambd, verbose=verbose) + def is_projective_plane(blocks, verbose=False): r""" Test whether the blocks form a projective plane on `\{0,...,v-1\}` @@ -661,6 +664,7 @@ def is_projective_plane(blocks, verbose=False): lambd=1, verbose=verbose) + def is_difference_matrix(M,G,k,lmbda=1,verbose=False): r""" Test if `M` is a `(G,k,\lambda)`-difference matrix. @@ -725,6 +729,7 @@ def is_difference_matrix(M,G,k,lmbda=1,verbose=False): """ return is_quasi_difference_matrix(M,G,k,lmbda=lmbda,mu=lmbda,u=0,verbose=verbose) + def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False): r""" Test if the matrix is a `(G,k;\lambda,\mu;u)`-quasi-difference matrix @@ -938,6 +943,7 @@ def is_quasi_difference_matrix(M,G,int k,int lmbda,int mu,int u,verbose=False): sig_free(M_c) return True + # Cached information for OA constructions (see .pxd file for more info) _OA_cache = sig_malloc(2*sizeof(cache_entry)) diff --git a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx index 26da661f3cd..72baf1a5d28 100644 --- a/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx +++ b/src/sage/combinat/designs/gen_quadrangles_with_spread.pyx @@ -123,6 +123,7 @@ def generalised_quadrangle_with_spread(const int s, const int t, raise RuntimeError( f"Sage can't build a GQ of order ({s}, {t}) with a spread") + def is_GQ_with_spread(GQ, S, s=None, t=None): r""" Check if GQ is a generalised quadrangle of order `(s,t)` and @@ -233,6 +234,7 @@ def dual_GQ_ovoid(GQ, O): D = IncidenceStructure(newBlocks) return (D, S) + def generalised_quadrangle_hermitian_with_ovoid(const int q): r""" Construct the generalised quadrangle `H(3,q^2)` with an ovoid. diff --git a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx index 066eecb9197..196a0d4a194 100644 --- a/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx +++ b/src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx @@ -51,6 +51,7 @@ from .orthogonal_arrays import orthogonal_array from sage.rings.integer cimport smallInteger from sage.arith.misc import prime_powers + @cached_function def find_recursive_construction(k, n): r""" @@ -114,6 +115,7 @@ def find_recursive_construction(k, n): return res return False + cpdef find_product_decomposition(int k,int n): r""" Find `n_1n_2=n` to obtain an `OA(k,n)` by the product construction. @@ -880,6 +882,7 @@ def int_as_sum(int value, list S, int k_max): return None + cpdef find_brouwer_van_rees_with_one_truncated_column(int k,int n): r""" Find `rm+x_1+...+x_c=n` such that the Brouwer-van Rees constructions yields a `OA(k,n)`. diff --git a/src/sage/combinat/expnums.pyx b/src/sage/combinat/expnums.pyx index bff30b763d7..216850b43f1 100644 --- a/src/sage/combinat/expnums.pyx +++ b/src/sage/combinat/expnums.pyx @@ -117,6 +117,7 @@ def expnums(int n, int aa): # return bell[1]; # end); + def expnums2(n, aa): r""" A vanilla python (but compiled via Cython) implementation of diff --git a/src/sage/combinat/fast_vector_partitions.pyx b/src/sage/combinat/fast_vector_partitions.pyx index 2a1e093104b..fe937b75ee7 100644 --- a/src/sage/combinat/fast_vector_partitions.pyx +++ b/src/sage/combinat/fast_vector_partitions.pyx @@ -126,19 +126,20 @@ def recursive_within_from_to(list m, list s, list e, bint useS, bint useE): if len(m) == 1: # We use this style of Cython code for now in order to get this to convert # to an optimized pure C for loop. See Cython github issue #532. - #for x in range(start, end - 1, -1): + # for x in range(start, end - 1, -1): for x from start >= x >= end by 1: yield [x] # we know the answer for singletons else: # We use this style of Cython code for now in order to get this to convert # to an optimized pure C for loop. See Cython github issue #532. - #for x in range(start, end - 1, -1): + # for x in range(start, end - 1, -1): for x from start >= x >= end by 1: useSS = useS and x == s[0] useEE = useE and x == e[0] for o in recursive_within_from_to(m[1:], s[1:], e[1:], useSS, useEE): yield [x] + o + def within_from_to(list m, list s, list e): r""" Iterate over a lexicographically ordered list of lists ``v`` satisfying @@ -229,6 +230,7 @@ def within_from_to(list m, list s, list e): return yield from recursive_within_from_to(m, ss, e, True, True) + cdef inline list vector_sub(list a, list b): """ Return ``a - b`` considered as vectors. @@ -241,6 +243,7 @@ cdef inline list vector_sub(list a, list b): ret.append(( a[i]) - ( b[i])) return ret + def recursive_vector_partitions(list v, list vL): r""" Iterate over a lexicographically ordered list of lists, each list diff --git a/src/sage/combinat/matrices/dancing_links.pyx b/src/sage/combinat/matrices/dancing_links.pyx index df6cb7915f8..f0ecfeacd17 100644 --- a/src/sage/combinat/matrices/dancing_links.pyx +++ b/src/sage/combinat/matrices/dancing_links.pyx @@ -67,7 +67,7 @@ There is also a method ``reinitialize`` to reinitialize the algorithm:: sage: x.get_solution() [0, 1] """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2008 Carlo Hamalainen # Copyright (C) 2015-2018 Sébastien Labbé # @@ -75,8 +75,8 @@ There is also a method ``reinitialize`` to reinitialize the algorithm:: # 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 cpython.object cimport PyObject_RichCompare from libcpp.vector cimport vector diff --git a/src/sage/combinat/partitions.pyx b/src/sage/combinat/partitions.pyx index c26ccdb3ddb..c461797067c 100644 --- a/src/sage/combinat/partitions.pyx +++ b/src/sage/combinat/partitions.pyx @@ -8,7 +8,7 @@ AUTHOR: that does all the actual heavy lifting. """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2007 William Stein # Copyright (C) 2007 Jonathan Bober # @@ -16,8 +16,9 @@ AUTHOR: # 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/ +# **************************************************************************** + def ZS1_iterator(int n): """ @@ -82,9 +83,10 @@ def ZS1_iterator(int n): if t > 1: h += 1 x[h] = t - #yield [x[i] for i in range(m+1)] + # yield [x[i] for i in range(m+1)] yield x[:m+1] - #free(x) + # free(x) + def ZS1_iterator_nk(int n, int k): """ @@ -176,4 +178,4 @@ def ZS1_iterator_nk(int n, int k): h += 1 x[m] = t yield x[:m+1] - #free(x) + # free(x) diff --git a/src/sage/combinat/posets/hasse_cython_flint.pyx b/src/sage/combinat/posets/hasse_cython_flint.pyx index fcbe29faaf6..5d2c5b967ae 100644 --- a/src/sage/combinat/posets/hasse_cython_flint.pyx +++ b/src/sage/combinat/posets/hasse_cython_flint.pyx @@ -61,7 +61,7 @@ cpdef Matrix_integer_dense moebius_matrix_fast(list positions): for i in range(n): pos_lens[i] = len(positions[i]) pos_array[i] = sig_malloc(pos_lens[i]*sizeof(int)) - for jind,j in enumerate(positions[i]): + for jind, j in enumerate(positions[i]): pos_array[i][jind] = j for i in range(n - 1, -1, -1): @@ -120,7 +120,7 @@ cpdef Matrix_integer_dense coxeter_matrix_fast(list positions): for i in range(n): pos_lens[i] = len(positions[i]) pos_array[i] = sig_malloc(pos_lens[i]*sizeof(int)) - for jind,j in enumerate(positions[i]): + for jind, j in enumerate(positions[i]): pos_array[i][jind] = j for i in range(n - 1, -1, -1): diff --git a/src/sage/combinat/posets/linear_extension_iterator.pyx b/src/sage/combinat/posets/linear_extension_iterator.pyx index 5eb101b32e2..69a84cb46f0 100644 --- a/src/sage/combinat/posets/linear_extension_iterator.pyx +++ b/src/sage/combinat/posets/linear_extension_iterator.pyx @@ -5,6 +5,8 @@ Fast linear extension iterator cimport cython from copy import copy + + def _linear_extension_prepare(D): r""" The preprocessing routine in Figure 7 of "Generating Linear @@ -27,9 +29,8 @@ def _linear_extension_prepare(D): sage: D = Poset({ 0:[1,2], 1:[3], 2:[3,4] })._hasse_diagram sage: _linear_extension_prepare(D) ([0, 1, 2, 3, 4], [1, 3], [2, 4]) - """ - dag_copy = copy(D) # this copy is destroyed during preparation + dag_copy = copy(D) # this copy is destroyed during preparation le = [] a = [] b = [] @@ -57,6 +58,7 @@ def _linear_extension_prepare(D): return (le, a, b) + @cython.wraparound(False) @cython.boundscheck(False) cdef void _linear_extension_switch(list _le, list _a, list _b, list _is_plus, Py_ssize_t i): @@ -81,6 +83,7 @@ cdef void _linear_extension_switch(list _le, list _a, list _b, list _is_plus, Py _b[i] = a _a[i] = b + @cython.wraparound(False) @cython.boundscheck(False) cdef bint _linear_extension_right_a(_D, list _le, list _a, list _b, Py_ssize_t i): @@ -109,6 +112,7 @@ cdef bint _linear_extension_right_a(_D, list _le, list _a, list _b, Py_ssize_t i y = _le[yindex] return y != _b[i] and _D.are_incomparable(x, y) + @cython.wraparound(False) @cython.boundscheck(False) cdef bint _linear_extension_right_b(_D, list _le, list _a, list _b, Py_ssize_t i): @@ -136,6 +140,7 @@ cdef bint _linear_extension_right_b(_D, list _le, list _a, list _b, Py_ssize_t i y = _le[yindex] return _D.are_incomparable(x, y) + @cython.wraparound(False) @cython.boundscheck(False) def _linear_extension_gen(_D, list _le, list _a, list _b, list _is_plus, Py_ssize_t i): @@ -276,7 +281,7 @@ def linear_extension_iterator(D): """ _le, _a, _b = _linear_extension_prepare(D) _max_pair = len(_a) - 1 - _is_plus = [True] # this is modified by _linear_extension_switch + _is_plus = [True] # this is modified by _linear_extension_switch yield _le[:] for e in _linear_extension_gen(D, _le, _a, _b, _is_plus, _max_pair): diff --git a/src/sage/combinat/root_system/braid_orbit.pyx b/src/sage/combinat/root_system/braid_orbit.pyx index d95bc388f83..5c605de8253 100644 --- a/src/sage/combinat/root_system/braid_orbit.pyx +++ b/src/sage/combinat/root_system/braid_orbit.pyx @@ -1,4 +1,4 @@ -#cython: wraparound=False, boundscheck=False +# cython: wraparound=False, boundscheck=False """ Braid Orbit @@ -48,11 +48,11 @@ cpdef set BraidOrbit(list word, list rels): cdef list rel l = len(word) - cdef set words = set( [tuple(word)] ) - cdef list test_words = [ tuple(word) ] + cdef set words = {tuple(word)} + cdef list test_words = [tuple(word)] - rels = rels + [ [b,a] for a,b in rels ] - rels = [ [tuple(a), tuple(b), len(a)] for a,b in rels ] + rels = rels + [[b, a] for a, b in rels] + rels = [[tuple(a), tuple(b), len(a)] for a, b in rels] loop_ind = 0 list_len = 1 @@ -101,8 +101,8 @@ cpdef bint is_fully_commutative(list word, list rels): cdef list rel l = len(word) - cdef set words = set( [tuple(word)] ) - cdef list test_words = [ tuple(word) ] + cdef set words = {tuple(word)} + cdef list test_words = [tuple(word)] rels = rels + [[b, a] for a, b in rels] rels = [[tuple(a), tuple(b), len(a)] for a, b in rels] diff --git a/src/sage/combinat/root_system/reflection_group_c.pyx b/src/sage/combinat/root_system/reflection_group_c.pyx index 247e9a62c02..6ad4f30212e 100644 --- a/src/sage/combinat/root_system/reflection_group_c.pyx +++ b/src/sage/combinat/root_system/reflection_group_c.pyx @@ -1,4 +1,4 @@ -#cython: wraparound=False, boundscheck=False +# cython: wraparound=False, boundscheck=False r""" This contains a few time-critical auxiliary cython functions for finite complex or real reflection groups. @@ -51,7 +51,7 @@ cdef class Iterator(): for i in range(n): si = S[i] noncom_i = [] - for j in range(i+1,n): + for j in range(i+1, n): sj = S[j] if si._mul_(sj) == sj._mul_(si): pass @@ -87,7 +87,7 @@ cdef class Iterator(): raise ValueError('the algorithm (="%s") must be either "depth", "breadth", or "parabolic"') self.algorithm = algorithm -# self.noncom = self.noncom_letters() + # self.noncom = self.noncom_letters() cdef list succ(self, PermutationGroupElement u, int first): cdef PermutationGroupElement si @@ -95,18 +95,18 @@ cdef class Iterator(): cdef list successors = [] cdef tuple S = self.S cdef int N = self.N -# cdef list nc = self.noncom[first] + # cdef list nc = self.noncom[first] for i in range(first): si = (S[i]) if self.test(u, si, i): - successors.append((_new_mul_(si,u), i)) - for i in range(first+1,self.n): -# for i in nc: + successors.append((_new_mul_(si, u), i)) + for i in range(first+1, self.n): + # for i in nc: if u.perm[i] < N: si = (S[i]) if self.test(u, si, i): - successors.append((_new_mul_(si,u), i)) + successors.append((_new_mul_(si, u), i)) return successors cdef list succ_words(self, PermutationGroupElement u, list word, int first): @@ -120,7 +120,7 @@ cdef class Iterator(): for i in range(first): si = (S[i]) if self.test(u, si, i): - u1 = (_new_mul_(si,u)) + u1 = (_new_mul_(si, u)) # try to use word+[i] and the reversed word_new = [i] + word u1._reduced_word = word_new @@ -129,7 +129,7 @@ cdef class Iterator(): if u.perm[i] < N: si = (S[i]) if self.test(u, si, i): - u1 = (_new_mul_(si,u)) + u1 = (_new_mul_(si, u)) word_new = [i] + word u1._reduced_word = word_new successors.append((u1, word_new, i)) @@ -375,6 +375,7 @@ cdef class Iterator(): for v in coset_reps: yield _new_mul_(w, v) + def iterator_tracking_words(W): r""" Return an iterator through the elements of ``self`` together @@ -417,7 +418,7 @@ def iterator_tracking_words(W): cdef list index_list = list(range(len(S))) cdef list level_set_cur = [(W.one(), [])] - cdef set level_set_old = set([ W.one() ]) + cdef set level_set_old = {W.one()} cdef list word cdef PermutationGroupElement x, y @@ -432,6 +433,7 @@ def iterator_tracking_words(W): level_set_new.append((y, word+[i])) level_set_cur = level_set_new + cdef inline bint has_left_descent(PermutationGroupElement w, int i, int N): return w.perm[i] >= N @@ -501,7 +503,7 @@ cpdef PermutationGroupElement reduce_in_coset(PermutationGroupElement w, tuple S w = _new_mul_(w, si) cdef list reduced_coset_representatives(W, list parabolic_big, list parabolic_small, - bint right): + bint right): cdef tuple S = tuple(W.simple_reflections()) cdef int N = W.number_of_reflections() cdef set totest = set([W.one()]) @@ -515,7 +517,7 @@ cdef list reduced_coset_representatives(W, list parabolic_big, list parabolic_sm S, parabolic_small, N, right) for i in parabolic_big]) res.update(totest) - totest = new.difference(res)#[ w for w in new if w not in res ] + totest = new.difference(res) # [w for w in new if w not in res] return list(res) cdef parabolic_recursive(PermutationGroupElement x, list v, f): @@ -558,6 +560,7 @@ def parabolic_iteration_application(W, f): parabolic_recursive(W.one(), coset_reps, f) + cpdef list reduced_word_c(W, PermutationGroupElement w): r""" Computes a reduced word for the element ``w`` in the diff --git a/src/sage/combinat/root_system/reflection_group_element.pyx b/src/sage/combinat/root_system/reflection_group_element.pyx index 8f5a61ff0a2..e8c05283167 100644 --- a/src/sage/combinat/root_system/reflection_group_element.pyx +++ b/src/sage/combinat/root_system/reflection_group_element.pyx @@ -115,7 +115,7 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): gens = [W.simple_reflection(j) for j in W._index_set] return _gap_factorization(self, gens) - #@cached_in_parent_method + # @cached_in_parent_method def reduced_word_in_reflections(self): r""" Return a word in the reflections to obtain ``self``. @@ -180,7 +180,7 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): """ return ZZ(len(self.reduced_word())) - #@cached_in_parent_method + # @cached_in_parent_method def to_matrix(self, on_space="primal"): r""" Return ``self`` as a matrix acting on the underlying vector @@ -481,7 +481,7 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): W = self._parent return PermutationGroupElement(self, W) - #@cached_in_parent_method + # @cached_in_parent_method def fix_space(self): r""" Return the fix space of ``self``. @@ -531,7 +531,7 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): I = identity_matrix(QQ, self._parent.rank()) return (self.to_matrix() - I).right_kernel() - #@cached_in_parent_method + # @cached_in_parent_method def reflection_eigenvalues(self, is_class_representative=False): r""" Return the reflection eigenvalues of ``self``. @@ -578,7 +578,7 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): """ return self._parent.reflection_eigenvalues(self, is_class_representative=is_class_representative) - #@cached_in_parent_method + # @cached_in_parent_method def galois_conjugates(self): r""" Return all Galois conjugates of ``self``. @@ -683,8 +683,8 @@ cdef class ComplexReflectionGroupElement(PermutationGroupElement): """ rk = self._parent.rank() M = self.to_matrix().list() - m = lcm([x.conductor() if hasattr(x,"conductor") else 1 for x in M]) - cdef list M_gals = [x.galois_conjugates(m) if hasattr(x,"galois_conjugates") else [x] for x in M] + m = lcm([x.conductor() if hasattr(x, "conductor") else 1 for x in M]) + cdef list M_gals = [x.galois_conjugates(m) if hasattr(x, "galois_conjugates") else [x] for x in M] cdef list conjugates = [] cdef int i for i in range(len(M_gals[0])): @@ -808,10 +808,10 @@ cdef class RealReflectionGroupElement(ComplexReflectionGroupElement): False """ if not isinstance(positive, bool): - raise TypeError("%s is not a boolean"%(bool)) + raise TypeError("%s is not a boolean" % (bool)) if i not in self._parent.index_set(): - raise ValueError("the given index %s is not in the index set"%i) + raise ValueError("the given index %s is not in the index set" % i) negative = not positive @@ -1049,9 +1049,8 @@ cdef class RealReflectionGroupElement(ComplexReflectionGroupElement): (1, 1) -> (0, -1) """ if self_on_left: - return self.action(vec,side="left") - else: - return self.action(vec,side="right") + return self.action(vec, side="left") + return self.action(vec, side="right") cpdef action_on_root_indices(self, i, side="right"): """ @@ -1177,11 +1176,12 @@ def _gap_factorization(w, gens): """ from sage.interfaces.gap3 import gap3 - gap3.execute('W := GroupWithGenerators(%s)'%str(gens)) + gap3.execute('W := GroupWithGenerators(%s)' % str(gens)) gap3.execute(_gap_factorization_code) - fac = gap3('MinimalWord(W,%s)'%str(w)).sage() + fac = gap3('MinimalWord(W,%s)' % str(w)).sage() return [i-1 for i in fac] + _gap_factorization_code = r""" # MinimalWord(G,w) # given a permutation group G find some expression of minimal length in the @@ -1232,6 +1232,7 @@ MinimalWord:=function(G,w) od; end;""" + def _gap_return(S, coerce_obj='self'): r""" Return the string ``S`` after a few modifications are done. @@ -1245,6 +1246,6 @@ def _gap_return(S, coerce_obj='self'): sage: _gap_return("[ (), (1,4)(2,3)(5,6), (1,6,2)(3,5,4) ]") # optional - gap3 "[self('()',check=False),self('(1,4)(2,3)(5,6)',check=False),self('(1,6,2)(3,5,4)',check=False)]" """ - S = S.replace(' ','').replace('\n','') - S = S.replace(',(','\',check=False),%s(\'('%coerce_obj).replace('[','[%s(\''%coerce_obj).replace(']','\',check=False)]') + S = S.replace(' ', '').replace('\n', '') + S = S.replace(',(', '\',check=False),%s(\'(' % coerce_obj).replace('[', '[%s(\'' % coerce_obj).replace(']', '\',check=False)]') return S diff --git a/src/sage/combinat/set_partition_iterator.pyx b/src/sage/combinat/set_partition_iterator.pyx index fff6a71fefe..a0868e743cc 100644 --- a/src/sage/combinat/set_partition_iterator.pyx +++ b/src/sage/combinat/set_partition_iterator.pyx @@ -20,6 +20,7 @@ cdef list from_word(list w, list base_set): sp[b].append(x) return sp + @cython.wraparound(False) @cython.boundscheck(False) def set_partition_iterator(base_set): @@ -74,6 +75,7 @@ def set_partition_iterator(base_set): # H3: increase a_{n-1} a[last] += 1 + @cython.wraparound(False) @cython.boundscheck(False) def _set_partition_block_gen(Py_ssize_t n, Py_ssize_t k, list a): @@ -108,6 +110,7 @@ def _set_partition_block_gen(Py_ssize_t n, Py_ssize_t k, list a): yield P a[n-1] = n-1 + @cython.wraparound(False) @cython.boundscheck(False) def set_partition_iterator_blocks(base_set, Py_ssize_t k): diff --git a/src/sage/combinat/subword_complex_c.pyx b/src/sage/combinat/subword_complex_c.pyx index 66da5184356..3e60bcce303 100644 --- a/src/sage/combinat/subword_complex_c.pyx +++ b/src/sage/combinat/subword_complex_c.pyx @@ -57,7 +57,7 @@ cpdef int _flip_c(W, set positions, list extended_root_conf_indices, if j != i: t = R[min(r, r_minus)] for k in range(min(i, j) + 1, max(i, j) + 1): - extended_root_conf_indices[k] = t.action_on_root_indices(extended_root_conf_indices[k],side="left") + extended_root_conf_indices[k] = t.action_on_root_indices(extended_root_conf_indices[k], side="left") return j cpdef list _construct_facets_c(tuple Q, w, int n=-1, int pos=0, int l=-1): diff --git a/src/sage/combinat/words/word_char.pyx b/src/sage/combinat/words/word_char.pyx index 433aae3f4db..faa9049db2f 100644 --- a/src/sage/combinat/words/word_char.pyx +++ b/src/sage/combinat/words/word_char.pyx @@ -1,15 +1,15 @@ r""" Fast word datatype using an array of unsigned char """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2014 Vincent Delecroix <20100.delecroix@gmail.com> # # 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.memory cimport check_allocarray, sig_free from cysignals.signals cimport sig_on, sig_off @@ -98,7 +98,7 @@ cdef class WordDatatype_char(WordDatatype): if data: self._set_data(data) - @cython.boundscheck(False) # assume that indexing will not cause any IndexErrors + @cython.boundscheck(False) # assume that indexing will not cause any IndexErrors @cython.wraparound(False) # not check not correctly handle negative indices cdef _set_data(self, data): r""" @@ -196,7 +196,7 @@ cdef class WordDatatype_char(WordDatatype): [1, 3, 2] """ cdef bitset_t seen - bitset_init(seen, 256) # allocation + initialization to 0 + bitset_init(seen, 256) # allocation + initialization to 0 cdef size_t i cdef list res = [] @@ -217,7 +217,7 @@ cdef class WordDatatype_char(WordDatatype): cdef type t = type(self) cdef WordDatatype_char other = t.__new__(t) other._data = data - other._master = master # can be None + other._master = master # can be None other._is_slice = 0 if master is None else 1 other._length = length other._parent = self._parent @@ -367,9 +367,9 @@ cdef class WordDatatype_char(WordDatatype): if isinstance(key, slice): # here the key is a slice PySlice_GetIndicesEx(key, - self._length, - &start, &stop, &step, - &slicelength) + self._length, + &start, &stop, &step, + &slicelength) if slicelength == 0: return self._new_c(NULL, 0, None) if step == 1: diff --git a/src/sage/combinat/words/word_datatypes.pyx b/src/sage/combinat/words/word_datatypes.pyx index 57c8079aad6..a25f09d5368 100644 --- a/src/sage/combinat/words/word_datatypes.pyx +++ b/src/sage/combinat/words/word_datatypes.pyx @@ -1,7 +1,7 @@ r""" Datatypes for finite words """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2009 Franco Saliola # Vincent Delecroix <20100.delecroix@gmail.com> # @@ -9,8 +9,8 @@ Datatypes for finite words # 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 cpython.object cimport Py_EQ, Py_NE from itertools import islice @@ -20,10 +20,10 @@ cdef class WordDatatype(): r""" The generic WordDatatype class. - Any word datatype must contain two attributes (at least):: + Any word datatype must contain two attributes (at least): - - _parent - - _hash + - ``_parent`` + - ``_hash`` They are automatically defined here and it's not necessary (and forbidden) to define them anywhere else.