From e12ad99318d4d8644d0e0592dc7ffc94b2bf4938 Mon Sep 17 00:00:00 2001 From: Xavier Caruso Date: Thu, 9 Feb 2023 10:12:52 +0100 Subject: [PATCH 01/61] add lazy_string in matrix2.pyx --- src/sage/matrix/matrix2.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index cc1343b1538..42186c057ec 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -79,6 +79,7 @@ AUTHORS: from cpython cimport * from cysignals.signals cimport sig_check +from sage.misc.lazy_string import lazy_string from sage.misc.randstate cimport randstate, current_randstate from sage.structure.coerce cimport py_scalar_parent from sage.structure.sequence import Sequence @@ -4856,7 +4857,7 @@ cdef class Matrix(Matrix1): return K R = self.base_ring() - tm = verbose("computing a right kernel for %sx%s matrix over %s" % (self.nrows(), self.ncols(), R),level=1) + tm = verbose(lazy_string("computing a right kernel for %sx%s matrix over %s", self.nrows(), self.ncols(), R), level=1) # Sanitize basis format # 'computed' is OK in right_kernel_matrix(), but not here From 3d0bf1d66f1b7ee6e8973d216a999a0d8ae4cd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Thu, 9 Feb 2023 11:43:49 +0200 Subject: [PATCH 02/61] Speed verbose when message is not shown --- src/sage/matrix/matrix2.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 42186c057ec..094c1dbd3ab 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -4879,7 +4879,7 @@ cdef class Matrix(Matrix1): else: K = ambient.submodule_with_basis(M.rows(), already_echelonized=False, check=False) - verbose("done computing a right kernel for %sx%s matrix over %s" % (self.nrows(), self.ncols(), R),level=1, t=tm) + verbose(lazy_string("done computing a right kernel for %sx%s matrix over %s", self.nrows(), self.ncols(), R), level=1, t=tm) self.cache('right_kernel', K) return K From 5a4d279ec75cb2c555977dc33a55db117acb48db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20R=C3=BCth?= Date: Thu, 9 Feb 2023 12:00:57 +0200 Subject: [PATCH 03/61] Do not slow down linear algebra cache lookups with verbose messages --- src/sage/matrix/matrix2.pyx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/matrix/matrix2.pyx b/src/sage/matrix/matrix2.pyx index 094c1dbd3ab..90c7f549f6a 100644 --- a/src/sage/matrix/matrix2.pyx +++ b/src/sage/matrix/matrix2.pyx @@ -4853,7 +4853,6 @@ cdef class Matrix(Matrix1): """ K = self.fetch('right_kernel') if K is not None: - verbose("retrieving cached right kernel for %sx%s matrix" % (self.nrows(), self.ncols()),level=1) return K R = self.base_ring() @@ -5029,7 +5028,6 @@ cdef class Matrix(Matrix1): """ K = self.fetch('left_kernel') if K is not None: - verbose("retrieving cached left kernel for %sx%s matrix" % (self.nrows(), self.ncols()),level=1) return K tm = verbose("computing left kernel for %sx%s matrix" % (self.nrows(), self.ncols()),level=1) @@ -7886,11 +7884,11 @@ cdef class Matrix(Matrix1): [ 1.00 0.000 10.0] [0.000 1.00 1.00] """ - tm = verbose('generic in-place Gauss elimination on %s x %s matrix using %s algorithm'%(self._nrows, self._ncols, algorithm)) cdef Py_ssize_t start_row, c, r, nr, nc, i, best_r if self.fetch('in_echelon_form'): return self.fetch('pivots') + tm = verbose('generic in-place Gauss elimination on %s x %s matrix using %s algorithm'%(self._nrows, self._ncols, algorithm)) self.check_mutability() cdef Matrix A 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 04/61] 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 05/61] 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 06/61] 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 07/61] 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:: From a03cb6a910d8710e6be26838410c3770d501dd83 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 28 Mar 2023 12:07:17 -0700 Subject: [PATCH 08/61] build/sage_bootstrap: Support 'sage -package create --source wheel --pypi' for wheels tagged py2.py3 --- build/sage_bootstrap/app.py | 2 +- build/sage_bootstrap/pypi.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/build/sage_bootstrap/app.py b/build/sage_bootstrap/app.py index c9523e8cdc7..22fb252410b 100644 --- a/build/sage_bootstrap/app.py +++ b/build/sage_bootstrap/app.py @@ -305,7 +305,7 @@ def create(self, package_name, version=None, tarball=None, pkg_type=None, upstre raise ValueError('Only platform-independent wheels can be used for wheel packages, got {0}'.format(tarball)) if not version: version = pypi_version.version - upstream_url = 'https://pypi.io/packages/py3/{0:1.1}/{0}/{1}'.format(package_name, tarball) + upstream_url = 'https://pypi.io/packages/{2}/{0:1.1}/{0}/{1}'.format(package_name, tarball, pypi_version.python_version) if not description: description = pypi_version.summary if not license: diff --git a/build/sage_bootstrap/pypi.py b/build/sage_bootstrap/pypi.py index a11f3a95b46..e3ca4e560c7 100644 --- a/build/sage_bootstrap/pypi.py +++ b/build/sage_bootstrap/pypi.py @@ -69,7 +69,8 @@ def url(self): Return the source url """ for download in self.json['urls']: - if download['python_version'] == self.python_version: + if self.python_version in download['python_version']: + self.python_version = download['python_version'] return download['url'] raise PyPiError('No %s url for %s found', self.python_version, self.name) @@ -79,7 +80,8 @@ def tarball(self): Return the source tarball name """ for download in self.json['urls']: - if download['python_version'] == self.python_version: + if self.python_version in download['python_version']: + self.python_version = download['python_version'] return download['filename'] raise PyPiError('No %s url for %s found', self.python_version, self.name) From 2de0447d4ab7bffca23c6f68d2e0ce83db9c4117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 30 Mar 2023 17:58:19 +0200 Subject: [PATCH 09/61] cython-linting a few pyx files --- src/sage/functions/prime_pi.pyx | 26 +++++++++++-------- src/sage/interfaces/process.pyx | 10 +++---- src/sage/interfaces/sagespawn.pyx | 8 +++--- src/sage/lfunctions/zero_sums.pyx | 7 +---- .../monoids/free_abelian_monoid_element.pxd | 1 - .../monoids/free_abelian_monoid_element.pyx | 10 ++++--- src/sage/tests/cython.pyx | 6 ++--- 7 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/sage/functions/prime_pi.pyx b/src/sage/functions/prime_pi.pyx index 38c68a2d4b4..fd2956be193 100644 --- a/src/sage/functions/prime_pi.pyx +++ b/src/sage/functions/prime_pi.pyx @@ -83,8 +83,9 @@ cdef class PrimePi(BuiltinFunction): """ super(PrimePi, self).__init__('prime_pi', latex_name=r"\pi", - conversions={'mathematica':'PrimePi', 'pari':'primepi', - 'sympy':'primepi'}) + conversions={'mathematica': 'PrimePi', + 'pari': 'primepi', + 'sympy': 'primepi'}) def __call__(self, *args, coerce=True, hold=False): r""" @@ -104,8 +105,8 @@ cdef class PrimePi(BuiltinFunction): TypeError: Symbolic function prime_pi takes 1 or 2 arguments (3 given) """ if len(args) > 2: - raise TypeError("Symbolic function %s takes 1 or 2"%self._name - + " arguments (%s given)"%len(args)) + raise TypeError(f"Symbolic function {self._name} takes 1 or 2" + f" arguments ({len(args)} given)") return super(PrimePi, self).__call__(args[0], coerce=coerce, hold=hold) def _eval_(self, x): @@ -189,14 +190,14 @@ cdef class PrimePi(BuiltinFunction): if xmax < xmin: return plot_step_function([], **kwds) if xmax < 2: - return plot_step_function([(xmin,0),(xmax,0)], **kwds) + return plot_step_function([(xmin, 0), (xmax, 0)], **kwds) y = self(xmin) v = [(xmin, y)] from sage.rings.fast_arith import prime_range for p in prime_range(xmin+1, xmax+1, py_ints=True): y += 1 - v.append((p,y)) - v.append((xmax,y)) + v.append((p, y)) + v.append((xmax, y)) return plot_step_function(v, vertical_lines=vertical_lines, **kwds) ######## @@ -235,19 +236,22 @@ cpdef Integer legendre_phi(x, a): if not isinstance(a, Integer): a = Integer(a) if a < Integer(0): - raise ValueError("a (=%s) must be non-negative"%a) + raise ValueError("a (=%s) must be non-negative" % a) y = Integer(x) # legendre_phi(x, a) = 0 when x <= 0 - if not y: return Integer(0) + if not y: + return Integer(0) # legendre_phi(x, 0) = x - if a == Integer(0): return Integer(y) + if a == Integer(0): + return Integer(y) # If a > prime_pi(2^32), we compute phi(x,a) = max(pi(x)-a+1,1) if a > Integer(203280221): ret = prime_pi(x)-a+Integer(1) - if ret < Integer(1): return Integer(1) + if ret < Integer(1): + return Integer(1) return ret # Deal with the general case diff --git a/src/sage/interfaces/process.pyx b/src/sage/interfaces/process.pyx index ea90d5b0de4..016de82a30f 100644 --- a/src/sage/interfaces/process.pyx +++ b/src/sage/interfaces/process.pyx @@ -2,15 +2,15 @@ Utilities for subprocess management """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** import errno import signal @@ -163,7 +163,7 @@ cdef class ContainChildren(): if exc[0] is not None: # Exception was raised exitcode = self.exceptcode if not self.silent: - sys.stderr.write("Exception raised by child process with pid=%s:\n"%pid) + sys.stderr.write("Exception raised by child process with pid=%s:\n" % pid) import traceback traceback.print_exception(*exc) sys.stdout.flush() @@ -245,9 +245,7 @@ def terminate(sp, interval=1, signals=[signal.SIGTERM, signal.SIGKILL]): sage: t = walltime() - t0 sage: t <= 4.0 or t True - """ - try: yield sp finally: diff --git a/src/sage/interfaces/sagespawn.pyx b/src/sage/interfaces/sagespawn.pyx index 2303d3297bb..6bb9b90e580 100644 --- a/src/sage/interfaces/sagespawn.pyx +++ b/src/sage/interfaces/sagespawn.pyx @@ -10,15 +10,15 @@ AUTHOR: see :trac:`10295`. """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2015 Jeroen Demeyer # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from pexpect import * from ptyprocess import PtyProcess @@ -26,7 +26,7 @@ from ptyprocess import PtyProcess from cpython.ref cimport Py_INCREF from libc.signal cimport * from posix.signal cimport killpg -from posix.unistd cimport getpid, getpgid, close, fork +from posix.unistd cimport getpid, getpgid, fork from time import sleep diff --git a/src/sage/lfunctions/zero_sums.pyx b/src/sage/lfunctions/zero_sums.pyx index 1b584caec25..a74cb5a8093 100644 --- a/src/sage/lfunctions/zero_sums.pyx +++ b/src/sage/lfunctions/zero_sums.pyx @@ -18,11 +18,10 @@ AUTHORS: # https://www.gnu.org/licenses/ # **************************************************************************** -from sage.arith.misc import next_prime, prime_powers +from sage.arith.misc import next_prime from sage.functions.log import log, exp from sage.functions.other import real, imag from sage.libs.flint.ulong_extras cimport n_is_prime -from sage.libs.pari.all import pari from sage.misc.verbose import verbose from sage.parallel.decorate import parallel from sage.parallel.ncpus import ncpus as num_cpus @@ -374,7 +373,6 @@ cdef class LFunctionZeroSum_abstract(SageObject): z = s - 1 sigma = RDF(real(z)) - log2 = log(RDF(2)) # Compute maximum possible Dirichlet series truncation error # When s is in the critical strip: no guaranteed precision if abs(sigma) <= 0.5: @@ -654,7 +652,6 @@ cdef class LFunctionZeroSum_abstract(SageObject): """ npi = self._pi twopi = 2 * npi - eg = self._euler_gamma t = RDF(Delta * twopi) expt = RDF(exp(t)) @@ -747,7 +744,6 @@ cdef class LFunctionZeroSum_abstract(SageObject): from scipy.special import erfcx npi = self._pi - eg = self._euler_gamma Deltasqrtpi = Delta * npi.sqrt() t = RDF(Delta * npi * 2) @@ -1346,7 +1342,6 @@ cdef class LFunctionZeroSum_EllipticCurve(LFunctionZeroSum_abstract): cdef double z = 0 cdef double p = 0 - cdef double q = 0 cdef double sqrtp = 0 cdef double sqrtq = 0 cdef double logp = 0 diff --git a/src/sage/monoids/free_abelian_monoid_element.pxd b/src/sage/monoids/free_abelian_monoid_element.pxd index 74dd0f7b5ed..092cd343f05 100644 --- a/src/sage/monoids/free_abelian_monoid_element.pxd +++ b/src/sage/monoids/free_abelian_monoid_element.pxd @@ -13,4 +13,3 @@ cdef class FreeAbelianMonoidElement(MonoidElement): cdef FreeAbelianMonoidElement x = (t.__new__(t)) x._init(self._n, self._parent) return x - diff --git a/src/sage/monoids/free_abelian_monoid_element.pyx b/src/sage/monoids/free_abelian_monoid_element.pyx index 87c9f91f445..65df8efe613 100644 --- a/src/sage/monoids/free_abelian_monoid_element.pyx +++ b/src/sage/monoids/free_abelian_monoid_element.pyx @@ -26,13 +26,13 @@ The list is a copy, so changing the list does not change the element:: a^7*b^2*d*e """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2006 William Stein # Copyright (C) 2005 David Kohel # # Distributed under the terms of the GNU General Public License (GPL) -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from cysignals.memory cimport check_allocarray, sig_free from cysignals.signals cimport sig_on, sig_off @@ -40,6 +40,7 @@ from sage.structure.richcmp cimport rich_to_bool from sage.rings.integer cimport Integer, _Integer_from_mpz from sage.libs.gmp.mpz cimport * + def is_FreeAbelianMonoidElement(x): r""" Queries whether ``x`` is an object of type ``FreeAbelianMonoidElement``. @@ -55,6 +56,7 @@ def is_FreeAbelianMonoidElement(x): """ return isinstance(x, FreeAbelianMonoidElement) + cdef class FreeAbelianMonoidElement(MonoidElement): cdef int _init(self, Py_ssize_t n, Parent parent) except -1: """ @@ -307,7 +309,7 @@ cdef class FreeAbelianMonoidElement(MonoidElement): a^2*b^4 """ if not isinstance(y, FreeAbelianMonoidElement): - raise TypeError("argument y (= %s) is of wrong type"%y) + raise TypeError("argument y (= %s) is of wrong type" % y) cdef FreeAbelianMonoidElement s, z, r s = self r = y diff --git a/src/sage/tests/cython.pyx b/src/sage/tests/cython.pyx index c668fd47f02..3036085fdf2 100644 --- a/src/sage/tests/cython.pyx +++ b/src/sage/tests/cython.pyx @@ -1,15 +1,15 @@ """ This file collects tests requiring Cython. """ -#***************************************************************************** +# *************************************************************************** # Copyright (C) 2012 Jeroen Demeyer # Copyright (C) 2012 Simon King # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# *************************************************************************** from sage.misc.fast_methods cimport FastHashable_class From 4700c30daac93d375b3ec558d342bb64077ef9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Thu, 30 Mar 2023 14:30:19 +0200 Subject: [PATCH 10/61] partial cython linting in algebras/ using --ignore=E501,E731,E741 --- .../algebras/clifford_algebra_element.pxd | 2 - .../algebras/clifford_algebra_element.pyx | 53 +++++++++---------- .../algebras/exterior_algebra_groebner.pxd | 2 - .../algebras/exterior_algebra_groebner.pyx | 41 ++++++-------- .../finite_dimensional_algebra_element.pyx | 39 ++++++-------- .../fast_parallel_fmats_methods.pxd | 1 - .../fast_parallel_fmats_methods.pyx | 28 +++++----- .../fast_parallel_fusion_ring_braid_repn.pxd | 1 - .../fast_parallel_fusion_ring_braid_repn.pyx | 9 ++-- .../algebras/fusion_rings/poly_tup_engine.pxd | 1 - .../algebras/fusion_rings/poly_tup_engine.pyx | 22 ++++---- .../algebras/fusion_rings/shm_managers.pxd | 1 - .../algebras/fusion_rings/shm_managers.pyx | 14 +++-- .../lie_algebras/lie_algebra_element.pxd | 2 +- .../lie_algebras/lie_algebra_element.pyx | 27 +++++----- 15 files changed, 115 insertions(+), 128 deletions(-) diff --git a/src/sage/algebras/clifford_algebra_element.pxd b/src/sage/algebras/clifford_algebra_element.pxd index 64ac7253351..14d5a7a625c 100644 --- a/src/sage/algebras/clifford_algebra_element.pxd +++ b/src/sage/algebras/clifford_algebra_element.pxd @@ -1,7 +1,6 @@ """ Clifford algebra elements """ - from sage.modules.with_basis.indexed_element cimport IndexedFreeModuleElement from sage.data_structures.bitset cimport FrozenBitset @@ -14,4 +13,3 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): cdef class CohomologyRAAGElement(CliffordAlgebraElement): pass - diff --git a/src/sage/algebras/clifford_algebra_element.pyx b/src/sage/algebras/clifford_algebra_element.pyx index 6a12d5657a3..046ee44c8e9 100644 --- a/src/sage/algebras/clifford_algebra_element.pyx +++ b/src/sage/algebras/clifford_algebra_element.pyx @@ -6,8 +6,7 @@ AUTHORS: - Travis Scrimshaw (2013-09-06): Initial version - Trevor Karn (2022-07-10): Rewrite multiplication using bitsets """ - -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2022 Trevor K. Karn # (C) 2022 Travis Scrimshaw # @@ -16,8 +15,7 @@ AUTHORS: # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # http://www.gnu.org/licenses/ -#***************************************************************************** - +# **************************************************************************** from sage.structure.parent cimport Parent from sage.data_structures.bitset cimport Bitset from sage.algebras.weyl_algebra import repr_from_monomials @@ -125,7 +123,7 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): for ml, cl in self: # Distribute the current term ``cl`` * ``ml`` over ``other``. - cur = copy(other._monomial_coefficients) # The current distribution of the term + cur = copy(other._monomial_coefficients) # The current distribution of the term for i in reversed(ml): # Distribute the current factor ``e[i]`` (the ``i``-th # element of the standard basis). @@ -142,10 +140,10 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): break # Add the additional term from the commutation # get a non-frozen bitset to manipulate - t = Bitset(mr) # a mutable copy + t = Bitset(mr) # a mutable copy t.discard(j) t = FrozenBitset(t) - next_level[t] = next_level.get(t, zero) + cr * Q[i,j] + next_level[t] = next_level.get(t, zero) + cr * Q[i, j] # Note: ``Q[i,j] == Q(e[i]+e[j]) - Q(e[i]) - Q(e[j])`` for # ``i != j``, where ``e[k]`` is the ``k``-th standard # basis vector. @@ -154,16 +152,16 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): del next_level[t] # Check to see if we have a squared term or not - mr = Bitset(mr) # temporarily mutable + mr = Bitset(mr) # temporarily mutable if i in mr: mr.discard(i) - cr *= Q[i,i] + cr *= Q[i, i] # Note: ``Q[i,i] == Q(e[i])`` where ``e[i]`` is the # ``i``-th standard basis vector. else: # mr is implicitly sorted mr.add(i) - mr = FrozenBitset(mr) # refreeze it + mr = FrozenBitset(mr) # refreeze it next_level[mr] = next_level.get(mr, zero) + cr if next_level[mr] == zero: del next_level[mr] @@ -213,11 +211,6 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): sage: r * 2 # indirect doctest 2*x*y*z + 2*x*y + 2*x*z + 2*y*z + 2*x + 2*y + 2*z + 2 """ - cdef dict d - cdef list to_remove - cdef Py_ssize_t num_cross, tot_cross, i, j - cdef FrozenBitset ml - if supp.isempty(): # Multiplication by a base ring element if coeff == self._parent._base.one(): return self @@ -315,7 +308,8 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): sage: all(x.reflection().reflection() == x for x in Cl.basis()) True """ - return self.__class__(self._parent, {m: (-1)**len(m) * c for m,c in self}) + return self.__class__(self._parent, + {m: (-1)**len(m) * c for m, c in self}) degree_negation = reflection @@ -361,7 +355,7 @@ cdef class CliffordAlgebraElement(IndexedFreeModuleElement): if not self._monomial_coefficients: return P.zero() g = P.gens() - return P.sum(c * P.prod(g[i] for i in reversed(m)) for m,c in self) + return P.sum(c * P.prod(g[i] for i in reversed(m)) for m, c in self) def conjugate(self): r""" @@ -475,7 +469,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): ml = FrozenBitset() if ml in self._monomial_coefficients: const_coeff = self._monomial_coefficients[ml] - d = dict(rhs._monomial_coefficients) # Make a shallow copy + d = dict(rhs._monomial_coefficients) # Make a shallow copy to_remove = [] if const_coeff != P._base.one(): for k in d: @@ -488,10 +482,12 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): d = {} n = P.ngens() - for ml, cl in self._monomial_coefficients.items(): # ml for "monomial on the left" + for ml, cl in self._monomial_coefficients.items(): + # ml for "monomial on the left" if ml.isempty(): # We already handled the trivial element continue - for mr,cr in rhs._monomial_coefficients.items(): # mr for "monomial on the right" + for mr, cr in rhs._monomial_coefficients.items(): + # mr for "monomial on the right" if mr.isempty(): t = ml else: @@ -502,7 +498,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): it = iter(mr) j = next(it) - num_cross = 0 # keep track of the number of signs + num_cross = 0 # keep track of the number of signs tot_cross = 0 for i in ml: while i > j: @@ -576,7 +572,8 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): n = self._parent.ngens() d = {} - for ml, cl in self._monomial_coefficients.items(): # ml for "monomial on the left" + for ml, cl in self._monomial_coefficients.items(): + # ml for "monomial on the left" if not ml.isdisjoint(supp): # if they intersect nontrivially, move along. continue @@ -584,7 +581,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): it = iter(supp) j = next(it) - num_cross = 0 # keep track of the number of signs + num_cross = 0 # keep track of the number of signs tot_cross = 0 for i in ml: while i > j: @@ -668,7 +665,8 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): const_coeff = self._monomial_coefficients.pop(mr) d[supp] = const_coeff - for mr, cr in self._monomial_coefficients.items(): # mr for "monomial on the right" + for mr, cr in self._monomial_coefficients.items(): + # mr for "monomial on the right" if not supp.isdisjoint(mr): # if they intersect nontrivially, move along. continue @@ -676,7 +674,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): it = iter(mr) j = next(it) # We assume mr is non-empty here - num_cross = 0 # keep track of the number of signs + num_cross = 0 # keep track of the number of signs tot_cross = 0 for i in supp: while i > j: @@ -839,7 +837,7 @@ cdef class ExteriorAlgebraElement(CliffordAlgebraElement): """ P = self._parent return P.sum([c * cx * P.interior_product_on_basis(m, mx) - for m,c in self for mx,cx in x]) + for m, c in self for mx, cx in x]) antiderivation = interior_product @@ -968,7 +966,8 @@ cdef class CohomologyRAAGElement(CliffordAlgebraElement): tp = tuple(sorted(mr + ml)) if any(tp[i] == tp[i+1] for i in range(len(tp)-1)): # e_i ^ e_i = 0 continue - if tp not in I: # not an independent set, so this term is also 0 + if tp not in I: + # not an independent set, so this term is also 0 continue t = list(mr) diff --git a/src/sage/algebras/exterior_algebra_groebner.pxd b/src/sage/algebras/exterior_algebra_groebner.pxd index d00fb2e8560..28cea102be7 100644 --- a/src/sage/algebras/exterior_algebra_groebner.pxd +++ b/src/sage/algebras/exterior_algebra_groebner.pxd @@ -1,7 +1,6 @@ """ Exterior algebras Gröbner bases """ - from sage.data_structures.bitset cimport FrozenBitset from sage.rings.integer cimport Integer from sage.algebras.clifford_algebra_element cimport CliffordAlgebraElement @@ -53,4 +52,3 @@ cdef class GroebnerStrategyDegRevLex(GroebnerStrategy): cdef class GroebnerStrategyDegLex(GroebnerStrategy): pass - diff --git a/src/sage/algebras/exterior_algebra_groebner.pyx b/src/sage/algebras/exterior_algebra_groebner.pyx index cdd445e7253..ba46a5f38b4 100644 --- a/src/sage/algebras/exterior_algebra_groebner.pyx +++ b/src/sage/algebras/exterior_algebra_groebner.pyx @@ -21,8 +21,8 @@ AUTHORS: # **************************************************************************** from cysignals.signals cimport sig_check -from sage.libs.gmp.mpz cimport mpz_sizeinbase, mpz_setbit, mpz_tstbit, mpz_cmp_si, mpz_sgn -from sage.data_structures.bitset_base cimport (bitset_t, bitset_init, bitset_first, +from sage.libs.gmp.mpz cimport mpz_sizeinbase, mpz_setbit, mpz_tstbit, mpz_sgn +from sage.data_structures.bitset_base cimport (bitset_init, bitset_first, bitset_next, bitset_set_to, bitset_len) from sage.structure.parent cimport Parent from sage.structure.richcmp cimport richcmp, rich_to_bool @@ -175,8 +175,8 @@ cdef class GroebnerStrategy: Convert ``f`` into a ``GBElement``. """ cdef dict mc = f._monomial_coefficients - #if not mc: - # return GBElement(f, FrozenBitset(), -1) + # if not mc: + # return GBElement(f, FrozenBitset(), -1) cdef Integer r = max(self.bitset_to_int(k) for k in mc) return GBElement(f, self.int_to_bitset(r), r) @@ -232,7 +232,7 @@ cdef class GroebnerStrategy: if self.build_S_poly(f0, f1): L.add(self.partial_S_poly_right(f0, f1)) L.add(self.partial_S_poly_right(f1, f0)) - else: # We compute a left Gröbner basis for two-sided ideals + else: # We compute a left Gröbner basis for two-sided ideals for f0, f1 in P: if self.build_S_poly(f0, f1): L.add(self.partial_S_poly_left(f0, f1)) @@ -272,14 +272,14 @@ cdef class GroebnerStrategy: cdef set L = self.preprocessing(P, G) cdef Py_ssize_t i from sage.matrix.constructor import matrix - cdef Integer r = Integer(2) ** self.rank - Integer(1) # r for "rank" or "reverso" + cdef Integer r = Integer(2) ** self.rank - Integer(1) # r for "rank" or "reverso" M = matrix({(i, r - self.bitset_to_int( m)): c - for i,f in enumerate(L) - for m,c in ( f).elt._monomial_coefficients.items()}, + for i, f in enumerate(L) + for m, c in ( f).elt._monomial_coefficients.items()}, sparse=True) M.echelonize() # Do this in place lead_supports = set(( f).lsi for f in L) - return [GBElement(self.E.element_class(self.E, {self.int_to_bitset(r - Integer(j)): c for j,c in M[i].iteritems()}), + return [GBElement(self.E.element_class(self.E, {self.int_to_bitset(r - Integer(j)): c for j, c in M[i].iteritems()}), self.int_to_bitset(Integer(r - p)), Integer(r - p)) for i, p in enumerate(M.pivots()) @@ -309,8 +309,7 @@ cdef class GroebnerStrategy: """ cdef FrozenBitset p0, p1 cdef long deg - cdef Py_ssize_t i, j, k - cdef set additions + cdef Py_ssize_t i, j cdef GBElement f0, f1 cdef list G = [], Gp cdef dict constructed = {} @@ -321,7 +320,7 @@ cdef class GroebnerStrategy: continue f0 = self.build_elt(f) if f0.lsi in constructed: - if f0 in constructed[f0.lsi]: # Already there + if f0 in constructed[f0.lsi]: # Already there continue constructed[f0.lsi].add(f0) else: @@ -338,7 +337,7 @@ cdef class GroebnerStrategy: continue f1 = self.build_elt(f) if f1.lsi in constructed: - if f1 in constructed[f1.lsi]: # Already there + if f1 in constructed[f1.lsi]: # Already there continue constructed[f1.lsi].add(f1) else: @@ -367,7 +366,7 @@ cdef class GroebnerStrategy: # Add the elements Gp to G when a new element is found for f0 in Gp: if f0.lsi in constructed: - if f0 in constructed[f0.lsi]: # Already there + if f0 in constructed[f0.lsi]: # Already there continue constructed[f0.lsi].add(f0) else: @@ -402,20 +401,16 @@ cdef class GroebnerStrategy: cdef GBElement f0, f1 # Now that we have a Gröbner basis, we make this into a reduced Gröbner basis - cdef tuple supp - cdef bint did_reduction - cdef FrozenBitset lm, s - cdef Integer r cdef Py_ssize_t num_zeros = 0 cdef Py_ssize_t n = len(G) cdef set pairs = set((i, j) for i in range(n) for j in range(n) if i != j) while pairs: sig_check() - i,j = pairs.pop() + i, j = pairs.pop() f0 = G[i] f1 = G[j] - assert f0.elt._monomial_coefficients is not f1.elt._monomial_coefficients, (i,j) + assert f0.elt._monomial_coefficients is not f1.elt._monomial_coefficients, (i, j) # We perform the classical reduction algorithm here on each pair # TODO: Make this faster by using the previous technique? if self.reduce_single(f0.elt, f1.elt): @@ -500,7 +495,6 @@ cdef class GroebnerStrategy: """ cdef FrozenBitset lm = self.leading_support(g), s, t cdef bint did_reduction = True, was_reduced=False - cdef tuple supp cdef CliffordAlgebraElement gp one = self.E._base.one() @@ -521,7 +515,6 @@ cdef class GroebnerStrategy: iaxpy(-coeff, gp._monomial_coefficients, f._monomial_coefficients) return was_reduced - cdef Integer bitset_to_int(self, FrozenBitset X): raise NotImplementedError @@ -658,8 +651,6 @@ cdef class GroebnerStrategyDegRevLex(GroebnerStrategy): """ Convert a nonnegative integer ``n`` to a :class:`FrozenBitset`. """ - cdef size_t i - if mpz_sgn(n.value) == 0: return FrozenBitset() @@ -701,8 +692,6 @@ cdef class GroebnerStrategyDegLex(GroebnerStrategy): """ Convert a nonnegative integer ``n`` to a :class:`FrozenBitset`. """ - cdef size_t i - if mpz_sgn(n.value) == 0: return FrozenBitset() diff --git a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx index b0ae904d3d2..1fc0977ce10 100644 --- a/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx +++ b/src/sage/algebras/finite_dimensional_algebras/finite_dimensional_algebra_element.pyx @@ -14,10 +14,8 @@ Elements of Finite Algebras # **************************************************************************** import re -from sage.misc.lazy_attribute import lazy_attribute from sage.matrix.matrix_space import MatrixSpace from sage.structure.element import is_Matrix -from sage.modules.free_module_element import vector from sage.rings.integer import Integer from cpython.object cimport PyObject_RichCompare as richcmp @@ -36,7 +34,7 @@ cpdef FiniteDimensionalAlgebraElement unpickle_FiniteDimensionalAlgebraElement(A """ cdef FiniteDimensionalAlgebraElement x = A.element_class.__new__(A.element_class) AlgebraElement.__init__(x, A) - x._vector = vec + x._vector = vec x.__matrix = mat return x @@ -90,13 +88,13 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): k = A.base_ring() n = A.degree() if elt is None: - self._vector = MatrixSpace(k,1,n)() + self._vector = MatrixSpace(k, 1, n)() self.__matrix = MatrixSpace(k, n)() else: if isinstance(elt, int): elt = Integer(elt) elif isinstance(elt, list): - elt = MatrixSpace(k,1,n)(elt) + elt = MatrixSpace(k, 1, n)(elt) if A == elt.parent(): mat = ( elt).__matrix if mat is None: @@ -115,7 +113,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): else: raise TypeError("algebra is not unitary") elif isinstance(elt, Vector): - self._vector = MatrixSpace(k,1,n)(list(elt)) + self._vector = MatrixSpace(k, 1, n)(list(elt)) elif is_Matrix(elt): if elt.ncols() != n: raise ValueError("matrix does not define an element of the algebra") @@ -171,7 +169,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): self._parent, D = state v = D.pop('_vector') if isinstance(v, Vector): - self._vector = MatrixSpace(self._parent.base_ring(), 1,len(v))(list(v)) + self._vector = MatrixSpace(self._parent.base_ring(), 1, len(v))(list(v)) else: self._vector = v self.__matrix = D.pop('_matrix', None) @@ -197,7 +195,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): if self.__matrix is None: A = self.parent() table = A.table() - ret = sum(self._vector[0,i] * table[i] for i in xrange(A.degree())) + ret = sum(self._vector[0, i] * table[i] for i in range(A.degree())) self.__matrix = MatrixSpace(A.base_ring(), A.degree())(ret) return self.__matrix @@ -211,9 +209,9 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): sage: B(5).vector() (5, 0, 5) """ - #By :trac:`23707`, ``self._vector`` now is a single row matrix, - #not a vector, which results in a speed-up. For backwards compatibility, - #this method still returns a vector. + # By :trac:`23707`, ``self._vector`` now is a single row matrix, + # not a vector, which results in a speed-up. + # For backwards compatibility, this method still returns a vector. return self._vector[0] def matrix(self): @@ -248,7 +246,7 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): {0: 1, 1: 1} """ cdef Py_ssize_t i - return {i:self._vector[0,i] for i in range(self._vector.ncols())} + return {i: self._vector[0, i] for i in range(self._vector.ncols())} def left_matrix(self): """ @@ -261,12 +259,11 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): [1 0 0] [0 1 0] [0 2 0] - """ A = self.parent() if A.is_commutative(): return self._matrix - return sum([self._vector[0,i] * A.left_table()[i] for + return sum([self._vector[0, i] * A.left_table()[i] for i in range(A.degree())]) def _repr_(self): @@ -299,8 +296,8 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): var = "*{}".format(A._names[n]) s += "{}{}".format(x, var) s = s.replace(" + -", " - ") - s = re.sub(r' 1(\.0+)?\*',' ', s) - s = re.sub(r' -1(\.0+)?\*',' -', s) + s = re.sub(r' 1(\.0+)?\*', ' ', s) + s = re.sub(r' -1(\.0+)?\*', ' -', s) if s == " ": return "0" return s[1:] @@ -330,9 +327,8 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]), Matrix([[0,1,0], [0,0,0], [0,0,0]]), Matrix([[0,0,0], [0,0,0], [0,0,1]])]) sage: A([2,1/4,3])[2] 3 - """ - return self._vector[0,m] + return self._vector[0, m] def __len__(self): """ @@ -341,11 +337,10 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): sage: A = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0,0], [0,1,0], [0,0,0]]), Matrix([[0,1,0], [0,0,0], [0,0,0]]), Matrix([[0,0,0], [0,0,0], [0,0,1]])]) sage: len(A([2,1/4,3])) 3 - """ return self._vector.ncols() - ## (Rich) comparison + # (Rich) comparison cpdef _richcmp_(self, right, int op): """ EXAMPLES:: @@ -375,7 +370,6 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): True sage: A(1) <= 0 False - """ return richcmp(self._vector, right._vector, op) @@ -435,7 +429,8 @@ cdef class FiniteDimensionalAlgebraElement(AlgebraElement): if not self._parent.base_ring().has_coerce_map_from(other.parent()): raise TypeError("unsupported operand parent(s) for *: '{}' and '{}'" .format(self.parent(), other.parent())) - return self._parent.element_class(self._parent, other * self._vector) # Note the different order + # Note the different order below + return self._parent.element_class(self._parent, other * self._vector) def __pow__(self, n, m): """ diff --git a/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pxd b/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pxd index 11dc0253b35..e0908ab5884 100644 --- a/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pxd +++ b/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pxd @@ -2,4 +2,3 @@ cdef _fmat(fvars, Nk_ij, one, a, b, c, d, x, y) cpdef _backward_subs(factory, bint flatten=*) cpdef executor(tuple params) cpdef _solve_for_linear_terms(factory, list eqns=*) - diff --git a/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pyx b/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pyx index 02dcd786458..a9b7eb50fab 100644 --- a/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pyx +++ b/src/sage/algebras/fusion_rings/fast_parallel_fmats_methods.pyx @@ -29,7 +29,7 @@ from sage.rings.ideal import Ideal from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing ########################## -### Fast class methods ### +# Fast class methods # ########################## cpdef _solve_for_linear_terms(factory, list eqns=None): @@ -87,7 +87,8 @@ cpdef _solve_for_linear_terms(factory, list eqns=None): # assert factory.test_fvars[s] == fvars[s], "OG value {}, Shared: {}".format(fvars[s], factory.test_fvars[s]) if len(eq_tup) == 2: idx = has_appropriate_linear_term(eq_tup) - if idx < 0: continue + if idx < 0: + continue # The chosen term is guaranteed to be univariate in the largest variable exp = eq_tup[idx][0] max_var = exp._data[0] @@ -161,7 +162,7 @@ cpdef _backward_subs(factory, bint flatten=True): sextuple = idx_to_sextuple[i] rhs = fvars[sextuple] d = {var_idx: fvars[idx_to_sextuple[var_idx]] - for var_idx in variables(rhs) if solved[var_idx]} + for var_idx in variables(rhs) if solved[var_idx]} if d: kp = compute_known_powers(get_variables_degrees([rhs], nvars), d, one) res = tuple(subs_squares(subs(rhs, kp, one), _ks).items()) @@ -210,7 +211,7 @@ cdef _fmat(fvars, _Nk_ij, id_anyon, a, b, c, d, x, y): # _Nk_ij = cached_function(_Nk_ij, name='_Nk_ij') ############### -### Mappers ### +# Mappers # ############### cdef req_cy(tuple basis, r_matrix, dict fvars, Nk_ij, id_anyon, tuple sextuple): @@ -227,6 +228,7 @@ cdef req_cy(tuple basis, r_matrix, dict fvars, Nk_ij, id_anyon, tuple sextuple): rhs += _fmat(fvars, Nk_ij, id_anyon, c, a, b, d, e, f) * r_matrix(f, c, d, base_coercion=False) * _fmat(fvars, Nk_ij, id_anyon, a, b, c, d, f, g) return lhs-rhs + @cython.wraparound(False) @cython.nonecheck(False) @cython.cdivision(True) @@ -287,13 +289,15 @@ cdef MPolynomial_libsingular feq_cy(tuple basis, fvars, Nk_ij, id_anyon, zero, t """ a, b, c, d, e, f, g, k, l = nonuple lhs = _fmat(fvars, Nk_ij, id_anyon, f, c, d, e, g, l) * _fmat(fvars, Nk_ij, id_anyon, a, b, l, e, f, k) - if lhs == 0 and prune: # it is believed that if lhs=0, the equation carries no new information + if lhs == 0 and prune: + # it is believed that if lhs=0, the equation carries no new information return zero rhs = zero for h in basis: rhs += _fmat(fvars, Nk_ij, id_anyon, a, b, c, g, f, h)*_fmat(fvars, Nk_ij, id_anyon, a, h, d, e, g, k)*_fmat(fvars, Nk_ij, id_anyon, b, c, d, k, h, l) return lhs - rhs + @cython.wraparound(False) @cython.nonecheck(False) @cython.cdivision(True) @@ -304,7 +308,7 @@ cdef get_reduced_pentagons(factory, tuple mp_params): # Set up multiprocessing parameters cdef list worker_results = list() cdef int child_id, n_proc - child_id, n_proc, output = mp_params + child_id, n_proc, _ = mp_params cdef unsigned long i cdef tuple nonuple, red cdef MPolynomial_libsingular pe @@ -395,7 +399,7 @@ cdef list compute_gb(factory, tuple args): cdef MPolynomialRing_libsingular R = PolynomialRing(factory._FR.field(), len(sorted_vars), 'a', order=term_order) # Zip tuples into R and compute Groebner basis - cdef idx_map = { old : new for new, old in enumerate(sorted_vars) } + cdef idx_map = {old : new for new, old in enumerate(sorted_vars)} nvars = len(sorted_vars) F = factory.field() cdef list polys = list() @@ -405,7 +409,7 @@ cdef list compute_gb(factory, tuple args): gb = Ideal(sorted(polys)).groebner_basis(algorithm="libsingular:slimgb") # Change back to fmats poly ring and append to temp_eqns - cdef dict inv_idx_map = { v : k for k, v in idx_map.items() } + cdef dict inv_idx_map = {v: k for k, v in idx_map.items()} cdef tuple t nvars = factory._poly_ring.ngens() for p in gb: @@ -418,7 +422,7 @@ cdef list compute_gb(factory, tuple args): return collect_eqns(res) ################ -### Reducers ### +# Reducers # ################ cdef inline list collect_eqns(list eqns): @@ -434,7 +438,7 @@ cdef inline list collect_eqns(list eqns): return list(reduced) ############################## -### Parallel code executor ### +# Parallel code executor # ############################## # Hard-coded module __dict__-style attribute with visible cdef methods @@ -490,7 +494,7 @@ cpdef executor(tuple params): return mappers[fn_name](fmats_obj, args) #################### -### Verification ### +# Verification # #################### cdef feq_verif(factory, worker_results, fvars, Nk_ij, id_anyon, tuple nonuple, float tol=5e-8): @@ -508,6 +512,7 @@ cdef feq_verif(factory, worker_results, fvars, Nk_ij, id_anyon, tuple nonuple, f if diff > tol or diff < -tol: worker_results.append(diff) + @cython.wraparound(False) @cython.nonecheck(False) @cython.cdivision(True) @@ -517,7 +522,6 @@ cdef pent_verify(factory, tuple mp_params): and reduce them. """ child_id, n_proc, verbose = mp_params - cdef float t0 cdef tuple nonuple cdef unsigned long long i cdef list worker_results = list() diff --git a/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pxd b/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pxd index b3eec73b15b..a992f0339a4 100644 --- a/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pxd +++ b/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pxd @@ -1,3 +1,2 @@ cpdef _unflatten_entries(factory, list entries) cpdef executor(tuple params) - diff --git a/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pyx b/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pyx index 9fcb4408c21..8fc054f50cd 100644 --- a/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pyx +++ b/src/sage/algebras/fusion_rings/fast_parallel_fusion_ring_braid_repn.pyx @@ -15,7 +15,7 @@ from sage.algebras.fusion_rings.fast_parallel_fmats_methods cimport _fmat from sage.rings.qqbar import QQbar ############### -### Mappers ### +# Mappers # ############### cdef mid_sig_ij(fusion_ring, row, col, a, b): @@ -96,6 +96,7 @@ cdef cached_odd_one_out_ij(fusion_ring, xi, xj, a, b): odd_one_out_ij_cache[xi, xj, a, b] = entry return entry + @cython.nonecheck(False) @cython.cdivision(True) cdef sig_2k(fusion_ring, tuple args): @@ -175,6 +176,7 @@ cdef sig_2k(fusion_ring, tuple args): worker_results.append(((basis_dict[nnz_pos], i), entry)) return worker_results + @cython.nonecheck(False) @cython.cdivision(True) cdef odd_one_out(fusion_ring, tuple args): @@ -252,7 +254,7 @@ cdef odd_one_out(fusion_ring, tuple args): return worker_results ############################## -### Parallel code executor ### +# Parallel code executor # ############################## # Hard-coded module __dict__-style attribute with visible cdef methods @@ -300,7 +302,7 @@ cpdef executor(tuple params): return mappers[fn_name](fusion_ring_obj, args) ###################################### -### Pickling circumvention helpers ### +# Pickling circumvention helpers # ###################################### cpdef _unflatten_entries(fusion_ring, list entries): @@ -323,7 +325,6 @@ cpdef _unflatten_entries(fusion_ring, list entries): True """ F = fusion_ring.fvars_field() - fm = fusion_ring.get_fmatrix() if F != QQbar: for i, (coord, entry) in enumerate(entries): entries[i] = (coord, F(entry)) diff --git a/src/sage/algebras/fusion_rings/poly_tup_engine.pxd b/src/sage/algebras/fusion_rings/poly_tup_engine.pxd index 22c6449385a..a4ddf9b92ae 100644 --- a/src/sage/algebras/fusion_rings/poly_tup_engine.pxd +++ b/src/sage/algebras/fusion_rings/poly_tup_engine.pxd @@ -21,4 +21,3 @@ cdef tuple reduce_poly_dict(dict eq_dict, ETuple nonz, KSHandler known_sq, Numbe cdef tuple _flatten_coeffs(tuple eq_tup) cpdef tuple _unflatten_coeffs(field, tuple eq_tup) cdef int has_appropriate_linear_term(tuple eq_tup) - diff --git a/src/sage/algebras/fusion_rings/poly_tup_engine.pyx b/src/sage/algebras/fusion_rings/poly_tup_engine.pyx index ebf3ea8aa8c..67176402134 100644 --- a/src/sage/algebras/fusion_rings/poly_tup_engine.pyx +++ b/src/sage/algebras/fusion_rings/poly_tup_engine.pyx @@ -9,7 +9,7 @@ Arithmetic Engine for Polynomials as Tuples # **************************************************************************** ########### -### API ### +# API # ########### cpdef inline tuple poly_to_tup(MPolynomial_libsingular poly): @@ -115,7 +115,7 @@ cpdef tuple _unflatten_coeffs(field, tuple eq_tup): return tuple(unflat) ################################# -### Useful private predicates ### +# Useful private predicates # ################################# cdef inline int has_appropriate_linear_term(tuple eq_tup): @@ -146,7 +146,7 @@ cdef inline int has_appropriate_linear_term(tuple eq_tup): return -1 ###################### -### "Change rings" ### +# "Change rings" # ###################### cpdef inline tup_to_univ_poly(tuple eq_tup, univ_poly_ring): @@ -215,7 +215,7 @@ cpdef inline tuple resize(tuple eq_tup, dict idx_map, int nvars): return tuple(resized) ########################### -### Convenience methods ### +# Convenience methods # ########################### cdef inline ETuple degrees(tuple poly_tup): @@ -225,7 +225,7 @@ cdef inline ETuple degrees(tuple poly_tup): # Deal with the empty tuple, representing the zero polynomial if not poly_tup: return ETuple() - cdef ETuple max_degs, exp + cdef ETuple max_degs cdef int i max_degs = ( poly_tup[0])[0] for i in range(1, len(poly_tup)): @@ -251,7 +251,7 @@ cpdef list get_variables_degrees(list eqns, int nvars): cdef int i max_deg = degrees(eqns[0]) for i in range(1, len(eqns)): - max_deg = max_deg.emax(degrees( (eqns[i]) )) + max_deg = max_deg.emax(degrees((eqns[i]))) cdef list dense = [0] * len(max_deg) for i in range(max_deg._nonzero): dense[max_deg._data[2*i]] = max_deg._data[2*i+1] @@ -339,7 +339,7 @@ cdef inline bint tup_fixes_sq(tuple eq_tup): return True ###################### -### Simplification ### +# Simplification # ###################### cdef dict subs_squares(dict eq_dict, KSHandler known_sq): @@ -358,7 +358,7 @@ cdef dict subs_squares(dict eq_dict, KSHandler known_sq): A dictionary of ``(ETuple, coeff)`` pairs. """ cdef dict subbed, new_e - cdef ETuple exp, lm + cdef ETuple exp cdef int idx, power subbed = dict() for exp, coeff in eq_dict.items(): @@ -434,7 +434,7 @@ cdef tuple reduce_poly_dict(dict eq_dict, ETuple nonz, KSHandler known_sq, Numbe return to_monic(gcf_rmvd, one) #################### -### Substitution ### +# Substitution # #################### cpdef dict compute_known_powers(max_degs, dict val_dict, one): @@ -521,7 +521,7 @@ cdef tuple tup_mul(tuple p1, tuple p2): return tuple(prod.items()) ############### -### Sorting ### +# Sorting # ############### cdef tuple monom_sortkey(ETuple exp): @@ -564,7 +564,7 @@ cpdef tuple poly_tup_sortkey(tuple eq_tup): (2, 0, 2, 2, 0, 1, -2, 1, 2, -2, 2, 1, 0, 1, 1, -1, 1) """ cdef ETuple exp - cdef int i, l, nnz + cdef int i cdef list key = [] for exp, c in eq_tup: # Compare by term degree diff --git a/src/sage/algebras/fusion_rings/shm_managers.pxd b/src/sage/algebras/fusion_rings/shm_managers.pxd index 342b533acae..8f4967d6d0a 100644 --- a/src/sage/algebras/fusion_rings/shm_managers.pxd +++ b/src/sage/algebras/fusion_rings/shm_managers.pxd @@ -21,4 +21,3 @@ cdef class FvarsHandler: cdef object fvars_t, pid_list cdef Py_ssize_t child_id cdef public object shm - diff --git a/src/sage/algebras/fusion_rings/shm_managers.pyx b/src/sage/algebras/fusion_rings/shm_managers.pyx index 89b4c173001..84cd66e2be8 100644 --- a/src/sage/algebras/fusion_rings/shm_managers.pyx +++ b/src/sage/algebras/fusion_rings/shm_managers.pyx @@ -96,7 +96,7 @@ cdef class KSHandler: sage: ks.shm.unlink() sage: f.shutdown_worker_pool() """ - def __init__(self, n_slots, field, use_mp=False, init_data={}, name=None): + def __init__(self, n_slots, field, use_mp=False, init_data=None, name=None): r""" Initialize ``self``. @@ -115,6 +115,8 @@ cdef class KSHandler: sage: f.shutdown_worker_pool() """ cdef int n, d + if init_data is None: + init_data = {} self.field = field n = n_slots d = self.field.degree() @@ -342,6 +344,7 @@ cdef class KSHandler: if self.ks_dat['known'][i]: yield i, self.get(i) + def make_KSHandler(n_slots, field, init_data): r""" Provide pickling / unpickling support for :class:`KSHandler`. @@ -358,6 +361,7 @@ def make_KSHandler(n_slots, field, init_data): """ return KSHandler(n_slots, field, init_data=init_data) + cdef class FvarsHandler: r""" A shared memory backed dict-like structure to manage the @@ -451,7 +455,8 @@ cdef class FvarsHandler: sage: fvars.shm.unlink() sage: f.shutdown_worker_pool() """ - def __init__(self, n_slots, field, idx_to_sextuple, init_data={}, use_mp=0, + def __init__(self, n_slots, field, idx_to_sextuple, init_data=None, + use_mp=0, pids_name=None, name=None, max_terms=20, n_bytes=32): r""" Initialize ``self``. @@ -477,6 +482,8 @@ cdef class FvarsHandler: self.bytes = n_bytes cdef int slots = self.bytes // 8 cdef int n_proc = use_mp + 1 + if init_data is None: + init_data = {} self.fvars_t = np.dtype([ ('modified', np.int8, (n_proc, )), ('ticks', 'u1', (max_terms, )), @@ -575,7 +582,7 @@ cdef class FvarsHandler: return self.obj_cache[idx] cdef ETuple e, exp cdef int count, nnz - cdef Integer d, num + cdef Integer num cdef list poly_tup, rats cdef NumberFieldElement_absolute cyc_coeff cdef Py_ssize_t cum, i, j, k @@ -753,6 +760,7 @@ cdef class FvarsHandler: for sextuple in self.sext_to_idx: yield sextuple, self[sextuple] + def make_FvarsHandler(n, field, idx_map, init_data): r""" Provide pickling / unpickling support for :class:`FvarsHandler`. diff --git a/src/sage/algebras/lie_algebras/lie_algebra_element.pxd b/src/sage/algebras/lie_algebras/lie_algebra_element.pxd index 8d82e65fefb..fdae38396b9 100644 --- a/src/sage/algebras/lie_algebras/lie_algebra_element.pxd +++ b/src/sage/algebras/lie_algebras/lie_algebra_element.pxd @@ -22,7 +22,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper): cpdef _bracket_(self, right) cpdef to_vector(self, bint sparse=*) cpdef dict monomial_coefficients(self, bint copy=*) - #cpdef lift(self) + # cpdef lift(self) cdef class UntwistedAffineLieAlgebraElement(Element): cdef dict _t_dict diff --git a/src/sage/algebras/lie_algebras/lie_algebra_element.pyx b/src/sage/algebras/lie_algebras/lie_algebra_element.pyx index d0a1f70510a..f26b19f1441 100644 --- a/src/sage/algebras/lie_algebras/lie_algebra_element.pyx +++ b/src/sage/algebras/lie_algebras/lie_algebra_element.pyx @@ -18,10 +18,9 @@ AUTHORS: # **************************************************************************** from copy import copy -from cpython.object cimport Py_LT, Py_LE, Py_EQ, Py_NE, Py_GT, Py_GE +from cpython.object cimport Py_EQ, Py_NE, Py_GT, Py_GE from sage.misc.repr import repr_lincomb -from sage.combinat.free_module import CombinatorialFreeModule from sage.structure.element cimport have_same_parent, parent from sage.structure.coerce cimport coercion_model from sage.cpython.wrapperdescr cimport wrapperdescr_fastcall @@ -116,7 +115,7 @@ cdef class LieAlgebraElement(IndexedFreeModuleElement): -[a, [a, b]] + [a, b] - [[a, b], b] """ s = codomain.zero() - if not self: # If we are 0 + if not self: # If we are 0 return s names = self.parent().variable_names() if base_map is None: @@ -408,7 +407,7 @@ cdef class LieAlgebraElementWrapper(ElementWrapper): if scalar_parent != self._parent.base_ring(): # Temporary needed by coercion (see Polynomial/FractionField tests). if self._parent.base_ring().has_coerce_map_from(scalar_parent): - scalar = self._parent.base_ring()( scalar ) + scalar = self._parent.base_ring()(scalar) else: return None if self_on_left: @@ -479,7 +478,7 @@ cdef class LieAlgebraMatrixWrapper(LieAlgebraElementWrapper): sage: z.value.is_immutable() True """ - value.set_immutable() # Make the matrix immutable for hashing + value.set_immutable() # Make the matrix immutable for hashing LieAlgebraElementWrapper.__init__(self, parent, value) @@ -681,7 +680,7 @@ cdef class LieSubalgebraElementWrapper(LieAlgebraElementWrapper): if scalar_parent != self._parent.base_ring(): # Temporary needed by coercion (see Polynomial/FractionField tests). if self._parent.base_ring().has_coerce_map_from(scalar_parent): - scalar = self._parent.base_ring()( scalar ) + scalar = self._parent.base_ring()(scalar) else: return None cdef LieSubalgebraElementWrapper ret @@ -827,7 +826,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper): zero = self._parent.base_ring().zero() I = self._parent._indices cdef int i - for i,v in enumerate(self.value): + for i, v in enumerate(self.value): if v != zero: yield (I[i], v) @@ -879,7 +878,7 @@ cdef class StructureCoefficientsElement(LieAlgebraMatrixWrapper): {'x': 2, 'z': -3/2} """ I = self._parent._indices - return {I[i]: v for i,v in self.value.iteritems()} + return {I[i]: v for i, v in self.value.iteritems()} def __getitem__(self, i): """ @@ -1262,7 +1261,7 @@ cdef class UntwistedAffineLieAlgebraElement(Element): cdef dict d = {} for t, g in self._t_dict.items(): for k, c in g.monomial_coefficients(copy=False).iteritems(): - d[k,t] = c + d[k, t] = c if self._c_coeff: d['c'] = self._c_coeff if self._d_coeff: @@ -1322,7 +1321,6 @@ cdef class UntwistedAffineLieAlgebraElement(Element): if not self or not y: return self._parent.zero() - gd = self._parent._g.basis() cdef dict d = {} cdef UntwistedAffineLieAlgebraElement rt = (y) c = self._parent.base_ring().zero() @@ -1472,11 +1470,11 @@ class FreeLieAlgebraElement(LieAlgebraElement): cdef dict d = {} zero = self.base_ring().zero() - for ml, cl in self._monomial_coefficients.iteritems(): # The left monomials - for mr, cr in y._monomial_coefficients.iteritems(): # The right monomials + for ml, cl in self._monomial_coefficients.iteritems(): # The left monomials + for mr, cr in y._monomial_coefficients.iteritems(): # The right monomials if ml == mr: continue - if ml < mr: # Make sure ml < mr + if ml < mr: # Make sure ml < mr a, b = ml, mr else: a, b = mr, ml @@ -1490,8 +1488,9 @@ class FreeLieAlgebraElement(LieAlgebraElement): return self.parent().zero() return type(self)(self.parent(), d) + ##################################################################### -## Helper classes for free Lie algebras +# Helper classes for free Lie algebras cdef class LieObject(SageObject): """ From 6470d0db374dc6d66a6cf4c57bac5c6c57ad01b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 1 Apr 2023 08:44:04 +0200 Subject: [PATCH 11/61] some cython-linting inside categories/ --- src/sage/categories/action.pyx | 17 ++++++------ src/sage/categories/category_cy_helper.pxd | 2 +- src/sage/categories/category_cy_helper.pyx | 12 ++++----- src/sage/categories/category_singleton.pyx | 5 ++-- src/sage/categories/functor.pyx | 15 +++++------ src/sage/categories/map.pxd | 5 ++-- src/sage/categories/map.pyx | 30 +++++++++++----------- src/sage/categories/morphism.pyx | 25 ++++++++---------- 8 files changed, 53 insertions(+), 58 deletions(-) diff --git a/src/sage/categories/action.pyx b/src/sage/categories/action.pyx index b15cebde220..0c82d6cfe08 100644 --- a/src/sage/categories/action.pyx +++ b/src/sage/categories/action.pyx @@ -43,15 +43,15 @@ AUTHOR: - Robert Bradshaw: initial version """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2007 Robert Bradshaw # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from cpython.tuple cimport PyTuple_GET_ITEM @@ -62,9 +62,7 @@ from sage.structure.element cimport parent from sage.structure.parent cimport Parent from . import homset -import sage.structure.element from weakref import ref -from sage.misc.constant_function import ConstantFunction cdef inline category(x): @@ -243,8 +241,8 @@ cdef class Action(Functor): def _repr_(self): side = "Left" if self._is_left else "Right" - return "%s %s by %r on %r"%(side, self._repr_name_(), self.G, - self.underlying_set()) + return "%s %s by %r on %r" % (side, self._repr_name_(), self.G, + self.underlying_set()) def _repr_name_(self): return "action" @@ -604,8 +602,9 @@ cdef class ActionEndomorphism(Morphism): return self._action._act_(self._g, x) def _repr_(self): - return "Action of %s on %s under %s."%(self._g, - self._action.underlying_set(), self._action) + return "Action of %s on %s under %s." % (self._g, + self._action.underlying_set(), + self._action) def __mul__(left, right): cdef ActionEndomorphism left_c, right_c diff --git a/src/sage/categories/category_cy_helper.pxd b/src/sage/categories/category_cy_helper.pxd index d0c833d9fe8..f50ce4e8226 100644 --- a/src/sage/categories/category_cy_helper.pxd +++ b/src/sage/categories/category_cy_helper.pxd @@ -1,6 +1,6 @@ cpdef tuple _sort_uniq(categories) cdef class AxiomContainer(dict): - pass + pass cpdef tuple canonicalize_axioms(AxiomContainer all_axioms, axioms) from sage.misc.classcall_metaclass cimport ClasscallMetaclass cpdef tuple _flatten_categories(categories, ClasscallMetaclass JoinCategory) diff --git a/src/sage/categories/category_cy_helper.pyx b/src/sage/categories/category_cy_helper.pyx index 135b015fc1c..1d0c5a2ad41 100644 --- a/src/sage/categories/category_cy_helper.pyx +++ b/src/sage/categories/category_cy_helper.pyx @@ -19,7 +19,7 @@ AUTHOR: #***************************************************************************** ####################################### -## Sorting +# Sorting cpdef inline tuple category_sort_key(object category): """ @@ -106,7 +106,7 @@ cpdef tuple _flatten_categories(categories, ClasscallMetaclass JoinCategory): return tuple(out) ############################################# -## Join +# Join cdef bint is_supercategory_of_done(new_cat, dict done): # This is a helper function. It replaces the closure @@ -164,7 +164,7 @@ cpdef tuple join_as_tuple(tuple categories, tuple axioms, tuple ignore_axioms): axs = axs | {axiom} done[category] = axs for axiom in axiomsS.difference(axs): - todo.add( (category, axiom) ) + todo.add((category, axiom)) # Invariants: # - the current list of categories is stored in the keys of ``done`` @@ -198,7 +198,7 @@ cpdef tuple join_as_tuple(tuple categories, tuple axioms, tuple ignore_axioms): # Mark old categories with new axioms as todo for category in done: for axiom in new_axioms: - todo.add( (category, axiom) ) + todo.add((category, axiom)) for new_cat in new_cats: axs = new_cat.axioms() for (cat, axiom) in ignore_axioms: @@ -206,13 +206,13 @@ cpdef tuple join_as_tuple(tuple categories, tuple axioms, tuple ignore_axioms): axs = axs | {axiom} done[new_cat] = axs for axiom in axiomsS.difference(axs): - todo.add( (new_cat, axiom) ) + todo.add((new_cat, axiom)) return _sort_uniq(done) ############################################# -## Axiom related functions +# Axiom related functions cdef class AxiomContainer(dict): """ diff --git a/src/sage/categories/category_singleton.pyx b/src/sage/categories/category_singleton.pyx index 1a5095e6017..ea8f9265033 100644 --- a/src/sage/categories/category_singleton.pyx +++ b/src/sage/categories/category_singleton.pyx @@ -9,13 +9,11 @@ Singleton categories # https://www.gnu.org/licenses/ # ***************************************************************************** -from sage.misc.cachefunc import cached_method, cached_function from sage.misc.constant_function import ConstantFunction -from sage.misc.lazy_attribute import lazy_attribute, lazy_class_attribute +from sage.misc.lazy_attribute import lazy_class_attribute from sage.categories.category import Category from sage.structure.category_object cimport CategoryObject from sage.structure.dynamic_class import DynamicMetaclass -from sage.structure.unique_representation import UniqueRepresentation from cpython.type cimport PyType_IsSubtype @@ -83,6 +81,7 @@ cdef class Category_contains_method_by_parent_class: except AttributeError: return False + class Category_singleton(Category): """ A base class for implementing singleton category diff --git a/src/sage/categories/functor.pyx b/src/sage/categories/functor.pyx index ccf01cc9177..f44fe19549e 100644 --- a/src/sage/categories/functor.pyx +++ b/src/sage/categories/functor.pyx @@ -56,10 +56,11 @@ def _Functor_unpickle(Cl, D, domain, codomain): """ F = Functor.__new__(Cl) Functor.__init__(F,domain,codomain) - for s,v in D: - setattr(F,s,v) + for s, v in D: + setattr(F, s, v) return F + cdef class Functor(SageObject): """ A class for functors between two categories @@ -314,9 +315,8 @@ cdef class Functor(SageObject): The identity functor on Category of rings sage: I.rename('Id'); I Id - """ - return "Functor from %s to %s"%(self.__domain, self.__codomain) + return "Functor from %s to %s" % (self.__domain, self.__codomain) def __call__(self, x): """ @@ -586,7 +586,6 @@ class IdentityFunctor_generic(ForgetfulFunctor_generic): sage: F = IdentityFunctor(Groups()) sage: loads(F.dumps()) == F True - """ return IdentityFunctor, (self.domain(), ) @@ -598,9 +597,8 @@ class IdentityFunctor_generic(ForgetfulFunctor_generic): sage: F = IdentityFunctor(fields) sage: F #indirect doctest The identity functor on Category of fields - """ - return "The identity functor on %s"%(self.domain()) + return "The identity functor on %s" % (self.domain()) def _apply_functor(self, x): """ @@ -622,6 +620,7 @@ class IdentityFunctor_generic(ForgetfulFunctor_generic): """ return x + def IdentityFunctor(C): """ Construct the identity functor of the given category. @@ -640,10 +639,10 @@ def IdentityFunctor(C): sage: F = IdentityFunctor(rings) sage: F(ZZ['x','y']) is ZZ['x','y'] True - """ return IdentityFunctor_generic(C) + def ForgetfulFunctor(domain, codomain): """ Construct the forgetful function from one category to another. diff --git a/src/sage/categories/map.pxd b/src/sage/categories/map.pxd index 120ef5ef0da..0467b872353 100644 --- a/src/sage/categories/map.pxd +++ b/src/sage/categories/map.pxd @@ -4,8 +4,9 @@ from sage.structure.element cimport Element cdef class Map(Element): cdef object __weakref__ - cdef public int _coerce_cost # a rough measure of the cost of using this morphism in the coercion system. - # 10 by default, 100 if a DefaultCoercionMorphism, 10000 if inexact. + cdef public int _coerce_cost + # a rough measure of the cost of using this morphism in the coercion system. + # 10 by default, 100 if a DefaultCoercionMorphism, 10000 if inexact. cdef _update_slots(self, dict) cdef dict _extra_slots(self) diff --git a/src/sage/categories/map.pyx b/src/sage/categories/map.pyx index 5b3a00a2328..5a7445913bb 100644 --- a/src/sage/categories/map.pyx +++ b/src/sage/categories/map.pyx @@ -131,13 +131,13 @@ cdef class Map(Element): C = parent.codomain() self._category_for = parent.homset_category() self._codomain = C - self.domain = ConstantFunction(D) - self.codomain = ConstantFunction(C) + self.domain = ConstantFunction(D) + self.codomain = ConstantFunction(C) self._is_coercion = False if D.is_exact() and C.is_exact(): - self._coerce_cost = 10 # default value. + self._coerce_cost = 10 # default value. else: - self._coerce_cost = 10000 # inexact morphisms are bad. + self._coerce_cost = 10000 # inexact morphisms are bad. def __copy__(self): """ @@ -559,13 +559,13 @@ cdef class Map(Element): D = self.domain() if D is None: return "Defunct map" - s = "%s map:"%self._repr_type() - s += "\n From: %s"%D - s += "\n To: %s"%self._codomain + s = "%s map:" % self._repr_type() + s += "\n From: %s" % D + s += "\n To: %s" % self._codomain if isinstance(self.domain, ConstantFunction): d = self._repr_defn() if d != '': - s += "\n Defn: %s"%('\n '.join(d.split('\n'))) + s += "\n Defn: %s" % ('\n '.join(d.split('\n'))) else: d = "(map internal to coercion system -- copy before use)" s = d + "\n" + s @@ -575,12 +575,12 @@ cdef class Map(Element): D = self.domain() if D is None: return "Defunct map" - s = "%s map:"%self._repr_type() - s += "\n From: %s"%D - s += "\n To: %s"%self._codomain + s = "%s map:" % self._repr_type() + s += "\n From: %s" % D + s += "\n To: %s" % self._codomain d = self._repr_defn() if d != '': - s += "\n Defn: %s"%('\n '.join(d.split('\n'))) + s += "\n Defn: %s" % ('\n '.join(d.split('\n'))) return s def domains(self): @@ -816,8 +816,8 @@ cdef class Map(Element): """ if not args and not kwds: return self(x) - else: - raise NotImplementedError("_call_with_args not overridden to accept arguments for %s" % type(self)) + raise NotImplementedError("_call_with_args not overridden " + f"to accept arguments for {type(self)}") def __mul__(self, right): r""" @@ -1777,7 +1777,7 @@ cdef class FormalCompositeMap(Map): From: Univariate Polynomial Ring in x over Rational Field To: Univariate Polynomial Ring in a over Rational Field """ - s = " %s"%(self.__list[0]) + s = " %s" % (self.__list[0]) for f in self.__list[1:]: s += "\nthen\n %s" % f return s diff --git a/src/sage/categories/morphism.pyx b/src/sage/categories/morphism.pyx index 59a73a43c62..031b41218e3 100644 --- a/src/sage/categories/morphism.pyx +++ b/src/sage/categories/morphism.pyx @@ -27,17 +27,15 @@ AUTHORS: """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2005 William Stein # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** - -import operator +# https://www.gnu.org/licenses/ +# **************************************************************************** from cpython.object cimport * @@ -51,6 +49,7 @@ from sage.structure.parent cimport Parent def is_Morphism(x): return isinstance(x, Morphism) + cdef class Morphism(Map): def _repr_(self): @@ -474,20 +473,18 @@ cdef class IdentityMorphism(Morphism): if not args and not kwds: return x cdef Parent C = self._codomain - if C._element_init_pass_parent: - from sage.misc.superseded import deprecation_cython as deprecation - deprecation(26879, "_element_init_pass_parent=True is deprecated. This probably means that _element_constructor_ should be a method and not some other kind of callable") - return C._element_constructor(C, x, *args, **kwds) - else: - return C._element_constructor(x, *args, **kwds) + return C._element_constructor(x, *args, **kwds) def __mul__(left, right): if not isinstance(right, Map): - raise TypeError("right (=%s) must be a map to multiply it by %s"%(right, left)) + raise TypeError(f"right (={right}) must be a map " + f"to multiply it by {left}") if not isinstance(left, Map): - raise TypeError("left (=%s) must be a map to multiply it by %s"%(left, right)) + raise TypeError(f"left (={left}) must be a map " + f"to multiply it by {right}") if right.codomain() != left.domain(): - raise TypeError("self (=%s) domain must equal right (=%s) codomain"%(left, right)) + raise TypeError(f"self (={left}) domain must equal " + f"right (={right}) codomain") if isinstance(left, IdentityMorphism): return right else: From 23d17d24bf13ea3b67e82411f72a4a732f357c34 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sat, 1 Apr 2023 21:05:25 +0200 Subject: [PATCH 12/61] implement conversion of complex_root_of to AA and QQbar --- src/sage/interfaces/sympy.py | 137 ++++++++++++++++++++ src/sage/symbolic/expression_conversions.py | 19 ++- 2 files changed, 155 insertions(+), 1 deletion(-) diff --git a/src/sage/interfaces/sympy.py b/src/sage/interfaces/sympy.py index aca0a43fa67..9ca4203b648 100644 --- a/src/sage/interfaces/sympy.py +++ b/src/sage/interfaces/sympy.py @@ -65,6 +65,17 @@ def _sympysage_float(self): from sage.rings.real_mpfr import create_RealNumber return create_RealNumber(str(self)) +def _sympysage_integer_ring(self): + r""" + EXAMPLES:: + + sage: import sympy + sage: sympy.ZZ._sage_() + Integer Ring + """ + from sage.rings.integer_ring import ZZ + return ZZ + def _sympysage_integer(self): """ EXAMPLES:: @@ -90,6 +101,121 @@ def _sympysage_rational(self): from sage.rings.rational import Rational return Rational((Integer(self.p), Integer(self.q))) +def _sympysage_rational_field(self): + r""" + EXAMPLES:: + + sage: import sympy + sage: sympy.QQ._sage_() + Rational Field + """ + from sage.rings.rational_field import QQ + return QQ + +def _sympysage_real_interval(self): + r""" + EXAMPLES:: + + sage: from sage.interfaces.sympy import sympy_init + sage: sympy_init() + + sage: from sympy import CRootOf + sage: from sympy.abc import x + sage: root = CRootOf(x**3 - x^2 - x - 1, 0) + sage: interval = root._get_interval() + sage: interval._sage_() + 2.? + sage: interval._sage_().parent() + Real Interval Field with 1024 bits of precision + """ + # NOTE: this is a very approximate conversion as we do not consider any + # potential issue with precision + # Just to be (a little bit) safe, we set it to 1024 + from sage.rings.real_mpfi import RealIntervalField + RIF = RealIntervalField(1024) + # NOTE: we call fraction_field since sympy stores mpq even + # for integral entries + domain = self.dom._sage_().fraction_field() + return RIF(domain(self.a)).union(RIF(domain(self.b))) + +def _sympysage_complex_interval(self): + r""" + EXAMPLES:: + + sage: from sage.interfaces.sympy import sympy_init + sage: sympy_init() + + sage: from sympy import CRootOf + sage: from sympy.abc import x + sage: root = CRootOf(x**10 - 2*x + 3, 9) + sage: interval = root._get_interval() + sage: interval._sage_() + 0.1? + 1.2?*I + sage: interval._sage_().parent() + Complex Interval Field with 1024 bits of precision + """ + # NOTE: this is a very approximate conversion as we do not consider any + # potential issue with precision + # Just to be (a little bit) safe, we set it to 1024 + from sage.rings.complex_interval_field import ComplexIntervalField + CIF = ComplexIntervalField(1024) + # NOTE: we call fraction_field since sympy stores mpq even + # for integral entries + domain = self.dom._sage_().fraction_field() + return CIF(domain(self.ax), domain(self.ay)).union(CIF(domain(self.bx), domain(self.by))) + +def _sympysage_polynomial_ring(self): + r""" + EXAMPLES:: + + sage: from sage.interfaces.sympy import sympy_init + sage: sympy_init() + + sage: import sympy + sage: ZZx = sympy.PolynomialRing(sympy.ZZ, 'x') + sage: ZZx._sage_() + Univariate Polynomial Ring in x over Integer Ring + + sage: ZZxy = sympy.PolynomialRing(ZZx, 'y') + sage: ZZxy._sage_() + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Integer Ring + """ + base_ring = self.domain._sage_() + variables = ','.join(map(str, self.gens)) + return base_ring[variables] + +def _sympysage_polynomial(self): + r""" + EXAMPLES:: + + sage: from sage.interfaces.sympy import sympy_init + sage: sympy_init() + + sage: import sympy + sage: from sympy.abc import x, y + sage: p = sympy.Poly(x*(x**2 + x - 1)**2) + sage: p._sage_() + x^5 + 2*x^4 - x^3 - 2*x^2 + x + sage: p._sage_().parent() + Univariate Polynomial Ring in x over Integer Ring + + sage: p = sympy.Poly(y*x**2 + x*y + 1) + sage: p._sage_() + x^2*y + x*y + 1 + sage: p._sage_().parent() + Multivariate Polynomial Ring in x, y over Integer Ring + + sage: p = sympy.Poly(y*x**2 + x*y + 1, x) + sage: p._sage_() + y*x^2 + y*x + 1 + sage: p._sage_().parent() + Univariate Polynomial Ring in x over Univariate Polynomial Ring in y over Integer Ring + """ + base_ring = self.domain._sage_() + variables = ','.join(map(str, self.gens)) + R = base_ring[variables] + return R.sum(base_ring(coeff) * R.monomial(*exp) for exp, coeff in self.rep.terms(order=None)) + def _sympysage_pinfty(self): """ EXAMPLES:: @@ -938,13 +1064,24 @@ def sympy_init(): from sympy.functions.special.tensor_functions import KroneckerDelta from sympy.logic.boolalg import BooleanTrue, BooleanFalse from sympy.integrals.integrals import Integral + from sympy.polys import Poly + from sympy.polys.domains.integerring import IntegerRing + from sympy.polys.domains.rationalfield import RationalField + from sympy.polys.domains.polynomialring import PolynomialRing from sympy.polys.rootoftools import CRootOf + from sympy.polys.rootisolation import RealInterval, ComplexInterval from sympy.series.order import Order from sympy.matrices import ImmutableMatrix, ImmutableSparseMatrix, Matrix, SparseMatrix Float._sage_ = _sympysage_float Integer._sage_ = _sympysage_integer Rational._sage_ = _sympysage_rational + RealInterval._sage_ = _sympysage_real_interval + ComplexInterval._sage_ = _sympysage_complex_interval + IntegerRing._sage_ = _sympysage_integer_ring + RationalField._sage_ = _sympysage_rational_field + PolynomialRing._sage_ = _sympysage_polynomial_ring + Poly._sage_ = _sympysage_polynomial Infinity._sage_ = _sympysage_pinfty NegativeInfinity._sage_ = _sympysage_ninfty ComplexInfinity._sage_ = _sympysage_uinfty diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index 9b2feeff147..c3cdacf9fe5 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -1245,6 +1245,16 @@ def composition(self, ex, operator): sage: a.composition(sin(pi/7), sin) 0.4338837391175581? + 0.?e-18*I + sage: x = SR.var('x') + sage: a.composition(complex_root_of(x^3 - x^2 - x - 1, 0), complex_root_of) + 1.839286755214161? + sage: a.composition(complex_root_of(x^5 - 1, 3), complex_root_of) + 0.3090169943749474? - 0.9510565162951536?*I + sage: a.composition(complex_root_of(x^2 + 1, 0), complex_root_of) + 1.?e-684 - 0.9999999999999999?*I + sage: a.composition(complex_root_of(x^2 + 1, 1), complex_root_of) + 1.?e-684 + 0.9999999999999999?*I + TESTS:: sage: QQbar(zeta(7)) @@ -1287,7 +1297,8 @@ def composition(self, ex, operator): ValueError: unable to represent as an algebraic number """ func = operator - operand, = ex.operands() + operands = ex.operands() + operand = operands[0] if isinstance(self.field, UniversalCyclotomicField): QQbar = self.field @@ -1295,6 +1306,7 @@ def composition(self, ex, operator): else: QQbar = self.field.algebraic_closure() hold = False + zeta = QQbar.zeta # Note that comparing functions themselves goes via maxima, and is SLOW func_name = repr(func) @@ -1330,6 +1342,11 @@ def composition(self, ex, operator): res = (exp_a - ~exp_a) / (exp_a + ~exp_a) elif func_name in self.reciprocal_trig_functions: res = ~self.reciprocal_trig_functions[func_name](operand)._algebraic_(QQbar) + elif func_name == 'complex_root_of': + cr = ex._sympy_() + poly = cr.poly._sage_() + interval = cr._get_interval()._sage_() + return self.field.polynomial_root(poly, interval) else: res = func(operand._algebraic_(self.field)) # We have to handle the case where we get the same symbolic From d88bf80ae24672d974ee3b45aa10ca4458210b44 Mon Sep 17 00:00:00 2001 From: Vincent Delecroix Date: Sun, 2 Apr 2023 13:14:53 +0200 Subject: [PATCH 13/61] fix algebraic conversion --- src/sage/symbolic/expression.pyx | 3 +++ src/sage/symbolic/expression_conversions.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 3526c9a2d7e..e3ce16f340a 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -2549,6 +2549,9 @@ cdef class Expression(Expression_abc): True sage: SR(1.2).is_algebraic() False + + sage: complex_root_of(x^3 - x^2 - x - 1, 0).is_algebraic() + True """ from sage.rings.qqbar import QQbar try: diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index c3cdacf9fe5..b4947937fd5 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -1298,7 +1298,10 @@ def composition(self, ex, operator): """ func = operator operands = ex.operands() - operand = operands[0] + if len(operands) == 1: + operand = operands[0] + else: + operand = None if isinstance(self.field, UniversalCyclotomicField): QQbar = self.field @@ -1322,6 +1325,7 @@ def composition(self, ex, operator): except TypeError: raise TypeError("unable to convert %r to %s" % (ex, self.field)) res = zeta(rat_arg.denom())**rat_arg.numer() + return self.field(res) elif func_name in ['sin', 'cos', 'tan']: exp_ia = exp(SR(-1).sqrt() * operand, hold=hold)._algebraic_(QQbar) if func_name == 'sin': @@ -1330,6 +1334,7 @@ def composition(self, ex, operator): res = (exp_ia + ~exp_ia) / 2 else: res = -zeta(4) * (exp_ia - ~exp_ia) / (exp_ia + ~exp_ia) + return self.field(res) elif func_name in ['sinh', 'cosh', 'tanh']: if not (SR(-1).sqrt()*operand).is_real(): raise ValueError("unable to represent as an algebraic number") @@ -1340,21 +1345,25 @@ def composition(self, ex, operator): res = (exp_a + ~exp_a) / 2 else: res = (exp_a - ~exp_a) / (exp_a + ~exp_a) + return self.field(res) elif func_name in self.reciprocal_trig_functions: res = ~self.reciprocal_trig_functions[func_name](operand)._algebraic_(QQbar) + return self.field(res) elif func_name == 'complex_root_of': cr = ex._sympy_() poly = cr.poly._sage_() interval = cr._get_interval()._sage_() return self.field.polynomial_root(poly, interval) - else: + elif operand is not None: res = func(operand._algebraic_(self.field)) # We have to handle the case where we get the same symbolic # expression back. For example, QQbar(zeta(7)). See # issue #12665. if (res - ex).is_trivial_zero(): raise TypeError("unable to convert %r to %s" % (ex, self.field)) - return self.field(res) + return self.field(res) + + raise ValueError("unable to represent as an algebraic number") def algebraic(ex, field): From 0f08bae4991baa1dae644fc3938d63d1bd75b002 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 24 Mar 2023 21:13:16 -0400 Subject: [PATCH 14/61] Add "flint" algorithm for integer factorization. We support a few integer factoring algorithms, including PARI (the default), qsieve (via FlintQS), and ECM-GMP. Sage already includes the FLINT library, and FLINT has its own integer factoring routine. This commit adds algorithm="flint" as an option, e.g. sage: ZZ(100).factor(algorithm="flint") To accomplish this, fmpz_factor() was added to sage.libs.flint, and a wrapper factor_using_flint() was added to sage.rings.factorint. The new option was also added to the global factor() function. --- src/sage/arith/misc.py | 7 +++ src/sage/libs/flint/flint_wrap.h | 1 + src/sage/libs/flint/fmpz_factor.pxd | 10 ++++ src/sage/libs/flint/types.pxd | 13 +++- src/sage/rings/factorint.pyx | 92 +++++++++++++++++++++++++++++ src/sage/rings/integer.pyx | 17 +++++- 6 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/sage/libs/flint/fmpz_factor.pxd diff --git a/src/sage/arith/misc.py b/src/sage/arith/misc.py index 763e584c72e..9c671105c5a 100644 --- a/src/sage/arith/misc.py +++ b/src/sage/arith/misc.py @@ -2531,6 +2531,8 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): - ``'pari'`` - (default) use the PARI c library + - ``'flint'`` - use the FLINT library + - ``'kash'`` - use KASH computer algebra system (requires that kash be installed) @@ -2579,6 +2581,11 @@ def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): sage: factor( -next_prime(10^2) * next_prime(10^7) ) -1 * 101 * 10000019 + :: + + sage: factor(293292629867846432923017396246429, algorithm='flint') + 3 * 4852301647696687 * 20148007492971089 + :: sage: factor(-500, algorithm='kash') # optional - kash diff --git a/src/sage/libs/flint/flint_wrap.h b/src/sage/libs/flint/flint_wrap.h index 1bfb23d0182..5c142d21658 100644 --- a/src/sage/libs/flint/flint_wrap.h +++ b/src/sage/libs/flint/flint_wrap.h @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/src/sage/libs/flint/fmpz_factor.pxd b/src/sage/libs/flint/fmpz_factor.pxd new file mode 100644 index 00000000000..f4c51ca3e9c --- /dev/null +++ b/src/sage/libs/flint/fmpz_factor.pxd @@ -0,0 +1,10 @@ +# distutils: libraries = flint +# distutils: depends = flint/fmpz_factor.h + +from sage.libs.flint.types cimport * + +# flint/fmpz_factor.h +cdef extern from "flint_wrap.h": + void fmpz_factor_clear(fmpz_factor_t) + void fmpz_factor_init(fmpz_factor_t) + void fmpz_factor(fmpz_factor_t, const fmpz_t) diff --git a/src/sage/libs/flint/types.pxd b/src/sage/libs/flint/types.pxd index 7208f89d9aa..aee66dc9aa2 100644 --- a/src/sage/libs/flint/types.pxd +++ b/src/sage/libs/flint/types.pxd @@ -1,4 +1,4 @@ -# distutils: depends = flint/flint.h flint/fmpz.h flint/fmpz_poly.h flint/fmpz_mat.h flint/fmpq.h flint/fmpq_poly.h flint/fmpq_mat.h flint/fmpz_mod_poly.h flint/nmod_poly.h flint/fq.h flint/fq_nmod.h flint/ulong_extras.h flint/padic.h flint/padic_poly.h flint/qadic.h flint/fmpz_poly_q.h +# distutils: depends = flint/flint.h flint/fmpz.h flint/fmpz_factor.h flint/fmpz_poly.h flint/fmpz_mat.h flint/fmpq.h flint/fmpq_poly.h flint/fmpq_mat.h flint/fmpz_mod_poly.h flint/nmod_poly.h flint/fq.h flint/fq_nmod.h flint/ulong_extras.h flint/padic.h flint/padic_poly.h flint/qadic.h flint/fmpz_poly_q.h """ Declarations for FLINT types @@ -42,6 +42,17 @@ cdef extern from "flint_wrap.h": ctypedef fmpz_preinvn_struct[1] fmpz_preinvn_t +# flint/fmpz_factor.h: +cdef extern from "flint_wrap.h": + ctypedef struct fmpz_factor_struct: + int sign + fmpz* p + ulong* exp + slong alloc + slong num + + ctypedef fmpz_factor_struct fmpz_factor_t[1] + # flint/fmpz_mod.h: cdef extern from "flint_wrap.h": ctypedef struct fmpz_mod_ctx_struct: diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 3a7e4a3648b..738facf13fb 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -17,8 +17,12 @@ AUTHORS: # http://www.gnu.org/licenses/ #***************************************************************************** +from cysignals.signals cimport sig_check, sig_on, sig_off + from sage.ext.stdsage cimport PY_NEW from sage.libs.gmp.mpz cimport * +from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz, fmpz_get_mpz +from sage.libs.flint.fmpz_factor cimport * from sage.rings.integer cimport Integer from sage.rings.fast_arith import prime_range @@ -350,3 +354,91 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): finally: if prev != debug_level: pari.set_debug_level(prev) + + +def factor_using_flint(n): + r""" + Factor the nonzero integer ``n`` using FLINT. + + This function returns a list of (factor, exponent) pairs. The + factors will be of type ``Integer``, and the exponents will be of + type ``int``. + + INPUT: + + - ``n`` -- a nonzero sage Integer; the number to factor. + + OUTPUT: + + A list of ``(Integer, int)`` pairs representing the factors and + their exponents. + + EXAMPLES:: + + sage: from sage.rings.factorint import factor_using_flint + sage: n = ZZ(9962572652930382) + sage: factors = factor_using_flint(n) + sage: factors + [(2, 1), (3, 1), (1660428775488397, 1)] + sage: prod( f^e for (f,e) in factors ) == n + True + + Negative numbers will have a leading factor of ``(-1)^1``:: + + sage: n = ZZ(-1 * 2 * 3) + sage: factor_using_flint(n) + [(-1, 1), (2, 1), (3, 1)] + + The factorization of unity is empty:: + + sage: factor_using_flint(ZZ.one()) + [] + + While zero has a single factor, of... zero:: + + sage: factor_using_flint(ZZ.zero()) + [(0, 1)] + + TESTS: + + Check that the integers [-10,000, 10,000] are factored correctly:: + + sage: all( + ....: prod( f^e for (f,e) in factor_using_flint(ZZ(c*k)) ) == c*k + ....: for k in range(10000) + ....: for c in [-1, 1] + ....: ) + True + """ + if n.is_zero(): + return [(n, int(1))] + + sig_on() + cdef fmpz_t p + fmpz_init(p) + fmpz_set_mpz(p, (n).value) + + cdef fmpz_factor_t factors + fmpz_factor_init(factors) + fmpz_factor(factors,p) + sig_off() + + pairs = [] + if factors.sign < 0: + # FLINT doesn't return the plus/minus one factor. + pairs.append( (Integer(-1), int(1)) ) + + cdef mpz_t mpz_factor; + for i in range(factors.num): + mpz_init(mpz_factor) + fmpz_get_mpz(mpz_factor, &factors.p[i]) + f = Integer() + mpz_set(f.value, mpz_factor) + mpz_clear(mpz_factor) + e = int(factors.exp[i]) + pairs.append( (f,e) ) + sig_check() + + fmpz_factor_clear(factors) + return pairs + diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 61bcda9cf62..8220e17b1bf 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -3834,6 +3834,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``'pari'`` - (default) use the PARI library + - ``'flint'`` - use the FLINT library + - ``'kash'`` - use the KASH computer algebra system (requires kash) @@ -3899,6 +3901,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: n.factor(limit=1000) 2 * 11 * 41835640583745019265831379463815822381094652231 + An example where FLINT is used:: + + sage: n = 82862385732327628428164127822 + sage: n.factor(algorithm='flint') + 2 * 3 * 11 * 13 * 41 * 73 * 22650083 * 1424602265462161 + We factor using a quadratic sieve algorithm:: sage: p = next_prime(10^20) # optional - sage.libs.pari @@ -3929,7 +3937,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): from sage.structure.factorization import Factorization from sage.structure.factorization_integer import IntegerFactorization - if algorithm not in ['pari', 'kash', 'magma', 'qsieve', 'ecm']: + if algorithm not in ['pari', 'flint', 'kash', 'magma', 'qsieve', 'ecm']: raise ValueError("Algorithm is not known") cdef Integer n, p, unit @@ -3982,6 +3990,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): F.sort() return IntegerFactorization(F, unit=unit, unsafe=True, sort=False, simplify=False) + elif algorithm == 'flint': + from sage.rings.factorint import factor_using_flint + F = factor_using_flint(n) + F.sort() + return IntegerFactorization(F, unit=unit, unsafe=True, + sort=False, simplify=False) + elif algorithm in ['kash', 'magma']: if algorithm == 'kash': from sage.interfaces.kash import kash as I From edcf4b9aab231c599282286e62e674c97bb2aef7 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 25 Mar 2023 14:53:20 -0400 Subject: [PATCH 15/61] Reimplement qsieve() using FLINT's qsieve_factor(). The qsieve() function from sage.interfaces.qsieve uses an old, standalone copy of Bill Hart's quadratic sieve that was moved into its own package, called FlintQS. This implementation isn't terribly reliable by modern standards (just look at the docstring), and it requires maintenance for security issues and to appease newer compilers. However, in the intervening years since FlintQS was forked, a quadratic sieve was added to FLINT itself, as qsieve_factor(). This is a bit slower than FlintQS in general, but returns the right answer much more often. Instead of bringing FlintQS up to date, this commit reimplements sage's qsieve() with FLINT's qsieve_factor(). This entails adding qsieve_factor() to sage.libs.flint, and rewriting qsieve() to call it and process the output. The implementation is very similar to factor(n, algorithm="flint"). The output type of the function has necessarily changed, since we now provide not only the factors but their exponents as well. --- src/sage/interfaces/qsieve.py | 289 ------------------------------- src/sage/interfaces/qsieve.pyx | 69 ++++++++ src/sage/libs/flint/flint_wrap.h | 1 + src/sage/libs/flint/qsieve.pxd | 8 + src/sage/rings/integer.pyx | 7 +- 5 files changed, 82 insertions(+), 292 deletions(-) delete mode 100644 src/sage/interfaces/qsieve.py create mode 100644 src/sage/interfaces/qsieve.pyx create mode 100644 src/sage/libs/flint/qsieve.pxd diff --git a/src/sage/interfaces/qsieve.py b/src/sage/interfaces/qsieve.py deleted file mode 100644 index aff8ef1c165..00000000000 --- a/src/sage/interfaces/qsieve.py +++ /dev/null @@ -1,289 +0,0 @@ -""" -Interface to Bill Hart's Quadratic Sieve -""" - -import os -import subprocess as sp - -import sage.rings.integer - -from sage.cpython.string import bytes_to_str -from sage.misc.temporary_file import tmp_dir - - -def qsieve(n, block=True, time=False, verbose=False): - r""" - Run Hart's quadratic sieve and return the distinct proper factors - of the integer n that it finds. - - CONDITIONS: - - The conditions for the quadratic sieve to work are as follows: - - - No small factors - - Not a perfect power - - Not prime - - If any of these fails, the sieve will also. - - - INPUT: - - - n -- an integer with at least 40 digits - - block -- (default: True) if True, you must wait until the - sieve computation is complete before using Sage further. - If False, Sage will run while the sieve computation - runs in parallel. If q is the returned object, use - q.quit() to terminate a running factorization. - - time -- (default: False) if True, time the command using - the UNIX "time" command (which you might have to install). - - verbose -- (default: False) if True, print out verbose - logging information about what happened during - the Sieve run (for non-blocking Sieve, verbose information - is always available via the log() method.) - - OUTPUT: - - - list -- a list of the distinct proper factors of n found - - str -- the time in cpu seconds that the computation took, as given - by the command line time command. (If time is False, - this is always an empty string.) - - EXAMPLES:: - - sage: k = 19; n = next_prime(10^k)*next_prime(10^(k+1)) - sage: factor(n) # (currently) uses PARI - 10000000000000000051 * 100000000000000000039 - sage: v, t = qsieve(n, time=True) # uses qsieve; optional - time - sage: v # optional - time - [10000000000000000051, 100000000000000000039] - sage: t # random; optional - time - '0.36 real 0.19 user 0.00 sys' - """ - Z = sage.rings.integer.Integer - n = Z(n) - if len(str(n)) < 40: - raise ValueError("n must have at least 40 digits") - if block: - return qsieve_block(n, time, verbose) - else: - return qsieve_nonblock(n, time) - -def qsieve_block(n, time, verbose=False): - """ - Compute the factorization of n using Hart's quadratic Sieve - blocking until complete. - """ - - cmd = ['QuadraticSieve'] - if time: - cmd = ['time'] + cmd - - env = os.environ.copy() - env['TMPDIR'] = tmp_dir('qsieve') - p = sp.Popen(cmd, env=env, stdout=sp.PIPE, stderr=sp.STDOUT, - stdin=sp.PIPE, encoding='latin1') - out, err = p.communicate(str(n)) - z = data_to_list(out, n, time=time) - if verbose: - print(z[-1]) - return z[:2] - -def data_to_list(out, n, time): - """ - Convert output of Hart's sieve and n to a list and time. - - INPUT: - - - out -- snapshot of text output of Hart's QuadraticSieve program - - n -- the integer being factored - - OUTPUT: - - - list -- proper factors found so far - - str -- time information - """ - i = out.find('FACTORS:') - if i == -1: - return [], '', out # whole thing - else: - verbose = out[:i] - out = out[i+len('FACTORS:')+1:].strip() - if time: - w = out.split('\n') - for i in range(len(w)): - if 'user' in w[i]: - break - if i < len(w): - t = w[i].strip() - out = '\n'.join(w[j] for j in range(i)) - else: - t = '' - else: - t = '' - Z = sage.rings.integer.Integer - v = out.split() - v = sorted(set([Z(m) for m in v if Z(m) != n])) - return v, t, verbose - - -from sage.interfaces.sagespawn import SageSpawn -import pexpect -from . import quit -class qsieve_nonblock: - """ - A non-blocking version of Hart's quadratic sieve. - - The sieve starts running when you create the object, but you can - still use Sage in parallel. - - EXAMPLES:: - - sage: k = 19; n = next_prime(10^k)*next_prime(10^(k+1)) - sage: q = qsieve(n, block=False, time=True) # optional - time - sage: q # random output; optional - time - Proper factors so far: [] - sage: q # random output; optional - time - ([10000000000000000051, 100000000000000000039], '0.21') - sage: q.list() # random output; optional - time - [10000000000000000051, 100000000000000000039] - sage: q.time() # random output; optional - time - '0.21' - - sage: q = qsieve(next_prime(10^20)*next_prime(10^21), block=False) - sage: q # random output - Proper factors so far: [100000000000000000039, 1000000000000000000117] - sage: q # random output - [100000000000000000039, 1000000000000000000117] - """ - def __init__(self, n, time): - self._n = n - if time: - cmd = 'time QuadraticSieve' - else: - cmd = 'QuadraticSieve' - env = os.environ.copy() - env['TMPDIR'] = tmp_dir('qsieve') - self._p = SageSpawn(cmd, env=env) - quit.register_spawned_process(self._p.pid, 'QuadraticSieve') - self._p.sendline(str(self._n)+'\n\n\n') - self._done = False - self._out = '' - self._time = '' - self._do_time = time - - def n(self): - """ - Return the integer that is being factored. - """ - return self._n - - def pid(self): - """ - Return the PIN id of the QuadraticSieve process (actually - of the time process that spawns the sieve process). - """ - return self._p.pid - - def done(self): - """ - Return True if the sieve process has completed. - """ - return self._done - - def __repr__(self): - """ - Return a text representation of self. - """ - if self._done: - if hasattr(self, '_killed') and self._killed: - return "Factorization was terminated early." - v = data_to_list(self._get(), self._n, self._do_time) - if self._do_time: - return str(v[:2]) - else: - return str(v[0]) - else: - return 'Proper factors so far: %s'%self.list() - - def cputime(self): - """ - Return the time in seconds (as a string) that it took to - factor n, or return '?' if the factorization has not - completed or the time is unknown. - """ - if not self._do_time: - raise ValueError("you have to start the sieve with the option time=True in order to get timing information") - try: - return data_to_list(self._get(), self._n, self._do_time)[1] - except IndexError: - return '?' - time = cputime - - def log(self): - """ - Return all output of running the sieve so far. - """ - return self._get() - - def __getitem__(self, i): - """ - Return the i-th factor (in sorted order) found so far. - """ - return self.list()[i] - - def __len__(self): - """ - Return the number of factors found so far. If q is the - Sieve object, type len(q) to see the number of factors. - """ - return len(self.list()) - - def list(self): - """ - Return a list of the factors found so far, as Sage - integers. - """ - try: - return data_to_list(self._get(), self._n, self._do_time)[0] - except IndexError: - return [] - - def quit(self): - """ - Terminate the QuadraticSieve process, in case you want - to give up on computing this factorization. - - EXAMPLES:: - - sage: n = next_prime(2^310)*next_prime(2^300) - sage: qs = qsieve(n, block=False) - sage: qs - Proper factors so far: [] - sage: qs.quit() - sage: qs - Factorization was terminated early. - """ - pid = self.pid() - os.killpg(int(pid),9) - #self._p.close() - self._killed = True - self._done = True - - def _get(self, timeout=0.1): - """ - Used internally to get information about what has been - computed so far. - """ - if self._done: - return self._out - e = self._p - try: - e.expect('xxx', timeout=timeout) - except pexpect.TIMEOUT: - pass - except pexpect.EOF: - self._done = True - self._p.close() - self._out += bytes_to_str(e.before) - return self._out diff --git a/src/sage/interfaces/qsieve.pyx b/src/sage/interfaces/qsieve.pyx new file mode 100644 index 00000000000..4935ad7f73a --- /dev/null +++ b/src/sage/interfaces/qsieve.pyx @@ -0,0 +1,69 @@ +""" +Interface to FLINT's ``qsieve_factor()``. This used to interact +with an external "QuadraticSieve" program, but its functionality has +been absorbed into flint. +""" + +from cysignals.signals cimport sig_check, sig_on, sig_off + +from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz, fmpz_get_mpz +from sage.libs.flint.fmpz_factor cimport * +from sage.libs.flint.qsieve cimport * +from sage.libs.gmp.mpz cimport mpz_t, mpz_init, mpz_set, mpz_clear +from sage.rings.integer cimport Integer + +def qsieve(n): + r""" + Factor ``n`` using the quadratic sieve. + + INPUT: + + - ``n`` -- an integer; neither prime nor a perfect power. + + OUTPUT: + + A list of the factors of ``n``. There is no guarantee that the + factors found will be prime, or distinct. + + EXAMPLES:: + + sage: k = 19; n = next_prime(10^k)*next_prime(10^(k+1)) + sage: factor(n) # (currently) uses PARI + 10000000000000000051 * 100000000000000000039 + sage: qsieve(n) + [(10000000000000000051, 1), (100000000000000000039, 1)] + + """ + if n.is_zero(): + return [n] + + n = Integer(n) + + sig_on() + cdef fmpz_t p + fmpz_init(p) + fmpz_set_mpz(p, (n).value) + + cdef fmpz_factor_t factors + fmpz_factor_init(factors) + qsieve_factor(factors,p) + sig_off() + + pairs = [] + if factors.sign < 0: + # FLINT doesn't return the plus/minus one factor. + pairs.append( (Integer(-1), int(1)) ) + + cdef mpz_t mpz_factor; + for i in range(factors.num): + mpz_init(mpz_factor) + fmpz_get_mpz(mpz_factor, &factors.p[i]) + f = Integer() + mpz_set(f.value, mpz_factor) + mpz_clear(mpz_factor) + e = int(factors.exp[i]) + pairs.append( (f,e) ) + sig_check() + + fmpz_factor_clear(factors) + return pairs diff --git a/src/sage/libs/flint/flint_wrap.h b/src/sage/libs/flint/flint_wrap.h index 5c142d21658..266535c3835 100644 --- a/src/sage/libs/flint/flint_wrap.h +++ b/src/sage/libs/flint/flint_wrap.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #undef ulong diff --git a/src/sage/libs/flint/qsieve.pxd b/src/sage/libs/flint/qsieve.pxd new file mode 100644 index 00000000000..ceab7a684a6 --- /dev/null +++ b/src/sage/libs/flint/qsieve.pxd @@ -0,0 +1,8 @@ +# distutils: libraries = flint +# distutils: depends = flint/qsieve.h + +from sage.libs.flint.types cimport * + +# flint/qsieve.h +cdef extern from "flint_wrap.h": + void qsieve_factor(fmpz_factor_t, const fmpz_t) diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 8220e17b1bf..d1651a1af67 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -4014,9 +4014,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): from warnings import warn warn(message, RuntimeWarning, stacklevel=5) from sage.interfaces.qsieve import qsieve - res = [(p, 1) for p in qsieve(n)[0]] - F = IntegerFactorization(res, unit) - return F + F = qsieve(n) + F.sort() + return IntegerFactorization(F, unit=unit, unsafe=True, + sort=False, simplify=False) else: from sage.interfaces.ecm import ecm res = [(p, 1) for p in ecm.factor(n, proof=proof)] From bc06aad2d60c374af39252243b84ee485690fd76 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 25 Mar 2023 14:54:54 -0400 Subject: [PATCH 16/61] Drop obsolete FlintQS package. Now that qsieve() is implemented with the FLINT library, the standalone QuadraticSieve program provided by the FlintQS package is not needed. --- .github/workflows/ci-cygwin-standard.yml | 2 +- COPYING.txt | 1 - build/pkgs/flintqs/SPKG.rst | 14 -------------- build/pkgs/flintqs/checksums.ini | 4 ---- build/pkgs/flintqs/dependencies | 4 ---- build/pkgs/flintqs/distros/arch.txt | 1 - build/pkgs/flintqs/distros/conda.txt | 1 - build/pkgs/flintqs/distros/debian.txt | 1 - build/pkgs/flintqs/distros/freebsd.txt | 1 - build/pkgs/flintqs/distros/gentoo.txt | 1 - build/pkgs/flintqs/distros/nix.txt | 1 - build/pkgs/flintqs/distros/repology.txt | 1 - build/pkgs/flintqs/distros/void.txt | 1 - build/pkgs/flintqs/package-version.txt | 1 - build/pkgs/flintqs/spkg-configure.m4 | 17 ----------------- build/pkgs/flintqs/spkg-install.in | 7 ------- build/pkgs/flintqs/type | 1 - src/doc/en/developer/portability_testing.rst | 2 +- 18 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 build/pkgs/flintqs/SPKG.rst delete mode 100644 build/pkgs/flintqs/checksums.ini delete mode 100644 build/pkgs/flintqs/dependencies delete mode 100644 build/pkgs/flintqs/distros/arch.txt delete mode 100644 build/pkgs/flintqs/distros/conda.txt delete mode 100644 build/pkgs/flintqs/distros/debian.txt delete mode 100644 build/pkgs/flintqs/distros/freebsd.txt delete mode 100644 build/pkgs/flintqs/distros/gentoo.txt delete mode 100644 build/pkgs/flintqs/distros/nix.txt delete mode 100644 build/pkgs/flintqs/distros/repology.txt delete mode 100644 build/pkgs/flintqs/distros/void.txt delete mode 100644 build/pkgs/flintqs/package-version.txt delete mode 100644 build/pkgs/flintqs/spkg-configure.m4 delete mode 100644 build/pkgs/flintqs/spkg-install.in delete mode 100644 build/pkgs/flintqs/type diff --git a/.github/workflows/ci-cygwin-standard.yml b/.github/workflows/ci-cygwin-standard.yml index 53c674028ef..326dd62490e 100644 --- a/.github/workflows/ci-cygwin-standard.yml +++ b/.github/workflows/ci-cygwin-standard.yml @@ -39,7 +39,7 @@ jobs: with: stage: ii-b previous_stages: i-* - targets: singular maxima gap pari gfan palp flintqs arb ecm givaro + targets: singular maxima gap pari gfan palp arb ecm givaro needs: [cygwin-stage-i-a, cygwin-stage-i-b] cygwin-stage-ii-c: diff --git a/COPYING.txt b/COPYING.txt index a785477fb4f..d5c28eacead 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -51,7 +51,6 @@ elliptic_curves None (database) extcode GPLv2+ fflas_ffpack LGPLv2.1+ flint GPLv2+ -flintqs GPLv2+ fplll LGPLv2.1+ freetype FreeType License (similar to BSD; see below) gap GPLv2+ diff --git a/build/pkgs/flintqs/SPKG.rst b/build/pkgs/flintqs/SPKG.rst deleted file mode 100644 index 28e0bed9329..00000000000 --- a/build/pkgs/flintqs/SPKG.rst +++ /dev/null @@ -1,14 +0,0 @@ -flintqs: Multi-polynomial quadratic sieve for integer factorization -=================================================================== - -Description ------------ - -This is William Hart's GPL'd highly optimized multi-polynomial quadratic -sieve for integer factorization: - - http://www.friedspace.com/QS/ - -See also http://www.maths.warwick.ac.uk/~masfaw/preprint.html - -See also the repository: https://github.com/sagemath/FlintQS diff --git a/build/pkgs/flintqs/checksums.ini b/build/pkgs/flintqs/checksums.ini deleted file mode 100644 index 56f20b4607c..00000000000 --- a/build/pkgs/flintqs/checksums.ini +++ /dev/null @@ -1,4 +0,0 @@ -tarball=flintqs-VERSION.tar.bz2 -sha1=9b89246517dae1e1dbbb051323bf9d19da8f99d2 -md5=3a285f1eef304602247ddd8cbc3412df -cksum=2363348369 diff --git a/build/pkgs/flintqs/dependencies b/build/pkgs/flintqs/dependencies deleted file mode 100644 index 42dc0e9c107..00000000000 --- a/build/pkgs/flintqs/dependencies +++ /dev/null @@ -1,4 +0,0 @@ -$(MP_LIBRARY) - ----------- -All lines of this file are ignored except the first. diff --git a/build/pkgs/flintqs/distros/arch.txt b/build/pkgs/flintqs/distros/arch.txt deleted file mode 100644 index 87de35f2830..00000000000 --- a/build/pkgs/flintqs/distros/arch.txt +++ /dev/null @@ -1 +0,0 @@ -flintqs diff --git a/build/pkgs/flintqs/distros/conda.txt b/build/pkgs/flintqs/distros/conda.txt deleted file mode 100644 index 87de35f2830..00000000000 --- a/build/pkgs/flintqs/distros/conda.txt +++ /dev/null @@ -1 +0,0 @@ -flintqs diff --git a/build/pkgs/flintqs/distros/debian.txt b/build/pkgs/flintqs/distros/debian.txt deleted file mode 100644 index 87de35f2830..00000000000 --- a/build/pkgs/flintqs/distros/debian.txt +++ /dev/null @@ -1 +0,0 @@ -flintqs diff --git a/build/pkgs/flintqs/distros/freebsd.txt b/build/pkgs/flintqs/distros/freebsd.txt deleted file mode 100644 index fbb4a5350ad..00000000000 --- a/build/pkgs/flintqs/distros/freebsd.txt +++ /dev/null @@ -1 +0,0 @@ -math/flintqs diff --git a/build/pkgs/flintqs/distros/gentoo.txt b/build/pkgs/flintqs/distros/gentoo.txt deleted file mode 100644 index 2b06251e947..00000000000 --- a/build/pkgs/flintqs/distros/gentoo.txt +++ /dev/null @@ -1 +0,0 @@ -sci-mathematics/flintqs diff --git a/build/pkgs/flintqs/distros/nix.txt b/build/pkgs/flintqs/distros/nix.txt deleted file mode 100644 index 87de35f2830..00000000000 --- a/build/pkgs/flintqs/distros/nix.txt +++ /dev/null @@ -1 +0,0 @@ -flintqs diff --git a/build/pkgs/flintqs/distros/repology.txt b/build/pkgs/flintqs/distros/repology.txt deleted file mode 100644 index 87de35f2830..00000000000 --- a/build/pkgs/flintqs/distros/repology.txt +++ /dev/null @@ -1 +0,0 @@ -flintqs diff --git a/build/pkgs/flintqs/distros/void.txt b/build/pkgs/flintqs/distros/void.txt deleted file mode 100644 index dcc1f9f725f..00000000000 --- a/build/pkgs/flintqs/distros/void.txt +++ /dev/null @@ -1 +0,0 @@ -FlintQS diff --git a/build/pkgs/flintqs/package-version.txt b/build/pkgs/flintqs/package-version.txt deleted file mode 100644 index f9c24f5d4ec..00000000000 --- a/build/pkgs/flintqs/package-version.txt +++ /dev/null @@ -1 +0,0 @@ -1.0.p0 diff --git a/build/pkgs/flintqs/spkg-configure.m4 b/build/pkgs/flintqs/spkg-configure.m4 deleted file mode 100644 index 8b50a817dee..00000000000 --- a/build/pkgs/flintqs/spkg-configure.m4 +++ /dev/null @@ -1,17 +0,0 @@ -SAGE_SPKG_CONFIGURE([flintqs], [ - # The QuadraticSieve program is the only interface to FlintQS that - # sagelib uses. As a result, we don't need to call SAGE_SPKG_DEPCHECK - # here because there's no possibility for a library conflict. - AC_CHECK_PROG(HAVE_QUADRATICSIEVE, QuadraticSieve, yes, no) - - # If we try to just do the obvious thing and swap the return value - # of AC_CHECK_PROG, then ./configure outputs - # - # checking for QuadraticSieve... no - # - # when QuadraticSieve is found... which is not great. - # - AS_IF([test "x$HAVE_QUADRATICSIEVE" = "xyes"], - [sage_spkg_install_flintqs=no], - [sage_spkg_install_flintqs=yes]) -]) diff --git a/build/pkgs/flintqs/spkg-install.in b/build/pkgs/flintqs/spkg-install.in deleted file mode 100644 index fefc1215b37..00000000000 --- a/build/pkgs/flintqs/spkg-install.in +++ /dev/null @@ -1,7 +0,0 @@ -cd src - -export CXXFLAGS="-fomit-frame-pointer -O3 -Wno-sign-compare -Wno-write-strings -I$SAGE_LOCAL/include $CXXFLAGS" - -sdh_configure -sdh_make -sdh_make_install diff --git a/build/pkgs/flintqs/type b/build/pkgs/flintqs/type deleted file mode 100644 index a6a7b9cd726..00000000000 --- a/build/pkgs/flintqs/type +++ /dev/null @@ -1 +0,0 @@ -standard diff --git a/src/doc/en/developer/portability_testing.rst b/src/doc/en/developer/portability_testing.rst index 90b2699bbf4..d289ba347e9 100644 --- a/src/doc/en/developer/portability_testing.rst +++ b/src/doc/en/developer/portability_testing.rst @@ -1055,7 +1055,7 @@ Scrolling down in the right pane shows "Annotations": docker (fedora-31, standard) artifacts/logs-commit-8ca1c2df8f1fb4c6d54b44b34b4d8320ebecb164-tox-docker-fedora-31-standard/config.log#L1 - configure: notice: the following SPKGs did not find equivalent system packages: arb cbc cddlib cmake eclib ecm fflas_ffpack flint flintqs fplll givaro gp + configure: notice: the following SPKGs did not find equivalent system packages: arb cbc cddlib cmake eclib ecm fflas_ffpack flint fplll givaro gp Clicking on the annotations does not take you to a very useful place. To view details, click on one of the items in the pane. This From 1f06bd282beb0bcaa21770451ee1ec475382b97e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 25 Mar 2023 15:13:06 -0400 Subject: [PATCH 17/61] src/sage/misc/citation.pyx: drop qsieve citation. We no longer have a separate "interface" for qsieve(). It now calls a function from the FLINT library, and FLINT is already cited. --- src/sage/misc/citation.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sage/misc/citation.pyx b/src/sage/misc/citation.pyx index 6bd24dd15b7..059589b9c0f 100644 --- a/src/sage/misc/citation.pyx +++ b/src/sage/misc/citation.pyx @@ -23,7 +23,6 @@ systems['Mathematica'] = ['sage.interfaces.mathematica'] systems['MuPAD'] = ['sage.interfaces.mupad'] systems['Octave'] = ['sage.interfaces.octave'] systems['povray'] = ['sage.interfaces.povray'] -systems['qsieve'] = ['sage.interfaces.qsieve'] systems['Macaulay2'] = ['sage.interfaces.macaulay2'] systems['mwrank'] = ['sage.interfaces.mwrank', 'sage.libs.eclib'] systems['matlab'] = ['sage.interfaces.matlab'] From efbe6b14d3fc93b3bdfb8443a33e7292b9084643 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 28 Mar 2023 09:28:31 -0400 Subject: [PATCH 18/61] src/sage/tests/book_stein_ent.py: update qsieve() output. --- src/sage/tests/book_stein_ent.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/tests/book_stein_ent.py b/src/sage/tests/book_stein_ent.py index aac0a11e922..b4f5bfe47d1 100644 --- a/src/sage/tests/book_stein_ent.py +++ b/src/sage/tests/book_stein_ent.py @@ -287,8 +287,7 @@ sage: q = next_prime(randrange(2^97)) sage: n = p * q sage: qsieve(n) # long time (8s on sage.math, 2011) -([6340271405786663791648052309, - 46102313108592180286398757159], '') +[(6340271405786663791648052309, 1), (46102313108592180286398757159, 1)] sage: legendre_symbol(2,3) -1 sage: legendre_symbol(1,3) From ca6503fc3bb488dbede097b1894370e84eb2a1d6 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Tue, 28 Mar 2023 09:29:02 -0400 Subject: [PATCH 19/61] src/doc/en/thematic_tutorials: update material relating to qsieve(). The integer factorization tutorial suggests that qsieve() is the best algorithm, that it is faster than PARI, and that sage's generic factor() should be rewritten to use qsieve() and ecm.factor(). We have toned down these claims: * PARI has gotten much faster and is competitive with qsieve() now that qsieve() is implemented with qsieve_factor() and returns fewer wildly incorrect answers. * I highly doubt that it's obvious which algorithm will work the best before you actually try them, making it very hard to improve on what PARI or FLINT are doing in a generic factor(). The (not tested) timings have also been removed so that we can test the output. Not only are the timings outdated and random, but they aren't even comparatively accurate anymore (for example, PARI doesn't take noticeably longer to factor the integer we give it than qsieve does). In any case, it's nice to check that the examples work. --- .../integer_factorization.rst | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/integer_factorization.rst b/src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/integer_factorization.rst index 24c6c15c21b..810db483bf0 100644 --- a/src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/integer_factorization.rst +++ b/src/doc/en/thematic_tutorials/explicit_methods_in_number_theory/integer_factorization.rst @@ -6,30 +6,24 @@ Quadratic Sieve --------------- Bill Hart's quadratic sieve is included with Sage. The quadratic sieve -is the best algorithm for factoring numbers of the form :math:`pq` up -to around 100 digits. It involves searching for relations, solving a -linear algebra problem modulo :math:`2`, then factoring :math:`n` -using a relation :math:`x^2 \equiv y^2 \mod n`. +is one of the best algorithms for factoring numbers of the form +:math:`pq` up to around 100 digits. It involves searching for +relations, solving a linear algebra problem modulo :math:`2`, then +factoring :math:`n` using a relation :math:`x^2 \equiv y^2 \mod n`. +Using the qsieve algorithm can be faster than the default, which +uses PARI. :: - sage: qsieve(next_prime(2^90)*next_prime(2^91), time=True) # not tested - ([1237940039285380274899124357, 2475880078570760549798248507], - '14.94user 0.53system 0:15.72elapsed 98%CPU (0avgtext+0avgdata 0maxresident)k') - -Using qsieve is twice as fast as Sage's general factor command in -this example. Note that Sage's general factor command does nothing -but call Pari's factor C library function. - -:: - - sage: time factor(next_prime(2^90)*next_prime(2^91)) # not tested - CPU times: user 28.71 s, sys: 0.28 s, total: 28.98 s - Wall time: 29.38 s + sage: n = next_prime(2^90)*next_prime(2^91) + sage: n.factor(algorithm="qsieve") + doctest:... RuntimeWarning: the factorization returned + by qsieve may be incomplete (the factors may not be prime) + or even wrong; see qsieve? for details + 1237940039285380274899124357 * 2475880078570760549798248507 + sage: n.factor() # uses PARI at the time of writing 1237940039285380274899124357 * 2475880078570760549798248507 -Obviously, Sage's factor command should not just call Pari, but -nobody has gotten around to rewriting it yet. GMP-ECM ------- @@ -43,19 +37,14 @@ over :math:`\ZZ/n\ZZ`, and doing arithmetic on that curve--if something goes wrong when doing arithmetic, we factor :math:`n`. -In the following example, GMP-ECM is over 10 times faster than -Sage's generic factor function. Again, this emphasizes that Sage's -generic factor command would benefit from a rewrite that uses -GMP-ECM and qsieve. +In the following example, GMP-ECM is much faster than Sage's generic +factor function. Again, this emphasizes that the best factoring +algorithm may depend on your specific problem. :: - sage: time ecm.factor(next_prime(2^40) * next_prime(2^300)) # not tested - CPU times: user 0.85 s, sys: 0.01 s, total: 0.86 s - Wall time: 1.73 s - [1099511627791, - 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397533] - sage: time factor(next_prime(2^40) * next_prime(2^300)) # not tested - CPU times: user 23.82 s, sys: 0.04 s, total: 23.86 s - Wall time: 24.35 s + sage: n = next_prime(2^40) * next_prime(2^300) + sage: n.factor(algorithm="ecm") + 1099511627791 * 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397533 + sage: n.factor() # uses PARI at the time of writing 1099511627791 * 2037035976334486086268445688409378161051468393665936250636140449354381299763336706183397533 From cfe19b457a5730d5d4e69e4671d3132352578630 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 30 Mar 2023 15:46:27 -0400 Subject: [PATCH 20/61] Move qsieve() from sage.interfaces to sage.libs.flint. This move reflects the recent reimplementation of qsieve() using the FLINT library. A deprecation warning has been added for the old name, and all uses within the sage library have been updated. --- src/doc/en/reference/interfaces/index.rst | 1 - src/doc/en/reference/libs/index.rst | 1 + src/sage/interfaces/all.py | 1 - src/sage/interfaces/qsieve.py | 4 ++++ src/sage/libs/all.py | 2 ++ src/sage/{interfaces => libs/flint}/qsieve.pyx | 0 src/sage/rings/integer.pyx | 2 +- 7 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/sage/interfaces/qsieve.py rename src/sage/{interfaces => libs/flint}/qsieve.pyx (100%) diff --git a/src/doc/en/reference/interfaces/index.rst b/src/doc/en/reference/interfaces/index.rst index 67d69886285..7d030df056d 100644 --- a/src/doc/en/reference/interfaces/index.rst +++ b/src/doc/en/reference/interfaces/index.rst @@ -99,7 +99,6 @@ and testing to make sure nothing funny is going on). sage/interfaces/povray sage/interfaces/psage sage/interfaces/qepcad - sage/interfaces/qsieve sage/interfaces/r sage/interfaces/rubik sage/interfaces/sage0 diff --git a/src/doc/en/reference/libs/index.rst b/src/doc/en/reference/libs/index.rst index fd0295e60c6..0fde7b179e0 100644 --- a/src/doc/en/reference/libs/index.rst +++ b/src/doc/en/reference/libs/index.rst @@ -45,6 +45,7 @@ FLINT sage/libs/flint/flint sage/libs/flint/fmpz_poly sage/libs/flint/arith + sage/libs/flint/qsieve Giac ---- diff --git a/src/sage/interfaces/all.py b/src/sage/interfaces/all.py index bb1d65494e1..1e0623ec4ec 100644 --- a/src/sage/interfaces/all.py +++ b/src/sage/interfaces/all.py @@ -38,7 +38,6 @@ lazy_import('sage.interfaces.povray', 'povray') lazy_import('sage.interfaces.psage', 'PSage') lazy_import('sage.interfaces.qepcad', ['qepcad', 'qepcad_version', 'qepcad_formula']) -lazy_import('sage.interfaces.qsieve', 'qsieve') lazy_import('sage.interfaces.r', ['r', 'R', 'r_version']) lazy_import('sage.interfaces.read_data', 'read_data') lazy_import('sage.interfaces.scilab', 'scilab') diff --git a/src/sage/interfaces/qsieve.py b/src/sage/interfaces/qsieve.py new file mode 100644 index 00000000000..94764b7f76a --- /dev/null +++ b/src/sage/interfaces/qsieve.py @@ -0,0 +1,4 @@ +from sage.misc.superseded import deprecated_function_alias +import sage.libs.flint.qsieve + +qsieve = deprecated_function_alias(1, sage.libs.flint.qsieve.qsieve) diff --git a/src/sage/libs/all.py b/src/sage/libs/all.py index 9fd69e148ff..50423191ca4 100644 --- a/src/sage/libs/all.py +++ b/src/sage/libs/all.py @@ -14,4 +14,6 @@ lazy_import('sage.libs.eclib.mwrank', 'set_precision', 'mwrank_set_precision') lazy_import('sage.libs.eclib.mwrank', 'initprimes', 'mwrank_initprimes') +lazy_import('sage.libs.flint.qsieve', 'qsieve') + lazy_import('sage.libs.giac.giac', 'libgiac') diff --git a/src/sage/interfaces/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx similarity index 100% rename from src/sage/interfaces/qsieve.pyx rename to src/sage/libs/flint/qsieve.pyx diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index d1651a1af67..7bb6dfd52e2 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -4013,7 +4013,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): message = "the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details" from warnings import warn warn(message, RuntimeWarning, stacklevel=5) - from sage.interfaces.qsieve import qsieve + from sage.libs.flint.qsieve import qsieve F = qsieve(n) F.sort() return IntegerFactorization(F, unit=unit, unsafe=True, From 73a0aa3cedbf03f713ebb0300bada211971ef201 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 12:19:18 -0400 Subject: [PATCH 21/61] src/sage/rings/factorint.pyx: fix pycodestyle warnings. --- src/sage/rings/factorint.pyx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 738facf13fb..9291be73bf9 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -428,7 +428,7 @@ def factor_using_flint(n): # FLINT doesn't return the plus/minus one factor. pairs.append( (Integer(-1), int(1)) ) - cdef mpz_t mpz_factor; + cdef mpz_t mpz_factor for i in range(factors.num): mpz_init(mpz_factor) fmpz_get_mpz(mpz_factor, &factors.p[i]) @@ -441,4 +441,3 @@ def factor_using_flint(n): fmpz_factor_clear(factors) return pairs - From 810817bc39e73a56df435ad1609c55ef865a438b Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 12:19:31 -0400 Subject: [PATCH 22/61] src/sage/libs/flint/qsieve.pyx: fix pycodestyle warnings. --- src/sage/libs/flint/qsieve.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 4935ad7f73a..7eab7fc6242 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -54,7 +54,7 @@ def qsieve(n): # FLINT doesn't return the plus/minus one factor. pairs.append( (Integer(-1), int(1)) ) - cdef mpz_t mpz_factor; + cdef mpz_t mpz_factor for i in range(factors.num): mpz_init(mpz_factor) fmpz_get_mpz(mpz_factor, &factors.p[i]) From 378aa6531271343c712a4e039c812919d91390ae Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 17:52:31 -0400 Subject: [PATCH 23/61] src/sage/libs/flint/qsieve.pyx: zero shouldn't have a factorization. To match the behavior of ZZ.zero().factor(), we make qsieve(0) raise an ArithmeticError instead of returning 0^1. --- src/sage/libs/flint/qsieve.pyx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 7eab7fc6242..92fbb518abf 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -33,12 +33,22 @@ def qsieve(n): sage: qsieve(n) [(10000000000000000051, 1), (100000000000000000039, 1)] - """ - if n.is_zero(): - return [n] + TESTS: + + The factorization of zero is undefined, to match the behavior of + ``ZZ.zero().factor()``:: + + sage: qsieve(ZZ.zero()) + Traceback (most recent call last): + ... + ArithmeticError: factorization of 0 is not defined + """ n = Integer(n) + if n.is_zero(): + raise ArithmeticError("factorization of 0 is not defined") + sig_on() cdef fmpz_t p fmpz_init(p) From 2da9dc084f101449e861dff6c1115dc2837c4644 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 20:13:24 -0400 Subject: [PATCH 24/61] src/sage/rings/factorint.pyx: require Integer arg in factor_using_flint(). This is an internal function, so we might as well ensure that the argument is the type that we expect it to be. --- src/sage/rings/factorint.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 9291be73bf9..fc4ddcd2b55 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -356,7 +356,7 @@ def factor_using_pari(n, int_=False, debug_level=0, proof=None): pari.set_debug_level(prev) -def factor_using_flint(n): +def factor_using_flint(Integer n): r""" Factor the nonzero integer ``n`` using FLINT. From 1e32c03154f5b4be262d3f01be4c09447e2e176e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 20:02:22 -0400 Subject: [PATCH 25/61] Tighten sig_on/sig_off in FLINT factorization routines. This makes it more obvious where the long computation takes place. --- src/sage/libs/flint/qsieve.pyx | 2 +- src/sage/rings/factorint.pyx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 92fbb518abf..68744c67c58 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -49,13 +49,13 @@ def qsieve(n): if n.is_zero(): raise ArithmeticError("factorization of 0 is not defined") - sig_on() cdef fmpz_t p fmpz_init(p) fmpz_set_mpz(p, (n).value) cdef fmpz_factor_t factors fmpz_factor_init(factors) + sig_on() qsieve_factor(factors,p) sig_off() diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index fc4ddcd2b55..e252ac06a7b 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -413,13 +413,14 @@ def factor_using_flint(Integer n): if n.is_zero(): return [(n, int(1))] - sig_on() cdef fmpz_t p fmpz_init(p) fmpz_set_mpz(p, (n).value) cdef fmpz_factor_t factors fmpz_factor_init(factors) + + sig_on() fmpz_factor(factors,p) sig_off() From ad48c3e6a0f361cf96ce1d40593e18e03ac5a420 Mon Sep 17 00:00:00 2001 From: Aadya Chinubhai Date: Mon, 3 Apr 2023 14:57:13 +0530 Subject: [PATCH 26/61] removed redundant imports from matrix_modn_dense_float.pyx --- src/sage/matrix/matrix_modn_dense_float.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/matrix/matrix_modn_dense_float.pyx b/src/sage/matrix/matrix_modn_dense_float.pyx index 646570ad65e..cf8b94aaf58 100644 --- a/src/sage/matrix/matrix_modn_dense_float.pyx +++ b/src/sage/matrix/matrix_modn_dense_float.pyx @@ -31,7 +31,7 @@ from sage.libs.linbox.linbox cimport \ from sage.libs.linbox.fflas cimport \ fgemm, pfgemm, fgemv, Det, pDet, Rank, pRank, ReducedRowEchelonForm, pReducedRowEchelonForm, applyP, \ - MinPoly, CharPoly, MinPoly, \ + MinPoly, CharPoly, \ ModFloatDensePolynomial as ModDensePoly ctypedef Poly1Dom[ModField, Dense] ModDensePolyRing From 5bbaf2fdddaac4913eaadea26986b46779c61204 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 2 Apr 2023 22:23:45 -0400 Subject: [PATCH 27/61] Factor out the code for FLINT -> python factorization conversions. Both qsieve() and factor_using_flint() need to convert a fmpz_factor_t to a list of (factor, exponent) pairs. Here we move that functionality into a new C function, fmpz_factor_to_pairlist, under sage.libs.flint. --- src/sage/libs/flint/fmpz_factor.pxd | 2 ++ src/sage/libs/flint/fmpz_factor.pyx | 33 +++++++++++++++++++++++++++++ src/sage/libs/flint/qsieve.pyx | 22 +++---------------- src/sage/rings/factorint.pyx | 20 +++-------------- 4 files changed, 41 insertions(+), 36 deletions(-) create mode 100644 src/sage/libs/flint/fmpz_factor.pyx diff --git a/src/sage/libs/flint/fmpz_factor.pxd b/src/sage/libs/flint/fmpz_factor.pxd index f4c51ca3e9c..b596e0c04b6 100644 --- a/src/sage/libs/flint/fmpz_factor.pxd +++ b/src/sage/libs/flint/fmpz_factor.pxd @@ -8,3 +8,5 @@ cdef extern from "flint_wrap.h": void fmpz_factor_clear(fmpz_factor_t) void fmpz_factor_init(fmpz_factor_t) void fmpz_factor(fmpz_factor_t, const fmpz_t) + +cdef fmpz_factor_to_pairlist(const fmpz_factor_t) diff --git a/src/sage/libs/flint/fmpz_factor.pyx b/src/sage/libs/flint/fmpz_factor.pyx new file mode 100644 index 00000000000..aa335c528db --- /dev/null +++ b/src/sage/libs/flint/fmpz_factor.pyx @@ -0,0 +1,33 @@ +from cysignals.signals cimport sig_check +from sage.libs.flint.fmpz cimport fmpz_get_mpz +from sage.libs.gmp.mpz cimport mpz_t, mpz_init, mpz_set, mpz_clear +from sage.rings.integer cimport Integer + +cdef fmpz_factor_to_pairlist(const fmpz_factor_t factors): + r""" + Helper function that converts a fmpz_factor_t into a list of + (factor, exponent) pairs. The factors are Integers, and the + exponents are Python ints. This is used and indirectly tested by + both :func:`qsieve` and + :func:`sage.rings.factorint.factor_using_flint`. The output + format was ultimately based on that of + :func:`sage.rings.factorint.factor_using_pari`. + """ + cdef list pairs = [] + + if factors.sign < 0: + # FLINT doesn't return the plus/minus one factor. + pairs.append( (Integer(-1), int(1)) ) + + cdef mpz_t mpz_factor + for i in range(factors.num): + mpz_init(mpz_factor) + fmpz_get_mpz(mpz_factor, &factors.p[i]) + f = Integer() + mpz_set(f.value, mpz_factor) + mpz_clear(mpz_factor) + e = int(factors.exp[i]) + pairs.append( (f,e) ) + sig_check() + + return pairs diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 68744c67c58..82ae1f7d996 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -4,12 +4,10 @@ with an external "QuadraticSieve" program, but its functionality has been absorbed into flint. """ -from cysignals.signals cimport sig_check, sig_on, sig_off - -from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz, fmpz_get_mpz +from cysignals.signals cimport sig_on, sig_off +from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz from sage.libs.flint.fmpz_factor cimport * from sage.libs.flint.qsieve cimport * -from sage.libs.gmp.mpz cimport mpz_t, mpz_init, mpz_set, mpz_clear from sage.rings.integer cimport Integer def qsieve(n): @@ -59,21 +57,7 @@ def qsieve(n): qsieve_factor(factors,p) sig_off() - pairs = [] - if factors.sign < 0: - # FLINT doesn't return the plus/minus one factor. - pairs.append( (Integer(-1), int(1)) ) - - cdef mpz_t mpz_factor - for i in range(factors.num): - mpz_init(mpz_factor) - fmpz_get_mpz(mpz_factor, &factors.p[i]) - f = Integer() - mpz_set(f.value, mpz_factor) - mpz_clear(mpz_factor) - e = int(factors.exp[i]) - pairs.append( (f,e) ) - sig_check() + pairs = fmpz_factor_to_pairlist(factors) fmpz_factor_clear(factors) return pairs diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index e252ac06a7b..5e21cc3417d 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -17,11 +17,11 @@ AUTHORS: # http://www.gnu.org/licenses/ #***************************************************************************** -from cysignals.signals cimport sig_check, sig_on, sig_off +from cysignals.signals cimport sig_on, sig_off from sage.ext.stdsage cimport PY_NEW from sage.libs.gmp.mpz cimport * -from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz, fmpz_get_mpz +from sage.libs.flint.fmpz cimport fmpz_t, fmpz_init, fmpz_set_mpz from sage.libs.flint.fmpz_factor cimport * from sage.rings.integer cimport Integer @@ -424,21 +424,7 @@ def factor_using_flint(Integer n): fmpz_factor(factors,p) sig_off() - pairs = [] - if factors.sign < 0: - # FLINT doesn't return the plus/minus one factor. - pairs.append( (Integer(-1), int(1)) ) - - cdef mpz_t mpz_factor - for i in range(factors.num): - mpz_init(mpz_factor) - fmpz_get_mpz(mpz_factor, &factors.p[i]) - f = Integer() - mpz_set(f.value, mpz_factor) - mpz_clear(mpz_factor) - e = int(factors.exp[i]) - pairs.append( (f,e) ) - sig_check() + pairs = fmpz_factor_to_pairlist(factors) fmpz_factor_clear(factors) return pairs From 7a70d48a3fae68cff50ee00c4e79791dceccea7c Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 3 Apr 2023 08:34:40 -0400 Subject: [PATCH 28/61] More pycodestyle tweaks in the new FLINT factorization modules. --- src/sage/libs/flint/fmpz_factor.pyx | 4 ++-- src/sage/libs/flint/qsieve.pyx | 3 ++- src/sage/rings/factorint.pyx | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sage/libs/flint/fmpz_factor.pyx b/src/sage/libs/flint/fmpz_factor.pyx index aa335c528db..4bc4e96a876 100644 --- a/src/sage/libs/flint/fmpz_factor.pyx +++ b/src/sage/libs/flint/fmpz_factor.pyx @@ -17,7 +17,7 @@ cdef fmpz_factor_to_pairlist(const fmpz_factor_t factors): if factors.sign < 0: # FLINT doesn't return the plus/minus one factor. - pairs.append( (Integer(-1), int(1)) ) + pairs.append((Integer(-1), int(1))) cdef mpz_t mpz_factor for i in range(factors.num): @@ -27,7 +27,7 @@ cdef fmpz_factor_to_pairlist(const fmpz_factor_t factors): mpz_set(f.value, mpz_factor) mpz_clear(mpz_factor) e = int(factors.exp[i]) - pairs.append( (f,e) ) + pairs.append((f, e)) sig_check() return pairs diff --git a/src/sage/libs/flint/qsieve.pyx b/src/sage/libs/flint/qsieve.pyx index 82ae1f7d996..780d6f5c150 100644 --- a/src/sage/libs/flint/qsieve.pyx +++ b/src/sage/libs/flint/qsieve.pyx @@ -10,6 +10,7 @@ from sage.libs.flint.fmpz_factor cimport * from sage.libs.flint.qsieve cimport * from sage.rings.integer cimport Integer + def qsieve(n): r""" Factor ``n`` using the quadratic sieve. @@ -54,7 +55,7 @@ def qsieve(n): cdef fmpz_factor_t factors fmpz_factor_init(factors) sig_on() - qsieve_factor(factors,p) + qsieve_factor(factors, p) sig_off() pairs = fmpz_factor_to_pairlist(factors) diff --git a/src/sage/rings/factorint.pyx b/src/sage/rings/factorint.pyx index 5e21cc3417d..77def414b13 100644 --- a/src/sage/rings/factorint.pyx +++ b/src/sage/rings/factorint.pyx @@ -421,7 +421,7 @@ def factor_using_flint(Integer n): fmpz_factor_init(factors) sig_on() - fmpz_factor(factors,p) + fmpz_factor(factors, p) sig_off() pairs = fmpz_factor_to_pairlist(factors) From 537fb136ad718e55581ad2955a79c3f5b2d61829 Mon Sep 17 00:00:00 2001 From: dcoudert Date: Tue, 4 Apr 2023 23:44:24 +0200 Subject: [PATCH 29/61] gh #35437: fix doctests --- src/sage/databases/oeis.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/sage/databases/oeis.py b/src/sage/databases/oeis.py index 509f0c10d46..8dfe567a810 100644 --- a/src/sage/databases/oeis.py +++ b/src/sage/databases/oeis.py @@ -981,7 +981,7 @@ def keywords(self): EXAMPLES:: sage: f = oeis(53) ; f # optional -- internet - A000053: Local stops on New York City Broadway line (IRT #1) subway. + A000053: Local stops on New York City... sage: f.keywords() # optional -- internet ('nonn', 'fini', ...) @@ -1630,13 +1630,15 @@ def cross_references(self, fetch=False): A005598: a(n) = 1 + Sum_{i=1..n} (n-i+1)*phi(i). sage: nbalanced.cross_references() # optional -- internet - ('A049703', 'A049695', 'A103116', 'A000010') + ('A000010', 'A002088', 'A011755', 'A049695', 'A049703', 'A103116') sage: nbalanced.cross_references(fetch=True) # optional -- internet - 0: A049703: a(0) = 0; for n>0, a(n) = A005598(n)/2. - 1: A049695: Array T read by diagonals; ... - 2: A103116: a(n) = Sum_{i=1..n} (n-i+1)*phi(i). - 3: A000010: Euler totient function phi(n): count numbers <= n and prime to n. + 0: A000010: Euler totient function phi(n): count numbers <= n and prime to n. + 1: A002088: Sum of totient function: a(n) = Sum_{k=1..n} phi(k), cf. A000010. + 2: A011755: a(n) = Sum_{k=1..n} k*phi(k). + 3: A049695: Array T read by diagonals; T(i,j) is the number of nonnegative slopes of lines determined by 2 lattice points in [ 0,i ] X [ 0,j ] if i > 0; T(0,j)=1 if j > 0; T(0,0)=0. + 4: A049703: a(0) = 0; for n>0, a(n) = A005598(n)/2. + 5: A103116: a(n) = Sum_{i=1..n} (n-i+1)*phi(i). sage: phi = _[3] # optional -- internet From e47e96f6375922b0159c95a5503da75127c366e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 2 Apr 2023 16:15:05 +0200 Subject: [PATCH 30/61] slight generalisation of MZV auxiliary F-algebra by allowing to start the odd indices at 1 or 3 --- src/sage/modular/multiple_zeta_F_algebra.py | 111 ++++++++++++++------ 1 file changed, 78 insertions(+), 33 deletions(-) diff --git a/src/sage/modular/multiple_zeta_F_algebra.py b/src/sage/modular/multiple_zeta_F_algebra.py index f2b21b9e668..2c0adeb29f5 100644 --- a/src/sage/modular/multiple_zeta_F_algebra.py +++ b/src/sage/modular/multiple_zeta_F_algebra.py @@ -11,6 +11,9 @@ Here we provide a basic direct implementation, endowed with the motivic coproduct. +The similar algebra on generators `f_1`, `f_3`, `f_5`, ... and `f_2` +is now also available. + AUTHORS: - Frédéric Chapoton (2022-09): Initial version @@ -41,40 +44,62 @@ from sage.modules.free_module_element import vector -# the indexing set: (integer power of f_2, word in 3, 5, 7,...) -W_Odds = Words(IntegerRange(3, Infinity, 2), infinite=False) +# the indexing set: (integer power of f_2, word in (1,) 3, 5, 7,...) +def W_Odds(start=3): + """ + Indexing set for the odd generators. + + INPUT: + + - ``start`` -- (default: ``3``) odd start index for odd generators + + EXAMPLES:: + + sage: from sage.modular.multiple_zeta_F_algebra import W_Odds + sage: W_Odds(3) + Finite words over {3, 5, ...} + """ + return Words(IntegerRange(start, Infinity, 2), infinite=False) def str_to_index(x: str) -> tuple: """ Convert a string to an index. - Every letter "2" contributes to the power of `f_2`. Other letters - define a word in `f_3`, `f_5`, ... + Every letter ``"2"`` contributes to the power of `f_2`. Other letters + define a word in (`f_1`,) `f_3`, `f_5`, ... - Usually the letters "2" form a prefix of the input. + Usually the letters ``"2"`` form a prefix of the input. EXAMPLES:: sage: from sage.modular.multiple_zeta_F_algebra import str_to_index sage: str_to_index("22357") (2, [3, 5, 7]) + + sage: str_to_index("22317") + (2, [3, 1, 7]) """ p = x.count("2") w = [int(i) for i in x if i != '2'] return (p, w) -def basis_f_odd_iterator(n) -> Iterator[tuple]: +def basis_f_odd_iterator(n, start=3) -> Iterator[tuple]: """ - Return an iterator over compositions of ``n`` with parts in ``(3,5,7,...)`` + Return an iterator over compositions of ``n`` with odd parts. - This is used to index a basis. + The parts are odd integers at least equal to the odd integer ``start``. + The odd integers allowed are therefore ``3,5,7,9,...`` by default. + + This set of compositions is used to index a basis. INPUT: - ``n`` -- an integer + - ``start`` -- (default: ``3``) odd integer, start index for odd generators + EXAMPLES:: sage: from sage.modular.multiple_zeta_F_algebra import basis_f_odd_iterator @@ -94,18 +119,19 @@ def basis_f_odd_iterator(n) -> Iterator[tuple]: if n == 0: yield tuple() return - if n == 1: - return - if n % 2: + if n % 2 and n >= start: yield (n,) - for k in range(3, n, 2): - for start in basis_f_odd_iterator(n - k): - yield start + (k, ) + for k in range(start, n, 2): + for word in basis_f_odd_iterator(n - k, start=start): + yield word + (k, ) -def basis_f_iterator(n) -> Iterator[tuple]: +def basis_f_iterator(n, start=3) -> Iterator[tuple]: """ - Return an iterator over decompositions of ``n`` using ``2,3,5,7,9,...``. + Return an iterator for decompositions of ``n`` using ``2`` and odd integers. + + The odd integers are taken at least equal to the odd integer ``start``. + The odd integers allowed are therefore ``3,5,7,9,...`` by default. The means that each term is made of a power of 2 and a composition of the remaining integer with parts in ``(3,5,7,...)`` @@ -116,6 +142,8 @@ def basis_f_iterator(n) -> Iterator[tuple]: - ``n`` -- an integer + - ``start`` -- (default: ``3``) odd start index for odd generators + Each term is returned as a pair (integer, word) where the integer is the exponent of 2. @@ -145,21 +173,27 @@ def basis_f_iterator(n) -> Iterator[tuple]: sage: list(basis_f_iterator(0)) [(0, word: )] + sage: list(basis_f_iterator(3, start=1)) + [(0, word: 3), (0, word: 111), (1, word: 1)] """ - if n and n < 2: - return + wodds = W_Odds(start) for k in range(n // 2 + 1): - for start in basis_f_odd_iterator(n - 2 * k): - yield (k, W_Odds(start, check=False)) + for word in basis_f_odd_iterator(n - 2 * k, start): + yield (k, wodds(word, check=False)) -def morphism_constructor(data: dict): - """ +def morphism_constructor(data: dict, start=3): + r""" Build a morphism from the F-algebra to some codomain. INPUT: - a dictionary containing the images of `f_2`, `f_3`, `f_5`, `f_7`, ... + - ``data`` -- a dictionary with integer keys containing the images of + `f_2, f_3, f_5, f_7, \ldots` + + - ``start`` -- (default: 3) start index for odd generators + + If ``start`` is ``1``, the dictionary must also provide the image of `f_1`. OUTPUT: @@ -172,10 +206,10 @@ def morphism_constructor(data: dict): EXAMPLES:: sage: from sage.modular.multiple_zeta_F_algebra import F_algebra, morphism_constructor - sage: F = F_algebra(QQ) sage: Z = Multizeta sage: D = {2: Z(2), 3: Z(3)} sage: rho = morphism_constructor(D) + sage: F = rho.domain() sage: rho(F("2")) ζ(2) sage: rho(F("3")) @@ -187,7 +221,7 @@ def morphism_constructor(data: dict): """ im_f2 = data[2] codomain = im_f2.parent() - domain = F_algebra(codomain.base_ring()) + domain = F_algebra(codomain.base_ring(), start=start) def morphism_on_basis(pw): p, w = pw @@ -211,6 +245,8 @@ class F_algebra(CombinatorialFreeModule): - ``R`` -- ring + - ``start`` -- (default: ``3``) odd start index for odd generators + EXAMPLES:: sage: from sage.modular.multiple_zeta_F_algebra import F_algebra @@ -229,10 +265,16 @@ class F_algebra(CombinatorialFreeModule): sage: s = f2*f3+f5; s f5 + f2*f3 """ - def __init__(self, R): + def __init__(self, R, start=3): r""" Initialize ``self``. + INPUT: + + - ``R`` -- base ring + + - ``start`` -- (default: ``3``) odd start index for odd generators + EXAMPLES:: sage: from sage.modular.multiple_zeta_F_algebra import F_algebra @@ -248,7 +290,10 @@ def __init__(self, R): """ if R not in Rings(): raise TypeError("argument R must be a ring") - Indices = NonNegativeIntegers().cartesian_product(W_Odds) + if start not in [1, 3]: + raise ValueError("argument start must be 1 or 3") + self._start = start + Indices = NonNegativeIntegers().cartesian_product(W_Odds(start)) cat = BialgebrasWithBasis(R).Commutative().Graded() CombinatorialFreeModule.__init__(self, R, Indices, latex_prefix="", prefix='f', @@ -259,7 +304,7 @@ def _repr_term(self, pw) -> str: Return the custom representation of terms. Each monomial is written as a power of `f_2` times a word - in `f_3`, `f_5`, ... + in (`f_1`,) `f_3`, `f_5`, ... EXAMPLES:: @@ -268,7 +313,7 @@ def _repr_term(self, pw) -> str: sage: f2 = F.gen(2) sage: f3 = F.gen(3) sage: f5 = F.gen(5) - sage: f2*f3+f5+f2**2 + sage: f2*f3+f5+f2**2 # indirect doctest f5 + f2*f3 + f2^2 """ p, w = pw @@ -324,7 +369,7 @@ def product_on_basis(self, pw1, pw2): sage: from sage.modular.multiple_zeta_F_algebra import F_algebra sage: A = F_algebra(QQ) sage: W = A.basis().keys() - sage: A.product(A("23"), A("25")) + sage: A.product(A("23"), A("25")) # indirect doctest f2^2*f3f5 + f2^2*f5f3 """ p1, w1 = pw1 @@ -347,7 +392,7 @@ def half_product_on_basis(self, pw1, pw2): sage: from sage.modular.multiple_zeta_F_algebra import F_algebra sage: A = F_algebra(QQ) sage: W = A.basis().keys() - sage: t = A.half_product(A("23"), A("25")); t + sage: t = A.half_product(A("23"), A("25")); t # indirect doctest f2^2*f3f5 TESTS:: @@ -530,7 +575,7 @@ def homogeneous_from_vector(self, vec, N): if isinstance(vec, (list, tuple)): vec = vector(vec) return self.sum(cf * self.monomial(bi) - for cf, bi in zip(vec, basis_f_iterator(N))) + for cf, bi in zip(vec, basis_f_iterator(N, self._start))) def _element_constructor_(self, x): r""" @@ -706,7 +751,7 @@ def homogeneous_to_vector(self): a, b = next(iter(self))[0] N = 2 * a + sum(int(x) for x in b) return vector(BR, [self.coefficient(b) - for b in basis_f_iterator(N)]) + for b in basis_f_iterator(N, self.parent()._start)]) def without_f2(self): """ From d9edc527b634296ae431362d0bcae1e5200ae191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Wed, 5 Apr 2023 08:45:48 +0200 Subject: [PATCH 31/61] reformulate the doc --- src/sage/modular/multiple_zeta_F_algebra.py | 48 +++++++++++---------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/sage/modular/multiple_zeta_F_algebra.py b/src/sage/modular/multiple_zeta_F_algebra.py index 2c0adeb29f5..fe81bc4ffdb 100644 --- a/src/sage/modular/multiple_zeta_F_algebra.py +++ b/src/sage/modular/multiple_zeta_F_algebra.py @@ -11,8 +11,9 @@ Here we provide a basic direct implementation, endowed with the motivic coproduct. -The similar algebra on generators `f_1`, `f_3`, `f_5`, ... and `f_2` -is now also available. +The similar algebra where the shuffle algebra has generators +`f_1, f_3, f_5, \ldots` is now also available. The implementation is even more +general, allowing any positive odd integer as start index. AUTHORS: @@ -44,11 +45,14 @@ from sage.modules.free_module_element import vector -# the indexing set: (integer power of f_2, word in (1,) 3, 5, 7,...) def W_Odds(start=3): - """ + r""" Indexing set for the odd generators. + This is the set of pairs + (integer power of `f_2`, word in `s, s+2, s+4, \ldots`) + where `s` is the chosen odd start index. + INPUT: - ``start`` -- (default: ``3``) odd start index for odd generators @@ -63,11 +67,11 @@ def W_Odds(start=3): def str_to_index(x: str) -> tuple: - """ + r""" Convert a string to an index. Every letter ``"2"`` contributes to the power of `f_2`. Other letters - define a word in (`f_1`,) `f_3`, `f_5`, ... + are odd and define a word in `f_1, f_3, f_5, \ldots` Usually the letters ``"2"`` form a prefix of the input. @@ -86,11 +90,11 @@ def str_to_index(x: str) -> tuple: def basis_f_odd_iterator(n, start=3) -> Iterator[tuple]: - """ + r""" Return an iterator over compositions of ``n`` with odd parts. - The parts are odd integers at least equal to the odd integer ``start``. - The odd integers allowed are therefore ``3,5,7,9,...`` by default. + Let `s` be the chosen odd start index. The allowed parts are the + odd integers at least equal to `s`, in the set `s,s+2,s+4,s+6,\ldots`. This set of compositions is used to index a basis. @@ -127,14 +131,14 @@ def basis_f_odd_iterator(n, start=3) -> Iterator[tuple]: def basis_f_iterator(n, start=3) -> Iterator[tuple]: - """ + r""" Return an iterator for decompositions of ``n`` using ``2`` and odd integers. - The odd integers are taken at least equal to the odd integer ``start``. - The odd integers allowed are therefore ``3,5,7,9,...`` by default. + Let `s` be the chosen odd start index. The allowed odd parts are the + odd integers at least equal to `s`, in the set `s,s+2,s+4,s+6,\ldots`. The means that each term is made of a power of 2 and a composition - of the remaining integer with parts in ``(3,5,7,...)`` + of the remaining integer with parts in `(s,s+2,s+4,\ldots)`. This set is indexing a basis of the homogeneous component of weight ``n``. @@ -186,15 +190,15 @@ def morphism_constructor(data: dict, start=3): r""" Build a morphism from the F-algebra to some codomain. + Let `s` be the chosen odd start index. + INPUT: - ``data`` -- a dictionary with integer keys containing the images of - `f_2, f_3, f_5, f_7, \ldots` + `f_2, f_s, f_{s+2}, f_{s+4}, \ldots` - ``start`` -- (default: 3) start index for odd generators - If ``start`` is ``1``, the dictionary must also provide the image of `f_1`. - OUTPUT: the unique morphism defined by the dictionary ``data`` @@ -273,7 +277,7 @@ def __init__(self, R, start=3): - ``R`` -- base ring - - ``start`` -- (default: ``3``) odd start index for odd generators + - ``start`` -- (default: ``3``) odd start index for odd generators EXAMPLES:: @@ -290,8 +294,8 @@ def __init__(self, R, start=3): """ if R not in Rings(): raise TypeError("argument R must be a ring") - if start not in [1, 3]: - raise ValueError("argument start must be 1 or 3") + if not start % 2 and start > 0: + raise ValueError("argument start must be odd and positive") self._start = start Indices = NonNegativeIntegers().cartesian_product(W_Odds(start)) cat = BialgebrasWithBasis(R).Commutative().Graded() @@ -300,11 +304,11 @@ def __init__(self, R, start=3): category=cat) def _repr_term(self, pw) -> str: - """ + r""" Return the custom representation of terms. Each monomial is written as a power of `f_2` times a word - in (`f_1`,) `f_3`, `f_5`, ... + in `f_1, f_3, f_5, \ldots`. EXAMPLES:: @@ -450,7 +454,7 @@ def gen(self, i): f2 = self.monomial(self._indices((1, []))) if i == 2: return f2 - # now i odd >= 3 + # now i odd >= start if i % 2: return self.monomial(self._indices((0, [i]))) # now powers of f2 From 80a350509f101260a20d450db1d6472f9d5508c6 Mon Sep 17 00:00:00 2001 From: Karan Handa Date: Thu, 6 Apr 2023 22:47:38 +0530 Subject: [PATCH 32/61] Add modules to modules/index.rst Add vector_numpy_integer_dense and vector_numpy_dense so that hyperlinks work again. --- src/doc/en/reference/modules/index.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/doc/en/reference/modules/index.rst b/src/doc/en/reference/modules/index.rst index c6109643c35..387da1b62d0 100644 --- a/src/doc/en/reference/modules/index.rst +++ b/src/doc/en/reference/modules/index.rst @@ -106,6 +106,8 @@ Vectors sage/modules/vector_callable_symbolic_dense sage/modules/vector_double_dense sage/modules/vector_real_double_dense + sage/modules/vector_numpy_dense + sage/modules/vector_numpy_integer_dense sage/modules/vector_complex_double_dense sage/modules/complex_double_vector sage/modules/real_double_vector From 9549887c3ffa67f902a88b1dd966514530e754ea Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Thu, 6 Apr 2023 17:41:29 -0400 Subject: [PATCH 33/61] src/sage/libs/flint/fmpz_factor.pyx: simplify fmpz_factor_to_pairlist(). There's no need for intermediate GMP integers in this function. --- src/sage/libs/flint/fmpz_factor.pyx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/sage/libs/flint/fmpz_factor.pyx b/src/sage/libs/flint/fmpz_factor.pyx index 4bc4e96a876..1d49e8ac22b 100644 --- a/src/sage/libs/flint/fmpz_factor.pyx +++ b/src/sage/libs/flint/fmpz_factor.pyx @@ -1,6 +1,5 @@ from cysignals.signals cimport sig_check from sage.libs.flint.fmpz cimport fmpz_get_mpz -from sage.libs.gmp.mpz cimport mpz_t, mpz_init, mpz_set, mpz_clear from sage.rings.integer cimport Integer cdef fmpz_factor_to_pairlist(const fmpz_factor_t factors): @@ -19,13 +18,9 @@ cdef fmpz_factor_to_pairlist(const fmpz_factor_t factors): # FLINT doesn't return the plus/minus one factor. pairs.append((Integer(-1), int(1))) - cdef mpz_t mpz_factor for i in range(factors.num): - mpz_init(mpz_factor) - fmpz_get_mpz(mpz_factor, &factors.p[i]) f = Integer() - mpz_set(f.value, mpz_factor) - mpz_clear(mpz_factor) + fmpz_get_mpz(f.value, &factors.p[i]) e = int(factors.exp[i]) pairs.append((f, e)) sig_check() From b166754b253eb41cb3bffd6071937a719acafd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Wed, 5 Apr 2023 10:43:59 -0300 Subject: [PATCH 34/61] Fix construction functor for p-adic relaxed types. The precision for relaxed p-adics has 3 components: `(default_prec, halting_prec, secure)` where the last one `secure` is a boolean defaulting to `False`. However, the `construction()` method doesn't know about it: ``` sage: K = QpER(5, secure=True) sage: K.construction(forbid_frac_field=True) (Completion[5, prec=(20, 40)], Rational Field) sage: R = ZpER(5, secure=True) sage: R.construction() (Completion[5, prec=(20, 40)], Integer Ring) ``` This has two undesired consequences for the `change()` method: a. The `secure` attribute is not copied: ``` sage: K.is_secure() True sage: K.change().is_secure() False sage: R.is_secure() True sage: R.change().is_secure() False ``` b. The `check=False` option is broken: ``` sage: K.change(check=False) ... ValueError: not enough values to unpack (expected 3, got 2) sage: R.change(check=False) ... ValueError: not enough values to unpack (expected 3, got 2) ``` Fixing the `construction()` method solves both issues. After this commit: ``` sage: K = QpER(5, secure=True) sage: K.construction(forbid_frac_field=True) (Completion[5, prec=(20, 40, True)], Rational Field) sage: K.change().is_secure() True sage: K.change(check=False) 5-adic Field handled with relaxed arithmetics sage: K.change(check=False).is_secure() True sage: R = ZpER(5, secure=True) sage: R.construction() (Completion[5, prec=(20, 40, True)], Integer Ring) sage: R.change().is_secure() True sage: R.change(check=False) 5-adic Ring handled with relaxed arithmetics sage: R.change(check=False).is_secure() True ``` --- src/sage/rings/padics/generic_nodes.py | 16 ++++++++++++++-- src/sage/rings/padics/local_generic.py | 19 +++++++++++++++++++ src/sage/rings/padics/padic_generic.py | 6 ++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/padics/generic_nodes.py b/src/sage/rings/padics/generic_nodes.py index 3c5d9c2aaf5..6d666302d27 100644 --- a/src/sage/rings/padics/generic_nodes.py +++ b/src/sage/rings/padics/generic_nodes.py @@ -1423,13 +1423,19 @@ def construction(self, forbid_frac_field=False): sage: S = F(Z) sage: S._precision_cap() (31, 41) + + The `secure` attribute for relaxed type is included in the functor:: + + sage: R = ZpER(5, secure=True) + sage: R.construction() + (Completion[5, prec=(20, 40, True)], Integer Ring) """ from sage.categories.pushout import CompletionFunctor extras = {'print_mode':self._printer.dict(), 'type':self._prec_type(), 'names':self._names} if hasattr(self, '_label'): extras['label'] = self._label if self._prec_type() == "relaxed": - prec = (self._default_prec, self._halting_prec) + prec = (self._default_prec, self._halting_prec, self._secure) else: prec = self._precision_cap() return (CompletionFunctor(self.prime(), prec, extras), ZZ) @@ -1595,6 +1601,12 @@ def construction(self, forbid_frac_field=False): sage: S = F(Z) sage: S._precision_cap() (31, 41) + + The `secure` attribute for relaxed type is included in the functor:: + + sage: K = QpER(5, secure=True) + sage: K.construction(forbid_frac_field=True) + (Completion[5, prec=(20, 40, True)], Rational Field) """ from sage.categories.pushout import FractionField, CompletionFunctor if forbid_frac_field: @@ -1602,7 +1614,7 @@ def construction(self, forbid_frac_field=False): if hasattr(self, '_label'): extras['label'] = self._label if self._prec_type() == "relaxed": - prec = (self._default_prec, self._halting_prec) + prec = (self._default_prec, self._halting_prec, self._secure) else: prec = self._precision_cap() return (CompletionFunctor(self.prime(), prec, extras), QQ) diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py index 2168d2e348b..df8487c609d 100644 --- a/src/sage/rings/padics/local_generic.py +++ b/src/sage/rings/padics/local_generic.py @@ -375,6 +375,25 @@ def change(self, **kwds): 37-adic Ring with lattice-cap precision (label: change) sage: S.change(label = "new") 37-adic Ring with lattice-cap precision (label: new) + + + TESTS: + + The `secure` attribute for relaxed type is copied:: + + sage: R = ZpER(5, secure=True); R + 5-adic Ring handled with relaxed arithmetics + sage: K = R.change(field=True); K + 5-adic Field handled with relaxed arithmetics + sage: K.is_secure() + True + + The `check=False` option works for relaxed type:: + + sage: R = ZpER(5) ; R + 5-adic Ring handled with relaxed arithmetics + sage: K = R.change(field=True, check=False) ; K + 5-adic Field handled with relaxed arithmetics """ # We support both print_* and * for *=mode, pos, sep, alphabet for atr in ('print_mode', 'print_pos', 'print_sep', 'print_alphabet'): diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index 2f9c2195720..56ee6610d0d 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -478,6 +478,12 @@ def integer_ring(self, print_mode=None): 2-adic Ring with lattice-cap precision (label: test) sage: R.integer_ring({'mode':'series'}) is R True + + The `secure` attribute for relaxed type is preserved:: + + sage: K = QpER(5, secure=True) + sage: K.integer_ring().is_secure() + True """ # Currently does not support fields with non integral defining # polynomials. This should change when the padic_general_extension From 1d0a04a6958eda4dea923b2fe6615c7086ce5f82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Thu, 6 Apr 2023 14:06:45 -0300 Subject: [PATCH 35/61] Run TestSuite for padic relaxed types with secure=True --- src/sage/rings/padics/padic_base_leaves.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py index 7963a442f97..3c382fd292b 100644 --- a/src/sage/rings/padics/padic_base_leaves.py +++ b/src/sage/rings/padics/padic_base_leaves.py @@ -1128,6 +1128,8 @@ def __init__(self, p, prec, print_mode, names): sage: R = ZpER(7) sage: TestSuite(R).run(skip=['_test_log', '_test_matrix_smith']) + sage: R = ZpER(7, secure=True) + sage: TestSuite(R).run(skip=['_test_log', '_test_matrix_smith']) """ from sage.rings.padics import padic_relaxed_element self._default_prec, self._halting_prec, self._secure = prec @@ -1163,6 +1165,8 @@ def __init__(self, p, prec, print_mode, names): sage: K = QpER(7) sage: TestSuite(K).run(skip=['_test_log', '_test_matrix_smith']) + sage: K = QpER(7, secure=True) + sage: TestSuite(K).run(skip=['_test_log', '_test_matrix_smith']) """ from sage.rings.padics import padic_relaxed_element self._default_prec, self._halting_prec, self._secure = prec From 18d6640d8b9e4586094b88588fb3f401d10b7bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Mon, 27 Feb 2023 15:19:47 -0300 Subject: [PATCH 36/61] Make Qp.integer_ring() faster. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The method pAdicGeneric.integer_ring() uses LocalGeneric.change() to turn a p-adic field into a p-adic ring. The latter calls a factory function which, by default, checks primality of p. However, when p came from a Qp this step is not necessary. We avoid it by adding `check=False` to the call to `LocalGeneric.change()` in `pAdicGeneric.integer_ring()`. This results in significant time savings for large primes, e.g. in the current test suite: Before this commit: ``` sage: R = Qp(next_prime(10^60)) sage: timeit('R.integer_ring()') 25 loops, best of 3: 22.2 ms per loop sage: %time TestSuite(R).run() CPU times: user 14.4 s, sys: 44 µs, total: 14.4 s Wall time: 14.4 s ``` After this commit: ``` sage: R = Qp(next_prime(10^60)) sage: timeit('R.integer_ring()') 625 loops, best of 3: 68 μs per loop sage: %time TestSuite(R).run() CPU times: user 714 ms, sys: 239 µs, total: 715 ms Wall time: 717 ms ``` Doctest of `padic_base_leaves.py` goes down from ~33 to ~5 seconds. --- src/sage/rings/padics/padic_generic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index 56ee6610d0d..93756aeb772 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -491,7 +491,7 @@ def integer_ring(self, print_mode=None): if not self.is_field() and print_mode is None: return self if print_mode is None: - return self.change(field=False) + return self.change(field=False, check=False) else: from sage.misc.superseded import deprecation deprecation(23227, "Use the change method if you want to change print options in integer_ring()") From fc3735d872162cea51514983bf2d14eb8d9bce2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gonzalo=20Tornar=C3=ADa?= Date: Thu, 6 Apr 2023 18:21:30 -0300 Subject: [PATCH 37/61] Don't call `sylvester_matrix` with zero polynomials --- src/sage/rings/polynomial/multi_polynomial.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 2f4d0dba284..bf82d922f28 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -1390,8 +1390,8 @@ cdef class MPolynomial(CommutativePolynomial): If both polynomials are of positive degree with respect to variable, the determinant of the Sylvester matrix is the resultant:: - sage: f = R.random_element(4) - sage: g = R.random_element(4) + sage: f = R.random_element(4) or (x^2 * y^2) + sage: g = R.random_element(4) or (x^2 * y^2) sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) True From 0f61ef0fea5deafb2fd8c6984369537dbb7ed58b Mon Sep 17 00:00:00 2001 From: Lorenz Panny Date: Mon, 13 Mar 2023 15:10:46 +0800 Subject: [PATCH 38/61] add .conductor() and .order_of_conductor() methods for orders in quadratic fields --- src/sage/rings/number_field/number_field.py | 25 ++++++++++++ src/sage/rings/number_field/order.py | 45 ++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index b696759489f..3bf7c97c616 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -12175,6 +12175,31 @@ def number_of_roots_of_unity(self): return 6 return 2 + def order_of_conductor(self, f): + r""" + Return the unique order with the given conductor in this quadratic field. + + .. SEEALSO :: + + :meth:`sage.rings.number_field.order.Order.conductor` + + EXAMPLES:: + + sage: K. = QuadraticField(-123) + sage: K.order_of_conductor(1) is K.maximal_order() + True + sage: K.order_of_conductor(2).gens() + (1, t) + sage: K.order_of_conductor(44).gens() + (1, 22*t) + sage: K.order_of_conductor(9001).conductor() + 9001 + """ + f = ZZ(f) + if f <= 0: + raise ValueError('conductor must be a positive integer') + return self.order([f * g for g in self.maximal_order().gens()]) + def is_fundamental_discriminant(D): r""" diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index ea8c6d6cfe1..288e4dc83c5 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -1179,6 +1179,44 @@ def __hash__(self): """ return hash((self._K, self._module_rep)) + def conductor(self): + r""" + For orders in *quadratic* number fields, return the conductor + of this order. + + The conductor is the unique positive integer `f` such that + the discriminant of this order is `f^2` times the discriminant + of the containing quadratic field. + + Not implemented for orders in number fields of degree `\neq 2`. + + .. SEEALSO :: + + :meth:`sage.rings.number_field.number_field.NumberField_quadratic.order_of_conductor` + + EXAMPLES:: + + sage: K. = QuadraticField(-101) + sage: K.maximal_order().conductor() + 1 + sage: K.order(5*t).conductor() + 5 + sage: K.discriminant().factor() + -1 * 2^2 * 101 + sage: K.order(5*t).discriminant().factor() + -1 * 2^2 * 5^2 * 101 + + TESTS:: + + sage: type(K.order(5*t).conductor()) + + """ + if not isinstance(self._K, sage.rings.abc.NumberField_quadratic): + raise NotImplementedError('not implemented for number fields of degree != 2') + D = self.discriminant() + D0 = self._K.discriminant() + return (D // D0).sqrt() + def random_element(self, *args, **kwds): r""" Return a random element of this order. @@ -1602,6 +1640,11 @@ def discriminant(self): 3 * 5 * 13^29 * 733 sage: L.discriminant() / O.discriminant() == L.index_in(O)^2 True + + TESTS:: + + sage: type(K.order(5*a).discriminant()) + """ try: return self.__discriminant @@ -1609,7 +1652,7 @@ def discriminant(self): if self._is_maximal(): D = self._K.discriminant() else: - D = self._K.discriminant(self.basis()) + D = ZZ(self._K.discriminant(self.basis())) self.__discriminant = D return D From ed3f38540e9961c6b291ce37badf150ea1d87d54 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Jan 2023 18:25:35 -0800 Subject: [PATCH 39/61] Replace remaining uses of is_SymbolicEquation, is_SymbolicVariable --- src/sage/calculus/calculus.py | 10 +++---- src/sage/calculus/desolvers.py | 33 +++++++++++---------- src/sage/calculus/functional.py | 8 +++-- src/sage/calculus/functions.py | 7 ++--- src/sage/calculus/var.pyx | 6 ++-- src/sage/interfaces/maxima_lib.py | 4 +-- src/sage/symbolic/assumptions.py | 5 ++-- src/sage/symbolic/callable.py | 4 +-- src/sage/symbolic/expression.pyx | 12 ++++---- src/sage/symbolic/expression_conversions.py | 6 ++-- src/sage/symbolic/integration/integral.py | 11 +++---- src/sage/symbolic/operators.py | 3 +- src/sage/symbolic/relation.py | 12 ++++---- 13 files changed, 61 insertions(+), 60 deletions(-) diff --git a/src/sage/calculus/calculus.py b/src/sage/calculus/calculus.py index 20788f956e0..dae380180ac 100644 --- a/src/sage/calculus/calculus.py +++ b/src/sage/calculus/calculus.py @@ -424,9 +424,9 @@ from sage.misc.latex import latex from sage.misc.parser import Parser, LookupNameMaker - -from sage.symbolic.ring import var, SR, is_SymbolicVariable -from sage.symbolic.expression import Expression, symbol_table +from sage.structure.element import Expression +from sage.symbolic.ring import var, SR +from sage.symbolic.expression import symbol_table from sage.symbolic.function import Function from sage.symbolic.function_factory import function_factory from sage.symbolic.integration.integral import (indefinite_integral, @@ -613,7 +613,7 @@ def symbolic_sum(expression, v, a, b, algorithm='maxima', hold=False): the summation the result might not be convertible into a Sage expression. """ - if not is_SymbolicVariable(v): + if not (isinstance(v, Expression) and v.is_symbol()): if isinstance(v, str): v = var(v) else: @@ -879,7 +879,7 @@ def symbolic_product(expression, v, a, b, algorithm='maxima', hold=False): (-1)^n*factorial(n)^2 """ - if not is_SymbolicVariable(v): + if not (isinstance(v, Expression) and v.is_symbol()): if isinstance(v, str): v = var(v) else: diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index 1e5d87de635..27d2e57bf36 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -77,13 +77,12 @@ from sage.interfaces.maxima import Maxima from sage.misc.lazy_import import lazy_import -lazy_import("sage.plot.all", "line") -from sage.symbolic.expression import is_SymbolicEquation -from sage.symbolic.ring import SR, is_SymbolicVariable -from sage.calculus.functional import diff +from sage.symbolic.ring import SR from sage.misc.functional import N from sage.rings.real_mpfr import RealField +from .functional import diff + maxima = Maxima() @@ -550,9 +549,9 @@ def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False, - Robert Bradshaw (10-2008) - Robert Marik (10-2009) """ - if is_SymbolicEquation(de): + if isinstance(de, Expression) and de.is_relational(): de = de.lhs() - de.rhs() - if is_SymbolicVariable(dvar): + if isinstance(dvar, Expression) and dvar.is_symbol(): raise ValueError("You have to declare dependent variable as a function evaluated at the independent variable, eg. y=function('y')(x)") # for backwards compatibility if isinstance(dvar, list): @@ -600,8 +599,9 @@ def sanitize_var(exprs): if show_method: maxima_method=P("method") - if (ics is not None): - if not is_SymbolicEquation(soln.sage()): + soln = soln.sage() + if ics is not None: + if not (isinstance(soln, Expression) and soln.is_relational()): if not show_method: maxima_method=P("method") raise NotImplementedError("Unable to use initial condition for this equation (%s)."%(str(maxima_method).strip())) @@ -649,8 +649,7 @@ def sanitize_var(exprs): if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this BVP. Remove the initial condition to get the general solution.") - soln=soln.sage() - if is_SymbolicEquation(soln) and soln.lhs() == dvar: + if isinstance(soln, Expression) and soln.is_relational() and soln.lhs() == dvar: # Remark: Here we do not check that the right hand side does not depend on dvar. # This probably will not happen for solutions obtained via ode2, anyway. soln = soln.rhs() @@ -796,9 +795,9 @@ def desolve_laplace(de, dvar, ics=None, ivar=None): #return maxima(cmd).rhs()._maxima_init_() ## verbatim copy from desolve - begin - if is_SymbolicEquation(de): + if isinstance(de, Expression) and de.is_relational(): de = de.lhs() - de.rhs() - if is_SymbolicVariable(dvar): + if isinstance(dvar, Expression) and dvar.is_symbol(): raise ValueError("You have to declare dependent variable as a function evaluated at the independent variable, eg. y=function('y')(x)") # for backwards compatibility if isinstance(dvar, list): @@ -959,7 +958,7 @@ def desolve_system(des, vars, ics=None, ivar=None, algorithm="maxima"): return desolve_laplace(des[0], vars[0], ics=ics, ivar=ivar) ivars = set([]) for i, de in enumerate(des): - if not is_SymbolicEquation(de): + if not (isinstance(de, Expression) and de.is_relational()): des[i] = de == 0 ivars = ivars.union(set(de.variables())) if ivar is None: @@ -1206,6 +1205,8 @@ def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): sage: f = lambda z : z[2]; g = lambda z : -sin(z[1]) sage: P = eulers_method_2x2_plot(f,g, 0.0, 0.75, 0.0, 0.1, 1.0) """ + from sage.plot.line import line + n = int((1.0)*(t1-t0)/h) t00 = t0 x00 = x0 @@ -1409,11 +1410,11 @@ def desolve_rk4_inner(de, dvar): YMIN = t return plot_slope_field(de, (ivar,XMIN,XMAX), (dvar,YMIN,YMAX))+R - if not is_SymbolicVariable(dvar): + if not (isinstance(dvar, Expression) and dvar.is_symbol()): from sage.symbolic.ring import SR from sage.calculus.all import diff from sage.symbolic.relation import solve - if is_SymbolicEquation(de): + if isinstance(de, Expression) and de.is_relational(): de = de.lhs() - de.rhs() # consider to add warning if the solution is not unique de=solve(de,diff(dvar,ivar),solution_dict=True) @@ -1706,7 +1707,7 @@ def Dfun(y, t): mxhnil=mxhnil, mxordn=mxordn, mxords=mxords, printmessg=printmessg) return sol - if is_SymbolicVariable(dvars): + if isinstance(dvars, Expression) and dvars.is_symbol(): dvars = [dvars] if not isinstance(des, (list, tuple)): diff --git a/src/sage/calculus/functional.py b/src/sage/calculus/functional.py index 0654118d257..64e5a428118 100644 --- a/src/sage/calculus/functional.py +++ b/src/sage/calculus/functional.py @@ -26,8 +26,8 @@ -a^3 + 3*a^2*x - 3*a*x^2 + x^3 """ -from .calculus import SR -from sage.symbolic.expression import Expression +from sage.structure.element import Expression + def simplify(f): r""" @@ -147,6 +147,7 @@ def derivative(f, *args, **kwds): except AttributeError: pass if not isinstance(f, Expression): + from sage.symbolic.ring import SR f = SR(f) return f.derivative(*args, **kwds) @@ -296,6 +297,7 @@ def integral(f, *args, **kwds): pass if not isinstance(f, Expression): + from sage.symbolic.ring import SR f = SR(f) return f.integral(*args, **kwds) @@ -349,6 +351,7 @@ def limit(f, dir=None, taylor=False, **argv): -limit((erf(x) - 1)*e^(x^2), x, +Infinity) """ if not isinstance(f, Expression): + from sage.symbolic.ring import SR f = SR(f) return f.limit(dir=dir, taylor=taylor, **argv) @@ -392,6 +395,7 @@ def taylor(f, *args): (x - 1)*(y + 1)^3 - 3*(x - 1)*(y + 1)^2 + (y + 1)^3 + 3*(x - 1)*(y + 1) - 3*(y + 1)^2 - x + 3*y + 3 """ if not isinstance(f, Expression): + from sage.symbolic.ring import SR f = SR(f) return f.taylor(*args) diff --git a/src/sage/calculus/functions.py b/src/sage/calculus/functions.py index 6a06f755101..910984cb578 100644 --- a/src/sage/calculus/functions.py +++ b/src/sage/calculus/functions.py @@ -2,9 +2,8 @@ Calculus functions """ from sage.matrix.constructor import matrix -from sage.structure.element import is_Matrix -from sage.structure.element import is_Vector -from sage.symbolic.ring import is_SymbolicVariable +from sage.structure.element import is_Matrix, is_Vector, Expression + from .functional import diff @@ -82,7 +81,7 @@ def wronskian(*args): # a 1x1 Wronskian is just its argument return args[0] else: - if is_SymbolicVariable(args[-1]): + if isinstance(args[-1], Expression) and args[-1].is_symbol(): # if last argument is a variable, peel it off and # differentiate the other args v = args[-1] diff --git a/src/sage/calculus/var.pyx b/src/sage/calculus/var.pyx index ed7a4305188..070728253d6 100644 --- a/src/sage/calculus/var.pyx +++ b/src/sage/calculus/var.pyx @@ -384,10 +384,12 @@ def clear_vars(): sage: k 15 """ + from sage.structure.element import Expression + G = globals() - from sage.symbolic.ring import is_SymbolicVariable for i in list(range(65, 65 + 26)) + list(range(97, 97 + 26)): - if chr(i) in G and is_SymbolicVariable(G[chr(i)]): + chr_i = chr(i) + if chr_i in G and isinstance(G[chr_i], Expression) and G[chr_i].is_symbol(): # We check to see if there is a corresponding pyobject # associated with the expression. This will work for # constants which we want to keep, but will fail for diff --git a/src/sage/interfaces/maxima_lib.py b/src/sage/interfaces/maxima_lib.py index 4ce8963b0be..c263ac65f02 100644 --- a/src/sage/interfaces/maxima_lib.py +++ b/src/sage/interfaces/maxima_lib.py @@ -114,6 +114,7 @@ # https://www.gnu.org/licenses/ # **************************************************************************** +from sage.structure.element import Expression from sage.symbolic.ring import SR from sage.libs.ecl import EclObject, ecl_eval @@ -1615,9 +1616,8 @@ def sr_to_max(expr): # For that, we should change the API of the functions there # (we need to have access to op, not only to expr.operands() if isinstance(op, FDerivativeOperator): - from sage.symbolic.ring import is_SymbolicVariable args = expr.operands() - if (not all(is_SymbolicVariable(v) for v in args) or + if (not all(isinstance(v, Expression) and v.is_symbol() for v in args) or len(args) != len(set(args))): # An evaluated derivative of the form f'(1) is not a # symbolic variable, yet we would like to treat it diff --git a/src/sage/symbolic/assumptions.py b/src/sage/symbolic/assumptions.py index 35c7dcfaeab..7a91bd3aaf1 100644 --- a/src/sage/symbolic/assumptions.py +++ b/src/sage/symbolic/assumptions.py @@ -75,7 +75,7 @@ from sage.rings.rational_field import QQ from sage.rings.real_mpfr import RR from sage.rings.cc import CC -from sage.symbolic.ring import is_SymbolicVariable +from sage.structure.element import Expression from sage.structure.unique_representation import UniqueRepresentation # #30074: We use the keys of a dict to store the assumptions. @@ -427,7 +427,8 @@ def preprocess_assumptions(args): if isinstance(x, str): del args[i] last = x - elif ((not hasattr(x, 'assume') or is_SymbolicVariable(x)) + elif ((not hasattr(x, 'assume') + or (isinstance(x, Expression) and x.is_symbol()) and last is not None): args[i] = GenericDeclaration(x, last) else: diff --git a/src/sage/symbolic/callable.py b/src/sage/symbolic/callable.py index 062a96cb766..4bd17c0ae4e 100644 --- a/src/sage/symbolic/callable.py +++ b/src/sage/symbolic/callable.py @@ -490,11 +490,11 @@ def create_key(self, args, check=True): (x, y) """ if check: - from sage.symbolic.ring import is_SymbolicVariable + from sage.structure.element import Expression if len(args) == 1 and isinstance(args[0], (list, tuple)): args, = args for arg in args: - if not is_SymbolicVariable(arg): + if not (isinstance(arg, Expression) and arg.is_symbol()): raise TypeError("must construct a function with a tuple (or list) of variables") args = tuple(args) return args diff --git a/src/sage/symbolic/expression.pyx b/src/sage/symbolic/expression.pyx index 3526c9a2d7e..f9aa910a37d 100644 --- a/src/sage/symbolic/expression.pyx +++ b/src/sage/symbolic/expression.pyx @@ -613,7 +613,7 @@ def _subs_make_dict(s): """ if isinstance(s, dict): return s - elif is_SymbolicEquation(s): + elif isinstance(s, Expression) and s.is_relational(): if s.operator() is not operator.eq: msg = "can only substitute equality, not inequalities; got {}" raise TypeError(msg.format(s)) @@ -692,7 +692,7 @@ def _subs_fun_make_dict(s): """ if isinstance(s, dict): return dict((k, v) if not isinstance(k, Expression) else (k.operator(), v.function(*k.operands())) for k, v in s.items()) - elif is_SymbolicEquation(s): + elif isinstance(s, Expression) and s.is_relational(): if s.operator() is not operator.eq: msg = "can only substitute equality, not inequalities; got {}" raise TypeError(msg.format(s)) @@ -6807,12 +6807,11 @@ cdef class Expression(Expression_abc): # we override type checking in CallableSymbolicExpressionRing, # since it checks for old SymbolicVariable's # and do the check here instead - from sage.symbolic.callable import CallableSymbolicExpressionRing - from sage.symbolic.ring import is_SymbolicVariable for i in args: - if not is_SymbolicVariable(i): + if not (isinstance(i, Expression) and i.is_symbol()): break else: + from sage.symbolic.callable import CallableSymbolicExpressionRing R = CallableSymbolicExpressionRing(args, check=False) return R(self) raise TypeError(f"must construct a function with symbolic variables as arguments, got {args}.") @@ -12878,7 +12877,6 @@ cdef class Expression(Expression_abc): sage: plot(f,0,1) Graphics object consisting of 1 graphics primitive """ - from sage.symbolic.ring import is_SymbolicVariable from sage.plot.plot import plot # see if the user passed a variable in. @@ -12887,7 +12885,7 @@ cdef class Expression(Expression_abc): else: param = None for i, arg in enumerate(args): - if is_SymbolicVariable(arg): + if isinstance(arg, Expression) and arg.is_symbol(): param = arg args = args[:i] + args[i+1:] break diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index 9b2feeff147..77a10f2d16c 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -579,11 +579,10 @@ def derivative(self, ex, operator): """ # This code should probably be moved into the interface # object in a nice way. - from sage.symbolic.ring import is_SymbolicVariable if self.name_init != "_maxima_init_": raise NotImplementedError args = ex.operands() - if (not all(is_SymbolicVariable(v) for v in args) or + if (not all(isinstance(v, Expression) and v.is_symbol() for v in args) or len(args) != len(set(args))): # An evaluated derivative of the form f'(1) is not a # symbolic variable, yet we would like to treat it like @@ -1103,12 +1102,11 @@ def derivative(self, ex, operator): ,1,1,2 """ - from sage.symbolic.ring import is_SymbolicVariable args = ex.operands() # the arguments the derivative is evaluated at params = operator.parameter_set() params_set = set(params) mult = ",".join(str(params.count(i)) for i in params_set) - if (not all(is_SymbolicVariable(v) for v in args) or + if (not all(isinstance(v, Expression) and v.is_symbol() for v in args) or len(args) != len(set(args))): # An evaluated derivative of the form f'(1) is not a # symbolic variable, yet we would like to treat it like diff --git a/src/sage/symbolic/integration/integral.py b/src/sage/symbolic/integration/integral.py index 34d96b1c731..bef57ef2d4f 100644 --- a/src/sage/symbolic/integration/integral.py +++ b/src/sage/symbolic/integration/integral.py @@ -11,7 +11,8 @@ # (at your option) any later version. # https://www.gnu.org/licenses/ # ****************************************************************************` -from sage.symbolic.ring import SR, is_SymbolicVariable +from sage.structure.element import Expression +from sage.symbolic.ring import SR from sage.symbolic.function import BuiltinFunction ################################################################## @@ -113,7 +114,7 @@ def _eval_(self, f, x): -1/2*x^2*sgn(x) + 3/2*x^2 """ # Check for x - if not is_SymbolicVariable(x): + if not (isinstance(x, Expression) and x.is_symbol()): if len(x.variables()) == 1: nx = x.variables()[0] f = f * x.diff(nx) @@ -173,7 +174,7 @@ def _print_latex_(self, f, x): \int \frac{\tan\left(x\right)}{x}\,{d x} """ from sage.misc.latex import latex - if not is_SymbolicVariable(x): + if not (isinstance(x, Expression) and x.is_symbol()): dx_str = "{d \\left(%s\\right)}" % latex(x) else: dx_str = "{d %s}" % latex(x) @@ -236,7 +237,7 @@ def _eval_(self, f, x, a, b): -1 """ # Check for x - if not is_SymbolicVariable(x): + if not (isinstance(x, Expression) and x.is_symbol()): if len(x.variables()) == 1: nx = x.variables()[0] f = f * x.diff(nx) @@ -346,7 +347,7 @@ def _print_latex_(self, f, x, a, b): \int_{0}^{1} \frac{\tan\left(x\right)}{x}\,{d x} """ from sage.misc.latex import latex - if not is_SymbolicVariable(x): + if not (isinstance(x, Expression) and x.is_symbol()): dx_str = "{d \\left(%s\\right)}" % latex(x) else: dx_str = "{d %s}" % latex(x) diff --git a/src/sage/symbolic/operators.py b/src/sage/symbolic/operators.py index f56724a6e0e..82dc0173a2d 100644 --- a/src/sage/symbolic/operators.py +++ b/src/sage/symbolic/operators.py @@ -1,7 +1,6 @@ "Operators" import operator -from sage.symbolic.ring import is_SymbolicVariable, SR def add_vararg(first, *rest): @@ -123,7 +122,7 @@ def __call__(self, *args): D[0](f)(1) """ - if (not all(is_SymbolicVariable(x) for x in args) or + if (not all(isinstance(x, Expression) and x.is_symbol() for x in args) or len(args) != len(set(args))): # An evaluated derivative of the form f'(1) is not a # symbolic variable, yet we would like to treat it diff --git a/src/sage/symbolic/relation.py b/src/sage/symbolic/relation.py index b8896a94be9..77cc3d353aa 100644 --- a/src/sage/symbolic/relation.py +++ b/src/sage/symbolic/relation.py @@ -1029,7 +1029,6 @@ def solve(f, *args, **kwds): TypeError: The first argument to solve() should be a symbolic expression or a list of symbolic expressions. """ - from sage.symbolic.ring import is_SymbolicVariable from sage.structure.element import Expression explicit_solutions = kwds.get('explicit_solutions', None) multiplicities = kwds.get('multiplicities', None) @@ -1076,13 +1075,13 @@ def solve(f, *args, **kwds): if not args: raise TypeError("Please input variables to solve for.") - if is_SymbolicVariable(x): + if isinstance(x, Expression) and x.is_symbol(): variables = args else: variables = tuple(x) for v in variables: - if not is_SymbolicVariable(v): + if not (isinstance(v, Expression) and v.is_symbol()): raise TypeError("%s is not a valid variable." % repr(v)) try: @@ -1100,7 +1099,7 @@ def solve(f, *args, **kwds): sympy_f = f._sympy_() else: sympy_f = [s._sympy_() for s in f] - if is_SymbolicVariable(x): + if isinstance(f, Expression) and f.is_symbol(): sympy_vars = (x._sympy_(),) else: sympy_vars = tuple([v._sympy_() for v in x]) @@ -1269,13 +1268,12 @@ def _solve_expression(f, x, explicit_solutions, multiplicities, sage: solve([x==3], [x], solution_dict=True, algorithm='sympy') [{x: 3}] """ - from sage.symbolic.ring import is_SymbolicVariable if f.is_relational(): if f.operator() is not operator.eq: if algorithm == 'sympy': from sympy import S, solveset from sage.interfaces.sympy import sympy_set_to_list - if is_SymbolicVariable(x): + if isinstance(x, Expression) and x.is_symbol(): sympy_vars = (x._sympy_(),) else: sympy_vars = tuple([v._sympy_() for v in x]) @@ -1313,7 +1311,7 @@ def has_integer_assumption(v): if algorithm == 'sympy': from sympy import S, solveset from sage.interfaces.sympy import sympy_set_to_list - if is_SymbolicVariable(x): + if isinstance(x, Expression) and x.is_symbol(): sympy_vars = (x._sympy_(),) else: sympy_vars = tuple([v._sympy_() for v in x]) From 37865e9123c8d9315b3f0cdf582bb26dc48f716e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 17 Feb 2023 20:38:37 -0800 Subject: [PATCH 40/61] src/sage/calculus/desolvers.py: Fix up is_SymbolicEquation removal --- src/sage/calculus/desolvers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index 27d2e57bf36..69987d62297 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -599,9 +599,8 @@ def sanitize_var(exprs): if show_method: maxima_method=P("method") - soln = soln.sage() if ics is not None: - if not (isinstance(soln, Expression) and soln.is_relational()): + if not (isinstance(soln.sage(), Expression) and soln.sage().is_relational()): if not show_method: maxima_method=P("method") raise NotImplementedError("Unable to use initial condition for this equation (%s)."%(str(maxima_method).strip())) @@ -649,6 +648,7 @@ def sanitize_var(exprs): if str(soln).strip() == 'false': raise NotImplementedError("Maxima was unable to solve this BVP. Remove the initial condition to get the general solution.") + soln = soln.sage() if isinstance(soln, Expression) and soln.is_relational() and soln.lhs() == dvar: # Remark: Here we do not check that the right hand side does not depend on dvar. # This probably will not happen for solutions obtained via ode2, anyway. From 112db801a1ade49d6598a2c6820f43f3aea77ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Apr 2023 09:12:11 +0200 Subject: [PATCH 41/61] fix all pycodestyle E303 warnings in rings/ --- .../asymptotic_expansion_generators.py | 9 ---- src/sage/rings/asymptotic/asymptotic_ring.py | 9 ---- ...otics_multivariate_generating_functions.py | 1 - src/sage/rings/asymptotic/growth_group.py | 2 - .../asymptotic/growth_group_cartesian.py | 27 ------------ src/sage/rings/asymptotic/term_monoid.py | 1 - src/sage/rings/continued_fraction.py | 2 - .../rings/function_field/ideal_polymod.py | 2 - src/sage/rings/infinity.py | 2 - src/sage/rings/invariants/invariant_theory.py | 42 ------------------- src/sage/rings/lazy_series.py | 1 - src/sage/rings/lazy_series_ring.py | 1 - src/sage/rings/multi_power_series_ring.py | 2 - .../rings/multi_power_series_ring_element.py | 5 --- src/sage/rings/number_field/S_unit_solver.py | 1 - src/sage/rings/number_field/class_group.py | 6 --- src/sage/rings/padics/generic_nodes.py | 1 - src/sage/rings/padics/lattice_precision.py | 2 - src/sage/rings/padics/local_generic.py | 4 -- src/sage/rings/padics/padic_generic.py | 2 - src/sage/rings/padics/padic_valuation.py | 2 - src/sage/rings/polynomial/complex_roots.py | 1 - .../laurent_polynomial_ring_base.py | 2 - .../polynomial/multi_polynomial_element.py | 1 - .../polynomial/multi_polynomial_ideal.py | 1 - .../rings/polynomial/ore_function_field.py | 1 - .../polynomial/padics/polynomial_padic.py | 1 - .../polynomial/polynomial_element_generic.py | 2 - .../polynomial/polynomial_quotient_ring.py | 2 - src/sage/rings/polynomial/polynomial_ring.py | 1 - src/sage/rings/power_series_ring.py | 1 - src/sage/rings/qqbar.py | 2 - src/sage/rings/qqbar_decorators.py | 1 - src/sage/rings/quotient_ring_element.py | 2 - src/sage/rings/rational_field.py | 3 -- src/sage/rings/tate_algebra.py | 1 - src/sage/rings/universal_cyclotomic_field.py | 2 - 37 files changed, 148 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py index 38d486541d1..9a27c9d61eb 100644 --- a/src/sage/rings/asymptotic/asymptotic_expansion_generators.py +++ b/src/sage/rings/asymptotic/asymptotic_expansion_generators.py @@ -197,7 +197,6 @@ def Stirling(var, precision=None, skip_constant_factor=False): return result - @staticmethod def log_Stirling(var, precision=None, skip_constant_summand=False): r""" @@ -321,7 +320,6 @@ def log_Stirling(var, precision=None, skip_constant_summand=False): return result - @staticmethod def _log_StirlingNegativePowers_(var, precision): r""" @@ -371,7 +369,6 @@ def _log_StirlingNegativePowers_(var, precision): A.zero()) return result + (1 / n**(2*precision + 1)).O() - @staticmethod def HarmonicNumber(var, precision=None, skip_constant_summand=False): r""" @@ -477,7 +474,6 @@ def HarmonicNumber(var, precision=None, skip_constant_summand=False): return result - @staticmethod def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False): r""" @@ -603,7 +599,6 @@ def Binomial_kn_over_n(var, k, precision=None, skip_constant_factor=False): return result - @staticmethod def SingularityAnalysis(var, zeta=1, alpha=0, beta=0, delta=0, precision=None, normalized=True): @@ -961,7 +956,6 @@ def inverse_gamma_derivative(shift, r): if precision is None: precision = series_precision() - if not normalized and not (beta in ZZ and delta in ZZ): raise ValueError("beta and delta must be integers") if delta != 0: @@ -1040,7 +1034,6 @@ def inverse_gamma_derivative(shift, r): return result - @staticmethod @experimental(20050) def ImplicitExpansion(var, phi, tau=None, precision=None): @@ -1208,7 +1201,6 @@ def ansatz(prec=precision): return A(tau) + ansatz(prec=precision-1).map_coefficients(lambda term: term.subs(solution_dict).simplify_rational()) - @staticmethod @experimental(20050) def ImplicitExpansionPeriodicPart(var, phi, period, tau=None, precision=None): @@ -1298,7 +1290,6 @@ def ImplicitExpansionPeriodicPart(var, phi, period, tau=None, precision=None): Z = aperiodic_expansion.parent().gen() return 1/rho * (aperiodic_expansion/(1 - 1/Z))**(1/period) - @staticmethod def InverseFunctionAnalysis(var, phi, tau=None, period=1, precision=None): r""" diff --git a/src/sage/rings/asymptotic/asymptotic_ring.py b/src/sage/rings/asymptotic/asymptotic_ring.py index ff419b69df5..b7b49d32dc9 100644 --- a/src/sage/rings/asymptotic/asymptotic_ring.py +++ b/src/sage/rings/asymptotic/asymptotic_ring.py @@ -1209,7 +1209,6 @@ def _mul_term_(self, term): return self.parent()(self.summands.mapped(lambda element: term * element), simplify=simplify, convert=False) - def _mul_(self, other): r""" Multiply this asymptotic expansion by another asymptotic expansion ``other``. @@ -1309,7 +1308,6 @@ def _div_(self, other): """ return self * ~other - def __invert__(self, precision=None): r""" Return the multiplicative inverse of this element. @@ -1485,7 +1483,6 @@ def exact_part(self): return self.parent(exact_terms) - def error_part(self): r""" Return the expansion consisting of all error terms of this @@ -1511,7 +1508,6 @@ def error_part(self): if not term.is_exact()), parent.zero()) - def __pow__(self, exponent, precision=None): r""" Calculate the power of this asymptotic expansion to the given ``exponent``. @@ -1717,10 +1713,8 @@ def __pow__(self, exponent, precision=None): raise combine_exceptions( ValueError('Cannot take %s to the exponent %s.' % (self, exponent)), e) - pow = __pow__ - def __pow_number__(self, exponent, precision=None, check_convergence=False): r""" Return the power of this asymptotic expansion to some @@ -1873,7 +1867,6 @@ def binomials(a): return result * pmax - def sqrt(self, precision=None): r""" Return the square root of this asymptotic expansion. @@ -2244,7 +2237,6 @@ def rpow(self, base, precision=None, locals=None): if not expr_o: return large_result - if base == 'e': geom = expr_o else: @@ -3911,7 +3903,6 @@ def _create_empty_summands_(): can_merge=can_absorb, merge=absorption) - def _create_element_in_extension_(self, term, old_term_parent=None): r""" Create an element in an extension of this asymptotic ring which diff --git a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py index 771d23c7b90..9a168fe5d6d 100644 --- a/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py +++ b/src/sage/rings/asymptotic/asymptotics_multivariate_generating_functions.py @@ -3324,7 +3324,6 @@ def _an_element_(self): from sage.rings.semirings.non_negative_integer_semiring import NN return self(NN.an_element(), [(self.base().an_element(), NN(3))]) - Element = FractionWithFactoredDenominator diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index 98f40457f07..26b38b88303 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -381,7 +381,6 @@ def __init__(self, var, repr=None, latex_name=None, ignore=None): raise ValueError('Variable names %s are not pairwise distinct.' % (var_bases,)) - self.var_bases = var_bases self.var_repr = var_repr @@ -1679,7 +1678,6 @@ class GenericGrowthGroup(UniqueRepresentation, Parent, WithLocals): # enable the category framework for elements Element = GenericGrowthElement - # set everything up to determine category from sage.categories.sets_cat import Sets from sage.categories.posets import Posets diff --git a/src/sage/rings/asymptotic/growth_group_cartesian.py b/src/sage/rings/asymptotic/growth_group_cartesian.py index 645d9723e68..155adb2398e 100644 --- a/src/sage/rings/asymptotic/growth_group_cartesian.py +++ b/src/sage/rings/asymptotic/growth_group_cartesian.py @@ -196,7 +196,6 @@ def create_key_and_extra_args(self, growth_groups, category, **kwds): return (tuple(growth_groups), category), kwds - def create_object(self, version, args, **kwds): r""" Create an object from the given arguments. @@ -287,7 +286,6 @@ class GenericProduct(CartesianProductPoset, GenericGrowthGroup): __classcall__ = CartesianProductPoset.__classcall__ - def __init__(self, sets, category, **kwds): r""" See :class:`GenericProduct` for details. @@ -319,10 +317,8 @@ def __init__(self, sets, category, **kwds): GenericGrowthGroup.__init__(self, sets[0], Vars, self.category(), **kwds) - __hash__ = CartesianProductPoset.__hash__ - def some_elements(self): r""" Return some elements of this Cartesian product of growth groups. @@ -399,7 +395,6 @@ def _create_element_in_extension_(self, element): category=self.category()) return parent(element) - def _element_constructor_(self, data): r""" Converts the given object to an element of this Cartesian @@ -520,10 +515,8 @@ def convert_factors(data, raw_data): return convert_factors((data,), data) - _repr_ = GenericGrowthGroup._repr_ - def _repr_short_(self): r""" A short (shorter than :meth:`._repr_`) representation string @@ -547,7 +540,6 @@ def _repr_short_(self): """ return ' * '.join(S._repr_short_() for S in self.cartesian_factors()) - def _convert_factors_(self, factors): r""" Helper method. Try to convert some ``factors`` to an @@ -617,7 +609,6 @@ def get_factors(data): return prod(self.cartesian_injection(*fs) for f in factors for fs in get_factors(f)) - def cartesian_injection(self, factor, element): r""" Inject the given element into this Cartesian product at the given factor. @@ -642,7 +633,6 @@ def cartesian_injection(self, factor, element): return self(tuple((f.one() if f != factor else element) for f in self.cartesian_factors())) - def _coerce_map_from_(self, S): r""" Return whether ``S`` coerces into this growth group. @@ -677,7 +667,6 @@ def _coerce_map_from_(self, S): for f in factors): return True - def _pushout_(self, other): r""" Construct the pushout of this and the other growth group. This is called by @@ -864,7 +853,6 @@ def next_custom(self): from sage.categories.cartesian_product import cartesian_product return pushout(cartesian_product(newS), cartesian_product(newO)) - def gens_monomial(self): r""" Return a tuple containing monomial generators of this growth group. @@ -900,7 +888,6 @@ def gens_monomial(self): for factor in self.cartesian_factors()), tuple()) - def variable_names(self): r""" Return the names of the variables. @@ -921,13 +908,11 @@ def variable_names(self): from itertools import groupby return tuple(v for v, _ in groupby(vars)) - class Element(CartesianProductPoset.Element): from .growth_group import _is_lt_one_ is_lt_one = _is_lt_one_ - def _repr_(self, latex=False): r""" A representation string for this Cartesian product element. @@ -961,7 +946,6 @@ def _repr_(self, latex=False): return '1' return s - def _latex_(self): r""" A representation string for this Cartesian product element. @@ -982,7 +966,6 @@ def _latex_(self): """ return self._repr_(latex=True) - def __pow__(self, exponent): r""" Calculate the power of this growth element to the given @@ -1013,7 +996,6 @@ def __pow__(self, exponent): return self.parent()._create_element_in_extension_( tuple(x ** exponent for x in self.cartesian_factors())) - def factors(self): r""" Return the atomic factors of this growth element. An atomic factor @@ -1062,12 +1044,10 @@ def factors(self): if not f.is_one()), tuple()) - from .growth_group import _log_factor_, _log_ log = _log_ log_factor = _log_factor_ - def _log_factor_(self, base=None, locals=None): r""" Helper method for calculating the logarithm of the factorization @@ -1120,11 +1100,9 @@ def try_create_growth(g): ArithmeticError('Cannot build log(%s) in %s.' % (self, self.parent())), e) - from .growth_group import _rpow_ rpow = _rpow_ - def _rpow_element_(self, base): r""" Return an element which is the power of ``base`` to this @@ -1166,7 +1144,6 @@ def _rpow_element_(self, base): raise ValueError # calling method has to deal with it... return factor._rpow_element_(base) - def exp(self): r""" The exponential of this element. @@ -1211,7 +1188,6 @@ def exp(self): """ return self.rpow('e') - def __invert__(self): r""" Return the multiplicative inverse of this Cartesian product. @@ -1235,7 +1211,6 @@ def __invert__(self): return self.parent()._create_element_in_extension_( tuple(~x for x in self.cartesian_factors())) - def _substitute_(self, rules): r""" Substitute the given ``rules`` in this @@ -1378,7 +1353,6 @@ def _singularity_analysis_(self, var, zeta, precision): 'singularity analysis of {} not yet implemented ' 'since it has more than two factors'.format(self)) - def variable_names(self): r""" Return the names of the variables of this growth element. @@ -1408,7 +1382,6 @@ def variable_names(self): from itertools import groupby return tuple(v for v, _ in groupby(vars)) - CartesianProduct = CartesianProductGrowthGroups diff --git a/src/sage/rings/asymptotic/term_monoid.py b/src/sage/rings/asymptotic/term_monoid.py index 38a130bbd60..fdfb8365f1a 100644 --- a/src/sage/rings/asymptotic/term_monoid.py +++ b/src/sage/rings/asymptotic/term_monoid.py @@ -4640,7 +4640,6 @@ def __init__(self, parent, growth, valid_from, **kwds): raise ValueError('B-Term has not defined all variables which occur in the term in valid_from.') self.valid_from = valid_from - def construction(self): r""" Return a construction of this term. diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index a16137ff609..c8a68cb309f 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -1018,8 +1018,6 @@ def __bool__(self): """ return bool(self.quotient(0)) or self.quotient(1) is not Infinity - - def is_zero(self): r""" Test whether ``self`` is zero. diff --git a/src/sage/rings/function_field/ideal_polymod.py b/src/sage/rings/function_field/ideal_polymod.py index b105c6047b1..0a5309b4584 100644 --- a/src/sage/rings/function_field/ideal_polymod.py +++ b/src/sage/rings/function_field/ideal_polymod.py @@ -118,8 +118,6 @@ def __bool__(self): """ return self._hnf.nrows() != 0 - - def __hash__(self): """ Return the hash of this ideal. diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index 400e1d060c1..aabe2572f31 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -759,7 +759,6 @@ def _coerce_map_from_(self, R): UnsignedInfinityRing = UnsignedInfinityRing_class() - class LessThanInfinity(_uniq, RingElement): def __init__(self, parent=UnsignedInfinityRing): """ @@ -1751,7 +1750,6 @@ def _gap_init_(self): minus_infinity = InfinityRing.gen(1) - def test_comparison(ring): """ Check comparison with infinity diff --git a/src/sage/rings/invariants/invariant_theory.py b/src/sage/rings/invariants/invariant_theory.py index 0c0aa1c9f69..2f6850f97cc 100644 --- a/src/sage/rings/invariants/invariant_theory.py +++ b/src/sage/rings/invariants/invariant_theory.py @@ -325,7 +325,6 @@ def __init__(self, n, homogeneous, ring, variables): self._ring = ring self._variables = variables - def _jacobian_determinant(self, *args): """ Return the Jacobian determinant. @@ -372,7 +371,6 @@ def diff(p, d): jac = [diff(p,d) for p,d in args] return matrix(self._ring, jac).det() - def ring(self): """ Return the polynomial ring. @@ -398,7 +396,6 @@ def ring(self): """ return self._ring - def variables(self): """ Return the variables of the form. @@ -422,7 +419,6 @@ def variables(self): """ return self._variables - def is_homogeneous(self): """ Return whether the forms were defined by homogeneous polynomials. @@ -687,7 +683,6 @@ def _repr_(self): s += ' given by ' + str(self.form()) return s - def form(self): """ Return the defining polynomial. @@ -709,7 +704,6 @@ def form(self): polynomial = form - def homogenized(self, var='h'): """ Return form as defined by a homogeneous polynomial. @@ -872,7 +866,6 @@ def coeff_tuple_iter(): raise ValueError('less monomials were passed than the form actually has') return result - def coefficients(self): """ Alias for ``coeffs()``. @@ -891,7 +884,6 @@ def coefficients(self): """ return self.coeffs() - def transformed(self, g): r""" Return the image under a linear transformation of the variables. @@ -1019,7 +1011,6 @@ def from_invariants(cls, discriminant, x, z, *args, **kwargs): polynomial = sum([coeffs[i]*x**(2-i)*z**i for i in range(3)]) return cls(2, 2, polynomial, *args) - @cached_method def monomials(self): """ @@ -1060,7 +1051,6 @@ def prod(a, b): mixed = tuple(mixed) return squares + mixed - @cached_method def coeffs(self): r""" @@ -1088,7 +1078,6 @@ def coeffs(self): """ return self._extract_coefficients(self.monomials()) - def scaled_coeffs(self): r""" The scaled coefficients of a quadratic form. @@ -1118,7 +1107,6 @@ def scaled_coeffs(self): mixed = tuple( c/2 for c in coeff[self._n:] ) return squares + mixed - @cached_method def matrix(self): r""" @@ -1158,7 +1146,6 @@ def matrix(self): _matrix_ = matrix - def discriminant(self): """ Return the discriminant of the quadratic form. @@ -1290,7 +1277,6 @@ def dual(self): p = sum([ sum([ Aadj[i,j]*var[i]*var[j] for i in range(n) ]) for j in range(n)]) return invariant_theory.quadratic_form(p, self.variables()) - def as_QuadraticForm(self): """ Convert into a :class:`~sage.quadratic_forms.quadratic_form.QuadraticForm`. @@ -1420,7 +1406,6 @@ def coeffs(self): """ return self._extract_coefficients(self.monomials()) - def scaled_coeffs(self): """ The coefficients of a binary quartic. @@ -1451,7 +1436,6 @@ def scaled_coeffs(self): coeff = self.coeffs() return (coeff[0], coeff[1]/4, coeff[2]/6, coeff[3]/4, coeff[4]) - @cached_method def EisensteinD(self): r""" @@ -1481,7 +1465,6 @@ def EisensteinD(self): assert len(a) == 5 return a[0]*a[4]+3*a[2]**2-4*a[1]*a[3] - @cached_method def EisensteinE(self): r""" @@ -1511,7 +1494,6 @@ def EisensteinE(self): assert len(a) == 5 return a[0]*a[3]**2 +a[1]**2*a[4] -a[0]*a[2]*a[4] -2*a[1]*a[2]*a[3] +a[2]**3 - @cached_method def g_covariant(self): r""" @@ -1563,7 +1545,6 @@ def g_covariant(self): (2*a2*a3 - 2*a1*a4)*xpow[3] + \ (a3**2 - a2*a4)*xpow[4] - @cached_method def h_covariant(self): r""" @@ -2614,7 +2595,6 @@ def monomials(self): else: return (x**2, y**2, R.one(), x*y, x, y) - @cached_method def coeffs(self): r""" @@ -2643,7 +2623,6 @@ def coeffs(self): """ return self._extract_coefficients(self.monomials()) - def scaled_coeffs(self): r""" Return the scaled coefficients of a quadratic. @@ -2793,7 +2772,6 @@ def monomials(self): return (x**3, y**3, R.one(), x**2*y, x**2, x*y**2, y**2, x, y, x*y) - @cached_method def coeffs(self): r""" @@ -2827,7 +2805,6 @@ def coeffs(self): """ return self._extract_coefficients(self.monomials()) - def scaled_coeffs(self): r""" Return the coefficients of a cubic. @@ -2866,7 +2843,6 @@ def scaled_coeffs(self): 1/F(3)*a[6], 1/F(3)*a[7], 1/F(3)*a[8], 1/F(6)*a[9]) - def S_invariant(self): """ Return the S-invariant. @@ -2888,7 +2864,6 @@ def S_invariant(self): +(c2*a2*a3*b3+a3*b3*b1*c1+b1*c1*c2*a2) ) return S - def T_invariant(self): """ Return the T-invariant. @@ -2939,7 +2914,6 @@ def T_invariant(self): c2**2*a2**2*b1*c1+a3**2*b3**2*b1*c1+a3**2*b3**2*c2*a2) ) return T - @cached_method def polar_conic(self): r""" @@ -2985,7 +2959,6 @@ def polar_conic(self): polar = matrix(self._ring, [[A00, A01, A02],[A01, A11, A12],[A02, A12, A22]]) return polar - @cached_method def Hessian(self): """ @@ -3023,7 +2996,6 @@ def Hessian(self): F = self._ring.base_ring() return 1/F(216) * H.det() - def Theta_covariant(self): r""" Return the `\Theta` covariant. @@ -3057,7 +3029,6 @@ def Theta_covariant(self): F = self._ring.base_ring() return 1/F(9) * _covariant_conic(U_coeffs, H_coeffs, quadratic.monomials()) - def J_covariant(self): """ Return the J-covariant of the ternary cubic. @@ -3268,7 +3239,6 @@ def get_form(self, i): __getitem__ = get_form - def homogenized(self, var='h'): """ Return form as defined by a homogeneous polynomial. @@ -3301,7 +3271,6 @@ def homogenized(self, var='h'): forms = [f.homogenized(var=var) for f in self._forms] return self.__class__(forms) - def _check_covariant(self, method_name, g=None, invariant=False): r""" Test whether ``method_name`` actually returns a covariant. @@ -3356,7 +3325,6 @@ def _check_covariant(self, method_name, g=None, invariant=False): class TwoAlgebraicForms(SeveralAlgebraicForms): - def first(self): """ Return the first of the two forms. @@ -3381,7 +3349,6 @@ def first(self): """ return self._forms[0] - def second(self): """ Return the second of the two forms. @@ -3677,7 +3644,6 @@ def Delta_invariant(self): """ return self.get_form(0).matrix().det() - def Delta_prime_invariant(self): r""" Return the `\Delta'` invariant. @@ -3696,7 +3662,6 @@ def Delta_prime_invariant(self): """ return self.get_form(1).matrix().det() - def _Theta_helper(self, scaled_coeffs_1, scaled_coeffs_2): """ Internal helper method for :meth:`Theta_invariant` and @@ -3743,7 +3708,6 @@ def Theta_invariant(self): """ return self._Theta_helper(self.get_form(0).scaled_coeffs(), self.get_form(1).scaled_coeffs()) - def Theta_prime_invariant(self): r""" Return the `\Theta'` invariant. @@ -3762,7 +3726,6 @@ def Theta_prime_invariant(self): """ return self._Theta_helper(self.get_form(1).scaled_coeffs(), self.get_form(0).scaled_coeffs()) - def Phi_invariant(self): r""" Return the `\Phi'` invariant. @@ -3800,7 +3763,6 @@ def Phi_invariant(self): - 2*b0*b3*B2*B5 - 2*b0*b2*B3*B5 + 2*a0*b4*B3*B5 - 2*b0*b1*B4*B5 \ + 2*a0*b3*B4*B5 - a0*a1*B5**2 + b0**2*B5**2 - def _T_helper(self, scaled_coeffs_1, scaled_coeffs_2): """ Internal helper method for :meth:`T_covariant` and @@ -3883,7 +3845,6 @@ def T01(a0, a1, a2, a3, b0, b1, b2, b3, b4, b5, A0, A1, A2, A3, B0, B1, B2, B3, return t00*w*w + 2*t01*w*x + 2*t02*w*y + 2*t30*w*z + t11*x*x + 2*t12*x*y \ + 2*t13*x*z + t22*y*y + 2*t23*y*z + t33*z*z - def T_covariant(self): """ The `T`-covariant. @@ -3905,7 +3866,6 @@ def T_covariant(self): """ return self._T_helper(self.get_form(0).scaled_coeffs(), self.get_form(1).scaled_coeffs()) - def T_prime_covariant(self): """ The `T'`-covariant. @@ -3928,7 +3888,6 @@ def T_prime_covariant(self): """ return self._T_helper(self.get_form(1).scaled_coeffs(), self.get_form(0).scaled_coeffs()) - def J_covariant(self): """ The `J`-covariant. @@ -3954,7 +3913,6 @@ def J_covariant(self): [self.T_covariant(), 4], [self.T_prime_covariant(), 4]) - def syzygy(self, Delta, Theta, Phi, Theta_prime, Delta_prime, U, V, T, T_prime, J): """ Return the syzygy evaluated on the invariants and covariants. diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index 8b0b8aa1dff..f31488d5354 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -3240,7 +3240,6 @@ def _div_(self, other): right_inverse = Stream_cauchy_invert(right) return P.element_class(P, Stream_cauchy_mul(left, right_inverse, P.is_sparse())) - def _floordiv_(self, other): r""" Return ``self`` floor divided by ``other``. diff --git a/src/sage/rings/lazy_series_ring.py b/src/sage/rings/lazy_series_ring.py index 0444afcaba3..d8ba728a61b 100644 --- a/src/sage/rings/lazy_series_ring.py +++ b/src/sage/rings/lazy_series_ring.py @@ -1506,7 +1506,6 @@ def residue_field(self): # === special functions === - def q_pochhammer(self, q=None): r""" Return the infinite ``q``-Pochhammer symbol `(a; q)_{\infty}`, diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 0f7aa3b2d43..3ed94af4f02 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -563,8 +563,6 @@ def change_ring(self, R): """ return PowerSeriesRing(R, names = self.variable_names(), default_prec = self.default_prec()) - - def remove_var(self, *var): """ Remove given variable or sequence of variables from self. diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 91ac18389c2..978de36ce2d 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -355,7 +355,6 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): except AttributeError: pass - # set the correct background value, depending on what type of input x is try: xparent = x.parent() # 'int' types have no parent @@ -631,7 +630,6 @@ def _latex_(self): 'gens':', '.join(g._latex_() for g in self.parent().gens()), 'prec':self._prec} - def _im_gens_(self, codomain, im_gens, base_map=None): """ Returns the image of this series under the map that sends the @@ -1765,8 +1763,6 @@ def __pari__(self): """ raise NotImplementedError("__pari__") - - ### ### the following don't make sense for multivariable power series ### @@ -1788,7 +1784,6 @@ def list(self): #return [self.parent(c) for c in self._bg_value.list()] raise NotImplementedError("Multivariate power series do not have list of coefficients; use 'coefficients' to get a dict of coefficients.") - def variable(self): """ Doesn't make sense for multivariate power series. diff --git a/src/sage/rings/number_field/S_unit_solver.py b/src/sage/rings/number_field/S_unit_solver.py index a0eb41b75b3..af226730584 100644 --- a/src/sage/rings/number_field/S_unit_solver.py +++ b/src/sage/rings/number_field/S_unit_solver.py @@ -1339,7 +1339,6 @@ def log_p_series_part(a, prime, prec): ZZ((gi * p**(-gi.valuation(p))) % (p**(prec+w-gi.valuation(p)))) * p**(gi.valuation(p)) * g**i for i,gi in enumerate(gamma) if gi != 0]) - beta = 0 delta = 1 - gamma for i in range(1, n+1): diff --git a/src/sage/rings/number_field/class_group.py b/src/sage/rings/number_field/class_group.py index 46b98c242e8..32b00310b85 100644 --- a/src/sage/rings/number_field/class_group.py +++ b/src/sage/rings/number_field/class_group.py @@ -294,7 +294,6 @@ def representative_prime(self, norm_bound=1000): return P raise RuntimeError("No prime of norm less than %s found in class %s" % (norm_bound, c)) - def gens(self): r""" Return generators for a representative ideal in this @@ -314,7 +313,6 @@ def gens(self): return self.ideal().gens() - class SFractionalIdealClass(FractionalIdealClass): r""" An S-fractional ideal class in a number field for a tuple of primes S. @@ -397,7 +395,6 @@ def _repr_(self): return 'Fractional S-ideal class %s' % self._value._repr_short() - class ClassGroup(AbelianGroupWithValues_class): r""" The class group of a number field. @@ -617,9 +614,6 @@ def number_field(self): return self._number_field - - - class SClassGroup(ClassGroup): r""" The S-class group of a number field. diff --git a/src/sage/rings/padics/generic_nodes.py b/src/sage/rings/padics/generic_nodes.py index 3c5d9c2aaf5..0b3507b82d7 100644 --- a/src/sage/rings/padics/generic_nodes.py +++ b/src/sage/rings/padics/generic_nodes.py @@ -1211,7 +1211,6 @@ def is_field(self, proof = True): """ return False - def krull_dimension(self): r""" Return the Krull dimension of self, i.e. 1 diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py index e9966629fdf..810d9de650c 100644 --- a/src/sage/rings/padics/lattice_precision.py +++ b/src/sage/rings/padics/lattice_precision.py @@ -440,7 +440,6 @@ def _quo_rem(self, other): return (self.__class__(self.p, (sx - sred)/(pd*ox), 0), self.__class__(self.p, sred, sval, valuation=sval)) - def __lshift__(self, n): r""" Return the product of this element by ``p^n``. @@ -1250,7 +1249,6 @@ def _format_history(self, time, status, timings): else: return status - def history(self, compact=True, separate_reduce=False, timings=True, output_type='asciiart'): r""" Show history. diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py index 2168d2e348b..79db1904f92 100644 --- a/src/sage/rings/padics/local_generic.py +++ b/src/sage/rings/padics/local_generic.py @@ -682,7 +682,6 @@ def ground_ring_of_tower(self): """ return self - def absolute_degree(self): r""" Return the degree of this extension over the prime p-adic field/ring. @@ -736,7 +735,6 @@ def degree(self): else: raise NotImplementedError("For a relative p-adic ring or field you must use relative_degree or absolute_degree as appropriate") - def absolute_e(self): r""" Return the absolute ramification index of this ring/field. @@ -844,7 +842,6 @@ def ramification_index(self): """ return self.e() - def absolute_f(self): r""" Return the degree of the residue field of this ring/field @@ -1172,7 +1169,6 @@ def _matrix_flatten_precision(self, M): M[i,j] <<= s return shift_rows, shift_cols - def _matrix_smith_form(self, M, transformation, integral, exact): r""" Return the Smith normal form of the matrix `M`. diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index 2f9c2195720..85424cfcec6 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -90,7 +90,6 @@ def some_elements(self): return L def _modified_print_mode(self, print_mode): - r""" Return a dictionary of print options, starting with ``self``'s print options but modified by the options in the dictionary @@ -963,7 +962,6 @@ def _test_shift(self, **options): xx = y + (x % b) tester.assertTrue(xx.is_equal_to(x,prec)) - def _test_log(self, **options): r""" Test the log operator on elements of this ring. diff --git a/src/sage/rings/padics/padic_valuation.py b/src/sage/rings/padics/padic_valuation.py index e1be8472585..a9df7bd33cf 100644 --- a/src/sage/rings/padics/padic_valuation.py +++ b/src/sage/rings/padics/padic_valuation.py @@ -256,7 +256,6 @@ def create_key_and_extra_args_for_number_field_from_valuation(self, R, v, prime, else: raise NotImplementedError("cannot rewrite %r which is defined on %r as a pseudo-valuation on %r"%(v, v.domain(), G.parent())) - assert(v.domain() is G.parent()) # To obtain uniqueness of p-adic valuations, we need a canonical @@ -379,7 +378,6 @@ def _normalize_number_field_data(self, R): return K, L, G - def create_object(self, version, key, **extra_args): r""" Create a `p`-adic valuation from ``key``. diff --git a/src/sage/rings/polynomial/complex_roots.py b/src/sage/rings/polynomial/complex_roots.py index 0d84a9c757b..cbbd42c8ccf 100644 --- a/src/sage/rings/polynomial/complex_roots.py +++ b/src/sage/rings/polynomial/complex_roots.py @@ -147,7 +147,6 @@ def row_disjoint(): return True - def complex_roots(p, skip_squarefree=False, retval='interval', min_prec=0): """ Compute the complex roots of a given polynomial with exact diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py index bb6b23e78d3..82394e3930c 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py @@ -101,7 +101,6 @@ def gen(self, i=0): self.__generators = tuple(self(x) for x in self._R.gens()) return self.__generators[i] - def variable_names_recursive(self, depth=infinity): r""" Return the list of variable names of this ring and its base rings, @@ -185,7 +184,6 @@ def construction(self): else: return LaurentPolynomialFunctor(vars[-1], True), LaurentPolynomialRing(self.base_ring(), vars[:-1]) - def completion(self, p=None, prec=20, extras=None): r""" Return the completion of ``self``. diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 3a320705dd7..fbf6b3d3765 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -1969,7 +1969,6 @@ def integral(self, var=None): raise ValueError("must specify which variable to integrate " "with respect to") - # TODO: # calling the coercion model bin_op is much more accurate than using the # true division (which is bypassed by polynomials). But it does not work diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index aaee4cbeddf..61f222e3eea 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -1643,7 +1643,6 @@ def intersection(self, *others): """ R = self.ring() - for other in others: if not isinstance(other, MPolynomialIdeal_singular_repr) or other.ring() != R: raise TypeError("Intersection is only available for ideals of the same ring.") diff --git a/src/sage/rings/polynomial/ore_function_field.py b/src/sage/rings/polynomial/ore_function_field.py index 34e6e2a6756..5a50e7c22b0 100644 --- a/src/sage/rings/polynomial/ore_function_field.py +++ b/src/sage/rings/polynomial/ore_function_field.py @@ -355,7 +355,6 @@ def characteristic(self): """ return self.base_ring().characteristic() - def twisting_morphism(self, n=1): r""" Return the twisting endomorphism defining this Ore function field iterated ``n`` times diff --git a/src/sage/rings/polynomial/padics/polynomial_padic.py b/src/sage/rings/polynomial/padics/polynomial_padic.py index c4719f31836..5dca5066033 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic.py @@ -252,7 +252,6 @@ def factor(self): G = self_normal.__pari__().factorpadic(self.base_ring().prime(), absprec) return _pari_padic_factorization_to_sage(G, self.parent(), self.leading_coefficient()) - def root_field(self, names, check_irreducible=True, **kwds): """ Return the p-adic extension field generated by the roots of the irreducible diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 368cbb688f6..9689947632f 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -260,7 +260,6 @@ def _derivative(self, var=None): except AttributeError: raise ValueError('cannot differentiate with respect to {}'.format(var)) - # compute formal derivative with respect to generator d = {} for n, c in self.__coeffs.items(): @@ -1553,7 +1552,6 @@ def _roots(self, secure, minval, hint): return roots - class Polynomial_generic_dense_cdv(Polynomial_generic_dense_inexact, Polynomial_generic_cdv): pass diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index d378de2b156..942c4b7d17d 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -2326,8 +2326,6 @@ def field_extension(self, names): return self.gen().field_extension(names) - - class PolynomialQuotientRing_field(PolynomialQuotientRing_domain, Field): """ EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index 150f6ce1c06..ea07c8f5437 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -958,7 +958,6 @@ def _macaulay2_init_(self, macaulay2=None): macaulay2 = m2_default return macaulay2._macaulay2_input_ring(self.base_ring(), self.gens()) - def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index 290a4e316b9..a65af81d061 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -365,7 +365,6 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, return _multi_variate(base_ring, num_gens=names, names=arg2, order=order, default_prec=default_prec, sparse=sparse) - # univariate case: the arguments to PowerSeriesRing used to be # (base_ring, name=None, default_prec=20, names=None, sparse=False), # and thus that is what the code below expects; this behavior is being diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index d70b2cd2bc3..8339127693b 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -4107,8 +4107,6 @@ def __bool__(self): self.exactify() return bool(self) - - def is_square(self): """ Return whether or not this number is square. diff --git a/src/sage/rings/qqbar_decorators.py b/src/sage/rings/qqbar_decorators.py index 1f79a55bdbe..0f7a19bed50 100644 --- a/src/sage/rings/qqbar_decorators.py +++ b/src/sage/rings/qqbar_decorators.py @@ -36,7 +36,6 @@ def handle_AA_and_QQbar(func): @sage_wraps(func) def wrapper(*args, **kwds): - """ TESTS:: diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index e2f190a4b1c..05cc52e7681 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -153,8 +153,6 @@ def __bool__(self): """ return self.__rep not in self.parent().defining_ideal() - - def is_unit(self): """ Return True if self is a unit in the quotient ring. diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index 28a4d3b65c0..ca704238181 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -383,7 +383,6 @@ def _coerce_map_from_(self, S): from sage.structure.coerce_maps import CallableConvertMap return CallableConvertMap(S, self, lambda x: x._value, parent_as_first_arg=False) - def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ Check to see if the map into ``codomain`` determined by ``im_gens`` is @@ -891,7 +890,6 @@ def phi(x): v = [(1-hilbert_symbol(x, b, p))//2 for p in P] return V(v) - M = matrix(GF(2), [phi(p) for p in P+[-1]]) # We search through all the primes for q in Primes(): @@ -1272,7 +1270,6 @@ def zeta(self, n=2): else: raise ValueError("no n-th root of unity in rational field") - def selmer_generators(self, S, m, proof=True, orders=False): r""" Return generators of the group `\QQ(S,m)`. diff --git a/src/sage/rings/tate_algebra.py b/src/sage/rings/tate_algebra.py index 877f2a2703e..5d94d204f69 100644 --- a/src/sage/rings/tate_algebra.py +++ b/src/sage/rings/tate_algebra.py @@ -683,7 +683,6 @@ def some_elements(self): return elts - # Tate algebras ############### diff --git a/src/sage/rings/universal_cyclotomic_field.py b/src/sage/rings/universal_cyclotomic_field.py index fb001918302..f5d2bc5b1d9 100644 --- a/src/sage/rings/universal_cyclotomic_field.py +++ b/src/sage/rings/universal_cyclotomic_field.py @@ -334,8 +334,6 @@ def __bool__(self): """ return bool(self._obj) - - def __reduce__(self): r""" TESTS:: From 81748fb44f58c2753550870e8b3f1709a0b46722 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Apr 2023 09:25:45 +0200 Subject: [PATCH 42/61] Update src/sage/modular/multiple_zeta_F_algebra.py micro-optimisation Co-authored-by: Travis Scrimshaw --- src/sage/modular/multiple_zeta_F_algebra.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/modular/multiple_zeta_F_algebra.py b/src/sage/modular/multiple_zeta_F_algebra.py index fe81bc4ffdb..f8875d4bc51 100644 --- a/src/sage/modular/multiple_zeta_F_algebra.py +++ b/src/sage/modular/multiple_zeta_F_algebra.py @@ -755,7 +755,7 @@ def homogeneous_to_vector(self): a, b = next(iter(self))[0] N = 2 * a + sum(int(x) for x in b) return vector(BR, [self.coefficient(b) - for b in basis_f_iterator(N, self.parent()._start)]) + for b in basis_f_iterator(N, F._start)]) def without_f2(self): """ From 335b7f8d4913c83aa9e3dae48b769bd95784a8ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Sat, 25 Mar 2023 16:27:43 +0100 Subject: [PATCH 43/61] Do not require a multiplicative generator for finite field nth_root Finding a multiplicative generator usually requires factoring the order of the multiplicative group, which can be very expensive. Instead, we only need primitive roots for powers of primes dividing n, where n is a strict divisor of the order of the multiplicative group (usually small). --- src/sage/rings/finite_rings/element_base.pyx | 59 ++++++++++++++------ 1 file changed, 41 insertions(+), 18 deletions(-) diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index 4f785ebf181..a7e32004002 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -52,38 +52,53 @@ cdef class FiniteRingElement(CommutativeRingElement): def _nth_root_common(self, n, all, algorithm, cunningham): """ This function exists to reduce code duplication between finite field - nth roots and integer_mod nth roots. + nth roots and integer_mod nth roots. It assumes that `self` is a field + element. The inputs are described there. TESTS:: sage: a = Zmod(17)(13) - sage: a._nth_root_common(4, True, "Johnston", False) - [3, 5, 14, 12] - sage: a._nth_root_common(4, True, "Johnston", cunningham=True) # optional - cunningham_tables - [3, 5, 14, 12] + sage: sorted(a._nth_root_common(4, True, "Johnston", False)) + [3, 5, 12, 14] + sage: sorted(a._nth_root_common(4, True, "Johnston", cunningham=True)) # optional - cunningham_tables + [3, 5, 12, 14] + + Test various prime powers:: + + sage: p = 5^5*10000000100 + 1 + sage: a = GF(p)(3)**(5^7) + sage: for e in range(20): + ....: r = a._nth_root_common(5^e, False, "Johnston", False) + ....: assert r**(5^e) == a + + Test very large modulus (assumed impossible to factor in reasonable time):: + + sage: p = 2^1024 + 643 + sage: a = GF(p, proof=False)(3)**(29*283*3539) + sage: r = a._nth_root_common(29*283*3539*12345, False, "Johnston", False) + sage: r**(29*283*3539*12345) == a + True + """ K = self.parent() q = K.order() + gcd = n.gcd(q-1) if self.is_one(): - gcd = n.gcd(q-1) if gcd == 1: if all: return [self] else: return self else: - # the following may eventually be improved to not need a multiplicative generator. - g = K.multiplicative_generator() - q1overn = (q-1)//gcd - nthroot = g**q1overn + nthroot = K.zeta(gcd) return [nthroot**a for a in range(gcd)] if all else nthroot - n = n % (q-1) - if n == 0: + if gcd == q-1: if all: return [] else: raise ValueError("no nth root") gcd, alpha, beta = n.xgcd(q-1) # gcd = alpha*n + beta*(q-1), so 1/n = alpha/gcd (mod q-1) if gcd == 1: return [self**alpha] if all else self**alpha + n = gcd q1overn = (q-1)//n if self**q1overn != 1: @@ -97,18 +112,26 @@ cdef class FiniteRingElement(CommutativeRingElement): F = n.factor() from sage.groups.generic import discrete_log if algorithm is None or algorithm == 'Johnston': - g = K.multiplicative_generator() + # In the style of the Adleman-Manders-Miller algorithm, + # we will use small order elements instead of a multiplicative + # generator, which can be expensive to compute. for r, v in F: + # 0 < v <= k k, h = (q-1).val_unit(r) - z = h * (-h).inverse_mod(r**v) + hinv = (-h).inverse_mod(r**v) + z = h * hinv x = (1 + z) // r**v - if k == 1: + if k == v: self = self**x else: - t = discrete_log(self**h, g**(r**v*h), r**(k-v), operation='*') - self = self**x * g**(-z*t) + # We need an element of order r^k (g^h in Johnston's article) + # self^x differs from the actual nth root by an element of + # order dividing r^(k-v) + gh = K.zeta(r**k) + t = discrete_log(self**h, gh**(r**v), r**(k-v), operation='*') + self = self**x * gh**(-hinv*t) if all: - nthroot = g**q1overn + nthroot = K.zeta(n) L = [self] for i in range(1,n): self *= nthroot From f6802e1887a648269eee0f965c7087d913e70245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Mon, 27 Mar 2023 23:14:25 +0200 Subject: [PATCH 44/61] Faster Kohel isogenies without bivariate polynomials This patch accelerates computation of Kohel formulas by replacing internal bivariate polynomials k[x,y] by a tower of polynomial rings k[x][y]. Because the y-coordinate of isogenies are always defined by a polynomial of y-degree 1, this is equivalent to working with a pair of univariate polynomials, which often have efficient representations especially over finite fields. The public API still exposes bivariate rational functions and is not modified. The resulting representation is several times faster. --- .../elliptic_curves/ell_curve_isogeny.py | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py index 9811ea6cf8d..9b3b42bc37b 100644 --- a/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py +++ b/src/sage/schemes/elliptic_curves/ell_curve_isogeny.py @@ -963,7 +963,7 @@ class EllipticCurveIsogeny(EllipticCurveHom): # __base_field = None __poly_ring = None # univariate in x over __base_field - __mpoly_ring = None # bivariate in x, y over __base_field + __mpoly_ring = None # __base_field[x][y], internal use only # # Rational Maps @@ -1003,7 +1003,7 @@ class EllipticCurveIsogeny(EllipticCurveHom): # __psi = None # psi polynomial __phi = None # phi polynomial - __omega = None # omega polynomial + __omega = None # omega polynomial, an element of k[x][y] # @@ -1559,7 +1559,7 @@ def __init_algebraic_structs(self, E): sage: phi._EllipticCurveIsogeny__poly_ring # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 17 sage: phi._EllipticCurveIsogeny__mpoly_ring # optional - sage.rings.finite_rings - Multivariate Polynomial Ring in x, y over Finite Field of size 17 + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Finite Field of size 17 Now, calling the initialization function does nothing more:: @@ -1571,7 +1571,7 @@ def __init_algebraic_structs(self, E): sage: phi._EllipticCurveIsogeny__poly_ring # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 17 sage: phi._EllipticCurveIsogeny__mpoly_ring # optional - sage.rings.finite_rings - Multivariate Polynomial Ring in x, y over Finite Field of size 17 + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Finite Field of size 17 sage: E = EllipticCurve(QQ, [0,0,0,1,0]) sage: phi = EllipticCurveIsogeny(E, E((0,0))) @@ -1583,7 +1583,7 @@ def __init_algebraic_structs(self, E): sage: phi._EllipticCurveIsogeny__poly_ring Univariate Polynomial Ring in x over Rational Field sage: phi._EllipticCurveIsogeny__mpoly_ring - Multivariate Polynomial Ring in x, y over Rational Field + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field sage: F = GF(19); R. = F[] # optional - sage.rings.finite_rings sage: E = EllipticCurve(j=GF(19)(0)) # optional - sage.rings.finite_rings @@ -1596,14 +1596,16 @@ def __init_algebraic_structs(self, E): sage: phi._EllipticCurveIsogeny__poly_ring # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 19 sage: phi._EllipticCurveIsogeny__mpoly_ring # optional - sage.rings.finite_rings - Multivariate Polynomial Ring in x, y over Finite Field of size 19 + Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Finite Field of size 19 """ self._domain = E self.__base_field = E.base_ring() self.__poly_ring = PolynomialRing(self.__base_field, ['x']) - self.__mpoly_ring = PolynomialRing(self.__base_field, ['x','y']) + self.__mpoly_ring = PolynomialRing(self.__poly_ring, ['y']) + # The fraction fields are implicitly part of the public API, being the parents + # of the rational maps. self.__xfield = FractionField(self.__poly_ring) - self.__xyfield = FractionField(self.__mpoly_ring) + self.__xyfield = FractionField(PolynomialRing(self.__base_field, ['x', 'y'])) def __compute_codomain(self): r""" @@ -2157,7 +2159,7 @@ def __initialize_rational_maps_via_velu(self): ((x^4 + 5*x^3 + x^2 + 4*x)/(x^3 + 5*x^2 + 3*x + 5), (x^5*y - 2*x^3*y - x^2*y - 2*x*y + 2*y)/(x^5 + 3*x^3 + 3*x^2 + x - 1)) """ x = self.__poly_ring.gen() - y = self.__mpoly_ring.gen(1) + y = self.__xyfield.gen(1) return self.__compute_via_velu(x,y) def __init_kernel_polynomial_velu(self): @@ -2314,7 +2316,7 @@ def __init_even_kernel_polynomial(self, E, psi_G): sage: from sage.schemes.elliptic_curves.ell_curve_isogeny import two_torsion_part sage: psig = two_torsion_part(E,x) # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__init_even_kernel_polynomial(E,psig) # optional - sage.rings.finite_rings - (x^3 + 6*x, x^3*y + x*y, 6, 0, 1, 2) + (x^3 + 6*x, (x^3 + x)*y, 6, 0, 1, 2) sage: F = GF(2^4, 'alpha'); R. = F[] # optional - sage.rings.finite_rings sage: E = EllipticCurve(F, [1,1,0,1,0]) # optional - sage.rings.finite_rings @@ -2325,7 +2327,7 @@ def __init_even_kernel_polynomial(self, E, psi_G): sage: psig = two_torsion_part(E,x) # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__init_even_kernel_polynomial(E,psig) # optional - sage.rings.finite_rings - (x^3 + x, x^3*y + x^2 + x*y, 1, 0, 1, 2) + (x^3 + x, (x^3 + x)*y + x^2, 1, 0, 1, 2) sage: E = EllipticCurve(GF(7), [0,-1,0,0,1]) # optional - sage.rings.finite_rings sage: R. = GF(7)[] # optional - sage.rings.finite_rings @@ -2337,7 +2339,7 @@ def __init_even_kernel_polynomial(self, E, psi_G): sage: psig = two_torsion_part(E,f) # optional - sage.rings.finite_rings sage: psig = two_torsion_part(E,f) # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__init_even_kernel_polynomial(E,psig) # optional - sage.rings.finite_rings - (x^7 + 5*x^6 + 2*x^5 + 6*x^4 + 3*x^3 + 5*x^2 + 6*x + 3, x^9*y - 3*x^8*y + 2*x^7*y - 3*x^3*y + 2*x^2*y + x*y - y, 1, 6, 3, 4) + (x^7 + 5*x^6 + 2*x^5 + 6*x^4 + 3*x^3 + 5*x^2 + 6*x + 3, (x^9 + 4*x^8 + 2*x^7 + 4*x^3 + 2*x^2 + x + 6)*y, 1, 6, 3, 4) """ # check if the polynomial really divides the two_torsion_polynomial if self.__check and E.division_polynomial(2, x=self.__poly_ring.gen()) % psi_G != 0 : @@ -2349,7 +2351,7 @@ def __init_even_kernel_polynomial(self, E, psi_G): a1, a2, a3, a4, a6 = E.a_invariants() b2, b4, _, _ = E.b_invariants() x = self.__poly_ring.gen() - y = self.__mpoly_ring.gen(1) + y = self.__mpoly_ring.gen() if n == 1: x0 = -psi_G.constant_coefficient() @@ -2430,7 +2432,7 @@ def __init_odd_kernel_polynomial(self, E, psi): sage: R. = GF(7)[] # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__init_odd_kernel_polynomial(E, x+6) # optional - sage.rings.finite_rings - (x^3 + 5*x^2 + 3*x + 2, x^3*y - 3*x^2*y + x*y, 2, 6, 1, 3) + (x^3 + 5*x^2 + 3*x + 2, (x^3 + 4*x^2 + x)*y, 2, 6, 1, 3) sage: F = GF(2^4, 'alpha'); R. = F[] # optional - sage.rings.finite_rings sage: alpha = F.gen() # optional - sage.rings.finite_rings @@ -2444,7 +2446,7 @@ def __init_odd_kernel_polynomial(self, E, psi): sage: R. = F[] # optional - sage.rings.finite_rings sage: f = x + alpha^2 + 1 # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__init_odd_kernel_polynomial(E, f) # optional - sage.rings.finite_rings - (x^3 + (alpha^2 + 1)*x + alpha^3 + alpha^2 + alpha, x^3*y + (alpha^2 + 1)*x^2*y + (alpha^2 + alpha + 1)*x^2 + (alpha^2 + 1)*x*y + (alpha^2 + alpha)*x + alpha*y + alpha, alpha^2 + alpha + 1, alpha^3 + alpha^2 + alpha, 1, 3) + (x^3 + (alpha^2 + 1)*x + alpha^3 + alpha^2 + alpha, (x^3 + (alpha^2 + 1)*x^2 + (alpha^2 + 1)*x + alpha)*y + (alpha^2 + alpha + 1)*x^2 + (alpha^2 + alpha)*x + alpha, alpha^2 + alpha + 1, alpha^3 + alpha^2 + alpha, 1, 3) sage: E = EllipticCurve(j=-262537412640768000) # optional - sage.rings.finite_rings sage: f = E.isogenies_prime_degree()[0].kernel_polynomial() # optional - sage.rings.finite_rings @@ -2536,11 +2538,12 @@ def __compute_omega_fast(self, E, psi, psi_pr, phi, phi_pr): sage: fi = phi._EllipticCurveIsogeny__phi # optional - sage.rings.finite_rings sage: fi_pr = fi.derivative() # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__compute_omega_fast(E, psi, psi_pr, fi, fi_pr) # optional - sage.rings.finite_rings - x^3*y - 3*x^2*y + x*y + (x^3 + 4*x^2 + x)*y """ a1 = E.a1() a3 = E.a3() - x, y = self.__mpoly_ring.gens() + x = self.__poly_ring.gen() + y = self.__mpoly_ring.gen() psi_2 = 2*y + a1*x + a3 @@ -2587,7 +2590,7 @@ def __compute_omega_general(self, E, psi, psi_pr, phi, phi_pr): sage: fi = phi._EllipticCurveIsogeny__phi # optional - sage.rings.finite_rings sage: fi_pr = fi.derivative() # optional - sage.rings.finite_rings sage: phi._EllipticCurveIsogeny__compute_omega_general(E, psi, psi_pr, fi, fi_pr) # optional - sage.rings.finite_rings - x^3*y + (alpha^2 + 1)*x^2*y + (alpha^2 + alpha + 1)*x^2 + (alpha^2 + 1)*x*y + (alpha^2 + alpha)*x + alpha*y + alpha + (x^3 + (alpha^2 + 1)*x^2 + (alpha^2 + 1)*x + alpha)*y + (alpha^2 + alpha + 1)*x^2 + (alpha^2 + alpha)*x + alpha A bug fixed in :trac:`7907`:: @@ -2604,7 +2607,8 @@ def __compute_omega_general(self, E, psi, psi_pr, phi, phi_pr): """ a1, a2, a3, a4, a6 = E.a_invariants() b2, b4, _, _ = E.b_invariants() - x, y = self.__mpoly_ring.gens() + x = self.__poly_ring.gen() + y = self.__mpoly_ring.gen() n = psi.degree() d = 2 * n + 1 @@ -2693,7 +2697,9 @@ def __compute_via_kohel(self, xP, yP): ((x^3 - 2*x^2 + 3*x + 2)/(x^2 - 2*x + 1), (x^3*y - 3*x^2*y + x*y)/(x^3 - 3*x^2 + 3*x - 1)) """ a = self.__phi(xP) - b = self.__omega(xP, yP) + omega0 = self.__omega[0] + omega1 = self.__omega[1] + b = omega0(xP) + omega1(xP)*yP c = self.__psi(xP) return a/c**2, b/c**3 From 75bb6e3213f1684fbb2523288c04a3b075dee52f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Apr 2023 11:52:17 +0200 Subject: [PATCH 45/61] partial cython-linting in graphs/ --- src/sage/graphs/base/boost_graph.pyx | 7 ++----- src/sage/graphs/base/c_graph.pyx | 7 ++----- src/sage/graphs/base/dense_graph.pyx | 8 +++----- src/sage/graphs/base/graph_backends.pyx | 4 +--- src/sage/graphs/base/sparse_graph.pxd | 7 ++++--- src/sage/graphs/base/sparse_graph.pyx | 5 ++--- src/sage/graphs/base/static_dense_graph.pyx | 2 +- src/sage/graphs/base/static_sparse_backend.pyx | 7 ++----- src/sage/graphs/base/static_sparse_graph.pxd | 12 ++++++------ src/sage/graphs/base/static_sparse_graph.pyx | 3 --- src/sage/graphs/generators/distance_regular.pyx | 9 ++------- src/sage/graphs/graph_decompositions/bandwidth.pyx | 2 +- .../graph_decompositions/clique_separators.pyx | 3 --- src/sage/graphs/graph_decompositions/cutwidth.pyx | 4 ++-- .../graphs/graph_decompositions/fast_digraph.pxd | 2 -- .../graphs/graph_decompositions/fast_digraph.pyx | 5 ++--- .../graphs/graph_decompositions/graph_products.pyx | 2 -- src/sage/graphs/graph_decompositions/rankwidth.pxd | 3 --- .../graph_decompositions/tree_decomposition.pyx | 5 ++--- .../graph_decompositions/vertex_separation.pyx | 12 ++++++------ 20 files changed, 38 insertions(+), 71 deletions(-) diff --git a/src/sage/graphs/base/boost_graph.pyx b/src/sage/graphs/base/boost_graph.pyx index fb1c6c3acda..22a6f4e5ba4 100644 --- a/src/sage/graphs/base/boost_graph.pyx +++ b/src/sage/graphs/base/boost_graph.pyx @@ -1183,7 +1183,6 @@ cpdef johnson_shortest_paths(g, weight_function=None, distances=True, predecesso cdef BoostVecWeightedGraph g_boost_und cdef int N = g.num_verts() cdef vector[vector[double]] result - cdef int u_int, v_int if g.is_directed(): boost_weighted_graph_from_sage_graph(&g_boost_dir, g, v_to_int, weight_function) @@ -1340,7 +1339,6 @@ cpdef floyd_warshall_shortest_paths(g, weight_function=None, distances=True, pre cdef BoostVecWeightedGraph g_boost_und cdef int N = g.num_verts() cdef vector[vector[double]] result - cdef int u_int, v_int if g.is_directed(): boost_weighted_graph_from_sage_graph(&g_boost_dir, g, v_to_int, weight_function) @@ -2330,13 +2328,13 @@ cdef double diameter_DiFUB(BoostVecWeightedDiGraphU g_boost, import sys # These variables are automatically deleted when the function terminates. cdef double LB, LB_1, LB_2, UB - cdef v_index s, m, d, v, tmp + cdef v_index m, v, tmp cdef v_index i cdef vector[double] distances cdef vector[pair[double, v_index]] order_1, order_2 # We select a vertex with low eccentricity using 2Dsweep - LB, s, m, d = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost, + LB, _, m, _ = diameter_lower_bound_2Dsweep(g_boost, rev_g_boost, source, algorithm) # If the lower bound is a very large number, it means that the digraph is @@ -2969,7 +2967,6 @@ cpdef wiener_index(g, algorithm=None, weight_function=None, check_weight=True): # These variables are automatically deleted when the function terminates. cdef v_index vi, u, v - cdef dict int_to_v = dict(enumerate(g)) cdef dict v_to_int = {vv: vi for vi, vv in enumerate(g)} cdef BoostVecWeightedDiGraphU g_boost_dir cdef BoostVecWeightedGraph g_boost_und diff --git a/src/sage/graphs/base/c_graph.pyx b/src/sage/graphs/base/c_graph.pyx index f47ebc07628..8a8877e9f07 100644 --- a/src/sage/graphs/base/c_graph.pyx +++ b/src/sage/graphs/base/c_graph.pyx @@ -44,7 +44,7 @@ method :meth:`realloc `. # **************************************************************************** from sage.data_structures.bitset_base cimport * -from sage.rings.integer cimport Integer, smallInteger +from sage.rings.integer cimport smallInteger from sage.arith.long cimport pyobject_to_long from libcpp.queue cimport priority_queue, queue from libcpp.stack cimport stack @@ -3751,7 +3751,6 @@ cdef class CGraphBackend(GenericGraphBackend): # studied. cdef int x_int = self.get_vertex(x) cdef int y_int = self.get_vertex(y) - cdef int u = 0 cdef int v = 0 cdef int w = 0 cdef int pred @@ -3978,7 +3977,6 @@ cdef class CGraphBackend(GenericGraphBackend): # studied. cdef int x_int = self.get_vertex(x) cdef int y_int = self.get_vertex(y) - cdef int u = 0 cdef int v = 0 cdef int w = 0 cdef int pred @@ -4680,7 +4678,6 @@ cdef class CGraphBackend(GenericGraphBackend): # // answer = [u] cycle = [self.vertex_label(u)] - tmp = u while u != uu: u = parent.get(u, uu) cycle.append(self.vertex_label(u)) @@ -4899,7 +4896,7 @@ cdef class Search_iterator: sage: next(g.breadth_first_search(0)) 0 """ - cdef int v_int, v_dist + cdef int v_int cdef int w_int cdef int l cdef CGraph cg = self.graph.cg() diff --git a/src/sage/graphs/base/dense_graph.pyx b/src/sage/graphs/base/dense_graph.pyx index cd0aa5cf5a0..9cb0a1676ae 100644 --- a/src/sage/graphs/base/dense_graph.pyx +++ b/src/sage/graphs/base/dense_graph.pyx @@ -236,17 +236,15 @@ cdef class DenseGraph(CGraph): sage: D.realloc(30) sage: D.current_allocation() 30 - """ - cdef int i, j + cdef int i if not total_verts: raise RuntimeError('dense graphs must allocate space for vertices') cdef bitset_t bits - cdef int min_verts, min_longs + cdef int min_verts if total_verts < self.active_vertices.size: min_verts = total_verts - min_longs = -1 bitset_init(bits, self.active_vertices.size) bitset_set_first_n(bits, total_verts) if not bitset_issubset(self.active_vertices, bits): @@ -402,7 +400,7 @@ cdef class DenseGraph(CGraph): """ cdef int num_arcs_old = self.num_arcs - cdef size_t i, j + cdef size_t i i = bitset_next(self.active_vertices, 0) while i != -1: self.add_arc_unsafe(i, i) diff --git a/src/sage/graphs/base/graph_backends.pyx b/src/sage/graphs/base/graph_backends.pyx index 3ff36d5cee2..c0ffc56533e 100644 --- a/src/sage/graphs/base/graph_backends.pyx +++ b/src/sage/graphs/base/graph_backends.pyx @@ -47,7 +47,6 @@ For an overview of graph data structures in sage, see Classes and methods ------------------- """ - # **************************************************************************** # Copyright (C) 2008 Robert L. Miller # 2018 Julian Rüth @@ -58,8 +57,7 @@ Classes and methods # (at your option) any later version. # https://www.gnu.org/licenses/ # **************************************************************************** - -from .c_graph cimport CGraphBackend, CGraph +from .c_graph cimport CGraphBackend cdef class GenericGraphBackend(SageObject): diff --git a/src/sage/graphs/base/sparse_graph.pxd b/src/sage/graphs/base/sparse_graph.pxd index c6f40497b16..719ad0ef8c9 100644 --- a/src/sage/graphs/base/sparse_graph.pxd +++ b/src/sage/graphs/base/sparse_graph.pxd @@ -1,12 +1,12 @@ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2008-2009 Robert L. Miller # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .c_graph cimport CGraph, CGraphBackend cimport cython @@ -23,6 +23,7 @@ cdef struct SparseGraphBTNode: SparseGraphBTNode *left SparseGraphBTNode *right + @cython.final cdef class SparseGraph(CGraph): cdef int hash_length diff --git a/src/sage/graphs/base/sparse_graph.pyx b/src/sage/graphs/base/sparse_graph.pyx index 491f679e9c9..714da06e519 100644 --- a/src/sage/graphs/base/sparse_graph.pyx +++ b/src/sage/graphs/base/sparse_graph.pyx @@ -1009,10 +1009,9 @@ cdef class SparseGraph(CGraph): - a pointer to the first label or ``NULL`` if there are none """ - cdef int i = (u * self.hash_length) + (v & self.hash_mask), j - cdef int compared, num_arcs + cdef int i = (u * self.hash_length) + (v & self.hash_mask) + cdef int compared cdef SparseGraphBTNode *temp = self.vertices[i] - cdef SparseGraphLLNode *label while temp: compared = compare(temp.vertex, v) if compared > 0: diff --git a/src/sage/graphs/base/static_dense_graph.pyx b/src/sage/graphs/base/static_dense_graph.pyx index 3be26ccd32e..99bf7a8a117 100644 --- a/src/sage/graphs/base/static_dense_graph.pyx +++ b/src/sage/graphs/base/static_dense_graph.pyx @@ -216,7 +216,7 @@ def is_strongly_regular(g, parameters=False): cdef bitset_t b_tmp cdef int n = g.order() cdef int inter - cdef int i, j, l, k + cdef int i, j, k if not g.order() or not g.size(): # no vertices or no edges return False diff --git a/src/sage/graphs/base/static_sparse_backend.pyx b/src/sage/graphs/base/static_sparse_backend.pyx index ebd1539101a..c380777c0e7 100644 --- a/src/sage/graphs/base/static_sparse_backend.pyx +++ b/src/sage/graphs/base/static_sparse_backend.pyx @@ -684,7 +684,6 @@ cdef class StaticSparseBackend(CGraphBackend): raise LookupError("one of the two vertices does not belong to the graph") cdef StaticSparseCGraph cg = self._cg - cdef list l cdef uint32_t * edge = has_edge(cg.g, u, v) if not edge: @@ -696,9 +695,7 @@ cdef class StaticSparseBackend(CGraphBackend): # all labels. if self.multiple_edges(None): return self._all_edge_labels(u, v, edge) - - else: - return edge_label(cg.g, edge) + return edge_label(cg.g, edge) cdef inline list _all_edge_labels(self, int u, int v, uint32_t* edge=NULL): """ @@ -1079,7 +1076,7 @@ cdef class StaticSparseBackend(CGraphBackend): - ``2`` -- as ``1`` but ignore the labels """ cdef object v, l - cdef int u_int, prev_u_int, v_int, l_int, l_int_other, tmp + cdef int u_int, prev_u_int, v_int, l_int_other, tmp cdef StaticSparseCGraph cg = self._cg cdef CGraph cg_other = other.cg() cdef list b_vertices_2 diff --git a/src/sage/graphs/base/static_sparse_graph.pxd b/src/sage/graphs/base/static_sparse_graph.pxd index 7fb0fa7725d..b7d6be3a823 100644 --- a/src/sage/graphs/base/static_sparse_graph.pxd +++ b/src/sage/graphs/base/static_sparse_graph.pxd @@ -8,17 +8,17 @@ ctypedef unsigned int uint cdef extern from "stdlib.h": ctypedef void const_void "const void" void qsort(void *base, int nmemb, int size, - int(*compar)(const_void *, const_void *)) nogil + int(*compar)(const_void *, const_void *)) nogil void *bsearch(const_void *key, const_void *base, size_t nmemb, size_t size, int(*compar)(const_void *, const_void *)) nogil ctypedef struct short_digraph_s: - uint32_t * edges - uint32_t ** neighbors - PyObject * edge_labels - int m - int n + uint32_t * edges + uint32_t ** neighbors + PyObject * edge_labels + int m + int n ctypedef short_digraph_s short_digraph[1] diff --git a/src/sage/graphs/base/static_sparse_graph.pyx b/src/sage/graphs/base/static_sparse_graph.pyx index 22509f2028c..a1f246883ff 100644 --- a/src/sage/graphs/base/static_sparse_graph.pyx +++ b/src/sage/graphs/base/static_sparse_graph.pyx @@ -182,7 +182,6 @@ with C arguments). # **************************************************************************** cimport cpython -from libc.string cimport memset from libc.limits cimport INT_MAX from libc.math cimport sqrt from libcpp.vector cimport vector @@ -783,7 +782,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int cdef MemoryAllocator mem = MemoryAllocator() cdef size_t v, w, i cdef size_t s_nscc = nscc - cdef int tmp = nscc + 1 cdef vector[vector[int]] scc_list = vector[vector[int]](nscc, vector[int]()) cdef vector[vector[int]] sons = vector[vector[int]](nscc + 1, vector[int]()) cdef vector[int].iterator iter @@ -827,7 +825,6 @@ cdef void strongly_connected_components_digraph_C(short_digraph g, int nscc, int output.neighbors[0] = output.edges for v in range(1, s_nscc + 1): - degv = sons[v].size() output.neighbors[v] = output.neighbors[v - 1] + sons[v - 1].size() for i in range(sons[v].size()): output.neighbors[v][i] = sons[v][i] diff --git a/src/sage/graphs/generators/distance_regular.pyx b/src/sage/graphs/generators/distance_regular.pyx index 9cf706540f7..21de59680e5 100644 --- a/src/sage/graphs/generators/distance_regular.pyx +++ b/src/sage/graphs/generators/distance_regular.pyx @@ -1277,7 +1277,6 @@ def graph_from_GQ_spread(const int s, const int t): (GQ, S) = designs.generalised_quadrangle_with_spread(s, t, check=False) - k = len(GQ.blocks()[0]) edges = [] for b in GQ.blocks(): if b in S: # skip blocks in spread @@ -1286,8 +1285,7 @@ def graph_from_GQ_spread(const int s, const int t): sig_check() edges.append((p1, p2)) - G = Graph(edges, format="list_of_edges") - return G + return Graph(edges, format="list_of_edges") def GeneralisedDodecagonGraph(const int s, const int t): @@ -1763,8 +1761,6 @@ def _line_graph_generalised_polygon(H): sig_check() vToLines[p].append(l) - k = len(vToLines[lines[0][0]]) - edges = [] for v in vToLines: lines = vToLines[v] @@ -1772,8 +1768,7 @@ def _line_graph_generalised_polygon(H): sig_check() edges.append((l1, l2)) - G = Graph(edges, format="list_of_edges") - return G + return Graph(edges, format="list_of_edges") def _intersection_array_from_graph(G): diff --git a/src/sage/graphs/graph_decompositions/bandwidth.pyx b/src/sage/graphs/graph_decompositions/bandwidth.pyx index 9f0491c0078..74f7ea24644 100644 --- a/src/sage/graphs/graph_decompositions/bandwidth.pyx +++ b/src/sage/graphs/graph_decompositions/bandwidth.pyx @@ -254,7 +254,7 @@ def bandwidth(G, k=None): cdef range_t ** ith_range_array = mem.allocarray(n, sizeof(range_t *)) cdef range_t * range_array_tmp = mem.allocarray(n, sizeof(range_t)) - cdef int i, j, kk + cdef int i, kk # compute the distance matrix all_pairs_shortest_path_BFS(G, NULL, distances, NULL, vertex_list=int_to_vertex) diff --git a/src/sage/graphs/graph_decompositions/clique_separators.pyx b/src/sage/graphs/graph_decompositions/clique_separators.pyx index 35a1cf2a4b8..73a26a6615c 100644 --- a/src/sage/graphs/graph_decompositions/clique_separators.pyx +++ b/src/sage/graphs/graph_decompositions/clique_separators.pyx @@ -21,7 +21,6 @@ Methods # https://www.gnu.org/licenses/ # **************************************************************************** -from libcpp.pair cimport pair from libcpp.vector cimport vector from libc.stdint cimport uint32_t from cysignals.signals cimport sig_on, sig_off, sig_check @@ -523,8 +522,6 @@ def atoms_and_clique_separators(G, tree=False, rooted_tree=False, separators=Fal cdef vector[int] Sint_min cdef vector[int] Cint cdef vector[int] Hx - cdef size_t ui, vi - cdef bint stop for i in range(N): sig_check() diff --git a/src/sage/graphs/graph_decompositions/cutwidth.pyx b/src/sage/graphs/graph_decompositions/cutwidth.pyx index 4984be70a74..d7e605e9c91 100644 --- a/src/sage/graphs/graph_decompositions/cutwidth.pyx +++ b/src/sage/graphs/graph_decompositions/cutwidth.pyx @@ -528,6 +528,7 @@ def cutwidth_dyn(G, lower_bound=0): finally: sig_free(neighborhoods) + cdef inline int exists(FastDigraph g, uint8_t* neighborhoods, int S, int cost_S, int v, int k): r""" Check whether an ordering with the given cost `k` exists, and updates data @@ -571,7 +572,6 @@ cdef inline int exists(FastDigraph g, uint8_t* neighborhoods, int S, int cost_S, cdef int mini = ( -1) cdef int i - cdef int next_set # For each possible extension of the current set with a vertex, check whether # there exists a cheap path toward {1..n}, and update the cost. @@ -735,7 +735,7 @@ def cutwidth_MILP(G, lower_bound=0, solver=None, verbose=0, p.set_objective(z['z']) - obj = p.solve(log=verbose) + _ = p.solve(log=verbose) # We now extract the ordering and the cost of the solution val_x = p.get_values(x, convert=bool, tolerance=integrality_tolerance) diff --git a/src/sage/graphs/graph_decompositions/fast_digraph.pxd b/src/sage/graphs/graph_decompositions/fast_digraph.pxd index eee5267ecd3..85466f67ac1 100644 --- a/src/sage/graphs/graph_decompositions/fast_digraph.pxd +++ b/src/sage/graphs/graph_decompositions/fast_digraph.pxd @@ -10,5 +10,3 @@ cdef int compute_out_neighborhood_cardinality(FastDigraph, int) cdef int popcount32(int) cdef int slow_popcount32(int) - - diff --git a/src/sage/graphs/graph_decompositions/fast_digraph.pyx b/src/sage/graphs/graph_decompositions/fast_digraph.pyx index 667a1cb3972..fd75e5e63c3 100644 --- a/src/sage/graphs/graph_decompositions/fast_digraph.pyx +++ b/src/sage/graphs/graph_decompositions/fast_digraph.pyx @@ -12,10 +12,9 @@ cardinality). In the following code, sets are represented as integers, where the `i`-th bit is set if element `i` belongs to the set. """ - -from libc.stdint cimport uint8_t from cysignals.memory cimport check_allocarray, check_calloc, sig_free + cdef class FastDigraph: def __cinit__(self, D, vertex_list=None): @@ -53,7 +52,7 @@ cdef class FastDigraph: self.n = D.order() self.graph = check_calloc(self.n, sizeof(int)) - cdef int i, j + cdef int i cdef int tmp # When the vertices are not consecutive integers diff --git a/src/sage/graphs/graph_decompositions/graph_products.pyx b/src/sage/graphs/graph_decompositions/graph_products.pyx index a51013e6df4..ed85f6f7ef2 100644 --- a/src/sage/graphs/graph_decompositions/graph_products.pyx +++ b/src/sage/graphs/graph_decompositions/graph_products.pyx @@ -130,8 +130,6 @@ Methods # https://www.gnu.org/licenses/ # **************************************************************************** -from copy import copy - def is_cartesian_product(g, certificate=False, relabeling=False): r""" diff --git a/src/sage/graphs/graph_decompositions/rankwidth.pxd b/src/sage/graphs/graph_decompositions/rankwidth.pxd index 8483ba64a83..d24460b5bb9 100644 --- a/src/sage/graphs/graph_decompositions/rankwidth.pxd +++ b/src/sage/graphs/graph_decompositions/rankwidth.pxd @@ -10,6 +10,3 @@ cdef extern from "rw.h": subset_t *adjacency_matrix cdef void print_rank_dec(subset_t s, int l) - - - diff --git a/src/sage/graphs/graph_decompositions/tree_decomposition.pyx b/src/sage/graphs/graph_decompositions/tree_decomposition.pyx index 2d699a2c314..fb9b217a49d 100644 --- a/src/sage/graphs/graph_decompositions/tree_decomposition.pyx +++ b/src/sage/graphs/graph_decompositions/tree_decomposition.pyx @@ -99,18 +99,17 @@ Methods # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. -# http://www.gnu.org/licenses/ +# https://www.gnu.org/licenses/ # **************************************************************************** from sage.sets.set import Set from sage.misc.cachefunc import cached_function -from itertools import combinations from itertools import chain from sage.features import PythonModule from sage.sets.disjoint_set import DisjointSet from sage.rings.infinity import Infinity from sage.graphs.distances_all_pairs cimport c_distances_all_pairs -from cysignals.memory cimport sig_malloc, sig_calloc, sig_free +from cysignals.memory cimport sig_calloc, sig_free def is_valid_tree_decomposition(G, T): diff --git a/src/sage/graphs/graph_decompositions/vertex_separation.pyx b/src/sage/graphs/graph_decompositions/vertex_separation.pyx index 3138ee1fea2..98ab0800e52 100644 --- a/src/sage/graphs/graph_decompositions/vertex_separation.pyx +++ b/src/sage/graphs/graph_decompositions/vertex_separation.pyx @@ -268,7 +268,7 @@ from cysignals.memory cimport check_malloc, sig_malloc, sig_free from cysignals.signals cimport sig_check, sig_on, sig_off from sage.graphs.graph_decompositions.fast_digraph cimport FastDigraph, compute_out_neighborhood_cardinality, popcount32 -from libc.stdint cimport uint8_t, int8_t +from libc.stdint cimport uint8_t from sage.data_structures.binary_matrix cimport * from sage.graphs.base.static_dense_graph cimport dense_graph_init from sage.misc.decorators import rename_keyword @@ -985,7 +985,7 @@ def vertex_separation_exp(G, verbose=False): memset(neighborhoods, -1, mem) - cdef int i, j, k + cdef int i, k for k in range(g.n): if verbose: print("Looking for a strategy of cost", str(k)) @@ -1467,12 +1467,12 @@ def vertex_separation_MILP(G, integrality=False, solver=None, verbose=0, """ from sage.numerical.mip import MIPSolverException - p, x, u, y, z = _vertex_separation_MILP_formulation(G, integrality=integrality, solver=solver) + p, _, _, y, z = _vertex_separation_MILP_formulation(G, integrality=integrality, solver=solver) N = G.order() V = list(G) try: - obj = p.solve(log=verbose) + _ = p.solve(log=verbose) except MIPSolverException: if integrality: raise ValueError("unbounded or unexpected error") @@ -1835,9 +1835,9 @@ cdef int vertex_separation_BAB_C(binary_matrix_t H, # ==> Allocate local data structures - cdef bitset_s *loc_b_prefix = bm_pool.rows[3 * level] + cdef bitset_s *loc_b_prefix = bm_pool.rows[3 * level] cdef bitset_s *loc_b_pref_and_neigh = bm_pool.rows[3 * level + 1] - cdef bitset_s *b_tmp = bm_pool.rows[3 * level + 2] + cdef bitset_s *b_tmp = bm_pool.rows[3 * level + 2] bitset_copy(loc_b_prefix, b_prefix) bitset_copy(loc_b_pref_and_neigh, b_prefix_and_neighborhood) From d467ad130bf9fb2a232efe41c8c6b2214585ab24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Mon, 27 Mar 2023 09:04:10 +0200 Subject: [PATCH 46/61] fix and activate pep E271 in python files --- src/sage/categories/simplicial_sets.py | 12 ++++++------ .../modular/modform_hecketriangle/abstract_ring.py | 14 +++++++------- .../modular/modform_hecketriangle/constructor.py | 4 ++-- src/sage/modular/modsym/ambient.py | 2 +- src/tox.ini | 3 ++- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/sage/categories/simplicial_sets.py b/src/sage/categories/simplicial_sets.py index 0bfcae1d2a2..bcc7150186d 100644 --- a/src/sage/categories/simplicial_sets.py +++ b/src/sage/categories/simplicial_sets.py @@ -456,7 +456,7 @@ def covering_map(self, character): """ from sage.topology.simplicial_set import AbstractSimplex, SimplicialSet from sage.topology.simplicial_set_morphism import SimplicialSetMorphism - char = {a : b for (a,b) in character.items()} + char = {a: b for (a, b) in character.items()} G = list(char.values())[0].parent() if not G.is_finite(): raise NotImplementedError("can only compute universal covers of spaces with finite fundamental group") @@ -465,14 +465,14 @@ def covering_map(self, character): for s in self.n_cells(0): for g in G: - cell = AbstractSimplex(0,name="({}, {})".format(s, g)) - cells_dict[(s,g)] = cell + cell = AbstractSimplex(0, name="({}, {})".format(s, g)) + cells_dict[(s, g)] = cell char[s] = G.one() for d in range(1, self.dimension() + 1): for s in self.n_cells(d): if s not in char.keys(): - if d==1 and s.is_degenerate(): + if d == 1 and s.is_degenerate(): char[s] = G.one() elif s.is_degenerate(): if 0 in s.degeneracies(): @@ -483,8 +483,8 @@ def covering_map(self, character): char[s] = char[self.face(s, d)] if s.is_nondegenerate(): for g in G: - cell = AbstractSimplex(d,name="({}, {})".format(s, g)) - cells_dict[(s,g)] = cell + cell = AbstractSimplex(d, name="({}, {})".format(s, g)) + cells_dict[(s, g)] = cell fd = [] faces = self.faces(s) f0 = faces[0] diff --git a/src/sage/modular/modform_hecketriangle/abstract_ring.py b/src/sage/modular/modform_hecketriangle/abstract_ring.py index aa70599f0cc..2cc1cad715f 100644 --- a/src/sage/modular/modform_hecketriangle/abstract_ring.py +++ b/src/sage/modular/modform_hecketriangle/abstract_ring.py @@ -816,11 +816,11 @@ def _derivative_op(self): (X,Y,Z,dX,dY,dZ) = self.diff_alg().gens() if (self.hecke_n() == infinity): - return (X*Z-X*Y) * dX\ + return (X*Z-X*Y) * dX\ + ZZ(1)/ZZ(2) * (Y*Z-X) * dY\ + ZZ(1)/ZZ(4) * (Z**2-X) * dZ else: - return 1/self._group.n() * (X*Z-Y) * dX\ + return 1/self._group.n() * (X*Z-Y) * dX\ + ZZ(1)/ZZ(2) * (Y*Z-X**(self._group.n()-1)) * dY\ + (self._group.n()-2) / (4*self._group.n()) * (Z**2-X**(self._group.n()-2)) * dZ @@ -1926,18 +1926,18 @@ def EisensteinSeries(self, k=None): # The case n=infinity is special (there are 2 cusps) # Until we/I get confirmation what is what sort of Eisenstein series # this case is excluded... - if n == infinity: + if n == infinity: # We set the weight zero Eisenstein series to 1 pass - elif k == 0: + elif k == 0: return self.one() - elif k == 2: + elif k == 2: # This is a bit problematic, e.g. for n=infinity there is a # classical Eisenstein series of weight 2 return self.E2() - elif k == 4: + elif k == 4: return self.E4() - elif k == 6: + elif k == 6: return self.E6() # Basic variables diff --git a/src/sage/modular/modform_hecketriangle/constructor.py b/src/sage/modular/modform_hecketriangle/constructor.py index c7079c8779b..2caae3a8d7e 100644 --- a/src/sage/modular/modform_hecketriangle/constructor.py +++ b/src/sage/modular/modform_hecketriangle/constructor.py @@ -141,8 +141,8 @@ def rational_type(f, n=ZZ(3), base_ring=ZZ): num = R(f.numerator()) denom = R(f.denominator()) - ep_num = set([ZZ(1) - 2*(( sum([g.exponents()[0][m] for m in [1,2]]) )%2) for g in dhom(num).monomials()]) - ep_denom = set([ZZ(1) - 2*(( sum([g.exponents()[0][m] for m in [1,2]]) )%2) for g in dhom(denom).monomials()]) + ep_num = set([ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(num).monomials()]) + ep_denom = set([ZZ.one() - 2*((sum([g.exponents()[0][m] for m in [1, 2]])) % 2) for g in dhom(denom).monomials()]) if (n == infinity): hom_num = R( num.subs(x=x**4, y=y**2, z=z**2) ) diff --git a/src/sage/modular/modsym/ambient.py b/src/sage/modular/modsym/ambient.py index d6dbdaf36c0..5e4edab0658 100644 --- a/src/sage/modular/modsym/ambient.py +++ b/src/sage/modular/modsym/ambient.py @@ -1773,7 +1773,7 @@ def factorization(self): # We only run through spaces of level a multiple of the conductor of the character, which # we compute below, or set to 1 in case of Gamma_H or Gamma_1 chi = self.character() - cond = 1 if chi is None else chi.conductor() + cond = 1 if chi is None else chi.conductor() # Now actually run through the divisor levels, taking only the ones with that are # a multiple of the conductor. for d in reversed(divisors(self.level())): diff --git a/src/tox.ini b/src/tox.ini index a4ab5c3c40b..6d8c120e8ef 100644 --- a/src/tox.ini +++ b/src/tox.ini @@ -108,6 +108,7 @@ description = # Check for the following issues: # E111: indentation is not a multiple of four # E211: whitespace before '(' + # E271: multiple spaces after keyword # E306: expected 1 blank line before a nested definition, found 0 # E401: multiple imports on one line # E701: multiple statements on one line (colon) @@ -124,7 +125,7 @@ description = # W605: invalid escape sequence ‘x’ # See https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes deps = pycodestyle -commands = pycodestyle --select E111,E211,E306,E401,E701,E702,E703,W291,W391,W605,E711,E712,E713,E721,E722 {posargs:{toxinidir}/sage/} +commands = pycodestyle --select E111,E211,E271,E306,E401,E701,E702,E703,W291,W391,W605,E711,E712,E713,E721,E722 {posargs:{toxinidir}/sage/} pycodestyle --select E111,E306,E401,E703,W293,W391,W605,E712,E713,E714,E721,E722 --filename *.pyx {posargs:{toxinidir}/sage/} [pycodestyle] From a1add9c64caeb41322bcc32b107d7c15f9bc0ed1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Fri, 7 Apr 2023 12:05:52 +0200 Subject: [PATCH 47/61] fix pycodestyle E502 in coding and crypto folders --- src/sage/coding/abstract_code.py | 2 +- src/sage/coding/information_set_decoder.py | 4 +- src/sage/coding/self_dual_codes.py | 350 ++++++++++----------- src/sage/crypto/mq/sr.py | 116 +++---- 4 files changed, 236 insertions(+), 236 deletions(-) diff --git a/src/sage/coding/abstract_code.py b/src/sage/coding/abstract_code.py index c041e8d0eb2..ead76be288a 100644 --- a/src/sage/coding/abstract_code.py +++ b/src/sage/coding/abstract_code.py @@ -127,7 +127,7 @@ def _explain_constructor(cl): var = "It accepts unspecified arguments as well.\n" else: var = "" - return("{}\n{}\n{}See the documentation of {}.{} for more details."\ + return("{}\n{}\n{}See the documentation of {}.{} for more details." .format(reqs, opts, var, cl.__module__, cl.__name__)) diff --git a/src/sage/coding/information_set_decoder.py b/src/sage/coding/information_set_decoder.py index 52f14af976a..fb4612fa69b 100644 --- a/src/sage/coding/information_set_decoder.py +++ b/src/sage/coding/information_set_decoder.py @@ -583,7 +583,7 @@ def time_search_loop(p): def compute_estimate(p): iters = 1.* binomial(n, k)/ \ sum( binomial(n-tau, k-i)*binomial(tau,i) for i in range(p+1) ) - estimate = iters*(T + \ + estimate = iters*(T + sum(P[pi] * (q-1)**pi * binomial(k, pi) for pi in range(p+1) )) return estimate @@ -846,7 +846,7 @@ def __init__(self, code, number_errors, algorithm=None, **kwargs): self._algorithm = algorithm_names[algorithm](code, number_errors, **kwargs) else: raise ValueError("Unknown ISD algorithm '{}'." - " The known algorithms are {}."\ + " The known algorithms are {}." .format(algorithm, sorted(algorithm_names))) _known_algorithms = { diff --git a/src/sage/coding/self_dual_codes.py b/src/sage/coding/self_dual_codes.py index 4dcdcdff82f..f2a3e8cd2a2 100644 --- a/src/sage/coding/self_dual_codes.py +++ b/src/sage/coding/self_dual_codes.py @@ -213,12 +213,12 @@ def _And7(): [1 0 1 1 0 0 0] [1 1 0 1 0 0 0] """ - return matrix(_F, [[1, 1, 1, 0, 0, 1, 1],\ - [1, 1, 1, 0, 1, 0, 1],\ - [1, 1, 1, 0, 1, 1, 0],\ - [0, 0, 0, 0, 1, 1, 1],\ - [0, 1, 1, 1, 0, 0, 0],\ - [1, 0, 1, 1, 0, 0, 0],\ + return matrix(_F, [[1, 1, 1, 0, 0, 1, 1], + [1, 1, 1, 0, 1, 0, 1], + [1, 1, 1, 0, 1, 1, 0], + [0, 0, 0, 0, 1, 1, 1], + [0, 1, 1, 1, 0, 0, 0], + [1, 0, 1, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0, 0]]) @cached_function @@ -239,13 +239,13 @@ def _H8(): [ 1 1 -1 -1 -1 -1 1 1] [ 1 -1 -1 1 -1 1 1 -1] """ - return matrix(ZZ, [[1, 1, 1, 1, 1, 1, 1, 1],\ - [1, -1, 1, -1, 1, -1, 1, -1],\ - [1, 1, -1, -1, 1, 1, -1, -1],\ - [1, -1, -1, 1, 1, -1, -1, 1],\ - [1, 1, 1, 1, -1, -1, -1, -1],\ - [1, -1, 1, -1, -1, 1, -1, 1],\ - [1, 1, -1, -1, -1, -1, 1, 1],\ + return matrix(ZZ, [[1, 1, 1, 1, 1, 1, 1, 1], + [1, -1, 1, -1, 1, -1, 1, -1], + [1, 1, -1, -1, 1, 1, -1, -1], + [1, -1, -1, 1, 1, -1, -1, 1], + [1, 1, 1, 1, -1, -1, -1, -1], + [1, -1, 1, -1, -1, 1, -1, 1], + [1, 1, -1, -1, -1, -1, 1, 1], [1, -1, -1, 1, -1, 1, 1, -1]]) # from Guava's Hadamard matrices database # Remark: The above matrix constructions aid in computing some "small" self-dual codes. @@ -305,7 +305,7 @@ def self_dual_binary_codes(n): genmat = _I2(n).augment(_I2(n)) # G = PermutationGroup([ "(2,4)", "(1,2)(3,4)" ]) spectrum = [1, 0, 2, 0, 1] - self_dual_codes_4_0 = {"order autgp":8,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_4_0 = {"order autgp":8,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique."} self_dual_codes["4"] = {"0":self_dual_codes_4_0} return self_dual_codes @@ -316,7 +316,7 @@ def self_dual_binary_codes(n): genmat = _I2(n).augment(_I2(n)) # G = PermutationGroup( ["(3,6)", "(2,3)(5,6)", "(1,2)(4,5)"] ) spectrum = [1, 0, 3, 0, 3, 0, 1] - self_dual_codes_6_0 = {"order autgp":48,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_6_0 = {"order autgp":48,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique"} self_dual_codes["6"] = {"0":self_dual_codes_6_0} return self_dual_codes @@ -328,14 +328,14 @@ def self_dual_binary_codes(n): genmat = _I2(n).augment(_I2(n)) # G = PermutationGroup( ["(4,8)", "(3,4)(7,8)", "(2,3)(6,7)", "(1,2)(5,6)"] ) spectrum = [1, 0, 4, 0, 6, 0, 4, 0, 1] - self_dual_codes_8_0 = {"order autgp":384,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_8_0 = {"order autgp":384,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique Type I of this length."} # [8,1]: genmat = _I2(n).augment(_matA(n)[4]) # G = PermutationGroup( ["(4,5)(6,7)", "(4,6)(5,7)", "(3,4)(7,8)",\ # "(2,3)(6,7)", "(1,2)(5,6)"] ) spectrum = [1, 0, 0, 0, 14, 0, 0, 0, 1] - self_dual_codes_8_1 = {"order autgp":1344,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_8_1 = {"order autgp":1344,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"II","Comment":"Unique Type II of this length."} self_dual_codes["8"] = {"0":self_dual_codes_8_0,"1":self_dual_codes_8_1} return self_dual_codes @@ -347,14 +347,14 @@ def self_dual_binary_codes(n): # G = PermutationGroup( ["(5,10)", "(4,5)(9,10)", "(3,4)(8,9)",\ # "(2,3)(7,8)", "(1,2)(6,7)"] ) spectrum = [1, 0, 5, 0, 10, 0, 10, 0, 5, 0, 1] - self_dual_codes_10_0 = {"order autgp":3840,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_10_0 = {"order autgp":3840,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"No Type II of this length."} # [10,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) # G = PermutationGroup( ["(5,10)", "(4,6)(7,8)", "(4,7)(6,8)", "(3,4)(8,9)",\ # "(2,3)(7,8)", "(1,2)(6,7)"] ) spectrum = [1, 0, 1, 0, 14, 0, 14, 0, 1, 0, 1] - self_dual_codes_10_1 = {"order autgp":2688,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_10_1 = {"order autgp":2688,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique lowest weight nonzero codeword."} self_dual_codes["10"] = {"0":self_dual_codes_10_0,"1":self_dual_codes_10_1} return self_dual_codes @@ -366,21 +366,21 @@ def self_dual_binary_codes(n): # G = PermutationGroup( ["(6,12)", "(5,6)(11,12)", "(4,5)(10,11)", "(3,4)(9,10)",\ # "(2,3)(8,9)", "(1,2)(7,8)"] ) spectrum = [1, 0, 6, 0, 15, 0, 20, 0, 15, 0, 6, 0, 1] - self_dual_codes_12_0 = {"order autgp":48080,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_12_0 = {"order autgp":48080,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"No Type II of this length."} # [12,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) # G = PermutationGroup( ["(2,3)(4,7)", "(2,4)(3,7)", "(2,4,9)(3,7,8)", "(2,4,8,10)(3,9)",\ # "(1,2,4,7,8,10)(3,9)", "(2,4,8,10)(3,9)(6,12)", "(2,4,8,10)(3,9)(5,6,11,12)"] ) spectrum = [1, 0, 2, 0, 15, 0, 28, 0, 15, 0, 2, 0, 1] - self_dual_codes_12_1 = {"order autgp":10752,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_12_1 = {"order autgp":10752,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Smallest automorphism group of these."} # [12,2]: genmat = _I2(n).augment(_matA(n)[6]) # G = PermutationGroup( ["(5,6)(11,12)", "(5,11)(6,12)", "(4,5)(10,11)", "(3,4)(9,10)",\ # "(2,3)(8,9)", "(1,2)(7,8)"] ) spectrum = [1, 0, 0, 0, 15, 0, 32, 0, 15, 0, 0, 0, 1] - self_dual_codes_12_2 = {"order autgp":23040,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_12_2 = {"order autgp":23040,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Largest minimum distance of these."} self_dual_codes["12"] = {"0":self_dual_codes_12_0,"1":self_dual_codes_12_1,"2":self_dual_codes_12_2} return self_dual_codes @@ -393,21 +393,21 @@ def self_dual_binary_codes(n): # G = PermutationGroup( ["(7,14)", "(6,7)(13,14)", "(5,6)(12,13)", "(4,5)(11,12)",\ # "(3,4)(10,11)", "(2,3)(9,10)", "(1,2)(8,9)"] ) spectrum = [1, 0, 7, 0, 21, 0, 35, 0, 35, 0, 21, 0, 7, 0, 1] - self_dual_codes_14_0 = {"order autgp":645120,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_14_0 = {"order autgp":645120,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"No Type II of this length. Huge aut gp."} # [14,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) # G = PermutationGroup( ["(7,14)", "(6,7)(13,14)", "(5,6)(12,13)", "(4,8)(9,10)",\ # "(4,9)(8,10)", "(3,4)(10,11)", "(2,3)(9,10)", "(1,2)(8,9)"] ) spectrum = [1, 0, 3, 0, 17, 0, 43, 0, 43, 0, 17, 0, 3, 0, 1] - self_dual_codes_14_1 = {"order autgp":64512,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_14_1 = {"order autgp":64512,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Automorphism group has order 64512."} # [14,2]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matId(n)[6]])) # G = PermutationGroup( ["(7,14)", "(5,6)(12,13)", "(5,12)(6,13)", "(4,5)(11,12)",\ # "(3,4)(10,11)", "(2,3)(9,10)", "(1,2)(8,9)"] ) spectrum = [1, 0, 1, 0, 15, 0, 47, 0, 47, 0, 15, 0, 1, 0, 1] - self_dual_codes_14_2 = {"order autgp":46080,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_14_2 = {"order autgp":46080,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique codeword of weight 2."} # [14,3]: genmat = _I2(n).augment(_And7()) @@ -415,9 +415,9 @@ def self_dual_binary_codes(n): # "(6,10)(9,14)", "(5,6)(8,9)", "(4,5)(9,10), (2,3)(11,12)", "(2,7)(3,13)",\ # "(1,2)(12,13)", "(1,4)(2,5)(3,8)(6,7)(9,13)(10,12)(11,14)"]) spectrum = [1, 0, 0, 0, 14, 0, 49, 0, 49, 0, 14, 0, 0, 0, 1] - self_dual_codes_14_3 = {"order autgp":56448,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_14_3 = {"order autgp":56448,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Largest minimum distance of these."} - self_dual_codes["14"] = {"0":self_dual_codes_14_0,"1":self_dual_codes_14_1,"2":self_dual_codes_14_2,\ + self_dual_codes["14"] = {"0":self_dual_codes_14_0,"1":self_dual_codes_14_1,"2":self_dual_codes_14_2, "3":self_dual_codes_14_3} return self_dual_codes @@ -429,14 +429,14 @@ def self_dual_binary_codes(n): # G = PermutationGroup( [ "(8,16)", "(7,8)(15,16)", "(6,7)(14,15)", "(5,6)(13,14)", # "(4,5)(12,13)", "(3,4)(11,12)", "(2,3)(10,11)", "(1,2)(9,10)"] ) spectrum = [1, 0, 8, 0, 28, 0, 56, 0, 70, 0, 56, 0, 28, 0, 8, 0, 1] - self_dual_codes_16_0 = {"order autgp":10321920,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_0 = {"order autgp":10321920,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Huge aut gp."} # [16,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) # G = PermutationGroup( [ "(8,16)", "(7,8)(15,16)", "(6,7)(14,15)", "(5,6)(13,14)",\ # "(4,9)(10,11)", "(4,10)(9,11)", "(3,4)(11,12)", "(2,3)(10,11)", "(1,2)(9,10)"] ) spectrum = [1, 0, 4, 0, 20, 0, 60, 0, 86, 0, 60, 0, 20, 0, 4, 0, 1] - self_dual_codes_16_1 = {"order autgp":516096,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_1 = {"order autgp":516096,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [16,2]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matA(n)[4]])) @@ -444,14 +444,14 @@ def self_dual_binary_codes(n): # "(5,6)(13,14)", "(4,9)(10,11)", "(4,10)(9,11)", "(3,4)(11,12)", "(2,3)(10,11)",\ # "(1,2)(9,10)","(1,5)(2,6)(3,7)(4,8)(9,13)(10,14)(11,15)(12,16)"] ) spectrum = [1, 0, 0, 0, 28, 0, 0, 0, 198, 0, 0, 0, 28, 0, 0, 0, 1] - self_dual_codes_16_2 = {"order autgp":3612672,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_2 = {"order autgp":3612672,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"II","Comment":"Same spectrum as the other Type II code."} # [16,3]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matId(n)[6]])) # G = PermutationGroup( [ "(8,16)", "(7,8)(15,16)", "(5,6)(13,14)", "(5,13)(6,14)",\ # "(4,5)(12,13)", "(3,4)(11,12)", "(2,3)(10,11)", "(1,2)(9,10)"] ) spectrum = [1, 0, 2, 0, 16, 0, 62, 0, 94, 0, 62, 0, 16, 0, 2, 0, 1] - self_dual_codes_16_3 = {"order autgp":184320,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_3 = {"order autgp":184320,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [16,4]: genmat = _I2(n).augment(_matA(n)[8]) @@ -467,7 +467,7 @@ def self_dual_binary_codes(n): # G = PermutationGroup( [ "(7,8)(15,16)", "(7,15)(8,16)", "(6,7)(14,15)",\ # "(5,6)(13,14)","(4,5)(12,13)","(3,4)(11,12)", "(2,3)(10,11)", "(1,2)(9,10)"] ) spectrum = [1, 0, 0, 0, 28, 0, 0, 0, 198, 0, 0, 0, 28, 0, 0, 0, 1] - self_dual_codes_16_4 = {"order autgp":5160960,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_4 = {"order autgp":5160960,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"II","Comment":"Same spectrum as the other Type II code. Large aut gp."} # [16,5]: genmat = _I2(n).augment(block_diagonal_matrix([_And7(),_matId(n)[7]])) @@ -476,7 +476,7 @@ def self_dual_binary_codes(n): # "(2,3)(12,13)", "(2,7)(3,14)", "(1,2)(13,14)",\ # "(1,4)(2,5)(3,9)(6,7)(10,14)(11,13)(12,15)" ] ) spectrum = [1, 0, 1, 0, 14, 0, 63, 0, 98, 0, 63, 0, 14, 0, 1, 0, 1] - self_dual_codes_16_5 = {"order autgp":112896,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_5 = {"order autgp":112896,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"'Exceptional' construction."} # [16,6]: J8 = MatrixSpace(ZZ,8,8)(64*[1]) @@ -485,9 +485,9 @@ def self_dual_binary_codes(n): # "(4,6)(11,13)", "(3,5)(12,14)", "(3,12)(5,14)", "(2,3)(14,15)",\ # "(1,2)(8,15)", "(1,4)(2,6)(3,7)(5,16)(8,13)(9,12)(10,14)(11,15)" ] ) spectrum = [1, 0, 0, 0, 12, 0, 64, 0, 102, 0, 64, 0, 12, 0, 0, 0, 1] - self_dual_codes_16_6 = {"order autgp":73728,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_16_6 = {"order autgp":73728,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"'Exceptional' construction. Min dist 4."} - self_dual_codes["16"] = {"0":self_dual_codes_16_0,"1":self_dual_codes_16_1,"2":self_dual_codes_16_2,\ + self_dual_codes["16"] = {"0":self_dual_codes_16_0,"1":self_dual_codes_16_1,"2":self_dual_codes_16_2, "3":self_dual_codes_16_3,"4":self_dual_codes_16_4,"5":self_dual_codes_16_5,"6":self_dual_codes_16_6} return self_dual_codes @@ -500,7 +500,7 @@ def self_dual_binary_codes(n): # G = PermutationGroup( [ "(9,18)", "(8,9)(17,18)", "(7,8)(16,17)", "(6,7)(15,16)",\ # "(5,6)(14,15)", "(4,5)(13,14)", "(3,4)(12,13)", "(2,3)(11,12)", "(1,2)(10,11)" ] ) spectrum = [1, 0, 9, 0, 36, 0, 84, 0, 126, 0, 126, 0, 84, 0, 36, 0, 9, 0, 1] - self_dual_codes_18_0 = {"order autgp":185794560,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_0 = {"order autgp":185794560,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Huge aut gp. S_9x(ZZ/2ZZ)^9?"} # [18,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) @@ -508,14 +508,14 @@ def self_dual_binary_codes(n): # "(5,6)(14,15)", "(4,10)(11,12)", "(4,11)(10,12)", "(3,4)(12,13)",\ # "(2,3)(11,12)", "(1,2)(10,11)" ] ) spectrum = [1, 0, 5, 0, 24, 0, 80, 0, 146, 0, 146, 0, 80, 0, 24, 0, 5, 0, 1] - self_dual_codes_18_1 = {"order autgp":5160960,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_1 = {"order autgp":5160960,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Large aut gp."} # [18,2]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matId(n)[6]])) # G = PermutationGroup( [ "(9,18)", "(8,9)(17,18)", "(7,8)(16,17)", "(5,6)(14,15)",\ # "(5,14)(6,15)","(4,5)(13,14)", "(3,4)(12,13)", "(2,3)(11,12)", "(1,2)(10,11)"] ) spectrum = [1, 0, 3, 0, 18, 0, 78, 0, 156, 0, 156, 0, 78, 0, 18, 0, 3, 0, 1] - self_dual_codes_18_2 = {"order autgp":1105920,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_2 = {"order autgp":1105920,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": ""} # [18,3]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matA(n)[4],_matId(n)[8]])) @@ -524,7 +524,7 @@ def self_dual_binary_codes(n): # "(3,4)(12,13)", "(2,3)(11,12)","(1,2)(10,11)",\ # "(1,5)(2,6)(3,7)(4,8)(10,14)(11,15)(12,16)(13,17)" ] ) spectrum = [1, 0, 1, 0, 28, 0, 28, 0, 198, 0, 198, 0, 28, 0, 28, 0, 1, 0, 1] - self_dual_codes_18_3 = {"order autgp":7225344,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_3 = {"order autgp":7225344,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Large aut gp. Unique codeword of smallest non-zero wt.\ Same spectrum as '[18,4]' sd code."} # [18,4]: @@ -532,7 +532,7 @@ def self_dual_binary_codes(n): # G = PermutationGroup( [ "(9,18)", "(7,8)(16,17)", "(7,16)(8,17)", "(6,7)(15,16)", \ # "(5,6)(14,15)", "(4,5)(13,14)", "(3,4)(12,13)", "(2,3)(11,12)", "(1,2)(10,11)" ] ) spectrum = [1, 0, 1, 0, 28, 0, 28, 0, 198, 0, 198, 0, 28, 0, 28, 0, 1, 0, 1] - self_dual_codes_18_4 = {"order autgp":10321920,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_4 = {"order autgp":10321920,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Huge aut gp. Unique codeword of smallest non-zero wt.\ Same spectrum as '[18,3]' sd code."} # [18,5]: @@ -546,27 +546,27 @@ def self_dual_binary_codes(n): # "(2,16,14)(3,15,4)(5,11,10,7,12,6,13)(9,18)",\ # "(2,16,14)(3,15,4)(5,11,10,7,12,6,13)(8,9,17,18)" ] ) spectrum = [1, 0, 2, 0, 15, 0, 77, 0, 161, 0, 161, 0, 77, 0, 15, 0, 2, 0, 1] - self_dual_codes_18_5 = {"order autgp":451584,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_5 = {"order autgp":451584,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional' construction."} # [18,6]: C = self_dual_binary_codes(n-2)["%s"%(n-2)]["6"]["code"] A0 = C.redundancy_matrix() genmat = _I2(n).augment(block_diagonal_matrix([A0,_matId(n)[8]])) - G = PermutationGroup( [ "(9,18)", "(7,10)(11,17)", "(7,11)(10,17)", "(6,7)(11,12)",\ - "(4,6)(12,14)", "(3,5)(13,15)", "(3,13)(5,15)", "(2,3)(15,16)", "(1,2)(8,16)",\ + G = PermutationGroup( [ "(9,18)", "(7,10)(11,17)", "(7,11)(10,17)", "(6,7)(11,12)", + "(4,6)(12,14)", "(3,5)(13,15)", "(3,13)(5,15)", "(2,3)(15,16)", "(1,2)(8,16)", "(1,4)(2,6)(3,7)(5,17)(8,14)(10,13)(11,15)(12,16)" ] ) spectrum = [1, 0, 1, 0, 12, 0, 76, 0, 166, 0, 166, 0, 76, 0, 12, 0, 1, 0, 1] - self_dual_codes_18_6 = {"order autgp":147456,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_6 = {"order autgp":147456,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional'. Unique codeword of smallest non-zero wt."} # [18,7] (equiv to H18 in [P]) - genmat = _MS(n)([[1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0],\ - [0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1],\ - [0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1],\ - [0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1],\ - [0,0,0,0,1,0,0,0,0,1,1,0,0,1,0,1,1,0],\ - [0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,1,0],\ - [0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0],\ - [0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1],\ + genmat = _MS(n)([[1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0], + [0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1], + [0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1], + [0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1], + [0,0,0,0,1,0,0,0,0,1,1,0,0,1,0,1,1,0], + [0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,1,0], + [0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0], + [0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1], [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1]]) # G = PermutationGroup( [ "(9,10)(16,18)", "(9,16)(10,18)", "(8,9)(14,16)",\ # "(7,11)(12,17)", "(7,12)(11,17)", "(5,6)(11,12)", "(5,7)(6,17)",\ @@ -574,35 +574,35 @@ def self_dual_binary_codes(n): # "(1,2)(5,8)(6,14)(7,9)(10,12)(11,18)(16,17)", "(1,3)(2,15)",\ # "(1,5)(2,6)(3,7)(4,11)(10,18)(12,13)(15,17)" ] ) spectrum = [1, 0, 0, 0, 9, 0, 75, 0, 171, 0, 171, 0, 75, 0, 9, 0, 0, 0, 1] - self_dual_codes_18_7 = {"order autgp":82944,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_7 = {"order autgp":82944,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional' construction. Min dist 4."} # [18, 8] (equiv to I18 in [P]) - I18 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],\ - [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0],\ - [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1],\ + I18 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0], + [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1], [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]) - genmat = _MS(n)([[1,0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 0, 0, 0, 0],\ - [0,1,0,0,0,0,0,0,0, 1, 0, 1, 1, 1, 0, 1, 1, 1],\ - [0,0,1,0,0,0,0,0,0, 0, 1, 1, 0, 0, 0, 1, 1, 1],\ - [0,0,0,1,0,0,0,0,0, 0, 1, 0, 0, 1, 0, 1, 1, 1],\ - [0,0,0,0,1,0,0,0,0, 0, 1, 0, 1, 0, 0, 1, 1, 1],\ - [0,0,0,0,0,1,0,0,0, 1, 1, 0, 0, 0, 0, 1, 1, 1],\ - [0,0,0,0,0,0,1,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1],\ - [0,0,0,0,0,0,0,1,0, 0, 0, 0, 0, 0, 1, 1, 0, 1],\ + genmat = _MS(n)([[1,0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 0, 0, 0, 0], + [0,1,0,0,0,0,0,0,0, 1, 0, 1, 1, 1, 0, 1, 1, 1], + [0,0,1,0,0,0,0,0,0, 0, 1, 1, 0, 0, 0, 1, 1, 1], + [0,0,0,1,0,0,0,0,0, 0, 1, 0, 0, 1, 0, 1, 1, 1], + [0,0,0,0,1,0,0,0,0, 0, 1, 0, 1, 0, 0, 1, 1, 1], + [0,0,0,0,0,1,0,0,0, 1, 1, 0, 0, 0, 0, 1, 1, 1], + [0,0,0,0,0,0,1,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1], + [0,0,0,0,0,0,0,1,0, 0, 0, 0, 0, 0, 1, 1, 0, 1], [0,0,0,0,0,0,0,0,1, 0, 0, 0, 0, 0, 1, 1, 1, 0]]) - G = PermutationGroup( [ "(9,15)(16,17)", "(9,16)(15,17)", "(8,9)(17,18)",\ - "(7,8)(16,17)", "(5,6)(10,13)", "(5,10)(6,13)", "(4,5)(13,14)",\ + G = PermutationGroup( [ "(9,15)(16,17)", "(9,16)(15,17)", "(8,9)(17,18)", + "(7,8)(16,17)", "(5,6)(10,13)", "(5,10)(6,13)", "(4,5)(13,14)", "(3,4)(12,14)", "(1,2)(6,10)", "(1,3)(2,12)" ] ) spectrum = [1, 0, 0, 0, 17, 0, 51, 0, 187, 0, 187, 0, 51, 0, 17, 0, 0, 0, 1] - self_dual_codes_18_8 = {"order autgp":322560,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_18_8 = {"order autgp":322560,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional' construction. Min dist 4."} - self_dual_codes["18"] = {"0":self_dual_codes_18_0,"1":self_dual_codes_18_1,"2":self_dual_codes_18_2,\ - "3":self_dual_codes_18_3,"4":self_dual_codes_18_4,"5":self_dual_codes_18_5,\ + self_dual_codes["18"] = {"0":self_dual_codes_18_0,"1":self_dual_codes_18_1,"2":self_dual_codes_18_2, + "3":self_dual_codes_18_3,"4":self_dual_codes_18_4,"5":self_dual_codes_18_5, "6":self_dual_codes_18_6,"7":self_dual_codes_18_7,"8":self_dual_codes_18_8} return self_dual_codes @@ -610,22 +610,22 @@ def self_dual_binary_codes(n): # all of these of these are Type I; 2 of these codes # are formally equivalent but with different automorphism groups; # one of these has a unique codeword of lowest weight - A10 = MatrixSpace(_F,10,10)([[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],\ - [1, 1, 1, 0, 1, 0, 1, 0, 1, 1],\ - [1, 0, 0, 1, 0, 1, 0, 1, 0, 1],\ - [0, 0, 0, 1, 1, 1, 0, 1, 0, 1],\ - [0, 0, 1, 1, 0, 1, 0, 1, 0, 1],\ - [0, 0, 0, 1, 0, 1, 1, 1, 0, 1],\ - [0, 1, 0, 1, 0, 1, 0, 1, 0, 1],\ - [0, 0, 0, 1, 0, 0, 0, 0, 1, 1],\ - [0, 0, 0, 0, 0, 1, 0, 0, 1, 1],\ + A10 = MatrixSpace(_F,10,10)([[1, 1, 1, 1, 1, 1, 1, 1, 1, 0], + [1, 1, 1, 0, 1, 0, 1, 0, 1, 1], + [1, 0, 0, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 1, 1, 0, 1, 0, 1], + [0, 0, 1, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 0, 1, 1, 1, 0, 1], + [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 1, 0, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]]) # [20,0]: genmat = _I2(n).augment(_I2(n)) # G = PermutationGroup( ["(10,20)", "(9,10)(19,20)", "(8,9)(18,19)", "(7,8)(17,18)", "(6,7)(16,17)",\ # "(5,6)(15,16)", "(4,5)(14,15)", "(3,4)(13,14)", "(2,3)(12,13)", "(1,2)(11,12)"] ) spectrum = [1, 0, 10, 0, 45, 0, 120, 0, 210, 0, 252, 0, 210, 0, 120, 0, 45, 0, 10, 0, 1] - self_dual_codes_20_0 = {"order autgp":3715891200,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_0 = {"order autgp":3715891200,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Huge aut gp"} # [20,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) @@ -633,7 +633,7 @@ def self_dual_binary_codes(n): # "(5,6)(15,16)", "(4,11)(12,13)", "(4,12)(11,13)", "(3,4)(13,14)",\ # "(2,3)(12,13)", "(1,2)(11,12)"] ) spectrum = [1, 0, 6, 0, 29, 0, 104, 0, 226, 0, 292, 0, 226, 0, 104, 0, 29, 0, 6, 0, 1] - self_dual_codes_20_1 = {"order autgp":61931520,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_1 = {"order autgp":61931520,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [20,2]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matId(n)[6]])) @@ -641,7 +641,7 @@ def self_dual_binary_codes(n): # "(5,6)(15,16)", "(5,15)(6,16)", "(4,5)(14,15)", "(3,4)(13,14)",\ # "(2,3)(12,13)", "(1,2)(11,12)"] ) spectrum = [1, 0, 4, 0, 21, 0, 96, 0, 234, 0, 312, 0, 234, 0, 96, 0, 21, 0, 4, 0, 1] - self_dual_codes_20_2 = {"order autgp":8847360,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_2 = {"order autgp":8847360,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [20,3]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matA(n)[4]])) @@ -649,7 +649,7 @@ def self_dual_binary_codes(n): # "(2,3)(12,13)", "(1,2)(11,12)", "(8,17)(9,10)", "(8,10)(9,17)", "(8,10,20)(9,19,17)",\ # "(8,19,20,9,17,10,18)", "(7,8,19,20,9,18)(10,17)"] ) spectrum =[1, 0, 0, 0, 29, 0, 32, 0, 226, 0, 448, 0, 226, 0, 32, 0, 29, 0, 0, 0, 1] - self_dual_codes_20_3 = {"order autgp":30965760,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_3 = {"order autgp":30965760,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Min dist 4."} # [20,4]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matA(n)[4],_matId(n)[8]])) @@ -660,7 +660,7 @@ def self_dual_binary_codes(n): # "(2,3,12)(4,11,14)(5,17,18)(6,15,8)(10,20)",\ # "(2,3,12)(4,11,14)(5,17,18)(6,15,8)(9,10,19,20)"] ) spectrum =[1, 0, 2, 0, 29, 0, 56, 0, 226, 0, 396, 0, 226, 0, 56, 0, 29, 0, 2, 0, 1] - self_dual_codes_20_4 = {"order autgp":28901376,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_4 = {"order autgp":28901376,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [20,5]: genmat = _I2(n).augment(block_diagonal_matrix([_And7(),_matId(n)[7]])) @@ -669,7 +669,7 @@ def self_dual_binary_codes(n): # "(4,15)(16,17)", "(4,16)(15,17)", "(2,3)(16,17)", "(2,4)(3,15)",\ # "(1,2)(15,16)", "(1,5)(2,6)(3,13)(4,7)(11,16)(12,15)(14,17)" ] ) # order 2709504 spectrum = [1, 0, 3, 0, 17, 0, 92, 0, 238, 0, 322, 0, 238, 0, 92, 0, 17, 0, 3, 0, 1] - self_dual_codes_20_5 = {"order autgp":2709504,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_5 = {"order autgp":2709504,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional' construction."} # [20,6]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[8],_matId(n)[8]])) @@ -677,7 +677,7 @@ def self_dual_binary_codes(n): # "(4,5)(14,15)", "(3,4)(13,14)", "(2,3)(12,13)", "(1,2)(11,12)",\ # "(10,20)", "(9,10,19,20)"] ) spectrum = [1, 0, 2, 0, 29, 0, 56, 0, 226, 0, 396, 0, 226, 0, 56, 0, 29, 0, 2, 0, 1] - self_dual_codes_20_6 = {"order autgp":41287680,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_6 = {"order autgp":41287680,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [20,7]: A0 = self_dual_binary_codes(n-4)["16"]["6"]["code"].redundancy_matrix() @@ -687,47 +687,47 @@ def self_dual_binary_codes(n): # "(3,14)(5,16)", "(2,3)(16,17)", "(1,2)(8,17)",\ # "(1,4)(2,6)(3,7)(5,18)(8,15)(11,14)(12,16)(13,17)" ] ) spectrum = [1,0,2,0,13,0,88,0,242,0,332,0,242,0,88,0,13,0,2,0,1] - self_dual_codes_20_7 = {"order autgp":589824,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_7 = {"order autgp":589824,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"'Exceptional' construction."} # [20,8]: (genmat, J20, and genmat2 are all equiv) genmat = _I2(n).augment(_matA(n)[10]) - J20 = _MS(n)([[1,1,1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1],\ + J20 = _MS(n)([[1,1,1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0,0,1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], [1,0,1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0]]) - genmat2 = _MS(n)([[1,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1],\ - [0,1,0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1],\ - [0,0,1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0],\ - [0,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0],\ + genmat2 = _MS(n)([[1,0,0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1], + [0,1,0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1], + [0,0,1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], + [0,0,0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0], + [0,0,0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0], + [0,0,0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0], + [0,0,0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0], + [0,0,0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0], + [0,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0], [0,0,0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1]]) # G = PermutationGroup( [ "(9,10)(19,20)", "(9,19)(10,20)", "(8,9)(18,19)", "(7,8)(17,18)",\ # "(6,7)(16,17)", "(5,6)(15,16)", "(4,5)(14,15)", "(3,4)(13,14)",\ # "(2,3)(12,13)", "(1,2)(11,12)"] ) spectrum =[1, 0, 0, 0, 45, 0, 0, 0, 210, 0, 512, 0, 210, 0, 0, 0, 45, 0, 0, 0, 1] - self_dual_codes_20_8 = {"order autgp":1857945600,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_8 = {"order autgp":1857945600,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Huge aut gp. Min dist 4."} # [20,9]: (genmat, K20 are equiv) genmat = _I2(n).augment(A10) - K20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],\ - [1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0],\ + K20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0], [0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,0]]) #genmat = K20 # not in standard form # G = PermutationGroup( [ "(4,13)(5,15)", "(4,15)(5,13)", "(3,4,13)(5,11,15)", @@ -737,18 +737,18 @@ def self_dual_binary_codes(n): # "(3,5,17,4,12)(6,15,7,11,13)(9,10)(16,18)", # "(3,5,17,4,12)(6,15,7,11,13)(8,9)(14,16)" ] ) spectrum = [1, 0, 0, 0, 21, 0, 48, 0, 234, 0, 416, 0, 234, 0, 48, 0, 21, 0, 0, 0, 1] - self_dual_codes_20_9 = {"order autgp":4423680,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_9 = {"order autgp":4423680,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Min dist 4."} # [20,10] - L20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],\ - [0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0],\ + L20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0], [0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0]]) genmat = L20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(15,16)(19,20)", @@ -756,18 +756,18 @@ def self_dual_binary_codes(n): # "(8,9)(12,13)", "(3,4)(5,6)", "(3,5)(4,6)", "(2,3)(6,7)", "(1,2)(5,6)", # "(1,8)(2,9)(3,10)(4,11)(5,12)(6,13)(7,14)(19,20)" ] ) # order 1354752 spectrum = [1, 0, 0, 0, 17, 0, 56, 0, 238, 0, 400, 0, 238, 0, 56, 0, 17, 0, 0, 0, 1] - self_dual_codes_20_10 = {"order autgp":1354752,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_10 = {"order autgp":1354752,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Min dist 4."} # [20,11] - S20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],\ - [1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0],\ - [1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0],\ + S20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0], + [1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0], [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0]] ) genmat = S20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(13,14)(15,16)", @@ -776,18 +776,18 @@ def self_dual_binary_codes(n): # "(1,2)(7,8)", "(1,3)(2,4)", "(1,9)(2,10)(3,11)(4,12)(5,13)(6,14)(7,15)(8,16)" ] ) # G.order() = 294912 spectrum = [1, 0, 0, 0, 13, 0, 64, 0, 242, 0, 384, 0, 242, 0, 64, 0, 13, 0, 0, 0, 1] - self_dual_codes_20_11 = {"order autgp":294912,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_11 = {"order autgp":294912,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Min dist 4."} # [20,12] - R20 = _MS(n)([[0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],\ - [0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,1,1,0],\ - [1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0],\ - [1,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1],\ + R20 = _MS(n)([[0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,1,1,0], + [1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], + [1,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1], [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1]]) genmat = R20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(15,16)(19,20)", @@ -796,18 +796,18 @@ def self_dual_binary_codes(n): # "(3,9,15)(4,10,16)(5,11,17)(6,12,18)(7,14,19)(8,13,20)", # "(1,2)(7,8)(9,15)(10,16)(11,17)(12,18)(13,19)(14,20)" ] ) # order 82944 spectrum = [1, 0, 0, 0, 9, 0, 72, 0, 246, 0, 368, 0, 246, 0, 72, 0, 9, 0, 0, 0, 1] - self_dual_codes_20_12 = {"order autgp":82944,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_12 = {"order autgp":82944,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Min dist 4."} # [20,13] - M20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0],\ - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1],\ - [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0],\ - [1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0],\ - [0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1],\ - [0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0],\ + M20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0], + [1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0], + [0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1], + [0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0], [0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,1,0,0,0,0]]) genmat = M20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(13,14)(15,16)", @@ -819,7 +819,7 @@ def self_dual_binary_codes(n): # "(1,2)(6,7)(11,12)(13,17)(14,18)(15,19)(16,20)", # "(1,5)(2,6)(3,7)(4,8)(9,17)(10,18)(11,19)(12,20)" ] ) spectrum = [1, 0, 0, 0, 5, 0, 80, 0, 250, 0, 352, 0, 250, 0, 80, 0, 5, 0, 0, 0, 1] - self_dual_codes_20_13 = {"order autgp":122880,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_13 = {"order autgp":122880,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "Min dist 4."} # [20,14]: # aut gp of this computed using a program by Robert Miller A0 = self_dual_binary_codes(n-2)["18"]["8"]["code"].redundancy_matrix() @@ -838,7 +838,7 @@ def self_dual_binary_codes(n): # "(7,8)(17,18)", "(4,15)(5,14)", "(4,5)(14,15)", "(4,15)(6,11)", "(5,6)(11,14)", # "(3,13)(4,15)", "(3,15)(4,13)", "(1,2)(4,15)", "(1,4)(2,15)(3,5)(13,14)", "(10,20)" ] ) spectrum = [1, 0, 1, 0, 17, 0, 68, 0, 238, 0, 374, 0, 238, 0, 68, 0, 17, 0, 1, 0, 1] - self_dual_codes_20_14 = {"order autgp":645120,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_14 = {"order autgp":645120,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment": "'Exceptional' construction."} # [20,15]: A0 = self_dual_binary_codes(n-2)["18"]["7"]["code"].redundancy_matrix() @@ -859,12 +859,12 @@ def self_dual_binary_codes(n): # "(1,2)(5,8)(6,15)(7,9)(11,13)(12,19)(17,18)", "(1,3)(2,16)", # "(1,5)(2,6)(3,7)(4,12)(11,19)(13,14)(16,18)" ] ) # order 165888 spectrum = [1, 0, 1, 0, 9, 0, 84, 0, 246, 0, 342, 0, 246, 0, 84, 0, 9, 0, 1, 0, 1] - self_dual_codes_20_15 = {"order autgp":165888,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_20_15 = {"order autgp":165888,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"'Exceptional' construction. Unique lowest wt codeword."} - self_dual_codes["20"] = {"0":self_dual_codes_20_0,"1":self_dual_codes_20_1,"2":self_dual_codes_20_2,\ - "3":self_dual_codes_20_3,"4":self_dual_codes_20_4,"5":self_dual_codes_20_5,\ - "6":self_dual_codes_20_6,"7":self_dual_codes_20_7,"8":self_dual_codes_20_8,\ - "9":self_dual_codes_20_9,"10":self_dual_codes_20_10,"11":self_dual_codes_20_11,\ + self_dual_codes["20"] = {"0":self_dual_codes_20_0,"1":self_dual_codes_20_1,"2":self_dual_codes_20_2, + "3":self_dual_codes_20_3,"4":self_dual_codes_20_4,"5":self_dual_codes_20_5, + "6":self_dual_codes_20_6,"7":self_dual_codes_20_7,"8":self_dual_codes_20_8, + "9":self_dual_codes_20_9,"10":self_dual_codes_20_10,"11":self_dual_codes_20_11, "12":self_dual_codes_20_12,"13":self_dual_codes_20_13,"14":self_dual_codes_20_14, "15":self_dual_codes_20_15} return self_dual_codes @@ -879,7 +879,7 @@ def self_dual_binary_codes(n): # "(8,9)(19,20)", "(7,8)(18,19)", "(6,7)(17,18)", "(5,6)(16,17)",\ # "(4,5)(15,16)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) # S_11x(ZZ/2ZZ)^11?? spectrum = [1, 0, 11, 0, 55, 0, 165, 0, 330, 0, 462, 0, 462, 0, 330, 0, 165, 0, 55, 0, 11, 0, 1] - self_dual_codes_22_0 = {"order autgp":81749606400,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_0 = {"order autgp":81749606400,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Huge aut gp."} # [22,1]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matId(n)[4]])) @@ -887,7 +887,7 @@ def self_dual_binary_codes(n): # "(8,9)(19,20)", "(7,8)(18,19)", "(6,7)(17,18)", "(5,6)(16,17)",\ # "(4,12)(13,14)", "(4,13)(12,14)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) spectrum = [1, 0, 7, 0, 35, 0, 133, 0, 330, 0, 518, 0, 518, 0, 330, 0, 133, 0, 35, 0, 7, 0, 1] - self_dual_codes_22_1 = {"order autgp":867041280,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_1 = {"order autgp":867041280,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [22,2]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matId(n)[6]])) @@ -895,7 +895,7 @@ def self_dual_binary_codes(n): # "(8,9)(19,20)", "(7,8)(18,19)", "(5,6)(16,17)", "(5,16)(6,17)",\ # "(4,5)(15,16)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) spectrum = [1, 0, 5, 0, 25, 0, 117, 0, 330, 0, 546, 0, 546, 0, 330, 0, 117, 0, 25, 0, 5, 0, 1] - self_dual_codes_22_2 = {"order autgp":88473600,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_2 = {"order autgp":88473600,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":""} # [22,3]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[8],_matId(n)[8]])) @@ -903,7 +903,7 @@ def self_dual_binary_codes(n): # "(7,8)(18,19)", "(7,18)(8,19)", "(6,7)(17,18)", "(5,6)(16,17)",\ # "(4,5)(15,16)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) spectrum = [1, 0, 3, 0, 31, 0, 85, 0, 282, 0, 622, 0, 622, 0, 282, 0, 85, 0, 31, 0, 3, 0, 1] - self_dual_codes_22_3 = {"order autgp":247726080,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_3 = {"order autgp":247726080,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Same spectrum as the '[20,5]' code."} # [22,4]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[10],_matId(n)[10]])) @@ -911,7 +911,7 @@ def self_dual_binary_codes(n): # "(8,9)(19,20)", "(7,8)(18,19)", "(6,7)(17,18)", "(5,6)(16,17)",\ # "(4,5)(15,16)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) spectrum = [1, 0, 1, 0, 45, 0, 45, 0, 210, 0, 722, 0, 722, 0, 210, 0, 45, 0, 45, 0, 1, 0, 1] - self_dual_codes_22_4 = {"order autgp":3715891200,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_4 = {"order autgp":3715891200,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique lowest weight codeword."} # [22,5]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[4],_matA(n)[4],_matId(n)[8]])) @@ -920,7 +920,7 @@ def self_dual_binary_codes(n): # "(5,6)(16,17)", "(4,12)(13,14)", "(4,13)(12,14)", "(3,4)(14,15)",\ # "(2,3)(13,14)", "(1,2)(12,13)", "(1,5)(2,6)(3,7)(4,8)(12,16)(13,17)(14,18)(15,19)" ] ) spectrum = [1, 0, 3, 0, 31, 0, 85, 0, 282, 0, 622, 0, 622, 0, 282, 0, 85, 0, 31, 0, 3, 0, 1] - self_dual_codes_22_5 = {"order autgp":173408256,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_5 = {"order autgp":173408256,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Same spectrum as the '[20,3]' code."} # [22,6]: genmat = _I2(n).augment(block_diagonal_matrix([_matA(n)[6],_matA(n)[4],_matId(n)[10]])) @@ -928,9 +928,9 @@ def self_dual_binary_codes(n): # "(9,10)(20,21)", "(8,9)(19,20)", "(7,8)(18,19)", "(5,6)(16,17)",\ # "(5,16)(6,17)", "(4,5)(15,16)", "(3,4)(14,15)", "(2,3)(13,14)", "(1,2)(12,13)" ] ) spectrum = [1, 0, 1, 0, 29, 0, 61, 0, 258, 0, 674, 0, 674, 0, 258, 0, 61, 0, 29, 0, 1, 0, 1] - self_dual_codes_22_6 = {"order autgp":61931520,"code":LinearCode(genmat),"spectrum":spectrum,\ + self_dual_codes_22_6 = {"order autgp":61931520,"code":LinearCode(genmat),"spectrum":spectrum, "Type":"I","Comment":"Unique lowest weight codeword."} - self_dual_codes["22"] = {"0":self_dual_codes_22_0,"1":self_dual_codes_22_1,"2":self_dual_codes_22_2,\ - "3":self_dual_codes_22_3,"4":self_dual_codes_22_4,"5":self_dual_codes_22_5,\ + self_dual_codes["22"] = {"0":self_dual_codes_22_0,"1":self_dual_codes_22_1,"2":self_dual_codes_22_2, + "3":self_dual_codes_22_3,"4":self_dual_codes_22_4,"5":self_dual_codes_22_5, "6":self_dual_codes_22_6} return self_dual_codes diff --git a/src/sage/crypto/mq/sr.py b/src/sage/crypto/mq/sr.py index 4c75ce56ca1..14385e96878 100644 --- a/src/sage/crypto/mq/sr.py +++ b/src/sage/crypto/mq/sr.py @@ -2716,9 +2716,9 @@ def mix_columns_matrix(self): M = Matrix(k, r, r, [a+1, a, a, a+1]) elif r == 4: - M = Matrix(k, r, [a, a+1, 1, 1, \ - 1, a, a+1, 1, \ - 1, 1, a, a+1, \ + M = Matrix(k, r, [a, a+1, 1, 1, + 1, a, a+1, 1, + 1, 1, a, a+1, a+1, 1, 1, a]) mix_columns = Matrix(k, r*c, r*c) @@ -2757,18 +2757,18 @@ def lin_matrix(self, length=None): length = r*c if e == 8: - Z = Matrix(GF(2), 8, 8, [1, 0, 0, 0, 1, 1, 1, 1, \ - 1, 1, 0, 0, 0, 1, 1, 1, \ - 1, 1, 1, 0, 0, 0, 1, 1, \ - 1, 1, 1, 1, 0, 0, 0, 1, \ - 1, 1, 1, 1, 1, 0, 0, 0, \ - 0, 1, 1, 1, 1, 1, 0, 0, \ - 0, 0, 1, 1, 1, 1, 1, 0, \ + Z = Matrix(GF(2), 8, 8, [1, 0, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1]) else: - Z = Matrix(GF(2), 4, 4, [1, 1, 1, 0, \ - 0, 1, 1, 1, \ - 1, 0, 1, 1, \ + Z = Matrix(GF(2), 4, 4, [1, 1, 1, 0, + 0, 1, 1, 1, + 1, 0, 1, 1, 1, 1, 0, 1]) Z = Z.transpose() # account for endianess mismatch @@ -2963,36 +2963,36 @@ def inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, w7*x6 + w7*x4 + w7*x3 + w6*x7 + w6*x5 + w6*x4 + w6*x0 + w5*x6 + w5*x5 + w5*x1 + w4*x7 + w4*x6 + w4*x2 + w3*x7 + w3*x3 + w2*x4 + w1*x5 + w0*x6, w7*x5 + w7*x3 + w7*x2 + w6*x6 + w6*x4 + w6*x3 + w5*x7 + w5*x5 + w5*x4 + w5*x0 + w4*x6 + w4*x5 + w4*x1 + w3*x7 + w3*x6 + w3*x2 + w2*x7 + w2*x3 + w1*x4 + w0*x5, w7*x7 + w7*x4 + w7*x2 + w7*x1 + w6*x5 + w6*x3 + w6*x2 + w5*x6 + w5*x4 + w5*x3 + w4*x7 + w4*x5 + w4*x4 + w4*x0 + w3*x6 + w3*x5 + w3*x1 + w2*x7 + w2*x6 + w2*x2 + w1*x7 + w1*x3 + w0*x4, - w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w4*x7 + w4*x6 + w4*x4 + w3*x7 + w3*x5 + w3*x0 + w2*x6 + w2*x1 \ + w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w4*x7 + w4*x6 + w4*x4 + w3*x7 + w3*x5 + w3*x0 + w2*x6 + w2*x1 + w1*x7 + w1*x2 + w0*x3, w7*x6 + w7*x3 + w7*x2 + w6*x7 + w6*x4 + w6*x3 + w5*x5 + w5*x4 + w4*x6 + w4*x5 + w3*x7 + w3*x6 + w2*x7 + w2*x0 + w1*x1 + w0*x2, w7*x7 + w7*x5 + w7*x2 + w7*x1 + w6*x6 + w6*x3 + w6*x2 + w5*x7 + w5*x4 + w5*x3 + w4*x5 + w4*x4 + w3*x6 + w3*x5 + w2*x7 + w2*x6 + w1*x7 + w1*x0 + w0*x1, w7*x6 + w7*x5 + w7*x2 + w7*x0 + w6*x7 + w6*x4 + w6*x3 + w5*x7 + w5*x6 + w5*x3 + w5*x1 + w4*x5 + w4*x4 + w3*x7 + w3*x4 + w3*x2 + w2*x6 + w2*x5 + w1*x5 + w1*x3 + w0*x7 + w0*x6 + x7, - w7*x6 + w7*x3 + w7*x2 + w6*x6 + w6*x5 + w6*x2 + w6*x0 + w5*x7 + w5*x4 + w5*x3 + w4*x7 + w4*x6 + w4*x3 + w4*x1 + w3*x5 + w3*x4 + w2*x7 + w2*x4 + w2*x2 + w1*x6 + w1*x5 + w0*x5 + w0*x3 \ + w7*x6 + w7*x3 + w7*x2 + w6*x6 + w6*x5 + w6*x2 + w6*x0 + w5*x7 + w5*x4 + w5*x3 + w4*x7 + w4*x6 + w4*x3 + w4*x1 + w3*x5 + w3*x4 + w2*x7 + w2*x4 + w2*x2 + w1*x6 + w1*x5 + w0*x5 + w0*x3 + x6, - w7*x7 + w7*x5 + w7*x4 + w7*x1 + w6*x6 + w6*x3 + w6*x2 + w5*x6 + w5*x5 + w5*x2 + w5*x0 + w4*x7 + w4*x4 + w4*x3 + w3*x7 + w3*x6 + w3*x3 + w3*x1 + w2*x5 + w2*x4 + w1*x7 + w1*x4 + w1*x2 \ + w7*x7 + w7*x5 + w7*x4 + w7*x1 + w6*x6 + w6*x3 + w6*x2 + w5*x6 + w5*x5 + w5*x2 + w5*x0 + w4*x7 + w4*x4 + w4*x3 + w3*x7 + w3*x6 + w3*x3 + w3*x1 + w2*x5 + w2*x4 + w1*x7 + w1*x4 + w1*x2 + w0*x6 + w0*x5 + x5, - w7*x7 + w7*x5 + w7*x2 + w7*x1 + w6*x7 + w6*x5 + w6*x4 + w6*x1 + w5*x6 + w5*x3 + w5*x2 + w4*x6 + w4*x5 + w4*x2 + w4*x0 + w3*x7 + w3*x4 + w3*x3 + w2*x7 + w2*x6 + w2*x3 + w2*x1 + w1*x5 \ + w7*x7 + w7*x5 + w7*x2 + w7*x1 + w6*x7 + w6*x5 + w6*x4 + w6*x1 + w5*x6 + w5*x3 + w5*x2 + w4*x6 + w4*x5 + w4*x2 + w4*x0 + w3*x7 + w3*x4 + w3*x3 + w2*x7 + w2*x6 + w2*x3 + w2*x1 + w1*x5 + w1*x4 + w0*x7 + w0*x4 + w0*x2 + x4, - w7*x5 + w7*x4 + w7*x3 + w7*x2 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w4*x6 + w4*x5 + w4*x4 + w4*x3 + w4*x2 + w3*x7 + w3*x6 + w3*x5 + w3*x4 + w3*x0 \ + w7*x5 + w7*x4 + w7*x3 + w7*x2 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w4*x6 + w4*x5 + w4*x4 + w4*x3 + w4*x2 + w3*x7 + w3*x6 + w3*x5 + w3*x4 + w3*x0 + w2*x7 + w2*x6 + w2*x5 + w2*x4 + w2*x3 + w1*x7 + w1*x6 + w1*x5 + w1*x1 + w0*x7 + w0*x6 + w0*x5 + w0*x4 + x3, - w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x7 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x6 + w4*x3 + w3*x7 + w3*x6 + w3*x5 + w3*x3 + w2*x7 + w2*x4 + w2*x0 \ + w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x7 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x6 + w4*x3 + w3*x7 + w3*x6 + w3*x5 + w3*x3 + w2*x7 + w2*x4 + w2*x0 + w1*x7 + w1*x6 + w1*x4 + w0*x5 + w0*x1 + x2, - w7*x6 + w7*x4 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x7 + w5*x5 + w5*x2 + w4*x7 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w3*x6 + w3*x3 + w2*x7 + w2*x6 + w2*x5 + w2*x3 \ + w7*x6 + w7*x4 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x7 + w5*x5 + w5*x2 + w4*x7 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w3*x6 + w3*x3 + w2*x7 + w2*x6 + w2*x5 + w2*x3 + w1*x7 + w1*x4 + w1*x0 + w0*x7 + w0*x6 + w0*x4 + x1, w7*x7 + w7*x4 + w7*x3 + w6*x7 + w6*x6 + w6*x3 + w6*x1 + w5*x5 + w5*x4 + w4*x7 + w4*x4 + w4*x2 + w3*x6 + w3*x5 + w2*x5 + w2*x3 + w1*x7 + w1*x6 + w0*x6 + w0*x4 + w0*x0 + x0, w7*x6 + w7*x5 + w7*x3 + w7*x0 + w7 + w6*x7 + w6*x5 + w6*x2 + w6*x0 + w5*x7 + w5*x4 + w5*x2 + w5*x1 + w4*x6 + w4*x4 + w4*x3 + w3*x6 + w3*x5 + w3*x1 + w2*x7 + w2*x3 + w1*x5 + w0*x7, - w7*x5 + w7*x4 + w7*x2 + w6*x7 + w6*x6 + w6*x4 + w6*x1 + w6 + w5*x6 + w5*x3 + w5*x1 + w5*x0 + w4*x5 + w4*x3 + w4*x2 + w3*x7 + w3*x5 + w3*x4 + w3*x0 + w2*x7 + w2*x6 + w2*x2 + w1*x4 \ + w7*x5 + w7*x4 + w7*x2 + w6*x7 + w6*x6 + w6*x4 + w6*x1 + w6 + w5*x6 + w5*x3 + w5*x1 + w5*x0 + w4*x5 + w4*x3 + w4*x2 + w3*x7 + w3*x5 + w3*x4 + w3*x0 + w2*x7 + w2*x6 + w2*x2 + w1*x4 + w0*x6, - w7*x7 + w7*x4 + w7*x3 + w7*x1 + w6*x6 + w6*x5 + w6*x3 + w6*x0 + w5*x7 + w5*x5 + w5*x2 + w5*x0 + w5 + w4*x7 + w4*x4 + w4*x2 + w4*x1 + w3*x6 + w3*x4 + w3*x3 + w2*x6 + w2*x5 + w2*x1 \ + w7*x7 + w7*x4 + w7*x3 + w7*x1 + w6*x6 + w6*x5 + w6*x3 + w6*x0 + w5*x7 + w5*x5 + w5*x2 + w5*x0 + w5 + w4*x7 + w4*x4 + w4*x2 + w4*x1 + w3*x6 + w3*x4 + w3*x3 + w2*x6 + w2*x5 + w2*x1 + w1*x7 + w1*x3 + w0*x5, - w7*x7 + w7*x6 + w7*x3 + w7*x2 + w7*x0 + w6*x5 + w6*x4 + w6*x2 + w5*x7 + w5*x6 + w5*x4 + w5*x1 + w4*x6 + w4*x3 + w4*x1 + w4*x0 + w4 + w3*x5 + w3*x3 + w3*x2 + w2*x7 + w2*x5 + w2*x4 \ + w7*x7 + w7*x6 + w7*x3 + w7*x2 + w7*x0 + w6*x5 + w6*x4 + w6*x2 + w5*x7 + w5*x6 + w5*x4 + w5*x1 + w4*x6 + w4*x3 + w4*x1 + w4*x0 + w4 + w3*x5 + w3*x3 + w3*x2 + w2*x7 + w2*x5 + w2*x4 + w2*x0 + w1*x7 + w1*x6 + w1*x2 + w0*x4, - w7*x3 + w7*x2 + w7*x1 + w7*x0 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w6*x0 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x2 + w5*x1 + w5*x0 + w4*x7 + w4*x6 + w4*x5 + w4*x4 \ + w7*x3 + w7*x2 + w7*x1 + w7*x0 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w6*x0 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x2 + w5*x1 + w5*x0 + w4*x7 + w4*x6 + w4*x5 + w4*x4 + w4*x3 + w4*x2 + w4*x0 + w3*x7 + w3*x6 + w3*x5 + w3*x4 + w3*x2 + w3 + w2*x7 + w2*x6 + w2*x4 + w1*x6 + w1*x1 + w0*x3, - w7*x7 + w7*x6 + w7*x5 + w7*x3 + w7*x2 + w7*x1 + w6*x7 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w5*x0 + w4*x7 + w4*x5 + w4*x2 + w4*x1 + w3*x7 + w3*x4 \ + w7*x7 + w7*x6 + w7*x5 + w7*x3 + w7*x2 + w7*x1 + w6*x7 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w5*x0 + w4*x7 + w4*x5 + w4*x2 + w4*x1 + w3*x7 + w3*x4 + w3*x3 + w2*x6 + w2*x5 + w2 + w1*x7 + w1*x0 + w0*x2, - w7*x6 + w7*x5 + w7*x4 + w7*x2 + w7*x1 + w7*x0 + w6*x7 + w6*x6 + w6*x4 + w6*x3 + w6*x2 + w6*x0 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x7 + w4*x6 + w4*x4 + w4*x1 + w4*x0 + w3*x6 \ + w7*x6 + w7*x5 + w7*x4 + w7*x2 + w7*x1 + w7*x0 + w6*x7 + w6*x6 + w6*x4 + w6*x3 + w6*x2 + w6*x0 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x7 + w4*x6 + w4*x4 + w4*x1 + w4*x0 + w3*x6 + w3*x3 + w3*x2 + w2*x5 + w2*x4 + w1*x7 + w1*x6 + w1 + w0*x1, w7*x7 + w7*x6 + w7*x4 + w7*x1 + w6*x6 + w6*x3 + w6*x1 + w6*x0 + w5*x5 + w5*x3 + w5*x2 + w4*x7 + w4*x5 + w4*x4 + w4*x0 + w3*x7 + w3*x6 + w3*x2 + w2*x4 + w1*x6 + w0*x0 + w0] @@ -3000,53 +3000,53 @@ def inversion_polynomials_single_sbox(self, x=None, w=None, biaffine_only=None, l.append(w7*x6 + w7*x5 + w7*x1 + w6*x7 + w6*x6 + w6*x2 + w5*x7 + w5*x3 + w4*x4 + w3*x5 + w2*x6 + w1*x7 + w0*x0 + 1) if not biaffine_only: - l.extend([w7**2 + w7*w6 + w7*w3 + w7*w1 + w7*x7 + w7*x6 + w7*x5 + w7*x2 + w7*x1 + w7*x0 + w6**2 + w6*w0 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w6*x0 + w5**2 + w5*w4 + w5*w3 \ - + w5*w2 + w5*x7 + w5*x5 + w5*x4 + w5*x1 + w5*x0 + w4**2 + w4*w2 + w4*w0 + w4*x5 + w4*x4 + w4*x2 + w3*w2 + w3*x6 + w3*x3 + w3*x1 + w3*x0 + w2*x7 + w2*x5 + w2*x4 \ + l.extend([w7**2 + w7*w6 + w7*w3 + w7*w1 + w7*x7 + w7*x6 + w7*x5 + w7*x2 + w7*x1 + w7*x0 + w6**2 + w6*w0 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w6*x0 + w5**2 + w5*w4 + w5*w3 + + w5*w2 + w5*x7 + w5*x5 + w5*x4 + w5*x1 + w5*x0 + w4**2 + w4*w2 + w4*w0 + w4*x5 + w4*x4 + w4*x2 + w3*w2 + w3*x6 + w3*x3 + w3*x1 + w3*x0 + w2*x7 + w2*x5 + w2*x4 + w2*x0 + w1*x4 + w0**2 + w0*x0, - w7*x6 + w7*x4 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w4*x5 + w4*x4 + w4*x3 + w4*x1 + w4*x0 + w3*x7 + w3*x5 + w3*x2 \ - + w2*x7 + w2*x6 + w2*x3 + w1*x7 + w1*x6 + w1*x5 + w1*x4 + w1*x2 + w0*x6 + w0*x5 + w0*x4 + w0*x2 + w0*x1 + x7**2 + x7*x6 + x7*x5 + x7*x3 + x7*x1 + x7*x0 + x6*x2 \ + w7*x6 + w7*x4 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w4*x5 + w4*x4 + w4*x3 + w4*x1 + w4*x0 + w3*x7 + w3*x5 + w3*x2 + + w2*x7 + w2*x6 + w2*x3 + w1*x7 + w1*x6 + w1*x5 + w1*x4 + w1*x2 + w0*x6 + w0*x5 + w0*x4 + w0*x2 + w0*x1 + x7**2 + x7*x6 + x7*x5 + x7*x3 + x7*x1 + x7*x0 + x6*x2 + x6*x1 + x5*x4 + x5*x3 + x5*x2 + x5*x1 + x4*x3 + x4*x2 + x4*x1 + x3**2 + x3*x2 + x2*x1 + x2*x0, - w7*x5 + w7*x4 + w7*x3 + w7*x1 + w7*x0 + w6*x7 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x3 + w4*x7 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w3*x6 + w3*x5 + w3*x4 + w3*x2 + w3*x1 \ - + w2*x6 + w2*x3 + w1*x7 + w1*x4 + w0*x7 + w0*x6 + w0*x5 + w0*x3 + x7*x3 + x7*x2 + x6*x5 + x6*x4 + x6*x3 + x6*x2 + x6*x0 + x5*x4 + x5*x3 + x5*x2 + x4**2 + x4*x3 \ + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w7*x0 + w6*x7 + w6*x5 + w6*x2 + w5*x7 + w5*x6 + w5*x3 + w4*x7 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w3*x6 + w3*x5 + w3*x4 + w3*x2 + w3*x1 + + w2*x6 + w2*x3 + w1*x7 + w1*x4 + w0*x7 + w0*x6 + w0*x5 + w0*x3 + x7*x3 + x7*x2 + x6*x5 + x6*x4 + x6*x3 + x6*x2 + x6*x0 + x5*x4 + x5*x3 + x5*x2 + x4**2 + x4*x3 + x3*x2 + x3*x1, - w7*w3 + w7*w2 + w7*x6 + w7*x5 + w7*x4 + w7*x1 + w7*x0 + w6*w5 + w6*w4 + w6*w3 + w6*w2 + w6*w0 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x0 + w5*w4 + w5*w3 + w5*w2 + w5*x7 \ - + w5*x6 + w5*x4 + w5*x3 + w5*x0 + w4**2 + w4*w3 + w4*x7 + w4*x4 + w4*x3 + w4*x1 + w3*w2 + w3*w1 + w3*x7 + w3*x5 + w3*x2 + w3*x0 + w2*x6 + w2*x4 + w2*x3 + w1*x7 \ + w7*w3 + w7*w2 + w7*x6 + w7*x5 + w7*x4 + w7*x1 + w7*x0 + w6*w5 + w6*w4 + w6*w3 + w6*w2 + w6*w0 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w6*x0 + w5*w4 + w5*w3 + w5*w2 + w5*x7 + + w5*x6 + w5*x4 + w5*x3 + w5*x0 + w4**2 + w4*w3 + w4*x7 + w4*x4 + w4*x3 + w4*x1 + w3*w2 + w3*w1 + w3*x7 + w3*x5 + w3*x2 + w3*x0 + w2*x6 + w2*x4 + w2*x3 + w1*x7 + w1*x3 + w0*x7, - w7*x5 + w7*x2 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x2 + w6*x1 + w5*x5 + w5*x3 + w5*x2 + w4*x3 + w4*x2 + w4*x1 + w3*x6 + w3*x3 + w3*x2 + w3*x0 + w2*x7 + w2*x6 \ - + w2*x5 + w2*x3 + w2*x2 + w1*x6 + w1*x4 + w1*x3 + w0*x4 + w0*x3 + w0*x2 + x7*x5 + x7*x4 + x7*x1 + x7*x0 + x6*x0 + x5**2 + x5*x2 + x5*x1 + x5*x0 + x4**2 + x4*x0 \ + w7*x5 + w7*x2 + w7*x1 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x2 + w6*x1 + w5*x5 + w5*x3 + w5*x2 + w4*x3 + w4*x2 + w4*x1 + w3*x6 + w3*x3 + w3*x2 + w3*x0 + w2*x7 + w2*x6 + + w2*x5 + w2*x3 + w2*x2 + w1*x6 + w1*x4 + w1*x3 + w0*x4 + w0*x3 + w0*x2 + x7*x5 + x7*x4 + x7*x1 + x7*x0 + x6*x0 + x5**2 + x5*x2 + x5*x1 + x5*x0 + x4**2 + x4*x0 + x3*x2 + x3*x0 + x1**2, - w7*w6 + w7*w5 + w7*w4 + w7*w3 + w7*x7 + w7*x5 + w7*x4 + w7*x3 + w7*x0 + w6**2 + w6*w5 + w6*w4 + w6*w2 + w6*w1 + w6*w0 + w6*x7 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w5*w4 \ - + w5*w1 + w5*w0 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w5*x2 + w4*w2 + w4*w1 + w4*x7 + w4*x6 + w4*x3 + w4*x2 + w4*x0 + w3*w0 + w3*x7 + w3*x6 + w3*x4 + w3*x1 + w2**2 \ + w7*w6 + w7*w5 + w7*w4 + w7*w3 + w7*x7 + w7*x5 + w7*x4 + w7*x3 + w7*x0 + w6**2 + w6*w5 + w6*w4 + w6*w2 + w6*w1 + w6*w0 + w6*x7 + w6*x4 + w6*x3 + w6*x2 + w6*x1 + w5*w4 + + w5*w1 + w5*w0 + w5*x7 + w5*x6 + w5*x5 + w5*x3 + w5*x2 + w4*w2 + w4*w1 + w4*x7 + w4*x6 + w4*x3 + w4*x2 + w4*x0 + w3*w0 + w3*x7 + w3*x6 + w3*x4 + w3*x1 + w2**2 + w2*x5 + w2*x3 + w2*x2 + w1*x7 + w1*x6 + w1*x2 + w0*x6, - w7*w5 + w7*w4 + w7*w1 + w7*w0 + w7*x6 + w7*x2 + w6*w0 + w6*x6 + w6*x3 + w6*x2 + w6*x1 + w5**2 + w5*w2 + w5*w1 + w5*w0 + w5*x7 + w5*x6 + w5*x5 + w5*x2 + w4**2 + w4*w0 \ - + w4*x6 + w4*x1 + w4*x0 + w3*w2 + w3*w0 + w3*x5 + w3*x4 + w3*x3 + w3*x2 + w3*x1 + w3*x0 + w2*x7 + w2*x6 + w2*x5 + w2*x4 + w2*x3 + w2*x2 + w2*x0 + w1**2 + w1*x7 \ + w7*w5 + w7*w4 + w7*w1 + w7*w0 + w7*x6 + w7*x2 + w6*w0 + w6*x6 + w6*x3 + w6*x2 + w6*x1 + w5**2 + w5*w2 + w5*w1 + w5*w0 + w5*x7 + w5*x6 + w5*x5 + w5*x2 + w4**2 + w4*w0 + + w4*x6 + w4*x1 + w4*x0 + w3*w2 + w3*w0 + w3*x5 + w3*x4 + w3*x3 + w3*x2 + w3*x1 + w3*x0 + w2*x7 + w2*x6 + w2*x5 + w2*x4 + w2*x3 + w2*x2 + w2*x0 + w1**2 + w1*x7 + w1*x6 + w1*x4 + w0*x3, - w7*x7 + w7*x6 + w7*x5 + w7*x2 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w5*x0 + w4*x7 + w4*x5 + w4*x2 + w3*x7 + w3*x6 + w3*x3 \ - + w2*x7 + w2*x6 + w2*x5 + w2*x4 + w2*x2 + w1*x6 + w1*x5 + w1*x4 + w1*x2 + w1*x1 + w0*x6 + w0*x3 + x7**2 + x7*x5 + x7*x3 + x6**2 + x6*x5 + x6*x2 + x6*x0 + x5**2 \ + w7*x7 + w7*x6 + w7*x5 + w7*x2 + w6*x7 + w6*x6 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w5*x0 + w4*x7 + w4*x5 + w4*x2 + w3*x7 + w3*x6 + w3*x3 + + w2*x7 + w2*x6 + w2*x5 + w2*x4 + w2*x2 + w1*x6 + w1*x5 + w1*x4 + w1*x2 + w1*x1 + w0*x6 + w0*x3 + x7**2 + x7*x5 + x7*x3 + x6**2 + x6*x5 + x6*x2 + x6*x0 + x5**2 + x4**2 + x4*x3 + x4*x2 + x4*x1 + x3**2 + x3*x1 + x2*x1, - w7**2 + w7*w6 + w7*w5 + w7*w3 + w7*w1 + w7*w0 + w7*x6 + w7*x5 + w7*x3 + w7*x2 + w7*x1 + w6*w2 + w6*w1 + w6*x7 + w6*x6 + w6*x5 + w6*x2 + w6*x1 + w6*x0 + w5*w4 + w5*w3 \ - + w5*w2 + w5*w1 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w5*x0 + w4*w3 + w4*w2 + w4*w1 + w4*x7 + w4*x5 + w4*x4 + w4*x1 + w4*x0 + w3**2 + w3*w2 + w3*x5 + w3*x4 \ + w7**2 + w7*w6 + w7*w5 + w7*w3 + w7*w1 + w7*w0 + w7*x6 + w7*x5 + w7*x3 + w7*x2 + w7*x1 + w6*w2 + w6*w1 + w6*x7 + w6*x6 + w6*x5 + w6*x2 + w6*x1 + w6*x0 + w5*w4 + w5*w3 + + w5*w2 + w5*w1 + w5*x6 + w5*x5 + w5*x4 + w5*x3 + w5*x1 + w5*x0 + w4*w3 + w4*w2 + w4*w1 + w4*x7 + w4*x5 + w4*x4 + w4*x1 + w4*x0 + w3**2 + w3*w2 + w3*x5 + w3*x4 + w3*x2 + w2*w1 + w2*w0 + w2*x6 + w2*x3 + w2*x1 + w2*x0 + w1*x7 + w1*x5 + w1*x4 + w1*x0 + w0*x4, - w7*x7 + w7*x5 + w7*x2 + w6*x7 + w6*x6 + w6*x3 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w4*x1 + w3*x6 + w3*x3 + w2*x7 + w2*x4 + w1*x7 \ - + w1*x6 + w1*x5 + w1*x3 + w0*x7 + w0*x6 + w0*x5 + w0*x3 + w0*x2 + w0*x0 + x7**2 + x7*x6 + x7*x3 + x7*x1 + x6**2 + x6*x0 + x5**2 + x5*x4 + x5*x3 + x5*x2 + x4**2 \ + w7*x7 + w7*x5 + w7*x2 + w6*x7 + w6*x6 + w6*x3 + w5*x7 + w5*x6 + w5*x5 + w5*x4 + w5*x2 + w4*x6 + w4*x5 + w4*x4 + w4*x2 + w4*x1 + w3*x6 + w3*x3 + w2*x7 + w2*x4 + w1*x7 + + w1*x6 + w1*x5 + w1*x3 + w0*x7 + w0*x6 + w0*x5 + w0*x3 + w0*x2 + w0*x0 + x7**2 + x7*x6 + x7*x3 + x7*x1 + x6**2 + x6*x0 + x5**2 + x5*x4 + x5*x3 + x5*x2 + x4**2 + x4*x2 + x4*x0 + x3*x2 + x0**2, - w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w6*x0 + w5*x7 + w5*x5 + w5*x2 + w4*x7 + w4*x6 + w4*x3 + w3*x7 + w3*x6 + w3*x5 + w3*x4 \ - + w3*x2 + w2*x6 + w2*x5 + w2*x4 + w2*x2 + w2*x1 + w1*x6 + w1*x3 + w0*x7 + w0*x4 + x7*x6 + x7*x5 + x7*x4 + x7*x3 + x6**2 + x6*x5 + x6*x4 + x6*x2 + x6*x1 + x6*x0 \ + w7*x7 + w7*x6 + w7*x5 + w7*x4 + w7*x3 + w7*x1 + w6*x5 + w6*x4 + w6*x3 + w6*x1 + w6*x0 + w5*x7 + w5*x5 + w5*x2 + w4*x7 + w4*x6 + w4*x3 + w3*x7 + w3*x6 + w3*x5 + w3*x4 + + w3*x2 + w2*x6 + w2*x5 + w2*x4 + w2*x2 + w2*x1 + w1*x6 + w1*x3 + w0*x7 + w0*x4 + x7*x6 + x7*x5 + x7*x4 + x7*x3 + x6**2 + x6*x5 + x6*x4 + x6*x2 + x6*x1 + x6*x0 + x5*x4 + x5*x1 + x5*x0 + x4*x2 + x4*x1 + x3*x0 + x2**2, - w7*x5 + w7*x4 + w7*x3 + w7*x2 + w6*x7 + w6*x1 + w5*x5 + w5*x4 + w5*x3 + w5*x2 + w5*x1 + w4*x7 + w4*x6 + w4*x4 + w4*x3 + w3*x6 + w3*x5 + w3*x4 + w3*x3 + w2*x2 + w2*x0 \ - + w1*x6 + w1*x5 + w1*x4 + w1*x3 + w1*x2 + w0*x7 + w0*x5 + w0*x4 + x7**2 + x7*x4 + x7*x2 + x6*x4 + x6*x3 + x6*x2 + x6*x1 + x5**2 + x5*x4 + x5*x3 + x5*x2 + x5*x0 \ + w7*x5 + w7*x4 + w7*x3 + w7*x2 + w6*x7 + w6*x1 + w5*x5 + w5*x4 + w5*x3 + w5*x2 + w5*x1 + w4*x7 + w4*x6 + w4*x4 + w4*x3 + w3*x6 + w3*x5 + w3*x4 + w3*x3 + w2*x2 + w2*x0 + + w1*x6 + w1*x5 + w1*x4 + w1*x3 + w1*x2 + w0*x7 + w0*x5 + w0*x4 + x7**2 + x7*x4 + x7*x2 + x6*x4 + x6*x3 + x6*x2 + x6*x1 + x5**2 + x5*x4 + x5*x3 + x5*x2 + x5*x0 + x4*x3 + x4*x2 + x4*x1 + x3**2 + x2*x0 + x1*x0, - w7*x6 + w7*x5 + w7*x3 + w7*x2 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w5*x7 + w5*x1 + w4*x5 + w4*x4 + w4*x3 + w4*x2 + w4*x1 + w3*x7 + w3*x6 + w3*x4 + w3*x3 + w2*x6 + w2*x5 \ - + w2*x4 + w2*x3 + w1*x2 + w1*x0 + w0*x6 + w0*x5 + w0*x4 + w0*x3 + w0*x2 + x7*x5 + x7*x2 + x7*x0 + x6**2 + x6*x5 + x6*x2 + x6*x1 + x6*x0 + x5**2 + x5*x4 + x4**2 \ + w7*x6 + w7*x5 + w7*x3 + w7*x2 + w6*x5 + w6*x4 + w6*x3 + w6*x2 + w5*x7 + w5*x1 + w4*x5 + w4*x4 + w4*x3 + w4*x2 + w4*x1 + w3*x7 + w3*x6 + w3*x4 + w3*x3 + w2*x6 + w2*x5 + + w2*x4 + w2*x3 + w1*x2 + w1*x0 + w0*x6 + w0*x5 + w0*x4 + w0*x3 + w0*x2 + x7*x5 + x7*x2 + x7*x0 + x6**2 + x6*x5 + x6*x2 + x6*x1 + x6*x0 + x5**2 + x5*x4 + x4**2 + x4*x2 + x4*x1 + x4*x0 + x3**2 + x3*x2 + x1*x0, - w7**2 + w7*w5 + w7*w3 + w7*x7 + w7*x6 + w7*x4 + w7*x3 + w7*x2 + w6**2 + w6*w5 + w6*w2 + w6*w0 + w6*x7 + w6*x6 + w6*x3 + w6*x2 + w6*x1 + w6*x0 + w5**2 + w5*x7 + w5*x6 \ - + w5*x5 + w5*x4 + w5*x2 + w5*x1 + w4**2 + w4*w3 + w4*w2 + w4*w1 + w4*x6 + w4*x5 + w4*x2 + w4*x1 + w3**2 + w3*w1 + w3*x6 + w3*x5 + w3*x3 + w3*x0 + w2*w1 + w2*x7 \ + w7**2 + w7*w5 + w7*w3 + w7*x7 + w7*x6 + w7*x4 + w7*x3 + w7*x2 + w6**2 + w6*w5 + w6*w2 + w6*w0 + w6*x7 + w6*x6 + w6*x3 + w6*x2 + w6*x1 + w6*x0 + w5**2 + w5*x7 + w5*x6 + + w5*x5 + w5*x4 + w5*x2 + w5*x1 + w4**2 + w4*w3 + w4*w2 + w4*w1 + w4*x6 + w4*x5 + w4*x2 + w4*x1 + w3**2 + w3*w1 + w3*x6 + w3*x5 + w3*x3 + w3*x0 + w2*w1 + w2*x7 + w2*x4 + w2*x2 + w2*x1 + w1*x6 + w1*x5 + w1*x1 + w0*x5, - w7*w5 + w7*w2 + w7*w0 + w7*x5 + w7*x3 + w6**2 + w6*w5 + w6*w2 + w6*w1 + w6*w0 + w6*x7 + w6*x3 + w6*x2 + w6*x0 + w5**2 + w5*w4 + w5*x7 + w5*x6 + w5*x4 + w5*x2 + w5*x0 \ - + w4**2 + w4*w2 + w4*w1 + w4*w0 + w4*x6 + w4*x4 + w4*x3 + w4*x2 + w4*x0 + w3**2 + w3*w2 + w3*x7 + w3*x6 + w3*x4 + w3*x3 + w3*x2 + w3*x0 + w2*x7 + w2*x6 + w2*x4 \ + w7*w5 + w7*w2 + w7*w0 + w7*x5 + w7*x3 + w6**2 + w6*w5 + w6*w2 + w6*w1 + w6*w0 + w6*x7 + w6*x3 + w6*x2 + w6*x0 + w5**2 + w5*w4 + w5*x7 + w5*x6 + w5*x4 + w5*x2 + w5*x0 + + w4**2 + w4*w2 + w4*w1 + w4*w0 + w4*x6 + w4*x4 + w4*x3 + w4*x2 + w4*x0 + w3**2 + w3*w2 + w3*x7 + w3*x6 + w3*x4 + w3*x3 + w3*x2 + w3*x0 + w2*x7 + w2*x6 + w2*x4 + w2*x1 + w2*x0 + w1*w0 + w1*x5 + w1*x4 + w0*x1, - w7**2 + w7*w4 + w7*w2 + w7*x6 + w7*x4 + w7*x0 + w6*w4 + w6*w3 + w6*w2 + w6*w1 + w6*x4 + w6*x3 + w6*x1 + w5**2 + w5*w4 + w5*w3 + w5*w2 + w5*w0 + w5*x7 + w5*x5 + w5*x3 \ - + w5*x1 + w5*x0 + w4*w3 + w4*w2 + w4*w1 + w4*x7 + w4*x5 + w4*x4 + w4*x3 + w4*x1 + w4*x0 + w3**2 + w3*x7 + w3*x5 + w3*x4 + w3*x3 + w3*x1 + w2*w0 + w2*x7 + w2*x5 \ + w7**2 + w7*w4 + w7*w2 + w7*x6 + w7*x4 + w7*x0 + w6*w4 + w6*w3 + w6*w2 + w6*w1 + w6*x4 + w6*x3 + w6*x1 + w5**2 + w5*w4 + w5*w3 + w5*w2 + w5*w0 + w5*x7 + w5*x5 + w5*x3 + + w5*x1 + w5*x0 + w4*w3 + w4*w2 + w4*w1 + w4*x7 + w4*x5 + w4*x4 + w4*x3 + w4*x1 + w4*x0 + w3**2 + w3*x7 + w3*x5 + w3*x4 + w3*x3 + w3*x1 + w2*w0 + w2*x7 + w2*x5 + w2*x2 + w2*x1 + w1*w0 + w1*x6 + w1*x5 + w0*x2]) return l From 141fe7a52f655bd13b403e3221b6852f3b233280 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Tue, 21 Mar 2023 11:43:48 +0100 Subject: [PATCH 48/61] Correct modular powers of GF(2) polynomials The NTL PowerMod API requires that the base argument has smaller degree than the modulus. Also enable the dedicated API for x^e mod f. --- src/sage/libs/ntl/ntl_GF2X_linkage.pxi | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/sage/libs/ntl/ntl_GF2X_linkage.pxi b/src/sage/libs/ntl/ntl_GF2X_linkage.pxi index 91d52652cd5..b67fc23c3a4 100644 --- a/src/sage/libs/ntl/ntl_GF2X_linkage.pxi +++ b/src/sage/libs/ntl/ntl_GF2X_linkage.pxi @@ -339,12 +339,23 @@ cdef inline int celement_pow(GF2X_c* res, GF2X_c* x, long e, GF2X_c *modulus, lo x^9 + x^8 + x^7 + x^5 + x^3 sage: pow(f, 2, h) x^9 + x^8 + x^7 + x^5 + x^3 + sage: pow(x, 1000, h) + x^8 + x^7 + x^4 + + Check that deg x >= deg modulus works (:issue:`35324`):: + + sage: pow(x+1, 2, x^2+x+1) + x + sage: pow(x^2+1, 2, x^2+x+1) + x + 1 + """ cdef GF2XModulus_c mod + cdef GF2X_c xmod if modulus == NULL: if GF2X_IsX(x[0]): - GF2X_LeftShift(res[0], x[0], e - 1) + GF2X_LeftShift(res[0], x[0], e - 1) else: do_sig = GF2X_deg(x[0]) > 1e5 if do_sig: @@ -353,14 +364,17 @@ cdef inline int celement_pow(GF2X_c* res, GF2X_c* x, long e, GF2X_c *modulus, lo if do_sig: sig_off() else: + GF2X_rem(xmod, x[0], modulus[0]) GF2XModulus_build(mod, modulus[0]) - - do_sig = GF2X_deg(x[0]) > 1e5 - if do_sig: - sig_on() - GF2X_PowerMod_long_pre(res[0], x[0], e, mod) - if do_sig: - sig_off() + if GF2X_IsX(xmod): + GF2X_PowerXMod_long_pre(res[0], e, mod) + else: + do_sig = GF2X_deg(x[0]) > 1e5 + if do_sig: + sig_on() + GF2X_PowerMod_long_pre(res[0], xmod, e, mod) + if do_sig: + sig_off() cdef inline int celement_gcd(GF2X_c* res, GF2X_c* a, GF2X_c *b, long parent) except -2: From ba86ac5248634009db93d45921b4660cf08fcd46 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 31 Jan 2023 21:44:39 -0800 Subject: [PATCH 49/61] src/sage/symbolic/assumptions.py: Fixup --- src/sage/symbolic/assumptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/assumptions.py b/src/sage/symbolic/assumptions.py index 7a91bd3aaf1..cca7f6182af 100644 --- a/src/sage/symbolic/assumptions.py +++ b/src/sage/symbolic/assumptions.py @@ -428,7 +428,7 @@ def preprocess_assumptions(args): del args[i] last = x elif ((not hasattr(x, 'assume') - or (isinstance(x, Expression) and x.is_symbol()) + or (isinstance(x, Expression) and x.is_symbol())) and last is not None): args[i] = GenericDeclaration(x, last) else: From bf927cc20414310a95c99625f930f3adc72e4fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Fri, 7 Apr 2023 23:28:38 +0200 Subject: [PATCH 50/61] Faster get_unsafe for NTL GF(p) polynomials Unlike similar Zmod(n) polynomials, the GF(p) NTL polynomials would call the IntegerModRing constructor for each get_unsafe call resulting in very slow polynomial evaluation. --- src/sage/libs/ntl/ntl_ZZ_pX.pyx | 2 -- src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/sage/libs/ntl/ntl_ZZ_pX.pyx b/src/sage/libs/ntl/ntl_ZZ_pX.pyx index 73151b5d481..5021846b1e0 100644 --- a/src/sage/libs/ntl/ntl_ZZ_pX.pyx +++ b/src/sage/libs/ntl/ntl_ZZ_pX.pyx @@ -264,9 +264,7 @@ cdef class ntl_ZZ_pX(): if i < 0: r.set_from_int(0) else: - sig_on() r.x = ZZ_pX_coeff( self.x, i) - sig_off() return r cdef int getitem_as_int(ntl_ZZ_pX self, long i): diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index 1b1d37f9d2a..e0621f2c4a4 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -209,7 +209,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: f[:3] 13*x^2 + 10*x + 5 """ - return self._parent._base(self.__poly[n]._sage_()) + return self._parent._base(( self.__poly)[n]._integer_()) def _unsafe_mutate(self, n, value): n = int(n) From eba04313c189500cd7b91a5587ed2d66de51619f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Oudompheng?= Date: Sat, 8 Apr 2023 00:01:32 +0200 Subject: [PATCH 51/61] Faster computation of cached Frobenius powers Calling repeatedly PARI fffrobenius function involves redundant computations that can be avoided by reusing already computed powers. --- src/sage/rings/finite_rings/finite_field_pari_ffelt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sage/rings/finite_rings/finite_field_pari_ffelt.py b/src/sage/rings/finite_rings/finite_field_pari_ffelt.py index bbb1040ee57..74df0d752dc 100644 --- a/src/sage/rings/finite_rings/finite_field_pari_ffelt.py +++ b/src/sage/rings/finite_rings/finite_field_pari_ffelt.py @@ -225,7 +225,12 @@ def _pari_frobenius(self, k=1): raise ValueError("_pari_frobenius requires a non-zero exponent") g = self.gen() i = len(self.__pari_frobenius_powers) + if i == 0: + self.__pari_frobenius_powers.append(g.__pari__().fffrobenius(1)) + i = 1 + f1 = self.__pari_frobenius_powers[0] while i < k: i += 1 - self.__pari_frobenius_powers.append(g.__pari__().fffrobenius(i)) + fi = self.__pari_frobenius_powers[-1].ffcompomap(f1) + self.__pari_frobenius_powers.append(fi) return self.__pari_frobenius_powers[k-1] From 3d89782ebbe1e561d2d043d21f89bc7d53753cf7 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 7 Apr 2023 16:32:23 -0700 Subject: [PATCH 52/61] src/sage/calculus/desolvers.py: Fix up imports --- src/sage/calculus/desolvers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/calculus/desolvers.py b/src/sage/calculus/desolvers.py index 69987d62297..e0c31925f44 100644 --- a/src/sage/calculus/desolvers.py +++ b/src/sage/calculus/desolvers.py @@ -77,9 +77,9 @@ from sage.interfaces.maxima import Maxima from sage.misc.lazy_import import lazy_import -from sage.symbolic.ring import SR from sage.misc.functional import N from sage.rings.real_mpfr import RealField +from sage.structure.element import Expression from .functional import diff @@ -1720,6 +1720,7 @@ def Dfun(y, t): if len(ivars)==1: return desolve_odeint_inner(next(iter(ivars))) elif not ivars: + from sage.symbolic.ring import SR with SR.temp_var() as ivar: return desolve_odeint_inner(ivar) else: From f0ddf138790b56925b2496d008133cc532a8aaeb Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 7 Apr 2023 16:35:04 -0700 Subject: [PATCH 53/61] src/sage/symbolic/operators.py: Fix up imports --- src/sage/symbolic/operators.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sage/symbolic/operators.py b/src/sage/symbolic/operators.py index 82dc0173a2d..3887583bab9 100644 --- a/src/sage/symbolic/operators.py +++ b/src/sage/symbolic/operators.py @@ -2,6 +2,8 @@ import operator +from sage.structure.element import Expression + def add_vararg(first, *rest): r""" @@ -130,6 +132,8 @@ def __call__(self, *args): # temporary variable e.g. `t0` and then evaluate the # derivative f'(t0) symbolically at t0=1. See trac # #12796. + from sage.symbolic.ring import SR + temp_args = SR.temp_var(n=len(args)) vars = [temp_args[i] for i in self._parameter_set] return self._f(*temp_args).diff(*vars).function(*temp_args)(*args) From ae7db7ed6b5b67e932cdb56f1ee7aaf98f89e48e Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Fri, 7 Apr 2023 16:53:07 -0700 Subject: [PATCH 54/61] src/sage/symbolic/relation.py: Add missing import --- src/sage/symbolic/relation.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/sage/symbolic/relation.py b/src/sage/symbolic/relation.py index 77cc3d353aa..2c41c6f329d 100644 --- a/src/sage/symbolic/relation.py +++ b/src/sage/symbolic/relation.py @@ -1268,6 +1268,8 @@ def _solve_expression(f, x, explicit_solutions, multiplicities, sage: solve([x==3], [x], solution_dict=True, algorithm='sympy') [{x: 3}] """ + from sage.structure.element import Expression + if f.is_relational(): if f.operator() is not operator.eq: if algorithm == 'sympy': From 5166396f9e6628a2ff1069f7c9ef6ef181ee3d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 8 Apr 2023 08:39:57 +0200 Subject: [PATCH 55/61] some matrices aligned --- src/sage/coding/self_dual_codes.py | 183 +++++++++++++++-------------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/src/sage/coding/self_dual_codes.py b/src/sage/coding/self_dual_codes.py index f2a3e8cd2a2..4fa7960e4df 100644 --- a/src/sage/coding/self_dual_codes.py +++ b/src/sage/coding/self_dual_codes.py @@ -214,12 +214,13 @@ def _And7(): [1 1 0 1 0 0 0] """ return matrix(_F, [[1, 1, 1, 0, 0, 1, 1], - [1, 1, 1, 0, 1, 0, 1], - [1, 1, 1, 0, 1, 1, 0], - [0, 0, 0, 0, 1, 1, 1], - [0, 1, 1, 1, 0, 0, 0], - [1, 0, 1, 1, 0, 0, 0], - [1, 1, 0, 1, 0, 0, 0]]) + [1, 1, 1, 0, 1, 0, 1], + [1, 1, 1, 0, 1, 1, 0], + [0, 0, 0, 0, 1, 1, 1], + [0, 1, 1, 1, 0, 0, 0], + [1, 0, 1, 1, 0, 0, 0], + [1, 1, 0, 1, 0, 0, 0]]) + @cached_function def _H8(): @@ -240,13 +241,13 @@ def _H8(): [ 1 -1 -1 1 -1 1 1 -1] """ return matrix(ZZ, [[1, 1, 1, 1, 1, 1, 1, 1], - [1, -1, 1, -1, 1, -1, 1, -1], - [1, 1, -1, -1, 1, 1, -1, -1], - [1, -1, -1, 1, 1, -1, -1, 1], - [1, 1, 1, 1, -1, -1, -1, -1], - [1, -1, 1, -1, -1, 1, -1, 1], - [1, 1, -1, -1, -1, -1, 1, 1], - [1, -1, -1, 1, -1, 1, 1, -1]]) # from Guava's Hadamard matrices database + [1, -1, 1, -1, 1, -1, 1, -1], + [1, 1, -1, -1, 1, 1, -1, -1], + [1, -1, -1, 1, 1, -1, -1, 1], + [1, 1, 1, 1, -1, -1, -1, -1], + [1, -1, 1, -1, -1, 1, -1, 1], + [1, 1, -1, -1, -1, -1, 1, 1], + [1, -1, -1, 1, -1, 1, 1, -1]]) # from Guava's Hadamard matrices database # Remark: The above matrix constructions aid in computing some "small" self-dual codes. @@ -560,14 +561,14 @@ def self_dual_binary_codes(n): "Type":"I","Comment": "'Exceptional'. Unique codeword of smallest non-zero wt."} # [18,7] (equiv to H18 in [P]) genmat = _MS(n)([[1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0], - [0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1], - [0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1], - [0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1], - [0,0,0,0,1,0,0,0,0,1,1,0,0,1,0,1,1,0], - [0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,1,0], - [0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0], - [0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1], - [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1]]) + [0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1], + [0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,0,0,1], + [0,0,0,1,0,0,0,0,0,1,1,1,1,0,0,0,0,1], + [0,0,0,0,1,0,0,0,0,1,1,0,0,1,0,1,1,0], + [0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,1,1,0], + [0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,0,1,0], + [0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1], + [0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1]]) # G = PermutationGroup( [ "(9,10)(16,18)", "(9,16)(10,18)", "(8,9)(14,16)",\ # "(7,11)(12,17)", "(7,12)(11,17)", "(5,6)(11,12)", "(5,7)(6,17)",\ # "(4,13)(5,8)(6,14)(7,9)(10,12)(11,18)(16,17)", "(3,4)(13,15)",\ @@ -578,23 +579,23 @@ def self_dual_binary_codes(n): "Type":"I","Comment": "'Exceptional' construction. Min dist 4."} # [18, 8] (equiv to I18 in [P]) I18 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], - [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0], - [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1], - [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]) + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0], + [0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1], + [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]) genmat = _MS(n)([[1,0,0,0,0,0,0,0,0, 1, 1, 1, 1, 1, 0, 0, 0, 0], - [0,1,0,0,0,0,0,0,0, 1, 0, 1, 1, 1, 0, 1, 1, 1], - [0,0,1,0,0,0,0,0,0, 0, 1, 1, 0, 0, 0, 1, 1, 1], - [0,0,0,1,0,0,0,0,0, 0, 1, 0, 0, 1, 0, 1, 1, 1], - [0,0,0,0,1,0,0,0,0, 0, 1, 0, 1, 0, 0, 1, 1, 1], - [0,0,0,0,0,1,0,0,0, 1, 1, 0, 0, 0, 0, 1, 1, 1], - [0,0,0,0,0,0,1,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1], - [0,0,0,0,0,0,0,1,0, 0, 0, 0, 0, 0, 1, 1, 0, 1], - [0,0,0,0,0,0,0,0,1, 0, 0, 0, 0, 0, 1, 1, 1, 0]]) + [0,1,0,0,0,0,0,0,0, 1, 0, 1, 1, 1, 0, 1, 1, 1], + [0,0,1,0,0,0,0,0,0, 0, 1, 1, 0, 0, 0, 1, 1, 1], + [0,0,0,1,0,0,0,0,0, 0, 1, 0, 0, 1, 0, 1, 1, 1], + [0,0,0,0,1,0,0,0,0, 0, 1, 0, 1, 0, 0, 1, 1, 1], + [0,0,0,0,0,1,0,0,0, 1, 1, 0, 0, 0, 0, 1, 1, 1], + [0,0,0,0,0,0,1,0,0, 0, 0, 0, 0, 0, 1, 0, 1, 1], + [0,0,0,0,0,0,0,1,0, 0, 0, 0, 0, 0, 1, 1, 0, 1], + [0,0,0,0,0,0,0,0,1, 0, 0, 0, 0, 0, 1, 1, 1, 0]]) G = PermutationGroup( [ "(9,15)(16,17)", "(9,16)(15,17)", "(8,9)(17,18)", "(7,8)(16,17)", "(5,6)(10,13)", "(5,10)(6,13)", "(4,5)(13,14)", "(3,4)(12,14)", "(1,2)(6,10)", "(1,3)(2,12)" ] ) @@ -611,15 +612,15 @@ def self_dual_binary_codes(n): # are formally equivalent but with different automorphism groups; # one of these has a unique codeword of lowest weight A10 = MatrixSpace(_F,10,10)([[1, 1, 1, 1, 1, 1, 1, 1, 1, 0], - [1, 1, 1, 0, 1, 0, 1, 0, 1, 1], - [1, 0, 0, 1, 0, 1, 0, 1, 0, 1], - [0, 0, 0, 1, 1, 1, 0, 1, 0, 1], - [0, 0, 1, 1, 0, 1, 0, 1, 0, 1], - [0, 0, 0, 1, 0, 1, 1, 1, 0, 1], - [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], - [0, 0, 0, 1, 0, 0, 0, 0, 1, 1], - [0, 0, 0, 0, 0, 1, 0, 0, 1, 1], - [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]]) + [1, 1, 1, 0, 1, 0, 1, 0, 1, 1], + [1, 0, 0, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 1, 1, 0, 1, 0, 1], + [0, 0, 1, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 0, 1, 1, 1, 0, 1], + [0, 1, 0, 1, 0, 1, 0, 1, 0, 1], + [0, 0, 0, 1, 0, 0, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 1, 0, 0, 1, 1], + [0, 0, 0, 0, 0, 0, 0, 1, 1, 1]]) # [20,0]: genmat = _I2(n).augment(_I2(n)) # G = PermutationGroup( ["(10,20)", "(9,10)(19,20)", "(8,9)(18,19)", "(7,8)(17,18)", "(6,7)(16,17)",\ @@ -720,15 +721,15 @@ def self_dual_binary_codes(n): # [20,9]: (genmat, K20 are equiv) genmat = _I2(n).augment(A10) K20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], - [1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,0]]) + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [1,0,1,0,1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,1,1,0,1,0,1,0,1,0]]) #genmat = K20 # not in standard form # G = PermutationGroup( [ "(4,13)(5,15)", "(4,15)(5,13)", "(3,4,13)(5,11,15)", # "(3,4,6,11,15,17)(5,13)", "(3,5,17,4,12)(6,15,7,11,13)", @@ -741,15 +742,15 @@ def self_dual_binary_codes(n): "Type":"I","Comment": "Min dist 4."} # [20,10] L20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], - [0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0], - [0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0]]) + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [1,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,0,0,0], + [0,1,0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0]]) genmat = L20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(15,16)(19,20)", # "(15,17)(16,18)", "(10,11)(12,13)", "(10,12)(11,13)", "(9,10)(13,14)", @@ -760,15 +761,15 @@ def self_dual_binary_codes(n): "Type":"I","Comment": "Min dist 4."} # [20,11] S20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], - [1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0], - [1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0], - [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0]] ) + [0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [1,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,0,0], + [1,1,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,1,0,0], + [1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,1,0,1,0]] ) genmat = S20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(13,14)(15,16)", # "(13,15)(14,16)", "(11,12)(15,16)", "(11,13)(12,14)", "(9,10)(15,16)", @@ -780,15 +781,15 @@ def self_dual_binary_codes(n): "Type":"I","Comment":"Min dist 4."} # [20,12] R20 = _MS(n)([[0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], - [0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,1,1,0], - [1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], - [1,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1], - [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1]]) + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,1,1,0], + [1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,0], + [1,1,0,0,0,0,0,0,0,1,0,1,0,1,0,1,0,1,0,1], + [1,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,1,1]]) genmat = R20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(15,16)(19,20)", # "(15,17)(16,18)", "(11,12)(13,14)", "(11,13)(12,14)", "(9,10)(13,14)", @@ -800,15 +801,15 @@ def self_dual_binary_codes(n): "Type":"I","Comment":"Min dist 4."} # [20,13] M20 = _MS(n)([[1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], - [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], - [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0], - [1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0], - [0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1], - [0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0], - [0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,1,0,0,0,0]]) + [0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0], + [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1], + [0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,1,1,0,0], + [1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0], + [0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1], + [0,0,1,1,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0], + [0,0,0,0,0,0,1,1,0,1,1,0,1,0,0,1,0,0,0,0]]) genmat = M20 # not in standard form # G = PermutationGroup( [ "(17,18)(19,20)", "(17,19)(18,20)", "(13,14)(15,16)", # "(13,15)(14,16)", "(9,10)(11,12)", "(9,11)(10,12)", "(5,6)(7,8)", From 263cce1422bb161f75aa08503a9a53a155fe5df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 8 Apr 2023 09:10:21 +0200 Subject: [PATCH 56/61] remove old deprecated properties in set_partition + pep8 cleanup --- src/sage/combinat/set_partition.py | 165 ++++++++++++----------------- 1 file changed, 65 insertions(+), 100 deletions(-) diff --git a/src/sage/combinat/set_partition.py b/src/sage/combinat/set_partition.py index 099ab265491..b464ea8a9d8 100644 --- a/src/sage/combinat/set_partition.py +++ b/src/sage/combinat/set_partition.py @@ -455,7 +455,7 @@ def union(s): for part in s: cur = [] for i in part: - cur.extend(self[i-1]) # -1 for indexing + cur.extend(self[i - 1]) # -1 for indexing ret.append(cur) return ret return [self.parent()(union(s)) for s in SP] @@ -517,18 +517,18 @@ def pre_conjugate(sp): if sp.max_block_size() == 1: return SetPartition([sp.base_set()]) support = sorted(a for S in sp for a in S) - initials = [a for S in sp for a in S if next(a,support) in S] + initials = [a for S in sp for a in S if next(a, support) in S] singletons = [a for S in sp for a in S if len(S) == 1] if not initials and not singletons: return sp rho = pre_conjugate( SetPartition([[a for a in S if a not in initials] - for S in sp if len(S)>1 and any(a not in initials for a in S)])) + for S in sp if len(S) > 1 and any(a not in initials for a in S)])) # add back initials as singletons and singletons as terminals return SetPartition([addback(S, singletons, support[::-1]) - for S in rho]+[[a] for a in initials]) + for S in rho] + [[a] for a in initials]) support = sorted(a for S in self for a in S) - return SetPartition([[support[-support.index(a)-1] for a in S] + return SetPartition([[support[-support.index(a) - 1] for a in S] for S in pre_conjugate(self)]) @@ -789,7 +789,7 @@ def _latex_(self): """ latex_options = self.latex_options() if latex_options["plot"] is None: - return repr(self).replace("{",r"\{").replace("}",r"\}") + return repr(self).replace("{", r"\{").replace("}", r"\}") from sage.misc.latex import latex latex.add_package_to_preamble_if_available("tikz") @@ -812,7 +812,7 @@ def _latex_(self): res += "\\draw (0,0) circle [radius={}];\n".format(radius) # Add nodes - for k,i in enumerate(base_set): + for k, i in enumerate(base_set): location = (cardinality - k) * degrees - 270 if latex_options['show_labels']: res += "\\node[label={}:{}]".format(location, i) @@ -841,7 +841,7 @@ def _latex_(self): elif latex_options['plot'] == 'linear': angle = latex_options['angle'] # setup line - for k,i in enumerate(base_set): + for k, i in enumerate(base_set): if latex_options['show_labels']: res += "\\node[below=.05cm] at ({},0) {{${}$}};\n".format(k, i) res += "\\node[draw,circle, inner sep=0pt, minimum width=4pt, fill=black] " @@ -944,9 +944,8 @@ def to_permutation(self): sage: s = SetPartition([[1,3],[2,4]]) sage: s.to_permutation() [3, 4, 1, 2] - """ - return Permutation(tuple( map(tuple, self.standard_form()) )) + return Permutation(tuple(map(tuple, self.standard_form()))) def to_restricted_growth_word(self, bijection="blocks"): r""" @@ -1072,13 +1071,13 @@ def to_restricted_growth_word_intertwining(self): """ A = sorted(self.arcs()) - O = [min(B) for B in self] # openers - C = [max(B) for B in self] # closers - I = [0]*self.size() + O = [min(B) for B in self] # openers + C = [max(B) for B in self] # closers + I = [0] * self.size() for i in O: - I[i-1] = sum(1 for k,l in A if k < i < l) + sum(1 for k in C if k < i) - for (i,j) in A: - I[j-1] = sum(1 for k,l in A if i < k < j < l) + sum(1 for k in C if i < k < j) + I[i-1] = sum(1 for k, l in A if k < i < l) + sum(1 for k in C if k < i) + for i, j in A: + I[j-1] = sum(1 for k, l in A if i < k < j < l) + sum(1 for k in C if i < k < j) return I def openers(self): @@ -1207,9 +1206,9 @@ def to_rook_placement_gamma(self): w = self.to_restricted_growth_word_blocks() # the set of openers - leftmost occurrences of a letter in w EC = sorted([w.index(i) for i in range(max(w)+1)]) - rooks = [] # pairs (row i, column j) - R = [] # attacked rows - for c in range(n): # columns from left to right + rooks = [] # pairs (row i, column j) + R = [] # attacked rows + for c in range(n): # columns from left to right if c not in EC: r = 0 w_c = w[c] @@ -1293,9 +1292,9 @@ def to_rook_placement_rho(self): # the number of closers which are larger than i and whose # block is before the block of i rs = [sum(1 for j in R if j > i and w[j] < w[i]) for i in range(n)] - EC = [n-j for j in R] # empty columns - rooks = [] # pairs (row i, column j) - for i in range(1,n): + EC = [n-j for j in R] # empty columns + rooks = [] # pairs (row i, column j) + for i in range(1, n): U = [j for j in range(n+1-i, n+1) if j not in EC] if rs[i] < len(U): j = U[rs[i]] @@ -1355,7 +1354,7 @@ def to_rook_placement_psi(self): P = sorted(P, key=lambda B: (-len(B), min(B))) b = P.index(B) i = j - b - 1 - degrees.append((j,i)) + degrees.append((j, i)) # reconstruct rooks from degree sequence rooks = [] attacked_rows = [] @@ -1364,7 +1363,7 @@ def to_rook_placement_psi(self): while d > i + sum(1 for r in attacked_rows if r > i): i += 1 attacked_rows.append(i) - rooks.append((i,j)) + rooks.append((i, j)) return sorted(rooks) def apply_permutation(self, p): @@ -1418,11 +1417,11 @@ def crossings_iterator(self): # each arc is sorted, but the set of arcs might not be arcs = sorted(self.arcs(), key=min) while arcs: - i1,j1 = arcs.pop(0) - for i2,j2 in arcs: + i1, j1 = arcs.pop(0) + for i2, j2 in arcs: # we know that i1 < i2 and i1 < j1 and i2 < j2 if i2 < j1 < j2: - yield ((i1,j1), (i2,j2)) + yield ((i1, j1), (i2, j2)) def crossings(self): r""" @@ -1472,9 +1471,9 @@ def number_of_crossings(self): sage: n.number_of_crossings() 1 """ - return Integer( len(list(self.crossings_iterator())) ) + return Integer(len(list(self.crossings_iterator()))) - def is_noncrossing(self): + def is_noncrossing(self) -> bool: r""" Check if ``self`` is noncrossing. @@ -1535,11 +1534,11 @@ def nestings_iterator(self): # each arc is sorted, but the set of arcs might not be arcs = sorted(self.arcs(), key=min) while arcs: - i1,j1 = arcs.pop(0) - for i2,j2 in arcs: + i1, j1 = arcs.pop(0) + for i2, j2 in arcs: # we know that i1 < i2 and i1 < j1 and i2 < j2 if i2 < j2 < j1: - yield ((i1,j1), (i2,j2)) + yield ((i1, j1), (i2, j2)) def nestings(self): r""" @@ -1596,7 +1595,7 @@ def number_of_nestings(self): c += one return c - def is_nonnesting(self): + def is_nonnesting(self) -> bool: r""" Return if ``self`` is nonnesting or not. @@ -1624,7 +1623,7 @@ def is_nonnesting(self): return True return False - def is_atomic(self): + def is_atomic(self) -> bool: r""" Return if ``self`` is an atomic set partition. @@ -1682,7 +1681,7 @@ def standardization(self): sage: SetPartition([('c','b'),('d','f'),('e','a')]).standardization() {{1, 5}, {2, 3}, {4, 6}} """ - r = {e: i for i,e in enumerate(sorted(self.base_set()), 1)} + r = {e: i for i, e in enumerate(sorted(self.base_set()), 1)} return SetPartitions(len(r))([[r[e] for e in b] for b in self]) def restriction(self, I): @@ -1782,7 +1781,7 @@ def ordered_set_partition_action(self, s): cur = 1 ret = [] for part in s: - sub_parts = [list(self[i-1]) for i in part] # -1 for indexing + sub_parts = [list(self[i - 1]) for i in part] # -1 for indexing # Standardizing sub_parts (the cur variable not being reset # to 1 gives us the offset we want): mins = [min(i) for i in sub_parts] @@ -1985,16 +1984,16 @@ def plot(self, angle=None, color='black', base_set_dict=None): if base_set_dict is not None: vertices_dict = base_set_dict else: - vertices_dict = {val: pos for pos,val in enumerate(sorted_vertices_list)} + vertices_dict = {val: pos for pos, val in enumerate(sorted_vertices_list)} for elt in vertices_dict: pos = vertices_dict[elt] - diag += point((pos,0), size=30, color=color) + diag += point((pos, 0), size=30, color=color) diag += text(elt, (pos, -sgn(angle)*0.1), color=color) # TODO: change 0.1 to something proportional to the height of the picture - for (k,j) in self.arcs(): - pos_k,pos_j = float(vertices_dict[k]),float(vertices_dict[j]) + for k, j in self.arcs(): + pos_k, pos_j = float(vertices_dict[k]), float(vertices_dict[j]) center = ((pos_k+pos_j) / 2, -abs(pos_j-pos_k) / (2*tan(angle))) r1 = abs((pos_j-pos_k) / (2*sin(angle))) sector = (sgn(angle) * (pi/2 - angle), sgn(angle) * (pi/2 + angle)) @@ -2079,7 +2078,7 @@ def __classcall_private__(cls, s=None, part=None): else: part = sorted(part, reverse=True) if part not in Partitions(len(s)): - raise ValueError("part must be an integer partition of %s"%len(s)) + raise ValueError("part must be an integer partition of %s" % len(s)) return SetPartitions_setparts(s, Partition(part)) else: return SetPartitions_set(s) @@ -2138,7 +2137,7 @@ def _element_constructor_(self, s, check=True): if isinstance(s, SetPartition): if isinstance(s.parent(), SetPartitions): return self.element_class(self, s, check=check) - raise ValueError("cannot convert %s into an element of %s"%(s, self)) + raise ValueError("cannot convert %s into an element of %s" % (s, self)) return self.element_class(self, s, check=check) Element = SetPartition @@ -2257,17 +2256,17 @@ def from_restricted_growth_word_intertwining(self, w): if len(w) == 0: return self.element_class(self, []) R = [[1]] - C = [1] # closers, always reverse sorted - m = 0 # max - for i in range(1,len(w)): - if w[i] == 1 + m: # i+1 is an opener + C = [1] # closers, always reverse sorted + m = 0 # max + for i in range(1, len(w)): + if w[i] == 1 + m: # i+1 is an opener m += 1 - R.append([i+1]) + R.append([i + 1]) else: # add i+1 to the block, such that there are I[i] closers thereafter l = C[w[i]] B = next(B for B in R if l in B) - B.append(i+1) + B.append(i + 1) C.remove(l) C = [i+1] + C return self.element_class(self, R) @@ -2372,9 +2371,9 @@ def from_arcs(self, arcs, n): sage: SetPartitions().from_arcs([(2,3)], 5) {{1}, {2, 3}, {4}, {5}} """ - P = DisjointSet(range(1,n+1)) - for i,j in arcs: - P.union(i,j) + P = DisjointSet(range(1, n + 1)) + for i, j in arcs: + P.union(i, j) return self.element_class(self, P) def from_rook_placement_gamma(self, rooks, n): @@ -2423,9 +2422,9 @@ def from_rook_placement_gamma(self, rooks, n): if n == 0: return self.element_class(self, []) # the columns of the board, beginning with column n-1 - C = [set(range(n+1-j, n+1)) for j in range(1,n)] + C = [set(range(n+1-j, n+1)) for j in range(1, n)] # delete cells north and east of each rook - for (j,i) in rooks: + for j, i in rooks: # north C[n-j-1].difference_update(range(j+1, i+1)) # east @@ -2478,10 +2477,10 @@ def from_rook_placement_rho(self, rooks, n): """ # the closers correspond to the empty columns cols = [j for j, _ in rooks] - R = [j for j in range(1,n+1) if j not in cols] + R = [j for j in range(1, n + 1) if j not in cols] # the columns of the board, beginning with column n-1 - C = [set(range(n+1-j, n+1)) if n-j not in R else set() for j in range(1,n)] - for (j,i) in rooks: # column j from right, row i from top + C = [set(range(n+1-j, n+1)) if n-j not in R else set() for j in range(1, n)] + for j, i in rooks: # column j from right, row i from top # south C[n-j-1].difference_update(range(i, n+1)) # east @@ -2491,10 +2490,10 @@ def from_rook_placement_rho(self, rooks, n): C_flat = [i for c in C for i in c] # the number of closers which are larger than i and whose # block is before the block of i - rs = [C_flat.count(i) for i in range(1,n+1)] + rs = [C_flat.count(i) for i in range(1, n + 1)] # create the blocks P = [[] for _ in R] - for i in range(1, n+1): + for i in range(1, n + 1): k = rs[i-1] # find k-th block which does not yet have a closer b = 0 @@ -2542,15 +2541,15 @@ def from_rook_placement_psi(self, rooks, n): # we refer to the cell in row i and column j with (i, j) P = [] rooks_by_column = {j: i for (i, j) in rooks} - for c in range(1, n+1): + for c in range(1, n + 1): # determine the weight of column c try: r = rooks_by_column[c] n_rooks = 1 - ne = r-1 + sum(1 for i,j in rooks if i > r and j < c) + ne = r-1 + sum(1 for i, j in rooks if i > r and j < c) except KeyError: n_rooks = 0 - ne = sum(1 for i,j in rooks if j < c) + ne = sum(1 for i, j in rooks if j < c) b = c - n_rooks - ne if len(P) == b-1: @@ -2560,7 +2559,7 @@ def from_rook_placement_psi(self, rooks, n): P = sorted(P, key=lambda B: (-len(B), min(B))) return self.element_class(self, P) - def is_less_than(self, s, t): + def is_less_than(self, s, t) -> bool: r""" Check if `s < t` in the refinement ordering on set partitions. @@ -2609,7 +2608,7 @@ def is_less_than(self, s, t): lt = is_less_than - def is_strict_refinement(self, s, t): + def is_strict_refinement(self, s, t) -> bool: r""" Return ``True`` if ``s`` is a strict refinement of ``t`` and satisfies `s \neq t`. @@ -2762,7 +2761,7 @@ def _repr_(self): sage: SetPartitions([1,2,3]) Set partitions of {1, 2, 3} """ - return "Set partitions of %s"%(Set(self._set)) + return "Set partitions of %s" % (Set(self._set)) def __contains__(self, x): """ @@ -2939,24 +2938,7 @@ def _repr_(self): sage: SetPartitions(4, [2,2]) Set partitions of {1, 2, 3, 4} with sizes in [2, 2] """ - return "Set partitions of %s with sizes in %s"%(Set(self._set), self._parts) - - @property - def parts(self): - r""" - ``self.parts`` is deprecated; use :meth:`shape` instead. - - TESTS:: - - sage: SetPartitions(5, [2,2,1]).parts - doctest:...: DeprecationWarning: The attribute parts for the partition of block sizes is deprecated, use the method shape instead. - See https://github.com/sagemath/sage/issues/25865 for details. - [2, 2, 1] - """ - from sage.misc.superseded import deprecation - deprecation(25865, "The attribute parts for the partition of block sizes is deprecated," - " use the method shape instead.") - return self.shape() + return "Set partitions of %s with sizes in %s" % (Set(self._set), self._parts) def shape(self): r""" @@ -3190,24 +3172,7 @@ def _repr_(self): sage: SetPartitions(5, 3) Set partitions of {1, 2, 3, 4, 5} with 3 parts """ - return "Set partitions of %s with %s parts"%(Set(self._set), self._k) - - @property - def n(self): - r""" - ``self.n`` is deprecated; use :meth:`number_of_blocks` instead. - - TESTS:: - - sage: SetPartitions(5, 3).n - doctest:...: DeprecationWarning: The attribute n for the number of blocks is deprecated, use the method number_of_blocks instead. - See https://github.com/sagemath/sage/issues/25462 for details. - 3 - """ - from sage.misc.superseded import deprecation - deprecation(25462, "The attribute n for the number of blocks is deprecated," - " use the method number_of_blocks instead.") - return self.number_of_blocks() + return "Set partitions of %s with %s parts" % (Set(self._set), self._k) def number_of_blocks(self): r""" From e33815f1f862adaa9dee8afd87aeaaf94586137b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 8 Apr 2023 11:37:57 +0200 Subject: [PATCH 57/61] pep8 and code details in weyl_characters.py --- .../combinat/root_system/weyl_characters.py | 111 +++++++++--------- 1 file changed, 55 insertions(+), 56 deletions(-) diff --git a/src/sage/combinat/root_system/weyl_characters.py b/src/sage/combinat/root_system/weyl_characters.py index 4ec0354f20a..94170220217 100644 --- a/src/sage/combinat/root_system/weyl_characters.py +++ b/src/sage/combinat/root_system/weyl_characters.py @@ -125,7 +125,7 @@ def __init__(self, ct, base_ring=ZZ, prefix=None, style="lattice", k=None, conju self._origin = self._space.zero() if prefix is None: if ct.is_atomic(): - prefix = ct[0]+str(ct[1]) + prefix = ct[0] + str(ct[1]) else: prefix = repr(ct) self._prefix = prefix @@ -510,7 +510,7 @@ def product_on_basis(self, a, b): # smaller character is the one that is decomposed # into weights. if sum(a.coefficients()) > sum(b.coefficients()): - a,b = b,a + a, b = b, a return self._product_helper(self._irr_weights(a), b) def _product_helper(self, d1, b): @@ -535,11 +535,11 @@ def _product_helper(self, d1, b): """ d = {} for k in d1: - [epsilon,g] = self.dot_reduce(b+k) + [epsilon, g] = self.dot_reduce(b + k) if epsilon == 1: - d[g] = d.get(g,0) + d1[k] + d[g] = d.get(g, 0) + d1[k] elif epsilon == -1: - d[g] = d.get(g,0) - d1[k] + d[g] = d.get(g, 0) - d1[k] return self._from_dict(d, coerce=True) def dot_reduce(self, a): @@ -576,31 +576,32 @@ def dot_reduce(self, a): return [0, self._space.zero()] elif c < -1: epsilon = -epsilon - ret -= (1+c)*alpha[i] + ret -= (1 + c) * alpha[i] done = False break if self._k is not None: l = self.level(ret) k = self._k if l > k: - if l == k+1: + if l == k + 1: return [0, self._space.zero()] else: epsilon = -epsilon - ret = self.affine_reflect(ret,k+1) + ret = self.affine_reflect(ret, k + 1) done = False return [epsilon, ret] def affine_reflect(self, wt, k=0): r""" + Return the reflection of wt in the hyperplane `\theta`. + + Optionally, this also shifts by a multiple `k` of `\theta`. + INPUT: - ``wt`` -- a weight - ``k`` -- (optional) a positive integer - Returns the reflection of wt in the hyperplane - `\theta`. Optionally shifts by a multiple `k`of `\theta`. - EXAMPLES:: sage: B22 = FusionRing("B2",2) @@ -609,8 +610,8 @@ def affine_reflect(self, wt, k=0): sage: [B22.affine_reflect(x,2) for x in fw] [(2, 1), (3/2, 3/2)] """ - coef = ZZ(2*wt.inner_product(self._highest)/self._hip) - return wt+(k-coef)*self._highest + coef = ZZ(2 * wt.inner_product(self._highest) / self._hip) + return wt + (k - coef) * self._highest def some_elements(self): """ @@ -722,7 +723,7 @@ def _demazure_helper(self, dd, word="long", debug=False): for i in index_set: temp = [] cm[i] = [0] * r - for ind,j in enumerate(index_set): + for ind, j in enumerate(index_set): cm[i][ind] = int(alpha[i].inner_product(alphacheck[j])) if cm[i][ind]: temp.append(ind) @@ -737,27 +738,27 @@ def _demazure_helper(self, dd, word="long", debug=False): print("i=%s" % i) next = {} for v in accum: - coroot = v[i-1] + coroot = v[i - 1] if debug: print(" v=%s, coroot=%s" % (v, coroot)) if coroot >= 0: mu = v - for j in range(coroot+1): - next[mu] = next.get(mu,0) + accum[v] + for j in range(coroot + 1): + next[mu] = next.get(mu, 0) + accum[v] if debug: print(" mu=%s, next[mu]=%s" % (mu, next[mu])) mu = list(mu) - for k in supp[i-1]: + for k in supp[i - 1]: mu[k] -= cm[i][k] mu = tuple(mu) else: mu = v - for j in range(-1-coroot): + for j in range(-1 - coroot): mu = list(mu) - for k in supp[i-1]: + for k in supp[i - 1]: mu[k] += cm[i][k] mu = tuple(mu) - next[mu] = next.get(mu,0) - accum[v] + next[mu] = next.get(mu, 0) - accum[v] if debug: print(" mu=%s, next[mu]=%s" % (mu, next[mu])) accum = {} @@ -789,9 +790,9 @@ def _weight_multiplicities(self, x): d1 = self._irr_weights(k) for l in d1: if l in d: - d[l] += c*d1[l] + d[l] += c * d1[l] else: - d[l] = c*d1[l] + d[l] = c * d1[l] for k in list(d): if d[k] == 0: del d[k] @@ -824,7 +825,7 @@ def irr_repr(self, hwv): sage: [B3.irr_repr(v) for v in B3.fundamental_weights()] ['B3(1,0,0)', 'B3(0,1,0)', 'B3(0,0,1)'] """ - return self._prefix+self._wt_repr(hwv) + return self._prefix + self._wt_repr(hwv) def level(self, wt): """ @@ -838,7 +839,7 @@ def level(self, wt): sage: [CartanType("F4~").dual().a()[x] for x in [1..4]] [2, 3, 2, 1] """ - return ZZ(2*wt.inner_product(self._highest)/self._hip) + return ZZ(2 * wt.inner_product(self._highest) / self._hip) def _dual_helper(self, wt): """ @@ -857,7 +858,7 @@ def _dual_helper(self, wt): alphacheck = self._space.simple_coroots() fw = self._space.fundamental_weights() for i in self._space.index_set(): - ret += wt.inner_product(alphacheck[i])*fw[self._opposition[i]] + ret += wt.inner_product(alphacheck[i]) * fw[self._opposition[i]] return ret def _wt_repr(self, wt): @@ -1078,7 +1079,7 @@ def _char_from_weights(self, mdict): hdict = {} ddict = mdict.copy() while ddict: - highest = max((x.inner_product(self._space.rho()),x) for x in ddict)[1] + highest = max((x.inner_product(self._space.rho()), x) for x in ddict)[1] if not highest.is_dominant(): raise ValueError("multiplicity dictionary may not be Weyl group invariant") sdict = self._irr_weights(highest) @@ -1279,8 +1280,10 @@ def dual(self): def highest_weight(self): """ - This method is only available for basis elements. Returns the - parametrizing dominant weight of an irreducible character. + Return the parametrizing dominant weight + of an irreducible character. + + This method is only available for basis elements. EXAMPLES:: @@ -1323,7 +1326,7 @@ def __pow__(self, n): n = -n res = self - for i in range(n-1): + for i in range(n - 1): res = self * res return res @@ -1371,13 +1374,12 @@ def symmetric_power(self, k): if k == 1: return self ret = par.zero() - for r in range(1, k+1): - adam_r = self._adams_operation_helper(r) - ret += par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.symmetric_power(k-r)) - dd = {} + for r in range(1, k + 1): + adam_r = self._adams_operator_helper(r) + ret += par.linear_combination((par._product_helper(adam_r, l), c) + for l, c in self.symmetric_power(k - r)) m = ret.weight_multiplicities() - for l in m: - dd[l] = m[l]/k + dd = {key: val / k for key, val in m.items()} return self.parent().char_from_weights(dd) @cached_method @@ -1410,8 +1412,8 @@ def exterior_power(self, k): if k == 1: return self ret = par.zero() - for r in range(1,k+1): - adam_r = self._adams_operation_helper(r) + for r in range(1, k + 1): + adam_r = self._adams_operator_helper(r) if is_even(r): ret -= par.linear_combination((par._product_helper(adam_r, l), c) for (l, c) in self.exterior_power(k-r)) else: @@ -1422,7 +1424,7 @@ def exterior_power(self, k): dd[l] = m[l]/k return self.parent().char_from_weights(dd) - def adams_operation(self, r): + def adams_operator(self, r): """ Return the `r`-th Adams operation of ``self``. @@ -1436,12 +1438,14 @@ def adams_operation(self, r): EXAMPLES:: sage: A2 = WeylCharacterRing("A2") - sage: A2(1,1,0).adams_operation(3) + sage: A2(1,1,0).adams_operator(3) A2(2,2,2) - A2(3,2,1) + A2(3,3,0) """ - return self.parent().char_from_weights(self._adams_operation_helper(r)) + return self.parent().char_from_weights(self._adams_operator_helper(r)) - def _adams_operation_helper(self, r): + adams_operation = adams_operator + + def _adams_operator_helper(self, r): """ Helper function for Adams operations. @@ -1455,14 +1459,11 @@ def _adams_operation_helper(self, r): EXAMPLES:: sage: A2 = WeylCharacterRing("A2") - sage: A2(1,1,0)._adams_operation_helper(3) + sage: A2(1,1,0)._adams_operator_helper(3) {(3, 3, 0): 1, (3, 0, 3): 1, (0, 3, 3): 1} """ d = self.weight_multiplicities() - dd = {} - for k in d: - dd[r*k] = d[k] - return dd + return {r * key: val for key, val in d.items()} def symmetric_square(self): """ @@ -1701,14 +1702,14 @@ def irreducible_character_freudenthal(hwv, debug=False): for alpha in positive_roots: mu_plus_i_alpha = mu + alpha while mu_plus_i_alpha in mdict: - accum += mdict[mu_plus_i_alpha]*(mu_plus_i_alpha).inner_product(alpha) + accum += mdict[mu_plus_i_alpha] * (mu_plus_i_alpha).inner_product(alpha) mu_plus_i_alpha += alpha if accum == 0: next_layer[mu] = 0 else: hwv_plus_rho = hwv + rho mu_plus_rho = mu + rho - next_layer[mu] = ZZ(2*accum)/ZZ((hwv_plus_rho).inner_product(hwv_plus_rho)-(mu_plus_rho).inner_product(mu_plus_rho)) + next_layer[mu] = ZZ(2 * accum) / ZZ((hwv_plus_rho).inner_product(hwv_plus_rho) - (mu_plus_rho).inner_product(mu_plus_rho)) current_layer = next_layer return mdict @@ -1786,7 +1787,7 @@ def __init__(self, parent, prefix): self._base_ring = parent._base_ring if prefix is None: # TODO: refactor this fragile logic into CartanType's - if self._parent._prefix.replace('x','_').isupper(): + if self._parent._prefix.replace('x', '_').isupper(): # The 'x' workaround above is to support reducible Cartan types like 'A1xB2' prefix = self._parent._prefix.lower() elif self._parent._prefix.islower(): @@ -1878,7 +1879,7 @@ def product_on_basis(self, a, b): sage: a2(1,0,0) * a2(0,1,0) # indirect doctest a2(1,1,0) """ - return self(a+b) + return self(a + b) def some_elements(self): """ @@ -2012,7 +2013,7 @@ def wt_repr(self, wt): sage: [G2.ambient().wt_repr(x) for x in G2.fundamental_weights()] ['g2(1,0)', 'g2(0,1)'] """ - return self._prefix+self.parent()._wt_repr(wt) + return self._prefix + self.parent()._wt_repr(wt) def _repr_term(self, t): """ @@ -2118,9 +2119,7 @@ def shift(self, mu): [g2(2,2), g2(1,3)] """ d1 = self.monomial_coefficients() - d2 = {} - for nu in d1: - d2[mu + nu] = d1[nu] + d2 = {mu + nu: val for nu, val in d1.items()} return self.parent()._from_dict(d2) def demazure(self, w, debug=False): @@ -2228,7 +2227,7 @@ def demazure_lusztig(self, i, v): if i in self.parent().space().index_set(): rho = self.parent().space().from_vector_notation(self.parent().space().rho(), style="coroots") inv = self.scale(-1) - return (-inv.shift(-rho).demazure([i]).shift(rho)+v * inv.demazure([i])).scale(-1) + return (-inv.shift(-rho).demazure([i]).shift(rho) + v * inv.demazure([i])).scale(-1) elif isinstance(i, list): if not i: return self From 67e7cf962a5f9f2d940217a55396427c48a19f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sun, 9 Apr 2023 10:52:49 +0200 Subject: [PATCH 58/61] refactor poset examples for better code coverage --- src/sage/combinat/posets/poset_examples.py | 200 ++++++++------------- 1 file changed, 73 insertions(+), 127 deletions(-) diff --git a/src/sage/combinat/posets/poset_examples.py b/src/sage/combinat/posets/poset_examples.py index e2e9d4ba8fe..41748b6d11a 100644 --- a/src/sage/combinat/posets/poset_examples.py +++ b/src/sage/combinat/posets/poset_examples.py @@ -106,6 +106,51 @@ from sage.categories.finite_lattice_posets import FiniteLatticePosets from sage.graphs.digraph import DiGraph from sage.rings.integer import Integer +from sage.sets.non_negative_integers import NonNegativeIntegers + + +def check_int(n, minimum=0): + """ + Check that ``n`` is an integer at least equal to ``minimum``. + + This is a boilerplate function ensuring input safety. + + INPUT: + + - ``n`` -- anything + + - ``minimum`` -- an optional integer (default: 0) + + EXAMPLES:: + + sage: from sage.combinat.posets.poset_examples import check_int + sage: check_int(6, 3) + 6 + sage: check_int(6) + 6 + + sage: check_int(-1) + Traceback (most recent call last): + ... + ValueError: number of elements must be a non-negative integer, not -1 + + sage: check_int(1, 3) + Traceback (most recent call last): + ... + ValueError: number of elements must be an integer at least 3, not 1 + + sage: check_int('junk') + Traceback (most recent call last): + ... + ValueError: number of elements must be a non-negative integer, not junk + """ + if minimum == 0: + msg = "a non-negative integer" + else: + msg = f"an integer at least {minimum}" + if n not in NonNegativeIntegers() or n < minimum: + raise ValueError("number of elements must be " + msg + f", not {n}") + return Integer(n) class Posets(metaclass=ClasscallMetaclass): @@ -155,12 +200,7 @@ def __classcall__(cls, n=None): """ if n is None: return sage.categories.posets.Posets() - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) return FinitePosets_n(n) @staticmethod @@ -203,12 +243,7 @@ def BooleanLattice(n, facade=None, use_subsets=False): sage: list(posets.BooleanLattice(1, use_subsets=True)) [{}, {1}] """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) if n == 0: if use_subsets: from sage.sets.set import Set @@ -282,12 +317,7 @@ def ChainPoset(n, facade=None): sage: C.cover_relations() [[0, 1]] """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) D = DiGraph([range(n), [[x, x + 1] for x in range(n - 1)]], format='vertices_and_edges') return FiniteLatticePoset(hasse_diagram=D, @@ -335,12 +365,7 @@ def AntichainPoset(n, facade=None): sage: C.cover_relations() [] """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) return Poset((range(n), []), facade=facade) @staticmethod @@ -398,12 +423,7 @@ def DiamondPoset(n, facade=None): sage: posets.DiamondPoset(7) Finite lattice containing 7 elements """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n <= 2: - raise ValueError("n must be an integer at least 3") + n = check_int(n, 3) c = [[n - 1] for x in range(n)] c[0] = [x for x in range(1, n - 1)] c[n - 1] = [] @@ -435,12 +455,7 @@ def Crown(n, facade=None): sage: posets.Crown(3) Finite poset containing 6 elements """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 2: - raise ValueError("n must be an integer at least 2") + n = check_int(n, 2) D = {i: [i + n, i + n + 1] for i in range(n - 1)} D[n - 1] = [n, n + n - 1] return FinitePoset(hasse_diagram=DiGraph(D), category=FinitePosets(), @@ -478,12 +493,7 @@ def DivisorLattice(n, facade=None): Finite lattice containing 1 elements with distinguished linear extension """ from sage.arith.misc import divisors, is_prime - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n <= 0: - raise ValueError("n must be a positive integer") + n = check_int(n, 1) Div_n = divisors(n) hasse = DiGraph([Div_n, lambda a, b: b % a == 0 and is_prime(b // a)]) return FiniteLatticePoset(hasse, elements=Div_n, facade=facade, @@ -623,9 +633,7 @@ def IntegerPartitionsDominanceOrder(n): [[4, 2], [5, 1]], [[5, 1], [6]]] """ - from sage.rings.semirings.non_negative_integer_semiring import NN - if n not in NN: - raise ValueError('n must be an integer') + n = check_int(n) from sage.combinat.partition import Partitions, Partition return LatticePoset((Partitions(n), Partition.dominates)).dual() @@ -663,14 +671,7 @@ def PowerPoset(n): 0 """ # Todo: Make this faster. - - try: - n = Integer(n) - except TypeError: - raise TypeError("parameter n must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("parameter n must be non-negative, not {0}".format(n)) - + n = check_int(n) all_pos_n = set() Pn = list(Posets(n)) for P in Pn: @@ -759,16 +760,6 @@ def RandomPoset(n, p): TESTS:: - sage: posets.RandomPoset('junk', 0.5) - Traceback (most recent call last): - ... - TypeError: number of elements must be an integer, not junk - - sage: posets.RandomPoset(-6, 0.5) - Traceback (most recent call last): - ... - ValueError: number of elements must be non-negative, not -6 - sage: posets.RandomPoset(6, 'garbage') Traceback (most recent call last): ... @@ -783,13 +774,7 @@ def RandomPoset(n, p): Finite poset containing 0 elements """ from sage.misc.prandom import random - - try: - n = Integer(n) - except (TypeError, ValueError): - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) try: p = float(p) except (TypeError, ValueError): @@ -856,16 +841,6 @@ def RandomLattice(n, p, properties=None): TESTS:: - sage: posets.RandomLattice('junk', 0.5) - Traceback (most recent call last): - ... - TypeError: number of elements must be an integer, not junk - - sage: posets.RandomLattice(-6, 0.5) - Traceback (most recent call last): - ... - ValueError: number of elements must be non-negative, not -6 - sage: posets.RandomLattice(6, 'garbage') Traceback (most recent call last): ... @@ -885,13 +860,7 @@ def RandomLattice(n, p, properties=None): Finite lattice containing 0 elements """ from copy import copy - - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) try: p = float(p) except Exception: @@ -973,10 +942,8 @@ def SetPartitions(n): sage: posets.SetPartitions(4) Finite lattice containing 15 elements """ - from sage.rings.semirings.non_negative_integer_semiring import NN - if n not in NN: - raise ValueError('n must be an integer') from sage.combinat.set_partition import SetPartitions + n = check_int(n) S = SetPartitions(n) def covers(x): @@ -1083,12 +1050,7 @@ def StandardExample(n, facade=None): sage: P(4) < P(3), P(4) > P(3) (False, False) """ - try: - n = Integer(n) - except TypeError: - raise TypeError("dimension must be an integer, not {0}".format(n)) - if n < 2: - raise ValueError("dimension must be at least 2, not {0}".format(n)) + n = check_int(n, 2) return Poset((range(2*n), [[i, j+n] for i in range(n) for j in range(n) if i != j]), facade=facade) @@ -1244,17 +1206,20 @@ def TetrahedralPoset(n, *colors, **labels): sage: tet = posets.TetrahedralPoset(3, 'green','yellow','blue','orange') sage: ji.is_isomorphic(tet) True + + TESTS:: + + sage: posets.TetrahedralPoset(4,'scarlet') + Traceback (most recent call last): + ... + ValueError: color input must be among: 'green', 'red', 'yellow', + 'orange', 'silver', and 'blue' """ + n = check_int(n, 2) n = n - 1 - try: - n = Integer(n) - except TypeError: - raise TypeError("n must be an integer") - if n < 2: - raise ValueError("n must be greater than 2") for c in colors: if c not in ('green', 'red', 'yellow', 'orange', 'silver', 'blue'): - raise ValueError("color input must be from the following: 'green', 'red', 'yellow', 'orange', 'silver', and 'blue'") + raise ValueError("color input must be among: 'green', 'red', 'yellow', 'orange', 'silver', and 'blue'") elem = [(i, j, k) for i in range(n) for j in range(n - i) for k in range(n - i - j)] rels = [] @@ -1421,12 +1386,7 @@ def UpDownPoset(n, m=1): sage: P = posets.UpDownPoset(0); P Finite poset containing 0 elements """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) try: m = Integer(m) except TypeError: @@ -1581,12 +1541,7 @@ def YoungFibonacci(n): from sage.categories.finite_posets import FinitePosets from sage.combinat.words.word import Word - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {0}".format(n)) - if n < 0: - raise ValueError("number of elements must be non-negative, not {0}".format(n)) + n = check_int(n) if n == 0: return MeetSemilattice({'': []}) @@ -1632,12 +1587,7 @@ def DoubleTailedDiamond(n): sage: P.cover_relations() [[1, 2], [2, 3], [2, 4], [3, 5], [4, 5], [5, 6]] """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {}".format(n)) - if n <= 0: - raise ValueError("number of elements must be nonnegative, not {}".format(n)) + n = check_int(n, 1) edges = [(i, i+1) for i in range(1, n)] edges.extend([(n, n+1), (n, n+2), (n+1, n+3), (n+2, n+3)]) @@ -1680,12 +1630,7 @@ def PermutationPattern(n): sage: posets.PermutationPattern(2) Finite poset containing 3 elements """ - try: - n = Integer(n) - except TypeError: - raise TypeError("number of elements must be an integer, not {}".format(n)) - if n <= 0: - raise ValueError("number of elements must be nonnegative, not {}".format(n)) + n = check_int(n, 1) elem = [] for i in range(1, n + 1): elem += Permutations(i) @@ -1841,6 +1786,7 @@ def RibbonPoset(n, descents): sage: sorted(R.cover_relations()) [[0, 1], [2, 1], [3, 2], [3, 4]] """ + n = check_int(n) return Mobile(DiGraph([list(range(n)), [(i + 1, i) if i in descents else (i, i + 1) for i in range(n - 1)]])) From a4281cf5a2cb04b1b00c1f5bce299933e8c1ab72 Mon Sep 17 00:00:00 2001 From: Kwankyu Lee Date: Tue, 11 Apr 2023 20:00:43 +0900 Subject: [PATCH 59/61] GitHub transition is now over --- src/doc/en/developer/advanced_git.rst | 11 +++++------ src/doc/en/developer/git_trac.rst | 11 +++++------ src/doc/en/developer/index.rst | 11 +++++------ src/doc/en/developer/manual_git.rst | 17 ++++++++--------- src/doc/en/developer/reviewer_checklist.rst | 11 +++++------ src/doc/en/developer/trac.rst | 21 +++++++++------------ src/doc/en/developer/walk_through.rst | 16 +++++++--------- src/doc/en/developer/workflows.rst | 11 +++++------ 8 files changed, 49 insertions(+), 60 deletions(-) diff --git a/src/doc/en/developer/advanced_git.rst b/src/doc/en/developer/advanced_git.rst index eb128986452..3adde7bd6c3 100644 --- a/src/doc/en/developer/advanced_git.rst +++ b/src/doc/en/developer/advanced_git.rst @@ -8,12 +8,11 @@ Advanced Git .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. diff --git a/src/doc/en/developer/git_trac.rst b/src/doc/en/developer/git_trac.rst index 462291488b9..155510b00b2 100644 --- a/src/doc/en/developer/git_trac.rst +++ b/src/doc/en/developer/git_trac.rst @@ -8,12 +8,11 @@ Optional: Using the Git-Trac Command .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. diff --git a/src/doc/en/developer/index.rst b/src/doc/en/developer/index.rst index d851df7b0e7..670f51dbc97 100644 --- a/src/doc/en/developer/index.rst +++ b/src/doc/en/developer/index.rst @@ -6,12 +6,11 @@ Welcome to the Sage Developer's Guide! .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. diff --git a/src/doc/en/developer/manual_git.rst b/src/doc/en/developer/manual_git.rst index 83f595abab7..cf0c109dacc 100644 --- a/src/doc/en/developer/manual_git.rst +++ b/src/doc/en/developer/manual_git.rst @@ -8,12 +8,11 @@ Using Git with the Sage Trac Server .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. @@ -167,9 +166,9 @@ repository, use these commands:: .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** After the - move, the Sage trac server git@trac.sagemath.org:sage.git will no longer be - available, but all branches will be available (in read-only mode) on + **Sage development moved to GitHub in February 2023.** After the move, the + Sage trac server git@trac.sagemath.org:sage.git no longer operates, but all + branches are available (in read-only mode) on https://github.com/sagemath/sagetrac-mirror.git. Instead of ``trac`` you can use any other name you want, of course. diff --git a/src/doc/en/developer/reviewer_checklist.rst b/src/doc/en/developer/reviewer_checklist.rst index 3ddc6b94f96..2f352b1dbb3 100644 --- a/src/doc/en/developer/reviewer_checklist.rst +++ b/src/doc/en/developer/reviewer_checklist.rst @@ -8,12 +8,11 @@ The reviewer's check list .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. diff --git a/src/doc/en/developer/trac.rst b/src/doc/en/developer/trac.rst index a584a61284f..74142dba417 100644 --- a/src/doc/en/developer/trac.rst +++ b/src/doc/en/developer/trac.rst @@ -8,12 +8,11 @@ The Sage Trac Server .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. @@ -46,8 +45,8 @@ the :trac:`Sage trac timeline `. .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** - All functions of our Trac server will be taken over by our main repository, + **Sage development moved to GitHub in February 2023.** + All functions of our Trac server were taken over by our main repository, https://github.com/sagemath/sage. @@ -354,10 +353,8 @@ other tests that run on GitHub Actions. .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** - After the move, the patch buildbot will no longer be available; the three - workflows above are considered a full replacement. If you miss any features - of the patch buildbot, please report this in :trac:`33457`. + **Sage development moved to GitHub in February 2023.** + After the move, the patch buildbot no longer operates. The following are some other relevant issues: diff --git a/src/doc/en/developer/walk_through.rst b/src/doc/en/developer/walk_through.rst index 74f0fd514f0..eb1620aea7c 100644 --- a/src/doc/en/developer/walk_through.rst +++ b/src/doc/en/developer/walk_through.rst @@ -8,12 +8,11 @@ Sage Development Process .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. @@ -124,9 +123,8 @@ actually takes place. .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** - After the move, https://github.com/sagemath/sage.git will be the - primary repository. + **Sage development moved to GitHub in February 2023.** + Now https://github.com/sagemath/sage.git is the primary repository. .. _section-walkthrough-branch: diff --git a/src/doc/en/developer/workflows.rst b/src/doc/en/developer/workflows.rst index b4d00265ee2..e37c2fca267 100644 --- a/src/doc/en/developer/workflows.rst +++ b/src/doc/en/developer/workflows.rst @@ -8,12 +8,11 @@ Distributed Development .. WARNING:: - **Sage development is scheduled to move to GitHub in February 2023.** The exact - date will be announced in ``_. After - the transition, some parts of this guide (especially those related with `the - Sage Trac server `_) will become obsolete and be - updated according to the new workflow on GitHub. See our `transition guide from Trac to - GitHub + **Sage development moved to GitHub in February 2023.** After the transition, + some parts of this guide (especially those related with `the Sage Trac + server `_) became obsolete and need to be + updated according to the new workflow on GitHub. See our `transition guide + from Trac to GitHub `_ for the preliminary version of the workflow. From b04d96ace079a8aa863cfb50ff59b0f76bfbe520 Mon Sep 17 00:00:00 2001 From: Ralf Hemmecke Date: Wed, 12 Apr 2023 12:46:26 +0200 Subject: [PATCH 60/61] docfix: decimal --> binary --- src/sage/symbolic/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/symbolic/constants.py b/src/sage/symbolic/constants.py index b5b8fe7ca33..587b63e2dcb 100644 --- a/src/sage/symbolic/constants.py +++ b/src/sage/symbolic/constants.py @@ -74,7 +74,7 @@ We can obtain floating point approximations to each of these constants by coercing into the real field with given precision. For -example, to 200 decimal places we have the following:: +example, to 200 binary places we have the following:: sage: R = RealField(200); R Real Field with 200 bits of precision From 97b45d80a7cfd72ad59767b2b3d27bade24fab3d Mon Sep 17 00:00:00 2001 From: Release Manager Date: Fri, 14 Apr 2023 00:35:31 +0200 Subject: [PATCH 61/61] Updated SageMath version to 10.0.beta9 --- .zenodo.json | 8 ++++---- VERSION.txt | 2 +- build/pkgs/configure/checksums.ini | 6 +++--- build/pkgs/configure/package-version.txt | 2 +- build/pkgs/sage_conf/install-requires.txt | 2 +- build/pkgs/sage_docbuild/install-requires.txt | 2 +- build/pkgs/sage_setup/install-requires.txt | 2 +- build/pkgs/sage_sws2rst/install-requires.txt | 2 +- build/pkgs/sagelib/install-requires.txt | 2 +- build/pkgs/sagemath_categories/install-requires.txt | 2 +- build/pkgs/sagemath_environment/install-requires.txt | 2 +- build/pkgs/sagemath_objects/install-requires.txt | 2 +- build/pkgs/sagemath_repl/install-requires.txt | 2 +- pkgs/sage-conf/VERSION.txt | 2 +- pkgs/sage-conf_pypi/VERSION.txt | 2 +- pkgs/sage-docbuild/VERSION.txt | 2 +- pkgs/sage-setup/VERSION.txt | 2 +- pkgs/sage-sws2rst/VERSION.txt | 2 +- pkgs/sagemath-categories/VERSION.txt | 2 +- pkgs/sagemath-environment/VERSION.txt | 2 +- pkgs/sagemath-objects/VERSION.txt | 2 +- pkgs/sagemath-repl/VERSION.txt | 2 +- src/VERSION.txt | 2 +- src/bin/sage-version.sh | 6 +++--- src/sage/version.py | 6 +++--- 25 files changed, 34 insertions(+), 34 deletions(-) diff --git a/.zenodo.json b/.zenodo.json index 28217d5ff6d..f1b7e15a43c 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,10 +1,10 @@ { "description": "Mirror of the Sage https://sagemath.org/ source tree", "license": "other-open", - "title": "sagemath/sage: 10.0.beta8", - "version": "10.0.beta8", + "title": "sagemath/sage: 10.0.beta9", + "version": "10.0.beta9", "upload_type": "software", - "publication_date": "2023-04-06", + "publication_date": "2023-04-13", "creators": [ { "affiliation": "SageMath.org", @@ -15,7 +15,7 @@ "related_identifiers": [ { "scheme": "url", - "identifier": "https://github.com/sagemath/sage/tree/10.0.beta8", + "identifier": "https://github.com/sagemath/sage/tree/10.0.beta9", "relation": "isSupplementTo" }, { diff --git a/VERSION.txt b/VERSION.txt index 91d81a8ce5e..9b8dbc84f95 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -SageMath version 10.0.beta8, Release Date: 2023-04-06 +SageMath version 10.0.beta9, Release Date: 2023-04-13 diff --git a/build/pkgs/configure/checksums.ini b/build/pkgs/configure/checksums.ini index 298ecf1e690..bc2cda13bb3 100644 --- a/build/pkgs/configure/checksums.ini +++ b/build/pkgs/configure/checksums.ini @@ -1,4 +1,4 @@ tarball=configure-VERSION.tar.gz -sha1=f113335fac0d8e24b95a49720495b1bad9007bd8 -md5=d0aa15b1095f9b9875e295f0681c77be -cksum=3230658013 +sha1=f6d0d32c169cb4cde477914507629fcaf42072c6 +md5=61a5d766c8932eed5d9bb934362dc5b0 +cksum=1115161346 diff --git a/build/pkgs/configure/package-version.txt b/build/pkgs/configure/package-version.txt index 3be35fd861a..69dcfa19bd8 100644 --- a/build/pkgs/configure/package-version.txt +++ b/build/pkgs/configure/package-version.txt @@ -1 +1 @@ -7dcb4bbb0a54a13e346159ce7d900d964606c7db +081c09ff32996b9bdc92540b968c3a3d6b72cf83 diff --git a/build/pkgs/sage_conf/install-requires.txt b/build/pkgs/sage_conf/install-requires.txt index 2903b5bb1d0..df283887224 100644 --- a/build/pkgs/sage_conf/install-requires.txt +++ b/build/pkgs/sage_conf/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-conf ~= 10.0b8 +sage-conf ~= 10.0b9 diff --git a/build/pkgs/sage_docbuild/install-requires.txt b/build/pkgs/sage_docbuild/install-requires.txt index af0b61ba07d..a9caf5cd2fd 100644 --- a/build/pkgs/sage_docbuild/install-requires.txt +++ b/build/pkgs/sage_docbuild/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-docbuild ~= 10.0b8 +sage-docbuild ~= 10.0b9 diff --git a/build/pkgs/sage_setup/install-requires.txt b/build/pkgs/sage_setup/install-requires.txt index e10a06a693e..4d81494c933 100644 --- a/build/pkgs/sage_setup/install-requires.txt +++ b/build/pkgs/sage_setup/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-setup ~= 10.0b8 +sage-setup ~= 10.0b9 diff --git a/build/pkgs/sage_sws2rst/install-requires.txt b/build/pkgs/sage_sws2rst/install-requires.txt index a37e70c6032..75f8f4dbc5c 100644 --- a/build/pkgs/sage_sws2rst/install-requires.txt +++ b/build/pkgs/sage_sws2rst/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sage-sws2rst ~= 10.0b8 +sage-sws2rst ~= 10.0b9 diff --git a/build/pkgs/sagelib/install-requires.txt b/build/pkgs/sagelib/install-requires.txt index 937a8ea52d3..9a3cdbab4a3 100644 --- a/build/pkgs/sagelib/install-requires.txt +++ b/build/pkgs/sagelib/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagelib ~= 10.0b8 +sagelib ~= 10.0b9 diff --git a/build/pkgs/sagemath_categories/install-requires.txt b/build/pkgs/sagemath_categories/install-requires.txt index 935fbc776e0..5de6b8e7ab2 100644 --- a/build/pkgs/sagemath_categories/install-requires.txt +++ b/build/pkgs/sagemath_categories/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-categories ~= 10.0b8 +sagemath-categories ~= 10.0b9 diff --git a/build/pkgs/sagemath_environment/install-requires.txt b/build/pkgs/sagemath_environment/install-requires.txt index 5f6936d1010..9ef3c2cdf16 100644 --- a/build/pkgs/sagemath_environment/install-requires.txt +++ b/build/pkgs/sagemath_environment/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-environment ~= 10.0b8 +sagemath-environment ~= 10.0b9 diff --git a/build/pkgs/sagemath_objects/install-requires.txt b/build/pkgs/sagemath_objects/install-requires.txt index 2c4769d9c3a..b4d5c72a7e7 100644 --- a/build/pkgs/sagemath_objects/install-requires.txt +++ b/build/pkgs/sagemath_objects/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-objects ~= 10.0b8 +sagemath-objects ~= 10.0b9 diff --git a/build/pkgs/sagemath_repl/install-requires.txt b/build/pkgs/sagemath_repl/install-requires.txt index 0e53e35d63d..4c62e5e6f79 100644 --- a/build/pkgs/sagemath_repl/install-requires.txt +++ b/build/pkgs/sagemath_repl/install-requires.txt @@ -1,2 +1,2 @@ # This file is updated on every release by the sage-update-version script -sagemath-repl ~= 10.0b8 +sagemath-repl ~= 10.0b9 diff --git a/pkgs/sage-conf/VERSION.txt b/pkgs/sage-conf/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sage-conf/VERSION.txt +++ b/pkgs/sage-conf/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sage-conf_pypi/VERSION.txt b/pkgs/sage-conf_pypi/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sage-conf_pypi/VERSION.txt +++ b/pkgs/sage-conf_pypi/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sage-docbuild/VERSION.txt b/pkgs/sage-docbuild/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sage-docbuild/VERSION.txt +++ b/pkgs/sage-docbuild/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sage-setup/VERSION.txt b/pkgs/sage-setup/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sage-setup/VERSION.txt +++ b/pkgs/sage-setup/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sage-sws2rst/VERSION.txt b/pkgs/sage-sws2rst/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sage-sws2rst/VERSION.txt +++ b/pkgs/sage-sws2rst/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sagemath-categories/VERSION.txt b/pkgs/sagemath-categories/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sagemath-categories/VERSION.txt +++ b/pkgs/sagemath-categories/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sagemath-environment/VERSION.txt b/pkgs/sagemath-environment/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sagemath-environment/VERSION.txt +++ b/pkgs/sagemath-environment/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sagemath-objects/VERSION.txt b/pkgs/sagemath-objects/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sagemath-objects/VERSION.txt +++ b/pkgs/sagemath-objects/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/pkgs/sagemath-repl/VERSION.txt b/pkgs/sagemath-repl/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/pkgs/sagemath-repl/VERSION.txt +++ b/pkgs/sagemath-repl/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/src/VERSION.txt b/src/VERSION.txt index df74bb50e91..4bf2f1819bd 100644 --- a/src/VERSION.txt +++ b/src/VERSION.txt @@ -1 +1 @@ -10.0.beta8 +10.0.beta9 diff --git a/src/bin/sage-version.sh b/src/bin/sage-version.sh index 4b2a9e4f9bf..d34ed34a51d 100644 --- a/src/bin/sage-version.sh +++ b/src/bin/sage-version.sh @@ -4,6 +4,6 @@ # which stops "setup.py develop" from rewriting it as a Python file. : # This file is auto-generated by the sage-update-version script, do not edit! -SAGE_VERSION='10.0.beta8' -SAGE_RELEASE_DATE='2023-04-06' -SAGE_VERSION_BANNER='SageMath version 10.0.beta8, Release Date: 2023-04-06' +SAGE_VERSION='10.0.beta9' +SAGE_RELEASE_DATE='2023-04-13' +SAGE_VERSION_BANNER='SageMath version 10.0.beta9, Release Date: 2023-04-13' diff --git a/src/sage/version.py b/src/sage/version.py index 9c2111ea0f1..1fcf16916ed 100644 --- a/src/sage/version.py +++ b/src/sage/version.py @@ -1,5 +1,5 @@ # Sage version information for Python scripts # This file is auto-generated by the sage-update-version script, do not edit! -version = '10.0.beta8' -date = '2023-04-06' -banner = 'SageMath version 10.0.beta8, Release Date: 2023-04-06' +version = '10.0.beta9' +date = '2023-04-13' +banner = 'SageMath version 10.0.beta9, Release Date: 2023-04-13'