Skip to content

Commit 39f1722

Browse files
committed
some pep8 fixes in rings, and activate E221
1 parent 0c390a0 commit 39f1722

File tree

12 files changed

+93
-91
lines changed

12 files changed

+93
-91
lines changed

src/sage/rings/function_field/function_field_polymod.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,11 @@ def monic_integral_model(self, names=None):
418418
raise ValueError("names must contain at most 2 entries")
419419

420420
if self.base_field() is not self.rational_function_field():
421-
L,from_L,to_L = self.simple_model()
422-
ret,ret_to_L,L_to_ret = L.monic_integral_model(names)
423-
from_ret = ret.hom( [from_L(ret_to_L(ret.gen())), from_L(ret_to_L(ret.base_field().gen()))] )
424-
to_ret = self.hom( [L_to_ret(to_L(k.gen())) for k in self._intermediate_fields(self.rational_function_field())] )
421+
L, from_L, to_L = self.simple_model()
422+
ret, ret_to_L, L_to_ret = L.monic_integral_model(names)
423+
from_ret = ret.hom([from_L(ret_to_L(ret.gen())),
424+
from_L(ret_to_L(ret.base_field().gen()))])
425+
to_ret = self.hom([L_to_ret(to_L(k.gen())) for k in self._intermediate_fields(self.rational_function_field())])
425426
return ret, from_ret, to_ret
426427
else:
427428
if self.polynomial().is_monic() and all(c.denominator().is_one() for c in self.polynomial()):
@@ -431,12 +432,12 @@ def monic_integral_model(self, names=None):
431432
return self.change_variable_name(names)
432433
else:
433434
if not names:
434-
names = (self.variable_name()+"_",)
435+
names = (self.variable_name() + "_",)
435436
if len(names) == 1:
436437
names = (names[0], self.rational_function_field().variable_name())
437438

438439
g, d = self._make_monic_integral(self.polynomial())
439-
K,from_K,to_K = self.base_field().change_variable_name(names[1])
440+
K, from_K, to_K = self.base_field().change_variable_name(names[1])
440441
g = g.map_coefficients(to_K)
441442
ret = K.extension(g, names=names[0])
442443
from_ret = ret.hom([self.gen() * d, self.base_field().gen()])
@@ -791,7 +792,7 @@ def free_module(self, base=None, basis=None, map=True):
791792
if not map:
792793
return V
793794
from_V = MapVectorSpaceToFunctionField(V, self)
794-
to_V = MapFunctionFieldToVectorSpace(self, V)
795+
to_V = MapFunctionFieldToVectorSpace(self, V)
795796
return (V, from_V, to_V)
796797

