Skip to content

Commit 79f8fe2

Browse files
committed
python-style loops in sage.graphs
1 parent 04232a4 commit 79f8fe2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/sage/graphs/chrompoly.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
185185
# Breadth first search from 0:
186186
bfs_reorder[0] = 0
187187
mpz_init(tot[0]) # sets to 0
188-
for i from 0 < i < nverts:
188+
for i in range(1, nverts):
189189
bfs_reorder[i] = -1
190190
mpz_init(tot[i]) # sets to 0
191191
mpz_init(tot[nverts]) # sets to 0
@@ -230,12 +230,12 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
230230
for i in range(nverts):
231231
mpz_clear(tot[i])
232232
raise
233-
for i from 0 <= i <= nverts:
233+
for i in range(nverts + 1):
234234
mpz_init(coeffs[i]) # also sets them to 0
235235
mpz_init(coeff)
236236
mpz_init_set_si(m, -1)
237237
# start with the zero polynomial: f(x) = 0
238-
for i from nverts >= i > 0:
238+
for i in range(nverts, 0, -1): # nverts >= i > 0
239239
if not mpz_sgn(tot[i]):
240240
continue
241241
mpz_neg(m, m)
@@ -244,7 +244,7 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
244244
# f += tot[i]*m*x*(x-1)**(i-1)
245245
mpz_addmul(coeffs[i], m, tot[i])
246246
mpz_set_si(coeff, 1)
247-
for j from 1 <= j < i:
247+
for j in range(1, i):
248248
# an iterative method for binomial coefficients...
249249
mpz_mul_si(coeff, coeff, j-i)
250250
mpz_divexact_ui(coeff, coeff, j)
@@ -254,13 +254,13 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
254254
mpz_mul(coeff, coeff, m)
255255
coeffs_ZZ = []
256256
cdef Integer c_ZZ
257-
for i from 0 <= i <= nverts:
257+
for i in range(nverts + 1):
258258
c_ZZ = Integer(0)
259259
mpz_set(c_ZZ.value, coeffs[i])
260260
coeffs_ZZ.append(c_ZZ)
261261
f = R(coeffs_ZZ)
262262

263-
for i from 0 <= i <= nverts:
263+
for i in range(nverts + 1):
264264
mpz_clear(tot[i])
265265
mpz_clear(coeffs[i])
266266

src/sage/graphs/matchpoly.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def matching_polynomial(G, complement=True, name=None):
223223
if complement and G.density() > 0.5: # this cutoff could probably be tuned
224224
f_comp = matching_polynomial(G.complement()).list()
225225
f = x.parent().zero()
226-
for i from 0 <= i <= nverts / 2: # implicit floor
226+
for i in range(nverts / 2 + 1): # implicit floor
227227
j = nverts - 2 * i
228228
f += complete_poly(j) * f_comp[j] * (-1)**i
229229
return f

0 commit comments

Comments
 (0)