diff --git a/src/sage/rings/function_field/constructor.py b/src/sage/rings/function_field/constructor.py index fa5a31cb683..9472e9baf5a 100644 --- a/src/sage/rings/function_field/constructor.py +++ b/src/sage/rings/function_field/constructor.py @@ -171,9 +171,9 @@ def create_key(self, polynomial, names): """ if names is None: names = polynomial.variable_name() - if not isinstance(names,tuple): + if not isinstance(names, tuple): names = (names,) - return (polynomial,names,polynomial.base_ring()) + return (polynomial, names, polynomial.base_ring()) def create_object(self, version, key, **extra_args): """ @@ -197,7 +197,7 @@ def create_object(self, version, key, **extra_args): base_field = f.base_ring() if isinstance(base_field, function_field_rational.RationalFunctionField): k = base_field.constant_field() - if k.is_finite(): # then we are in positive characteristic + if k.is_finite(): # then we are in positive characteristic # irreducible and separable if f.is_irreducible() and not all(e % k.characteristic() == 0 for e in f.exponents()): # monic and integral diff --git a/src/sage/rings/function_field/derivations.py b/src/sage/rings/function_field/derivations.py index 32252d41eff..dc5c91c9553 100644 --- a/src/sage/rings/function_field/derivations.py +++ b/src/sage/rings/function_field/derivations.py @@ -54,7 +54,7 @@ class FunctionFieldDerivation(RingDerivationWithoutTwist): sage: d d/dx """ - def __init__(self, parent): + def __init__(self, parent) -> None: r""" Initialize a derivation. diff --git a/src/sage/rings/function_field/derivations_polymod.py b/src/sage/rings/function_field/derivations_polymod.py index 952d5813dd6..cf059ed8d53 100644 --- a/src/sage/rings/function_field/derivations_polymod.py +++ b/src/sage/rings/function_field/derivations_polymod.py @@ -39,7 +39,7 @@ class FunctionFieldDerivation_separable(FunctionFieldDerivation): sage: L.derivation() d/dx """ - def __init__(self, parent, d): + def __init__(self, parent, d) -> None: """ Initialize a derivation. @@ -164,7 +164,7 @@ def _lmul_(self, factor): class FunctionFieldDerivation_inseparable(FunctionFieldDerivation): - def __init__(self, parent, u=None): + def __init__(self, parent, u=None) -> None: r""" Initialize this derivation. @@ -286,7 +286,7 @@ class FunctionFieldHigherDerivation(Map): From: Rational function field in x over Finite Field of size 2 To: Rational function field in x over Finite Field of size 2 """ - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize. @@ -386,7 +386,7 @@ class RationalFunctionFieldHigherDerivation_global(FunctionFieldHigherDerivation sage: h(x^2, 2) 1 """ - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize. @@ -580,7 +580,7 @@ class FunctionFieldHigherDerivation_global(FunctionFieldHigherDerivation): ((x^7 + 1)/x^2)*y^2 + x^3*y """ - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize. @@ -826,7 +826,7 @@ class FunctionFieldHigherDerivation_char_zero(FunctionFieldHigherDerivation): sage: h(h(h(e,1),1),1) == 3*2*h(e,3) True """ - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize. diff --git a/src/sage/rings/function_field/derivations_rational.py b/src/sage/rings/function_field/derivations_rational.py index 777f16d3e08..73bb7965a70 100644 --- a/src/sage/rings/function_field/derivations_rational.py +++ b/src/sage/rings/function_field/derivations_rational.py @@ -31,7 +31,7 @@ class FunctionFieldDerivation_rational(FunctionFieldDerivation): sage: K.derivation() d/dx """ - def __init__(self, parent, u=None): + def __init__(self, parent, u=None) -> None: """ Initialize a derivation. diff --git a/src/sage/rings/function_field/differential.py b/src/sage/rings/function_field/differential.py index 8f841180532..d85e85ca105 100644 --- a/src/sage/rings/function_field/differential.py +++ b/src/sage/rings/function_field/differential.py @@ -98,7 +98,7 @@ class FunctionFieldDifferential(ModuleElement): sage: y.differential() # needs sage.rings.function_field ((21/4*x/(x^7 + 27/4))*y^2 + ((3/2*x^7 + 9/4)/(x^8 + 27/4*x))*y + 7/2*x^4/(x^7 + 27/4)) d(x) """ - def __init__(self, parent, f, t=None): + def __init__(self, parent, f, t=None) -> None: """ Initialize the differential `fdt`. @@ -116,7 +116,7 @@ def __init__(self, parent, f, t=None): self._f = f - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the differential. @@ -132,7 +132,7 @@ def _repr_(self): sage: f.differential() (-1/x^2) d(x) """ - if self._f.is_zero(): # zero differential + if self._f.is_zero(): # zero differential return '0' r = 'd({})'.format(self.parent()._gen_base_differential) @@ -142,7 +142,7 @@ def _repr_(self): return '({})'.format(self._f) + ' ' + r - def _latex_(self): + def _latex_(self) -> str: r""" Return a latex representation of the differential. @@ -155,7 +155,7 @@ def _latex_(self): sage: latex(w) # needs sage.rings.function_field \left( x y^{2} + \frac{1}{x} y \right)\, dx """ - if self._f.is_zero(): # zero differential + if self._f.is_zero(): # zero differential return '0' r = 'd{}'.format(self.parent()._gen_base_differential) @@ -165,7 +165,7 @@ def _latex_(self): return '\\left(' + latex(self._f) + '\\right)\\,' + r - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of ``self``. @@ -396,7 +396,7 @@ def divisor(self): """ F = self.parent().function_field() x = F.base_field().gen() - return self._f.divisor() + (-2)*F(x).divisor_of_poles() + F.different() + return self._f.divisor() + (-2) * F(x).divisor_of_poles() + F.different() def valuation(self, place): """ @@ -416,7 +416,7 @@ def valuation(self, place): """ F = self.parent().function_field() x = F.base_field().gen() - return (self._f.valuation(place) + 2*min(F(x).valuation(place), 0) + return (self._f.valuation(place) + 2 * min(F(x).valuation(place), 0) + F.different().valuation(place)) def residue(self, place): @@ -471,7 +471,7 @@ def residue(self, place): sage: sum([QQ(w.residue(p)) for p in d.support()]) 0 """ - R,fr_R,to_R = place._residue_field() + R, fr_R, to_R = place._residue_field() # Step 1: compute f such that fds equals this differential. s = place.local_uniformizer() @@ -485,10 +485,10 @@ def residue(self, place): return R.zero() else: g_shifted = g * s**(-r) - c = g_shifted.higher_derivative(-r-1, s) + c = g_shifted.higher_derivative(-r - 1, s) return to_R(c) - def monomial_coefficients(self, copy=True): + def monomial_coefficients(self, copy: bool = True): """ Return a dictionary whose keys are indices of basis elements in the support of ``self`` and whose values are the corresponding coefficients. @@ -600,7 +600,7 @@ class DifferentialsSpace(UniqueRepresentation, Parent): """ Element = FunctionFieldDifferential - def __init__(self, field, category=None): + def __init__(self, field, category=None) -> None: """ Initialize the space of differentials of the function field. @@ -627,7 +627,7 @@ def __init__(self, field, category=None): self._gen_base_differential = F.gen() self._gen_derivative_inv = ~der(F.gen()) # used for fast computation - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the space of differentials. @@ -770,7 +770,7 @@ class DifferentialsSpaceInclusion(Morphism): To: Space of differentials of Function field in y defined by y^2 - x*y + 4*x^3 """ - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of this morphism. @@ -790,7 +790,7 @@ def _repr_(self): s += "\n To: {}".format(self.codomain()) return s - def is_injective(self): + def is_injective(self) -> bool: """ Return ``True``, since the inclusion morphism is injective. @@ -849,4 +849,4 @@ def _call_(self, v): """ domain = self.domain() F = self.codomain().function_field() - return F(v._f)*F(domain._gen_base_differential).differential() + return F(v._f) * F(domain._gen_base_differential).differential() diff --git a/src/sage/rings/function_field/divisor.py b/src/sage/rings/function_field/divisor.py index 94f3ff2bce3..1cdd589dd58 100644 --- a/src/sage/rings/function_field/divisor.py +++ b/src/sage/rings/function_field/divisor.py @@ -147,7 +147,7 @@ class FunctionFieldDivisor(ModuleElement): + 3*Place (x, (1/(x^3 + x^2 + x))*y^2) - 6*Place (x + 1, y + 1) """ - def __init__(self, parent, data): + def __init__(self, parent, data) -> None: """ Initialize. @@ -161,7 +161,7 @@ def __init__(self, parent, data): ModuleElement.__init__(self, parent) self._data = data - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of the divisor. @@ -214,8 +214,8 @@ def _format(self, formatter, mul, cr): if m == 1: r = formatter(p) elif m == -1: - r = '- ' + formatter(p) # seems more readable than `-` - else: # nonzero + r = '- ' + formatter(p) # seems more readable than `-` + else: # nonzero r = formatter(m) + mul + formatter(p) for p in places: m = self._data[p] @@ -229,7 +229,7 @@ def _format(self, formatter, mul, cr): r += cr + minus + formatter(-m) + mul + formatter(p) return r - def _repr_(self, split=True): + def _repr_(self, split: bool = True) -> str: """ Return a string representation of the divisor. @@ -249,7 +249,7 @@ def _repr_(self, split=True): """ return self._format(repr, '*', '\n' if split else '') - def _latex_(self): + def _latex_(self) -> str: r""" Return the LaTeX representation of the divisor. @@ -355,7 +355,7 @@ def _add_(self, other): True """ divisor_group = self.parent() - places = set(self.support()).union( set(other.support())) + places = set(self.support()).union(set(other.support())) data = {} for place in places: m = self.multiplicity(place) + other.multiplicity(place) @@ -583,7 +583,7 @@ def basis_function_space(self): sage: D.basis_function_space() [x/(x + 3), 1/(x + 3)] """ - basis,_ = self._function_space() + basis, _ = self._function_space() return basis @cached_method @@ -624,8 +624,8 @@ def to_V(f): from sage.rings.function_field.maps import ( FunctionFieldLinearMap, FunctionFieldLinearMapSection) - mor_from_V = FunctionFieldLinearMap(Hom(V,F), from_V) - mor_to_V = FunctionFieldLinearMapSection(Hom(F,V), to_V) + mor_from_V = FunctionFieldLinearMap(Hom(V, F), from_V) + mor_to_V = FunctionFieldLinearMapSection(Hom(F, V), to_V) return V, mor_from_V, mor_to_V @@ -728,8 +728,8 @@ def to_V(w): from sage.rings.function_field.maps import ( FunctionFieldLinearMap, FunctionFieldLinearMapSection) - mor_from_V = FunctionFieldLinearMap(Hom(V,W), from_V) - mor_to_V = FunctionFieldLinearMapSection(Hom(W,V), to_V) + mor_from_V = FunctionFieldLinearMap(Hom(V, W), from_V) + mor_to_V = FunctionFieldLinearMapSection(Hom(W, V), to_V) return V, mor_from_V, mor_to_V @@ -804,16 +804,16 @@ def _basis(self): # Step 2: construct matrix M of rational functions in x such that # M * B == C where B = [b1,b1,...,bn], C =[v1,v2,...,vn] - V,fr,to = F.free_module(map=True) + V, fr, to = F.free_module(map=True) B = matrix([to(b) for b in J.gens_over_base()]) C = matrix([to(v) for v in I.gens_over_base()]) M = C * B.inverse() # Step 2.5: get the denominator d of M and set mat = d * M den = lcm([e.denominator() for e in M.list()]) - R = den.parent() # polynomial ring + R = den.parent() # polynomial ring one = R.one() - mat = matrix(R, n, [e.numerator() for e in (den*M).list()]) + mat = matrix(R, n, [e.numerator() for e in (den * M).list()]) gens = list(I.gens_over_base()) # Step 3: transform mat to a weak Popov form, together with gens @@ -825,13 +825,13 @@ def _basis(self): bestp = -1 best = -1 for c in range(n): - d = mat[i,c].degree() + d = mat[i, c].degree() if d >= best: bestp = c best = d if best >= 0: - pivot_row[bestp].append((i,best)) + pivot_row[bestp].append((i, best)) if len(pivot_row[bestp]) > 1: conflicts.append(bestp) @@ -839,31 +839,31 @@ def _basis(self): while conflicts: c = conflicts.pop() row = pivot_row[c] - i,ideg = row.pop() - j,jdeg = row.pop() + i, ideg = row.pop() + j, jdeg = row.pop() if jdeg > ideg: - i,j = j,i - ideg,jdeg = jdeg,ideg + i, j = j, i + ideg, jdeg = jdeg, ideg - coeff = - mat[i,c].lc() / mat[j,c].lc() + coeff = - mat[i, c].lc() / mat[j, c].lc() s = coeff * one.shift(ideg - jdeg) mat.add_multiple_of_row(i, j, s) gens[i] += s * gens[j] - row.append((j,jdeg)) + row.append((j, jdeg)) bestp = -1 best = -1 for c in range(n): - d = mat[i,c].degree() + d = mat[i, c].degree() if d >= best: bestp = c best = d if best >= 0: - pivot_row[bestp].append((i,best)) + pivot_row[bestp].append((i, best)) if len(pivot_row[bestp]) > 1: conflicts.append(bestp) @@ -920,9 +920,9 @@ def pivot(v): for i in range(n): e = v[i] if e != 0: - return (i,e.numerator().degree() - e.denominator().degree()) + return (i, e.numerator().degree() - e.denominator().degree()) - def greater(v, w): # v and w are not equal + def greater(v, w): # v and w are not equal return v[0] < w[0] or v[0] == w[0] and v[1] > w[1] # collate rows by their pivot position @@ -942,7 +942,7 @@ def greater(v, w): # v and w are not equal head = pivots[0] for p in pivots[1:]: - if not greater(head,p): + if not greater(head, p): head = p rows = pivot_rows[head] @@ -953,7 +953,7 @@ def greater(v, w): # v and w are not equal for i in rows[1:]: vi = vbasis[i][head[0]] ci = vi.numerator().lc() / vi.denominator().lc() - vbasis[i] -= ci/cr * vbasis[r] + vbasis[i] -= ci / cr * vbasis[r] p = pivot(vbasis[i]) if p in pivot_rows: pivot_rows[p].append(i) @@ -968,11 +968,11 @@ def coordinates(f): coords = [k(0) for i in range(m)] while v != 0: p = pivot(v) - ind = npivots.index(p) # an exception implies x is not in the domain + ind = npivots.index(p) # an exception implies x is not in the domain w = nbasis[ind] cv = v[p[0]].numerator().lc() / v[p[0]].denominator().lc() cw = w[p[0]].numerator().lc() / w[p[0]].denominator().lc() - c = cv/cw + c = cv / cw v -= c * w coords[ind] = c return coords @@ -999,7 +999,7 @@ class DivisorGroup(UniqueRepresentation, Parent): """ Element = FunctionFieldDivisor - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize. @@ -1012,9 +1012,9 @@ def __init__(self, field): """ Parent.__init__(self, base=IntegerRing(), category=CommutativeAdditiveGroups()) - self._field = field # function field + self._field = field # function field - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the group of divisors. @@ -1063,7 +1063,7 @@ def _coerce_map_from_(self, S): """ if isinstance(S, PlaceSet): func = lambda place: prime_divisor(self._field, place) - return SetMorphism(Hom(S,self), func) + return SetMorphism(Hom(S, self), func) def function_field(self): """ @@ -1097,10 +1097,10 @@ def _an_element_(self): N = 10 d = 1 places = [] - while len(places) <= N: # collect at least N places + while len(places) <= N: # collect at least N places places += self._field.places(d) d += 1 e = self.element_class(self, {}) - for i in range(random.randint(0,N)): + for i in range(random.randint(0, N)): e += random.choice(places) return e diff --git a/src/sage/rings/function_field/drinfeld_modules/action.py b/src/sage/rings/function_field/drinfeld_modules/action.py index fb6ea191125..9bb50a00a18 100644 --- a/src/sage/rings/function_field/drinfeld_modules/action.py +++ b/src/sage/rings/function_field/drinfeld_modules/action.py @@ -81,7 +81,7 @@ class DrinfeldModuleAction(Action): True """ - def __init__(self, drinfeld_module): + def __init__(self, drinfeld_module) -> None: """ Initialize ``self``. @@ -140,7 +140,7 @@ def _act_(self, pol, x): raise TypeError('second input must be in the field acted upon') return self._drinfeld_module(pol)(x) - def _latex_(self): + def _latex_(self) -> str: r""" Return a LaTeX representation of the action. @@ -160,7 +160,7 @@ def _latex_(self): f'{latex(self._base)}\\text{{{{ }}' \ f'induced{{ }}by{{ }}}}{latex(self._drinfeld_module)}' - def _repr_(self): + def _repr_(self) -> str: r""" Return a string representation of the action. diff --git a/src/sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py index ac3c1367cac..b9fc6416be8 100644 --- a/src/sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/charzero_drinfeld_module.py @@ -149,7 +149,7 @@ def _compute_coefficient_exp(self, k): c = self._base.zero() for i in range(k): j = k - i - c += self._compute_coefficient_exp(i)*self._compute_coefficient_log(j)**(q**i) + c += self._compute_coefficient_exp(i) * self._compute_coefficient_log(j)**(q**i) return -c def exponential(self, prec=Infinity, name='z'): @@ -242,7 +242,7 @@ def coeff_exp(k): L = LazyPowerSeriesRing(self._base, name) return L(coeff_exp, valuation=1) L = PowerSeriesRing(self._base, name, default_prec=prec) - return L([0] + [coeff_exp(i) for i in range(1,prec)], prec=prec) + return L([0] + [coeff_exp(i) for i in range(1, prec)], prec=prec) @cached_method def _compute_coefficient_log(self, k): @@ -274,8 +274,8 @@ def _compute_coefficient_log(self, k): for i in range(k): j = k - i if j < r + 1: - c += self._compute_coefficient_log(i)*self._gen[j]**(q**i) - return c/(T - T**(q**k)) + c += self._compute_coefficient_log(i) * self._gen[j]**(q**i) + return c / (T - T**(q**k)) def logarithm(self, prec=Infinity, name='z'): r""" @@ -391,7 +391,7 @@ def _compute_goss_polynomial(self, n, q, poly_ring, X): pol += self._compute_coefficient_exp(i) * self._compute_goss_polynomial(n - m, q, poly_ring, X) m *= q i += 1 - return X*(self._compute_goss_polynomial(n - 1, q, poly_ring, X) + pol) + return X * (self._compute_goss_polynomial(n - 1, q, poly_ring, X) + pol) def goss_polynomial(self, n, var='X'): r""" @@ -600,7 +600,7 @@ def class_polynomial(self): # We compute the bound s gs = self.coefficients_in_function_ring(sparse=False) - s = max(gs[i].degree() // (q**i - 1) for i in range(1, r+1)) + s = max(gs[i].degree() // (q**i - 1) for i in range(1, r + 1)) if s == 0: return A.one() @@ -609,9 +609,9 @@ def class_polynomial(self): # (for the standard structure of A-module!) M = matrix(Fq, s) qk = 1 - for k in range(r+1): + for k in range(r + 1): for i in range(s): - e = (i+1)*qk + e = (i + 1) * qk for j in range(s): e -= 1 if e < 0: @@ -626,10 +626,10 @@ def class_polynomial(self): # the Fq-vector space generated by the phi_T^i(T^(-s+1)) # for i varying in NN. v = vector(Fq, s) - v[s-1] = 1 + v[s - 1] = 1 vs = [v] - for i in range(s-1): - v = v*M + for i in range(s - 1): + v = v * M vs.append(v) V = matrix(vs) V.echelonize() @@ -643,7 +643,7 @@ def class_polynomial(self): while ip < dim and j == pivots[ip]: j += 1 ip += 1 - V[i,j] = 1 + V[i, j] = 1 N = (V * M * ~V).submatrix(dim, dim) # The class module is now H where the action of T diff --git a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py index ed19c6064d9..b702997999e 100644 --- a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py @@ -621,7 +621,7 @@ def __classcall_private__(cls, function_ring, gen, name='τ'): return DrinfeldModule_charzero(gen, category) return cls.__classcall__(cls, gen, category) - def __init__(self, gen, category): + def __init__(self, gen, category) -> None: """ Initialize ``self``. @@ -750,7 +750,7 @@ def _Hom_(self, other, category): from sage.rings.function_field.drinfeld_modules.homset import DrinfeldModuleHomset return DrinfeldModuleHomset(self, other, category) - def _latex_(self): + def _latex_(self) -> str: r""" Return a LaTeX representation of the Drinfeld module. @@ -780,7 +780,7 @@ def _latex_(self): return f'\\phi: {latex(self._function_ring.gen())} \\mapsto ' \ f'{latex(self._gen)}' - def _repr_(self): + def _repr_(self) -> str: r""" Return a string representation of this Drinfeld module. @@ -797,7 +797,7 @@ def _repr_(self): return f'Drinfeld module defined by {self._function_ring.gen()} ' \ f'|--> {self._gen}' - def _test_category(self, **options): + def _test_category(self, **options) -> None: """ Run generic tests on the method :meth:`.category`. @@ -824,7 +824,7 @@ def _test_category(self, **options): tester.assertTrue(isinstance(self, category.parent_class), _LazyString("category of %s improperly initialized", (self,), {})) - def __hash__(self): + def __hash__(self) -> int: r""" Return a hash of ``self``. @@ -1000,7 +1000,7 @@ def basic_j_invariant_parameters(self, coeff_indices=None, nonzero=False): raise TypeError('coefficients indices must be integers') if max(coeff_indices) >= r or min(coeff_indices) <= 0: raise ValueError(f'indices must be > 0 and < {r}') - if not all(coeff_indices[i] < coeff_indices[i+1] for i in + if not all(coeff_indices[i] < coeff_indices[i + 1] for i in range(len(coeff_indices) - 1)): raise ValueError('indices must be distinct and sorted') if nonzero: @@ -1022,7 +1022,7 @@ def basic_j_invariant_parameters(self, coeff_indices=None, nonzero=False): # Create inequalities of the form # delta_i <= (q^r - 1)/(q^{gcd(i,r)} - 1) upper_bounds = [Integer((q**r - 1) / (q**(gcd(i, r)) - 1))]\ - + [0]*(len(coeff_indices) + 1) + + [0] * (len(coeff_indices) + 1) upper_bounds[idx + 1] = -1 inequalities.extend((lower_bounds, upper_bounds)) equation.append(1 - q**r) @@ -1270,7 +1270,7 @@ def height(self): except NotImplementedError: raise NotImplementedError('height not implemented in this case') - def is_isomorphic(self, other, absolutely=False): + def is_isomorphic(self, other, absolutely=False) -> bool: r""" Return ``True`` if this Drinfeld module is isomorphic to ``other``; return ``False`` otherwise. @@ -1396,7 +1396,7 @@ def is_isomorphic(self, other, absolutely=False): B = other.gen() e = Integer(0) ue = self._base(1) - for i in range(1, r+1): + for i in range(1, r + 1): ai = A[i] bi = B[i] if ai == 0 and bi == 0: @@ -1407,8 +1407,8 @@ def is_isomorphic(self, other, absolutely=False): # u^e = ue # u^(q^i - 1) = ai/bi e, s, t = e.xgcd(q**i - 1) - ue = ue**s * (ai/bi)**t - for i in range(1, r+1): + ue = ue**s * (ai / bi)**t + for i in range(1, r + 1): if A[i]: f = (q**i - 1) // e if A[i] != B[i] * ue**f: @@ -1666,14 +1666,14 @@ def j_invariant(self, parameter=None, check=True): if r != 2: raise TypeError("parameter must not be None " "if the rank is greater than 2") - return self._gen[1]**(q+1)/self._gen[2] + return self._gen[1]**(q + 1) / self._gen[2] if parameter in ZZ: parameter = ZZ(parameter) if parameter <= 0 or parameter >= r: raise ValueError("integer parameter must be >= 1 and < the " f"rank (={r})") - dk = Integer((q**r - 1)/(q**gcd(parameter, r) - 1)) - dr = Integer((q**parameter - 1)/(q**gcd(parameter, r) - 1)) + dk = Integer((q**r - 1) / (q**gcd(parameter, r) - 1)) + dr = Integer((q**parameter - 1) / (q**gcd(parameter, r) - 1)) return self._gen[parameter]**dk / self._gen[-1]**dr elif isinstance(parameter, (tuple, list)): if len(parameter) != 2: @@ -1696,8 +1696,8 @@ def j_invariant(self, parameter=None, check=True): # d_1 (q - 1) + ... + d_{r-1} (q^{r-1} - 1) # = d_r (q^r - 1) if check: - right = parameter_1[-1]*(q**r - 1) - left = sum(parameter_1[i]*(q**(parameter_0[i]) - 1) for i in + right = parameter_1[-1] * (q**r - 1) + left = sum(parameter_1[i] * (q**(parameter_0[i]) - 1) for i in range(len(parameter_0))) if left != right: raise ValueError("parameter does not satisfy the " @@ -2120,4 +2120,4 @@ def frobenius_relative(self, n=1): d = self.characteristic().degree() if d < 0: raise ValueError("the characteristic of the Drinfeld module must be nonzero") - return self.hom(tau**(n*d)) + return self.hom(tau**(n * d)) diff --git a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py index c6a1f2ca08b..8a0f9234721 100644 --- a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py @@ -124,7 +124,7 @@ class DrinfeldModule_finite(DrinfeldModule): True """ - def __init__(self, gen, category): + def __init__(self, gen, category) -> None: """ Initialize ``self``. @@ -201,15 +201,15 @@ def _frobenius_matrix_crystalline(self): drin_coeffs = self.coefficients(sparse=False) poly_K = PolynomialRing(K, name=str(A.gen())) matrix_poly_K = MatrixSpace(poly_K, r, r) - mu_coeffs = ((poly_K.gen() - drin_coeffs[0])**(n+1)) \ + mu_coeffs = ((poly_K.gen() - drin_coeffs[0])**(n + 1)) \ .coefficients(sparse=False) def companion(order): # + [1] is required to satisfy formatting for companion matrix - M = matrix_poly_K(companion_matrix([(drin_coeffs[i]/drin_coeffs[r]) - .frobenius(qdeg*order) + M = matrix_poly_K(companion_matrix([(drin_coeffs[i] / drin_coeffs[r]) + .frobenius(qdeg * order) for i in range(r)] + [1], format='top')) - M[0, r-1] += poly_K.gen() / drin_coeffs[r].frobenius(qdeg*order) + M[0, r - 1] += poly_K.gen() / drin_coeffs[r].frobenius(qdeg * order) return M companion_initial = prod([companion(i) for i in range(nrem, 0, -1)]) @@ -218,12 +218,12 @@ def companion(order): reduced_companions = [] for k in range(nquo - 1, 0, -1): M = Matrix(poly_K, r, r) - modulus = poly_K([c.frobenius(qdeg*(-k*nstar % n)) + modulus = poly_K([c.frobenius(qdeg * (-k * nstar % n)) for c in mu_coeffs]) for i, row in enumerate(companion_step): for j, entry in enumerate(row): reduction = entry % modulus - M[i, j] = poly_K([c.frobenius(qdeg*(k*nstar)) + M[i, j] = poly_K([c.frobenius(qdeg * (k * nstar)) for c in reduction .coefficients(sparse=False)]) reduced_companions.append(M) @@ -491,9 +491,9 @@ def _frobenius_charpoly_CSA(self): n = self._base_degree_over_constants r = self.rank() lc = chi[0][r] - coeffs = [A([K(chi[i][j]/lc).in_base() - for i in range((r-j)*n // r + 1)]) - for j in range(r+1)] + coeffs = [A([K(chi[i][j] / lc).in_base() + for i in range((r - j) * n // r + 1)]) + for j in range(r + 1)] return PolynomialRing(A, name='X')(coeffs) def _frobenius_charpoly_crystalline(self): @@ -613,10 +613,10 @@ def _frobenius_charpoly_gekeler(self): # linear system. The system is prepared such that the solution # vector has the form [a_0, a_1, ... a_{r-1}]^T with each a_i # corresponding to a block of length (n*(r - i))//r + 1 - shifts = [(n*(r - i))//r + 1 for i in range(r)] - rows, cols = n*r + 1, sum(shifts) + shifts = [(n * (r - i)) // r + 1 for i in range(r)] + rows, cols = n * r + 1, sum(shifts) block_shifts = [0] - for i in range(r-1): + for i in range(r - 1): block_shifts.append(block_shifts[-1] + shifts[i]) # Compute the images \phi_T^i for i = 0 .. n. gen_powers = [self(A.gen()**i).coefficients(sparse=False) @@ -626,7 +626,7 @@ def _frobenius_charpoly_gekeler(self): for j in range(r): for k in range(shifts[j]): for i in range(len(gen_powers[k])): - sys[i + n*j, block_shifts[j] + k] = gen_powers[k][i] + sys[i + n * j, block_shifts[j] + k] = gen_powers[k][i] if sys.right_nullity() != 0: raise NotImplementedError("'gekeler' algorithm failed") sol = list(sys.solve_right(vec)) @@ -752,9 +752,9 @@ def frobenius_norm(self): r = self.rank() p = self.characteristic() norm = K(self.coefficients()[-1]).norm() - self._frobenius_norm = (-1) ** (n*r - n - r) \ + self._frobenius_norm = (-1) ** (n * r - n - r) \ * norm**(-1) \ - * p ** (n//p.degree()) + * p ** (n // p.degree()) return self._frobenius_norm def frobenius_trace(self, algorithm=None): @@ -998,16 +998,16 @@ def invert(self, ore_pol): # Write the system and solve it k = deg // r A = self._function_ring - mat_rows = [[E.zero() for _ in range(k+1)] for _ in range(k+1)] + mat_rows = [[E.zero() for _ in range(k + 1)] for _ in range(k + 1)] mat_rows[0][0] = E.one() phiT = self.gen() phiTi = self.ore_polring().one() - for i in range(1, k+1): + for i in range(1, k + 1): phiTi *= phiT - for j in range(i+1): - mat_rows[j][i] = phiTi[r*j] + for j in range(i + 1): + mat_rows[j][i] = phiTi[r * j] mat = Matrix(mat_rows) - vec = vector([ore_pol[r*j] for j in range(k+1)]) + vec = vector([ore_pol[r * j] for j in range(k + 1)]) coeffs_K = list(mat.inverse() * vec) # Cast the coefficients to Fq try: diff --git a/src/sage/rings/function_field/drinfeld_modules/homset.py b/src/sage/rings/function_field/drinfeld_modules/homset.py index 4b5afb487c5..05e5cb17667 100644 --- a/src/sage/rings/function_field/drinfeld_modules/homset.py +++ b/src/sage/rings/function_field/drinfeld_modules/homset.py @@ -72,7 +72,7 @@ class DrinfeldModuleMorphismAction(Action): To: Drinfeld module defined by T |--> (2*z^2 + 4*z + 4)*τ^2 + (z^2 + 4*z + 3)*τ + z Defn: τ + 2 """ - def __init__(self, A, H, is_left, op): + def __init__(self, A, H, is_left, op) -> None: r""" Initialize this action. @@ -241,7 +241,7 @@ class DrinfeldModuleHomset(Homset): """ Element = DrinfeldModuleMorphism - def __init__(self, X, Y, category=None, check=True): + def __init__(self, X, Y, category=None, check=True) -> None: """ Initialize ``self``. @@ -289,7 +289,7 @@ def __init__(self, X, Y, category=None, check=True): self.register_coercion(A) self._basis = None - def _latex_(self): + def _latex_(self) -> str: r""" Return a LaTeX representation of the homset. @@ -309,7 +309,7 @@ def _latex_(self): f'\\text{{{{ }}to{{ }}(gen){{ }}}}'\ f'{latex(self.codomain().gen())}' - def _repr_(self): + def _repr_(self) -> str: r""" Return a string representation of the homset. @@ -327,7 +327,7 @@ def _repr_(self): return f'Set of Drinfeld module morphisms from (gen) '\ f'{self.domain().gen()} to (gen) {self.codomain().gen()}' - def __contains__(self, x): + def __contains__(self, x) -> bool: r""" Return ``True`` if the input defines a morphism in the homset. @@ -586,8 +586,8 @@ def _A_basis(self): # We compute the tau^i in M(phi) lc = ~(phiT[r]) - xT = [-AF(lc*phiT[i]) for i in range(r)] - xT[0] += lc*TF + xT = [-AF(lc * phiT[i]) for i in range(r)] + xT[0] += lc * TF taus = [] for i in range(r): taui = r * [AF.zero()] @@ -595,14 +595,14 @@ def _A_basis(self): taus.append(taui) for i in range(r): s = FrobT(taui[-1]) - taui = [s*xT[0]] + [FrobT(taui[j-1]) + s*xT[j] for j in range(1,r)] + taui = [s * xT[0]] + [FrobT(taui[j - 1]) + s * xT[j] for j in range(1, r)] taus.append(taui) # We precompute the Frob^k(z^i) z = F(Fo.gen()) zs = [] zq = z - for k in range(r+1): + for k in range(r + 1): x = F.one() for i in range(d): zs.append(x) @@ -617,17 +617,17 @@ def _A_basis(self): # sum(g_k*tau^k(x), k=0..r) - T*x # = sum(g_k*Frob^k(z^i)*tau^(k+j), k=0..r) - T*x row = r * [AF.zero()] - for k in range(r+1): - s = psiT[k] * zs[k*d + i] + for k in range(r + 1): + s = psiT[k] * zs[k * d + i] for l in range(r): - row[l] += s*taus[k+j][l] + row[l] += s * taus[k + j][l] row[j] -= zs[i] * TF # We write it in the A-basis rowA = [] for c in row: c0 = Fo(c[0]).vector() c1 = Fo(c[1]).vector() - rowA += [c0[k] + T*c1[k] for k in range(d)] + rowA += [c0[k] + T * c1[k] for k in range(d)] rows.append(rowA) M = Matrix(rows) @@ -642,7 +642,7 @@ def _A_basis(self): u = S.zero() for i in range(d): for j in range(r): - a = ker[row, i*r + j] + a = ker[row, i * r + j] u += zs[i] * t**j * sum(a[k] * phiT**k for k in range(a.degree() + 1)) isogenies.append(self(u)) @@ -711,32 +711,32 @@ def _Fq_basis(self, degree): # the Frobenius of K/Fq frob_matrices = [identity_matrix(Fq, n)] + [Matrix(Fq, n) for _ in range(d + r)] for i, elem in enumerate(K_basis): - for k in range(1, d+r+1): + for k in range(1, d + r + 1): elem = elem ** q v = elem.vector() for j in range(n): - frob_matrices[k][i,j] = v[j] + frob_matrices[k][i, j] = v[j] # We write the linear system and solve it - sys = Matrix(Fq, (d + r + 1)*n, (d + 1)*n) + sys = Matrix(Fq, (d + r + 1) * n, (d + 1) * n) for k in range(0, d + r + 1): for i in range(max(0, k - r), min(k, d) + 1): # We represent multiplication and Frobenius # as operators acting on K as a vector space # over Fq - oper = K(phiT[k-i] ** (q**i)).matrix() \ - - frob_matrices[k-i] * K(psiT[k-i]).matrix() + oper = K(phiT[k - i] ** (q**i)).matrix() \ + - frob_matrices[k - i] * K(psiT[k - i]).matrix() for j in range(n): for l in range(n): - sys[k*n + j, i*n + l] = oper[l, j] + sys[k * n + j, i * n + l] = oper[l, j] sol = sys.right_kernel().basis() # Reconstruct the Ore polynomial from the coefficients basis = [] tau = domain.ore_polring().gen() for basis_elem in sol: - ore_poly = sum([sum([K_basis[j].backend() * basis_elem[i*n + j] - for j in range(n)])*(tau**i) + ore_poly = sum([sum([K_basis[j].backend() * basis_elem[i * n + j] + for j in range(n)]) * (tau**i) for i in range(d + 1)]) basis.append(self(ore_poly)) @@ -935,7 +935,7 @@ def basis_over_frobenius(self): # morphisms from domain to codomain. for j in range(n): for k in range(n): - for i in range(r+1): + for i in range(r + 1): # Coefficients of tau^{i + k} coming from the # relation defining morphisms of Drinfeld modules # These are elements of K, expanded in terms of @@ -943,8 +943,8 @@ def basis_over_frobenius(self): poly = K(phiT[i]**(q**k) * K_basis[j] - psiT[i] * K_basis[j]**(q**i)).polynomial() deg = (i + k) // n - row = n * (i + k - n*deg) - col = k*n + j + row = n * (i + k - n * deg) + col = k * n + j for b in range(poly.degree() + 1): sys[row + b, col] += poly[b] * taun**deg @@ -957,7 +957,7 @@ def basis_over_frobenius(self): basis_poly = 0 for i in range(n): for j in range(n): - basis_poly += basis_vector[n*i + j].subs(tau**n) * K_basis[j].backend() * tau**i + basis_poly += basis_vector[n * i + j].subs(tau**n) * K_basis[j].backend() * tau**i basis.append(self(basis_poly)) return basis diff --git a/src/sage/rings/function_field/drinfeld_modules/morphism.py b/src/sage/rings/function_field/drinfeld_modules/morphism.py index 7a246fa8173..692ff9511d8 100644 --- a/src/sage/rings/function_field/drinfeld_modules/morphism.py +++ b/src/sage/rings/function_field/drinfeld_modules/morphism.py @@ -186,7 +186,7 @@ def __classcall_private__(cls, parent, x): raise ValueError('Ore polynomial does not define a morphism') return cls.__classcall__(cls, parent, ore_pol) - def __init__(self, parent, ore_pol): + def __init__(self, parent, ore_pol) -> None: r""" Initialize ``self``. @@ -217,7 +217,7 @@ def __init__(self, parent, ore_pol): self._codomain = parent.codomain() self._ore_polynomial = ore_pol - def _latex_(self): + def _latex_(self) -> str: r""" Return a LaTeX representation of the morphism. @@ -235,7 +235,7 @@ def _latex_(self): """ return f'{latex(self._ore_polynomial)}' - def _repr_(self): + def _repr_(self) -> str: r""" Return a string representation of the morphism. @@ -265,7 +265,7 @@ def _repr_(self): f' To: {self._codomain}\n' \ f' Defn: {self._ore_polynomial}' - def __hash__(self): + def __hash__(self) -> int: r""" Return a hash of ``self``. @@ -331,7 +331,7 @@ def is_identity(self): """ return self._ore_polynomial == 1 - def is_isogeny(self): + def is_isogeny(self) -> bool: r""" Return ``True`` whether the morphism is an isogeny. @@ -695,7 +695,7 @@ def _motive_matrix(self): # The first row: # we write u = u0 + u1*phiT + u2*phiT^2 + ... u = self.ore_polynomial() - us = [ ] + us = [] while not u.is_zero(): u, ui = u.right_quo_rem(phiT) us.append(ui) @@ -711,8 +711,8 @@ def _motive_matrix(self): T = KT.gen() for i in range(1, r): twist = [c.map_coefficients(Frob) for c in row] - row = [(inv*T - B[0]) * twist[-1]] - row += [twist[j-1] - B[j]*twist[-1] for j in range(1, r)] + row = [(inv * T - B[0]) * twist[-1]] + row += [twist[j - 1] - B[j] * twist[-1] for j in range(1, r)] rows.append(row) return matrix(KT, rows) diff --git a/src/sage/rings/function_field/extensions.py b/src/sage/rings/function_field/extensions.py index 94e810a9f87..212d1e6b884 100644 --- a/src/sage/rings/function_field/extensions.py +++ b/src/sage/rings/function_field/extensions.py @@ -83,7 +83,7 @@ class ConstantFieldExtension(FunctionFieldExtension): - ``k_ext`` -- an extension of `k` """ - def __init__(self, F, k_ext): + def __init__(self, F, k_ext) -> None: """ Initialize. @@ -104,7 +104,7 @@ def __init__(self, F, k_ext): # construct constant field extension F_ext of F def_poly = F.polynomial().base_extend(F_ext_base) F_ext = F_ext_base.extension(def_poly, names=def_poly.variable_name()) - else: # rational function field + else: # rational function field F_ext = F_ext_base # embedding of F into F_ext diff --git a/src/sage/rings/function_field/function_field.py b/src/sage/rings/function_field/function_field.py index c46a231a21d..2e2ece950ad 100644 --- a/src/sage/rings/function_field/function_field.py +++ b/src/sage/rings/function_field/function_field.py @@ -234,15 +234,30 @@ # https://www.gnu.org/licenses/ # ***************************************************************************** +from __future__ import annotations + +from typing import TYPE_CHECKING, Literal + +from sage.categories.function_fields import FunctionFields +from sage.categories.homset import Hom from sage.misc.cachefunc import cached_method from sage.misc.lazy_import import LazyImport +from sage.rings.integer import Integer from sage.rings.ring import Field -from sage.categories.homset import Hom -from sage.categories.function_fields import FunctionFields from sage.structure.category_object import CategoryObject +if TYPE_CHECKING: + from sage.rings.function_field.divisor import DivisorGroup + from sage.rings.function_field.element import FunctionFieldElement + from sage.rings.function_field.extensions import ConstantFieldExtension + from sage.rings.function_field.function_field_rational import RationalFunctionField + from sage.rings.function_field.jacobian_base import Jacobian_base + from sage.rings.function_field.maps import FunctionFieldCompletion + from sage.rings.function_field.place import PlaceSet + from sage.rings.function_field.valuation import FunctionFieldValuation -def is_FunctionField(x): + +def is_FunctionField(x) -> bool: """ Return ``True`` if ``x`` is a function field. @@ -284,7 +299,7 @@ class FunctionField(Field): """ _differentials_space = LazyImport('sage.rings.function_field.differential', 'DifferentialsSpace') - def __init__(self, base_field, names, category=FunctionFields()): + def __init__(self, base_field, names, category=FunctionFields()) -> None: """ Initialize. @@ -304,7 +319,7 @@ def __init__(self, base_field, names, category=FunctionFields()): to_constant_base_field._make_weak_references() self.constant_base_field().register_conversion(to_constant_base_field) - def is_perfect(self): + def is_perfect(self) -> bool: r""" Return whether the field is perfect, i.e., its characteristic `p` is zero or every element has a `p`-th root. @@ -318,7 +333,7 @@ def is_perfect(self): """ return self.characteristic() == 0 - def some_elements(self): + def some_elements(self) -> list[FunctionFieldElement]: """ Return some elements in this function field. @@ -361,13 +376,13 @@ def some_elements(self): for numerator in polynomials: for denominator in polynomials: if denominator: - some_element = numerator/denominator + some_element = numerator / denominator if some_element not in elements: elements.append(some_element) return elements - def characteristic(self): + def characteristic(self) -> Integer: """ Return the characteristic of the function field. @@ -389,7 +404,7 @@ def characteristic(self): """ return self.constant_base_field().characteristic() - def is_finite(self): + def is_finite(self) -> Literal[False]: """ Return whether the function field is finite, which is false. @@ -404,7 +419,7 @@ def is_finite(self): """ return False - def is_global(self): + def is_global(self) -> bool: """ Return whether the function field is global, that is, whether the constant field is finite. @@ -456,7 +471,7 @@ def extension(self, f, names=None): from . import constructor return constructor.FunctionFieldExtension(f, names) - def order_with_basis(self, basis, check=True): + def order_with_basis(self, basis, check: bool = True): """ Return the order with given basis over the maximal order of the base field. @@ -504,7 +519,7 @@ def order_with_basis(self, basis, check=True): from .order_basis import FunctionFieldOrder_basis return FunctionFieldOrder_basis(tuple([self(a) for a in basis]), check=check) - def order(self, x, check=True): + def order(self, x, check: bool = True): """ Return the order generated by ``x`` over the base maximal order. @@ -541,13 +556,13 @@ def order(self, x, check=True): if len(x) == 1: g = x[0] basis = [self(1)] - for i in range(self.degree()-1): - basis.append(basis[-1]*g) + for i in range(self.degree() - 1): + basis.append(basis[-1] * g) else: raise NotImplementedError return self.order_with_basis(basis, check=check) - def order_infinite_with_basis(self, basis, check=True): + def order_infinite_with_basis(self, basis, check: bool = True): """ Return the order with given basis over the maximal infinite order of the base field. @@ -597,7 +612,7 @@ def order_infinite_with_basis(self, basis, check=True): from .order_basis import FunctionFieldOrderInfinite_basis return FunctionFieldOrderInfinite_basis(tuple([self(g) for g in basis]), check=check) - def order_infinite(self, x, check=True): + def order_infinite(self, x, check: bool = True): """ Return the order generated by ``x`` over the maximal infinite order. @@ -630,8 +645,8 @@ def order_infinite(self, x, check=True): if len(x) == 1: g = x[0] basis = [self(1)] - for i in range(self.degree()-1): - basis.append(basis[-1]*g) + for i in range(self.degree() - 1): + basis.append(basis[-1] * g) else: raise NotImplementedError return self.order_infinite_with_basis(tuple(basis), check=check) @@ -729,7 +744,7 @@ def _coerce_map_from_(self, source): # canonical, we require the names of the roots to match return source.hom([sourcegen_in_self], base_morphism=base_coercion) - def _test_derivation(self, **options): + def _test_derivation(self, **options) -> None: """ Test the correctness of the derivations of the function field. @@ -754,13 +769,13 @@ def _test_derivation(self, **options): f = self.polynomial() tester.assertEqual(0, d(f)) # Leibniz's law - for x,y in tester.some_elements(product(S, S)): - tester.assertEqual(d(x*y), x*d(y) + d(x)*y) + for x, y in tester.some_elements(product(S, S)): + tester.assertEqual(d(x * y), x * d(y) + d(x) * y) # Linearity - for x,y in tester.some_elements(product(S, S)): - tester.assertEqual(d(x+y), d(x) + d(y)) - for c,x in tester.some_elements(product(K, S)): - tester.assertEqual(d(c*x), c*d(x)) + for x, y in tester.some_elements(product(S, S)): + tester.assertEqual(d(x + y), d(x) + d(y)) + for c, x in tester.some_elements(product(K, S)): + tester.assertEqual(d(c * x), c * d(x)) # Constants map to zero for c in tester.some_elements(K): tester.assertEqual(d(c), 0) @@ -847,7 +862,7 @@ def _intermediate_fields(self, base): raise ValueError("field has not been constructed as a finite extension of base") return ret - def rational_function_field(self): + def rational_function_field(self) -> RationalFunctionField: r""" Return the rational function field from which this field has been created as an extension. @@ -872,7 +887,7 @@ def rational_function_field(self): return self if isinstance(self, RationalFunctionField) else self.base_field().rational_function_field() - def valuation(self, prime): + def valuation(self, prime) -> FunctionFieldValuation: r""" Return the discrete valuation on this function field defined by ``prime``. @@ -1067,7 +1082,7 @@ def basis_of_holomorphic_differentials(self): basis_of_differentials_of_first_kind = basis_of_holomorphic_differentials - def divisor_group(self): + def divisor_group(self) -> DivisorGroup: """ Return the group of divisors attached to the function field. @@ -1090,7 +1105,7 @@ def divisor_group(self): from .divisor import DivisorGroup return DivisorGroup(self) - def place_set(self): + def place_set(self) -> PlaceSet: """ Return the set of all places of the function field. @@ -1113,7 +1128,7 @@ def place_set(self): return PlaceSet(self) @cached_method - def completion(self, place, name=None, prec=None, gen_name=None): + def completion(self, place, name=None, prec=None, gen_name=None) -> FunctionFieldCompletion: """ Return the completion of the function field at the place. @@ -1216,7 +1231,7 @@ def completion(self, place, name=None, prec=None, gen_name=None): from .maps import FunctionFieldCompletion return FunctionFieldCompletion(self, place, name=name, prec=prec, gen_name=gen_name) - def hilbert_symbol(self, a, b, P): + def hilbert_symbol(self, a, b, P) -> Integer: r""" Return the Hilbert symbol `(a,b)_{F_P}` for the local field `F_P`. @@ -1301,7 +1316,7 @@ def hilbert_symbol(self, a, b, P): raise ValueError('a and b must be elements of the function field') if a.is_zero() or b.is_zero(): - return 0 + return Integer(0) # Compute the completion map to precision 1 for computation of the # valuations v(a), v(b) as well as the elements a0, b0 @@ -1331,10 +1346,9 @@ def hilbert_symbol(self, a, b, P): # Finally, put the result together and transform it into the correct output res = k(-1)**(v_a * v_b * e) * a_rd_pw * b_rd_pw - from sage.rings.integer import Integer return Integer(1) if res.is_one() else Integer(-1) - def extension_constant_field(self, k): + def extension_constant_field(self, k) -> ConstantFieldExtension: """ Return the constant field extension with constant field `k`. @@ -1357,7 +1371,7 @@ def extension_constant_field(self, k): return ConstantFieldExtension(self, k) @cached_method - def jacobian(self, model=None, base_div=None, **kwds): + def jacobian(self, model=None, base_div=None, **kwds) -> Jacobian_base: """ Return the Jacobian of the function field. @@ -1415,9 +1429,8 @@ def jacobian(self, model=None, base_div=None, **kwds): if base_place is None: raise ValueError('the function field has no rational place') # appropriate base divisor is constructed below. - else: - if isinstance(base_div, FunctionFieldPlace): - base_div = base_div.divisor() + elif isinstance(base_div, FunctionFieldPlace): + base_div = base_div.divisor() g = self.genus() curve = kwds.get('curve') @@ -1426,15 +1439,15 @@ def jacobian(self, model=None, base_div=None, **kwds): from .jacobian_khuri_makdisi import Jacobian if model == 'km' or model.endswith('large'): if base_div is None: - base_div = (2*g + 1) * base_place - if not base_div.degree() >= 2*g + 1: + base_div = (2 * g + 1) * base_place + if not base_div.degree() >= 2 * g + 1: raise ValueError("Khuri-Makdisi large model requires base divisor of degree " "at least 2*g + 1 for genus g") return Jacobian(self, base_div, model='large', curve=curve) elif model.endswith('medium'): if base_div is None: - base_div = (2*g + 1) * base_place - if not base_div.degree() >= 2*g + 1: + base_div = (2 * g + 1) * base_place + if not base_div.degree() >= 2 * g + 1: raise ValueError("Khuri-Makdisi medium model requires base divisor of degree " "at least 2*g + 1 for genus g") return Jacobian(self, base_div, model='medium', curve=curve) diff --git a/src/sage/rings/function_field/function_field_polymod.py b/src/sage/rings/function_field/function_field_polymod.py index c158014d85c..cee41825462 100644 --- a/src/sage/rings/function_field/function_field_polymod.py +++ b/src/sage/rings/function_field/function_field_polymod.py @@ -26,6 +26,8 @@ # http://www.gnu.org/licenses/ # ***************************************************************************** +from typing import Literal + from sage.arith.functions import lcm from sage.categories.function_fields import FunctionFields from sage.categories.homset import Hom @@ -107,7 +109,7 @@ class FunctionField_polymod(FunctionField): """ Element = FunctionFieldElement_polymod - def __init__(self, polynomial, names, category=None): + def __init__(self, polynomial, names, category=None) -> None: """ Create a function field defined as an extension of another function field by adjoining a root of a univariate polynomial. @@ -171,7 +173,7 @@ def __init__(self, polynomial, names, category=None): self._populate_coercion_lists_(coerce_list=[base_field, self._ring]) self._gen = self(self._ring.gen()) - def __hash__(self): + def __hash__(self) -> int: """ Return hash of the function field. @@ -186,7 +188,7 @@ def __hash__(self): """ return self._hash - def _element_constructor_(self, x): + def _element_constructor_(self, x) -> FunctionFieldElement_polymod: r""" Make ``x`` into an element of the function field, possibly not canonically. @@ -226,7 +228,7 @@ def gen(self, n=0): raise IndexError("there is only one generator") return self._gen - def ngens(self): + def ngens(self) -> Literal[1]: """ Return the number of generators of the function field over its base field. This is by definition 1. @@ -478,7 +480,7 @@ def _make_monic_integral(self, f): d = lcm([b.denominator() for b in f.list() if b]) if d != 1: x = f.parent().gen() - g = (d**n) * f(x/d) + g = (d**n) * f(x / d) else: g = f return g, d @@ -517,7 +519,7 @@ def constant_base_field(self): return self.base_field().constant_base_field() @cached_method(key=lambda self, base: self.base_field() if base is None else base) - def degree(self, base=None): + def degree(self, base=None) -> Integer: """ Return the degree of the function field over the function field ``base``. @@ -558,7 +560,7 @@ def degree(self, base=None): return ZZ(1) return self._polynomial.degree() * self.base_field().degree(base) - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the function field. @@ -571,7 +573,7 @@ def _repr_(self): """ return f"Function field in {self.variable_name()} defined by {self._polynomial}" - def _latex_(self): + def _latex_(self) -> str: r""" Return the LaTeX representation of the function field. @@ -600,7 +602,7 @@ def base_field(self): """ return self._base_field - def random_element(self, *args, **kwds): + def random_element(self, *args, **kwds) -> FunctionFieldElement_polymod: """ Create a random element of the function field. Parameters are passed onto the random_element method of the base_field. @@ -630,7 +632,7 @@ def polynomial(self): """ return self._polynomial - def is_separable(self, base=None): + def is_separable(self, base=None) -> bool: r""" Return whether this is a separable extension of ``base``. @@ -694,7 +696,7 @@ def polynomial_ring(self): return self._ring @cached_method(key=lambda self, base, basis, map: (self.base_field() if base is None else base, basis, map)) - def free_module(self, base=None, basis=None, map=True): + def free_module(self, base=None, basis=None, map: bool = True): """ Return a vector space and isomorphisms from the field to and from the vector space. @@ -889,7 +891,7 @@ def equation_order(self): (1, x^3*y, x^6*y^2, x^9*y^3, x^12*y^4) """ d = self._make_monic_integral(self.polynomial())[1] - return self.order(d*self.gen(), check=False) + return self.order(d * self.gen(), check=False) def hom(self, im_gens, base_morphism=None): """ @@ -1157,9 +1159,9 @@ def _simple_model(self, name='v'): factor = self.constant_base_field().zero() exponent = 0 while True: - v = M(a+b*factor*x**exponent) + v = M(a + b * factor * x**exponent) minpoly = v.matrix(K).minpoly() - if minpoly.degree() == M.degree()*L.degree(): + if minpoly.degree() == M.degree() * L.degree(): break factor += 1 if factor == 0: @@ -1542,7 +1544,7 @@ def separable_model(self, names=None): raise NotImplementedError("constructing a separable model is only implemented for function fields over a perfect constant base field") if names is None: - names = (self.variable_name()+"_", self.rational_function_field().variable_name()+"_") + names = (self.variable_name() + "_", self.rational_function_field().variable_name() + "_") L, from_L, to_L = self.monic_integral_model() @@ -1720,7 +1722,7 @@ def _inversion_isomorphism(self): K = self.base_field() R = PolynomialRing(K, 'T') x = K.gen() - xinv = 1/x + xinv = 1 / x h = K.hom(xinv) F_poly = R([h(c) for c in self.polynomial().list()]) @@ -1731,7 +1733,7 @@ def _inversion_isomorphism(self): M, M2F, F2M = F.monic_integral_model('s') - return M, F2self*M2F, F2M*self2F + return M, F2self * M2F, F2M * self2F def places_above(self, p): """ @@ -1843,7 +1845,8 @@ def exact_constant_field(self, name='t'): return k_ext, embedding - def genus(self): + @cached_method + def genus(self) -> Integer: """ Return the genus of the function field. @@ -2042,7 +2045,7 @@ class FunctionField_global(FunctionField_simple): """ _differentials_space = LazyImport('sage.rings.function_field.differential', 'DifferentialsSpace_global') - def __init__(self, polynomial, names): + def __init__(self, polynomial, names) -> None: """ Initialize. @@ -2283,7 +2286,7 @@ def _weierstrass_places(self): Mx = matrix(M.nrows(), [c._x for c in M.list()]) detM = self(Mx.determinant() % self._polynomial) - R = detM.divisor() + sum(gaps)*W # ramification divisor + R = detM.divisor() + sum(gaps) * W # ramification divisor return R, gaps @@ -2307,19 +2310,19 @@ def L_polynomial(self, name='t'): q = self.constant_field().order() g = self.genus() - B = [len(self.places(i+1)) for i in range(g)] - N = [sum(d * B[d-1] for d in ZZ(i+1).divisors()) for i in range(g)] - S = [N[i] - q**(i+1) - 1 for i in range(g)] + B = [len(self.places(i + 1)) for i in range(g)] + N = [sum(d * B[d - 1] for d in ZZ(i + 1).divisors()) for i in range(g)] + S = [N[i] - q**(i + 1) - 1 for i in range(g)] a = [1] - for i in range(1, g+1): - a.append(sum(S[j] * a[i-j-1] for j in range(i)) / i) - for j in range(1, g+1): - a.append(q**j * a[g-j]) + for i in range(1, g + 1): + a.append(sum(S[j] * a[i - j - 1] for j in range(i)) / i) + for j in range(1, g + 1): + a.append(q**j * a[g - j]) return ZZ[name](a) - def number_of_rational_places(self, r=1): + def number_of_rational_places(self, r=1) -> Integer: """ Return the number of rational places of the function field whose constant field extended by degree ``r``. @@ -2347,7 +2350,7 @@ def number_of_rational_places(self, r=1): R = IntegerRing()[[L.parent().gen()]] # power series ring f = R(Lp / L, prec=r) - n = f[r-1] + q**r + 1 + n = f[r - 1] + q**r + 1 return n @@ -2484,7 +2487,7 @@ def _maximal_order_basis(self): for f in pols_in_S: p = f.polynomial(S.gen(0)) s = 0 - for i in range(p.degree()+1): + for i in range(p.degree() + 1): s += p[i].subs(x) * y**i pols.append(s) @@ -2511,7 +2514,7 @@ def _maximal_order_basis(self): basis_V = [to_V(bvec) for bvec in _basis] l = lcm([vvec.denominator() for vvec in basis_V]) - _mat = matrix([[coeff.numerator() for coeff in l*v] for v in basis_V]) + _mat = matrix([[coeff.numerator() for coeff in l * v] for v in basis_V]) reversed_hermite_form(_mat) basis = [fr_V(v) / l for v in _mat if not v.is_zero()] @@ -2563,9 +2566,9 @@ def primitive_integal_element_infinite(self): y = self.gen() x = self.base_field().gen() - cf = max([(f[i].numerator().degree()/(n-i)).ceil() for i in range(n) + cf = max([(f[i].numerator().degree() / (n - i)).ceil() for i in range(n) if f[i] != 0]) - return y*x**(-cf) + return y * x**(-cf) @cached_method def equation_order_infinite(self): diff --git a/src/sage/rings/function_field/function_field_rational.py b/src/sage/rings/function_field/function_field_rational.py index 74ebb736992..ffc72b51f33 100644 --- a/src/sage/rings/function_field/function_field_rational.py +++ b/src/sage/rings/function_field/function_field_rational.py @@ -25,6 +25,8 @@ # http://www.gnu.org/licenses/ # ***************************************************************************** +from typing import Literal + from sage.arith.functions import lcm from sage.categories.function_fields import FunctionFields from sage.categories.homset import Hom @@ -125,7 +127,7 @@ class RationalFunctionField(FunctionField): """ Element = FunctionFieldElement_rational - def __init__(self, constant_field, names, category=None): + def __init__(self, constant_field, names, category=None) -> None: """ Initialize. @@ -191,7 +193,7 @@ def __reduce__(self): from .constructor import FunctionField return FunctionField, (self._constant_field, self._names) - def __hash__(self): + def __hash__(self) -> int: """ Return hash of the function field. @@ -205,7 +207,7 @@ def __hash__(self): """ return self._hash - def _repr_(self): + def _repr_(self) -> str: """ Return string representation of the function field. @@ -218,7 +220,7 @@ def _repr_(self): return "Rational function field in %s over %s" % ( self.variable_name(), self._constant_field) - def _element_constructor_(self, x): + def _element_constructor_(self, x) -> FunctionFieldElement_rational: r""" Coerce ``x`` into an element of the function field, possibly not canonically. @@ -480,7 +482,7 @@ def polynomial_ring(self, var='x'): return self[var] @cached_method(key=lambda self, base, basis, map: map) - def free_module(self, base=None, basis=None, map=True): + def free_module(self, base=None, basis=None, map: bool = True): """ Return a vector space `V` and isomorphisms from the field to `V` and from `V` to the field. @@ -545,7 +547,7 @@ def free_module(self, base=None, basis=None, map=True): to_V = MapFunctionFieldToVectorSpace(self, V) return (V, from_V, to_V) - def random_element(self, *args, **kwds): + def random_element(self, *args, **kwds) -> FunctionFieldElement_rational: """ Create a random element of the rational function field. @@ -559,7 +561,7 @@ def random_element(self, *args, **kwds): """ return self(self._field.random_element(*args, **kwds)) - def degree(self, base=None): + def degree(self, base=None) -> Integer: """ Return the degree over the base field of the rational function field. Since the base field is the rational function field itself, the @@ -603,7 +605,7 @@ def gen(self, n=0): raise IndexError("Only one generator.") return self._gen - def ngens(self): + def ngens(self) -> Literal[1]: """ Return the number of generators, which is 1. @@ -770,7 +772,7 @@ def different(self): """ return self.divisor_group().zero() - def genus(self): + def genus(self) -> Integer: """ Return the genus of the function field, namely 0. diff --git a/src/sage/rings/function_field/function_field_test.py b/src/sage/rings/function_field/function_field_test.py index e8a1359eadf..a5822679c87 100644 --- a/src/sage/rings/function_field/function_field_test.py +++ b/src/sage/rings/function_field/function_field_test.py @@ -18,23 +18,23 @@ def J(): @pytest.fixture def K(): - return FunctionField(FiniteField(5**2,'a'), 'x') + return FunctionField(FiniteField(5**2, 'a'), 'x') @pytest.fixture def L(F): x = F.gen() Y = PolynomialRing(F, 'Y').gen() - return F.extension(Y**2 + Y + x + 1/x, 'y') + return F.extension(Y**2 + Y + x + 1 / x, 'y') @pytest.fixture def M(K, R, S): x = K.gen() y = R.gen() - L = K.extension(y**3 - (x**3 + 2*x*y + 1/x)) + L = K.extension(y**3 - (x**3 + 2 * x * y + 1 / x)) t = S.gen() - return L.extension(t**2 - x*y) + return L.extension(t**2 - x * y) @pytest.fixture @@ -56,7 +56,7 @@ def R(K): def S(K, R): x = K.gen() y = R.gen() - L = K.extension(y**3 - (x**3 + 2*x*y + 1/x)) + L = K.extension(y**3 - (x**3 + 2 * x * y + 1 / x)) return PolynomialRing(L, 't') @@ -72,18 +72,18 @@ def T(F): # # https://github.com/pytest-dev/pytest/issues/349 # -pairs = [ ("J", None), +pairs = [("J", None), ("K", 16), ("L", 2), ("M", 1), ("N", 1), ("O", None), ("T", None), - ("S", 8) ] + ("S", 8)] @pytest.mark.parametrize("ff,max_runs", pairs) -def test_function_field_testsuite(ff, max_runs, request): +def test_function_field_testsuite(ff, max_runs, request) -> None: r""" Run the TestSuite() on some function fields that are constructed in the documentation. They are slow, random, and not @@ -109,7 +109,7 @@ def test_function_field_testsuite(ff, max_runs, request): ff = request.getfixturevalue(ff) # Pass max_runs only if it's not None; otherwise use the default - run_args = { "verbose": True, "raise_on_failure": True } + run_args = {"verbose": True, "raise_on_failure": True} if max_runs: run_args["max_runs"] = max_runs diff --git a/src/sage/rings/function_field/ideal.py b/src/sage/rings/function_field/ideal.py index e00bae907e4..2daa6e9ecbf 100644 --- a/src/sage/rings/function_field/ideal.py +++ b/src/sage/rings/function_field/ideal.py @@ -119,7 +119,7 @@ class FunctionFieldIdeal(Element): sage: O.ideal(x^3 + 1) Ideal (x^3 + 1) of Maximal order of Rational function field in x over Finite Field of size 7 """ - def __init__(self, ring): + def __init__(self, ring) -> None: """ Initialize. @@ -134,7 +134,7 @@ def __init__(self, ring): Element.__init__(self, ring.ideal_monoid()) self._ring = ring - def _repr_short(self): + def _repr_short(self) -> str: """ Return a string representation of this ideal that doesn't include the name of the ambient ring. @@ -154,7 +154,7 @@ def _repr_short(self): return "(%s)" % (', '.join([repr(g) for g in self.gens_reduced()]), ) - def _repr_(self): + def _repr_(self) -> str: """ Return a string representation of this ideal. @@ -214,7 +214,7 @@ def _repr_(self): return "Ideal %s of %s" % (self._repr_short(), self.ring()) - def _latex_(self): + def _latex_(self) -> str: r""" Return the LaTeX representation of the ideal. @@ -607,7 +607,7 @@ class FunctionFieldIdeal_module(FunctionFieldIdeal, Ideal_generic): sage: I^2 Ideal (x^3 + 1, (-x^3 - 1)*y) of Order in Function field in y defined by y^2 - x^3 - 1 """ - def __init__(self, ring, module): + def __init__(self, ring, module) -> None: """ Initialize. @@ -631,7 +631,7 @@ def __init__(self, ring, module): # module generators are still ideal generators Ideal_generic.__init__(self, ring, self._gens, coerce=False) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if ``x`` is in this ideal. @@ -652,7 +652,7 @@ def __contains__(self, x): """ return self._structure[2](x) in self._module - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of this ideal. @@ -665,7 +665,7 @@ def __hash__(self): sage: I = O.ideal(y) sage: d = {I: 1} # indirect doctest """ - return hash((self._ring,self._module)) + return hash((self._ring, self._module)) def _richcmp_(self, other, op): """ @@ -803,7 +803,7 @@ def _mul_(self, other): sage: I * J Ideal ((-x^5 + x^4 - x^2 + x)*y + x^3 + 1, (x^3 - x^2 + 1)*y) of Order in Function field in y defined by y^2 - x^3 - 1 """ - return self.ring().ideal([x*y for x in self.gens() for y in other.gens()]) + return self.ring().ideal([x * y for x in self.gens() for y in other.gens()]) def _acted_upon_(self, other, on_left): """ @@ -843,7 +843,7 @@ def intersection(self, other): try: if self.ring().has_coerce_map_from(other): return self - except (TypeError,ArithmeticError,ValueError): + except (TypeError, ArithmeticError, ValueError): pass other = self.ring().ideal(other) @@ -912,7 +912,7 @@ class FunctionFieldIdealInfinite_module(FunctionFieldIdealInfinite, Ideal_generi sage: O.ideal(y) Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 1 """ - def __init__(self, ring, module): + def __init__(self, ring, module) -> None: """ Initialize. @@ -937,7 +937,7 @@ def __init__(self, ring, module): # module generators are still ideal generators Ideal_generic.__init__(self, ring, self._gens, coerce=False) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if ``x`` is in this ideal. @@ -962,7 +962,7 @@ def __contains__(self, x): """ return self._structure[2](x) in self._module - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of this ideal. @@ -975,7 +975,7 @@ def __hash__(self): sage: I = O.ideal_with_gens_over_base([1, y]) sage: d = {I: 2} # indirect doctest """ - return hash((self._ring,self._module)) + return hash((self._ring, self._module)) def __eq__(self, other): """ @@ -1052,7 +1052,7 @@ class IdealMonoid(UniqueRepresentation, Parent): Monoid of ideals of Maximal order of Rational function field in x over Finite Field of size 2 """ - def __init__(self, R): + def __init__(self, R) -> None: """ Initialize the ideal monoid. @@ -1069,7 +1069,7 @@ def __init__(self, R): self.__R = R self._populate_coercion_lists_() - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the ideal monoid. @@ -1109,7 +1109,7 @@ def _element_constructor_(self, x): sage: M([x-4, 1/x]) Ideal (1/x) of Maximal order of Rational function field in x over Finite Field of size 2 """ - try: # x is an ideal + try: # x is an ideal x = x.gens() except AttributeError: pass diff --git a/src/sage/rings/function_field/ideal_polymod.py b/src/sage/rings/function_field/ideal_polymod.py index da0c837e963..d7b6f22eede 100644 --- a/src/sage/rings/function_field/ideal_polymod.py +++ b/src/sage/rings/function_field/ideal_polymod.py @@ -52,7 +52,7 @@ class FunctionFieldIdeal_polymod(FunctionFieldIdeal): sage: O.ideal(y) Ideal (y) of Maximal order of Function field in y defined by y^2 + x^3*y + x """ - def __init__(self, ring, hnf, denominator=1): + def __init__(self, ring, hnf, denominator=1) -> None: """ Initialize. @@ -93,7 +93,7 @@ def __init__(self, ring, hnf, denominator=1): # if the second gen is zero, the tuple has only the first gen. self._gens_two_vecs = None - def __bool__(self): + def __bool__(self) -> bool: """ Test if this ideal is zero. @@ -128,7 +128,7 @@ def __bool__(self): """ return self._hnf.nrows() != 0 - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of this ideal. @@ -151,7 +151,7 @@ def __hash__(self): """ return hash((self._ring, self._hnf, self._denominator)) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if ``x`` is in this ideal. @@ -833,7 +833,7 @@ def norm(self): return n @cached_method - def is_prime(self): + def is_prime(self) -> bool: """ Return ``True`` if this ideal is a prime ideal. @@ -1046,7 +1046,7 @@ class FunctionFieldIdeal_global(FunctionFieldIdeal_polymod): sage: O.ideal(y) Ideal (y) of Maximal order of Function field in y defined by y^2 + x^3*y + x """ - def __init__(self, ring, hnf, denominator=1): + def __init__(self, ring, hnf, denominator=1) -> None: """ Initialize. @@ -1319,7 +1319,7 @@ class FunctionFieldIdealInfinite_polymod(FunctionFieldIdealInfinite): Ideal (1/x^4*y^2) of Maximal infinite order of Function field in y defined by y^3 + y^2 + 2*x^4 """ - def __init__(self, ring, ideal): + def __init__(self, ring, ideal) -> None: """ Initialize this ideal. @@ -1335,7 +1335,7 @@ def __init__(self, ring, ideal): FunctionFieldIdealInfinite.__init__(self, ring) self._ideal = ideal - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of this ideal. @@ -1357,7 +1357,7 @@ def __hash__(self): """ return hash((self.ring(), self._ideal)) - def __contains__(self, x): + def __contains__(self, x) -> bool: """ Return ``True`` if ``x`` is in this ideal. diff --git a/src/sage/rings/function_field/ideal_rational.py b/src/sage/rings/function_field/ideal_rational.py index 6cb21710e0d..4a99313b9a8 100644 --- a/src/sage/rings/function_field/ideal_rational.py +++ b/src/sage/rings/function_field/ideal_rational.py @@ -40,7 +40,7 @@ class FunctionFieldIdeal_rational(FunctionFieldIdeal): sage: I = O.ideal(1/(x^2+x)); I Ideal (1/(x^2 + x)) of Maximal order of Rational function field in x over Rational Field """ - def __init__(self, ring, gen): + def __init__(self, ring, gen) -> None: """ Initialize. @@ -54,7 +54,7 @@ def __init__(self, ring, gen): FunctionFieldIdeal.__init__(self, ring) self._gen = gen - def __hash__(self): + def __hash__(self) -> int: """ Return the hash computed from the data. @@ -65,9 +65,9 @@ def __hash__(self): sage: I = O.ideal(1/(x^2+x)) sage: d = { I: 1, I^2: 2 } """ - return hash( (self._ring, self._gen) ) + return hash((self._ring, self._gen)) - def __contains__(self, element): + def __contains__(self, element) -> bool: """ Test if ``element`` is in this ideal. @@ -304,7 +304,7 @@ def valuation(self, ideal): O = self.ring() d = ideal.denominator() - return self._valuation(d*ideal) - self._valuation(O.ideal(d)) + return self._valuation(d * ideal) - self._valuation(O.ideal(d)) def _valuation(self, ideal): """ @@ -369,7 +369,7 @@ class FunctionFieldIdealInfinite_rational(FunctionFieldIdealInfinite): sage: Oinf.ideal(x) Ideal (x) of Maximal infinite order of Rational function field in x over Finite Field of size 2 """ - def __init__(self, ring, gen): + def __init__(self, ring, gen) -> None: """ Initialize. @@ -384,7 +384,7 @@ def __init__(self, ring, gen): FunctionFieldIdealInfinite.__init__(self, ring) self._gen = gen - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of this fractional ideal. @@ -397,9 +397,9 @@ def __hash__(self): sage: J = Oinf.ideal(1/x) sage: d = { I: 1, J: 2 } """ - return hash( (self.ring(), self._gen) ) + return hash((self.ring(), self._gen)) - def __contains__(self, element): + def __contains__(self, element) -> bool: """ Test if ``element`` is in this ideal. @@ -531,7 +531,7 @@ def is_prime(self): True """ x = self._ring.fraction_field().gen() - return self._gen == 1/x + return self._gen == 1 / x def gen(self): """ diff --git a/src/sage/rings/function_field/jacobian_base.py b/src/sage/rings/function_field/jacobian_base.py index 7274be0aea7..e4b86bf79d4 100644 --- a/src/sage/rings/function_field/jacobian_base.py +++ b/src/sage/rings/function_field/jacobian_base.py @@ -195,7 +195,7 @@ class JacobianGroupFunctor(ConstructionFunctor): """ rank = 20 - def __init__(self, base_field, field): + def __init__(self, base_field, field) -> None: """ Initialize. @@ -287,7 +287,7 @@ class JacobianGroup_base(Parent): """ _embedding_map_class = None - def __init__(self, parent, function_field, base_div): + def __init__(self, parent, function_field, base_div) -> None: """ Initialize. @@ -306,7 +306,7 @@ def __init__(self, parent, function_field, base_div): self._genus = parent._function_field.genus() # equals function_field.genus() self._base_div = base_div - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -462,8 +462,8 @@ def _bound_on_order(self): q = F.constant_base_field().order() g = self._genus - c = 2*g/(q.sqrt() - 1) - return integer_floor(math.exp(c)*q**g) + c = 2 * g / (q.sqrt() - 1) + return integer_floor(math.exp(c) * q**g) def order(self, algorithm='numeric'): """ @@ -492,50 +492,50 @@ def order(self, algorithm='numeric'): if algorithm == 'numeric': # numeric method - fast but might be inaccurate by numerical noise from sage.rings.qqbar import AlgebraicField - h = Integer(math.prod([(1-a**(-b))**m for a, m in f.change_ring(AlgebraicField()).roots()])) + h = Integer(math.prod([(1 - a**(-b))**m for a, m in f.change_ring(AlgebraicField()).roots()])) return h # algebraic method - slow es = [] s = -1 - for i in range(1, 2*g + 1): - es.append(s*f[i]) + for i in range(1, 2 * g + 1): + es.append(s * f[i]) s = -s es ps = [es[0]] - for i in range(1, 2*g): + for i in range(1, 2 * g): p = 0 s = 1 for j in range(i): - p = p + s*es[j]*ps[-j-1] + p = p + s * es[j] * ps[-j - 1] s = -s - ps.append(p + s*(i + 1)*es[i]) + ps.append(p + s * (i + 1) * es[i]) - while len(ps) < b*2*g: + while len(ps) < b * 2 * g: p = 0 s = 1 - for j in range(2*g): - p = p + s*es[j]*ps[-j-1] + for j in range(2 * g): + p = p + s * es[j] * ps[-j - 1] s = -s ps.append(p) - qs = [ps[b*(i + 1) - 1] for i in range(2*g)] + qs = [ps[b * (i + 1) - 1] for i in range(2 * g)] fs = [qs[0]] - for i in range(1, 2*g): + for i in range(1, 2 * g): k = qs[i] s = -1 for j in range(i): - k = k + s*fs[j]*qs[i - j - 1] + k = k + s * fs[j] * qs[i - j - 1] s = -s - fs.append(-s*k // (i + 1)) + fs.append(-s * k // (i + 1)) bs = [1] s = -1 - for i in range(2*g): - bs.append(s*fs[i]) + for i in range(2 * g): + bs.append(s * fs[i]) s = -s return sum(bs) @@ -584,7 +584,7 @@ class Jacobian_base(Parent): sage: F.jacobian() Jacobian of Function field in y defined by y^2 + y + (x^2 + 1)/x (Hess model) """ - def __init__(self, function_field, base_div, **kwds): + def __init__(self, function_field, base_div, **kwds) -> None: """ Initialize. @@ -604,7 +604,7 @@ def __init__(self, function_field, base_div, **kwds): base=function_field.constant_base_field(), facade=True) - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -682,7 +682,7 @@ def __call__(self, x): K = G._function_field return G.point(K.divisor_group()(x.divisor())) if x in F.place_set(): - return self(x - x.degree()*self._base_place) + return self(x - x.degree() * self._base_place) if x == 0: return self.group().zero() if x in F.divisor_group(): @@ -789,7 +789,7 @@ def group(self, k_ext=None): return grp - def set_base_place(self, place): + def set_base_place(self, place) -> None: """ Set ``place`` as the base place. diff --git a/src/sage/rings/function_field/jacobian_hess.py b/src/sage/rings/function_field/jacobian_hess.py index 8b3e0fea220..dfc3c33107f 100644 --- a/src/sage/rings/function_field/jacobian_hess.py +++ b/src/sage/rings/function_field/jacobian_hess.py @@ -118,7 +118,7 @@ class JacobianPoint(JacobianPoint_base): sage: -(dS.divisor() + ds.divisor()) == pl True """ - def __init__(self, parent, dS, ds): + def __init__(self, parent, dS, ds) -> None: """ Initialize. @@ -135,7 +135,7 @@ def __init__(self, parent, dS, ds): super().__init__(parent) self._data = (dS, ds) - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -152,7 +152,7 @@ def _repr_(self): divisor = (~dS).divisor() + (~ds).divisor() return f'[{divisor}]' - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of ``self``. @@ -445,7 +445,7 @@ class JacobianGroupEmbedding(Map): To: Group of rational points of Jacobian over Finite Field in z3 of size 17^3 (Hess model) """ - def __init__(self, base_group, extension_group): + def __init__(self, base_group, extension_group) -> None: """ Initialize. @@ -484,7 +484,7 @@ def __init__(self, base_group, extension_group): Map.__init__(self, Hom(base_group, extension_group, CommutativeAdditiveGroups())) - def _repr_type(self): + def _repr_type(self) -> str: """ Return string representation of ``self``. @@ -559,7 +559,7 @@ class JacobianGroup(UniqueRepresentation, JacobianGroup_base): Element = JacobianPoint _embedding_map_class = JacobianGroupEmbedding - def __init__(self, parent, function_field, base_div): + def __init__(self, parent, function_field, base_div) -> None: """ Initialize. @@ -585,7 +585,7 @@ def __init__(self, parent, function_field, base_div): self._base_place = None - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -865,7 +865,7 @@ class JacobianGroup_finite_field(JacobianGroup, JacobianGroup_finite_field_base) """ Element = JacobianPoint_finite_field - def __init__(self, parent, function_field, base_div): + def __init__(self, parent, function_field, base_div) -> None: """ Initialize. @@ -1012,7 +1012,7 @@ class Jacobian(Jacobian_base, UniqueRepresentation): Jacobian of Projective Plane Curve over Finite Field of size 17 defined by x^3 - y^2*z + 5*z^3 (Hess model) """ - def __init__(self, function_field, base_div, **kwds): + def __init__(self, function_field, base_div, **kwds) -> None: """ Initialize. @@ -1032,7 +1032,7 @@ def __init__(self, function_field, base_div, **kwds): else: self._group_class = JacobianGroup - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. diff --git a/src/sage/rings/function_field/jacobian_khuri_makdisi.py b/src/sage/rings/function_field/jacobian_khuri_makdisi.py index a1d53aff8b6..2fb4d3bed96 100644 --- a/src/sage/rings/function_field/jacobian_khuri_makdisi.py +++ b/src/sage/rings/function_field/jacobian_khuri_makdisi.py @@ -170,7 +170,7 @@ class JacobianPoint(JacobianPoint_base): [0 0 0 0 0 1 0 0 5] [0 0 0 0 0 0 1 0 4] """ - def __init__(self, parent, w): + def __init__(self, parent, w) -> None: """ Initialize. @@ -190,7 +190,7 @@ def __init__(self, parent, w): w.set_immutable() self._w = w - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -212,7 +212,7 @@ def _repr_(self): """ return f'Point of Jacobian determined by \n{self._w}' - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of ``self``. @@ -508,7 +508,7 @@ class JacobianGroupEmbedding(Map): To: Group of rational points of Jacobian over Finite Field in z2 of size 5^2 (Khuri-Makdisi large model) """ - def __init__(self, base_group, extension_group): + def __init__(self, base_group, extension_group) -> None: """ Initialize. @@ -532,7 +532,7 @@ def __init__(self, base_group, extension_group): Map.__init__(self, Hom(base_group, extension_group, CommutativeAdditiveGroups())) - def _repr_type(self): + def _repr_type(self) -> str: """ Return string representation of ``self``. @@ -603,7 +603,7 @@ class JacobianGroup(UniqueRepresentation, JacobianGroup_base): Element = JacobianPoint _embedding_map_class = JacobianGroupEmbedding - def __init__(self, parent, function_field, base_div): + def __init__(self, parent, function_field, base_div) -> None: """ Initialize. @@ -663,7 +663,7 @@ def mu(n, m, i, j): self._base_place = None - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. @@ -855,7 +855,7 @@ class JacobianGroup_finite_field(JacobianGroup, JacobianGroup_finite_field_base) """ Element = JacobianPoint_finite_field - def __init__(self, parent, function_field, base_div): + def __init__(self, parent, function_field, base_div) -> None: """ Initialize. @@ -916,7 +916,7 @@ def __iter__(self): return generators.append(F._places_finite(deg)) deg += 1 - multiples.append((d0 + 1)*[None]) + multiples.append((d0 + 1) * [None]) wn = self._wd_from_divisor(new_pl.divisor()) dn = new_pl.degree() wr = zero_divisor @@ -979,7 +979,7 @@ class Jacobian(UniqueRepresentation, Jacobian_base): Jacobian of Projective Plane Curve over Finite Field of size 7 defined by x^3 - y^2*z - 2*z^3 (Khuri-Makdisi large model) """ - def __init__(self, function_field, base_div, model, **kwds): + def __init__(self, function_field, base_div, model, **kwds) -> None: """ Initialize. @@ -1009,7 +1009,7 @@ def __init__(self, function_field, base_div, model, **kwds): else: self._group_class = JacobianGroup - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of ``self``. diff --git a/src/sage/rings/function_field/maps.py b/src/sage/rings/function_field/maps.py index 6b37456c64c..08a057798c0 100644 --- a/src/sage/rings/function_field/maps.py +++ b/src/sage/rings/function_field/maps.py @@ -165,7 +165,7 @@ def _richcmp_(self, other, op): return richcmp((self.domain(), self.codomain()), (other.domain(), other.codomain()), op) - def __hash__(self): + def __hash__(self) -> int: r""" Return a hash value of this map. @@ -198,7 +198,7 @@ class MapVectorSpaceToFunctionField(FunctionFieldVectorSpaceIsomorphism): From: Vector space of dimension 2 over Rational function field in x over Rational Field To: Function field in y defined by y^2 - x*y + 4*x^3 """ - def __init__(self, V, K): + def __init__(self, V, K) -> None: """ EXAMPLES:: @@ -307,7 +307,7 @@ class MapFunctionFieldToVectorSpace(FunctionFieldVectorSpaceIsomorphism): From: Function field in y defined by y^2 - x*y + 4*x^3 To: Vector space of dimension 2 over Rational function field in x over Rational Field """ - def __init__(self, K, V): + def __init__(self, K, V) -> None: """ Initialize. @@ -380,7 +380,7 @@ class FunctionFieldMorphism(RingHomomorphism): Function Field endomorphism of Rational function field in x over Rational Field Defn: x |--> 1/x """ - def __init__(self, parent, im_gen, base_morphism): + def __init__(self, parent, im_gen, base_morphism) -> None: """ Initialize. @@ -448,7 +448,7 @@ class FunctionFieldMorphism_polymod(FunctionFieldMorphism): sage: f(y).charpoly('y') y^3 + 6*x^3 + x """ - def __init__(self, parent, im_gen, base_morphism): + def __init__(self, parent, im_gen, base_morphism) -> None: """ Initialize. @@ -493,7 +493,7 @@ class FunctionFieldMorphism_rational(FunctionFieldMorphism): """ Morphism from a rational function field to a function field. """ - def __init__(self, parent, im_gen, base_morphism): + def __init__(self, parent, im_gen, base_morphism) -> None: """ Initialize. @@ -560,7 +560,7 @@ class FunctionFieldConversionToConstantBaseField(Map): From: Rational function field in x over Rational Field To: Rational Field """ - def __init__(self, parent): + def __init__(self, parent) -> None: """ Initialize. @@ -767,7 +767,7 @@ class FunctionFieldCompletion(Map): b + b*t + b*t^3 + b*t^4 + (b + 1)*t^5 + (b + 1)*t^7 + b*t^9 + b*t^11 + b*t^12 + b*t^13 + b*t^15 + b*t^16 + (b + 1)*t^17 + (b + 1)*t^19 + O(t^20) """ - def __init__(self, field, place, name=None, prec=None, gen_name=None): + def __init__(self, field, place, name=None, prec=None, gen_name=None) -> None: """ Initialize. diff --git a/src/sage/rings/function_field/order.py b/src/sage/rings/function_field/order.py index 3795e0ea25a..aa047af1667 100644 --- a/src/sage/rings/function_field/order.py +++ b/src/sage/rings/function_field/order.py @@ -132,7 +132,7 @@ class FunctionFieldOrder_base(CachedRepresentation, Parent): sage: F.maximal_order() Maximal order of Rational function field in y over Rational Field """ - def __init__(self, field, ideal_class=FunctionFieldIdeal, category=None): + def __init__(self, field, ideal_class=FunctionFieldIdeal, category=None) -> None: """ Initialize. @@ -148,7 +148,7 @@ def __init__(self, field, ideal_class=FunctionFieldIdeal, category=None): self._ideal_class_ = ideal_class # element class for parent ideal monoid self._field = field - def is_field(self, proof=True): + def is_field(self, proof: bool = True) -> bool: """ Return ``False`` since orders are never fields. @@ -159,7 +159,7 @@ def is_field(self, proof=True): """ return False - def is_noetherian(self): + def is_noetherian(self) -> bool: """ Return ``True`` since orders in function fields are Noetherian. @@ -183,7 +183,7 @@ def function_field(self): fraction_field = function_field - def is_subring(self, other): + def is_subring(self, other) -> bool: """ Return ``True`` if the order is a subring of the other order. @@ -219,7 +219,7 @@ class FunctionFieldOrder(FunctionFieldOrder_base): """ Base class for orders in function fields. """ - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation. @@ -235,7 +235,7 @@ class FunctionFieldOrderInfinite(FunctionFieldOrder_base): """ Base class for infinite orders in function fields. """ - def _repr_(self): + def _repr_(self) -> str: """ EXAMPLES:: @@ -249,7 +249,7 @@ class FunctionFieldMaximalOrder(UniqueRepresentation, FunctionFieldOrder): """ Base class of maximal orders of function fields. """ - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the order. @@ -265,7 +265,7 @@ class FunctionFieldMaximalOrderInfinite(FunctionFieldMaximalOrder, FunctionField """ Base class of maximal infinite orders of function fields. """ - def _repr_(self): + def _repr_(self) -> str: """ EXAMPLES:: diff --git a/src/sage/rings/function_field/order_basis.py b/src/sage/rings/function_field/order_basis.py index 1cf89e3f966..2cd72089ab7 100644 --- a/src/sage/rings/function_field/order_basis.py +++ b/src/sage/rings/function_field/order_basis.py @@ -67,7 +67,7 @@ class FunctionFieldOrder_basis(FunctionFieldOrder): ... ValueError: basis (y, y, y^3, y^4, 2*x*y + (x^4 + 1)/x) is not linearly independent """ - def __init__(self, basis, check=True): + def __init__(self, basis, check: bool = True) -> None: """ Initialize. @@ -104,7 +104,7 @@ def __init__(self, basis, check=True): raise ValueError("basis {} is not linearly independent".format(basis)) if to_V(field(1)) not in self._module: raise ValueError("the identity element must be in the module spanned by basis {}".format(basis)) - if not all(to_V(a*b) in self._module for a in basis for b in basis): + if not all(to_V(a * b) in self._module for a in basis for b in basis): raise ValueError("the module generated by basis {} must be closed under multiplication".format(basis)) def _element_constructor_(self, f): @@ -240,7 +240,7 @@ def ideal(self, *gens): gens = [gens] K = self.function_field() - return self.ideal_with_gens_over_base([b*K(g) for b in self.basis() for g in gens]) + return self.ideal_with_gens_over_base([b * K(g) for b in self.basis() for g in gens]) def polynomial(self): """ @@ -361,7 +361,7 @@ class FunctionFieldOrderInfinite_basis(FunctionFieldOrderInfinite): sage: O.basis() (1/x*y + 1, 1/x*y, 1/x^2*y^2, 1/x^3*y^3) """ - def __init__(self, basis, check=True): + def __init__(self, basis, check: bool = True) -> None: """ Initialize. @@ -401,7 +401,7 @@ def __init__(self, basis, check=True): raise ValueError("basis {} is not linearly independent".format(basis)) if W.coordinate_vector(to(field(1))) not in self._module: raise ValueError("the identity element must be in the module spanned by basis {}".format(basis)) - if not all(W.coordinate_vector(to(a*b)) in self._module for a in basis for b in basis): + if not all(W.coordinate_vector(to(a * b)) in self._module for a in basis for b in basis): raise ValueError("the module generated by basis {} must be closed under multiplication".format(basis)) def _element_constructor_(self, f): @@ -494,7 +494,7 @@ def ideal_with_gens_over_base(self, gens): gens = [F(a) for a in gens] V, from_V, to_V = F.vector_space() - M = V.span([to_V(b) for b in gens], base_ring=S) # not work + M = V.span([to_V(b) for b in gens], base_ring=S) # not work return self.ideal_monoid().element_class(self, M) @@ -533,7 +533,7 @@ def ideal(self, *gens): gens = [gens] K = self.function_field() - return self.ideal_with_gens_over_base([b*K(g) for b in self.basis() for g in gens]) + return self.ideal_with_gens_over_base([b * K(g) for b in self.basis() for g in gens]) def polynomial(self): """ diff --git a/src/sage/rings/function_field/order_polymod.py b/src/sage/rings/function_field/order_polymod.py index 2f4224f84f3..51a6251a8e3 100644 --- a/src/sage/rings/function_field/order_polymod.py +++ b/src/sage/rings/function_field/order_polymod.py @@ -237,7 +237,7 @@ def _ideal_from_vectors(self, vecs): vecs = [[(d * c).numerator() for c in v] for v in vecs] return self._ideal_from_vectors_and_denominator(vecs, d, check=False) - def _ideal_from_vectors_and_denominator(self, vecs, d=1, check=True): + def _ideal_from_vectors_and_denominator(self, vecs, d=1, check: bool = True): """ Return an ideal generated as a module by vectors divided by ``d`` over the polynomial ring underlying the rational function field. diff --git a/src/sage/rings/function_field/place.py b/src/sage/rings/function_field/place.py index a17c97b7316..a4fb7c1b0e9 100644 --- a/src/sage/rings/function_field/place.py +++ b/src/sage/rings/function_field/place.py @@ -81,7 +81,7 @@ class FunctionFieldPlace(Element): sage: L.places_finite()[0] # needs sage.rings.function_field Place (x, y) """ - def __init__(self, parent, prime): + def __init__(self, parent, prime) -> None: """ Initialize the place. @@ -96,7 +96,7 @@ def __init__(self, parent, prime): self._prime = prime - def __hash__(self): + def __hash__(self) -> int: """ Return the hash of the place. @@ -110,7 +110,7 @@ def __hash__(self): """ return hash((self.function_field(), self._prime)) - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the place. @@ -129,7 +129,7 @@ def _repr_(self): gens_str = ', '.join(repr(g) for g in gens) return "Place ({})".format(gens_str) - def _latex_(self): + def _latex_(self) -> str: r""" Return the LaTeX representation of the place. @@ -335,7 +335,7 @@ class PlaceSet(UniqueRepresentation, Parent): """ Element = FunctionFieldPlace - def __init__(self, field): + def __init__(self, field) -> None: """ Initialize the set of places of the function ``field``. @@ -351,7 +351,7 @@ def __init__(self, field): self._field = field - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the place. diff --git a/src/sage/rings/function_field/place_polymod.py b/src/sage/rings/function_field/place_polymod.py index c651ea2f5b3..a03ff377393 100644 --- a/src/sage/rings/function_field/place_polymod.py +++ b/src/sage/rings/function_field/place_polymod.py @@ -142,7 +142,7 @@ def gaps(self): [[1, 2, 4], [1, 2, 4], [1, 2, 4]] """ if self.degree() == 1: - return self._gaps_rational() # faster for rational places + return self._gaps_rational() # faster for rational places else: return self._gaps_wronskian() @@ -182,7 +182,7 @@ def _gaps_rational(self): # Hess' Riemann-Roch basis algorithm stripped down for gaps computation def dim_RR(M): den = lcm([e.denominator() for e in M.list()]) - mat = matrix(R, M.nrows(), [(den*e).numerator() for e in M.list()]) + mat = matrix(R, M.nrows(), [(den * e).numerator() for e in M.list()]) # initialise pivot_row and conflicts list pivot_row = [[] for i in range(n)] @@ -191,13 +191,13 @@ def dim_RR(M): bestp = -1 best = -1 for c in range(n): - d = mat[i,c].degree() + d = mat[i, c].degree() if d >= best: bestp = c best = d if best >= 0: - pivot_row[bestp].append((i,best)) + pivot_row[bestp].append((i, best)) if len(pivot_row[bestp]) > 1: conflicts.append(bestp) @@ -205,42 +205,42 @@ def dim_RR(M): while conflicts: c = conflicts.pop() row = pivot_row[c] - i,ideg = row.pop() - j,jdeg = row.pop() + i, ideg = row.pop() + j, jdeg = row.pop() if jdeg > ideg: - i,j = j,i - ideg,jdeg = jdeg,ideg + i, j = j, i + ideg, jdeg = jdeg, ideg - coeff = - mat[i,c].lc() / mat[j,c].lc() + coeff = - mat[i, c].lc() / mat[j, c].lc() s = coeff * one.shift(ideg - jdeg) mat.add_multiple_of_row(i, j, s) - row.append((j,jdeg)) + row.append((j, jdeg)) bestp = -1 best = -1 for c in range(n): - d = mat[i,c].degree() + d = mat[i, c].degree() if d >= best: bestp = c best = d if best >= 0: - pivot_row[bestp].append((i,best)) + pivot_row[bestp].append((i, best)) if len(pivot_row[bestp]) > 1: conflicts.append(bestp) dim = 0 for j in range(n): - i,ideg = pivot_row[j][0] + i, ideg = pivot_row[j][0] k = den.degree() - ideg + 1 if k > 0: dim += k return dim - V,fr,to = F.vector_space() + V, fr, to = F.vector_space() prime_inv = ~ self.prime_ideal() I = O.ideal(1) @@ -264,7 +264,7 @@ def dim_RR(M): else: prev = dim i += 1 - else: # self is a finite place + else: # self is a finite place Binv = B.inverse() while g: I = I * prime_inv @@ -305,7 +305,7 @@ def _gaps_wronskian(self): from sage.modules.free_module_element import vector F = self.function_field() - R,fr_R,to_R = self._residue_field() + R, fr_R, to_R = self._residue_field() der = F.higher_derivation() sep = self.local_uniformizer() @@ -480,8 +480,8 @@ def _residue_field(self, name=None): Obasis = O.basis() M = prime.hnf() - R = M.base_ring() # univariate polynomial ring - n = M.nrows() # extension degree of the function field + R = M.base_ring() # univariate polynomial ring + n = M.nrows() # extension degree of the function field # Step 1: construct a vector space representing the residue field # @@ -492,8 +492,8 @@ def _residue_field(self, name=None): # coefficients of the polynomials. V is the space of these vectors. k = F.constant_base_field() - degs = [M[i,i].degree() for i in range(n)] - deg = sum(degs) # degree of the place + degs = [M[i, i].degree() for i in range(n)] + deg = sum(degs) # degree of the place # Let V = k**deg @@ -540,7 +540,7 @@ def candidates(): # over k (as there are finite number of intermediate fields). a = O._kummer_gen if a is not None: - K,fr_K,_ = self.place_below().residue_field() + K, fr_K, _ = self.place_below().residue_field() b = fr_K(K.gen()) if isinstance(k, (NumberField, sage.rings.abc.AlgebraicField)): kk = ZZ @@ -559,9 +559,9 @@ def candidates(): # Trial 3: exhaustive search in O using only polynomials # with coefficients 0 or 1 for d in range(deg): - G = itertools.product(itertools.product([0,1],repeat=d+1), repeat=n) + G = itertools.product(itertools.product([0, 1], repeat=d + 1), repeat=n) for g in G: - gen = sum([R(c1)*c2 for c1,c2 in zip(g, Obasis)]) + gen = sum([R(c1) * c2 for c1, c2 in zip(g, Obasis)]) yield gen # Trial 4: exhaustive search in O using all polynomials @@ -577,7 +577,7 @@ def candidates(): if g[j].leading_coefficient() != 1: continue - gen = sum([c1*c2 for c1,c2 in zip(g, Obasis)]) + gen = sum([c1 * c2 for c1, c2 in zip(g, Obasis)]) yield gen # Search for a primitive element. It is such an element g of O @@ -616,7 +616,7 @@ def to_W(e): prim = min_poly.roots(K)[0][0] W, from_W, to_W = K.vector_space(k, basis=[prim**i for i in range(deg)], map=True) - else: # deg == 1 + else: # deg == 1 K = k def from_W(e): @@ -638,7 +638,7 @@ def from_K(e): # at this place and no other poles at finite places. p = prime.prime_below().gen().numerator() beta = prime._beta - alpha = ~p * sum(c1*c2 for c1,c2 in zip(beta, Obasis)) + alpha = ~p * sum(c1 * c2 for c1, c2 in zip(beta, Obasis)) alpha_powered_by_ramification_index = alpha ** prime._ramification_index def to_K(f): @@ -648,8 +648,8 @@ def to_K(f): # s powered by the valuation of den at the prime alpha_power = alpha_powered_by_ramification_index ** den.valuation(p) - rn = num * alpha_power # in O - rd = den * alpha_power # in O but not in prime + rn = num * alpha_power # in O + rd = den * alpha_power # in O but not in prime # Note that rn is not in O if and only if f is # not in the valuation ring. Hence f is in the diff --git a/src/sage/rings/function_field/place_rational.py b/src/sage/rings/function_field/place_rational.py index 31ffd6a40b0..af479cffda4 100644 --- a/src/sage/rings/function_field/place_rational.py +++ b/src/sage/rings/function_field/place_rational.py @@ -142,7 +142,7 @@ def to_K(f): K, from_K, _to_K = O._residue_field(prime, name=name) def to_K(f): - if f in O: # f.denominator() is 1 + if f in O: # f.denominator() is 1 return _to_K(f.numerator()) else: d = F(f.denominator()) @@ -157,8 +157,8 @@ def to_K(f): raise TypeError("not in the valuation ring") s = ~prime.gen() - rd = d * s**dv # in O but not in prime - rn = n * s**nv # in O but not in prime + rd = d * s**dv # in O but not in prime + rn = n * s**nv # in O but not in prime return to_K(rn) / to_K(rd) return K, from_K, to_K diff --git a/src/sage/rings/function_field/valuation.py b/src/sage/rings/function_field/valuation.py index e92600e55b6..fc585d4a252 100644 --- a/src/sage/rings/function_field/valuation.py +++ b/src/sage/rings/function_field/valuation.py @@ -616,7 +616,7 @@ def element_with_valuation(self, s): return super().element_with_valuation(s) a, b = self.value_group()._element_with_valuation(constant_valuation.value_group(), s) - ret = self.uniformizer()**a * constant_valuation.element_with_valuation(constant_valuation.value_group().gen()*b) + ret = self.uniformizer()**a * constant_valuation.element_with_valuation(constant_valuation.value_group().gen() * b) return self.simplify(ret, error=s) @@ -634,7 +634,7 @@ class ClassicalFunctionFieldValuation_base(DiscreteFunctionFieldValuation_base): sage: isinstance(v, ClassicalFunctionFieldValuation_base) True """ - def _test_classical_residue_field(self, **options): + def _test_classical_residue_field(self, **options) -> None: r""" Check correctness of the residue field of a discrete valuation at a classical point. @@ -680,7 +680,7 @@ class InducedRationalFunctionFieldValuation_base(FunctionFieldValuation_base): sage: K. = FunctionField(QQ) sage: v = K.valuation(x^2 + 1) # indirect doctest """ - def __init__(self, parent, base_valuation): + def __init__(self, parent, base_valuation) -> None: r""" TESTS:: @@ -779,7 +779,7 @@ def reduce(self, f): assert not ret.is_zero() return self.residue_field()(ret) - def _repr_(self): + def _repr_(self) -> str: r""" Return a printable representation of this valuation. @@ -874,7 +874,7 @@ def restriction(self, ring): return self._base_valuation.restriction(ring) return super().restriction(ring) - def simplify(self, f, error=None, force=False): + def simplify(self, f, error=None, force: bool = False): r""" Return a simplified version of ``f``. @@ -924,10 +924,10 @@ def simplify(self, f, error=None, force=False): # This case is not implemented yet, so we just return f which is always safe. return f - numerator = self.domain()(self._base_valuation.simplify(numerator, error=error+v_denominator, force=force)) - denominator = self.domain()(self._base_valuation.simplify(denominator, error=max(v_denominator, error - v_numerator + 2*v_denominator), force=force)) + numerator = self.domain()(self._base_valuation.simplify(numerator, error=error + v_denominator, force=force)) + denominator = self.domain()(self._base_valuation.simplify(denominator, error=max(v_denominator, error - v_numerator + 2 * v_denominator), force=force)) - ret = numerator/denominator + ret = numerator / denominator assert self(ret - f) > error return ret @@ -991,7 +991,7 @@ class FiniteRationalFunctionFieldValuation(InducedRationalFunctionFieldValuation sage: q = L.valuation(x^6 - t); q (x^6 + 2*t)-adic valuation """ - def __init__(self, parent, base_valuation): + def __init__(self, parent, base_valuation) -> None: r""" TESTS:: @@ -1018,7 +1018,7 @@ class NonClassicalRationalFunctionFieldValuation(InducedRationalFunctionFieldVal sage: w = K.valuation(v); w # indirect doctest 2-adic valuation """ - def __init__(self, parent, base_valuation): + def __init__(self, parent, base_valuation) -> None: r""" TESTS: @@ -1092,7 +1092,7 @@ class FunctionFieldFromLimitValuation(FiniteExtensionFromLimitValuation, Discret sage: w = v.extension(L); w # needs sage.rings.function_field (x - 1)-adic valuation """ - def __init__(self, parent, approximant, G, approximants): + def __init__(self, parent, approximant, G, approximants) -> None: r""" TESTS:: @@ -1157,7 +1157,7 @@ class FunctionFieldMappedValuation_base(FunctionFieldValuation_base, MappedValua sage: v = K.valuation(1/x); v Valuation at the infinite place """ - def __init__(self, parent, base_valuation, to_base_valuation_domain, from_base_valuation_domain): + def __init__(self, parent, base_valuation, to_base_valuation_domain, from_base_valuation_domain) -> None: r""" TESTS:: @@ -1225,7 +1225,7 @@ def scale(self, scalar): return self.domain().valuation((self._base_valuation.scale(scalar), self._to_base, self._from_base)) return super().scale(scalar) - def _repr_(self): + def _repr_(self) -> str: r""" Return a printable representation of this valuation. @@ -1273,7 +1273,7 @@ class FunctionFieldMappedValuationRelative_base(FunctionFieldMappedValuation_bas sage: v = K.valuation(1/x); v Valuation at the infinite place """ - def __init__(self, parent, base_valuation, to_base_valuation_domain, from_base_valuation_domain): + def __init__(self, parent, base_valuation, to_base_valuation_domain, from_base_valuation_domain) -> None: r""" TESTS:: @@ -1318,7 +1318,7 @@ class RationalFunctionFieldMappedValuation(FunctionFieldMappedValuationRelative_ [ Gauss valuation induced by 2-adic valuation, v(x) = 1 ] (in Rational function field in x over Rational Field after x |--> 1/x) """ - def __init__(self, parent, base_valuation, to_base_valuation_doain, from_base_valuation_domain): + def __init__(self, parent, base_valuation, to_base_valuation_doain, from_base_valuation_domain) -> None: r""" TESTS:: @@ -1344,7 +1344,7 @@ class InfiniteRationalFunctionFieldValuation(FunctionFieldMappedValuationRelativ sage: K. = FunctionField(QQ) sage: v = K.valuation(1/x) # indirect doctest """ - def __init__(self, parent): + def __init__(self, parent) -> None: r""" TESTS:: @@ -1355,11 +1355,11 @@ def __init__(self, parent): True """ x = parent.domain().gen() - FunctionFieldMappedValuationRelative_base.__init__(self, parent, FunctionFieldValuation(parent.domain(), x), parent.domain().hom([1/x]), parent.domain().hom([1/x])) + FunctionFieldMappedValuationRelative_base.__init__(self, parent, FunctionFieldValuation(parent.domain(), x), parent.domain().hom([1 / x]), parent.domain().hom([1 / x])) RationalFunctionFieldValuation_base.__init__(self, parent) ClassicalFunctionFieldValuation_base.__init__(self, parent) - def _repr_(self): + def _repr_(self) -> str: r""" Return a printable representation of this valuation. @@ -1401,7 +1401,7 @@ class FunctionFieldExtensionMappedValuation(FunctionFieldMappedValuationRelative sage: isinstance(w, FunctionFieldExtensionMappedValuation) # needs sage.rings.function_field True """ - def _repr_(self): + def _repr_(self) -> str: r""" Return a printable representation of this valuation. diff --git a/src/sage/rings/function_field/valuation_ring.py b/src/sage/rings/function_field/valuation_ring.py index 9269d21ea2d..1c29214bea5 100644 --- a/src/sage/rings/function_field/valuation_ring.py +++ b/src/sage/rings/function_field/valuation_ring.py @@ -91,7 +91,7 @@ class FunctionFieldValuationRing(UniqueRepresentation, Parent): sage: p.valuation_ring() Valuation ring at Place (x, x*y) """ - def __init__(self, field, place, category=None): + def __init__(self, field, place, category=None) -> None: """ Initialize. @@ -134,7 +134,7 @@ def _element_constructor_(self, x): else: raise TypeError - def _repr_(self): + def _repr_(self) -> str: """ Return the string representation of the valuation ring. @@ -206,6 +206,6 @@ def residue_field(self, name=None): from .maps import FunctionFieldRingMorphism as morphism k, from_k, to_k = self._place._residue_field(name=name) - mor_from_k = morphism(Hom(k,self), from_k) - mor_to_k = morphism(Hom(self,k), to_k) + mor_from_k = morphism(Hom(k, self), from_k) + mor_to_k = morphism(Hom(self, k), to_k) return k, mor_from_k, mor_to_k