797798
def maximal_order(self):
@@ -982,7 +983,7 @@ def hom(self, im_gens, base_morphism=None):
982983
yy |--> y
983984
984985
"""
985-
if not isinstance(im_gens, (list,tuple)):
986+
if not isinstance(im_gens, (list, tuple)):
986987
im_gens = [im_gens]
987988
if len(im_gens) == 0:
988989
raise ValueError("no images specified")
@@ -1025,11 +1026,11 @@ def genus(self):
10251026
# making the auxiliary ring which only has polynomials
10261027
# with integral coefficients.
10271028
tmpAuxRing = PolynomialRing(self._base_field.constant_field(),
1028-
str(self._base_field.gen())+','+str(self._ring.gen()))
1029+
str(self._base_field.gen()) + ',' + str(self._ring.gen()))
10291030
intMinPoly, d = self._make_monic_integral(self._polynomial)
10301031
curveIdeal = tmpAuxRing.ideal(intMinPoly)
10311032

1032-
singular.lib('normal.lib') #loading genus method in Singular
1033+
singular.lib('normal.lib') # loading genus method in Singular
10331034
return int(curveIdeal._singular_().genus())
10341035

10351036
else:
@@ -1170,7 +1171,7 @@ def _simple_model(self, name='v'):
11701171
B = MS(B)
11711172
M_b = V_to_N(B.solve_left(M_to_V(b)))
11721173
M_a = V_to_N(B.solve_left(M_to_V(a)))
1173-
M_to_N = M.hom([M_a,M_b])
1174+
M_to_N = M.hom([M_a, M_b])
11741175

11751176
return N, N_to_M, M_to_N
11761177

@@ -1285,7 +1286,7 @@ def simple_model(self, name=None):
12851286
if isinstance(self.base_field(), RationalFunctionField):
12861287
# the extension is simple already
12871288
if name == self.variable_name():
1288-
id = Hom(self,self).identity()
1289+
id = Hom(self, self).identity()
12891290
return self, id, id
12901291
else:
12911292
ret = self.base_field().extension(self.polynomial(), names=(name,))
@@ -1299,8 +1300,8 @@ def simple_model(self, name=None):
12991300
self_ = base_.extension(self.polynomial().map_coefficients(to_base_), names=(name,))
13001301
gens_in_base_ = [to_base_(k.gen())
13011302
for k in base._intermediate_fields(base.rational_function_field())]
1302-
to_self_ = self.hom([self_.gen()]+gens_in_base_)
1303-
from_self_ = self_.hom([self.gen(),from_base_(base_.gen())])
1303+
to_self_ = self.hom([self_.gen()] + gens_in_base_)
1304+
from_self_ = self_.hom([self.gen(), from_base_(base_.gen())])
13041305

13051306
# now collapse self_/base_/K(x)
13061307
ret, ret_to_self_, self__to_ret = self_._simple_model(name)
@@ -1549,20 +1550,20 @@ def separable_model(self, names=None):
15491550
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
15501551
R = PolynomialRing(self.constant_base_field(), names=names)
15511552
S = R.remove_var(names[1])
1552-
f = R( L.polynomial().change_variable_name(names[1]).map_coefficients(
1553-
lambda c:c.numerator().change_variable_name(names[0]), S))
1553+
f = R(L.polynomial().change_variable_name(names[1]).map_coefficients(
1554+
lambda c: c.numerator().change_variable_name(names[0]), S))
15541555
f = f.polynomial(R.gen(0)).change_ring(K)
15551556
f /= f.leading_coefficient()
15561557
# f must be separable in the other variable (otherwise it would factor)
15571558
assert f.gcd(f.derivative()).is_one()
15581559

15591560
ret = K.extension(f, names=(names[0],))
15601561
# isomorphisms between L and ret are given by swapping generators
1561-
ret_to_L = ret.hom( [L(L.base_field().gen()), L.gen()] )
1562-
L_to_ret = L.hom( [ret(K.gen()), ret.gen()] )
1562+
ret_to_L = ret.hom([L(L.base_field().gen()), L.gen()])
1563+
L_to_ret = L.hom([ret(K.gen()), ret.gen()])
15631564
# compose with from_L and to_L to get the desired isomorphisms between self and ret
1564-
f = ret.hom( [from_L(ret_to_L(ret.gen())), from_L(ret_to_L(ret.base_field().gen()))] )
1565-
t = self.hom( [L_to_ret(to_L(self.gen())), L_to_ret(to_L(self.base_field().gen()))] )
1565+
f = ret.hom([from_L(ret_to_L(ret.gen())), from_L(ret_to_L(ret.base_field().gen()))])
1566+
t = self.hom([L_to_ret(to_L(self.gen())), L_to_ret(to_L(self.base_field().gen()))])
15661567
return ret, f, t
15671568

15681569
def change_variable_name(self, name):
@@ -1637,13 +1638,13 @@ def change_variable_name(self, name):
16371638
raise ValueError("name must contain at least one string")
16381639
elif len(name) == 1:
16391640
base = self.base_field()
1640-
from_base = to_base = Hom(base,base).identity()
1641+
from_base = to_base = Hom(base, base).identity()
16411642
else:
16421643
base, from_base, to_base = self.base_field().change_variable_name(name[1:])
16431644

16441645
ret = base.extension(self.polynomial().map_coefficients(to_base), names=(name[0],))
1645-
f = ret.hom( [k.gen() for k in self._intermediate_fields(self.rational_function_field())] )
1646-
t = self.hom( [k.gen() for k in ret._intermediate_fields(ret.rational_function_field())] )
1646+
f = ret.hom([k.gen() for k in self._intermediate_fields(self.rational_function_field())])
1647+
t = self.hom([k.gen() for k in ret._intermediate_fields(ret.rational_function_field())])
16471648
return ret, f, t
16481649

16491650

@@ -1701,16 +1702,16 @@ def _inversion_isomorphism(self):
17011702
x |--> x)
17021703
"""
17031704
K = self.base_field()
1704-
R = PolynomialRing(K,'T')
1705+
R = PolynomialRing(K, 'T')
17051706
x = K.gen()
17061707
xinv = 1/x
17071708

