Skip to content

Commit 7ac55dd

Browse files
committed
various small details in padics
1 parent 665a3fa commit 7ac55dd

12 files changed

+84
-62
lines changed

src/sage/rings/padics/common_conversion.pyx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ cdef long get_ordp(x, PowComputer_class prime_pow) except? -10000:
127127
else:
128128
curterm = get_ordp(a, prime_pow)
129129
k = min(k, curterm + shift, maxordp)
130-
if e != 1: shift += 1
130+
if e != 1:
131+
shift += 1
131132
# We don't want to multiply by e again.
132133
return k
133134
elif isinstance(x, pAdicGenericElement):
@@ -206,7 +207,8 @@ cdef long get_preccap(x, PowComputer_class prime_pow) except? -10000:
206207
else:
207208
curterm = get_preccap(a, prime_pow)
208209
k = min(k, curterm + shift)
209-
if e != 1: shift += 1
210+
if e != 1:
211+
shift += 1
210212
# We don't want to multiply by e again.
211213
return k
212214
elif isinstance(x, pAdicGenericElement):
@@ -242,7 +244,8 @@ cdef long comb_prec(iprec, long prec) except? -10000:
242244
243245
- ``prec`` -- a long
244246
"""
245-
if iprec is infinity: return prec
247+
if iprec is infinity:
248+
return prec
246249
cdef Integer intprec
247250
if isinstance(iprec, Integer):
248251
intprec = <Integer>iprec
@@ -302,13 +305,13 @@ cdef int _process_args_and_kwds(long *aprec, long *rprec, args, kwds, bint absol
302305
raise TypeError("_call_with_args() got multiple values for keyword argument 'relprec'")
303306
relprec = args[1]
304307
else:
305-
relprec = kwds.get("relprec",infinity)
308+
relprec = kwds.get("relprec", infinity)
306309
if len(args) >= 1:
307310
if "absprec" in kwds:
308311
raise TypeError("_call_with_args() got multiple values for keyword argument 'absprec'")
309312
absprec = args[0]
310313
else:
311-
absprec = kwds.get("absprec",infinity)
314+
absprec = kwds.get("absprec", infinity)
312315
if absolute:
313316
aprec[0] = comb_prec(absprec, prime_pow.ram_prec_cap)
314317
rprec[0] = comb_prec(relprec, maxordp)

src/sage/rings/padics/local_generic_element.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ cdef class LocalGenericElement(CommutativeRingElement):
377377

378378
# make sure that start and stop are nonnegative
379379
if start<0:
380-
i += -start # fix the value of ppow below
380+
i += -start # fix the value of ppow below
381381
start = 0
382382
stop = max(stop, 0)
383383

src/sage/rings/padics/morphism.pyx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,11 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism):
259259
sage: f * g
260260
Frobenius endomorphism on 5-adic Unramified Extension ... lifting a |--> a^(5^7) on the residue field
261261
"""
262-
if isinstance(right,FrobeniusEndomorphism_padics):
263-
return self.__class__(self.domain(), self._power+right.power())
264-
else:
265-
return RingHomomorphism._composition(self,right)
262+
if isinstance(right, FrobeniusEndomorphism_padics):
263+
return self.__class__(self.domain(), self._power + right.power())
264+
return RingHomomorphism._composition(self, right)
266265

267-
def is_injective(self):
266+
def is_injective(self) -> bool:
268267
"""
269268
Return ``True`` since any power of the Frobenius endomorphism
270269
over an unramified `p`-adic field is always injective.
@@ -278,7 +277,7 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism):
278277
"""
279278
return True
280279

281-
def is_surjective(self):
280+
def is_surjective(self) -> bool:
282281
"""
283282
Return ``True`` since any power of the Frobenius endomorphism
284283
over an unramified `p`-adic field is always surjective.
@@ -292,7 +291,7 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism):
292291
"""
293292
return True
294293

