From 3d65943a894e29ad879d0d3819d8181a84cced2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Sat, 5 Feb 2022 21:27:53 +0100 Subject: [PATCH] pycodestyle cleaning in rings/valuations/ --- .../rings/valuation/augmented_valuation.py | 53 +++++----- .../rings/valuation/developing_valuation.py | 18 ++-- src/sage/rings/valuation/gauss_valuation.py | 43 ++++---- .../rings/valuation/inductive_valuation.py | 97 +++++++++---------- src/sage/rings/valuation/limit_valuation.py | 24 ++--- src/sage/rings/valuation/mapped_valuation.py | 22 ++--- src/sage/rings/valuation/scaled_valuation.py | 15 ++- src/sage/rings/valuation/trivial_valuation.py | 48 +++------ src/sage/rings/valuation/valuation.py | 36 ++++--- src/sage/rings/valuation/valuation_space.py | 69 +++++++------ .../rings/valuation/valuations_catalog.py | 8 +- src/sage/rings/valuation/value_group.py | 21 ++-- 12 files changed, 208 insertions(+), 246 deletions(-) diff --git a/src/sage/rings/valuation/augmented_valuation.py b/src/sage/rings/valuation/augmented_valuation.py index 863a2c080d6..fbad8a0a39d 100644 --- a/src/sage/rings/valuation/augmented_valuation.py +++ b/src/sage/rings/valuation/augmented_valuation.py @@ -213,7 +213,7 @@ def create_key(self, base_valuation, phi, mu, check=True): if not is_key: raise ValueError(reason) if mu <= base_valuation(phi): - raise ValueError("the value of the key polynomial must strictly increase but `%s` does not exceed `%s`."%(mu, base_valuation(phi))) + raise ValueError("the value of the key polynomial must strictly increase but `%s` does not exceed `%s`." % (mu, base_valuation(phi))) if not isinstance(base_valuation, InductiveValuation): raise TypeError("base_valuation must be inductive") @@ -251,7 +251,7 @@ def create_object(self, version, key): else: return parent.__make_element_class__(InfiniteAugmentedValuation)(parent, base_valuation, phi, mu) - + AugmentedValuation = AugmentedValuationFactory("sage.rings.valuation.augmented_valuation.AugmentedValuation") @@ -361,7 +361,7 @@ def equivalence_unit(self, s, reciprocal=False): """ if reciprocal: ret = self._base_valuation.element_with_valuation(s) - residue = self.reduce(ret*self._base_valuation.element_with_valuation(-s), check=False) + residue = self.reduce(ret * self._base_valuation.element_with_valuation(-s), check=False) assert residue.is_constant() ret *= self.lift(~(residue[0])) else: @@ -407,7 +407,7 @@ def element_with_valuation(self, s): """ if s not in self.value_group(): - raise ValueError("s must be in the value group of the valuation but %r is not in %r."%(s, self.value_group())) + raise ValueError("s must be in the value group of the valuation but %r is not in %r." % (s, self.value_group())) error = s ret = self.domain().one() @@ -433,8 +433,8 @@ def _repr_(self): """ vals = self.augmentation_chain() vals.reverse() - vals = [ "v(%s) = %s"%(v._phi, v._mu) if isinstance(v, AugmentedValuation_base) else str(v) for v in vals ] - return "[ %s ]"%", ".join(vals) + vals = ["v(%s) = %s" % (v._phi, v._mu) if isinstance(v, AugmentedValuation_base) else str(v) for v in vals] + return "[ %s ]" % ", ".join(vals) def augmentation_chain(self): r""" @@ -487,7 +487,7 @@ def psi(self): """ R = self._base_valuation.equivalence_unit(-self._base_valuation(self._phi)) - F = self._base_valuation.reduce(self._phi*R, check=False).monic() + F = self._base_valuation.reduce(self._phi * R, check=False).monic() assert F.is_irreducible() return F @@ -557,7 +557,7 @@ def extensions(self, ring): return [self] from sage.rings.polynomial.polynomial_ring import is_PolynomialRing - if is_PolynomialRing(ring): # univariate + if is_PolynomialRing(ring): # univariate base_valuations = self._base_valuation.extensions(ring) phi = self.phi().change_ring(ring.base_ring()) @@ -572,7 +572,7 @@ def extensions(self, ring): # self(phi) = self._mu, i.e., w(phi) = w(unit) + sum e_i * w(f_i) where # the sum runs over all the factors in the equivalence decomposition of phi # Solving for mu gives - mu = (self._mu - v(F.unit()) - sum([ee*v(ff) for ff,ee in F if ff != f])) / e + mu = (self._mu - v(F.unit()) - sum([ee * v(ff) for ff, ee in F if ff != f])) / e ret.append(AugmentedValuation(v, f, mu)) return ret @@ -591,14 +591,13 @@ def restriction(self, ring): sage: w.restriction(QQ['x']) [ Gauss valuation induced by 2-adic valuation, v(x^2 + x + 1) = 1 ] - """ if ring.is_subring(self.domain()): base = self._base_valuation.restriction(ring) if ring.is_subring(self.domain().base_ring()): return base from sage.rings.polynomial.polynomial_ring import is_PolynomialRing - if is_PolynomialRing(ring): # univariate + if is_PolynomialRing(ring): # univariate return base.augmentation(self.phi().change_ring(ring.base_ring()), self._mu) return super(AugmentedValuation_base, self).restriction(ring) @@ -724,7 +723,7 @@ def scale(self, scalar): """ if scalar in QQ and scalar > 0 and scalar != 1: - return self._base_valuation.scale(scalar).augmentation(self.phi(), scalar*self._mu) + return self._base_valuation.scale(scalar).augmentation(self.phi(), scalar * self._mu) return super(AugmentedValuation_base, self).scale(scalar) def _residue_ring_generator_name(self): @@ -1299,11 +1298,11 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations # rewrite as sum of f_i phi^{i tau}, i.e., drop the coefficients that # can have no influence on the reduction - for i,c in enumerate(coefficients): + for i, c in enumerate(coefficients): if i % tau != 0: if check: v = self._base_valuation(c) + i*self._mu - assert v != 0 # this can not happen for an augmented valuation + assert v != 0 # this can not happen for an augmented valuation if v < 0: raise ValueError("f must not have negative valuation") else: @@ -1329,7 +1328,7 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations C = [self._base_valuation.reduce(c, check=False)(self._residue_field_generator()) if valuations[i] is not infinity else self._base_valuation.residue_ring().zero() - for i,c in enumerate(coefficients)] + for i, c in enumerate(coefficients)] # reduce the Q'^i phi^i return self.residue_ring()(C) @@ -1446,16 +1445,18 @@ def lift(self, F, report_coefficients=False): # in the last step of reduce, the f_iQ^i are reduced, and evaluated at # the generator of the residue field # here, we undo this: - coeffs = [ R0(c if self.psi().degree()==1 else list(c._vector_() if hasattr(c, '_vector_') else c.list())) - for c in F.coefficients(sparse=False) ] - coeffs = [ self._base_valuation.lift(c) for c in coeffs ] + coeffs = [R0(c if self.psi().degree() == 1 + else list(c._vector_() if hasattr(c, '_vector_') + else c.list())) + for c in F.coefficients(sparse=False)] + coeffs = [self._base_valuation.lift(c) for c in coeffs] # now the coefficients correspond to the expansion with (f_iQ^i)(Q^{-1} phi)^i # now we undo the factors of Q^i (the if else is necessary to handle the case when mu is infinity, i.e., when _Q_reciprocal() is undefined) - coeffs = [ (c if i == 0 else c*self._Q_reciprocal(i)).map_coefficients(_lift_to_maximal_precision) - for i,c in enumerate(coeffs) ] + coeffs = [(c if i == 0 else c*self._Q_reciprocal(i)).map_coefficients(_lift_to_maximal_precision) + for i, c in enumerate(coeffs)] # reduce the coefficients mod phi; the part that exceeds phi has no effect on the reduction of the coefficient - coeffs = [ next(self.coefficients(c)) for c in coeffs ] + coeffs = [next(self.coefficients(c)) for c in coeffs] if report_coefficients: return coeffs @@ -1539,7 +1540,7 @@ def lift_to_key(self, F, check=True): return self.phi() coefficients = self.lift(F, report_coefficients=True)[:-1] - coefficients = [c*self._Q(F.degree()) for i,c in enumerate(coefficients)] + [self.domain().one()] + coefficients = [c * self._Q(F.degree()) for i, c in enumerate(coefficients)] + [self.domain().one()] if len(coefficients) >= 2: # In the phi-adic development, the second-highest coefficient could # spill over into the highest coefficient (which is a constant one) @@ -1722,7 +1723,7 @@ def valuations(self, f, coefficients=None, call_error=False): if call_error: lowest_valuation = infinity - for i,c in enumerate(coefficients or self.coefficients(f)): + for i, c in enumerate(coefficients or self.coefficients(f)): if call_error: if lowest_valuation is not infinity: v = self._base_valuation.lower_bound(c) @@ -1824,7 +1825,7 @@ def simplify(self, f, error=None, force=False, effective_degree=None, size_heuri return self.domain().change_ring(self.domain())([ 0 if valuations[i] > error else self._base_valuation.simplify(c, error=error-i*self._mu, force=force, phiadic=True) - for (i,c) in enumerate(coefficients)])(self.phi()) + for (i, c) in enumerate(coefficients)])(self.phi()) else: # We iterate through the coefficients of the polynomial (in the # usual x-adic way) starting from the leading coefficient and try @@ -1874,11 +1875,11 @@ def lower_bound(self, f): if self.phi() == self.domain().gen(): constant_valuation = self.restriction(f.base_ring()) ret = infinity - for i,c in enumerate(f.coefficients(sparse=False)): + for i, c in enumerate(f.coefficients(sparse=False)): v = constant_valuation.lower_bound(c) if v is infinity: continue - v += i*self._mu + v += i * self._mu if ret is infinity or v < ret: ret = v return ret diff --git a/src/sage/rings/valuation/developing_valuation.py b/src/sage/rings/valuation/developing_valuation.py index 3750d777bd1..3cfaa1147c3 100644 --- a/src/sage/rings/valuation/developing_valuation.py +++ b/src/sage/rings/valuation/developing_valuation.py @@ -41,14 +41,14 @@ [x + 1, 1] """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2013-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .valuation import DiscretePseudoValuation from sage.misc.abstract_method import abstract_method @@ -87,11 +87,11 @@ def __init__(self, parent, phi): domain = parent.domain() from sage.rings.polynomial.polynomial_ring import is_PolynomialRing if not is_PolynomialRing(domain) or not domain.ngens() == 1: - raise TypeError("domain must be a univariate polynomial ring but %r is not"%(domain,)) + raise TypeError("domain must be a univariate polynomial ring but %r is not" % (domain,)) phi = domain.coerce(phi) if phi.is_constant() or not phi.is_monic(): - raise ValueError("phi must be a monic non-constant polynomial but %r is not"%(phi,)) + raise ValueError("phi must be a monic non-constant polynomial but %r is not" % (phi,)) self._phi = phi @@ -141,7 +141,7 @@ def effective_degree(self, f, valuations=None): if valuations is None: valuations = list(self.valuations(f)) v = min(valuations) - return [i for i,w in enumerate(valuations) if w == v][-1] + return [i for i, w in enumerate(valuations) if w == v][-1] @cached_method def _pow(self, f, e, error, effective_degree): @@ -212,7 +212,7 @@ def coefficients(self, f): yield domain(c) else: while f.degree() >= 0: - f,r = self._quo_rem(f) + f, r = self._quo_rem(f) yield r def _quo_rem(self, f): @@ -226,13 +226,12 @@ def _quo_rem(self, f): sage: v = GaussValuation(S, QQ.valuation(2)) sage: v._quo_rem(x^2 + 1) (x, 1) - """ return f.quo_rem(self.phi()) def newton_polygon(self, f, valuations=None): r""" - Return the newton polygon of the `\phi`-adic development of ``f``. + Return the Newton polygon of the `\phi`-adic development of ``f``. INPUT: @@ -335,7 +334,6 @@ def _test_effective_degree(self, **options): sage: S. = R[] sage: v = GaussValuation(S) sage: v._test_effective_degree() - """ tester = self._tester(**options) S = tester.some_elements(self.domain().base_ring().some_elements()) diff --git a/src/sage/rings/valuation/gauss_valuation.py b/src/sage/rings/valuation/gauss_valuation.py index ef59c605002..2431b5982ad 100644 --- a/src/sage/rings/valuation/gauss_valuation.py +++ b/src/sage/rings/valuation/gauss_valuation.py @@ -36,14 +36,14 @@ 0 """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2013-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .inductive_valuation import NonFinalInductiveValuation @@ -76,9 +76,8 @@ class GaussValuationFactory(UniqueFactory): 0 sage: w(x + 2) 0 - """ - def create_key(self, domain, v = None): + def create_key(self, domain, v=None): r""" Normalize and check the parameters to create a Gauss valuation. @@ -94,17 +93,17 @@ def create_key(self, domain, v = None): """ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing if not is_PolynomialRing(domain): - raise TypeError("GaussValuations can only be created over polynomial rings but %r is not a polynomial ring"%(domain,)) + raise TypeError("GaussValuations can only be created over polynomial rings but %r is not a polynomial ring" % (domain,)) if not domain.ngens() == 1: - raise NotImplementedError("domain must be univariate but %r is not univariate"%(domain,)) + raise NotImplementedError("domain must be univariate but %r is not univariate" % (domain,)) if v is None: v = domain.base_ring().valuation() if not v.domain() is domain.base_ring(): - raise ValueError("the domain of v must be the base ring of domain but %r is not defined over %r but over %r"%(v, domain.base_ring(), v.domain())) + raise ValueError("the domain of v must be the base ring of domain but %r is not defined over %r but over %r" % (v, domain.base_ring(), v.domain())) if not v.is_discrete_valuation(): - raise ValueError("v must be a discrete valuation but %r is not"%(v,)) + raise ValueError("v must be a discrete valuation but %r is not" % (v,)) return (domain, v) @@ -125,8 +124,10 @@ def create_object(self, version, key, **extra_args): parent = DiscretePseudoValuationSpace(domain) return parent.__make_element_class__(GaussValuation_generic)(parent, v) + GaussValuation = GaussValuationFactory("sage.rings.valuation.gauss_valuation.GaussValuation") + class GaussValuation_generic(NonFinalInductiveValuation): """ A Gauss valuation on a polynomial ring ``domain``. @@ -193,7 +194,7 @@ def value_semigroup(self): sage: v = GaussValuation(S, QQ.valuation(5)) sage: v.value_semigroup() Additive Abelian Semigroup generated by -1, 1 - + """ return self._base_valuation.value_semigroup() @@ -207,9 +208,8 @@ def _repr_(self): sage: v = GaussValuation(S, QQ.valuation(5)) sage: v # indirect doctest Gauss valuation induced by 5-adic valuation - """ - return "Gauss valuation induced by %r"%self._base_valuation + return "Gauss valuation induced by %r" % self._base_valuation @cached_method def uniformizer(self): @@ -359,7 +359,7 @@ def reduce(self, f, check=True, degree_bound=None, coefficients=None, valuations return f.map_coefficients(self._base_valuation.reduce, self._base_valuation.residue_field()) except Exception: if check and not all(v >= 0 for v in self.valuations(f)): - raise ValueError("reduction not defined for non-integral elements and %r is not integral over %r"%(f, self)) + raise ValueError("reduction not defined for non-integral elements and %r is not integral over %r" % (f, self)) raise def lift(self, F): @@ -426,11 +426,11 @@ def lift_to_key(self, F): F = self.residue_ring().coerce(F) if F.is_constant(): - raise ValueError("F must not be constant but %r is constant"%(F,)) + raise ValueError("F must not be constant but %r is constant" % (F,)) if not F.is_monic(): - raise ValueError("F must be monic but %r is not monic"%(F,)) + raise ValueError("F must be monic but %r is not monic" % (F,)) if not F.is_irreducible(): - raise ValueError("F must be irreducible but %r factors"%(F,)) + raise ValueError("F must be irreducible but %r factors" % (F,)) return self.lift(F) @@ -459,7 +459,7 @@ def equivalence_unit(self, s, reciprocal=False): """ if reciprocal: return self.equivalence_reciprocal(self.equivalence_unit(-s)) - + ret = self._base_valuation.element_with_valuation(s) return self.domain()(ret) @@ -647,12 +647,12 @@ def monic_integral_model(self, G): while self(H) < 0: # this might fail if the base ring is not a field factor *= u - substitution = x/factor + substitution = x / factor H = G(substitution) * (factor ** G.degree()) assert H.is_monic() return H.parent().hom(substitution, G.parent()), G.parent().hom(x / substitution[1], H.parent()), H - + def _ge_(self, other): r""" Return whether this valuation is greater than or equal to ``other`` @@ -707,7 +707,7 @@ def _relative_size(self, f): Coefficients is going to lead to a significant shrinking of the Coefficients of ``f``. - EXAMPLES:: + EXAMPLES:: sage: R. = QQ[] sage: v = GaussValuation(R, QQ.valuation(2)) @@ -822,9 +822,8 @@ def upper_bound(self, f): 10 sage: v(1024*x + 1) 0 - """ - f = self.domain().coerce(f) + f = self.domain().coerce(f) coefficients = f.coefficients(sparse=True) if not coefficients: from sage.rings.infinity import infinity diff --git a/src/sage/rings/valuation/inductive_valuation.py b/src/sage/rings/valuation/inductive_valuation.py index 31479167c15..8b0f004c91f 100644 --- a/src/sage/rings/valuation/inductive_valuation.py +++ b/src/sage/rings/valuation/inductive_valuation.py @@ -174,13 +174,13 @@ def equivalence_reciprocal(self, f, coefficients=None, valuations=None, check=Tr if valuations is None: valuations = list(self.valuations(f, coefficients=coefficients)) if not self.is_equivalence_unit(f, valuations=valuations): - raise ValueError("f must be an equivalence unit but %r is not"%(f,)) + raise ValueError("f must be an equivalence unit but %r is not" % (f,)) if coefficients is None: e0 = next(self.coefficients(f)) else: e0 = coefficients[0] - + # f is an equivalence unit, its valuation is given by the constant coefficient if valuations is None: vf = self(e0) @@ -260,7 +260,7 @@ def equivalence_unit(self, s, reciprocal=False): ValueError: s must be in the value semigroup of this valuation but -1 is not in Additive Abelian Semigroup generated by 1 """ - + @abstract_method def augmentation_chain(self): r""" @@ -364,7 +364,7 @@ def element_with_valuation(self, s): Traceback (most recent call last): ... ValueError: s must be in the value semigroup of this valuation but -2 is not in Additive Abelian Semigroup generated by 1 - + """ def _test_element_with_valuation_inductive_valuation(self, **options): @@ -412,7 +412,7 @@ def _test_EF(self, **options): """ tester = self._tester(**options) chain = self.augmentation_chain() - for w,v in zip(chain, chain[1:]): + for w, v in zip(chain, chain[1:]): from sage.rings.infinity import infinity from sage.rings.integer_ring import ZZ if w(w.phi()) is infinity: @@ -431,13 +431,13 @@ def _test_augmentation_chain(self, **options): sage: R. = QQ[] sage: v = GaussValuation(R, valuations.TrivialValuation(QQ)) sage: v._test_augmentation_chain() - + """ tester = self._tester(**options) chain = self.augmentation_chain() tester.assertIs(chain[0], self) tester.assertTrue(chain[-1].is_gauss_valuation()) - for w,v in zip(chain, chain[1:]): + for w, v in zip(chain, chain[1:]): tester.assertGreaterEqual(w, v) def _test_equivalence_unit(self, **options): @@ -510,7 +510,7 @@ def _test_equivalence_reciprocal(self, **options): if self.domain().base() not in Fields(): continue raise - tester.assertEqual(self.reduce(f*g), 1) + tester.assertEqual(self.reduce(f * g), 1) def _test_inductive_valuation_inheritance(self, **options): r""" @@ -644,7 +644,7 @@ def augmentation(self, phi, mu, check=True): Make sure that we do not make the assumption that the degrees of the key polynomials are strictly increasing:: - + sage: v_K = QQ.valuation(3) sage: A. = QQ[] sage: v0 = GaussValuation(A,v_K) @@ -653,7 +653,7 @@ def augmentation(self, phi, mu, check=True): sage: v2 = v1.augmentation(t^12 + 3, 7/6) sage: v3 = v2.augmentation(t^12 + 3*t^2 + 3, 9/4) sage: v4 = v1.augmentation(t^12 + 3*t^2 + 3, 9/4) - sage: v3 <= v4 and v3 >= v4 + sage: v3 <= v4 and v3 >= v4 True .. SEEALSO:: @@ -805,17 +805,17 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a raise ValueError("G must be squarefree") from sage.rings.infinity import infinity - assert self(G) is not infinity # this is a valuation and G is non-zero + assert self(G) is not infinity # this is a valuation and G is non-zero ret = [] F = self.equivalence_decomposition(G, assume_not_equivalence_unit=True, coefficients=coefficients, valuations=valuations, compute_unit=False, degree_bound=principal_part_bound) - assert len(F), "%s equivalence-decomposes as an equivalence-unit %s"%(G, F) + assert len(F), "%s equivalence-decomposes as an equivalence-unit %s" % (G, F) if len(F) == 1 and F[0][1] == 1 and F[0][0].degree() == G.degree(): assert self.is_key(G, assume_equivalence_irreducible=assume_equivalence_irreducible) ret.append((self.augmentation(G, infinity, check=False), G.degree(), principal_part_bound, None, None)) else: - for phi,e in F: + for phi, e in F: if G == phi: # Something strange happened here: # G is not a key (we checked that before) but phi==G is; so phi must have less precision than G @@ -824,7 +824,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a # that really what we should do?) assert not G.base_ring().is_exact() prec = min([c.precision_absolute() for c in phi.list()]) - g = G.map_coefficients(lambda c:c.add_bigoh(prec)) + g = G.map_coefficients(lambda c: c.add_bigoh(prec)) assert self.is_key(g) ret.append((self.augmentation(g, infinity, check=False), g.degree(), principal_part_bound, None, None)) assert len(F) == 1 @@ -876,19 +876,19 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a from sage.geometry.newton_polygon import NewtonPolygon NP = NewtonPolygon(w.newton_polygon(G, valuations=w_valuations).vertices(), last_slope=0) - verbose("Newton-Polygon for v(phi)=%s : %s"%(self(phi), NP), level=11) + verbose("Newton-Polygon for v(phi)=%s : %s" % (self(phi), NP), level=11) slopes = NP.slopes(repetition=True) - multiplicities = {slope : len([s for s in slopes if s == slope]) for slope in slopes} + multiplicities = {slope: len([s for s in slopes if s == slope]) for slope in slopes} slopes = list(multiplicities) if NP.vertices()[0][0] != 0: slopes = [-infinity] + slopes multiplicities[-infinity] = 1 for i, slope in enumerate(slopes): - verbose("Slope = %s"%slope, level=12) + verbose("Slope = %s" % slope, level=12) new_mu = old_mu - slope - new_valuations = [val - (j*slope if slope is not -infinity else (0 if j == 0 else -infinity)) - for j,val in enumerate(w_valuations)] + new_valuations = [val - (j * slope if slope is not -infinity else (0 if j == 0 else -infinity)) + for j, val in enumerate(w_valuations)] if phi.degree() == self.phi().degree(): assert new_mu > self(phi), "the valuation of the key polynomial must increase when the degree stagnates" # phi has already been simplified internally by the @@ -897,11 +897,11 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a # precision it needs to be defined. phi = base.simplify(phi, new_mu, force=True) w = base.augmentation(phi, new_mu, check=False) - verbose("Augmented %s to %s"%(self, w), level=13) + verbose("Augmented %s to %s" % (self, w), level=13) assert slope is -infinity or 0 in w.newton_polygon(G).slopes(repetition=False) from sage.rings.integer_ring import ZZ - assert (phi.degree() / self.phi().degree()) in ZZ + assert (phi.degree() / self.phi().degree()) in ZZ degree_bound = multiplicities[slope] * phi.degree() assert degree_bound <= G.degree() assert degree_bound >= phi.degree() @@ -913,7 +913,7 @@ def mac_lane_step(self, G, principal_part_bound=None, assume_squarefree=False, a assert ret, "a MacLane step produced no augmentations" if not report_degree_bounds_and_caches: - ret = [v for v,_,_,_,_ in ret] + ret = [v for v, _, _, _, _ in ret] return ret def is_key(self, phi, explain=False, assume_equivalence_irreducible=False): @@ -966,7 +966,7 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): r""" Return whether the polynomial ``f`` is minimal with respect to this valuation. - + A polynomial `f` is minimal with respect to `v` if it is not a constant and any non-zero polynomial `h` which is `v`-divisible by `f` has at least the degree of `f`. @@ -1013,7 +1013,7 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): if f.is_constant(): return False - + if not assume_equivalence_irreducible and not self.is_equivalence_irreducible(f): # any factor divides f with respect to this valuation return False @@ -1026,20 +1026,20 @@ def is_minimal(self, f, assume_equivalence_irreducible=False): v = self.extension(domain) f = domain(f) return v.is_minimal(f / f.leading_coefficient()) - + if self.is_gauss_valuation(): if self(f) == 0: F = self.reduce(f, check=False) assert not F.is_constant() return F.is_irreducible() else: - assert(self(f) <= 0) # f is monic + assert(self(f) <= 0) # f is monic # f is not minimal: # Let g be f stripped of its leading term, i.e., g = f - x^n. # Then g and f are equivalent with respect to this valuation # and in particular g divides f with respect to this valuation return False - + if self.is_equivalent(self.phi(), f): assert f.degree() >= self.phi().degree() # If an h divides f with respect to this valuation, then it also divides phi: @@ -1111,7 +1111,7 @@ def _equivalence_reduction(self, f, coefficients=None, valuations=None, degree_b if vv is not infinity and vv == 0 else 0 for c, vv in zip(coefficients, fR_valuations)] - return valuation, phi_divides, self.reduce(f*R, check=False, degree_bound=degree_bound, coefficients=fR_coefficients, valuations=fR_valuations) + return valuation, phi_divides, self.reduce(f * R, check=False, degree_bound=degree_bound, coefficients=fR_coefficients, valuations=fR_valuations) def is_equivalence_irreducible(self, f, coefficients=None, valuations=None): r""" @@ -1280,12 +1280,12 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi v = self.extension(domain) ret = v.equivalence_decomposition(v.domain()(f)) return Factorization([(self._eliminate_denominators(g), e) - for (g,e) in ret], unit=self._eliminate_denominators(ret.unit()), sort=False) + for (g, e) in ret], unit=self._eliminate_denominators(ret.unit()), sort=False) valuation, phi_divides, F = self._equivalence_reduction(f, coefficients=coefficients, valuations=valuations, degree_bound=degree_bound) F = F.factor() from sage.misc.verbose import verbose - verbose("%s factors as %s = %s in reduction"%(f, F.prod(), F), level=20) + verbose("%s factors as %s = %s in reduction" % (f, F.prod(), F), level=20) unit = self.domain().one() if compute_unit: @@ -1295,7 +1295,7 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi if compute_unit: from sage.misc.misc_c import prod - unit *= self.lift(self.residue_ring()(prod([ psi.leading_coefficient()**e for psi,e in F ]))) + unit *= self.lift(self.residue_ring()(prod([psi.leading_coefficient()**e for psi, e in F]))) # A potential speedup that we tried to implement here: # When F factors as T^n - a, then instead of using any lift of T^n - a @@ -1303,26 +1303,27 @@ def equivalence_decomposition(self, f, assume_not_equivalence_unit=False, coeffi # constant coefficient of f[0]. Doing so saved a few invocations of # mac_lane_step but in the end made hardly any difference. - F = [(self.lift_to_key(psi/psi.leading_coefficient()),e) for psi,e in F] + F = [(self.lift_to_key(psi / psi.leading_coefficient()), e) + for psi, e in F] if compute_unit: - for g,e in F: + for g, e in F: v_g = self(g) - unit *= self._pow(self.equivalence_unit(-v_g, reciprocal=True), e, error=-v_g*e, effective_degree=0) + unit *= self._pow(self.equivalence_unit(-v_g, reciprocal=True), e, error=-v_g * e, effective_degree=0) unit = self.simplify(unit, effective_degree=0, force=True) if phi_divides: - for i,(g,e) in enumerate(F): + for i, (g, e) in enumerate(F): if g == self.phi(): - F[i] = (self.phi(),e+phi_divides) + F[i] = (self.phi(), e + phi_divides) break else: - F.append((self.phi(),phi_divides)) + F.append((self.phi(), phi_divides)) ret = Factorization(F, unit=unit, sort=False) if compute_unit: - assert self.is_equivalent(ret.prod(), f) # this might fail because of leading zeros in inexact rings + assert self.is_equivalent(ret.prod(), f) # this might fail because of leading zeros in inexact rings assert self.is_equivalence_unit(ret.unit()) return ret @@ -1387,9 +1388,10 @@ def minimal_representative(self, f): g = h * f vg = self(g) - coeffs = [c if v == vg else c.parent().zero() for v,c in zip(self.valuations(g), self.coefficients(g))] + coeffs = [c if v == vg else c.parent().zero() + for v, c in zip(self.valuations(g), self.coefficients(g))] coeffs[degree] = self.domain().base_ring().one() - ret = sum([c*self._phi**i for i,c in enumerate(coeffs)]) + ret = sum([c * self._phi**i for i, c in enumerate(coeffs)]) assert self.effective_degree(ret) == degree assert ret.is_monic() @@ -1398,7 +1400,7 @@ def minimal_representative(self, f): from sage.structure.factorization import Factorization ret = Factorization([(ret, 1)], unit=e, sort=False) - assert self.is_equivalent(ret.prod(), f) # this might fail because of leading zeros + assert self.is_equivalent(ret.prod(), f) # this might fail because of leading zeros return ret @abstract_method @@ -1482,7 +1484,7 @@ def _eliminate_denominators(self, f): extended_domain = self.domain().change_ring(fractions) g = extended_domain.coerce(f) - + w = self.extension(extended_domain) # drop coefficients whose valuation is not minimal (recursively) valuation = w(g) @@ -1494,7 +1496,7 @@ def _eliminate_denominators(self, f): nonfraction_valuation = self.restriction(nonfractions) # if this fails then there is no equivalent polynomial in the domain of this valuation ret = g.map_coefficients( - lambda c: c.numerator()*nonfraction_valuation.inverse(c.denominator(), + lambda c: c.numerator() * nonfraction_valuation.inverse(c.denominator(), valuation + nonfraction_valuation(c.denominator()) - nonfraction_valuation(c.numerator()) @@ -1503,7 +1505,6 @@ def _eliminate_denominators(self, f): assert w.is_equivalent(f, ret) return ret - def _test_eliminate_denominators(self, **options): r""" Test the correctness of :meth:`_eliminate_denominators`. @@ -1543,7 +1544,7 @@ def _test_lift_to_key(self, **options): """ tester = self._tester(**options) - + try: self.residue_ring() except NotImplementedError: @@ -1572,14 +1573,13 @@ def _test_lift_to_key(self, **options): F = F.change_ring(w.residue_ring()) roots = F.roots(multiplicities=False) tester.assertGreaterEqual(len(roots), 1) - + # check that f has the right reduction if F == F.parent().gen(): tester.assertTrue(self.is_equivalent(f, self.phi())) else: tester.assertEqual(self.reduce(f * self.equivalence_reciprocal(self.equivalence_unit(self(f)))), F) - def _test_is_equivalence_irreducible(self, **options): r""" Test the correctness of :meth:`is_equivalence_irreducible`. @@ -1598,7 +1598,7 @@ def _test_is_equivalence_irreducible(self, **options): continue is_equivalence_irreducible = self.is_equivalence_irreducible(f) F = self.equivalence_decomposition(f) - tester.assertEqual(is_equivalence_irreducible, len(F)==0 or (len(F)==1 and F[0][1]==1)) + tester.assertEqual(is_equivalence_irreducible, len(F) == 0 or (len(F) == 1 and F[0][1] == 1)) if self.is_equivalence_unit(f): tester.assertTrue(f.is_constant() or self.is_equivalence_irreducible(f)) @@ -1689,4 +1689,3 @@ def _lift_to_maximal_precision(c): """ return c if c.parent().is_exact() else c.lift_to_precision() - diff --git a/src/sage/rings/valuation/limit_valuation.py b/src/sage/rings/valuation/limit_valuation.py index 1b6e85983de..a64bc844a75 100644 --- a/src/sage/rings/valuation/limit_valuation.py +++ b/src/sage/rings/valuation/limit_valuation.py @@ -72,15 +72,14 @@ overview can also be found in Section 4.6 of [Rüt2014]_. """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2016-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ -#***************************************************************************** - +# **************************************************************************** from sage.misc.abstract_method import abstract_method from .valuation import DiscretePseudoValuation, InfiniteDiscretePseudoValuation from sage.structure.factory import UniqueFactory @@ -151,8 +150,10 @@ def create_object(self, version, key): parent = DiscretePseudoValuationSpace(base_valuation.domain()) return parent.__make_element_class__(MacLaneLimitValuation)(parent, base_valuation, G) + LimitValuation = LimitValuationFactory("sage.rings.valuation.limit_valuation.LimitValuation") + class LimitValuation_generic(DiscretePseudoValuation): r""" Base class for limit valuations. @@ -188,14 +189,14 @@ class LimitValuation_generic(DiscretePseudoValuation): def __init__(self, parent, approximation): r""" TESTS:: - + sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) sage: v = K.valuation(2) sage: from sage.rings.valuation.limit_valuation import LimitValuation_generic sage: isinstance(v._base_valuation, LimitValuation_generic) True - + """ DiscretePseudoValuation.__init__(self, parent) @@ -379,7 +380,7 @@ class MacLaneLimitValuation(LimitValuation_generic, InfiniteDiscretePseudoValuat def __init__(self, parent, approximation, G): r""" TESTS:: - + sage: R. = QQ[] sage: K. = QQ.extension(x^2 + 1) sage: v = K.valuation(2) @@ -387,7 +388,7 @@ def __init__(self, parent, approximation, G): sage: from sage.rings.valuation.limit_valuation import MacLaneLimitValuation sage: isinstance(u, MacLaneLimitValuation) True - + """ LimitValuation_generic.__init__(self, parent, approximation) InfiniteDiscretePseudoValuation.__init__(self, parent) @@ -528,9 +529,9 @@ def _improve_approximation(self): assume_squarefree=True, assume_equivalence_irreducible=True, check=False, - principal_part_bound=1 if self._approximation.E()*self._approximation.F() == self._approximation.phi().degree() else None, + principal_part_bound=1 if self._approximation.E() * self._approximation.F() == self._approximation.phi().degree() else None, report_degree_bounds_and_caches=True) - assert(len(approximations)==1) + assert(len(approximations) == 1) self._approximation, _, _, self._next_coefficients, self._next_valuations = approximations[0] def _improve_approximation_for_call(self, f): @@ -786,7 +787,7 @@ def _weakly_separating_element(self, other): # phi of the initial approximant must be good enough to separate it # from any other approximant of an extension ret = self._initial_approximation.phi() - assert(self(ret) > other(ret)) # I could not come up with an example where this fails + assert(self(ret) > other(ret)) # I could not come up with an example where this fails return ret else: # if the valuations are sane, it should be possible to separate @@ -839,7 +840,7 @@ def _relative_size(self, f): coefficients is going to lead to a significant shrinking of the coefficients of ``f``. - EXAMPLES:: + EXAMPLES:: sage: K = QQ sage: R. = K[] @@ -945,6 +946,5 @@ def is_negative_pseudo_valuation(self): sage: u = v.extension(L) sage: u.is_negative_pseudo_valuation() False - """ return False diff --git a/src/sage/rings/valuation/mapped_valuation.py b/src/sage/rings/valuation/mapped_valuation.py index 8fec87aee69..87799bc9b20 100644 --- a/src/sage/rings/valuation/mapped_valuation.py +++ b/src/sage/rings/valuation/mapped_valuation.py @@ -6,7 +6,7 @@ Extensions of valuations over finite field extensions `L=K[x]/(G)` are realized through an infinite valuation on `K[x]` which maps `G` to infinity:: - + sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) @@ -81,7 +81,7 @@ def __init__(self, parent, base_valuation): """ DiscretePseudoValuation.__init__(self, parent) - self._base_valuation = base_valuation + self._base_valuation = base_valuation @abstract_method def _repr_(self): @@ -234,7 +234,7 @@ def simplify(self, x, error=None, force=False): Produce an element which differs from ``x`` by an element of valuation strictly greater than the valuation of ``x`` (or strictly greater than ``error`` if set.) - + If ``force`` is not set, then expensive simplifications may be avoided. EXAMPLES:: @@ -420,18 +420,18 @@ class FiniteExtensionFromInfiniteValuation(MappedValuation_base, DiscreteValuati def __init__(self, parent, base_valuation): r""" TESTS:: - + sage: K. = FunctionField(QQ) sage: R. = K[] sage: L. = K.extension(y^2 - x) - + sage: v = K.valuation(0) sage: w = v.extension(L) sage: from sage.rings.valuation.mapped_valuation import FiniteExtensionFromInfiniteValuation sage: isinstance(w, FiniteExtensionFromInfiniteValuation) True sage: TestSuite(w).run() # long time - + """ MappedValuation_base.__init__(self, parent, base_valuation) DiscreteValuation.__init__(self, parent) @@ -510,7 +510,7 @@ def _relative_size(self, x): coefficients is going to lead to a significant shrinking of the coefficients of ``x``. - EXAMPLES:: + EXAMPLES:: sage: K = QQ sage: R. = K[] @@ -662,8 +662,8 @@ def _repr_(self): augmentations = self._base_valuation._initial_approximation.augmentation_chain()[::-1] unique_approximant = None for l in range(len(augmentations)): - if len([a for a in approximants if a[:l+1] == augmentations[:l+1]]) == 1: - unique_approximant = augmentations[:l+1] + if len([a for a in approximants if a[:l + 1] == augmentations[:l + 1]]) == 1: + unique_approximant = augmentations[:l + 1] break assert(unique_approximant is not None) if unique_approximant[0].is_gauss_valuation(): @@ -671,5 +671,5 @@ def _repr_(self): if len(unique_approximant) == 1: return repr(unique_approximant[0]) from .augmented_valuation import AugmentedValuation_base - return "[ %s ]-adic valuation"%(", ".join("v(%r) = %r"%(v._phi, v._mu) if (isinstance(v, AugmentedValuation_base) and v.domain() == self._base_valuation.domain()) else repr(v) for v in unique_approximant)) - return "%s-adic valuation"%(self._base_valuation) + return "[ %s ]-adic valuation" % (", ".join("v(%r) = %r" % (v._phi, v._mu) if (isinstance(v, AugmentedValuation_base) and v.domain() == self._base_valuation.domain()) else repr(v) for v in unique_approximant)) + return "%s-adic valuation" % (self._base_valuation) diff --git a/src/sage/rings/valuation/scaled_valuation.py b/src/sage/rings/valuation/scaled_valuation.py index 6e34d3ce95d..214e209ff26 100644 --- a/src/sage/rings/valuation/scaled_valuation.py +++ b/src/sage/rings/valuation/scaled_valuation.py @@ -12,14 +12,14 @@ - Julian Rüth (2016-11-10): initial version """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2016-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ -#***************************************************************************** +# **************************************************************************** from sage.structure.factory import UniqueFactory @@ -34,7 +34,6 @@ class ScaledValuationFactory(UniqueFactory): sage: 3*ZZ.valuation(2) # indirect doctest 3 * 2-adic valuation - """ def create_key(self, base, s): r""" @@ -44,7 +43,6 @@ def create_key(self, base, s): sage: 3*ZZ.valuation(2) is 2*(3/2*ZZ.valuation(2)) # indirect doctest True - """ from sage.rings.infinity import infinity from sage.rings.rational_field import QQ @@ -63,7 +61,7 @@ def create_key(self, base, s): raise ValueError("s must not be 1") if isinstance(base, ScaledValuation_generic): - return self.create_key(base._base_valuation, s*base._scale) + return self.create_key(base._base_valuation, s * base._scale) return base, s @@ -88,6 +86,7 @@ def create_object(self, version, key): ScaledValuation = ScaledValuationFactory("sage.rings.valuation.scaled_valuation.ScaledValuation") + class ScaledValuation_generic(DiscreteValuation): r""" A valuation which scales another ``base_valuation`` by a finite positive factor ``s``. @@ -121,8 +120,7 @@ def __init__(self, parent, base_valuation, s): """ DiscreteValuation.__init__(self, parent) - - self._base_valuation = base_valuation + self._base_valuation = base_valuation self._scale = s def _repr_(self): @@ -133,9 +131,8 @@ def _repr_(self): sage: 3*ZZ.valuation(2) # indirect doctest 3 * 2-adic valuation - """ - return "%r * %r"%(self._scale, self._base_valuation) + return "%r * %r" % (self._scale, self._base_valuation) def residue_ring(self): r""" diff --git a/src/sage/rings/valuation/trivial_valuation.py b/src/sage/rings/valuation/trivial_valuation.py index abf91cdc025..ddbf9d7e1b7 100644 --- a/src/sage/rings/valuation/trivial_valuation.py +++ b/src/sage/rings/valuation/trivial_valuation.py @@ -12,16 +12,15 @@ Trivial valuation on Rational Field sage: v(1) 0 - """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2016-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. -# http://www.gnu.org/licenses/ -#***************************************************************************** +# https://www.gnu.org/licenses/ +# **************************************************************************** from .valuation import DiscretePseudoValuation, DiscreteValuation, InfiniteDiscretePseudoValuation from .valuation_space import DiscretePseudoValuationSpace @@ -38,7 +37,6 @@ class TrivialValuationFactory(UniqueFactory): Trivial valuation on Rational Field sage: v(1) 0 - """ def __init__(self, clazz, parent, *args, **kwargs): r""" @@ -47,7 +45,6 @@ def __init__(self, clazz, parent, *args, **kwargs): sage: from sage.rings.valuation.trivial_valuation import TrivialValuationFactory sage: isinstance(valuations.TrivialValuation, TrivialValuationFactory) True - """ UniqueFactory.__init__(self, *args, **kwargs) self._class = clazz @@ -61,7 +58,6 @@ def create_key(self, domain): sage: valuations.TrivialValuation(QQ) is valuations.TrivialValuation(QQ) # indirect doctest True - """ return domain, @@ -73,12 +69,12 @@ def create_object(self, version, key, **extra_args): sage: valuations.TrivialValuation(QQ) # indirect doctest Trivial valuation on Rational Field - """ domain, = key parent = self._parent(domain) return parent.__make_element_class__(self._class)(parent) + class TrivialDiscretePseudoValuation_base(DiscretePseudoValuation): r""" Base class for code shared by trivial valuations. @@ -91,7 +87,6 @@ class TrivialDiscretePseudoValuation_base(DiscretePseudoValuation): TESTS:: sage: TestSuite(v).run() # long time - """ def uniformizer(self): r""" @@ -104,7 +99,6 @@ def uniformizer(self): Traceback (most recent call last): ... ValueError: Trivial valuations do not define a uniformizing element - """ raise ValueError("Trivial valuations do not define a uniformizing element") @@ -117,7 +111,6 @@ def is_trivial(self): sage: v = valuations.TrivialPseudoValuation(QQ) sage: v.is_trivial() True - """ return True @@ -130,10 +123,10 @@ def is_negative_pseudo_valuation(self): sage: v = valuations.TrivialPseudoValuation(QQ) sage: v.is_negative_pseudo_valuation() False - """ return False + class TrivialDiscretePseudoValuation(TrivialDiscretePseudoValuation_base, InfiniteDiscretePseudoValuation): r""" The trivial pseudo-valuation that is `\infty` everywhere. @@ -146,7 +139,6 @@ class TrivialDiscretePseudoValuation(TrivialDiscretePseudoValuation_base, Infini TESTS:: sage: TestSuite(v).run() # long time - """ def __init__(self, parent): r""" @@ -156,7 +148,6 @@ def __init__(self, parent): sage: v = valuations.TrivialPseudoValuation(QQ) sage: isinstance(v, TrivialDiscretePseudoValuation) True - """ TrivialDiscretePseudoValuation_base.__init__(self, parent) InfiniteDiscretePseudoValuation.__init__(self, parent) @@ -172,7 +163,6 @@ def _call_(self, x): +Infinity sage: v(1) +Infinity - """ from sage.rings.infinity import infinity return infinity @@ -185,9 +175,8 @@ def _repr_(self): sage: valuations.TrivialPseudoValuation(QQ) # indirect doctest Trivial pseudo-valuation on Rational Field - """ - return "Trivial pseudo-valuation on %r"%(self.domain(),) + return "Trivial pseudo-valuation on %r" % (self.domain(),) def value_group(self): r""" @@ -202,7 +191,6 @@ def value_group(self): Traceback (most recent call last): ... ValueError: The trivial pseudo-valuation that is infinity everywhere does not have a value group. - """ raise ValueError("The trivial pseudo-valuation that is infinity everywhere does not have a value group.") @@ -214,7 +202,6 @@ def residue_ring(self): sage: valuations.TrivialPseudoValuation(QQ).residue_ring() Quotient of Rational Field by the ideal (1) - """ return self.domain().quo(self.domain().one()) @@ -227,7 +214,6 @@ def reduce(self, x): sage: v = valuations.TrivialPseudoValuation(QQ) sage: v.reduce(1) 0 - """ self.domain().coerce(x) return self.residue_ring().zero() @@ -241,9 +227,8 @@ def lift(self, X): sage: v = valuations.TrivialPseudoValuation(QQ) sage: v.lift(v.residue_ring().zero()) 0 - """ - self.residue_ring().coerce(X) # ignore the output + self.residue_ring().coerce(X) # ignore the output return self.domain().zero() def _ge_(self, other): @@ -257,11 +242,11 @@ def _ge_(self, other): sage: w = valuations.TrivialValuation(QQ) sage: v >= w True - """ # the trivial discrete valuation is the biggest valuation return True + class TrivialDiscreteValuation(TrivialDiscretePseudoValuation_base, DiscreteValuation): r""" The trivial valuation that is zero on non-zero elements. @@ -274,7 +259,6 @@ class TrivialDiscreteValuation(TrivialDiscretePseudoValuation_base, DiscreteValu TESTS:: sage: TestSuite(v).run() # long time - """ def __init__(self, parent): r""" @@ -284,7 +268,6 @@ def __init__(self, parent): sage: v = valuations.TrivialValuation(QQ) sage: isinstance(v, TrivialDiscreteValuation) True - """ TrivialDiscretePseudoValuation_base.__init__(self, parent) DiscreteValuation.__init__(self, parent) @@ -300,7 +283,6 @@ def _call_(self, x): +Infinity sage: v(1) 0 - """ from sage.rings.infinity import infinity return infinity if x == 0 else self.codomain().zero() @@ -313,9 +295,8 @@ def _repr_(self): sage: valuations.TrivialValuation(QQ) # indirect doctest Trivial valuation on Rational Field - """ - return "Trivial valuation on %r"%(self.domain(),) + return "Trivial valuation on %r" % (self.domain(),) def value_group(self): r""" @@ -328,7 +309,6 @@ def value_group(self): sage: v = valuations.TrivialValuation(QQ) sage: v.value_group() Trivial Additive Abelian Group - """ from .value_group import DiscreteValueGroup return DiscreteValueGroup(0) @@ -341,7 +321,6 @@ def residue_ring(self): sage: valuations.TrivialValuation(QQ).residue_ring() Rational Field - """ return self.domain() @@ -354,7 +333,6 @@ def reduce(self, x): sage: v = valuations.TrivialValuation(QQ) sage: v.reduce(1) 1 - """ return self.domain().coerce(x) @@ -367,7 +345,6 @@ def lift(self, X): sage: v = valuations.TrivialValuation(QQ) sage: v.lift(v.residue_ring().zero()) 0 - """ return self.residue_ring().coerce(X) @@ -396,13 +373,10 @@ def _ge_(self, other): sage: w = valuations.TrivialValuation(QQ) sage: w >= v False - """ # the trivial discrete valuation is the smallest valuation - if self is other: - return True - return False + return self is other + TrivialValuation = TrivialValuationFactory(TrivialDiscreteValuation, DiscretePseudoValuationSpace, "sage.rings.valuation.trivial_valuation.TrivialValuation") TrivialPseudoValuation = TrivialValuationFactory(TrivialDiscretePseudoValuation, DiscretePseudoValuationSpace, "sage.rings.valuation.trivial_valuation.TrivialPseudoValuation") - diff --git a/src/sage/rings/valuation/valuation.py b/src/sage/rings/valuation/valuation.py index 947cc804b28..8256963d819 100644 --- a/src/sage/rings/valuation/valuation.py +++ b/src/sage/rings/valuation/valuation.py @@ -44,16 +44,15 @@ sage: w.augmentation(x, infinity) [ Gauss valuation induced by 2-adic valuation, v(x) = +Infinity ] - """ -#***************************************************************************** +# **************************************************************************** # Copyright (C) 2013-2017 Julian Rüth # # Distributed under the terms of the GNU General Public License (GPL) # as published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # http://www.gnu.org/licenses/ -#***************************************************************************** +# **************************************************************************** from sage.categories.morphism import Morphism from sage.structure.richcmp import op_EQ, op_NE, op_LE, op_LT, op_GE, op_GT @@ -112,7 +111,7 @@ def is_equivalent(self, f, g): if self(f) is infinity: return self(g) is infinity - return self(f-g) > self(f) + return self(f - g) > self(f) def __hash__(self): r""" @@ -316,6 +315,7 @@ def is_discrete_valuation(self): """ return False + class NegativeInfiniteDiscretePseudoValuation(InfiniteDiscretePseudoValuation): r""" Abstract base class for pseudo-valuations which attain the value `\infty` @@ -664,7 +664,7 @@ def mac_lane_approximants(self, G, assume_squarefree=False, require_final_EF=Tru raise ValueError("G must be defined over the domain of this valuation") from sage.misc.verbose import verbose - verbose("Approximants of %r on %r towards %r"%(self, self.domain(), G), level=3) + verbose("Approximants of %r on %r towards %r" % (self, self.domain(), G), level=3) from sage.rings.valuation.gauss_valuation import GaussValuation @@ -690,14 +690,14 @@ def is_sufficient(leaf, others): return False if require_final_EF and not leaf.ef: return False - if require_maximal_degree and leaf.valuation.phi().degree() != leaf.valuation.E()*leaf.valuation.F(): + if require_maximal_degree and leaf.valuation.phi().degree() != leaf.valuation.E() * leaf.valuation.F(): return False if require_incomparability: if any(leaf.valuation <= o.valuation for o in others): return False return True - seed = MacLaneApproximantNode(GaussValuation(R,self), None, G.degree() == 1, G.degree(), None, None) + seed = MacLaneApproximantNode(GaussValuation(R, self), None, G.degree() == 1, G.degree(), None, None) seed.forced_leaf = is_sufficient(seed, []) def create_children(node): @@ -737,20 +737,18 @@ def reduce_tree(v, w): from sage.all import RecursivelyEnumeratedSet tree = RecursivelyEnumeratedSet([seed], - successors = create_children, - structure = 'forest', - enumeration = 'breadth') + successors=create_children, + structure='forest', + enumeration='breadth') # this is a tad faster but annoying for profiling / debugging if algorithm == 'parallel': - nodes = tree.map_reduce( - map_function = lambda x: [x], - reduce_init = []) + nodes = tree.map_reduce(map_function=lambda x: [x], + reduce_init=[]) elif algorithm == 'serial': from sage.parallel.map_reduce import RESetMapReduce - nodes = RESetMapReduce( - forest = tree, - map_function = lambda x: [x], - reduce_init = []).run_serial() + nodes = RESetMapReduce(forest=tree, + map_function=lambda x: [x], + reduce_init=[]).run_serial() else: raise NotImplementedError(algorithm) leafs = set([node.valuation for node in nodes]) @@ -802,7 +800,7 @@ def _pow(self, x, e, error): else: return self.simplify(x*self._pow(x, e-1, error=error*(e-1)/e), error=error) - def mac_lane_approximant(self, G, valuation, approximants = None): + def mac_lane_approximant(self, G, valuation, approximants=None): r""" Return the approximant from :meth:`mac_lane_approximants` for ``G`` which is approximated by or approximates ``valuation``. @@ -998,7 +996,7 @@ def montes_factorization(self, G, assume_squarefree=False, required_precision=No ret = [w.phi() for w in W] from sage.structure.factorization import Factorization - return Factorization([ (g,1) for g in ret ], simplify=False) + return Factorization([(g, 1) for g in ret], simplify=False) def _ge_(self, other): r""" diff --git a/src/sage/rings/valuation/valuation_space.py b/src/sage/rings/valuation/valuation_space.py index 759d9fc2981..4f3af1b715e 100644 --- a/src/sage/rings/valuation/valuation_space.py +++ b/src/sage/rings/valuation/valuation_space.py @@ -21,7 +21,7 @@ Note that many tests not only in this module do not create instances of valuations directly since this gives the wrong inheritance structure on the resulting objects:: - + sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace sage: from sage.rings.valuation.trivial_valuation import TrivialDiscretePseudoValuation sage: H = DiscretePseudoValuationSpace(QQ) @@ -30,17 +30,17 @@ Traceback (most recent call last): ... AssertionError: False is not true - + Instead, the valuations need to be created through the ``__make_element_class__`` of the containing space:: - + sage: from sage.rings.valuation.trivial_valuation import TrivialDiscretePseudoValuation sage: v = H.__make_element_class__(TrivialDiscretePseudoValuation)(H) sage: v._test_category() - + The factories such as ``TrivialPseudoValuation`` provide the right inheritance structure:: - + sage: v = valuations.TrivialPseudoValuation(QQ) sage: v._test_category() @@ -118,7 +118,7 @@ def __init__(self, domain): from sage.categories.all import Sets UniqueRepresentation.__init__(self) - Homset.__init__(self, domain, DiscreteValuationCodomain(), category = Sets()) + Homset.__init__(self, domain, DiscreteValuationCodomain(), category=Sets()) from sage.categories.domains import Domains if domain not in Domains(): @@ -144,9 +144,9 @@ def _abstract_element_class(self): True """ - class_name = "%s._abstract_element_class"%self.__class__.__name__ + class_name = "%s._abstract_element_class" % self.__class__.__name__ from sage.structure.dynamic_class import dynamic_class - return dynamic_class(class_name, (super(DiscretePseudoValuationSpace,self)._abstract_element_class, self.__class__.ElementMethods)) + return dynamic_class(class_name, (super(DiscretePseudoValuationSpace, self)._abstract_element_class, self.__class__.ElementMethods)) def _get_action_(self, S, op, self_on_left): r""" @@ -185,7 +185,7 @@ def _an_element_(self): def _repr_(self): r""" Return a printable representation of this space. - + EXAMPLES:: sage: from sage.rings.valuation.valuation_space import DiscretePseudoValuationSpace @@ -193,7 +193,7 @@ def _repr_(self): Discrete pseudo-valuations on Rational Field """ - return "Discrete pseudo-valuations on %r"%(self.domain(),) + return "Discrete pseudo-valuations on %r" % (self.domain(),) def __contains__(self, x): r""" @@ -264,7 +264,7 @@ def _element_constructor_(self, x): pass else: return x - raise ValueError("element cannot be converted into the space of %r"%(self,)) + raise ValueError("element cannot be converted into the space of %r" % (self,)) class ElementMethods: r""" @@ -328,7 +328,7 @@ def is_discrete_valuation(self): sage: QQ.valuation(2).is_discrete_valuation() True - + """ def is_negative_pseudo_valuation(self): @@ -396,7 +396,7 @@ def uniformizer(self): Traceback (most recent call last): ... ValueError: Trivial valuations do not define a uniformizing element - + """ @cached_method @@ -463,7 +463,7 @@ def value_semigroup(self): from .value_group import DiscreteValueSemigroup # return the semigroup generated by the elements of the group return DiscreteValueSemigroup([]) + self.value_group() - raise NotImplementedError("cannot determine value semigroup of %r"%(self,)) + raise NotImplementedError("cannot determine value semigroup of %r" % (self,)) def element_with_valuation(self, s): r""" @@ -481,10 +481,10 @@ def element_with_valuation(self, s): from sage.rings.rational_field import QQ s = QQ.coerce(s) if s not in self.value_semigroup(): - raise ValueError("s must be in the value semigroup of this valuation but %r is not in %r"%(s, self.value_semigroup())) + raise ValueError("s must be in the value semigroup of this valuation but %r is not in %r" % (s, self.value_semigroup())) if s == 0: return self.domain().one() - exp = s/self.value_group().gen() + exp = s / self.value_group().gen() if exp not in ZZ: raise NotImplementedError("s must be a multiple of %r but %r is not"%(self.value_group().gen(), s)) ret = self.domain()(self.uniformizer() ** ZZ(exp)) @@ -544,7 +544,6 @@ def residue_field(self): return FunctionField(ret.base_ring().fraction_field(), names=(ret.variable_name(),)) return ret.fraction_field() - @abstract_method def reduce(self, x): r""" @@ -667,7 +666,7 @@ def scale(self, scalar): sage: w = v.scale(3) sage: w(3) 3 - + Scaling can also be done through multiplication with a scalar:: sage: w/3 == v @@ -740,7 +739,7 @@ def separating_element(self, others): if other.is_trivial(): raise ValueError("all valuations must be non-trivial but %r is not"%(other,)) - if len(others)==0: + if len(others) == 0: return self.uniformizer() # see the proof of Lemma 6.9 in http://www1.spms.ntu.edu.sg/~frederique/antchap6.pdf @@ -760,7 +759,7 @@ def separating_element(self, others): while any(other(ret) >= 0 for other in others[:i]): assert(others[i](ret) < 0) ret *= factor - else: # others[i](ret) > 0 + else: # others[i](ret) > 0 # construct an element which approximates a unit with respect to others[i] # and has negative valuation with respect to others[:i] from sage.rings.all import NN @@ -782,7 +781,7 @@ def _strictly_separating_element(self, other): valuation with respect to ``other``. .. NOTE:: - + Overriding this method tends to be a nuisance as you need to handle all possible types (as in Python type) of valuations. This is essentially the same problem that you have when @@ -828,7 +827,7 @@ def _strictly_separating_element(self, other): else: # Since n,nn,d,dd are all non-negative this is essentially equivalent to # a/b > d/n and b/a > nn/dd - # which is + # which is # dd/nn > a/b > d/n assert(dd/nn > d/n) from sage.rings.continued_fraction import continued_fraction @@ -851,7 +850,7 @@ def _strictly_separating_element(self, other): ab_cf.extend([y,1,1]) ab = continued_fraction(ab_cf).value() a,b = ab.numerator(), ab.denominator() - + ret = self.domain()(numerator**a / denominator**b) assert(self(ret) > 0) assert(other(ret) < 0) @@ -930,7 +929,7 @@ def shift(self, x, s): s = ZZ(s / self.value_group().gen()) if s > 0: return x * self.uniformizer()**s - else: # s < 0 + else: # s < 0 if ~self.uniformizer() in self.domain(): return self.domain()(x / self.uniformizer()**(-s)) else: @@ -948,7 +947,7 @@ def simplify(self, x, error=None, force=False): Produce an element which differs from ``x`` by an element of valuation strictly greater than the valuation of ``x`` (or strictly greater than ``error`` if set.) - + If ``force`` is not set, then expensive simplifications may be avoided. EXAMPLES:: @@ -1048,7 +1047,7 @@ def _relative_size(self, x): coefficients is going to lead to a significant shrinking of the coefficients of ``x``. - EXAMPLES:: + EXAMPLES:: sage: v = Qp(2).valuation() sage: v._relative_size(2) @@ -1132,7 +1131,7 @@ def _test_simplify(self, **options): for x in tester.some_elements(X): y = self.simplify(x) tester.assertEqual(self(x), self(y)) - if self(x) >= 0 and has_residue_ring: + if self(x) >= 0 and has_residue_ring: tester.assertEqual(self.reduce(x), self.reduce(y)) if self.is_trivial() and not self.is_discrete_valuation(): @@ -1233,10 +1232,10 @@ def _test_add(self, **options): tester = self._tester(**options) S = self.domain().some_elements() from itertools import product - for x,y in tester.some_elements(product(S,S)): - tester.assertGreaterEqual(self(x+y),min(self(x),self(y))) + for x, y in tester.some_elements(product(S, S)): + tester.assertGreaterEqual(self(x + y), min(self(x), self(y))) if self(x) != self(y): - tester.assertEqual(self(x+y),min(self(x),self(y))) + tester.assertEqual(self(x + y), min(self(x), self(y))) def _test_infinite_zero(self, **options): r""" @@ -1265,11 +1264,11 @@ def _test_mul(self, **options): tester = self._tester(**options) S = self.domain().some_elements() from itertools import product - for x,y in tester.some_elements(product(S,S)): + for x, y in tester.some_elements(product(S, S)): from sage.rings.infinity import infinity if set([self(x), self(y)]) == set([infinity, -infinity]): continue - tester.assertEqual(self(x*y),self(x)+self(y)) + tester.assertEqual(self(x * y), self(x) + self(y)) def _test_no_infinite_units(self, **options): r""" @@ -1342,7 +1341,7 @@ def _test_value_semigroup(self, **options): """ tester = self._tester(**options) - + if self.is_trivial() and not self.is_discrete_valuation(): # the trivial pseudo-valuation does not have a value semigroup return @@ -1361,7 +1360,7 @@ def _test_element_with_valuation(self, **options): """ tester = self._tester(**options) - + if self.is_trivial() and not self.is_discrete_valuation(): # the trivial pseudo-valuation does not have a value semigroup return @@ -1647,7 +1646,7 @@ def _test_inverse(self, **options): tester.assertIs(y.parent(), self.domain()) if self.domain().is_exact(): - tester.assertGreaterEqual(self(x*y - 1), prec) + tester.assertGreaterEqual(self(x * y - 1), prec) class ScaleAction(Action): diff --git a/src/sage/rings/valuation/valuations_catalog.py b/src/sage/rings/valuation/valuations_catalog.py index ebd7c2f8290..0d0f3362768 100644 --- a/src/sage/rings/valuation/valuations_catalog.py +++ b/src/sage/rings/valuation/valuations_catalog.py @@ -1,7 +1,5 @@ -# not using absolute imports here as importing absolute_import would make -# "absolute_import" show up in -completion from sage.rings.padics.padic_valuation import pAdicValuation from sage.rings.function_field.function_field_valuation import FunctionFieldValuation -from sage.rings.valuation.gauss_valuation import GaussValuation -from sage.rings.valuation.trivial_valuation import TrivialDiscretePseudoValuation, TrivialPseudoValuation, TrivialValuation -from sage.rings.valuation.limit_valuation import LimitValuation +from .gauss_valuation import GaussValuation +from .trivial_valuation import TrivialDiscretePseudoValuation, TrivialPseudoValuation, TrivialValuation +from .limit_valuation import LimitValuation diff --git a/src/sage/rings/valuation/value_group.py b/src/sage/rings/valuation/value_group.py index cc0edf113bc..4ef2038f70f 100644 --- a/src/sage/rings/valuation/value_group.py +++ b/src/sage/rings/valuation/value_group.py @@ -201,10 +201,10 @@ def _element_constructor_(self, x): """ x = QQ.coerce(x) - if x == 0 or (self._generator != 0 and x/self._generator in ZZ): + if x == 0 or (self._generator != 0 and x / self._generator in ZZ): return x - raise ValueError("`{0}` is not in {1}.".format(x,self)) + raise ValueError("`{0}` is not in {1}.".format(x, self)) def _repr_(self): r""" @@ -219,7 +219,7 @@ def _repr_(self): """ if self.is_trivial(): return "Trivial Additive Abelian Group" - return "Additive Abelian Group generated by %r"%(self._generator,) + return "Additive Abelian Group generated by %r" % (self._generator,) def __add__(self, other): r""" @@ -271,10 +271,9 @@ def _mul_(self, other, switch_sides=False): Additive Abelian Group generated by 1/4 sage: D * 0 Trivial Additive Abelian Group - """ other = QQ.coerce(other) - return DiscreteValueGroup(self._generator*other) + return DiscreteValueGroup(self._generator * other) def index(self, other): r""" @@ -530,7 +529,7 @@ def _solve_linear_program(self, target): exp = target / self._generators[0] if exp not in NN: return None - return {0 : exp} + return {0: exp} if len(self._generators) == 2 and self._generators[0] == - self._generators[1]: from sage.rings.integer_ring import ZZ @@ -542,7 +541,8 @@ def _solve_linear_program(self, target): from sage.numerical.mip import MixedIntegerLinearProgram, MIPSolverException P = MixedIntegerLinearProgram(maximization=False, solver="ppl") x = P.new_variable(integer=True, nonnegative=True) - constraint = sum([g*x[i] for i,g in enumerate(self._generators)]) == target + constraint = sum([g * x[i] + for i, g in enumerate(self._generators)]) == target P.add_constraint(constraint) P.set_objective(None) try: @@ -574,13 +574,12 @@ def _element_constructor_(self, x): Traceback (most recent call last): ... ValueError: `-1` is not in Additive Abelian Semigroup generated by 1. - """ x = QQ.coerce(x) if x in self._generators or self._solve_linear_program(x) is not None: return x - raise ValueError("`{0}` is not in {1}.".format(x,self)) + raise ValueError("`{0}` is not in {1}.".format(x, self)) def _repr_(self): r""" @@ -674,7 +673,6 @@ def some_elements(self): sage: from sage.rings.valuation.value_group import DiscreteValueSemigroup sage: list(DiscreteValueSemigroup([-3/8,1/2]).some_elements()) [0, -3/8, 1/2, ...] - """ yield self(0) if self.is_trivial(): @@ -683,7 +681,8 @@ def some_elements(self): yield g from sage.rings.integer_ring import ZZ for x in (ZZ**len(self._generators)).some_elements(): - yield QQ.coerce(sum([abs(c)*g for c,g in zip(x,self._generators)])) + yield QQ.coerce(sum([abs(c) * g + for c, g in zip(x, self._generators)])) def is_trivial(self): r"""