@@ -2503,9 +2503,9 @@ def mutate(self, sequence, inplace=True, input_type=None):
2503
2503
sequence = self .first_green_vertex ()
2504
2504
elif sequence == 'red' :
2505
2505
sequence = self .first_red_vertex ()
2506
- elif sequence == 'urban' or sequence == 'urban_renewal' :
2506
+ elif sequence in { 'urban' , 'urban_renewal' } :
2507
2507
sequence = self .first_urban_renewal ()
2508
- elif sequence == 'all_urbans' or sequence == 'all_urban_renewals' :
2508
+ elif sequence in { 'all_urbans' , 'all_urban_renewals' } :
2509
2509
sequence = self .urban_renewals ()
2510
2510
elif hasattr (self , sequence ):
2511
2511
sequence = getattr (self , sequence )()
@@ -2581,33 +2581,32 @@ def mutate(self, sequence, inplace=True, input_type=None):
2581
2581
' "indices", or "cluster_vars"' )
2582
2582
2583
2583
# Classifies the input_type. Raises warnings if the input is ambiguous, and errors if the input is not all of the same type.
2584
- else :
2585
- if is_vertices :
2586
- input_type = "vertices"
2587
- for x in seqq :
2588
- if is_indices and seed ._nlist [x ] != x :
2589
- print ("Input can be ambiguously interpreted as both"
2590
- " vertices and indices."
2584
+ elif is_vertices :
2585
+ input_type = "vertices"
2586
+ for x in seqq :
2587
+ if is_indices and seed ._nlist [x ] != x :
2588
+ print ("Input can be ambiguously interpreted as both"
2589
+ " vertices and indices."
2590
+ " Mutating at vertices by default." )
2591
+ break
2592
+
2593
+ elif is_cluster_vars :
2594
+ cluster_var_index = seed .cluster_index (x )
2595
+ vertex_index = seed ._nlist .index (x )
2596
+ if isinstance (cluster_var_index , int ) and cluster_var_index != vertex_index :
2597
+ print ("Input can be ambiguously interpreted as"
2598
+ " both vertices and cluster variables."
2591
2599
" Mutating at vertices by default." )
2592
2600
break
2593
2601
2594
- elif is_cluster_vars :
2595
- cluster_var_index = seed .cluster_index (x )
2596
- vertex_index = seed ._nlist .index (x )
2597
- if isinstance (cluster_var_index , int ) and cluster_var_index != vertex_index :
2598
- print ("Input can be ambiguously interpreted as"
2599
- " both vertices and cluster variables."
2600
- " Mutating at vertices by default." )
2601
- break
2602
-
2603
- # It should be impossible to interpret an index as a cluster variable.
2604
- elif is_indices :
2605
- input_type = "indices"
2606
- elif is_cluster_vars :
2607
- input_type = "cluster_vars"
2608
- else :
2609
- raise ValueError ('mutation sequences must consist of exactly'
2610
- ' one of vertices, indices, or cluster variables' )
2602
+ # It should be impossible to interpret an index as a cluster variable.
2603
+ elif is_indices :
2604
+ input_type = "indices"
2605
+ elif is_cluster_vars :
2606
+ input_type = "cluster_vars"
2607
+ else :
2608
+ raise ValueError ('mutation sequences must consist of exactly'
2609
+ ' one of vertices, indices, or cluster variables' )
2611
2610
2612
2611
if input_type == "cluster_vars" and len (seqq ) > 1 :
2613
2612
mutation_seed = deepcopy (seed )
@@ -3503,8 +3502,8 @@ def mutation_class_iter(self, depth=infinity, show_depth=False,
3503
3502
Check that :issue:`14638` is fixed::
3504
3503
3505
3504
sage: S = ClusterSeed(['E',6])
3506
- sage: MC = S.mutation_class(depth=7 ); len(MC) # long time
3507
- 534
3505
+ sage: MC = S.mutation_class(depth=6 ); len(MC) # long time
3506
+ 388
3508
3507
3509
3508
Infinite type examples::
3510
3509
@@ -4272,11 +4271,10 @@ def greedy(self, a1, a2, algorithm='by_recursion'):
4272
4271
oddT = set (T ).intersection (PathSubset (a1 , 0 ))
4273
4272
evenT = set (T ).symmetric_difference (oddT )
4274
4273
ans = ans + S .x (0 )** (b * len (evenT )) * S .x (1 )** (c * len (oddT ))
4275
- else :
4276
- if is_LeeLiZel_allowable (T , a2 , a1 , c , b ):
4277
- oddT = set (T ).intersection (PathSubset (a2 , 0 ))
4278
- evenT = set (T ).symmetric_difference (oddT )
4279
- ans = ans + S .x (0 )** (b * len (oddT )) * S .x (1 )** (c * len (evenT ))
4274
+ elif is_LeeLiZel_allowable (T , a2 , a1 , c , b ):
4275
+ oddT = set (T ).intersection (PathSubset (a2 , 0 ))
4276
+ evenT = set (T ).symmetric_difference (oddT )
4277
+ ans = ans + S .x (0 )** (b * len (oddT )) * S .x (1 )** (c * len (evenT ))
4280
4278
ans = ans * S .x (0 )** (- a1 )* S .x (1 )** (- a2 )
4281
4279
return ans
4282
4280
elif algorithm == 'just_numbers' :
@@ -4431,15 +4429,15 @@ def find_upper_bound(self, verbose=False):
4431
4429
4432
4430
while True :
4433
4431
R = PolynomialRing (QQ , gens , order = 'invlex' )
4434
- I = R .ideal (rels )
4435
- J = R .ideal (initial_product )
4432
+ ideal_I = R .ideal (rels )
4433
+ ideal_J = R .ideal (initial_product )
4436
4434
if verbose :
4437
4435
msg = 'Computing relations among {} generators'
4438
4436
print (msg .format (len (gens )))
4439
4437
start = time .time ()
4440
- ISat = I .saturation (J )[0 ]
4441
- spend = time .time () - start
4438
+ ISat = ideal_I .saturation (ideal_J )[0 ]
4442
4439
if verbose :
4440
+ spend = time .time () - start
4443
4441
msg = 'Computed {} relations in {} seconds'
4444
4442
print (msg .format (len (ISat .gens ()), spend ))
4445
4443
deep_ideal = R .ideal (deep_gens ) + ISat
@@ -4451,7 +4449,7 @@ def find_upper_bound(self, verbose=False):
4451
4449
spend = time .time () - start
4452
4450
if M == initial_product_ideal :
4453
4451
if verbose :
4454
- print ('Verified that there are no new elements in' , spend , ' seconds' )
4452
+ print (f 'Verified that there are no new elements in { spend } seconds' )
4455
4453
print ('Returning a presentation for the upper bound' )
4456
4454
return R .quotient_ring (ISat )
4457
4455
else :
@@ -4695,7 +4693,7 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
4695
4693
# Computes the Laurent Polynomial for each vector in the decomposition.
4696
4694
finalP = []
4697
4695
# Laurent polynomial for each vector in {0,1}^n
4698
- for i in range ( len ( vd ) ):
4696
+ for i , vdi in enumerate ( vd ):
4699
4697
numerator = 0
4700
4698
if cList [i ]:
4701
4699
# If the vector in vd is negative then it did not
@@ -4712,19 +4710,20 @@ def _produce_upper_cluster_algebra_element(self, vd, cList):
4712
4710
expn = 0
4713
4711
# The exponent is determined by the vectors a,s, and the matrix B.
4714
4712
for k in range (num_cols ):
4715
- expn += (vd [ i ] [0 ][k ]- s [k ])* max (0 , B [j ][k ])+ s [k ]* max (0 , - B [j ][k ])
4716
- term *= x ** expn
4713
+ expn += (vdi [0 ][k ]- s [k ])* max (0 , B [j ][k ])+ s [k ]* max (0 , - B [j ][k ])
4714
+ term *= x ** expn
4717
4715
numerator += term
4718
4716
# Gives a numerator for the negative vector, or else the product would be zero.
4719
4717
else :
4720
4718
numerator = 1
4721
4719
4722
4720
# Uses the vectors in vd to calculates the denominator of the Laurent.
4723
4721
denominator = 1
4724
- for l in range (num_cols ):
4725
- denominator = denominator * (R .gen (l ))** vd [i ][0 ][l ]
4722
+ powers = vdi [0 ]
4723
+ for ell in range (num_cols ):
4724
+ denominator = denominator * R .gen (ell )** powers [ell ]
4726
4725
# Each copy of a vector in vd contributes a factor of the Laurent polynomial calculated from it.
4727
- final = (numerator / denominator )** vd [ i ] [1 ]
4726
+ final = (numerator / denominator )** vdi [1 ]
4728
4727
finalP .append (final )
4729
4728
laurentP = 1
4730
4729
# The UCA element for the vector a is the product of the elements produced from the vectors in its decomposition.
@@ -4762,15 +4761,15 @@ def coeff_recurs(p, q, a1, a2, b, c):
4762
4761
"""
4763
4762
if p == 0 and q == 0 :
4764
4763
return 1
4765
- elif p < 0 or q < 0 :
4764
+ if p < 0 or q < 0 :
4766
4765
return 0
4767
- else :
4768
- if c * a1 * q <= b * a2 * p :
4769
- return sum (( - 1 ) ** ( k - 1 ) * coeff_recurs ( p - k , q , a1 , a2 , b , c ) * _bino (a2 - c * q + k - 1 , k )
4770
- for k in range (1 , p + 1 ))
4771
- else :
4772
- return sum (( - 1 ) ** ( k - 1 ) * coeff_recurs ( p , q - k , a1 , a2 , b , c ) * _bino (a1 - b * p + k - 1 , k )
4773
- for k in range (1 , q + 1 ))
4766
+ if c * a1 * q <= b * a2 * p :
4767
+ return sum (( - 1 ) ** ( k - 1 ) * coeff_recurs ( p - k , q , a1 , a2 , b , c )
4768
+ * _bino (a2 - c * q + k - 1 , k )
4769
+ for k in range (1 , p + 1 ))
4770
+ return sum (( - 1 ) ** ( k - 1 ) * coeff_recurs ( p , q - k , a1 , a2 , b , c )
4771
+ * _bino (a1 - b * p + k - 1 , k )
4772
+ for k in range (1 , q + 1 ))
4774
4773
4775
4774
4776
4775
def PathSubset (n , m ):
0 commit comments