17081709
h = K.hom(xinv)
17091710
F_poly = R([h(c) for c in self.polynomial().list()])
17101711
F = K.extension(F_poly)
17111712

1712-
self2F = self.hom([F.gen(),xinv])
1713-
F2self = F.hom([self.gen(),xinv])
1713+
self2F = self.hom([F.gen(), xinv])
1714+
F2self = F.hom([self.gen(), xinv])
17141715

17151716
M, M2F, F2M = F.monic_integral_model('s')
17161717

@@ -1844,7 +1845,7 @@ def genus(self):
18441845
The genus is computed by the Hurwitz genus formula.
18451846
"""
18461847
k, _ = self.exact_constant_field()
1847-
different_degree = self.different().degree() # must be even
1848+
different_degree = self.different().degree() # must be even
18481849
return Integer(different_degree // 2 - self.degree() / k.degree()) + 1
18491850

18501851
def residue_field(self, place, name=None):
@@ -2123,7 +2124,7 @@ def _places_finite(self, degree):
21232124

21242125
for d in degree.divisors():
21252126
for p in K._places_finite(degree=d):
2126-
for prime,_,_ in O.decomposition(p.prime_ideal()):
2127+
for prime, _, _ in O.decomposition(p.prime_ideal()):
21272128
place = prime.place()
21282129
if place.degree() == degree:
21292130
yield place
@@ -2167,7 +2168,7 @@ def _places_infinite(self, degree):
21672168
<generator object ...>
21682169
"""
21692170
Oinf = self.maximal_order_infinite()
2170-
for prime,_,_ in Oinf.decomposition():
2171+
for prime, _, _ in Oinf.decomposition():
21712172
place = prime.place()
21722173
if place.degree() == degree:
21732174
yield place
@@ -2312,7 +2313,7 @@ def number_of_rational_places(self, r=1):
23122313
L = self.L_polynomial()
23132314
Lp = L.derivative()
23142315

2315-
R = IntegerRing()[[L.parent().gen()]] # power series ring
2316+
R = IntegerRing()[[L.parent().gen()]] # power series ring
23162317

23172318
f = R(Lp / L, prec=r)
23182319
n = f[r-1] + q**r + 1
@@ -2408,13 +2409,13 @@ def _maximal_order_basis(self):
24082409
from .hermite_form_polynomial import reversed_hermite_form
24092410

24102411
k = self.constant_base_field()
2411-
K = self.base_field() # rational function field
2412+
K = self.base_field() # rational function field
24122413
n = self.degree()
24132414

24142415
# Construct the defining polynomial of the function field as a
24152416
# two-variate polynomial g in the ring k[y,x] where k is the constant
24162417
# base field.
2417-
S,(y,x) = PolynomialRing(k, names='y,x', order='lex').objgens()
2418+
S, (y, x) = PolynomialRing(k, names='y,x', order='lex').objgens()
24182419
v = self.polynomial().list()
24192420
g = sum([v[i].numerator().subs(x) * y**i for i in range(len(v))])
24202421

@@ -2431,15 +2432,15 @@ def _maximal_order_basis(self):
24312432
gflat = R.zero()
24322433
for m in g.monomials():
24332434
c = g.monomial_coefficient(m).polynomial('zz')
2434-
gflat += R(c) * R(m) # R(m) is a monomial in yy and xx
2435+
gflat += R(c) * R(m) # R(m) is a monomial in yy and xx
24352436