295-
def is_identity(self):
294+
def is_identity(self) -> bool:
296295
"""
297296
Return ``True`` if this morphism is the identity morphism.
298297

src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
462462
else:
463463
poly = x._ntl_rep_abs()[0]
464464
if absprec is infinity:
465-
self._set_from_ZZ_pX_rel(&(<ntl_ZZ_pX>poly).x,(<ntl_ZZ_pX>poly).c, rprec)
465+
self._set_from_ZZ_pX_rel(&(<ntl_ZZ_pX>poly).x,
466+
(<ntl_ZZ_pX>poly).c, rprec)
466467
else:
467-
self._set_from_ZZ_pX_both(&(<ntl_ZZ_pX>poly).x,(<ntl_ZZ_pX>poly).c, aprec, rprec)
468+
self._set_from_ZZ_pX_both(&(<ntl_ZZ_pX>poly).x,
469+
(<ntl_ZZ_pX>poly).c, aprec, rprec)
468470
elif x.parent() is parent.fraction_field():
469471
_x = <pAdicZZpXCRElement>x
470472
if _x.relprec < 0:
@@ -963,7 +965,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
963965
mpz_set(tmp_m, den_unit)
964966
mpz_to_ZZ(&den_zz, tmp_m)
965967
mpz_clear(tmp_m)
966-
#The context has been restored in setting self.relprec
968+
# The context has been restored in setting self.relprec
967969
ZZ_p_div(tmp_zp, ZZ_to_ZZ_p(num_zz), ZZ_to_ZZ_p(den_zz))
968970
ZZ_pX_SetCoeff(self.unit, 0, tmp_zp)
969971
self.ordp = 0
@@ -1062,13 +1064,15 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
10621064
cdef long curval
10631065
cdef ZZ_c tmp_z
10641066
while mini == -1:
1065-
if not ZZ_IsZero(ZZX_coeff(poly,i)):
1066-
minval = ZZ_remove(tmp_z, ZZX_coeff(poly, i), self.prime_pow.pow_ZZ_tmp(1)[0])
1067+
if not ZZ_IsZero(ZZX_coeff(poly, i)):
1068+
minval = ZZ_remove(tmp_z, ZZX_coeff(poly, i),
1069+
self.prime_pow.pow_ZZ_tmp(1)[0])
10671070
mini = i
10681071
i += 1
10691072
while i <= deg:
1070-
if not ZZ_IsZero(ZZX_coeff(poly,i)):
1071-
curval = ZZ_remove(tmp_z, ZZX_coeff(poly, i), self.prime_pow.pow_ZZ_tmp(1)[0])
1073+
if not ZZ_IsZero(ZZX_coeff(poly, i)):
1074+
curval = ZZ_remove(tmp_z, ZZX_coeff(poly, i),
1075+
self.prime_pow.pow_ZZ_tmp(1)[0])
10721076
if curval < minval:
10731077
minval = curval
10741078
mini = i
@@ -2978,7 +2982,8 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
29782982
v = self._new_c(rp)
29792983
cdef pAdicZZpXCRElement u = self.unit_part()
29802984
cdef long goal
2981-
if n is not None: goal = rp - n + self.ordp
2985+
if n is not None:
2986+
goal = rp - n + self.ordp
29822987
while u.relprec > 0:
29832988
v = self._new_c(rp)
29842989
self.prime_pow.teichmuller_set_c(&v.unit, &u.unit, rp)
@@ -2987,11 +2992,13 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement):
29872992
L.append(v)
29882993
elif rp == goal:
29892994
return v
2990-
if rp == 1: break
2995+
if rp == 1:
2996+
break
29912997
ZZ_pX_sub(u.unit, u.unit, v.unit)
29922998
u.relprec = -u.relprec
29932999
u._normalize()
2994-
if u.relprec == 0: break
3000+
if u.relprec == 0:
3001+
break
29953002
rp -= 1
29963003
u.ordp -= 1
29973004
while u.ordp > 0:

src/sage/rings/padics/padic_ext_element.pyx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,16 @@ cdef class pAdicExtElement(pAdicGenericElement):
377377
R = self.parent()
378378
if R.absolute_e() != 1:
379379
raise NotImplementedError("Frobenius automorphism only implemented for unramified extensions")
380-
if self.is_zero(): return self
380+
if self.is_zero():
381+
return self
381382
L = self.teichmuller_expansion()
382383
ppow = R.uniformizer_pow(self.valuation())
383384
if arithmetic:
384385
exp = R.prime()
385386
else:
386387
exp = R.prime()**(R.absolute_degree()-1)
387388
ans = ppow * L[0]**exp
388-
for m in range(1,len(L)):
389+
for m in range(1, len(L)):
389390
ppow = ppow << 1
390391
ans += ppow * L[m]**exp
391392
return ans
@@ -504,7 +505,7 @@ cdef class pAdicExtElement(pAdicGenericElement):
504505

505506
if absprec == 0:
506507
from sage.rings.finite_rings.integer_mod import Mod
507-
return Mod(0,1)
508+
return Mod(0, 1)
508509
elif absprec == 1:
509510
return R.residue_field()(self.expansion(0))
510511
else:

src/sage/rings/padics/padic_generic_element.pyx

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,13 +1017,14 @@ cdef class pAdicGenericElement(LocalGenericElement):
10171017
elt = self
10181018
while True:
10191019
poly = elt.polynomial()
1020-
vector = V([ poly[i] for i in range(deg) ])
1021-
if vector in W: break
1020+
vector = V([poly[i] for i in range(deg)])
1021+
if vector in W:
1022+
break
10221023
vectors.append(vector)
10231024
W += V.span([vector])
10241025
elt *= self
10251026
W = V.span_of_basis(vectors)
1026-
coeffs = [ -c for c in W.coordinate_vector(vector) ] + [K(1)]
1027+
coeffs = [-c for c in W.coordinate_vector(vector)] + [K(1)]
10271028
return polring(coeffs)
10281029
else:
10291030
raise NotImplementedError
@@ -1492,10 +1493,12 @@ cdef class pAdicGenericElement(LocalGenericElement):
14921493
if self.parent().is_field():
14931494
return self.parent().one()
14941495
1495-
if min(self.valuation(),other.valuation()) >= min(self.precision_absolute(),other.precision_absolute()):
1496-
return self.parent().zero().add_bigoh(min(self.precision_absolute(),other.precision_absolute()))
1496+
if min(self.valuation(), other.valuation()) >= min(self.precision_absolute(), other.precision_absolute()):
1497+
return self.parent().zero().add_bigoh(
1498+
min(self.precision_absolute(), other.precision_absolute()))
14971499
1498-
return self.parent().uniformiser_pow( min(self.valuation(),other.valuation()) )
1500+
return self.parent().uniformiser_pow(
1501+
min(self.valuation(),other.valuation()))
14991502
15001503
@coerce_binop
15011504
def xgcd(self, other):
@@ -2380,7 +2383,8 @@ cdef class pAdicGenericElement(LocalGenericElement):
23802383
a += 1
23812384
p2a = p2a*p
23822385
upper_u = ((aprec+a*e)/(alpha*p2a)).floor()
2383-
if a >= mina and upper_u <= 0: break
2386+
if a >= mina and upper_u <= 0:
2387+
break
23842388
23852389
# We perform this last operation after the test
23862390
# because it is costly and may raise OverflowError
@@ -3755,9 +3759,8 @@ cdef class pAdicGenericElement(LocalGenericElement):
37553759
root = (~root) << (val // n)
37563760
37573761
if all:
3758-
return [ parent(root*zeta) for zeta in K.roots_of_unity(n) ]
3759-
else:
3760-
return parent(root)
3762+
return [parent(root*zeta) for zeta in K.roots_of_unity(n)]
3763+
return parent(root)
37613764
37623765
def _inverse_pth_root(self, twist=None, hint=None):
37633766
r"""
@@ -3844,7 +3847,8 @@ cdef class pAdicGenericElement(LocalGenericElement):
38443847
# we can alternatively update it after each update of x
38453848
# (which is theoretically a bit faster)
38463849
b = ainv - x**p
3847-
if b == 0: break
3850+
if b == 0:
3851+
break
38483852
curprec = b.valuation()
38493853
bexp = iter(b.unit_part().expansion())
38503854
maxprec = prec
@@ -3903,7 +3907,7 @@ cdef class pAdicGenericElement(LocalGenericElement):
39033907
x *= invroottwist**exponent
39043908
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
39053909
S = PolynomialRing(k, name='x')
3906-
AS = S([ coeff, rho ] + (p-2)*[0] + [1])
3910+
AS = S([coeff, rho] + (p-2)*[0] + [1])
39073911
roots = AS.roots()
39083912
if len(roots) == 0:
39093913
return x, curprec
@@ -4364,7 +4368,7 @@ def _AHE_coefficients(p, N, prec):
43644368
cache_internal_prec = 0
43654369
if cache_internal_prec < internal_prec:
43664370
parent = ZpFM(p, internal_prec)
4367-
values = [ parent(1) ]
4371+
values = [parent(1)]
43684372
for i in range(len(values), N):
43694373
c = 0
43704374
dec = 1
@@ -4484,7 +4488,7 @@ cpdef dwork_mahler_coeffs(R, int bd=20):
44844488
for k in range(1, p):
44854489
v.append(v[-1] / R(k))
44864490
if bd > 1:
4487-
R1 = Qp(p, prec=bd) # Need divisions in this calculation
4491+
R1 = Qp(p, prec=bd) # Need divisions in this calculation
44884492
u = [R1(x) for x in v]
44894493
for i in range(1, bd):
44904494
u[0] = ((u[-1] + u[0]) / i) >> 1
@@ -4573,7 +4577,7 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
45734577
cdef long long q, q1, q3, r, r1, r2, s1, s2, k
45744578
cdef array.array vv, ans1
45754579
4576-
if (f == 1 and prec == 1): # Shortcut for this key special case
4580+
if (f == 1 and prec == 1): # Shortcut for this key special case
45774581
ans1 = array.array('l', [0]) * p
45784582
ans1[0] = p-1
45794583
for r in range(1, p-1):
@@ -4585,7 +4589,7 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
45854589
q1 = q - 1
45864590
bd = (p*prec+p-2) // (p-1) - 1
45874591
R = Zp(p, prec, 'fixed-mod')
4588-
if p == 2: # Dwork expansion has denominators when p = 2
4592+
if p == 2: # Dwork expansion has denominators when p = 2
45894593
R1 = Qp(p, prec)
45904594
use_longs = False
45914595
else:
@@ -4606,7 +4610,8 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
46064610
ans = [0 for r in range(q1)]
46074611
ans[0] = -u
46084612
for r in range(1, q1):
4609-
if ans[r]: continue
4613+
if ans[r]:
4614+
continue
46104615
if use_longs:
46114616
s1 = 1
46124617
else:
@@ -4615,7 +4620,7 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
46154620
for j in range(1, f+1):
46164621
k = r1 % p
46174622
r1 = (r1 + k * q1) // p
4618-
if use_longs: # Use Dwork expansion to compute p-adic Gamma
4623+
if use_longs: # Use Dwork expansion to compute p-adic Gamma
46194624
s1 *= -evaluate_dwork_mahler_long(vv, r1*r2 % q3,
46204625
p, bd, k, q3)
46214626
s1 %= q3
@@ -4634,7 +4639,8 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs):
46344639
s **= f // j
46354640
ans[r] = -s
46364641
for i in range(j-1):
4637-
r1 = r1 * p % q1 # Initially r1 == r
4642+
r1 = r1 * p % q1 # Initially r1 == r
46384643
ans[r1] = ans[r]
4639-
if p != 2: return ans
4644+
if p != 2:
4645+
return ans
46404646
return [R(x) for x in ans]

