Skip to content

Commit

Permalink
Trac #33298: pycodestyle cleaning in rings/valuations/
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/33298
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): David Coudert
  • Loading branch information
Release Manager committed Feb 14, 2022
2 parents edad8da + 3d65943 commit 90ec768
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 246 deletions.
53 changes: 27 additions & 26 deletions src/sage/rings/valuation/augmented_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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"""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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())

Expand All @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 8 additions & 10 deletions src/sage/rings/valuation/developing_valuation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
[x + 1, 1]
"""
#*****************************************************************************
# ****************************************************************************
# Copyright (C) 2013-2017 Julian Rüth <julian.rueth@fsfe.org>
#
# 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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down Expand Up @@ -335,7 +334,6 @@ def _test_effective_degree(self, **options):
sage: S.<x> = R[]
sage: v = GaussValuation(S)
sage: v._test_effective_degree()
"""
tester = self._tester(**options)
S = tester.some_elements(self.domain().base_ring().some_elements())
Expand Down
Loading

0 comments on commit 90ec768

Please sign in to comment.