Skip to content

Commit 5c5b8df

Browse files
committed
suggested details
1 parent 57c55ae commit 5c5b8df

File tree

5 files changed

+55
-76
lines changed

5 files changed

+55
-76
lines changed

src/sage/coding/binary_code.pyx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,14 +3373,16 @@ cdef class BinaryCodeClassifier:
33733373
e[k] = 0 # see state 12 and 17
33743374
state = 2 # continue down the tree
33753375

3376-
elif state == 5: # same as state 3, but in the case where we haven't yet defined zeta
3377-
# i.e. this is our first time down the tree. Once we get to the bottom,
3378-
# we will have zeta = nu = rho, so we do:
3376+
elif state == 5:
3377+
# same as state 3, but in the case where we haven't yet defined zeta
3378+
# i.e. this is our first time down the tree. Once we get to the bottom,
3379+
# we will have zeta = nu = rho, so we do:
33793380
zf__Lambda_zeta[k] = Lambda[k]
33803381
zb__Lambda_rho[k] = Lambda[k]
33813382
state = 4
33823383

3383-
elif state == 6: # at this stage, there is no reason to continue downward, so backtrack
3384+
elif state == 6:
3385+
# at this stage, there is no reason to continue downward, so backtrack
33843386
j = k
33853387

33863388
# return to the longest ancestor nu[i] of nu that could have a
@@ -3401,9 +3403,10 @@ cdef class BinaryCodeClassifier:
34013403
else:
34023404
k = hh-1
34033405
# TODO: is the following line necessary?
3404-
if k == -1: k = 0
3406+
if k == -1:
3407+
k = 0
34053408

3406-
if hb > k:# update hb since we are backtracking
3409+
if hb > k: # update hb since we are backtracking
34073410
hb = k
34083411
# if j == hh, then all nodes lower than our current position are equivalent, so bail out
34093412
if j == hh:

src/sage/libs/singular/singular.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ cdef Rational si2sa_QQ(number *n, number **nn, ring *_ring):
104104
nom = nlGetNumerator(n, _ring.cf)
105105
mpz_init(nom_z)
106106

107-
if (SR_HDL(nom) & SR_INT):
107+
if SR_HDL(nom) & SR_INT:
108108
mpz_set_si(nom_z, SR_TO_INT(nom))
109109
else:
110110
mpz_set(nom_z,nom.z)
@@ -116,7 +116,7 @@ cdef Rational si2sa_QQ(number *n, number **nn, ring *_ring):
116116
denom = nlGetDenom(n, _ring.cf)
117117
mpz_init(denom_z)
118118

119-
if (SR_HDL(denom) & SR_INT):
119+
if SR_HDL(denom) & SR_INT:
120120
mpz_set_si(denom_z, SR_TO_INT(denom))
121121
else:
122122
mpz_set(denom_z,denom.z)

src/sage/rings/finite_rings/element_base.pyx

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ cdef class FiniteRingElement(CommutativeRingElement):
8888
if self.is_one():
8989
if gcd == 1:
9090
return [self] if all else self
91-
else:
92-
nthroot = K.zeta(gcd)
93-
return [nthroot**a for a in range(gcd)] if all else nthroot
91+
nthroot = K.zeta(gcd)
92+
return [nthroot**a for a in range(gcd)] if all else nthroot
9493
if gcd == q-1:
9594
if all:
9695
return []
97-
else:
98-
raise ValueError("no nth root")
96+
raise ValueError("no nth root")
9997
gcd, alpha, _ = n.xgcd(q-1) # gcd = alpha*n + beta*(q-1), so 1/n = alpha/gcd (mod q-1)
10098
if gcd == 1:
10199
return [self**alpha] if all else self**alpha
@@ -105,8 +103,7 @@ cdef class FiniteRingElement(CommutativeRingElement):
105103
if self**q1overn != 1:
106104
if all:
107105
return []
108-
else:
109-
raise ValueError("no nth root")
106+
raise ValueError("no nth root")
110107
self = self**alpha
111108
if cunningham:
112109
from sage.rings.factorint import factor_cunningham
@@ -136,12 +133,11 @@ cdef class FiniteRingElement(CommutativeRingElement):
136133
if all:
137134
nthroot = K.zeta(n)
138135
L = [self]
139-
for i in range(1,n):
136+
for i in range(1, n):
140137
self *= nthroot
141138
L.append(self)
142139
return L
143-
else:
144-
return self
140+
return self
145141
else:
146142
raise ValueError("unknown algorithm")
147143

