@@ -2497,9 +2497,9 @@ def mutate(self, sequence, inplace=True, input_type=None):
2497
2497
sequence = self .first_green_vertex ()
2498
2498
elif sequence == 'red' :
2499
2499
sequence = self .first_red_vertex ()
2500
- elif sequence == 'urban' or sequence == 'urban_renewal' :
2500
+ elif sequence in { 'urban' , 'urban_renewal' } :
2501
2501
sequence = self .first_urban_renewal ()
2502
- elif sequence == 'all_urbans' or sequence == 'all_urban_renewals' :
2502
+ elif sequence in { 'all_urbans' , 'all_urban_renewals' } :
2503
2503
sequence = self .urban_renewals ()
2504
2504
elif hasattr (self , sequence ):
2505
2505
sequence = getattr (self , sequence )()
@@ -2575,33 +2575,32 @@ def mutate(self, sequence, inplace=True, input_type=None):
2575
2575
' "indices", or "cluster_vars"' )
2576
2576
2577
2577
# 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."
2585
2593
" Mutating at vertices by default." )
2586
2594
break
2587
2595
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' )
2605
2604
2606
2605
if input_type == "cluster_vars" and len (seqq ) > 1 :
2607
2606
mutation_seed = deepcopy (seed )
@@ -3497,8 +3496,8 @@ def mutation_class_iter(self, depth=infinity, show_depth=False,
3497
3496
Check that :issue:`14638` is fixed::
3498
3497
3499
3498
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
3502
3501
3503
3502
Infinite type examples::
3504
3503
@@ -4266,11 +4265,10 @@ def greedy(self, a1, a2, algorithm='by_recursion'):
4266
4265
oddT = set (T ).intersection (PathSubset (a1 , 0 ))
4267
4266
evenT = set (T ).symmetric_difference (oddT )
4268
4267
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 ))
4274
4272
ans = ans * S .x (0 )** (- a1 )* S .x (1 )** (- a2 )
4275
4273
return ans
4276
4274
elif algorithm == 'just_numbers' :
@@ -4425,15 +4423,15 @@ def find_upper_bound(self, verbose=False):
4425
4423
4426
4424
while True :
4427
4425
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 )
4430
4428
if verbose :
4431
4429
msg = 'Computing relations among {} generators'
4432
4430
print (msg .format (len (gens )))
4433
4431
start = time .time ()
4434
- ISat = I .saturation (J )[0 ]
4435
- spend = time .time () - start
4432
+ ISat = ideal_I .saturation (ideal_J )[0 ]
4436
4433
if verbose :
4434
+ spend = time .time () - start
4437
4435
msg = 'Computed {} relations in {} seconds'
4438
4436
print (msg .format (len (ISat .gens ()), spend ))
4439
4437
deep_ideal = R .ideal (deep_gens ) + ISat
@@ -4445,7 +4443,7 @@ def find_upper_bound(self, verbose=False):
4445
4443
spend = time .time () - start
4446
4444
if M == initial_product_ideal :
4447
4445
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' )
4449
4447
print ('Returning a presentation for the upper bound' )
4450
4448
return R .quotient_ring (ISat )
4451
4449
else :
@@ -4689,7 +4687,7 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
4689
4687
# Computes the Laurent Polynomial for each vector in the decomposition.
4690
4688
finalP = []
4691
4689
# Laurent polynomial for each vector in {0,1}^n
4692
- for i in range ( len ( vd ) ):
4690
+ for i , vdi in enumerate ( vd ):
4693
4691
numerator = 0
4694
4692
if cList [i ]:
4695
4693
# If the vector in vd is negative then it did not
@@ -4706,19 +4704,20 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
4706
4704
expn = 0
4707
4705
# The exponent is determined by the vectors a,s, and the matrix B.
4708
4706
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
4711
4709
numerator += term
4712
4710
# Gives a numerator for the negative vector, or else the product would be zero.
4713
4711
else :
4714
4712
numerator = 1
4715
4713
4716
4714
# Uses the vectors in vd to calculates the denominator of the Laurent.
4717
4715
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 ]
4720
4719
# 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 ]
4722
4721
finalP .append (final )
4723
4722
laurentP = 1
4724
4723
# 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):
4758
4757
return 1
4759
4758
elif p < 0 or q < 0 :
4760
4759
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 ))
4761
4763
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 ))
4768
4766
4769
4767
4770
4768
def PathSubset (n , m ):
0 commit comments