src/sage/rings/padics/padic_printing.pyx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ class pAdicPrinterDefaults(SageObject):
105105
self._max_terse_terms = int(max_terse_terms)
106106
self._sep = sep
107107
if alphabet is None:
108-
self._alphabet = ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z')
108+
txt = '0123456789'
109+
txt += 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
110+
self._alphabet = tuple(txt)
109111
else:
110112
self._alphabet = alphabet
111113

@@ -144,11 +146,11 @@ class pAdicPrinterDefaults(SageObject):
144146
"""
145147
if mode is None:
146148
return self._mode
149+
150+
if mode in ['val-unit', 'series', 'terse', 'digits', 'bars']:
151+
self._mode = mode
147152
else:
148-
if mode in ['val-unit','series','terse','digits','bars']:
149-
self._mode = mode
150-
else:
151-
raise ValueError("invalid printing mode")
153+
raise ValueError("invalid printing mode")
152154

153155
def allow_negatives(self, neg=None):
154156
r"""
@@ -1041,7 +1043,8 @@ cdef class pAdicPrinter_class(SageObject):
10411043
s += "^{%s})" % (elt.precision_absolute())
10421044
else:
10431045
s += "^%s)" % (elt.precision_absolute())
1044-
if s == "": s = "0"
1046+
if s == "":
1047+
return "0"
10451048
return s
10461049
10471050
cdef _repr_spec(self, pAdicGenericElement elt, bint do_latex, bint pos, int mode, bint paren, ram_name):