@@ -243,10 +239,11 @@ cdef class FinitePolyExtElement(FiniteRingElement):
243239
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
244240
R = PolynomialRing(self.parent().prime_subfield(), var)
245241
return R(self.__pari__().minpoly('x').lift())
246-
elif algorithm == 'matrix':
242+
243+
if algorithm == 'matrix':
247244
return self.matrix().minpoly(var)
248-
else:
249-
raise ValueError("unknown algorithm '%s'" % algorithm)
245+
246+
raise ValueError("unknown algorithm '%s'" % algorithm)
250247

251248
# We have two names for the same method
252249
# for compatibility with sage.matrix
@@ -505,8 +502,7 @@ cdef class FinitePolyExtElement(FiniteRingElement):
505502
"""
506503
if self.parent().degree()>1:
507504
return self.polynomial()._latex_()
508-
else:
509-
return str(self)
505+
return str(self)
510506

511507
def __pari__(self, var=None):
512508
r"""
@@ -626,10 +622,11 @@ cdef class FinitePolyExtElement(FiniteRingElement):
626622
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
627623
R = PolynomialRing(self.parent().prime_subfield(), var)
628624
return R(self.__pari__().charpoly('x').lift())
629-
elif algorithm == 'matrix':
625+
626+
if algorithm == 'matrix':
630627
return self.matrix().charpoly(var)
631-
else:
632-
raise ValueError("unknown algorithm '%s'" % algorithm)
628+
629+
raise ValueError("unknown algorithm '%s'" % algorithm)
633630

634631
def norm(self):
635632
"""
@@ -659,10 +656,7 @@ cdef class FinitePolyExtElement(FiniteRingElement):
659656
"""
660657
f = self.charpoly('x')
661658
n = f[0]
662-
if f.degree() % 2:
663-
return -n
664-
else:
665-
return n
659+
return -n if f.degree() % 2 else n
666660

