diff --git a/src/sage/combinat/affine_permutation.py b/src/sage/combinat/affine_permutation.py index 74113055d13..cc2a03ec499 100644 --- a/src/sage/combinat/affine_permutation.py +++ b/src/sage/combinat/affine_permutation.py @@ -13,7 +13,6 @@ # **************************************************************************** from itertools import repeat -from sage.arith.misc import binomial from sage.categories.affine_weyl_groups import AffineWeylGroups from sage.combinat.composition import Composition from sage.combinat.partition import Partition @@ -23,7 +22,7 @@ from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod from sage.misc.prandom import randint -from sage.rings.integer_ring import ZZ +from sage.rings.integer import Integer from sage.structure.list_clone import ClonableArray from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation @@ -76,14 +75,14 @@ def __init__(self, parent, lst, check=True): Type A affine permutation with window [1, 2, 3, 4] """ if check: - lst = [ZZ(val) for val in lst] + lst = [Integer(val) for val in lst] self.k = parent.k self.n = self.k + 1 - #This N doesn't matter for type A, but comes up in all other types. + # This N doesn't matter for type A, but comes up in all other types. if parent.cartan_type()[0] == 'A': self.N = self.n elif parent.cartan_type()[0] in ['B', 'C', 'D']: - self.N = 2*self.k + 1 + self.N = 2 * self.k + 1 elif parent.cartan_type()[0] == 'G': self.N = 6 else: @@ -245,7 +244,7 @@ def is_i_grassmannian(self, i=0, side='right') -> bool: """ return self == self.parent().one() or self.descents(side) == [i] - def index_set(self): + def index_set(self) -> tuple: r""" Index set of the affine permutation group. @@ -255,7 +254,7 @@ def index_set(self): sage: A.index_set() (0, 1, 2, 3, 4, 5, 6, 7) """ - return tuple(range(self.k+1)) + return tuple(range(self.k + 1)) def lower_covers(self, side='right'): r""" @@ -305,7 +304,7 @@ def reduced_word(self): sage: p.reduced_word() [0, 7, 4, 1, 0, 7, 5, 4, 2, 1] """ - #This is about 25% faster than the default algorithm. + # This is about 25% faster than the default algorithm. x = self i = 0 word = [] @@ -410,10 +409,10 @@ def grassmannian_quotient(self, i=0, side='right'): class AffinePermutationTypeA(AffinePermutation): - #---------------------- - #Type-specific methods. - #(Methods existing in all types, but with type-specific definition.) - #---------------------- + # ---------------------- + # Type-specific methods. + # (Methods existing in all types, but with type-specific definition.) + # ---------------------- def check(self): r""" Check that ``self`` is an affine permutation. @@ -440,13 +439,14 @@ def check(self): if not self: return k = self.parent().k - #Type A. + # Type A if len(self) != k + 1: - raise ValueError("length of list must be k+1="+str(k+1)) - if binomial(k+2,2) != sum(self): - raise ValueError("window does not sum to " + str(binomial((k+2),2))) - l = sorted([i % (k+1) for i in self]) - if l != list(range(k+1)): + raise ValueError(f"length of list must be k+1={k + 1}") + sigma = (k + 2).binomial(2) + if sigma != sum(self): + raise ValueError(f"window does not sum to {sigma}") + l = sorted(i % (k + 1) for i in self) + if any(i != j for i, j in enumerate(l)): raise ValueError("entries must have distinct residues") def value(self, i, base_window=False): @@ -510,11 +510,11 @@ def apply_simple_reflection_right(self, i): Type A affine permutation with window [3, -1, 6, 0, 5, 4, 10, 9] """ j = i % (self.k+1) - #Cloning is currently kinda broken, in that caches don't clear which - #leads to strangeness with the cloned object. - #The clone approach is quite a bit (2x) faster, though, so this should - #switch once the caching situation is fixed. - #with self.clone(check=False) as l: + # Cloning is currently kinda broken, in that caches don't clear which + # leads to strangeness with the cloned object. + # The clone approach is quite a bit (2x) faster, though, so this should + # switch once the caching situation is fixed. + # with self.clone(check=False) as l: l = self[:] if j == 0: a = l[0] @@ -524,7 +524,6 @@ def apply_simple_reflection_right(self, i): a = l[j-1] l[j-1] = l[j] l[j] = a - #return l return type(self)(self.parent(), l, check=False) def apply_simple_reflection_left(self, i): @@ -539,18 +538,18 @@ def apply_simple_reflection_left(self, i): sage: p.apply_simple_reflection_left(11) Type A affine permutation with window [4, -1, 0, 6, 5, 3, 10, 9] """ - #Here are a couple other methods we tried out, but turned out - #to be slower than the current implementation. - #1) This one was very bad: - # return self.inverse().apply_simple_reflection_right(i).inverse() - #2) Also bad, though not quite so bad: - # return (self.parent().simple_reflection(i))*self - i = i % (self.k+1) - #Cloning is currently kinda broken, in that caches don't clear which - #leads to strangeness with the cloned object. - #The clone approach is quite a bit faster, though, so this should switch - #once the caching situation is fixed. - #with self.clone(check=False) as l: + # Here are a couple other methods we tried out, but turned out + # to be slower than the current implementation. + # 1) This one was very bad: + # return self.inverse().apply_simple_reflection_right(i).inverse() + # 2) Also bad, though not quite so bad: + # return (self.parent().simple_reflection(i))*self + i = i % (self.k + 1) + # Cloning is currently kinda broken, in that caches don't clear which + # leads to strangeness with the cloned object. + # The clone approach is quite a bit faster, though, + # so this should switch once the caching situation is fixed. + # with self.clone(check=False) as l: l = [] if i != self.k: for m in range(self.k + 1): @@ -627,10 +626,10 @@ def to_type_a(self): """ return self - #---------------------- - #Type-A-specific methods. - #Only available in Type A. - #---------------------- + # ---------------------- + # Type-A-specific methods. + # Only available in Type A. + # ---------------------- def flip_automorphism(self): r""" @@ -699,7 +698,7 @@ def maximal_cyclic_factor(self, typ='decreasing', side='right', verbose=False): else: descents = self.descents(side='left') side = 'left' - #for now, assume side is 'right') + # for now, assume side is 'right') best_T = [] for i in descents: y = self.clone().apply_simple_reflection(i,side) @@ -834,8 +833,8 @@ def to_lehmer_code(self, typ='decreasing', side='right'): """ code = [0 for i in range(self.k+1)] if typ[0] == 'i' and side[0] == 'r': - #Find number of positions to the right of position i with smaller - #value than the number in position i. + # Find number of positions to the right of position i with smaller + # value than the number in position i. for i in range(self.k+1): a = self(i) for j in range(i+1, i+self.k+1): @@ -843,9 +842,9 @@ def to_lehmer_code(self, typ='decreasing', side='right'): if b < a: code[i] += (a-b) // (self.k+1) + 1 elif typ[0] == 'd' and side[0] == 'r': - #Find number of positions to the left of position i with larger - #value than the number in position i. Then cyclically shift - #the resulting vector. + # Find number of positions to the left of position i with larger + # value than the number in position i. Then cyclically shift + # the resulting vector. for i in range(self.k+1): a = self(i) for j in range(i-self.k, i): @@ -855,18 +854,18 @@ def to_lehmer_code(self, typ='decreasing', side='right'): if a < b: code[i-1] += ((b-a)//(self.k+1)+1) elif typ[0] == 'i' and side[0] == 'l': - #Find number of positions to the right of i smaller than i, then - #cyclically shift the resulting vector. + # Find number of positions to the right of i smaller than i, then + # cyclically shift the resulting vector. for i in range(self.k+1): pos = self.position(i) for j in range(pos+1, pos+self.k+1): b = self(j) - #A small rotation is necessary for the reduced word from - #the lehmer code to match the element. + # A small rotation is necessary for the reduced word from + # the lehmer code to match the element. if b < i: code[i-1] += (i-b) // (self.k+1) + 1 elif typ[0] == 'd' and side[0] == 'l': - #Find number of positions to the left of i larger than i. + # Find number of positions to the left of i larger than i. for i in range(self.k+1): pos = self.position(i) for j in range(pos-self.k, pos): @@ -1103,7 +1102,7 @@ def value(self, i): sage: C = AffinePermutationGroup(['C',4,1]) sage: x = C.one() - sage: [x.value(i) for i in range(-10,10)] == list(range(-10,10)) + sage: all(x.value(i) == i for i in range(-10,10)) True """ N = 2*self.k + 1 @@ -1124,7 +1123,7 @@ def position(self, i): sage: C = AffinePermutationGroup(['C',4,1]) sage: x = C.one() - sage: [x.position(i) for i in range(-10,10)] == list(range(-10,10)) + sage: all(x.position(i) == i for i in range(-10,10)) True """ N = 2*self.k + 1 @@ -2001,9 +2000,9 @@ class AffinePermutationGroupGeneric(UniqueRepresentation, Parent): methods for the specific affine permutation groups. """ - #---------------------- - #Type-free methods. - #---------------------- + # ---------------------- + # Type-free methods. + # ---------------------- def __init__(self, cartan_type): r""" @@ -2014,13 +2013,13 @@ def __init__(self, cartan_type): """ Parent.__init__(self, category=AffineWeylGroups()) ct = CartanType(cartan_type) - self.k = ct.n + self.k = Integer(ct.n) self.n = ct.rank() - #This N doesn't matter for type A, but comes up in all other types. + # This N doesn't matter for type A, but comes up in all other types. if ct.letter == 'A': self.N = self.k + 1 elif ct.letter == 'B' or ct.letter == 'C' or ct.letter == 'D': - self.N = 2*self.k + 1 + self.N = 2 * self.k + 1 elif ct.letter == 'G': self.N = 6 self._cartan_type = ct @@ -2034,14 +2033,14 @@ def _element_constructor_(self, *args, **keywords): """ return self.element_class(self, *args, **keywords) - def _repr_(self): + def _repr_(self) -> str: r""" TESTS:: sage: AffinePermutationGroup(['A',7,1]) The group of affine permutations of type ['A', 7, 1] """ - return "The group of affine permutations of type "+str(self.cartan_type()) + return "The group of affine permutations of type " + str(self.cartan_type()) def _test_enumeration(self, n=4, **options): r""" @@ -2242,12 +2241,12 @@ def one(self): True sage: TestSuite(A).run() """ - return self(list(range(1, self.k + 2))) + return self(range(1, self.k + 2)) - #------------------------ - #Type-unique methods. - #(Methods which do not exist in all types.) - #------------------------ + # ------------------------ + # Type-unique methods. + # (Methods which do not exist in all types.) + # ------------------------ def from_lehmer_code(self, C, typ='decreasing', side='right'): r""" Return the affine permutation with the supplied Lehmer code (a weak @@ -2353,7 +2352,7 @@ def one(self): True sage: TestSuite(C).run() """ - return self(list(range(1, self.k + 1))) + return self(range(1, self.k + 1)) Element = AffinePermutationTypeC diff --git a/src/sage/combinat/baxter_permutations.py b/src/sage/combinat/baxter_permutations.py index 08b67b96540..6cddccb1940 100644 --- a/src/sage/combinat/baxter_permutations.py +++ b/src/sage/combinat/baxter_permutations.py @@ -1,13 +1,12 @@ """ Baxter permutations """ - -from sage.structure.unique_representation import UniqueRepresentation -from sage.structure.parent import Parent -from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets from sage.combinat.permutation import Permutations - +from sage.rings.integer import Integer from sage.rings.integer_ring import ZZ +from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets +from sage.structure.parent import Parent +from sage.structure.unique_representation import UniqueRepresentation class BaxterPermutations(UniqueRepresentation, Parent): @@ -79,11 +78,11 @@ def __init__(self, n): Baxter permutations of size 5 """ self.element_class = Permutations(n).element_class - self._n = ZZ(n) + self._n = Integer(n) from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets super().__init__(category=FiniteEnumeratedSets()) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of ``self``. @@ -93,9 +92,9 @@ def _repr_(self): sage: BaxterPermutations_size(5) Baxter permutations of size 5 """ - return "Baxter permutations of size %s" % self._n + return f"Baxter permutations of size {self._n}" - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Return ``True`` if and only if ``x`` is a Baxter permutation of size ``self._n``. @@ -228,12 +227,11 @@ def cardinality(self): Integer Ring """ if self._n == 0: - return 1 - from sage.arith.misc import binomial - return sum((binomial(self._n + 1, k) * - binomial(self._n + 1, k + 1) * - binomial(self._n + 1, k + 2)) // - ((self._n + 1) * binomial(self._n + 1, 2)) + return ZZ.one() + n = self._n + 1 + return sum((n.binomial(k) * + n.binomial(k + 1) * + n.binomial(k + 2)) // (n * n.binomial(2)) for k in range(self._n)) diff --git a/src/sage/combinat/blob_algebra.py b/src/sage/combinat/blob_algebra.py index 595063a69fd..2ea8a223e40 100644 --- a/src/sage/combinat/blob_algebra.py +++ b/src/sage/combinat/blob_algebra.py @@ -17,22 +17,19 @@ # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.structure.parent import Parent -from sage.structure.unique_representation import UniqueRepresentation -from sage.structure.element import Element, get_coercion_model -from sage.structure.richcmp import richcmp -#from sage.misc.inherit_comparison import InheritComparisonClasscallMetaclass -from sage.misc.cachefunc import cached_method -from sage.combinat.subset import powerset -from sage.arith.misc import binomial -from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.categories.algebras import Algebras +from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets from sage.combinat.diagram_algebras import (TemperleyLiebDiagrams, diagram_latex, TL_diagram_ascii_art) -from sage.combinat.free_module import CombinatorialFreeModule from sage.combinat.dyck_word import DyckWords - -#@add_metaclass(InheritComparisonClasscallMetaclass) +from sage.combinat.free_module import CombinatorialFreeModule +from sage.combinat.subset import powerset +from sage.misc.cachefunc import cached_method +from sage.rings.integer import Integer +from sage.structure.element import Element, get_coercion_model +from sage.structure.parent import Parent +from sage.structure.richcmp import richcmp +from sage.structure.unique_representation import UniqueRepresentation class BlobDiagram(Element): @@ -167,7 +164,7 @@ def __init__(self, n): sage: BD4 = BlobDiagrams(4) sage: TestSuite(BD4).run() """ - self._n = n + self._n = Integer(n) self._TL_diagrams = TemperleyLiebDiagrams(n) Parent.__init__(self, category=FiniteEnumeratedSets()) @@ -181,7 +178,7 @@ def _repr_(self): sage: BlobDiagrams(4) Blob diagrams of order 4 """ - return "Blob diagrams of order {}".format(self._n) + return f"Blob diagrams of order {self._n}" def cardinality(self): r""" @@ -194,7 +191,7 @@ def cardinality(self): sage: BD4.cardinality() 70 """ - return binomial(2*self._n, self._n) + return (2 * self._n).binomial(self._n) def order(self): r""" @@ -221,7 +218,7 @@ def base_set(self): sage: sorted(BD4.base_set()) [-4, -3, -2, -1, 1, 2, 3, 4] """ - return frozenset(range(1,self._n+1)).union(range(-self._n,0)) + return frozenset(range(1, self._n + 1)).union(range(-self._n, 0)) def _element_constructor_(self, marked, unmarked=None): r""" diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index 5ab85f84208..7860f4e0d87 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -332,7 +332,7 @@ def __init__(self, data, frozen=None, is_principal=False, user_labels=None, user else: labelset = set(user_labels) # Sanitizes our ``user_labels`` to use Integers instead of ints - user_labels = [ZZ(x) if x in ZZ else x for x in user_labels] + user_labels = [Integer(x) if x in ZZ else x for x in user_labels] if labelset != set(self._nlist + self._mlist) and labelset != set(range(self._n + self._m)): raise ValueError('user_labels conflict with both the given' ' vertex labels and the default labels') @@ -3593,7 +3593,7 @@ def mutation_class_iter(self, depth=infinity, show_depth=False, else: orbits = [index for index in range(n) if index > i or sd2._M[index, i] != 0] - clusters[cl2] = [sd2, orbits, clusters[key][2]+[i]] + clusters[cl2] = [sd2, orbits, clusters[key][2] + [i]] if return_paths: yield (sd2, clusters[cl2][2]) else: @@ -3602,10 +3602,10 @@ def mutation_class_iter(self, depth=infinity, show_depth=False, if show_depth and gets_bigger: timer2 = time.time() dc = str(depth_counter) - dc += ' ' * (5-len(dc)) + dc += ' ' * (5 - len(dc)) nr = str(len(clusters)) - nr += ' ' * (10-len(nr)) - print(f"Depth: {dc} found: {nr} Time: {timer2-timer:.2f} s") + nr += ' ' * (10 - len(nr)) + print(f"Depth: {dc} found: {nr} Time: {timer2 - timer:.2f} s") def mutation_class(self, depth=infinity, show_depth=False, return_paths=False, up_to_equivalence=True, only_sink_source=False): @@ -4718,7 +4718,7 @@ def _produce_upper_cluster_algebra_element(self, vd, cList): for l in range(num_cols): denominator = denominator * (R.gen(l))**vd[i][0][l] # Each copy of a vector in vd contributes a factor of the Laurent polynomial calculated from it. - final = (numerator/denominator)**vd[i][1] + final = (numerator / denominator)**vd[i][1] finalP.append(final) laurentP = 1 # The UCA element for the vector a is the product of the elements produced from the vectors in its decomposition. @@ -4740,10 +4740,8 @@ def _bino(n, k): 0 """ if n >= 0: - from sage.arith.misc import binomial - return binomial(n, k) - else: - return 0 + return Integer(n).binomial(k) + return 0 def coeff_recurs(p, q, a1, a2, b, c): @@ -5192,7 +5190,7 @@ def almost_positive_root(self): mt = self._mutation_type._repr_() # mt is a string of the shape "['A', 15]" # where A is a single letter and 15 is an integer - Phi = RootSystem([mt[2: 3], ZZ(mt[6: -1])]) + Phi = RootSystem([mt[2: 3], Integer(mt[6: -1])]) Phiplus = Phi.root_lattice().simple_roots() if self.denominator() == 1: diff --git a/src/sage/combinat/dyck_word.py b/src/sage/combinat/dyck_word.py index df841984f31..22aa66d39f9 100644 --- a/src/sage/combinat/dyck_word.py +++ b/src/sage/combinat/dyck_word.py @@ -90,7 +90,7 @@ from sage.categories.infinite_enumerated_sets import InfiniteEnumeratedSets from sage.categories.posets import Posets -from sage.rings.integer_ring import ZZ +from sage.rings.integer import Integer from sage.rings.rational_field import QQ from sage.combinat.permutation import Permutation, Permutations from sage.combinat.words.word import Word @@ -544,13 +544,13 @@ def _repr_lattice(self, type=None, labelling=None, underpath=True) -> str: row = " " * (n - alst[-1] - 1) + final_fall + "\n" for i in range(n - 1): c = 0 - row = row + " "*(n-i-2-alst[-i-2]) + row = row + " " * (n-i-2-alst[-i-2]) c += n-i-2-alst[-i-2] if alst[-i-2]+1 != alst[-i-1]: row += " _" c += alst[-i-2] - alst[-i-1] if underpath: - row += "__"*(alst[-i-2]-alst[-i-1])+"|" + labels[-1] + "x "*(n-c-2-i) + " ."*i + "\n" + row += "__" * (alst[-i-2]-alst[-i-1]) + "|" + labels[-1] + "x "*(n-c-2-i) + " ." * i + "\n" else: row += "__"*(alst[-i-2]-alst[-i-1])+"| " + "x "*(n-c-2-i) + " ."*i + labels[-1] + "\n" labels.pop() @@ -3286,14 +3286,14 @@ def __classcall_private__(cls, k1=None, k2=None, complete=True): return CompleteDyckWords_all() return DyckWords_all() - k1 = ZZ(k1) + k1 = Integer(k1) if k1 < 0: raise ValueError("k1 (= %s) must be nonnegative" % k1) return CompleteDyckWords_size(k1) else: - k1 = ZZ(k1) + k1 = Integer(k1) - k2 = ZZ(k2) + k2 = Integer(k2) if k1 < 0 or (k2 is not None and k2 < 0): raise ValueError("k1 (= %s) and k2 (= %s) must be nonnegative, with k1 >= k2" % (k1, k2)) if k1 < k2: @@ -3638,8 +3638,8 @@ def __init__(self, k1, k2): # Dyck paths, not words; having k1 opening parens and k2 closing # parens corresponds to paths of length k1 + k2 ending at height # k1 - k2. - k1 = ZZ(k1) - k2 = ZZ(k2) + k1 = Integer(k1) + k2 = Integer(k2) self.n = k1 + k2 self.endht = k1 - k2 @@ -3697,8 +3697,8 @@ def __init__(self, k1, k2): Integer Ring sage: TestSuite(DyckWords(4,2)).run() """ - self.k1 = ZZ(k1) - self.k2 = ZZ(k2) + self.k1 = Integer(k1) + self.k2 = Integer(k2) DyckWords.__init__(self, category=FiniteEnumeratedSets()) def _repr_(self) -> str: @@ -3780,8 +3780,7 @@ def cardinality(self) -> int: ....: for p in range(7)) True """ - from sage.arith.misc import binomial - return (self.k1 - self.k2 + 1) * binomial(self.k1 + self.k2, self.k2) // (self.k1 + 1) + return (self.k1 - self.k2 + 1) * (self.k1 + self.k2).binomial(self.k2) // (self.k1 + 1) ################################################################ # Complete Dyck words diff --git a/src/sage/combinat/interval_posets.py b/src/sage/combinat/interval_posets.py index afdae758dfc..9fa34fd3986 100644 --- a/src/sage/combinat/interval_posets.py +++ b/src/sage/combinat/interval_posets.py @@ -47,6 +47,7 @@ from sage.misc.lazy_attribute import lazy_attribute from sage.misc.lazy_import import lazy_import from sage.rings.integer import Integer +from sage.rings.integer_ring import ZZ from sage.rings.semirings.non_negative_integer_semiring import NN from sage.sets.non_negative_integers import NonNegativeIntegers from sage.sets.disjoint_union_enumerated_sets import DisjointUnionEnumeratedSets @@ -3757,11 +3758,10 @@ def cardinality(self) -> Integer: sage: [TamariIntervalPosets(i).cardinality() for i in range(6)] [1, 1, 3, 13, 68, 399] """ - from sage.arith.misc import binomial n = self._size if n == 0: - return Integer(1) - return (2 * binomial(4 * n + 1, n - 1)) // (n * (n + 1)) + return ZZ.one() + return (2 * Integer(4 * n + 1).binomial(n - 1)) // (n * (n + 1)) # return Integer(2 * factorial(4*n+1)/(factorial(n+1)*factorial(3*n+2))) def __iter__(self) -> Iterator[TIP]: diff --git a/src/sage/combinat/posets/posets.py b/src/sage/combinat/posets/posets.py index a2039494ce4..173cbb872da 100644 --- a/src/sage/combinat/posets/posets.py +++ b/src/sage/combinat/posets/posets.py @@ -292,7 +292,6 @@ from sage.misc.cachefunc import cached_method from sage.misc.lazy_attribute import lazy_attribute from sage.misc.misc_c import prod -from sage.arith.misc import binomial from sage.categories.category import Category from sage.categories.sets_cat import Sets from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets @@ -1815,7 +1814,7 @@ def atkinson(self, a): for r in range(1, n + 1): new_a_spec.append(0) for i in range(max(1, r - n + k), min(r, k) + 1): - k_val = binomial(r - 1, i - 1) * binomial(n - r, k - i) + k_val = Integer(r - 1).binomial(i - 1) * Integer(n - r).binomial(k - i) new_a_spec[-1] += k_val * a_spec[i - 1] * n_lin_exts return new_a_spec @@ -5295,7 +5294,7 @@ def factor(self): dg = self._hasse_diagram if not dg.is_connected(): raise NotImplementedError('the poset is not connected') - if ZZ(dg.num_verts()).is_prime(): + if Integer(dg.num_verts()).is_prime(): return [self] G = dg.to_undirected() is_product, dic = G.is_cartesian_product(relabeling=True) @@ -5306,7 +5305,7 @@ def factor(self): prod_dg = dg.relabel(dic, inplace=False) v0 = next(iter(dic.values())) n = len(v0) - factors_range = list(range(n)) + factors_range = range(n) fusion = Graph(n) def edge_color(va, vb): @@ -6492,7 +6491,7 @@ def random_order_ideal(self, direction='down'): with seed(currseed): for _ in range(count): for element in range(n): - if random() % 2 == 1: + if random() % 2: # should use one random bit s = [state[i] for i in lower_covers[element]] if 1 not in s: if 2 not in s: @@ -7168,12 +7167,12 @@ def order_polytope(self): True """ from sage.geometry.polyhedron.constructor import Polyhedron - ineqs = [[0] + [ZZ(j == v) - ZZ(j == u) for j in self] + ineqs = [[0] + [Integer(j == v) - Integer(j == u) for j in self] for u, v in self.hasse_diagram().edges(sort=False, labels=False)] for i in self.maximal_elements(): - ineqs += [[1] + [-ZZ(j == i) for j in self]] + ineqs += [[1] + [-Integer(j == i) for j in self]] for i in self.minimal_elements(): - ineqs += [[0] + [ZZ(j == i) for j in self]] + ineqs += [[0] + [Integer(j == i) for j in self]] return Polyhedron(ieqs=ineqs, base_ring=ZZ) def chain_polytope(self): @@ -7207,10 +7206,10 @@ def chain_polytope(self): A 5-dimensional polyhedron in ZZ^5 defined as the convex hull of 8 vertices """ from sage.geometry.polyhedron.constructor import Polyhedron - ineqs = [[1] + [-ZZ(j in chain) for j in self] + ineqs = [[1] + [-Integer(j in chain) for j in self] for chain in self.maximal_chains_iterator()] for i in self: - ineqs += [[0] + [ZZ(j == i) for j in self]] + ineqs += [[0] + [Integer(j == i) for j in self]] return Polyhedron(ieqs=ineqs, base_ring=ZZ) def zeta_polynomial(self): @@ -8141,7 +8140,7 @@ def is_eulerian(self, k=None, certificate=False): n = self.cardinality() if n == 1: return True - if k is None and not certificate and n % 2 == 1: + if k is None and not certificate and n % 2: return False H = self._hasse_diagram diff --git a/src/sage/combinat/root_system/pieri_factors.py b/src/sage/combinat/root_system/pieri_factors.py index fa97defb73e..c1f2ba8afd3 100644 --- a/src/sage/combinat/root_system/pieri_factors.py +++ b/src/sage/combinat/root_system/pieri_factors.py @@ -11,22 +11,21 @@ # https://www.gnu.org/licenses/ # ***************************************************************************** +from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets +import sage.combinat.ranker +from sage.combinat.root_system.root_system import RootSystem +from sage.combinat.root_system.weyl_group import WeylGroup from sage.misc.cachefunc import cached_method -from sage.misc.constant_function import ConstantFunction from sage.misc.call import attrcall +from sage.misc.constant_function import ConstantFunction from sage.misc.lazy_import import lazy_import from sage.misc.misc_c import prod -from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets -from sage.structure.parent import Parent -from sage.structure.unique_representation import UniqueRepresentation +from sage.rings.infinity import infinity from sage.rings.integer import Integer from sage.rings.rational_field import QQ -from sage.rings.infinity import infinity -from sage.arith.misc import binomial -import sage.combinat.ranker from sage.sets.recursively_enumerated_set import RecursivelyEnumeratedSet -from sage.combinat.root_system.root_system import RootSystem -from sage.combinat.root_system.weyl_group import WeylGroup +from sage.structure.parent import Parent +from sage.structure.unique_representation import UniqueRepresentation lazy_import('sage.graphs.digraph', 'DiGraph') lazy_import('sage.combinat.root_system.dynkin_diagram', 'DynkinDiagram') @@ -755,8 +754,7 @@ def cardinality(self): """ if self._min_length == len(self._min_support) and self._max_length == len(self._max_support) - 1: return Integer(2**(len(self._extra_support)) - 1) - else: - return self.generating_series(weight=ConstantFunction(1)) + return self.generating_series(weight=ConstantFunction(1)) def generating_series(self, weight=None): r""" @@ -774,7 +772,7 @@ def generating_series(self, weight=None): weight = self.default_weight() l_min = len(self._min_support) l_max = len(self._max_support) - return sum(binomial(l_max - l_min, l - l_min) * weight(l) + return sum(Integer(l_max - l_min).binomial(l - l_min) * weight(l) for l in range(self._min_length, self._max_length + 1)) def __iter__(self): diff --git a/src/sage/combinat/words/shuffle_product.py b/src/sage/combinat/words/shuffle_product.py index 5aea554b6b6..9d5c43dd73b 100644 --- a/src/sage/combinat/words/shuffle_product.py +++ b/src/sage/combinat/words/shuffle_product.py @@ -21,11 +21,11 @@ # # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.combinat.words.word import Word_class, Word -from sage.arith.misc import binomial from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets -from sage.combinat.integer_vector import IntegerVectors from sage.combinat.composition import Composition +from sage.combinat.integer_vector import IntegerVectors +from sage.combinat.words.word import Word_class, Word +from sage.rings.integer import Integer from sage.structure.parent import Parent from sage.structure.unique_representation import UniqueRepresentation @@ -174,7 +174,7 @@ def cardinality(self): """ len_w1 = self._w1.length() len_w2 = self._w2.length() - return binomial(len_w1 + len_w2, len_w1) + return Integer(len_w1 + len_w2).binomial(len_w1) def __iter__(self): """