24362437
k_poly = R(k.polynomial('zz'))
24372438

24382439
# invoke Singular
24392440
pols_in_R = normalize(R.ideal([k_poly, gflat]))
24402441

24412442
# reconstruct polynomials in S
2442-
h = R.hom([y,x,k.gen()],S)
2443+
h = R.hom([y, x, k.gen()], S)
24432444
pols_in_S = [h(f) for f in pols_in_R]
24442445
else:
24452446
# Call Singular. Singular's "normal" function returns a basis

src/sage/rings/function_field/function_field_rational.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def _to_polynomial(self, f):
323323
"""
324324
K = f.parent().constant_base_field()
325325
if f.denominator() in K:
326-
return f.numerator()/K(f.denominator())
326+
return f.numerator() / K(f.denominator())
327327
raise ValueError("only polynomials can be converted to the underlying polynomial ring")
328328

329329
def _to_bivariate_polynomial(self, f):
@@ -350,7 +350,8 @@ def _to_bivariate_polynomial(self, f):
350350
v = f.list()
351351
denom = lcm([a.denominator() for a in v])
352352
S = denom.parent()
353-
x,t = S.base_ring()['%s,%s' % (f.parent().variable_name(),self.variable_name())].gens()
353+
x, t = S.base_ring()['%s,%s' % (f.parent().variable_name(),
354+
self.variable_name())].gens()
354355
phi = S.hom([t])
355356
return sum([phi((denom * v[i]).numerator()) * x**i for i in range(len(v))]), denom
356357

@@ -420,20 +421,20 @@ def _factor_univariate_polynomial(self, f, proof=None):
420421
x = f.parent().gen()
421422
t = f.parent().base_ring().gen()
422423
phi = F.parent().hom([x, t])
423-
v = [(phi(P),e) for P, e in fac]
424-
unit = phi(fac.unit())/d
424+
v = [(phi(P), e) for P, e in fac]
425+
unit = phi(fac.unit()) / d
425426
w = []
426427
for a, e in v:
427428
c = a.leading_coefficient()
428-
a = a/c
429+
a = a / c
429430
# undo any variable substitution that we introduced for the bivariate polynomial
430431
if old_variable_name != a.variable_name():
431432
a = a.change_variable_name(old_variable_name)
432433
unit *= (c**e)
433434
if a.is_unit():
434435
unit *= a**e
435436
else:
436-
w.append((a,e))
437+
w.append((a, e))
437438
from sage.structure.factorization import Factorization
438439
return Factorization(w, unit=unit)
439440

@@ -553,7 +554,7 @@ def free_module(self, base=None, basis=None, map=True):
553554
if not map:
554555
return V
555556
from_V = MapVectorSpaceToFunctionField(V, self)
556-
to_V = MapFunctionFieldToVectorSpace(self, V)
557+
to_V = MapFunctionFieldToVectorSpace(self, V)
557558
return (V, from_V, to_V)
558559

559560
def random_element(self, *args, **kwds):
@@ -683,7 +684,7 @@ def hom(self, im_gens, base_morphism=None):
683684
"""
684685
if isinstance(im_gens, CategoryObject):
685686
return self.Hom(im_gens).natural_map()
686-
if not isinstance(im_gens, (list,tuple)):
687+
if not isinstance(im_gens, (list, tuple)):
687688
im_gens = [im_gens]
688689
if len(im_gens) != 1:
689690
raise ValueError("there must be exactly one generator")
@@ -834,8 +835,8 @@ def change_variable_name(self, name):
834835
raise ValueError("names must be a tuple with a single string")
835836
name = name[0]
836837
if name == self.variable_name():
837-
id = Hom(self,self).identity()
838-
return self,id,id
838+
id = Hom(self, self).identity()
839+
return self, id, id
839840
else:
840841
from .constructor import FunctionField
841842
ret = FunctionField(self.constant_base_field(), name)

0 commit comments

Comments
 (0)