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 9783a367898..88f170fede7 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 @@ -286,7 +287,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. @@ -299,7 +300,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. @@ -308,7 +309,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). @@ -425,7 +426,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. @@ -480,9 +482,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 @@ -492,7 +495,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. @@ -519,7 +522,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) @@ -5738,7 +5741,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: """ @@ -6265,7 +6268,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: """ @@ -6378,7 +6381,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): @@ -6450,7 +6454,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): """ @@ -6646,7 +6650,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): @@ -6692,7 +6696,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``. @@ -6721,7 +6726,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): """ @@ -6785,7 +6790,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): """ @@ -6893,7 +6898,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 @@ -6951,7 +6956,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): """ @@ -7041,7 +7047,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""" @@ -7205,7 +7211,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): @@ -7608,7 +7614,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): @@ -8175,7 +8181,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): @@ -8247,7 +8253,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): @@ -8319,7 +8325,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): @@ -8382,7 +8388,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 @@ -8394,7 +8400,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 # @@ -8900,11 +8906,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__ @@ -9016,7 +9022,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 @@ -9121,7 +9127,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): """ @@ -9154,7 +9160,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): """ @@ -9186,7 +9192,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): """ @@ -9249,28 +9255,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): @@ -9310,13 +9321,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): @@ -9342,7 +9353,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): @@ -9374,7 +9385,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): @@ -9406,7 +9417,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): @@ -9438,7 +9449,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): @@ -9508,8 +9519,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)