From 7572f1485a042e8c442f39b88ece778c39e9439c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 20 Mar 2023 20:59:55 +0100 Subject: [PATCH 1/4] fix E502 in schemes and combinat --- .../combinat/designs/difference_family.py | 8 +- .../finite_state_machine_generators.py | 4 +- src/sage/combinat/gelfand_tsetlin_patterns.py | 4 +- src/sage/combinat/integer_vector.py | 5 +- .../multiset_partition_into_sets_ordered.py | 4 +- .../combinat/ncsf_qsym/generic_basis_code.py | 11 +- .../tensor_product_kr_tableaux.py | 6 +- .../root_system/root_lattice_realizations.py | 11 +- src/sage/combinat/sf/sfa.py | 20 +-- src/sage/combinat/words/paths.py | 8 +- src/sage/combinat/words/suffix_trees.py | 9 +- src/sage/combinat/words/word_generators.py | 7 +- src/sage/schemes/affine/affine_morphism.py | 9 +- src/sage/schemes/affine/affine_space.py | 6 +- src/sage/schemes/berkovich/berkovich_space.py | 24 ++-- src/sage/schemes/curves/affine_curve.py | 14 +- src/sage/schemes/curves/projective_curve.py | 12 +- src/sage/schemes/elliptic_curves/ell_egros.py | 8 +- .../elliptic_curves/ell_rational_field.py | 8 +- .../schemes/elliptic_curves/mod5family.py | 14 +- src/sage/schemes/elliptic_curves/padics.py | 4 +- src/sage/schemes/generic/point.py | 7 +- .../hyperelliptic_finite_field.py | 6 +- .../schemes/hyperelliptic_curves/mestre.py | 22 ++-- .../product_projective/rational_point.py | 7 +- .../schemes/projective/projective_morphism.py | 121 +++++++++--------- 26 files changed, 184 insertions(+), 175 deletions(-) diff --git a/src/sage/combinat/designs/difference_family.py b/src/sage/combinat/designs/difference_family.py index 95c9104e4b3..31a7105d1a7 100644 --- a/src/sage/combinat/designs/difference_family.py +++ b/src/sage/combinat/designs/difference_family.py @@ -594,8 +594,8 @@ def radical_difference_set(K, k, l=1, existence=False, check=True): x = K.multiplicative_generator() D = K.cyclotomic_cosets(x**((v-1)//k), [K.one()]) if is_difference_family(K, D, v, k, l): - print("** You found a new example of radical difference set **\n"\ - "** for the parameters (v,k,l)=({},{},{}). **\n"\ + print("** You found a new example of radical difference set **\n" + "** for the parameters (v,k,l)=({},{},{}). **\n" "** Please contact sage-devel@googlegroups.com **\n".format(v, k, l)) if existence: return True @@ -605,8 +605,8 @@ def radical_difference_set(K, k, l=1, existence=False, check=True): D = K.cyclotomic_cosets(x**((v-1)//(k-1)), [K.one()]) D[0].insert(0,K.zero()) if is_difference_family(K, D, v, k, l): - print("** You found a new example of radical difference set **\n"\ - "** for the parameters (v,k,l)=({},{},{}). **\n"\ + print("** You found a new example of radical difference set **\n" + "** for the parameters (v,k,l)=({},{},{}). **\n" "** Please contact sage-devel@googlegroups.com **\n".format(v, k, l)) if existence: return True diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index 4a5a875796b..385e35e14c9 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -1989,8 +1989,8 @@ def f(n): cycle[1:]) required_initial_values.update(intersection) output_sum = sum([edge[2] - for edge in recursion_digraph.\ - outgoing_edge_iterator(cycle[1:])], + for edge in recursion_digraph. + outgoing_edge_iterator(cycle[1:])], []) if not is_zero(output_sum): raise ValueError( diff --git a/src/sage/combinat/gelfand_tsetlin_patterns.py b/src/sage/combinat/gelfand_tsetlin_patterns.py index eda712ded06..76583cd8fea 100644 --- a/src/sage/combinat/gelfand_tsetlin_patterns.py +++ b/src/sage/combinat/gelfand_tsetlin_patterns.py @@ -994,7 +994,7 @@ def _row_iter(self, upper_row): [2, 0] [2, 1] """ - row = [x-1 for x in upper_row[1:]] + row = [x - 1 for x in upper_row[1:]] row_len = len(row) pos = 0 while pos >= 0: @@ -1003,7 +1003,7 @@ def _row_iter(self, upper_row): pos -= 1 continue # If it would create an invalid entry, backstep - if ( pos > 0 and (row[pos] >= row[pos-1] \ + if ( pos > 0 and (row[pos] >= row[pos-1] or (self._strict and row[pos] == row[pos-1]-1)) ) \ or row[pos] >= upper_row[pos] \ or (self._k is not None and row[pos] >= self._k): diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 94a5010f445..37c1d1b9de3 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -1416,8 +1416,9 @@ def cardinality(self): return Integer(binomial(self.n + self.k - 1, self.n)) # do by inclusion / exclusion on the number # i of parts greater than m - return Integer(sum( (-1)**i * binomial(self.n+self.k-1-i*(m+1), self.k-1) \ - * binomial(self.k,i) for i in range(self.n/(m+1)+1) )) + return Integer(sum((-1)**i * binomial(self.n+self.k-1-i*(m+1), self.k-1) + * binomial(self.k, i) + for i in range(self.n / (m + 1) + 1))) return ZZ.sum(ZZ.one() for x in self) def __iter__(self): diff --git a/src/sage/combinat/multiset_partition_into_sets_ordered.py b/src/sage/combinat/multiset_partition_into_sets_ordered.py index 283926a2c87..462b52cd447 100755 --- a/src/sage/combinat/multiset_partition_into_sets_ordered.py +++ b/src/sage/combinat/multiset_partition_into_sets_ordered.py @@ -2787,8 +2787,8 @@ def _base_iterator(constraints): if min_ord: min_k = max(1, min_k, min_ord // len(A)) if infinity not in (max_k, max_ord): - return chain(*(_iterator_order(A, ord, range(min_k, max_k+1)) \ - for ord in range(min_ord, max_ord+1))) + return chain(*(_iterator_order(A, ord, range(min_k, max_k + 1)) + for ord in range(min_ord, max_ord + 1))) # else return None diff --git a/src/sage/combinat/ncsf_qsym/generic_basis_code.py b/src/sage/combinat/ncsf_qsym/generic_basis_code.py index 270a79e1a46..0f2b819457f 100644 --- a/src/sage/combinat/ncsf_qsym/generic_basis_code.py +++ b/src/sage/combinat/ncsf_qsym/generic_basis_code.py @@ -472,8 +472,9 @@ def skew(self, x, y, side='left'): x = self(x) y = self.dual()(y) v = 1 if side == 'left' else 0 - return self.sum(coeff * y[IJ[1-v]] * self[IJ[v]] \ - for (IJ, coeff) in x.coproduct() if IJ[1-v] in y.support()) + return self.sum(coeff * y[IJ[1-v]] * self[IJ[v]] + for (IJ, coeff) in x.coproduct() + if IJ[1-v] in y.support()) else: return self._skew_by_coercion(x, y, side=side) @@ -710,9 +711,9 @@ def duality_pairing_matrix(self, basis, degree): # TODO: generalize to keys indexing the basis of the graded component from sage.combinat.composition import Compositions return matrix(self.base_ring(), - [[self.duality_pairing(self[I], basis[J]) \ - for J in Compositions(degree)] \ - for I in Compositions(degree)]) + [[self.duality_pairing(self[I], basis[J]) + for J in Compositions(degree)] + for I in Compositions(degree)]) def counit_on_basis(self, I): r""" diff --git a/src/sage/combinat/rigged_configurations/tensor_product_kr_tableaux.py b/src/sage/combinat/rigged_configurations/tensor_product_kr_tableaux.py index 7f66de8c32d..74d923e0fd9 100644 --- a/src/sage/combinat/rigged_configurations/tensor_product_kr_tableaux.py +++ b/src/sage/combinat/rigged_configurations/tensor_product_kr_tableaux.py @@ -320,12 +320,12 @@ def __init__(self, cartan_type, B): FullTensorProductOfRegularCrystals.__init__(self, tensor_prod, cartan_type=cartan_type) # This is needed to override the module_generators set in FullTensorProductOfRegularCrystals self.module_generators = HighestWeightTensorKRT(self) - self.rename("Tensor product of Kirillov-Reshetikhin tableaux of type %s and factor(s) %s"%(\ - cartan_type, B)) + self.rename("Tensor product of Kirillov-Reshetikhin tableaux " + f"of type {cartan_type} and factor(s) {B}") def __iter__(self): """ - Returns the iterator of ``self``. + Return the iterator of ``self``. EXAMPLES:: diff --git a/src/sage/combinat/root_system/root_lattice_realizations.py b/src/sage/combinat/root_system/root_lattice_realizations.py index fb63471ffb0..64bb150b109 100644 --- a/src/sage/combinat/root_system/root_lattice_realizations.py +++ b/src/sage/combinat/root_system/root_lattice_realizations.py @@ -464,7 +464,7 @@ def simple_roots(self): @cached_method def alpha(self): r""" - Returns the family `(\alpha_i)_{i\in I}` of the simple roots, + Return the family `(\alpha_i)_{i\in I}` of the simple roots, with the extra feature that, for simple irreducible root systems, `\alpha_0` yields the opposite of the highest root. @@ -475,13 +475,12 @@ def alpha(self): alpha[1] sage: alpha[0] -alpha[1] - alpha[2] - """ if self.root_system.is_finite() and self.root_system.is_irreducible(): - return Family(self.index_set(), self.simple_root, \ - hidden_keys = [0], hidden_function = lambda i: - self.highest_root()) - else: - return self.simple_roots() + return Family(self.index_set(), self.simple_root, + hidden_keys=[0], + hidden_function=lambda i: - self.highest_root()) + return self.simple_roots() @cached_method def basic_imaginary_roots(self): diff --git a/src/sage/combinat/sf/sfa.py b/src/sage/combinat/sf/sfa.py index a833b1f5d81..7a69c18eef5 100644 --- a/src/sage/combinat/sf/sfa.py +++ b/src/sage/combinat/sf/sfa.py @@ -2090,19 +2090,20 @@ def _from_cache(self, element, cache_function, cache_dict, **subs_dict): # needed for the old kschur functions - TCS part = _Partitions(part) for part2, c2 in cache_dict[sum(part)][part].items(): - if hasattr(c2,'subs'): # c3 may be in the base ring - c3 = c*BR(c2.subs(**subs_dict)) + if hasattr(c2, 'subs'): # c3 may be in the base ring + c3 = c * BR(c2.subs(**subs_dict)) else: - c3 = c*BR(c2) + c3 = c * BR(c2) # c3 = c*c2 # if hasattr(c3,'subs'): # c3 may be in the base ring # c3 = c3.subs(**subs_dict) - z_elt[ part2 ] = z_elt.get(part2, zero) + BR(c3) + z_elt[part2] = z_elt.get(part2, zero) + BR(c3) return self._from_dict(z_elt) - def _invert_morphism(self, n, base_ring, self_to_other_cache, other_to_self_cache,\ - to_other_function=None, to_self_function=None, \ - upper_triangular=False, lower_triangular=False, \ + def _invert_morphism(self, n, base_ring, + self_to_other_cache, other_to_self_cache, + to_other_function=None, to_self_function=None, + upper_triangular=False, lower_triangular=False, ones_on_diagonal=False): r""" Compute the inverse of a morphism between ``self`` and ``other`` @@ -5979,8 +5980,9 @@ def character_to_frobenius_image(self, n): 2*s[2, 2, 1] + s[3, 1, 1] + 4*s[3, 2] + 3*s[4, 1] + 2*s[5] """ p = self.parent().symmetric_function_ring().p() - return self.parent()(p.sum(self.eval_at_permutation_roots(rho) \ - *p(rho)/rho.centralizer_size() for rho in Partitions(n))) + return self.parent()(p.sum(self.eval_at_permutation_roots(rho) + * p(rho) / rho.centralizer_size() + for rho in Partitions(n))) def principal_specialization(self, n=infinity, q=None): r""" diff --git a/src/sage/combinat/words/paths.py b/src/sage/combinat/words/paths.py index 0c8dbb324a3..40f56e62891 100644 --- a/src/sage/combinat/words/paths.py +++ b/src/sage/combinat/words/paths.py @@ -455,10 +455,10 @@ def __eq__(self, other): sage: W1 == W3 False """ - return self is other or (type(self) == type(other) and \ - self.alphabet() == other.alphabet() and \ - self.vector_space() == other.vector_space() and \ - self.letters_to_steps() == other.letters_to_steps()) + return self is other or (type(self) == type(other) and + self.alphabet() == other.alphabet() and + self.vector_space() == other.vector_space() and + self.letters_to_steps() == other.letters_to_steps()) def __ne__(self, other): r""" diff --git a/src/sage/combinat/words/suffix_trees.py b/src/sage/combinat/words/suffix_trees.py index a0e4727a1c0..9815645fbf8 100644 --- a/src/sage/combinat/words/suffix_trees.py +++ b/src/sage/combinat/words/suffix_trees.py @@ -286,14 +286,13 @@ def transition_function(self, node, word): if word.is_empty(): return 0 if word.length() == 1: - return self._transition_function[(node,word)] - else: - return self.transition_function( \ - self._transition_function[(node,word[0:1])], word[1:]) + return self._transition_function[(node, word)] + return self.transition_function( + self._transition_function[(node, word[0:1])], word[1:]) def states(self): r""" - Returns the states of the automaton defined by the suffix trie. + Return the states of the automaton defined by the suffix trie. EXAMPLES:: diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index 66c5f25eda7..b046273b7e5 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -1276,10 +1276,9 @@ def StandardEpisturmianWord(self, directive_word): """ if not isinstance(directive_word, Word_class): raise TypeError("directive_word is not a word, so it cannot be used to build an episturmian word") - epistandard = directive_word.parent()(\ - self._StandardEpisturmianWord_LetterIterator(directive_word), - datatype='iter') - return epistandard + return directive_word.parent()( + self._StandardEpisturmianWord_LetterIterator(directive_word), + datatype='iter') def _StandardEpisturmianWord_LetterIterator(self, directive_word): r""" diff --git a/src/sage/schemes/affine/affine_morphism.py b/src/sage/schemes/affine/affine_morphism.py index b61b011f979..df4cb2a1d9d 100644 --- a/src/sage/schemes/affine/affine_morphism.py +++ b/src/sage/schemes/affine/affine_morphism.py @@ -385,9 +385,12 @@ def _fastpolys(self): if self._is_prime_finite_field: prime = polys[0].base_ring().characteristic() degree = max(poly_numerator.degree(), poly_denominator.degree()) - height = max([abs(c.lift()) for c in poly_numerator.coefficients()]\ - + [abs(c.lift()) for c in poly_denominator.coefficients()]) - num_terms = max(len(poly_numerator.coefficients()), len(poly_denominator.coefficients())) + height = max([abs(c.lift()) + for c in poly_numerator.coefficients()] + + [abs(c.lift()) + for c in poly_denominator.coefficients()]) + num_terms = max(len(poly_numerator.coefficients()), + len(poly_denominator.coefficients())) largest_value = num_terms * height * (prime - 1) ** degree # If the calculations will not overflow the float data type use domain float # Else use domain integer diff --git a/src/sage/schemes/affine/affine_space.py b/src/sage/schemes/affine/affine_space.py index 52c13b29068..b38a3411899 100644 --- a/src/sage/schemes/affine/affine_space.py +++ b/src/sage/schemes/affine/affine_space.py @@ -598,10 +598,10 @@ def __mul__(self, right): if isinstance(right, AffineSpace_generic): if self is right: return self.__pow__(2) - return AffineSpace(self.dimension_relative() + right.dimension_relative(),\ + return AffineSpace(self.dimension_relative() + right.dimension_relative(), self.base_ring(), self.variable_names() + right.variable_names()) elif isinstance(right, AlgebraicScheme_subscheme): - AS = self*right.ambient_space() + AS = self * right.ambient_space() CR = AS.coordinate_ring() n = self.ambient_space().coordinate_ring().ngens() @@ -609,7 +609,7 @@ def __mul__(self, right): psi = right.ambient_space().coordinate_ring().hom(list(CR.gens()[n:]), CR) return AS.subscheme([phi(t) for t in self.defining_polynomials()] + [psi(t) for t in right.defining_polynomials()]) else: - raise TypeError('%s must be an affine space or affine subscheme'%right) + raise TypeError('%s must be an affine space or affine subscheme' % right) def change_ring(self, R): r""" diff --git a/src/sage/schemes/berkovich/berkovich_space.py b/src/sage/schemes/berkovich/berkovich_space.py index 17eee57dd0a..5900fafbcc8 100644 --- a/src/sage/schemes/berkovich/berkovich_space.py +++ b/src/sage/schemes/berkovich/berkovich_space.py @@ -430,8 +430,8 @@ def __init__(self, base, ideal=None): if not isinstance(ideal, NumberFieldFractionalIdeal): raise ValueError('ideal was not an ideal of a number field') if ideal.number_field() != base: - raise ValueError('passed number field ' + \ - '%s but ideal was an ideal of %s' %(base, ideal.number_field())) + raise ValueError('passed number field ' + + '%s but ideal was an ideal of %s' % (base, ideal.number_field())) prime = ideal.smallest_integer() else: if ideal not in QQ: @@ -445,8 +445,8 @@ def __init__(self, base, ideal=None): ideal = None self._base_type = 'padic field' else: - raise ValueError("base of Berkovich Space must be a padic field " + \ - "or a number field") + raise ValueError("base of Berkovich Space must be a padic field " + "or a number field") self._ideal = ideal self._p = prime Parent.__init__(self, base=base, category=TopologicalSpaces()) @@ -471,10 +471,10 @@ def _repr_(self): in a with defining polynomial z^2 + 1 """ if self._base_type == 'padic field': - return "Affine Berkovich line over Cp(%s) of precision %s" %(self.prime(),\ + return "Affine Berkovich line over Cp(%s) of precision %s" % (self.prime(), self.base().precision_cap()) else: - return "Affine Berkovich line over Cp(%s), with base %s" %(self.prime(),\ + return "Affine Berkovich line over Cp(%s), with base %s" % (self.prime(), self.base()) def _latex_(self): @@ -623,8 +623,8 @@ def __init__(self, base, ideal=None): raise ValueError("base of projective Berkovich space must be projective space") if not isinstance(base.base_ring(), sage.rings.abc.pAdicField): if base.base_ring() not in NumberFields(): - raise ValueError("base of projective Berkovich space must be " + \ - "projective space over Qp or a number field") + raise ValueError("base of projective Berkovich space must be " + "projective space over Qp or a number field") else: if ideal is None: raise ValueError('passed a number field but not an ideal') @@ -632,8 +632,8 @@ def __init__(self, base, ideal=None): if not isinstance(ideal, NumberFieldFractionalIdeal): raise ValueError('ideal was not a number field ideal') if ideal.number_field() != base.base_ring(): - raise ValueError('passed number field ' + \ - '%s but ideal was an ideal of %s' %(base.base_ring(), ideal.number_field())) + raise ValueError('passed number field ' + + '%s but ideal was an ideal of %s' % (base.base_ring(), ideal.number_field())) prime = ideal.smallest_integer() else: if ideal not in QQ: @@ -701,10 +701,10 @@ def _repr_(self): Projective Berkovich line over Cp(2), with base Number Field in a with defining polynomial x^2 + 1 """ if self._base_type == 'padic field': - return "Projective Berkovich line over Cp(%s) of precision %s" %(self.prime(),\ + return "Projective Berkovich line over Cp(%s) of precision %s" % (self.prime(), self.base().base_ring().precision_cap()) else: - return "Projective Berkovich line over Cp(%s), with base %s" %(self.prime(),\ + return "Projective Berkovich line over Cp(%s), with base %s" % (self.prime(), self.base().base_ring()) def _latex_(self): diff --git a/src/sage/schemes/curves/affine_curve.py b/src/sage/schemes/curves/affine_curve.py index a329e927d51..3f963d08698 100644 --- a/src/sage/schemes/curves/affine_curve.py +++ b/src/sage/schemes/curves/affine_curve.py @@ -993,7 +993,8 @@ def projection(self, indices, AS=None): indices = [int(i) for i in indices] # type checking indices.sort() if indices[0] < 0 or indices[-1] > n - 1: - raise ValueError("index values must be between 0 and one minus the dimension of the ambient space " \ + raise ValueError("index values must be between 0 and one " + "minus the dimension of the ambient space " "of this curve") # construct the projection map if AS is None: @@ -1512,8 +1513,9 @@ def extension(self): if C.is_smooth(): raise TypeError("this curve is already nonsingular") else: - raise TypeError("this curve has no singular points over its base field. If working over"\ - " a number field use extend=True") + raise TypeError("this curve has no singular points over " + "its base field. If working over " + "a number field use extend=True") not_resolved = True t = 0 # loop through the patches and blow up each until no patch has singular points @@ -1588,8 +1590,8 @@ def extension(self): b_data = [B[0][i]] # projection map and its inverse t_pi = B[2][i] - coords = [(BC.ambient_space().gens()[j] - pts[0][j])/(BC.ambient_space().gens()[i] - pts[0][i]) for\ - j in range(n)] + coords = [(BC.ambient_space().gens()[j] - pts[0][j]) / (BC.ambient_space().gens()[i] - pts[0][i]) + for j in range(n)] coords.pop(i) coords.insert(0, BC.ambient_space().gens()[i]) H = Hom(BC, B[0][i]) @@ -1598,7 +1600,7 @@ def extension(self): # with the projection map L = list(t_maps) for j in range(len(t_maps)): - L[j] = L[j]*t_pi + L[j] = L[j] * t_pi for j in range(len(B[1][i])): L.insert(t + j, B[1][i][j]) b_data.append(L) diff --git a/src/sage/schemes/curves/projective_curve.py b/src/sage/schemes/curves/projective_curve.py index e5a6ba01be1..16fd91956da 100644 --- a/src/sage/schemes/curves/projective_curve.py +++ b/src/sage/schemes/curves/projective_curve.py @@ -1243,13 +1243,13 @@ def excellent_position(self, Q): # since (0 : 0 : 1) has multiplicity r, divide out by the highest # shared power of the corresponding variable before doing the resultant computations if j == 0: - div_pow = min([e[1] for e in npoly.exponents()]) - npoly = PP.coordinate_ring()(dict([((v[0],v[1] - div_pow,v[2]),g) for (v,g) in\ - npoly.dict().items()])) + div_pow = min(e[1] for e in npoly.exponents()) + npoly = PP.coordinate_ring()({(v0, v1 - div_pow, v2): g + for (v0, v1, v2), g in npoly.dict().items()}) else: - div_pow = min([e[0] for e in npoly.exponents()]) - npoly = PP.coordinate_ring()(dict([((v[0] - div_pow,v[1],v[2]),g) for (v,g) in\ - npoly.dict().items()])) + div_pow = min(e[0] for e in npoly.exponents()) + npoly = PP.coordinate_ring()({(v0 - div_pow, v1, v2): g + for (v0, v1, v2), g in npoly.dict().items()}) # check the degree again if npoly.degree() != d - r: need_continue = True diff --git a/src/sage/schemes/elliptic_curves/ell_egros.py b/src/sage/schemes/elliptic_curves/ell_egros.py index 53c507e4c89..42c8d0738be 100644 --- a/src/sage/schemes/elliptic_curves/ell_egros.py +++ b/src/sage/schemes/elliptic_curves/ell_egros.py @@ -115,11 +115,9 @@ def is_possible_j(j, S=[]): True """ j = QQ(j) - return (j.is_zero() and 3 in S) \ - or (j == 1728) \ - or (j.is_S_integral(S) \ - and j.prime_to_S_part(S).is_nth_power(3) \ - and (j-1728).prime_to_S_part(S).abs().is_square()) + return (j.is_zero() and 3 in S) or (j == 1728) \ + or (j.is_S_integral(S) and j.prime_to_S_part(S).is_nth_power(3) + and (j - 1728).prime_to_S_part(S).abs().is_square()) def curve_key(E1): diff --git a/src/sage/schemes/elliptic_curves/ell_rational_field.py b/src/sage/schemes/elliptic_curves/ell_rational_field.py index f1b7d937748..0e551bd0748 100644 --- a/src/sage/schemes/elliptic_curves/ell_rational_field.py +++ b/src/sage/schemes/elliptic_curves/ell_rational_field.py @@ -2344,17 +2344,17 @@ def _compute_gens(self, proof, xterm = 1 yterm = 1 C = E.mwrank_curve(verbose) - if not (verbose is None): + if verbose is not None: C.set_verbose(verbose) C.two_descent(verbose=verbose, second_limit=descent_second_limit) C.saturate(bound=sat_bound) G = C.gens() if proof is True and C.certain() is False: del self.__mwrank_curve - raise RuntimeError("Unable to compute the rank, hence generators, with certainty (lower bound=%s, generators found=%s). This could be because Sha(E/Q)[2] is nontrivial."%(C.rank(),G) + \ - "\nTry increasing descent_second_limit then trying this command again.") + raise RuntimeError("Unable to compute the rank, hence generators, with certainty (lower bound=%s, generators found=%s). This could be because Sha(E/Q)[2] is nontrivial." % (C.rank(), G) + + "\nTry increasing descent_second_limit then trying this command again.") proved = C.certain() - G = [[x*xterm,y*yterm,z] for x, y, z in G] + G = [[x*xterm, y*yterm, z] for x, y, z in G] else: # when gens() calls mwrank it passes the command-line # parameter "-p 100" which helps curves with large diff --git a/src/sage/schemes/elliptic_curves/mod5family.py b/src/sage/schemes/elliptic_curves/mod5family.py index 1afc5588f74..9fe4b2db894 100644 --- a/src/sage/schemes/elliptic_curves/mod5family.py +++ b/src/sage/schemes/elliptic_curves/mod5family.py @@ -81,19 +81,19 @@ def mod5family(a, b): beta[21] = 100050*(J - 1)**10*(143 + 107250*J + 808368*J**2 + 38518336*J**3 - 451953408*J**4 + 757651968*J**5 - 367276032*J**6) beta[22] = 450225*(J - 1)**11*(-13 - 11440*J - 117216*J**2 - 6444800*J**3 + 94192384*J**4 - 142000128*J**5 + 95551488*J**6) beta[23] = 156600*(J - 1)**11*(-13 - 13299*J - 163284*J**2 - 11171552*J**3 + 217203840*J**4 - 474406656*J**5 + 747740160*J**6 - 429981696*J**7) - beta[24] = 6525*(J - 1)**12*(91 + 107536*J + 1680624*J**2 + 132912128*J**3 -\ + beta[24] = 6525*(J - 1)**12*(91 + 107536*J + 1680624*J**2 + 132912128*J**3 - 3147511552*J**4 + 6260502528*J**5 - 21054173184*J**6 + 10319560704*J**7) - beta[25] = 1566*(J - 1)**12*(91 + 123292*J + 2261248*J**2 + 216211904*J**3 - \ + beta[25] = 1566*(J - 1)**12*(91 + 123292*J + 2261248*J**2 + 216211904*J**3 - 6487793920*J**4 + 17369596928*J**5 - 97854234624*J**6 + 96136740864*J**7 - 20639121408*J**8) - beta[26] = 3915*(J - 1)**13*(-7 - 10816*J - 242352*J**2 - 26620160*J**3 + 953885440*J**4 - \ + beta[26] = 3915*(J - 1)**13*(-7 - 10816*J - 242352*J**2 - 26620160*J**3 + 953885440*J**4 - 2350596096*J**5 + 26796552192*J**6 - 13329432576*J**7) - beta[27] = 580*(J - 1)**13*(-7 - 12259*J - 317176*J**2 - 41205008*J**3 + \ + beta[27] = 580*(J - 1)**13*(-7 - 12259*J - 317176*J**2 - 41205008*J**3 + 1808220160*J**4 - 5714806016*J**5 + 93590857728*J**6 - 70131806208*J**7 - 36118462464*J**8) - beta[28] = 435*(J - 1)**14*(1 + 1976*J + 60720*J**2 + 8987648*J**3 - 463120640*J**4 + 1359157248*J**5 - \ + beta[28] = 435*(J - 1)**14*(1 + 1976*J + 60720*J**2 + 8987648*J**3 - 463120640*J**4 + 1359157248*J**5 - 40644882432*J**6 - 5016453120*J**7 + 61917364224*J**8) - beta[29] = 30*(J - 1)**14*(1 + 2218*J + 77680*J**2 + 13365152*J**3 - \ + beta[29] = 30*(J - 1)**14*(1 + 2218*J + 77680*J**2 + 13365152*J**3 - 822366976*J**4 + 2990693888*J**5 - 118286217216*J**6 - 24514928640*J**7 + 509958291456*J**8 - 743008370688*J**9) - beta[30] = (J - 1)**15*(-1 - 2480*J - 101040*J**2 - 19642496*J**3 + 1399023872*J**4 - \ + beta[30] = (J - 1)**15*(-1 - 2480*J - 101040*J**2 - 19642496*J**3 + 1399023872*J**4 - 4759216128*J**5 + 315623485440*J**6 + 471904911360*J**7 - 2600529297408*J**8 + 8916100448256*J**9) R = PolynomialRing(QQ, 't') diff --git a/src/sage/schemes/elliptic_curves/padics.py b/src/sage/schemes/elliptic_curves/padics.py index e4d88113716..2ed6110bef6 100644 --- a/src/sage/schemes/elliptic_curves/padics.py +++ b/src/sage/schemes/elliptic_curves/padics.py @@ -208,8 +208,8 @@ def padic_lseries(self, p, normalize=None, implementation='eclib', sage: L[3] O(11^0) """ - p, normalize, implementation, precision = self._normalize_padic_lseries(p,\ - normalize, implementation, precision) + p, normalize, implementation, precision = self._normalize_padic_lseries(p, + normalize, implementation, precision) if implementation in ['sage', 'eclib', 'num']: if self.ap(p) % p != 0: diff --git a/src/sage/schemes/generic/point.py b/src/sage/schemes/generic/point.py index 0cadc10957e..91cc15cc16f 100644 --- a/src/sage/schemes/generic/point.py +++ b/src/sage/schemes/generic/point.py @@ -100,6 +100,7 @@ def __init__(self, S): """ SchemePoint.__init__(self, S, parent=S) + class SchemeTopologicalPoint_affine_open(SchemeTopologicalPoint): def __init__(self, u, x): """ @@ -114,9 +115,9 @@ def __init__(self, u, x): self.__x = x def _repr_(self): - return "Point on %s defined by x in U, where:\n U: %s\n x: %s"%(\ - self.scheme(), self.embedding_of_affine_open().domain(), - self.point_on_affine()) + return "Point on %s defined by x in U, where:\n U: %s\n x: %s" % ( + self.scheme(), self.embedding_of_affine_open().domain(), + self.point_on_affine()) def point_on_affine(self): """ diff --git a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py index ab883076d33..eab55498a81 100644 --- a/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py +++ b/src/sage/schemes/hyperelliptic_curves/hyperelliptic_finite_field.py @@ -641,7 +641,7 @@ def _points_fast_sqrt(self): elif K.characteristic() == 2: # deg(P) = 2 and char(K) = 2 # quadratic equation doesn't work in characteristic 2 so use brute # force - points += [self.point([K(1), y, K(0)], check=True) for y in K \ + points += [self.point([K(1), y, K(0)], check=True) for y in K if not P(K(1), y, K(0))] else: # deg(P) = 2 and char(K) not 2 # P(1, y, 0) = y^2 + r*y + s @@ -733,7 +733,7 @@ def _points_cache_sqrt(self, brute_force=False): # (0:1:0) is a point on the curve points = [self.point([K(0), K(1), K(0)], check=True)] else: - points=[] + points = [] if P.degree() > 2: # P(1, y, 0) = r*y + s s = P(K(1), K(0), K(0)) @@ -744,7 +744,7 @@ def _points_cache_sqrt(self, brute_force=False): elif K.characteristic() == 2: # deg(P) = 2 and char(K) = 2 # quadratic equation doesn't work in characteristic 2 so use brute # force - points += [self.point([K(1), y, K(0)], check=True) for y in K \ + points += [self.point([K(1), y, K(0)], check=True) for y in K if not P(K(1), y, K(0))] else: # deg(P) = 2 and char(K) not 2 # P(1, y, 0) = y^2 + r*y + s diff --git a/src/sage/schemes/hyperelliptic_curves/mestre.py b/src/sage/schemes/hyperelliptic_curves/mestre.py index 31ba672800c..1073321e7d9 100644 --- a/src/sage/schemes/hyperelliptic_curves/mestre.py +++ b/src/sage/schemes/hyperelliptic_curves/mestre.py @@ -160,20 +160,20 @@ def HyperellipticCurve_from_invariants(i, reduced=True, precision=None, from sage.interfaces.magma import magma from sage.misc.sage_eval import sage_eval if MConic.has_rational_point(algorithm='magma'): - parametrization = [l.replace('$.1', 't').replace('$.2', 'u') \ + parametrization = [l.replace('$.1', 't').replace('$.2', 'u') for l in str(magma(MConic).Parametrization()).splitlines()[4:7]] - [F1, F2, F3] = [sage_eval(p, locals={'t':t,'u':1,'a':k.gen()}) \ - for p in parametrization] + [F1, F2, F3] = [sage_eval(p, locals={'t': t, 'u': 1, 'a': k.gen()}) + for p in parametrization] else: - raise ValueError("No such curve exists over %s as there are no " \ - "rational points on %s" % (k, MConic)) + raise ValueError(f"No such curve exists over {k} as there are no " + f"rational points on {MConic}") else: if MConic.has_rational_point(): parametrization = MConic.parametrization(morphism=False)[0] [F1, F2, F3] = [p(t, 1) for p in parametrization] else: - raise ValueError("No such curve exists over %s as there are no " \ - "rational points on %s" % (k, MConic)) + raise ValueError(f"No such curve exists over {k} as there are no " + f"rational points on {MConic}") # setting the cijk from Mestre's algorithm c111 = 12*x*y - 2*y/3 - 4*z @@ -195,14 +195,14 @@ def HyperellipticCurve_from_invariants(i, reduced=True, precision=None, c233*F2*F3**2 + c333*F3**3 try: - f = f*f.denominator() # clear the denominator + f = f * f.denominator() # clear the denominator except (AttributeError, TypeError): pass if reduced: - raise NotImplementedError("Reduction of hyperelliptic curves not " \ - "yet implemented. " \ - "See trac #14755 and #14756.") + raise NotImplementedError("Reduction of hyperelliptic curves not " + "yet implemented. " + "See github #14755 and #14756.") return HyperellipticCurve(f) diff --git a/src/sage/schemes/product_projective/rational_point.py b/src/sage/schemes/product_projective/rational_point.py index 53e08bcc171..55a2ad8d3cb 100644 --- a/src/sage/schemes/product_projective/rational_point.py +++ b/src/sage/schemes/product_projective/rational_point.py @@ -471,15 +471,16 @@ def parallel_function_combination(point_p_max): # lift all coordinates of given point using chinese remainder theorem L = [modulo_points[j][tupl[j]][k].lift() for j in range(len_primes - 1)] L.append(point_p_max[k].lift()) - point.append( crt(L, primes_list) ) + point.append(crt(L, primes_list)) for i in range(num_comp): for j in range(comp_dim_relative[i]): m[i][j] = point[dim_prefix[i] + j] # generating matrix to compute LLL reduction for each component - M = [matrix(ZZ, comp_dim_relative[i] + 1, comp_dim_relative[i], m[i]) \ - for i in range(num_comp)] + M = [matrix(ZZ, comp_dim_relative[i] + 1, + comp_dim_relative[i], m[i]) + for i in range(num_comp)] A = [M[i].LLL() for i in range(num_comp)] point = [] for i in range(num_comp): diff --git a/src/sage/schemes/projective/projective_morphism.py b/src/sage/schemes/projective/projective_morphism.py index 9c608f67a48..1be87705132 100644 --- a/src/sage/schemes/projective/projective_morphism.py +++ b/src/sage/schemes/projective/projective_morphism.py @@ -239,7 +239,7 @@ def __init__(self, parent, polys, check=True): try: polys = [K(f) for f in polys] except TypeError: - raise TypeError("polys (=%s) must be elements of %s"%(polys, source_ring)) + raise TypeError("polys (=%s) must be elements of %s" % (polys, source_ring)) if parent.codomain().is_projective(): degs = [] @@ -258,7 +258,7 @@ def __init__(self, parent, polys, check=True): if not all(d == deg for deg in degs[1:]): raise ValueError("polys (={}) must be of the same degree".format(polys)) - polys = [(l*f).numerator() for f in polys] + polys = [(l * f).numerator() for f in polys] elif parent.codomain().is_affine(): for f in polys: num = f.numerator() @@ -397,19 +397,19 @@ def __call__(self, x, check=True): try: x = self.domain()(x) except (TypeError, NotImplementedError): - raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented"%(x, self.domain())) - #else pass it onto the eval below + raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented" % (x, self.domain())) + # else pass it onto the eval below elif isinstance(x, AlgebraicScheme_subscheme_projective): - return x._forward_image(self) #call subscheme eval - else: #not a projective point or subscheme + return x._forward_image(self) # call subscheme eval + else: # not a projective point or subscheme try: x = self.domain()(x) except (TypeError, NotImplementedError): try: x = self.domain().subscheme(x) - return x._forward_image(self) #call subscheme eval + return x._forward_image(self) # call subscheme eval except (TypeError, NotImplementedError): - raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented"%(x, self.domain())) + raise TypeError("%s fails to convert into the map's domain %s, but a `pushforward` method is not properly implemented" % (x, self.domain())) R = x.domain().coordinate_ring() if R is self.base_ring(): @@ -549,7 +549,7 @@ def __eq__(self, right): return False n = len(self._polys) return all(self._polys[i] * right._polys[j] == self._polys[j] * right._polys[i] - for i in range(n) for j in range(i+1, n)) + for i in range(n) for j in range(i + 1, n)) def __ne__(self, right): """ @@ -790,10 +790,10 @@ def scale_by(self, t): if isinstance(R, QuotientRing_generic): phi = R._internal_coerce_map_from(self.domain().ambient_space().coordinate_ring()) for i in range(self.codomain().ambient_space().dimension_relative() + 1): - new_polys = [phi(u*t).lift() for u in self] + new_polys = [phi(u * t).lift() for u in self] else: for i in range(self.codomain().ambient_space().dimension_relative() + 1): - new_polys = [R(u*t) for u in self] + new_polys = [R(u * t) for u in self] self._polys = tuple(new_polys) def normalize_coordinates(self, **kwds): @@ -932,13 +932,13 @@ def normalize_coordinates(self, **kwds): if ideal is not None: from sage.rings.number_field.number_field_ideal import NumberFieldFractionalIdeal if not (ideal in ZZ or isinstance(ideal, NumberFieldFractionalIdeal)): - raise TypeError('ideal must be an ideal of a number field, not %s' %ideal) + raise TypeError('ideal must be an ideal of a number field, not %s' % ideal) if isinstance(ideal, NumberFieldFractionalIdeal): if ideal.number_field() != self.base_ring(): - raise ValueError('ideal must be an ideal of the base ring of this morphism ' + \ - ', not an ideal of %s' %ideal.number_field()) + raise ValueError('ideal must be an ideal of the base ring of this morphism ' + + ', not an ideal of %s' % ideal.number_field()) if not ideal.is_prime(): - raise ValueError('ideal was %s, not a prime ideal' %ideal) + raise ValueError('ideal was %s, not a prime ideal' % ideal) for generator in ideal.gens(): if generator.valuation(ideal) == 1: uniformizer = generator @@ -946,10 +946,10 @@ def normalize_coordinates(self, **kwds): else: ideal = ZZ(ideal) if self.base_ring() != QQ: - raise ValueError('ideal was an integer, but the base ring of this ' + \ - 'morphism is %s' %self.base_ring()) + raise ValueError('ideal was an integer, but the base ring of this ' + + 'morphism is %s' % self.base_ring()) if not ideal.is_prime(): - raise ValueError('ideal must be a prime, not %s' %ideal) + raise ValueError('ideal must be a prime, not %s' % ideal) uniformizer = ideal valuations = [] for poly in self: @@ -957,25 +957,25 @@ def normalize_coordinates(self, **kwds): if coefficient != 0: valuations.append(coefficient.valuation(ideal)) min_val = min(valuations) - self.scale_by(uniformizer**(-1*min_val)) + self.scale_by(uniformizer**(-1 * min_val)) return valuation = kwds.pop('valuation', None) if valuation is not None: from sage.rings.padics.padic_valuation import pAdicValuation_base if not isinstance(valuation, pAdicValuation_base): - raise TypeError('valuation must be a valuation on a number field, not %s' %valuation) + raise TypeError('valuation must be a valuation on a number field, not %s' % valuation) if valuation.domain() != self.base_ring(): - raise ValueError('the domain of valuation must be the base ring of this morphism ' + \ - 'not %s' %valuation.domain()) + raise ValueError('the domain of valuation must be the base ring of this morphism ' + + 'not %s' % valuation.domain()) uniformizer = valuation.uniformizer() - ramification_index = 1/valuation(uniformizer) + ramification_index = 1 / valuation(uniformizer) valuations = [] for poly in self: for coefficient, monomial in poly: if coefficient != 0: valuations.append(valuation(coefficient) * ramification_index) min_val = min(valuations) - self.scale_by(uniformizer**(-1*min_val)) + self.scale_by(uniformizer**(-1 * min_val)) return # clear any denominators from the coefficients @@ -1018,7 +1018,7 @@ def normalize_coordinates(self, **kwds): GCD = gcd([O(c) for poly in self for c in poly.coefficients()]) if GCD != 1: - self.scale_by(1/GCD) + self.scale_by(1 / GCD) from sage.rings.padics.padic_base_generic import pAdicGeneric # if R is not padic, we make the first coordinate positive if not isinstance(R, pAdicGeneric): @@ -1186,13 +1186,13 @@ def dehomogenize(self, n): except KeyError: pass # it is possible to dehomogenize the domain and codomain at different coordinates - if isinstance(n,(tuple,list)): - ind=tuple(n) + if isinstance(n, (tuple, list)): + ind = tuple(n) else: - ind=(n,n) + ind = (n, n) PS_domain = self.domain() A_domain = PS_domain.ambient_space() - if self._polys[ind[1]].substitute({A_domain.gen(ind[0]):1}) == 0: + if self._polys[ind[1]].substitute({A_domain.gen(ind[0]): 1}) == 0: raise ValueError("can't dehomogenize at 0 coordinate") else: Aff_domain = PS_domain.affine_patch(ind[0]) @@ -1211,11 +1211,11 @@ def dehomogenize(self, n): H = Hom(Aff_domain, self.codomain().affine_patch(ind[1])) # since often you dehomogenize at the same coordinate in domain # and codomain it should be stored appropriately. - if ind == (n,n): - self.__dehomogenization[ind]=H(F) + if ind == (n, n): + self.__dehomogenization[ind] = H(F) return self.__dehomogenization[ind] else: - self.__dehomogenization[n]=H(F) + self.__dehomogenization[n] = H(F) return self.__dehomogenization[n] @cached_method @@ -1374,11 +1374,11 @@ def global_height(self, prec=None): raise TypeError("Must be over a Numberfield or a Numberfield Order or QQbar") # Get the coefficients from all of the polynomials in the dynamical system - coeffs = [x for xs in [k.coefficients() for k in f] for x in xs] + coeffs = [x for k in f for x in k.coefficients()] from sage.schemes.projective.projective_space import ProjectiveSpace - P = ProjectiveSpace(K, len(coeffs)-1) + P = ProjectiveSpace(K, len(coeffs) - 1) return P.point(coeffs).global_height(prec=prec) def local_height(self, v, prec=None): @@ -1755,7 +1755,7 @@ def _number_field_from_algebraics(self): if not (is_ProjectiveSpace(self.domain()) and is_ProjectiveSpace(self.domain())): raise NotImplementedError("not implemented for subschemes") - K_pre,C,phi = number_field_elements_from_algebraics([c for f in self \ + K_pre, C, phi = number_field_elements_from_algebraics([c for f in self for c in f.coefficients()], minimal=True) # check if the same field if K_pre is QQ: @@ -1771,17 +1771,17 @@ def _number_field_from_algebraics(self): else: from sage.rings.number_field.number_field import NumberField K = NumberField(K_pre.polynomial(), embedding=phi(K_pre.gen()), name='a') - psi = K_pre.hom([K.gen()], K) # Identification of K_pre with K - C = [ psi(c) for c in C ] # The elements of C were in K_pre, move them to K + psi = K_pre.hom([K.gen()], K) # Identification of K_pre with K + C = [psi(c) for c in C] # The elements of C were in K_pre, move them to K from sage.schemes.projective.projective_space import ProjectiveSpace N = self.domain().dimension_relative() - PS = ProjectiveSpace(K,N,self.domain().variable_names()) + PS = ProjectiveSpace(K, N, self.domain().variable_names()) if self.is_endomorphism(): H = End(PS) else: - PS2 = ProjectiveSpace(K,self.codomain().dimension_relative(),\ - self.codomain().variable_names()) - H = Hom(PS,PS2) + PS2 = ProjectiveSpace(K, self.codomain().dimension_relative(), + self.codomain().variable_names()) + H = Hom(PS, PS2) R = PS.coordinate_ring() exps = [f.exponents() for f in self] F = [] @@ -2104,20 +2104,20 @@ def reduce_base_field(self): return self # otherwise we are not in the prime subfield so coercion # to it does not work - for L,phi in K.subfields(): + for L, phi in K.subfields(): # find the right subfield and its embedding if L.degree() == d: break # we need to rewrite each of the coefficients in terms of the generator # of L. To do this, we'll set-up an ideal and use elimination R = PolynomialRing(K.prime_subfield(), 2, 'a') - a,b = R.gens() + a, b = R.gens() from sage.schemes.projective.projective_space import ProjectiveSpace - new_domain = ProjectiveSpace(L, self.domain().dimension_relative(),\ - self.domain().variable_names()) + new_domain = ProjectiveSpace(L, self.domain().dimension_relative(), + self.domain().variable_names()) new_R = new_domain.coordinate_ring() - u = phi(L.gen()) # gen of L in terms of gen of K - g = R(str(u).replace(K.variable_name(),R.variable_names()[0])) #converted to R + u = phi(L.gen()) # gen of L in terms of gen of K + g = R(str(u).replace(K.variable_name(), R.variable_names()[0])) #converted to R new_f = [] for fi in self: mon = fi.monomials() @@ -2148,14 +2148,14 @@ def reduce_base_field(self): return H(new_f) elif isinstance(K, AlgebraicClosureFiniteField_generic): self.domain().coordinate_ring() - #find the degree of the extension containing the coefficients + # find the degree of the extension containing the coefficients c = [v for g in self for v in g.coefficients()] d = lcm([a.minpoly().degree() for a in c]) - #get the appropriate subfield + # get the appropriate subfield L, L_to_K = K.subfield(d) from sage.schemes.projective.projective_space import ProjectiveSpace - new_domain = ProjectiveSpace(L, self.domain().dimension_relative(),\ - self.domain().variable_names()) + new_domain = ProjectiveSpace(L, self.domain().dimension_relative(), + self.domain().variable_names()) new_R = new_domain.coordinate_ring() # we need to rewrite each of the coefficients in terms of the generator # of L. To do this, we'll set-up an ideal and use elimination @@ -2168,16 +2168,17 @@ def reduce_base_field(self): for c in coef: # for each coefficient move to the correct base field da = c.minpoly().degree() - for M,M_to_L in L.subfields(): - #find the right subfield and it's embedding + for M, M_to_L in L.subfields(): + # find the right subfield and it's embedding if M.degree() == da: break - c = M((str(c).replace(c.as_finite_field_element()[0].variable_name(),\ - M.variable_name()))) + c = M((str(c).replace(c.as_finite_field_element()[0].variable_name(), + M.variable_name()))) new_c.append(M_to_L(c)) # reconstruct as a poly in the new domain - new_f.append(sum([new_c[i]*prod([new_R.gen(j)**mon_deg[i][j] \ - for j in range(new_R.ngens())]) for i in range(len(mon))])) + new_f.append(sum([new_c[i] * prod(new_R.gen(j)**mon_deg[i][j] + for j in range(new_R.ngens())) + for i in range(len(mon))])) # return the correct type of map if self.is_endomorphism(): H = Hom(new_domain, new_domain) @@ -2465,7 +2466,9 @@ def representatives(self): M = kernel.sage_matrix(R) # m * n matrix over R reprs = [] for i in range(M.ncols()): - reprs.append(X.hom([lift(F[j]*M[r][i] / F[r]) for j in range(n)], Y)) + Mri = M[r][i] / F[r] + reprs.append(X.hom([lift(F[j] * Mri) + for j in range(n)], Y)) return reprs @@ -2726,7 +2729,7 @@ def projective_degrees(self): G = self.graph() I = G.defining_ideal() # a bihomogeneous ideal - degrees = xn*[vector([1,0])] + yn*[vector([0,1])] + degrees = xn * [vector([1, 0])] + yn * [vector([0, 1])] res = I.graded_free_resolution(degrees=degrees, algorithm='shreyer') kpoly = res.K_polynomial() From b159124643caa89c7040d7fc53e0afe664e6460b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 21 Mar 2023 20:04:46 +0100 Subject: [PATCH 2/4] fix reviewer suggestions --- .../finite_state_machine_generators.py | 23 +++++++++---------- src/sage/combinat/gelfand_tsetlin_patterns.py | 6 ++--- src/sage/combinat/integer_vector.py | 7 +++--- src/sage/combinat/words/word_generators.py | 11 +++++---- .../schemes/hyperelliptic_curves/mestre.py | 2 +- .../schemes/projective/projective_morphism.py | 3 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/sage/combinat/finite_state_machine_generators.py b/src/sage/combinat/finite_state_machine_generators.py index 385e35e14c9..ed5cca2588b 100644 --- a/src/sage/combinat/finite_state_machine_generators.py +++ b/src/sage/combinat/finite_state_machine_generators.py @@ -276,7 +276,7 @@ def Word(self, word, input_alphabet=None): letters = list(word) length = len(letters) from sage.rings.integer_ring import ZZ - return Automaton([(ZZ(i), ZZ(i+1), letter) + return Automaton([(ZZ(i), ZZ(i + 1), letter) for i, letter in enumerate(letters)], initial_states=[ZZ(0)], final_states=[ZZ(length)], @@ -1241,7 +1241,7 @@ def convert_output(output): for ring in output_rings: try: return ring(output) - except (ValueError,TypeError): + except (ValueError, TypeError): pass return output @@ -1353,12 +1353,12 @@ def to_list(output): assert equation == parsed_equation, \ "Parsing of %s failed for unknown reasons." % (equation,) - rule = self.RecursionRule(K=K,r=r, k=k, s=s, t=to_list(t)) + rule = self.RecursionRule(K=K, r=r, k=k, s=s, t=to_list(t)) return rule def Recursion(self, recursions, base, function=None, var=None, input_alphabet=None, word_function=None, - is_zero=None, output_rings=[ZZ, QQ]): + is_zero=None, output_rings=[ZZ, QQ]): r""" Return a transducer realizing the given recursion when reading the digit expansion with base ``base``. @@ -1815,11 +1815,11 @@ def Recursion(self, recursions, base, function=None, var=None, for given_rule in rules: q, remainder = given_rule.r.quo_rem(base**given_rule.K) - rule=self.RecursionRule(K=given_rule.K, - r=remainder, - k=given_rule.k, - s=given_rule.s - base**given_rule.k*q, - t=given_rule.t) + rule = self.RecursionRule(K=given_rule.K, + r=remainder, + k=given_rule.k, + s=given_rule.s - base**given_rule.k * q, + t=given_rule.t) for m in range(max_K - rule.K + 1): for ell in range(base**m): R = rule.r + base**rule.K * ell @@ -1988,9 +1988,8 @@ def f(n): "Too many initial conditions, only give one of %s." % cycle[1:]) required_initial_values.update(intersection) - output_sum = sum([edge[2] - for edge in recursion_digraph. - outgoing_edge_iterator(cycle[1:])], + output_sum = sum([e[2] + for e in recursion_digraph.outgoing_edge_iterator(cycle[1:])], []) if not is_zero(output_sum): raise ValueError( diff --git a/src/sage/combinat/gelfand_tsetlin_patterns.py b/src/sage/combinat/gelfand_tsetlin_patterns.py index 76583cd8fea..a1ec97586c7 100644 --- a/src/sage/combinat/gelfand_tsetlin_patterns.py +++ b/src/sage/combinat/gelfand_tsetlin_patterns.py @@ -1003,11 +1003,11 @@ def _row_iter(self, upper_row): pos -= 1 continue # If it would create an invalid entry, backstep - if ( pos > 0 and (row[pos] >= row[pos-1] - or (self._strict and row[pos] == row[pos-1]-1)) ) \ + if (pos > 0 and (row[pos] >= row[pos - 1] + or (self._strict and row[pos] == row[pos - 1] - 1))) \ or row[pos] >= upper_row[pos] \ or (self._k is not None and row[pos] >= self._k): - row[pos] = upper_row[pos+1] - 1 + row[pos] = upper_row[pos + 1] - 1 pos -= 1 continue row[pos] += 1 diff --git a/src/sage/combinat/integer_vector.py b/src/sage/combinat/integer_vector.py index 37c1d1b9de3..1a8b962216e 100644 --- a/src/sage/combinat/integer_vector.py +++ b/src/sage/combinat/integer_vector.py @@ -1416,9 +1416,10 @@ def cardinality(self): return Integer(binomial(self.n + self.k - 1, self.n)) # do by inclusion / exclusion on the number # i of parts greater than m - return Integer(sum((-1)**i * binomial(self.n+self.k-1-i*(m+1), self.k-1) - * binomial(self.k, i) - for i in range(self.n / (m + 1) + 1))) + n, k = self.n, self.k + return Integer(sum( + (-1)**i * binomial(n + k - 1 - i * (m + 1), k - 1) + * binomial(k, i) for i in range(self.n // (m + 1) + 1))) return ZZ.sum(ZZ.one() for x in self) def __iter__(self): diff --git a/src/sage/combinat/words/word_generators.py b/src/sage/combinat/words/word_generators.py index b046273b7e5..c48b529ef48 100644 --- a/src/sage/combinat/words/word_generators.py +++ b/src/sage/combinat/words/word_generators.py @@ -139,7 +139,7 @@ class LowerChristoffelWord(FiniteWord_list): word: 01 """ - def __init__(self, p, q, alphabet=(0,1), algorithm='cf'): + def __init__(self, p, q, alphabet=(0, 1), algorithm='cf'): r""" INPUT: @@ -184,7 +184,7 @@ def __init__(self, p, q, alphabet=(0,1), algorithm='cf'): if len(set(alphabet)) != 2: raise ValueError("alphabet must contain exactly two distinct elements") # Compute gcd of p, q; raise TypeError if not 1. - if gcd(p,q) != 1: + if gcd(p, q) != 1: raise ValueError("%s and %s are not relatively prime" % (p, q)) # Compute the Christoffel word if algorithm == 'linear': @@ -194,7 +194,7 @@ def __init__(self, p, q, alphabet=(0,1), algorithm='cf'): w = [alphabet[0]] else: for i in range(p + q): - v = (u+p) % (p+q) + v = (u + p) % (p + q) new_letter = alphabet[0] if u < v else alphabet[1] w.append(new_letter) u = v @@ -208,7 +208,7 @@ def __init__(self, p, q, alphabet=(0,1), algorithm='cf'): cf = QQ((p, q)).continued_fraction_list() u = [alphabet[0]] v = [alphabet[1]] - #do not consider the first zero if p < q + # do not consider the first zero if p < q start = 1 if p < q else 0 for i in range(start, len(cf)-1): if i % 2 == 0: @@ -1276,9 +1276,10 @@ def StandardEpisturmianWord(self, directive_word): """ if not isinstance(directive_word, Word_class): raise TypeError("directive_word is not a word, so it cannot be used to build an episturmian word") - return directive_word.parent()( + epistandard = directive_word.parent()( self._StandardEpisturmianWord_LetterIterator(directive_word), datatype='iter') + return epistandard def _StandardEpisturmianWord_LetterIterator(self, directive_word): r""" diff --git a/src/sage/schemes/hyperelliptic_curves/mestre.py b/src/sage/schemes/hyperelliptic_curves/mestre.py index 1073321e7d9..effc174ef68 100644 --- a/src/sage/schemes/hyperelliptic_curves/mestre.py +++ b/src/sage/schemes/hyperelliptic_curves/mestre.py @@ -202,7 +202,7 @@ def HyperellipticCurve_from_invariants(i, reduced=True, precision=None, if reduced: raise NotImplementedError("Reduction of hyperelliptic curves not " "yet implemented. " - "See github #14755 and #14756.") + "See issues #14755 and #14756.") return HyperellipticCurve(f) diff --git a/src/sage/schemes/projective/projective_morphism.py b/src/sage/schemes/projective/projective_morphism.py index 1be87705132..145af208535 100644 --- a/src/sage/schemes/projective/projective_morphism.py +++ b/src/sage/schemes/projective/projective_morphism.py @@ -2467,8 +2467,7 @@ def representatives(self): reprs = [] for i in range(M.ncols()): Mri = M[r][i] / F[r] - reprs.append(X.hom([lift(F[j] * Mri) - for j in range(n)], Y)) + reprs.append(X.hom([lift(F[j] * Mri) for j in range(n)], Y)) return reprs From 3b06eaefdbe2503f638e0a5f610d82f5fe0872d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 22 Mar 2023 08:27:26 +0100 Subject: [PATCH 3/4] fix detail --- src/sage/schemes/projective/projective_morphism.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sage/schemes/projective/projective_morphism.py b/src/sage/schemes/projective/projective_morphism.py index 145af208535..bfbf8b69252 100644 --- a/src/sage/schemes/projective/projective_morphism.py +++ b/src/sage/schemes/projective/projective_morphism.py @@ -1523,9 +1523,9 @@ def wronskian_ideal(self): from sage.schemes.projective.projective_space import is_ProjectiveSpace if not (is_ProjectiveSpace(dom) and is_ProjectiveSpace(self.codomain())): raise NotImplementedError("not implemented for subschemes") - N = dom.dimension_relative()+1 + N = dom.dimension_relative() + 1 R = dom.coordinate_ring() - J = jacobian(self.defining_polynomials(),dom.gens()) + J = jacobian(self.defining_polynomials(), dom.gens()) return R.ideal(J.minors(N)) @@ -2466,8 +2466,8 @@ def representatives(self): M = kernel.sage_matrix(R) # m * n matrix over R reprs = [] for i in range(M.ncols()): - Mri = M[r][i] / F[r] - reprs.append(X.hom([lift(F[j] * Mri) for j in range(n)], Y)) + lifts = [lift(F[j] * M[r][i] / F[r]) for j in range(n)] + reprs.append(X.hom(lifts, Y)) return reprs From 5fa42e9eb9b27f5b68b17cff30091eebf4fa048c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 22 Mar 2023 14:35:18 +0100 Subject: [PATCH 4/4] Update mestre.py fix the doctests --- src/sage/schemes/hyperelliptic_curves/mestre.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/schemes/hyperelliptic_curves/mestre.py b/src/sage/schemes/hyperelliptic_curves/mestre.py index effc174ef68..0396df9927f 100644 --- a/src/sage/schemes/hyperelliptic_curves/mestre.py +++ b/src/sage/schemes/hyperelliptic_curves/mestre.py @@ -67,13 +67,13 @@ def HyperellipticCurve_from_invariants(i, reduced=True, precision=None, sage: HyperellipticCurve_from_invariants([3840,414720,491028480,2437709561856]) Traceback (most recent call last): ... - NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See trac #14755 and #14756. + NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See issues #14755 and #14756. sage: HyperellipticCurve_from_invariants([3840,414720,491028480,2437709561856],reduced = False) Hyperelliptic Curve over Rational Field defined by y^2 = -46656*x^6 + 46656*x^5 - 19440*x^4 + 4320*x^3 - 540*x^2 + 4410*x - 1 sage: HyperellipticCurve_from_invariants([21, 225/64, 22941/512, 1]) Traceback (most recent call last): ... - NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See trac #14755 and #14756. + NotImplementedError: Reduction of hyperelliptic curves not yet implemented. See issues #14755 and #14756. An example over a finite field::