src/sage/rings/padics/padic_template_element_header.pxi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ AUTHORS:
1919
- David Roe (2012-03-01) -- initial version
2020
"""
2121

22-
#*****************************************************************************
22+
# ***************************************************************************
2323
# Copyright (C) 2012 David Roe <[email protected]>
2424
# William Stein <[email protected]>
2525
#
2626
# Distributed under the terms of the GNU General Public License (GPL)
2727
# as published by the Free Software Foundation; either version 2 of
2828
# the License, or (at your option) any later version.
2929
#
30-
# http://www.gnu.org/licenses/
31-
#*****************************************************************************
30+
# https://www.gnu.org/licenses/
31+
# ***************************************************************************
3232

3333
from sage.structure.element cimport ModuleElement, RingElement
3434
from sage.rings.padics.padic_generic_element cimport pAdicGenericElement
@@ -43,7 +43,6 @@ cdef class pAdicTemplateElement(pAdicGenericElement):
4343
cdef int _get_unit(self, celement value) except -1
4444
cdef pAdicTemplateElement _lshift_c(self, long shift)
4545
cdef pAdicTemplateElement _rshift_c(self, long shift)
46-
#cpdef RingElement _floordiv_c_impl(self, RingElement right)
4746
cdef int check_preccap(self) except -1
4847
cdef pAdicTemplateElement lift_to_precision_c(self, long absprec)
4948
cpdef pAdicTemplateElement unit_part(self)

0 commit comments

Comments
 (0)