Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python-style loops in sage.graphs #36142

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/sage/graphs/chrompoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
# Breadth first search from 0:
bfs_reorder[0] = 0
mpz_init(tot[0]) # sets to 0
for i from 0 < i < nverts:
for i in range(1, nverts):
bfs_reorder[i] = -1
mpz_init(tot[i]) # sets to 0
mpz_init(tot[nverts]) # sets to 0
Expand Down Expand Up @@ -230,12 +230,12 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
for i in range(nverts):
mpz_clear(tot[i])
raise
for i from 0 <= i <= nverts:
for i in range(nverts + 1):
mpz_init(coeffs[i]) # also sets them to 0
mpz_init(coeff)
mpz_init_set_si(m, -1)
# start with the zero polynomial: f(x) = 0
for i from nverts >= i > 0:
for i in range(nverts, 0, -1): # nverts >= i > 0
if not mpz_sgn(tot[i]):
continue
mpz_neg(m, m)
Expand All @@ -244,7 +244,7 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
# f += tot[i]*m*x*(x-1)**(i-1)
mpz_addmul(coeffs[i], m, tot[i])
mpz_set_si(coeff, 1)
for j from 1 <= j < i:
for j in range(1, i):
# an iterative method for binomial coefficients...
mpz_mul_si(coeff, coeff, j-i)
mpz_divexact_ui(coeff, coeff, j)
Expand All @@ -254,13 +254,13 @@ def chromatic_polynomial(G, return_tree_basis=False, algorithm='C', cache=None):
mpz_mul(coeff, coeff, m)
coeffs_ZZ = []
cdef Integer c_ZZ
for i from 0 <= i <= nverts:
for i in range(nverts + 1):
c_ZZ = Integer(0)
mpz_set(c_ZZ.value, coeffs[i])
coeffs_ZZ.append(c_ZZ)
f = R(coeffs_ZZ)

for i from 0 <= i <= nverts:
for i in range(nverts + 1):
mpz_clear(tot[i])
mpz_clear(coeffs[i])

Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/matchpoly.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def matching_polynomial(G, complement=True, name=None):
if complement and G.density() > 0.5: # this cutoff could probably be tuned
f_comp = matching_polynomial(G.complement()).list()
f = x.parent().zero()
for i from 0 <= i <= nverts / 2: # implicit floor
for i in range(nverts / 2 + 1): # implicit floor
dcoudert marked this conversation as resolved.
Show resolved Hide resolved
j = nverts - 2 * i
f += complete_poly(j) * f_comp[j] * (-1)**i
return f
Expand Down
Loading