diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index 83baa7a0f5e..e4d2138e699 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -2194,7 +2194,7 @@ def to_noncrossing_permutation(self) -> Permutation: pi[touches[i] - 1] = pi[touches[i + 1] - 1] pi[touches[-1] - 1] = a D, touch_sequence = pealing(D, return_touches=True) - return Permutations()(pi, check_input=False) + return Permutations()(pi, check=False) @combinatorial_map(name='to 321 avoiding permutation') def to_321_avoiding_permutation(self) -> Permutation: diff --git a/src/sage/combinat/permutation.py b/src/sage/combinat/permutation.py index e4c73bcfb9b..c69ecb7403d 100644 --- a/src/sage/combinat/permutation.py +++ b/src/sage/combinat/permutation.py @@ -262,6 +262,7 @@ from sage.libs.gap.libgap import libgap from sage.matrix.matrix_space import MatrixSpace from sage.misc.cachefunc import cached_method +from sage.misc.decorators import rename_keyword from sage.misc.prandom import sample from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ @@ -287,7 +288,7 @@ class Permutation(CombinatorialElement): - list of integers, viewed as one-line permutation notation. The construction checks that you give an acceptable entry. To avoid - the check, use the ``check_input`` option. + the check, use the ``check`` option. - string, expressing the permutation in cycle notation. @@ -300,7 +301,7 @@ class Permutation(CombinatorialElement): the permutation obtained from the pair using the inverse of the Robinson-Schensted algorithm. - - ``check_input`` (boolean) -- whether to check that input is correct. Slows + - ``check`` (boolean) -- whether to check that input is correct. Slows the function down, but ensures that nothing bad happens. This is set to ``True`` by default. @@ -309,7 +310,7 @@ class Permutation(CombinatorialElement): Since :trac:`13742` the input is checked for correctness : it is not accepted unless it actually is a permutation on `\{1, \ldots, n\}`. It means that some :meth:`Permutation` objects cannot be created anymore - without setting ``check_input = False``, as there is no certainty that + without setting ``check=False``, as there is no certainty that its functions can handle them, and this should be fixed in a much better way ASAP (the functions should be rewritten to handle those cases, and new tests be added). @@ -426,7 +427,8 @@ class Permutation(CombinatorialElement): [] """ @staticmethod - def __classcall_private__(cls, l, check_input = True): + @rename_keyword(deprecation=35233, check_input='check') + def __classcall_private__(cls, l, check=True): """ Return a permutation in the general permutations parent. @@ -481,9 +483,10 @@ def __classcall_private__(cls, l, check_input = True): raise ValueError("cannot convert l (= %s) to a Permutation"%l) # otherwise, it gets processed by CombinatorialElement's __init__. - return Permutations()(l, check_input=check_input) + return Permutations()(l, check=check) - def __init__(self, parent, l, check_input=True): + @rename_keyword(deprecation=35233, check_input='check') + def __init__(self, parent, l, check=True): """ Constructor. Checks that INPUT is not a mess, and calls :class:`CombinatorialElement`. It should not, because @@ -493,7 +496,7 @@ def __init__(self, parent, l, check_input=True): - ``l`` -- a list of ``int`` variables - - ``check_input`` (boolean) -- whether to check that input is + - ``check`` (boolean) -- whether to check that input is correct. Slows the function down, but ensures that nothing bad happens. @@ -520,7 +523,7 @@ def __init__(self, parent, l, check_input=True): """ l = list(l) - if check_input and len(l) > 0: + if check and len(l) > 0: # Make a copy to sort later lst = list(l) @@ -5759,7 +5762,7 @@ def __iter__(self) -> Iterator[Permutation]: [] """ for x in itertools.permutations(range(1,self.n+1), int(self._k)): - yield self.element_class(self, x) + yield self.element_class(self, x, check=False) def cardinality(self) -> Integer: """ @@ -6286,7 +6289,7 @@ def __iter__(self) -> Iterator: ['t', 'a', 'c']] """ for p in itertools.permutations(self._set, len(self._set)): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) def cardinality(self) -> Integer: """ @@ -6399,7 +6402,8 @@ def __iter__(self): mset_list = [lmset.index(x) for x in lmset] indices = libgap.Arrangements(mset_list, self._k).sage() for ktuple in indices: - yield self.element_class(self, [lmset[x] for x in ktuple]) + yield self.element_class(self, [lmset[x] for x in ktuple], + check=False) class Permutations_setk(Permutations_set): @@ -6471,7 +6475,7 @@ def __iter__(self): [[1, 2], [1, 4], [2, 1], [2, 4], [4, 1], [4, 2]] """ for perm in itertools.permutations(self._set, int(self._k)): - yield self.element_class(self, perm) + yield self.element_class(self, perm, check=False) def random_element(self): """ @@ -6667,7 +6671,7 @@ def __iter__(self): n = 0 while True: for p in itertools.permutations(range(1, n + 1)): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) n += 1 def graded_component(self, n): @@ -6713,7 +6717,8 @@ def __init__(self, n, category=None): category = FiniteEnumeratedSets() Permutations.__init__(self, category=category) - def _element_constructor_(self, x, check_input=True): + @rename_keyword(deprecation=35233, check_input='check') + def _element_constructor_(self, x, check=True): """ Construct an element of ``self`` from ``x``. @@ -6742,7 +6747,7 @@ def _element_constructor_(self, x, check_input=True): """ if len(x) < self.n: x = list(x) + list(range(len(x) + 1, self.n + 1)) - return self.element_class(self, x, check_input=check_input) + return self.element_class(self, x, check=check) def __contains__(self, x): """ @@ -6806,7 +6811,7 @@ def __iter__(self): [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] """ for p in itertools.permutations(range(1, self.n + 1)): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) def _coerce_map_from_(self, G): """ @@ -6914,7 +6919,7 @@ def identity(self): sage: Permutations(0).identity() [] """ - return self.element_class(self, range(1,self.n+1)) + return self.element_class(self, range(1,self.n+1), check=False) one = identity @@ -6972,7 +6977,8 @@ def random_element(self): sage: s in Permutations(4) True """ - return self.element_class(self, sample(range(1,self.n+1), self.n)) + return self.element_class(self, sample(range(1, self.n+1), self.n), + check=False) def cardinality(self): """ @@ -7062,7 +7068,7 @@ def element_in_conjugacy_classes(self, nu): i += nui for i in range(nu.size(), self.n): l.append(i+1) - return self.element_class(self, l) + return self.element_class(self, l, check=False) def conjugacy_classes_representatives(self): r""" @@ -7226,7 +7232,7 @@ def simple_reflection(self, i): g = list(range(1, self.n+1)) g[i-1] = i+1 g[i] = i - return self.element_class(self, g) + return self.element_class(self, g, check=False) class Element(Permutation): def has_left_descent(self, i, mult=None): @@ -7630,7 +7636,7 @@ def from_cycles(n, cycles, parent=None): for i in range(n): if p[i] is None: p[i] = ZZ(i + 1) - return parent(p, check_input=False) + return parent(p, check=False) def from_lehmer_code(lehmer, parent=None): @@ -8197,7 +8203,7 @@ def __iter__(self): pos += 1 for le in dag.topological_sort_generator(): - yield self.element_class(self, le) + yield self.element_class(self, le, check=False) class StandardPermutations_recoilsfatter(Permutations): @@ -8269,7 +8275,7 @@ def __iter__(self): dag.add_edge(pos+1, pos) for le in dag.topological_sort_generator(): - yield self.element_class(self, le) + yield self.element_class(self, le, check=False) class StandardPermutations_recoils(Permutations): @@ -8341,7 +8347,7 @@ def __iter__(self): dag.add_edge(pos+1, pos) for le in dag.topological_sort_generator(): - yield self.element_class(self, le) + yield self.element_class(self, le, check=False) def from_major_code(mc, final_descent=False): @@ -8404,7 +8410,7 @@ def from_major_code(mc, final_descent=False): #Lemma 2.2 in Skandera #Get the descents of w and place them in reverse order - d = Permutation(w, check_input=False).descents(final_descent=final_descent) + d = Permutation(w, check=False).descents(final_descent=final_descent) d.reverse() #a is the list of all positions which are not descents @@ -8416,7 +8422,7 @@ def from_major_code(mc, final_descent=False): indices = d + a w.insert(indices[l], i) - return Permutation(w, check_input = False) + return Permutation(w, check=False) ################ # Bruhat Order # @@ -8922,11 +8928,11 @@ def __iter__(self, distinct=False): """ if len(self.partition) == 1: for i in CyclicPermutations(self.partition[0]).iterator(distinct=distinct): - yield self.element_class(self, [i]) + yield self.element_class(self, [i], check=False) else: for right in CyclicPermutationsOfPartition(self.partition[1:]).iterator(distinct=distinct): for perm in CyclicPermutations(self.partition[0]).iterator(distinct=distinct): - yield self.element_class(self, [perm] + list(right)) + yield self.element_class(self, [perm] + list(right), check=False) iterator = __iter__ @@ -9038,7 +9044,7 @@ def __iter__(self): n = 0 while True: for x in itertools.permutations(range(1, n + 1)): - x = self.element_class(self, x) + x = self.element_class(self, x, check=False) if all(x.avoids(p) for p in self._a): yield x n += 1 @@ -9143,7 +9149,7 @@ def __iter__(self): """ if self.n > 0: return iter(PatternAvoider(self, self._a)) - return iter([self.element_class(self, [])]) + return iter([self.element_class(self, [], check=False)]) def cardinality(self): """ @@ -9176,7 +9182,7 @@ def __iter__(self): sage: Permutations(3, avoiding=[1,2]).list() [[3, 2, 1]] """ - yield self.element_class(self, range(self.n, 0, -1)) + yield self.element_class(self, range(self.n, 0, -1), check=False) def cardinality(self): """ @@ -9208,7 +9214,7 @@ def __iter__(self): sage: Permutations(3, avoiding=[2,1]).list() [[1, 2, 3]] """ - yield self.element_class(self, range(1, self.n+1)) + yield self.element_class(self, range(1, self.n+1), check=False) def cardinality(self): """ @@ -9271,28 +9277,33 @@ def __iter__(self): elif self.n < 3: for p in itertools.permutations(range(1, self.n + 1)): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) return elif self.n == 3: for p in itertools.permutations(range(1, self.n + 1)): if p != (1, 3, 2): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) return #Yield all the 132 avoiding permutations to the right. for right in StandardPermutations_avoiding_132(self.n - 1): - yield self.element_class(self, [self.n] + list(right)) + yield self.element_class(self, [self.n] + list(right), + check=False) #yi for i in range(1, self.n-1): for left in StandardPermutations_avoiding_132(i): for right in StandardPermutations_avoiding_132(self.n-i-1): - yield self.element_class(self, [x+(self.n-i-1) for x in left] + [self.n] + list(right) ) + yield self.element_class(self, + [x + (self.n-i-1) for x in left] + + [self.n] + list(right), + check=False) #Yield all the 132 avoiding permutations to the left for left in StandardPermutations_avoiding_132(self.n - 1): - yield self.element_class(self, list(left) + [self.n]) + yield self.element_class(self, list(left) + [self.n], + check=False) class StandardPermutations_avoiding_123(StandardPermutations_avoiding_generic): @@ -9332,13 +9343,13 @@ def __iter__(self): elif self.n < 3: for p in itertools.permutations(range(1, self.n + 1)): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) return elif self.n == 3: for p in itertools.permutations(range(1, self.n + 1)): if p != (1, 2, 3): - yield self.element_class(self, p) + yield self.element_class(self, p, check=False) return for p in StandardPermutations_avoiding_132(self.n): @@ -9364,7 +9375,7 @@ def __iter__(self): new_p.append( non_minima[b] ) b += 1 - yield self.element_class(self, new_p) + yield self.element_class(self, new_p, check=False) class StandardPermutations_avoiding_321(StandardPermutations_avoiding_generic): @@ -9396,7 +9407,7 @@ def __iter__(self): [[2, 3, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_123(self.n): - yield self.element_class(self, p.reverse()) + yield self.element_class(self, p.reverse(), check=False) class StandardPermutations_avoiding_231(StandardPermutations_avoiding_generic): @@ -9428,7 +9439,7 @@ def __iter__(self): [[3, 2, 1], [3, 1, 2], [1, 3, 2], [2, 1, 3], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): - yield self.element_class(self, p.reverse()) + yield self.element_class(self, p.reverse(), check=False) class StandardPermutations_avoiding_312(StandardPermutations_avoiding_generic): @@ -9460,7 +9471,7 @@ def __iter__(self): [[3, 2, 1], [2, 3, 1], [2, 1, 3], [1, 3, 2], [1, 2, 3]] """ for p in StandardPermutations_avoiding_132(self.n): - yield self.element_class(self, p.complement()) + yield self.element_class(self, p.complement(), check=False) class StandardPermutations_avoiding_213(StandardPermutations_avoiding_generic): @@ -9530,8 +9541,10 @@ def _rec(self, obj, state): yld = True for pos in reversed(range(len(obj)+1)): - new_obj = self._parent.element_class(self._parent, obj[:pos] + [i] + obj[pos:]) - if all( not new_obj.has_pattern(p) for p in self._patterns): + new_obj = self._parent.element_class(self._parent, + obj[:pos] + [i] + obj[pos:], + check=False) + if all(not new_obj.has_pattern(p) for p in self._patterns): yield new_obj, new_state, yld diff --git a/src/sage/libs/gap/element.pyx b/src/sage/libs/gap/element.pyx index 90b729037a4..aac3bbe8590 100644 --- a/src/sage/libs/gap/element.pyx +++ b/src/sage/libs/gap/element.pyx @@ -3089,7 +3089,7 @@ cdef class GapElement_Permutation(GapElement): lst = libgap.ListPerm(self) if parent is None: - return Permutation(lst.sage(), check_input=False) + return Permutation(lst.sage(), check=False) else: return parent.one()._generate_new_GAP(lst)