diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index 077232d7d55..8b75f3ed19f 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -990,7 +990,7 @@ def maximal_order(self, take_shortcuts=True, order_basis=None): ....: (-511, 608), (493, 880), (105, -709), (-213, 530), ....: (97, 745)] sage: all(QuaternionAlgebra(a, b).maximal_order().is_maximal() - ....: for (a, b) in invars) + ....: for a, b in invars) True """ if self.base_ring() != QQ: @@ -1071,7 +1071,7 @@ def maximal_order(self, take_shortcuts=True, order_basis=None): e_n = [] x_rows = A.solve_left(matrix([V(vec.coefficient_tuple()) - for (vec, val) in f]), + for vec, val in f]), check=False).rows() denoms = [x.denominator() for x in x_rows] for i in range(4): @@ -1199,7 +1199,7 @@ def order_with_level(self, level): fact = M1.factor() B = O.basis() - for (p, r) in fact: + for p, r in fact: a = int(-p) // 2 for v in GF(p)**4: x = sum([int(v[i] + a) * B[i] for i in range(4)]) @@ -4584,10 +4584,9 @@ def normalize_basis_at_p(e, p, B=QuaternionAlgebraElement_abstract.pair): sage: e = [A(1), k, j, 1/2 + 1/2*i + 1/2*j + 1/2*k] sage: e_norm = normalize_basis_at_p(e, 2) sage: V = QQ**4 - sage: V.span([V(x.coefficient_tuple()) for (x,_) in e_norm]).dimension() + sage: V.span([V(x.coefficient_tuple()) for x, _ in e_norm]).dimension() 4 """ - N = len(e) if N == 0: return [] diff --git a/src/sage/algebras/steenrod/steenrod_algebra.py b/src/sage/algebras/steenrod/steenrod_algebra.py index 2a37d879853..7aa7035034f 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra.py +++ b/src/sage/algebras/steenrod/steenrod_algebra.py @@ -648,7 +648,7 @@ def _basis_key_iterator(self): EXAMPLES:: sage: A = SteenrodAlgebra(3,basis='adem') - sage: for (idx,key) in zip((1,..,10),A._basis_key_iterator()): + sage: for idx, key in zip((1,..,10),A._basis_key_iterator()): ....: print("> %2d %-20s %s" % (idx,key,A.monomial(key))) > 1 () 1 > 2 (1,) beta @@ -767,17 +767,15 @@ def _repr_(self) -> str: sage: SteenrodAlgebra(p=5, profile=(lambda n: 4, lambda n: 1)) sub-Hopf algebra of mod 5 Steenrod algebra, milnor basis, profile function ([4, 4, 4, ..., 4, 4, +Infinity, +Infinity, +Infinity, ...], [1, 1, 1, ..., 1, 1, 2, 2, ...]) """ - def abridge_list(l): + def abridge_list(li): """ - String rep for list ``l`` if ``l`` is short enough; + String rep for list ``li`` if ``li`` is short enough; otherwise print the first few terms and the last few terms, with an ellipsis in between. """ - if len(l) < 8: - l_str = str(l) - else: - l_str = str(l[:3]).rstrip("]") + ", ..., " + str(l[-2:]).lstrip("[") - return l_str + if len(li) < 8: + return str(li) + return str(li[:3]).rstrip("]") + ", ..., " + str(li[-2:]).lstrip("[") from sage.rings.infinity import Infinity profile = self._profile @@ -1345,8 +1343,8 @@ def coprod_list(t): right_q = sorted(all_q - a) sign = Permutation(convert_perm(left_q + right_q)).signature() tens_q[(tuple(left_q), tuple(right_q))] = sign - tens = {((q[0], l), (q[1], r)): tq - for l, r in zip(left_p, right_p) + tens = {((q[0], lp), (q[1], rp)): tq + for lp, rp in zip(left_p, right_p) for q, tq in tens_q.items()} return self.tensor_square()._from_dict(tens, coerce=True) elif basis == 'serre-cartan': @@ -1642,14 +1640,14 @@ def _milnor_on_basis(self, t): elif basis == 'woody' or basis == 'woodz': # each entry in t is a pair (m,k), corresponding to w(m,k), defined by # `w(m,k) = \text{Sq}^{2^m (2^{k+1}-1)}`. - for (m, k) in t: + for m, k in t: ans = ans * A.Sq(2**m * (2**(k+1) - 1)) # wall[_long] elif basis.find('wall') >= 0: # each entry in t is a pair (m,k), corresponding to Q^m_k, defined by # `Q^m_k = Sq(2^k) Sq(2^{k+1}) ... Sq(2^m)`. - for (m, k) in t: + for m, k in t: exponent = 2**k ans = ans * A.Sq(exponent) for i in range(m-k): @@ -1660,7 +1658,7 @@ def _milnor_on_basis(self, t): elif basis.find('pst') >= 0: if not self._generic: # each entry in t is a pair (i,j), corresponding to P^i_j - for (i, j) in t: + for i, j in t: ans = ans * A.pst(i, j) else: # t = (Q, P) where Q is the tuple of Q_i's, and P is a @@ -1668,14 +1666,14 @@ def _milnor_on_basis(self, t): # corresponding to (P^i_j)^n if t[0]: ans = ans * A.Q(*t[0]) - for ((i, j), n) in t[1]: + for (i, j), n in t[1]: ans = ans * (A.pst(i, j))**n # arnona[_long] elif basis.find('arnona') >= 0: # each entry in t is a pair (m,k), corresponding to X^m_k, defined by # `X^m_k = Sq(2^m) ... Sq(2^{k+1}) Sq(2^k)` - for (m, k) in t: + for m, k in t: exponent = 2**k X = A.Sq(exponent) for i in range(m-k): @@ -1689,7 +1687,7 @@ def _milnor_on_basis(self, t): # each entry in t is a pair (i,j), corresponding to # c_{i,j}, the iterated commutator defined by c_{i,1} # = Sq(2^i) and c_{i,j} = [c_{i,j-1}, Sq(2^{i+j-1})]. - for (i, j) in t: + for i, j in t: comm = A.Sq(2**i) for k in range(2, j+1): y = A.Sq(2**(i+k-1)) @@ -1703,7 +1701,7 @@ def _milnor_on_basis(self, t): # c_{i,j} = [P(p^{i+j-1}), c_{i,j-1}]. if t[0]: ans = ans * A.Q(*t[0]) - for ((i, j), n) in t[1]: + for (i, j), n in t[1]: comm = A.P(p**i) for k in range(2, j+1): y = A.P(p**(i+k-1)) @@ -1947,7 +1945,7 @@ def q_degree(m, prime=3): if basis == 'woody' or basis == 'woodz': # each entry in t is a pair (m,k), corresponding to w(m,k), defined by # `w(m,k) = \text{Sq}^{2^m (2^{k+1}-1)}`. - return sum(2**m * (2**(k+1)-1) for (m, k) in t) + return sum(2**m * (2**(k+1)-1) for m, k in t) # wall, arnon_a if basis.find('wall') >= 0 or basis.find('arnona') >= 0: @@ -1958,7 +1956,7 @@ def q_degree(m, prime=3): # Arnon A: each entry in t is a pair (m,k), corresponding # to X^m_k, defined by `X^m_k = Sq(2^m) ... Sq(2^{k+1}) # Sq(2^k)` - return sum(2**k * (2**(m-k+1)-1) for (m, k) in t) + return sum(2**k * (2**(m-k+1)-1) for m, k in t) # pst, comm if basis.find('pst') >= 0 or basis.find('comm') >= 0: @@ -1969,7 +1967,7 @@ def q_degree(m, prime=3): # to c_{i,j}, the iterated commutator defined by # c_{i,1} = Sq(2^i) and c_{i,j} = [c_{i,j-1}, # Sq(2^{i+j-1})]. - return sum(2**m * (2**k - 1) for (m, k) in t) + return sum(2**m * (2**k - 1) for m, k in t) # p odd: # # Pst: have pair (Q, P) where Q is a tuple of Q's, as in @@ -1982,7 +1980,7 @@ def q_degree(m, prime=3): # iterated commutator defined by c_{s,1} = P(p^s) and # c_{s,t} = [P(p^{s+t-1}), c_{s,t-1}]. q_deg = q_degree(t[0], prime=p) - p_deg = sum(2 * n * p**s * (p**t - 1) for ((s, t), n) in t[1]) + p_deg = sum(2 * n * p**s * (p**t - 1) for (s, t), n in t[1]) return q_deg + p_deg # coercion methods: @@ -2236,7 +2234,7 @@ def basis(self, d=None): Lazy family (Term map from basis key family of mod 7 Steenrod algebra, milnor basis to mod 7 Steenrod algebra, milnor basis(i))_{i in basis key family of mod 7 Steenrod algebra, milnor basis} - sage: for (idx,a) in zip((1,..,9),A7.basis()): + sage: for idx, a in zip((1,..,9),A7.basis()): ....: print("{} {}".format(idx, a)) 1 1 2 Q_0 @@ -3435,7 +3433,7 @@ def coproduct(self, algorithm='milnor'): 1 sage: Sq(*supp[0][1]) Sq(2) - sage: [(Sq(*x), Sq(*y)) for (x,y) in supp] + sage: [(Sq(*x), Sq(*y)) for x, y in supp] [(1, Sq(2)), (Sq(1), Sq(1)), (Sq(2), 1)] The ``support`` of an element does not include the @@ -3453,7 +3451,7 @@ def coproduct(self, algorithm='milnor'): (((), (1,)), ((), (1,))): 2, (((), (2,)), ((), ())): 2} sage: mc = b.monomial_coefficients() - sage: sorted([(A3.monomial(x), A3.monomial(y), mc[x,y]) for (x,y) in mc]) + sage: sorted([(A3.monomial(x), A3.monomial(y), mc[x,y]) for x, y in mc]) [(1, P(2), 2), (P(1), P(1), 2), (P(2), 1, 2)] """ A = self.parent() @@ -3627,7 +3625,7 @@ def may_weight(self): return wt else: # p odd wt = Infinity - for (mono1, mono2) in self.milnor().support(): + for mono1, mono2 in self.milnor().support(): P_wt = 0 index = 1 for n in mono2: diff --git a/src/sage/algebras/steenrod/steenrod_algebra_bases.py b/src/sage/algebras/steenrod/steenrod_algebra_bases.py index 04c24c9a3b5..e4f4f0a526a 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra_bases.py +++ b/src/sage/algebras/steenrod/steenrod_algebra_bases.py @@ -361,13 +361,13 @@ def steenrod_algebra_basis(n, basis='milnor', p=2, **kwds): return serre_cartan_basis(n, p, **kwds) # Atomic bases, p odd: elif generic and (basis_name.find('pst') >= 0 - or basis_name.find('comm') >= 0): + or basis_name.find('comm') >= 0): return atomic_basis_odd(n, basis_name, p, **kwds) # Atomic bases, p=2 elif not generic and (basis_name == 'woody' or basis_name == 'woodz' - or basis_name == 'wall' or basis_name == 'arnona' - or basis_name.find('pst') >= 0 - or basis_name.find('comm') >= 0): + or basis_name == 'wall' or basis_name == 'arnona' + or basis_name.find('pst') >= 0 + or basis_name.find('comm') >= 0): return atomic_basis(n, basis_name, **kwds) # Arnon 'C' basis elif not generic and basis == 'arnonc': @@ -726,7 +726,7 @@ def serre_cartan_basis(n, p=2, bound=1, **kwds): for vec in serre_cartan_basis(n - last, bound=2 * last): new = vec + (last,) result.append(new) - else: # p odd + else: # p odd if n % (2 * (p-1)) == 0 and n//(2 * (p-1)) >= bound: result = [(0, int(n//(2 * (p-1))), 0)] elif n == 1: @@ -739,7 +739,7 @@ def serre_cartan_basis(n, p=2, bound=1, **kwds): if n - 2*(p-1)*last > 0: for vec in serre_cartan_basis(n - 2*(p-1)*last, p, p*last, generic=generic): - result.append(vec + (last,0)) + result.append(vec + (last, 0)) # case 2: append P^{last} beta if bound == 1: bound = 0 @@ -849,7 +849,7 @@ def degree_dictionary(n, basis): m = 0 deg = 2**m * (2**(k+1) - 1) while deg <= n: - dict[deg] = (m,k) + dict[deg] = (m, k) if m > 0: m = m - 1 k = k + 1 @@ -862,7 +862,7 @@ def degree_dictionary(n, basis): m = 0 deg = 2**k * (2**(m-k+1) - 1) while deg <= n: - dict[deg] = (m,k) + dict[deg] = (m, k) if k == 0: m = m + 1 k = m @@ -875,9 +875,9 @@ def degree_dictionary(n, basis): deg = 2**s * (2**t - 1) while deg <= n: if basis.find('pst') >= 0: - dict[deg] = (s,t) + dict[deg] = (s, t) else: # comm - dict[deg] = (s,t) + dict[deg] = (s, t) if s == 0: s = t t = 1 @@ -889,18 +889,18 @@ def degree_dictionary(n, basis): def sorting_pair(s, t, basis): # pair used for sorting the basis if basis.find('wood') >= 0 and basis.find('z') >= 0: - return (-s-t,-s) + return (-s-t, -s) elif basis.find('wood') >= 0 or basis.find('wall') >= 0 or \ basis.find('arnon') >= 0: - return (-s,-t) + return (-s, -t) elif basis.find('rlex') >= 0: - return (t,s) + return (t, s) elif basis.find('llex') >= 0: - return (s,t) + return (s, t) elif basis.find('deg') >= 0: - return (s+t,t) + return (s+t, t) elif basis.find('revz') >= 0: - return (s+t,s) + return (s+t, s) from sage.rings.infinity import Infinity profile = kwds.get("profile", None) @@ -926,7 +926,7 @@ def sorting_pair(s, t, basis): # pair used for sorting the basis okay = True if basis.find('pst') >= 0: if profile is not None and len(profile) > 0: - for (s,t) in big_list: + for s, t in big_list: if ((len(profile) > t-1 and profile[t-1] <= s) or (len(profile) <= t-1 and trunc < Infinity)): okay = False @@ -1087,7 +1087,7 @@ def sorting_pair(s, t, basis): # pair used for sorting the basis okay = False break - for ((s, t), _) in p_mono: + for (s, t), _ in p_mono: if ((len(profile[0]) > t-1 and profile[0][t-1] <= s) or (len(profile[0]) <= t-1 and trunc < Infinity)): okay = False @@ -1135,7 +1135,7 @@ def steenrod_basis_error_check(dim, p, **kwds): generic = kwds.get('generic', p != 2) if not generic: - bases = ('adem','woody', 'woodz', 'wall', 'arnona', 'arnonc', + bases = ('adem', 'woody', 'woodz', 'wall', 'arnona', 'arnonc', 'pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz', 'comm_rlex', 'comm_llex', 'comm_deg', 'comm_revz') else: @@ -1146,11 +1146,13 @@ def steenrod_basis_error_check(dim, p, **kwds): for i in range(dim): if i % 5 == 0: verbose("up to dimension %s" % i) - milnor_dim = len(steenrod_algebra_basis.f(i,'milnor',p=p,generic=generic)) + milnor_dim = len(steenrod_algebra_basis.f(i, 'milnor', p=p, + generic=generic)) for B in bases: - if milnor_dim != len(steenrod_algebra_basis.f(i,B,p,generic=generic)): + if milnor_dim != len(steenrod_algebra_basis.f(i, B, p, + generic=generic)): print("problem with milnor/{} in dimension {}".format(B, i)) - mat = convert_to_milnor_matrix.f(i,B,p,generic=generic) + mat = convert_to_milnor_matrix.f(i, B, p, generic=generic) if mat.nrows() != 0 and not mat.is_invertible(): print("%s invertibility problem in dim %s at p=%s" % (B, i, p)) @@ -1158,17 +1160,21 @@ def steenrod_basis_error_check(dim, p, **kwds): bases = ('pst_rlex', 'pst_llex', 'pst_deg', 'pst_revz') if not generic: - profiles = [(4,3,2,1), (2,2,3,1,1), (0,0,0,2)] + profiles = [(4, 3, 2, 1), (2, 2, 3, 1, 1), (0, 0, 0, 2)] else: - profiles = [((3,2,1), ()), ((), (2,1,2)), ((3,2,1), (2,2,2,2))] + profiles = [((3, 2, 1), ()), ((), (2, 1, 2)), ((3, 2, 1), (2, 2, 2, 2))] for i in range(dim): if i % 5 == 0: verbose("up to dimension %s" % i) for pro in profiles: - milnor_dim = len(steenrod_algebra_basis.f(i,'milnor',p=p,profile=pro,generic=generic)) + milnor_dim = len(steenrod_algebra_basis.f(i, 'milnor', p=p, + profile=pro, + generic=generic)) for B in bases: - if milnor_dim != len(steenrod_algebra_basis.f(i,B,p,profile=pro,generic=generic)): + if milnor_dim != len(steenrod_algebra_basis.f(i, B, p, + profile=pro, + generic=generic)): print("problem with milnor/%s in dimension %s with profile %s" % (B, i, pro)) verbose("done checking with profiles") diff --git a/src/sage/algebras/steenrod/steenrod_algebra_misc.py b/src/sage/algebras/steenrod/steenrod_algebra_misc.py index b3d77dfce18..dbe3afe0525 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra_misc.py +++ b/src/sage/algebras/steenrod/steenrod_algebra_misc.py @@ -260,16 +260,16 @@ def is_valid_profile(profile, truncation_type, p=2, generic=None): pro = list(profile) + [truncation_type]*len(profile) r = 0 for pro_r in pro: - r += 1 # index of pro_r + r += 1 # index of pro_r if pro_r < Infinity: - for i in range(1,r): + for i in range(1, r): if pro_r < min(pro[r-i-1] - i, pro[i-1]): return False else: # p odd: e = list(profile[0]) + [truncation_type]*len(profile[0]) k = list(profile[1]) - if not set(k).issubset({1,2}): + if not set(k).issubset({1, 2}): return False if truncation_type > 0: k = k + [2] @@ -279,14 +279,14 @@ def is_valid_profile(profile, truncation_type, p=2, generic=None): e = e + [truncation_type] * (len(k) - len(e)) r = 0 for e_r in e: - r += 1 # index of e_r + r += 1 # index of e_r if e_r < Infinity: - for i in range(1,r): + for i in range(1, r): if e_r < min(e[r-i-1] - i, e[i-1]): return False r = -1 for k_r in k: - r += 1 # index of k_r + r += 1 # index of k_r if k_r == 1: for j in range(r): i = r-j @@ -501,13 +501,13 @@ def normalize_profile(profile, precision=None, truncation_type='auto', p=2, gene return new_profile, truncation_type else: raise ValueError("invalid profile") - else: # p odd + else: # p odd if profile is None or profile == Infinity: # no specified profile or infinite profile: return profile # for the entire Steenrod algebra new_profile = ((), ()) truncation_type = Infinity - else: # profile should be a list or tuple of length 2 + else: # profile should be a list or tuple of length 2 assert isinstance(profile, (list, tuple)) and len(profile) == 2, \ "Invalid form for profile" e = profile[0] @@ -697,26 +697,26 @@ def serre_cartan_mono_to_string(mono, latex=False, generic=False): P = "P" if len(mono) == 0 or mono == (0,): return "1" + + if not generic: + string = "" + for n in mono: + string = string + sq + "^{" + str(n) + "} " else: - if not generic: - string = "" - for n in mono: - string = string + sq + "^{" + str(n) + "} " - else: - string = "" - index = 0 - for n in mono: - from sage.misc.functional import is_even - if is_even(index): - if n == 1: - if latex: - string = string + "\\beta " - else: - string = string + "beta " - else: - string = string + P + "^{" + str(n) + "} " - index += 1 - return string.strip(" ") + string = "" + index = 0 + for n in mono: + from sage.misc.functional import is_even + if is_even(index): + if n == 1: + if latex: + string = string + "\\beta " + else: + string = string + "beta " + else: + string = string + P + "^{" + str(n) + "} " + index += 1 + return string.strip(" ") def wood_mono_to_string(mono, latex=False): @@ -756,12 +756,10 @@ def wood_mono_to_string(mono, latex=False): sq = "Sq" if len(mono) == 0: return "1" - else: - string = "" - for (s,t) in mono: - string = string + sq + "^{" + \ - str(2**s * (2**(t+1)-1)) + "} " - return string.strip(" ") + string = "" + for s, t in mono: + string = string + sq + "^{" + str(2**s * (2**(t+1)-1)) + "} " + return string.strip(" ") def wall_mono_to_string(mono, latex=False): @@ -797,12 +795,10 @@ def wall_mono_to_string(mono, latex=False): """ if len(mono) == 0: return "1" - else: - string = "" - for (m,k) in mono: - string = string + "Q^{" + str(m) + "}_{" \ - + str(k) + "} " - return string.strip(" ") + string = "" + for m, k in mono: + string = string + "Q^{" + str(m) + "}_{" + str(k) + "} " + return string.strip(" ") def wall_long_mono_to_string(mono, latex=False): @@ -842,12 +838,11 @@ def wall_long_mono_to_string(mono, latex=False): sq = "Sq" if len(mono) == 0: return "1" - else: - string = "" - for (m,k) in mono: - for i in range(k,m+1): - string = string + sq + "^{" + str(2**i) + "} " - return string.strip(" ") + string = "" + for m, k in mono: + for i in range(k, m + 1): + string = string + sq + "^{" + str(2**i) + "} " + return string.strip(" ") def arnonA_mono_to_string(mono, latex=False, p=2): @@ -882,12 +877,10 @@ def arnonA_mono_to_string(mono, latex=False, p=2): """ if len(mono) == 0: return "1" - else: - string = "" - for (m,k) in mono: - string = string + "X^{" + str(m) + "}_{" \ - + str(k) + "} " - return string.strip(" ") + string = "" + for m, k in mono: + string = string + "X^{" + str(m) + "}_{" + str(k) + "} " + return string.strip(" ") def arnonA_long_mono_to_string(mono, latex=False, p=2): @@ -927,12 +920,11 @@ def arnonA_long_mono_to_string(mono, latex=False, p=2): sq = "Sq" if len(mono) == 0: return "1" - else: - string = "" - for (m,k) in mono: - for i in range(m,k-1,-1): - string = string + sq + "^{" + str(2**i) + "} " - return string.strip(" ") + string = "" + for m, k in mono: + for i in range(m, k - 1, -1): + string = string + sq + "^{" + str(2**i) + "} " + return string.strip(" ") def pst_mono_to_string(mono, latex=False, generic=False): @@ -975,27 +967,27 @@ def pst_mono_to_string(mono, latex=False, generic=False): """ if len(mono) == 0: return "1" + + string = "" + if not generic: + for s, t in mono: + string = string + "P^{" + str(s) + "}_{" \ + + str(t) + "} " else: - string = "" - if not generic: - for (s,t) in mono: + for e in mono[0]: + string = string + "Q_{" + str(e) + "} " + for (s, t), n in mono[1]: + if n == 1: string = string + "P^{" + str(s) + "}_{" \ + str(t) + "} " - else: - for e in mono[0]: - string = string + "Q_{" + str(e) + "} " - for ((s,t), n) in mono[1]: - if n == 1: - string = string + "P^{" + str(s) + "}_{" \ - + str(t) + "} " + else: + if latex: + pow = "{%s}" % n else: - if latex: - pow = "{%s}" % n - else: - pow = str(n) - string = string + "(P^{" + str(s) + "}_{" \ - + str(t) + "})^" + pow + " " - return string.strip(" ") + pow = str(n) + string = string + "(P^{" + str(s) + "}_{" \ + + str(t) + "})^" + pow + " " + return string.strip(" ") def comm_mono_to_string(mono, latex=False, generic=False): @@ -1038,26 +1030,26 @@ def comm_mono_to_string(mono, latex=False, generic=False): """ if len(mono) == 0: return "1" + + string = "" + if not generic: + for s, t in mono: + string = string + "c_{" + str(s) + "," \ + + str(t) + "} " else: - string = "" - if not generic: - for (s,t) in mono: - string = string + "c_{" + str(s) + "," \ - + str(t) + "} " - else: - for e in mono[0]: - string = string + "Q_{" + str(e) + "} " - for ((s,t), n) in mono[1]: - string = string + "c_{" + str(s) + "," \ - + str(t) + "}" - if n > 1: - if latex: - pow = "^{%s}" % n - else: - pow = "^%s" % n - string = string + pow - string = string + " " - return string.strip(" ") + for e in mono[0]: + string = string + "Q_{" + str(e) + "} " + for (s, t), n in mono[1]: + string = string + "c_{" + str(s) + "," \ + + str(t) + "}" + if n > 1: + if latex: + pow = "^{%s}" % n + else: + pow = "^%s" % n + string = string + pow + string = string + " " + return string.strip(" ") def comm_long_mono_to_string(mono, p, latex=False, generic=False): @@ -1101,34 +1093,34 @@ def comm_long_mono_to_string(mono, p, latex=False, generic=False): """ if len(mono) == 0: return "1" + + string = "" + if not generic: + for s, t in mono: + if s + t > 4: + comma = "," + else: + comma = "" + string = string + "s_{" + for i in range(t): + string = string + str(2**(s+i)) + comma + string = string.strip(",") + "} " else: - string = "" - if not generic: - for (s,t) in mono: - if s + t > 4: - comma = "," + for e in mono[0]: + string = string + "Q_{" + str(e) + "} " + for (s, t), n in mono[1]: + string = string + "s_{" + for i in range(t): + string = string + str(p**(s+i)) + "," + string = string.strip(",") + "}" + if n > 1: + if latex: + pow = "^{%s}" % n else: - comma = "" - string = string + "s_{" - for i in range(t): - string = string + str(2**(s+i)) + comma - string = string.strip(",") + "} " - else: - for e in mono[0]: - string = string + "Q_{" + str(e) + "} " - for ((s,t), n) in mono[1]: - string = string + "s_{" - for i in range(t): - string = string + str(p**(s+i)) + "," - string = string.strip(",") + "}" - if n > 1: - if latex: - pow = "^{%s}" % n - else: - pow = "^%s" % n - string = string + pow - string = string + " " - return string.strip(" ") + pow = "^%s" % n + string = string + pow + string = string + " " + return string.strip(" ") # miscellany: @@ -1162,5 +1154,5 @@ def convert_perm(m): sage: sage.algebras.steenrod.steenrod_algebra_misc.convert_perm((5,0,6,3)) [3, 1, 4, 2] """ - m2 = sorted(m) - return [list(m2).index(x)+1 for x in m] + d = {x: i for i, x in enumerate(sorted(m), start=1)} + return [d[x] for x in m] diff --git a/src/sage/algebras/steenrod/steenrod_algebra_mult.py b/src/sage/algebras/steenrod/steenrod_algebra_mult.py index f3569521b77..4198521dfab 100644 --- a/src/sage/algebras/steenrod/steenrod_algebra_mult.py +++ b/src/sage/algebras/steenrod/steenrod_algebra_mult.py @@ -255,11 +255,11 @@ def milnor_multiplication(r, s): M = list(range(rows)) for i in range(rows): M[i] = [0]*cols - for j in range(1,cols): + for j in range(1, cols): M[0][j] = s[j-1] - for i in range(1,rows): + for i in range(1, rows): M[i][0] = r[i-1] - for j in range(1,cols): + for j in range(1, cols): M[i][j] = 0 found = True while found: @@ -268,7 +268,8 @@ def milnor_multiplication(r, s): okay = 1 diagonal = [0]*diags while n <= diags and okay is not None: - nth_diagonal = [M[i][n-i] for i in range(max(0,n-cols+1), min(1+n,rows))] + nth_diagonal = [M[i][n-i] + for i in range(max(0, n-cols+1), min(1+n, rows))] okay = multinomial(nth_diagonal) diagonal[n-1] = okay n = n + 1 @@ -298,12 +299,12 @@ def milnor_multiplication(r, s): temp_col_sum += M[k][j] if temp_col_sum != 0: found = True - for row in range(1,i): + for row in range(1, i): M[row][0] = r[row-1] - for col in range(1,cols): + for col in range(1, cols): M[0][col] = M[0][col] + M[row][col] M[row][col] = 0 - for col in range(1,j): + for col in range(1, j): M[0][col] = M[0][col] + M[i][col] M[i][col] = 0 M[0][j] = M[0][j] - 1 @@ -441,7 +442,7 @@ def milnor_multiplication_odd(m1, m2, p): """ from sage.rings.finite_rings.finite_field_constructor import GF F = GF(p) - (f,s) = m2 + f, s = m2 # First compute Q_e0 Q_e1 ... P(r1, r2, ...) Q_f0 Q_f1 ... # Store results (as dictionary of pairs of tuples) in 'answer'. answer = {m1: F(1)} @@ -452,7 +453,7 @@ def milnor_multiplication_odd(m1, m2, p): if k not in mono[0]: q_mono = set(mono[0]) if q_mono: - ind = len(q_mono.intersection(range(k,1+max(q_mono)))) + ind = len(q_mono.intersection(range(k, 1+max(q_mono)))) else: ind = 0 coeff = (-1)**ind * old_answer[mono] @@ -460,15 +461,15 @@ def milnor_multiplication_odd(m1, m2, p): if ind == 0: lst.append(k) else: - lst.insert(-ind,k) + lst.insert(-ind, k) q_mono = tuple(lst) p_mono = mono[1] answer[(q_mono, p_mono)] = F(coeff) - for i in range(1,1+len(mono[1])): + for i in range(1, 1+len(mono[1])): if (k+i not in mono[0]) and (p**k <= mono[1][i-1]): q_mono = set(mono[0]) if q_mono: - ind = len(q_mono.intersection(range(k+i,1+max(q_mono)))) + ind = len(q_mono.intersection(range(k+i, 1+max(q_mono)))) else: ind = 0 coeff = (-1)**ind * old_answer[mono] @@ -476,7 +477,7 @@ def milnor_multiplication_odd(m1, m2, p): if ind == 0: lst.append(k+i) else: - lst.insert(-ind,k+i) + lst.insert(-ind, k+i) q_mono = tuple(lst) p_mono = list(mono[1]) p_mono[i-1] = p_mono[i-1] - p**k @@ -496,8 +497,8 @@ def milnor_multiplication_odd(m1, m2, p): result = answer else: result = {} - for (e, r) in answer: - old_coeff = answer[(e,r)] + for e, r in answer: + old_coeff = answer[(e, r)] # Milnor multiplication for r and s rows = len(r) + 1 cols = len(s) + 1 @@ -506,11 +507,11 @@ def milnor_multiplication_odd(m1, m2, p): M = list(range(rows)) for i in range(rows): M[i] = [0]*cols - for j in range(1,cols): + for j in range(1, cols): M[0][j] = s[j-1] - for i in range(1,rows): + for i in range(1, rows): M[i][0] = r[i-1] - for j in range(1,cols): + for j in range(1, cols): M[i][j] = 0 found = True while found: @@ -519,8 +520,8 @@ def milnor_multiplication_odd(m1, m2, p): coeff = old_coeff diagonal = [0]*diags while n <= diags and coeff != 0: - nth_diagonal = [M[i][n-i] for i in range(max(0,n-cols+1), min(1+n,rows))] - coeff = coeff * multinomial_odd(nth_diagonal,p) + nth_diagonal = [M[i][n-i] for i in range(max(0, n-cols+1), min(1+n, rows))] + coeff = coeff * multinomial_odd(nth_diagonal, p) diagonal[n-1] = sum(nth_diagonal) n = n + 1 if F(coeff) != 0: @@ -528,10 +529,10 @@ def milnor_multiplication_odd(m1, m2, p): while i >= 0 and diagonal[i] == 0: i = i - 1 t = tuple(diagonal[:i+1]) - if (e,t) in result: - result[(e,t)] = F(coeff + result[(e,t)]) + if (e, t) in result: + result[(e, t)] = F(coeff + result[(e, t)]) else: - result[(e,t)] = F(coeff) + result[(e, t)] = F(coeff) # now look for new matrices: found = False i = 1 @@ -548,12 +549,12 @@ def milnor_multiplication_odd(m1, m2, p): temp_col_sum += M[k][j] if temp_col_sum != 0: found = True - for row in range(1,i): + for row in range(1, i): M[row][0] = r[row-1] - for col in range(1,cols): + for col in range(1, cols): M[0][col] = M[0][col] + M[row][col] M[row][col] = 0 - for col in range(1,j): + for col in range(1, j): M[0][col] = M[0][col] + M[i][col] M[i][col] = 0 M[0][j] = M[0][j] - 1 @@ -773,14 +774,14 @@ def adem(a, b, c=0, p=2, generic=None): elif a == 0: return {(b,): 1} elif a >= 2*b: - return {(a,b): 1} + return {(a, b): 1} result = {} for c in range(1 + a//2): if binomial_mod2(b-c-1, a-2*c) == 1: if c == 0: result[(a+b,)] = 1 else: - result[(a+b-c,c)] = 1 + result[(a+b-c, c)] = 1 return result # p odd if a == 0 and b == 0: @@ -792,40 +793,40 @@ def adem(a, b, c=0, p=2, generic=None): else: A = a B = c - bockstein = b # should be 0 or 1 + bockstein = b # should be 0 or 1 if A == 0: return {(bockstein, B, 0): 1} if B == 0: return {(0, A, bockstein): 1} if bockstein == 0: - if A >= p*B: # admissible - return {(0,A,0,B,0): 1} + if A >= p*B: # admissible + return {(0, A, 0, B, 0): 1} result = {} for j in range(1 + a//p): coeff = (-1)**(A+j) * binomial_modp((B-j) * (p-1) - 1, A - p*j, p) if coeff % p != 0: if j == 0: - result[(0,A+B,0)] = coeff + result[(0, A+B, 0)] = coeff else: - result[(0,A+B-j,0,j,0)] = coeff + result[(0, A+B-j, 0, j, 0)] = coeff else: - if A >= p*B + 1: # admissible - return {(0,A,1,B,0): 1} + if A >= p*B + 1: # admissible + return {(0, A, 1, B, 0): 1} result = {} for j in range(1 + a//p): coeff = (-1)**(A+j) * binomial_modp((B-j) * (p-1), A - p*j, p) if coeff % p != 0: if j == 0: - result[(1,A+B,0)] = coeff + result[(1, A+B, 0)] = coeff else: - result[(1,A+B-j,0,j,0)] = coeff + result[(1, A+B-j, 0, j, 0)] = coeff for j in range(1 + (a-1)//p): coeff = (-1)**(A+j-1) * binomial_modp((B-j) * (p-1) - 1, A - p*j - 1, p) if coeff % p != 0: if j == 0: - result[(0,A+B,1)] = coeff + result[(0, A+B, 1)] = coeff else: - result[(0,A+B-j,1,j,0)] = coeff + result[(0, A+B-j, 1, j, 0)] = coeff return result