Skip to content

Commit e09181b

Browse files
author
Release Manager
committed
sagemathgh-39683: spaces around modulo in combinat and rings adding some space around `%` signs in a few cython files in combinat and rings folders ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. URL: sagemath#39683 Reported by: Frédéric Chapoton Reviewer(s): David Coudert
2 parents 280481b + 54500b0 commit e09181b

15 files changed

+84
-81
lines changed

src/sage/combinat/designs/evenly_distributed_sets.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ cdef class EvenlyDistributedSetsBacktracker:
533533
x += 1
534534
else:
535535
kk += 1
536-
x += m - x%m
536+
x += m - x % m
537537
else:
538538
x += 1
539539

@@ -554,7 +554,7 @@ cdef class EvenlyDistributedSetsBacktracker:
554554
if self.check:
555555
self._check_cosets(kk)
556556
elif self.cosets[x / m]:
557-
x += m - x%m
557+
x += m - x % m
558558
elif kk == 2:
559559
if self.min_orb[x] < x:
560560
x += 1
@@ -649,12 +649,12 @@ cdef class EvenlyDistributedSetsBacktracker:
649649
c = 0
650650
for i in range(self.e):
651651
c += self.cosets[i]
652-
if c != (kk * (kk-1)) / 2:
652+
if 2 * c != (kk * (kk-1)):
653653
raise RuntimeError("the number of elements in cosets is wrong! Got {} instead of {}.".format(c, (kk*(kk-1))/2))
654654

655655
for i in range(kk):
656656
for j in range(i):
657657
if self.cosets[ self.diff[self.B[i]][self.B[j]] / m ] != 1:
658-
raise RuntimeError("self.cosets misses the difference B[{}]-B[{}]".format(i,j))
658+
raise RuntimeError("self.cosets misses the difference B[{}]-B[{}]".format(i, j))
659659

660660
return 0

src/sage/combinat/designs/orthogonal_arrays_find_recursive.pyx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ cpdef find_product_decomposition(int k, int n):
146146
"""
147147
cdef int n1,n2
148148
for n1 in range(2, n):
149-
n2 = n/n1 # n2 is decreasing along the loop
149+
if n % n1:
150+
# we want to iterate only through divisors of n1... it seems
151+
# faster to use that rather than calling the divisors function
152+
continue
153+
n2 = n // n1 # n2 is decreasing along the loop
150154
if n2 < n1:
151155
break
152-
if n%n1: # we want to iterate only through divisors of n1... it seems
153-
# faster to use that rather than calling the divisors function
154-
continue
155156
if is_available(k, n1) and is_available(k, n2):
156157
from sage.combinat.designs.orthogonal_arrays import wilson_construction
157158
return wilson_construction, (None,k,n1,n2,(),False)
@@ -187,11 +188,11 @@ cpdef find_wilson_decomposition_with_one_truncated_group(int k, int n):
187188
"""
188189
cdef int r,u,m
189190
# If there exists a TD(k+1,t) then k+1 < t+2, i.e. k <= t
190-
for r in range(max(1,k),n-1):
191-
u = n%r
191+
for r in range(max(1, k), n - 1):
192+
u = n % r
192193
# We ensure that 1<=u, and that there can exists a TD(k,u), i.e k<u+2
193194
# (unless u == 1)
194-
if u == 0 or (u>1 and k >= u+2):
195+
if u == 0 or (u > 1 and k >= u + 2):
195196
continue
196197

197198
m = n // r

src/sage/combinat/designs/subhypergraph_search.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Methods
114114
# Distributed under the terms of the GNU General Public License (GPL)
115115
# as published by the Free Software Foundation; either version 2 of
116116
# the License, or (at your option) any later version.
117-
# http://www.gnu.org/licenses/
117+
# https://www.gnu.org/licenses/
118118
# ****************************************************************************
119119

