Skip to content

Commit ef43673

Browse files
committed
cleanup and code details in cluster_algebra_quiver
1 parent 931cc5e commit ef43673

File tree

7 files changed

+194
-209
lines changed

7 files changed

+194
-209
lines changed

src/sage/combinat/cluster_algebra_quiver/all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
- :ref:`sage.combinat.cluster_algebra_quiver.cluster_seed`
99
"""
1010
# install the docstring of this module to the containing package
11+
from sage.misc.lazy_import import lazy_import
1112
from sage.misc.namespace_package import install_doc
12-
install_doc(__package__, __doc__)
1313

14-
from sage.misc.lazy_import import lazy_import
14+
install_doc(__package__, __doc__)
1515
lazy_import("sage.combinat.cluster_algebra_quiver.quiver_mutation_type",
1616
"QuiverMutationType")
1717
lazy_import("sage.combinat.cluster_algebra_quiver.quiver", "ClusterQuiver")

src/sage/combinat/cluster_algebra_quiver/cluster_seed.py

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,9 +2497,9 @@ def mutate(self, sequence, inplace=True, input_type=None):
24972497
sequence = self.first_green_vertex()
24982498
elif sequence == 'red':
24992499
sequence = self.first_red_vertex()
2500-
elif sequence == 'urban' or sequence == 'urban_renewal':
2500+
elif sequence in {'urban', 'urban_renewal'}:
25012501
sequence = self.first_urban_renewal()
2502-
elif sequence == 'all_urbans' or sequence == 'all_urban_renewals':
2502+
elif sequence in {'all_urbans', 'all_urban_renewals'}:
25032503
sequence = self.urban_renewals()
25042504
elif hasattr(self, sequence):
25052505
sequence = getattr(self, sequence)()
@@ -2575,33 +2575,32 @@ def mutate(self, sequence, inplace=True, input_type=None):
25752575
' "indices", or "cluster_vars"')
25762576

25772577
# Classifies the input_type. Raises warnings if the input is ambiguous, and errors if the input is not all of the same type.
2578-
else:
2579-
if is_vertices:
2580-
input_type = "vertices"
2581-
for x in seqq:
2582-
if is_indices and seed._nlist[x] != x:
2583-
print("Input can be ambiguously interpreted as both"
2584-
" vertices and indices."
2578+
elif is_vertices:
2579+
input_type = "vertices"
2580+
for x in seqq:
2581+
if is_indices and seed._nlist[x] != x:
2582+
print("Input can be ambiguously interpreted as both"
2583+
" vertices and indices."
2584+
" Mutating at vertices by default.")
2585+
break
2586+
2587+
elif is_cluster_vars:
2588+
cluster_var_index = seed.cluster_index(x)
2589+
vertex_index = seed._nlist.index(x)
2590+
if isinstance(cluster_var_index, int) and cluster_var_index != vertex_index:
2591+
print("Input can be ambiguously interpreted as"
2592+
" both vertices and cluster variables."
25852593
" Mutating at vertices by default.")
25862594
break
25872595

2588-
elif is_cluster_vars:
2589-
cluster_var_index = seed.cluster_index(x)
2590-
vertex_index = seed._nlist.index(x)
2591-
if isinstance(cluster_var_index, int) and cluster_var_index != vertex_index:
2592-
print("Input can be ambiguously interpreted as"
2593-
" both vertices and cluster variables."
2594-
" Mutating at vertices by default.")
2595-
break
2596-
2597-
# It should be impossible to interpret an index as a cluster variable.
2598-
elif is_indices:
2599-
input_type = "indices"
2600-
elif is_cluster_vars:
2601-
input_type = "cluster_vars"
2602-
else:
2603-
raise ValueError('mutation sequences must consist of exactly'
2604-
' one of vertices, indices, or cluster variables')
2596+
# It should be impossible to interpret an index as a cluster variable.
2597+
elif is_indices:
2598+
input_type = "indices"
2599+
elif is_cluster_vars:
2600+
input_type = "cluster_vars"
2601+
else:
2602+
raise ValueError('mutation sequences must consist of exactly'
2603+
' one of vertices, indices, or cluster variables')
26052604

26062605
if input_type == "cluster_vars" and len(seqq) > 1:
26072606
mutation_seed = deepcopy(seed)
@@ -3497,8 +3496,8 @@ def mutation_class_iter(self, depth=infinity, show_depth=False,
34973496
Check that :issue:`14638` is fixed::
34983497
34993498
sage: S = ClusterSeed(['E',6])
3500-
sage: MC = S.mutation_class(depth=7); len(MC) # long time
3501-
534
3499+
sage: MC = S.mutation_class(depth=6); len(MC) # long time
3500+
388
35023501
35033502
Infinite type examples::
35043503
@@ -4266,11 +4265,10 @@ def greedy(self, a1, a2, algorithm='by_recursion'):
42664265
oddT = set(T).intersection(PathSubset(a1, 0))
42674266
evenT = set(T).symmetric_difference(oddT)
42684267
ans = ans + S.x(0)**(b*len(evenT)) * S.x(1)**(c*len(oddT))
4269-
else:
4270-
if is_LeeLiZel_allowable(T, a2, a1, c, b):
4271-
oddT = set(T).intersection(PathSubset(a2, 0))
4272-
evenT = set(T).symmetric_difference(oddT)
4273-
ans = ans + S.x(0)**(b*len(oddT)) * S.x(1)**(c*len(evenT))
4268+
elif is_LeeLiZel_allowable(T, a2, a1, c, b):
4269+
oddT = set(T).intersection(PathSubset(a2, 0))
4270+
evenT = set(T).symmetric_difference(oddT)
4271+
ans = ans + S.x(0)**(b*len(oddT)) * S.x(1)**(c*len(evenT))
42744272
ans = ans*S.x(0)**(-a1)*S.x(1)**(-a2)
42754273
return ans
42764274
elif algorithm == 'just_numbers':
@@ -4425,15 +4423,15 @@ def find_upper_bound(self, verbose=False):
44254423

44264424
while True:
44274425
R = PolynomialRing(QQ, gens, order='invlex')
4428-
I = R.ideal(rels)
4429-
J = R.ideal(initial_product)
4426+
ideal_I = R.ideal(rels)
4427+
ideal_J = R.ideal(initial_product)
44304428
if verbose:
44314429
msg = 'Computing relations among {} generators'
44324430
print(msg.format(len(gens)))
44334431
start = time.time()
4434-
ISat = I.saturation(J)[0]
4435-
spend = time.time() - start
4432+
ISat = ideal_I.saturation(ideal_J)[0]
44364433
if verbose:
4434+
spend = time.time() - start
44374435
msg = 'Computed {} relations in {} seconds'
44384436
print(msg.format(len(ISat.gens()), spend))
44394437
deep_ideal = R.ideal(deep_gens) + ISat
@@ -4445,7 +4443,7 @@ def find_upper_bound(self, verbose=False):
44454443
spend = time.time() - start
44464444
if M == initial_product_ideal:
44474445
if verbose:
4448-
print('Verified that there are no new elements in', spend, 'seconds')
4446+
print(f'Verified that there are no new elements in {spend} seconds')
44494447
print('Returning a presentation for the upper bound')
44504448
return R.quotient_ring(ISat)
44514449
else:
@@ -4689,7 +4687,7 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
46894687
# Computes the Laurent Polynomial for each vector in the decomposition.
46904688
finalP = []
46914689
# Laurent polynomial for each vector in {0,1}^n
4692-
for i in range(len(vd)):
4690+
for i, vdi in enumerate(vd):
46934691
numerator = 0
46944692
if cList[i]:
46954693
# If the vector in vd is negative then it did not
@@ -4706,19 +4704,20 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
47064704
expn = 0
47074705
# The exponent is determined by the vectors a,s, and the matrix B.
47084706
for k in range(num_cols):
4709-
expn += (vd[i][0][k]-s[k])*max(0, B[j][k])+s[k]*max(0, -B[j][k])
4710-
term *= x ** expn
4707+
expn += (vdi[0][k]-s[k])*max(0, B[j][k])+s[k]*max(0, -B[j][k])
4708+
term *= x**expn
47114709
numerator += term
47124710
# Gives a numerator for the negative vector, or else the product would be zero.
47134711
else:
47144712
numerator = 1
47154713

47164714
# Uses the vectors in vd to calculates the denominator of the Laurent.
47174715
denominator = 1
4718-
for l in range(num_cols):
4719-
denominator = denominator * (R.gen(l))**vd[i][0][l]
4716+
powers = vdi[0]
4717+
for ell in range(num_cols):
4718+
denominator = denominator * R.gen(ell)**powers[ell]
47204719
# Each copy of a vector in vd contributes a factor of the Laurent polynomial calculated from it.
4721-
final = (numerator / denominator)**vd[i][1]
4720+
final = (numerator / denominator)**vdi[1]
47224721
finalP.append(final)
47234722
laurentP = 1
47244723
# The UCA element for the vector a is the product of the elements produced from the vectors in its decomposition.
@@ -4758,13 +4757,12 @@ def coeff_recurs(p, q, a1, a2, b, c):
47584757
return 1
47594758
elif p < 0 or q < 0:
47604759
return 0
4760+
elif c*a1*q <= b*a2*p:
4761+
return sum((-1)**(k-1)*coeff_recurs(p-k, q, a1, a2, b, c)*_bino(a2-c*q+k-1, k)
4762+
for k in range(1, p+1))
47614763
else:
4762-
if c*a1*q <= b*a2*p:
4763-
return sum((-1)**(k-1)*coeff_recurs(p-k, q, a1, a2, b, c)*_bino(a2-c*q+k-1, k)
4764-
for k in range(1, p+1))
4765-
else:
4766-
return sum((-1)**(k-1)*coeff_recurs(p, q-k, a1, a2, b, c)*_bino(a1-b*p+k-1, k)
4767-
for k in range(1, q+1))
4764+
return sum((-1)**(k-1)*coeff_recurs(p, q-k, a1, a2, b, c)*_bino(a1-b*p+k-1, k)
4765+
for k in range(1, q+1))
47684766

47694767

47704768
def PathSubset(n, m):

src/sage/combinat/cluster_algebra_quiver/interact.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def cluster_interact(self, fig_size=1, circular=True, kind='seed'):
4848
description="Show last mutation vertex")
4949

5050
mut_buttons = widgets.ToggleButtons(options=list(range(self._n)),
51-
style={'button_width':'initial'},
52-
description='Mutate at: ')
51+
style={'button_width': 'initial'},
52+
description='Mutate at: ')
5353

5454
which_plot = widgets.Dropdown(options=['circular', 'spring'],
5555
value='circular' if circular else "spring",

0 commit comments

Comments
 (0)