667661
def trace(self):
668662
"""
@@ -926,8 +920,7 @@ cdef class FinitePolyExtElement(FiniteRingElement):
926920
if n <= 0:
927921
if all:
928922
return []
929-
else:
930-
raise ValueError
923+
raise ValueError
931924
return [self] if all else self
932925
if n < 0:
933926
self = ~self
@@ -936,13 +929,11 @@ cdef class FinitePolyExtElement(FiniteRingElement):
936929
if self == 1:
937930
if all:
938931
return [a for a in self.parent().list() if a != 0]
939-
else:
940-
return self
932+
return self
941933
else:
942934
if all:
943935
return []
944-
else:
945-
raise ValueError
936+
raise ValueError
946937
if extend:
947938
raise NotImplementedError
948939
n = Integer(n)

src/sage/rings/finite_rings/integer_mod.pyx

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,19 +1507,16 @@ cdef class IntegerMod_abstract(FiniteRingElement):
15071507
if self == 1:
15081508
if all:
15091509
return [K(a) for a in range(1, K.order())]
1510-
else:
1511-
return self
1510+
return self
15121511
else:
15131512
if all:
15141513
return []
1515-
else:
1516-
raise ValueError
1514+
raise ValueError
15171515
F = K.factored_order()
15181516
if len(F) == 0:
15191517
if all:
15201518
return [self]
1521-
else:
1522-
return self
1519+
return self
15231520
if len(F) != 1:
15241521
if all:
15251522
# we should probably do a first pass to see if there are any solutions so that we don't get giant intermediate lists and waste time...
@@ -1539,24 +1536,20 @@ cdef class IntegerMod_abstract(FiniteRingElement):
15391536
if n < 0:
15401537
if all:
15411538
return []
1542-
else:
1543-
raise ValueError
1539+
raise ValueError
15441540
if all:
15451541
if k == 1:
15461542
return [self]
1547-
else:
1548-
minval = max(1, (k/n).ceil())
1549-
return [K(a*p**minval) for a in range(p**(k-minval))]
1550-
else:
1551-
return self
1543+
minval = max(1, (k/n).ceil())
1544+
return [K(a*p**minval) for a in range(p**(k-minval))]
1545+
return self
15521546
if n < 0:
15531547
try:
15541548
self = ~self
15551549
except ZeroDivisionError:
15561550
if all:
15571551
return []
1558-
else:
1559-
raise ValueError
1552+
raise ValueError
15601553
n = -n
15611554
if p == 2 and k == 1:
15621555
return [self] if all else self
@@ -1565,8 +1558,7 @@ cdef class IntegerMod_abstract(FiniteRingElement):
15651558
if not n.divides(pval):
15661559
if all:
15671560
return []
1568-
else:
1569-
raise ValueError("no nth root")
1561+
raise ValueError("no nth root")
15701562
if pval > 0:
15711563
if all:
15721564
return [K(a.lift()*p**(pval // n) + p**(k - (pval - pval//n)) * b) for a in mod(upart, p**(k-pval)).nth_root(n, all=True, algorithm=algorithm) for b in range(p**(pval - pval//n))]
@@ -1580,27 +1572,23 @@ cdef class IntegerMod_abstract(FiniteRingElement):
15801572
if n % 2 == 0:
15811573
if all:
15821574
return []
1583-
else:
1584-
raise ValueError("no nth root")
1575+
raise ValueError("no nth root")
15851576
else:
15861577
sign = [-1]
15871578
self = -self
15881579
elif n % 2 == 0:
15891580
if k > 2 and self % 8 == 5:
15901581
if all:
15911582
return []
1592-
else:
1593-
raise ValueError("no nth root")
1583+
raise ValueError("no nth root")
15941584
sign = [1, -1]
15951585
if k == 2:
15961586
if all:
15971587
return [K(s) for s in sign[:2]]
1598-
else:
1599-
return K(sign[0])
1588+
return K(sign[0])
16001589
if all:
1601-
modp = [mod(self,8)]
1602-
else:
1603-
modp = mod(self,8)
1590+
modp = [mod(self, 8)]
1591+
modp = mod(self, 8)
16041592
else:
16051593
sign = [1]
16061594
modp = self % p
@@ -1614,13 +1602,11 @@ cdef class IntegerMod_abstract(FiniteRingElement):
16141602
if self == 1:
16151603
if all:
16161604
return [s*K(p*a+m.lift()) for a in range(p**(k-(2 if p==2 else 1))) for m in modp for s in sign]
1617-
else:
1618-
return K(modp.lift())
1605+
return K(modp.lift())
16191606
else:
16201607
if all:
16211608
return []
1622-
else:
1623-
raise ValueError("no nth root")
1609+
raise ValueError("no nth root")
16241610
if all:
16251611
ans = [plog // n + p**(k - nval) * i for i in range(p**nval)]
16261612
ans = [s*K(R.teichmuller(m) * a.exp()) for a in ans for m in modp for s in sign]

src/sage/rings/polynomial/polynomial_element.pyx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,8 +1175,7 @@ cdef class Polynomial(CommutativePolynomial):
11751175
cdef Py_ssize_t d = self.degree()
11761176
if 0 <= i <= d:
11771177
return self.get_unsafe(i)
1178-
else:
1179-
return self._parent._base.zero()
1178+
return self._parent._base.zero()
11801179

11811180
cdef get_unsafe(self, Py_ssize_t i):
11821181
"""
@@ -1822,13 +1821,14 @@ cdef class Polynomial(CommutativePolynomial):
18221821
cdef Polynomial _right = right
18231822
if self.is_term():
18241823
return _right._mul_term(self, term_on_right=False)
1825-
elif _right.is_term():
1824+
1825+
if _right.is_term():
18261826
return self._mul_term(_right, term_on_right=True)
18271827

1828-
elif self._parent.is_exact():
1828+
if self._parent.is_exact():
18291829
return self._mul_karatsuba(right)
1830-
else:
1831-
return self._mul_generic(right)
1830+
1831+
return self._mul_generic(right)
18321832

18331833
cpdef Polynomial _mul_trunc_(self, Polynomial right, long n):
18341834
r"""
@@ -6814,8 +6814,7 @@ cdef class Polynomial(CommutativePolynomial):
68146814
if len(e) == 1:
68156815
if e[0] == 0:
68166816
return []
6817-
else:
6818-
return [(infinity.infinity, e[0])]
6817+
return [(infinity.infinity, e[0])]
68196818

68206819
if e[0] == 0:
68216820
slopes = []
@@ -6831,8 +6830,8 @@ cdef class Polynomial(CommutativePolynomial):
68316830
slopes = slopes[:-1]
68326831
points = points[:-1]
68336832
s = -(v-points[-1][1])/(e[i]-points[-1][0])
6834-
slopes.append((s,e[i]-points[-1][0]))
6835-
points.append((e[i],v))
6833+
slopes.append((s, e[i]-points[-1][0]))
6834+
points.append((e[i], v))
68366835

68376836
return slopes
68386837

0 commit comments

Comments
 (0)