120120
from libc.stdlib cimport qsort
@@ -133,7 +133,7 @@ cdef inline int bs_get(uint64_t * bitset, int index) noexcept:
133133
r"""
134134
Return a bit of a bitset
135135
"""
136-
return (bitset[index//64]>>(index%64))&1
136+
return (bitset[index // 64] >> (index % 64)) & 1
137137

138138
cdef inline void bs_set(uint64_t * bitset, int index, int bit) noexcept:
139139
r"""
@@ -142,8 +142,8 @@ cdef inline void bs_set(uint64_t * bitset, int index, int bit) noexcept:
142142
"bit" *MUST* be equal to either 0 or to 1. The code does not involve any
143143
"if".
144144
"""
145-
bitset[index//64] &= ~((<uint64_t> 1)<<index%64)
146-
bitset[index//64] |= (<uint64_t> bit)<<index%64
145+
bitset[index // 64] &= ~((<uint64_t> 1) << index % 64)
146+
bitset[index // 64] |= (<uint64_t> bit) << index % 64
147147

148148
cdef inline int bs_issubset64(uint64_t * b1, uint64_t b2, int limbs) noexcept:
149149
r"""

src/sage/rings/fraction_field_element.pyx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,15 @@ cdef class FractionFieldElement(FieldElement):
519519
"""
520520
if self.is_zero():
521521
return "0"
522-
s = "%s" % self._numerator
522+
s = str(self._numerator)
523523
if self._denominator != 1:
524-
denom_string = str( self._denominator )
524+
denom_string = str(self._denominator)
525525
if self._denominator._is_atomic() and not ('*' in denom_string or '/' in denom_string):
526-
s = "%s/%s"%(self._numerator._coeff_repr(no_space=False),denom_string)
526+
s = "%s/%s" % (self._numerator._coeff_repr(no_space=False),
527+
denom_string)
527528
else:
528-
s = "%s/(%s)"%(self._numerator._coeff_repr(no_space=False),denom_string)
529+
s = "%s/(%s)" % (self._numerator._coeff_repr(no_space=False),
530+
denom_string)
529531
return s
530532

531533
def _latex_(self):
@@ -563,8 +565,8 @@ cdef class FractionFieldElement(FieldElement):
563565
return "0"
564566
if self._denominator == 1:
565567
return latex.latex(self._numerator)
566-
return "\\frac{%s}{%s}"%(latex.latex(self._numerator),
567-
latex.latex(self._denominator))
568+
return "\\frac{%s}{%s}" % (latex.latex(self._numerator),
569+
latex.latex(self._denominator))
568570

569571
def _magma_init_(self, magma):
570572
"""

src/sage/rings/integer_ring.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,13 +801,14 @@ cdef class IntegerRing_class(CommutativeRing):
801801
cdef integer.Integer n_max, n_min, n_width
802802
cdef randstate rstate = current_randstate()
803803
cdef int den = rstate.c_random()-SAGE_RAND_MAX/2
804-
if den == 0: den = 1
804+
if den == 0:
805+
den = 1
805806
if (distribution is None and x is None) or distribution == "1/n":
806807
mpz_set_si(value, (SAGE_RAND_MAX/5*2) / den)
807808
elif distribution is None or distribution == "uniform":
808809
if y is None:
809810
if x is None:
810-
mpz_set_si(value, rstate.c_random()%5 - 2)
811+
mpz_set_si(value, rstate.c_random() % 5 - 2)
811812
else:
812813
n_max = x if isinstance(x, integer.Integer) else self(x)
813814
mpz_urandomm(value, rstate.gmp_state, n_max.value)

src/sage/rings/laurent_series_ring_element.pyx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,7 @@ cdef class LaurentSeries(AlgebraElement):
332332
if self.is_zero():
333333
if self.prec() is infinity:
334334
return "0"
335-
else:
336-
return "O(%s^%s)"%(self._parent.variable_name(),self.prec())
335+
return "O(%s^%s)" % (self._parent.variable_name(), self.prec())
337336
s = " "
338337
v = self.__u.list()
339338
valuation = self.__n
@@ -349,28 +348,28 @@ cdef class LaurentSeries(AlgebraElement):
349348
if not first:
350349
s += " + "
351350
if not atomic_repr and (x[1:].find("+") != -1 or x[1:].find("-") != -1):
352-
x = "(%s)"%x
351+
x = "(%s)" % x
353352
if e == 1:
354-
var = "*%s"%X
353+
var = "*%s" % X
355354
elif e == 0:
356355
var = ""
357356
else:
358-
var = "*%s^%s"%(X,e)
359-
s += "%s%s"%(x,var)
357+
var = "*%s^%s" % (X, e)
358+
s += "%s%s" % (x, var)
360359
first = False
361360
s = s.replace(" + -", " - ")
362361
s = s.replace(" 1*"," ")
363362
s = s.replace(" -1*", " -")
364363
if self.prec() == 0:
365364
bigoh = "O(1)"
366365
elif self.prec() == 1:
367-
bigoh = "O(%s)"%self._parent.variable_name()
366+
bigoh = "O(%s)" % self._parent.variable_name()
368367
else:
369-
bigoh = "O(%s^%s)"%(self._parent.variable_name(),self.prec())
368+
bigoh = "O(%s^%s)" % (self._parent.variable_name(),self.prec())
370369
if self.prec() != infinity:
371370
if s == " ":
372371
return bigoh
373-
s += " + %s"%bigoh
372+
s += " + %s" % bigoh
374373
return s[1:]
375374

376375
def verschiebung(self, n):
@@ -472,20 +471,20 @@ cdef class LaurentSeries(AlgebraElement):
472471
if not first:
473472
s += " + "
474473
if not atomic_repr and e > 0 and (x[1:].find("+") != -1 or x[1:].find("-") != -1):
475-
x = "\\left(%s\\right)"%x
474+
x = "\\left(%s\\right)" % x
476475
if e == 1:
477-
var = "|%s"%X
476+
var = "|%s" % X
478477
elif e == 0:
479478
var = ""
480479
elif e > 0:
481-
var = "|%s^{%s}"%(X,e)
480+
var = "|%s^{%s}" % (X, e)
482481
if e >= 0:
483-
s += "%s%s"%(x,var)
482+
s += "%s%s" % (x, var)
484483
else: # negative e
485484
if e == -1:
486-
s += "\\frac{%s}{%s}"%(x, X)
485+
s += "\\frac{%s}{%s}" % (x, X)
487486
else:
488-
s += "\\frac{%s}{%s^{%s}}"%(x, X,-e)
487+
s += "\\frac{%s}{%s^{%s}}" % (x, X, -e)
489488
first = False
490489
s = s.replace(" + -", " - ")
491490
s = s.replace(" 1|"," ")
@@ -496,12 +495,12 @@ cdef class LaurentSeries(AlgebraElement):
496495
if pr == 0:
497496
bigoh = "O(1)"
498497
elif pr == 1:
499-
bigoh = "O(%s)"%(X,)
498+
bigoh = "O(%s)" % (X,)
500499
else:
501-
bigoh = "O(%s^{%s})"%(X,pr)
500+
bigoh = "O(%s^{%s})" % (X, pr)
502501
if s == " ":
503502
return bigoh
504-
s += " + %s"%bigoh
503+
s += " + %s" % bigoh
505504
return s[1:]
506505

507506
def __hash__(self):

src/sage/rings/morphism.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,9 +2098,9 @@ cdef class RingHomomorphism_from_base(RingHomomorphism):
20982098
"""
20992099
RingHomomorphism.__init__(self, parent)
21002100
if underlying.domain() != parent.domain().base():
2101-
raise ValueError("The given homomorphism has to have the domain %s"%parent.domain().base())
2101+
raise ValueError("The given homomorphism has to have the domain %s" % parent.domain().base())
21022102
if underlying.codomain() != parent.codomain().base():
2103-
raise ValueError("The given homomorphism has to have the codomain %s"%parent.codomain().base())
2103+
raise ValueError("The given homomorphism has to have the codomain %s" % parent.codomain().base())
21042104
if parent.domain().construction()[0] != parent.codomain().construction()[0]:
21052105
raise ValueError(f"domain ({parent.domain()}) and codomain ({parent.codomain()}) must have the same functorial construction over their base rings")
21062106
self._underlying = underlying

src/sage/rings/number_field/number_field_morphisms.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding):
237237
"""
238238
if ambient_field is None:
239239
if K.coerce_embedding() is None:
240-
raise TypeError("No embedding available for %s"%K)
240+
raise TypeError("No embedding available for %s" % K)
241241
Kemb = K
242242
while Kemb.coerce_embedding() is not None:
243243
Kemb = Kemb.coerce_embedding().codomain()
244244
if L.coerce_embedding() is None:
245-
raise TypeError("No embedding available for %s"%L)
245+
raise TypeError("No embedding available for %s" % L)
246246
Lemb = L
247247
while Lemb.coerce_embedding() is not None:
248248
Lemb = Lemb.coerce_embedding().codomain()

src/sage/rings/number_field/totallyreal_data.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ cdef class tr_data:
851851
self.a[k] = lrint(ceil(akmin))
852852
self.amax[k] = lrint(floor(akmax))
853853

854-
if self.a[n-1] == 0 and (n-k)%2 == 1:
854+
if self.a[n-1] == 0 and (n-k) % 2 == 1:
855855
# Can replace alpha by -alpha, so if all
856856
# "odd" coefficients are zero, may assume next
857857
# "odd" coefficient is positive.

src/sage/rings/padics/common_conversion.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ cdef long get_ordp(x, PowComputer_class prime_pow) except? -10000:
156156
return maxordp
157157
k = mpz_remove(temp.value, value.value, prime_pow.prime.value)
158158
else:
159-
raise NotImplementedError("Cannot determine p-adic valuation of an element of %s"%parent(x))
159+
raise NotImplementedError("Cannot determine p-adic valuation of an element of %s" % parent(x))
160160
# Should check for overflow
161161
return k * e
162162

@@ -228,7 +228,7 @@ cdef long get_preccap(x, PowComputer_class prime_pow) except? -10000:
228228
if mpz_cmp_ui(temp.value, 1) != 0:
229229
raise TypeError("cannot coerce from the given integer mod ring (not a power of the same prime)")
230230
else:
231-
raise NotImplementedError("Cannot determine p-adic precision of an element of %s"%parent(x))
231+
raise NotImplementedError("Cannot determine p-adic precision of an element of %s" % parent(x))
232232
return k * e
233233

234234
cdef long comb_prec(iprec, long prec) except? -10000:

0 commit comments

Comments
 (0)