@@ -727,7 +727,9 @@ def ProductOfChains(chain_lengths, facade=None):
727
727
return LatticePoset (facade = facade )
728
728
from sage .categories .cartesian_product import cartesian_product
729
729
elements = cartesian_product ([range (i ) for i in l ])
730
- compare = lambda a , b : all (x <= y for x , y in zip (a , b ))
730
+
731
+ def compare (a , b ):
732
+ return all (x <= y for x , y in zip (a , b ))
731
733
return LatticePoset ([elements , compare ], facade = facade )
732
734
733
735
@staticmethod
@@ -875,7 +877,7 @@ def RandomLattice(n, p, properties=None):
875
877
covers = _random_lattice (n , p )
876
878
covers_dict = {i : covers [i ] for i in range (n )}
877
879
D = DiGraph (covers_dict )
878
- D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
880
+ D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
879
881
return LatticePoset (D , cover_relations = True )
880
882
881
883
if isinstance (properties , str ):
@@ -906,23 +908,23 @@ def RandomLattice(n, p, properties=None):
906
908
907
909
if properties == set (['planar' ]):
908
910
D = _random_planar_lattice (n )
909
- D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
911
+ D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
910
912
return LatticePoset (D )
911
913
912
914
if properties == set (['dismantlable' ]):
913
915
D = _random_dismantlable_lattice (n )
914
- D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
916
+ D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
915
917
return LatticePoset (D )
916
918
917
919
if properties == set (['stone' ]):
918
920
D = _random_stone_lattice (n )
919
- D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
921
+ D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
920
922
return LatticePoset (D )
921
923
922
924
if properties == set (['distributive' ]):
923
925
tmp = Poset (_random_distributive_lattice (n )).order_ideals_lattice (as_ideals = False )
924
926
D = copy (tmp ._hasse_diagram )
925
- D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
927
+ D .relabel ([i - 1 for i in Permutations (n ).random_element ()])
926
928
return LatticePoset (D )
927
929
928
930
raise AssertionError ("bug in RandomLattice()" )
@@ -948,7 +950,7 @@ def SetPartitions(n):
948
950
949
951
def covers (x ):
950
952
for i , s in enumerate (x ):
951
- for j in range (i + 1 , len (x )):
953
+ for j in range (i + 1 , len (x )):
952
954
L = list (x )
953
955
L [i ] = s .union (x [j ])
954
956
L .pop (j )
@@ -1051,8 +1053,8 @@ def StandardExample(n, facade=None):
1051
1053
(False, False)
1052
1054
"""
1053
1055
n = check_int (n , 2 )
1054
- return Poset ((range (2 * n ), [[i , j + n ] for i in range (n )
1055
- for j in range (n ) if i != j ]),
1056
+ return Poset ((range (2 * n ), [[i , j + n ] for i in range (n )
1057
+ for j in range (n ) if i != j ]),
1056
1058
facade = facade )
1057
1059
1058
1060
@staticmethod
@@ -1548,20 +1550,20 @@ def YoungFibonacci(n):
1548
1550
1549
1551
covers = []
1550
1552
current_level = ['' ]
1551
- for i in range (1 , n + 1 ):
1553
+ for i in range (1 , n + 1 ):
1552
1554
new_level = set ()
1553
1555
for low in current_level :
1554
1556
ind = low .find ('1' )
1555
1557
if ind != - 1 : # = found a '1' -> change first '1' to '2'
1556
- up = low [:ind ]+ '2' + low [ind + 1 :]
1558
+ up = low [:ind ] + '2' + low [ind + 1 :]
1557
1559
new_level .add (up )
1558
1560
covers .append ((low , up ))
1559
1561
else : # no '1' in low
1560
1562
ind = len (low )
1561
1563
1562
1564
# add '1' to every position not after first existing '1'
1563
- for j in range (ind + 1 ):
1564
- up = '2' * j + '1' + low [j :len (low )]
1565
+ for j in range (ind + 1 ):
1566
+ up = '2' * j + '1' + low [j :len (low )]
1565
1567
new_level .add (up )
1566
1568
covers .append ((low , up ))
1567
1569
@@ -1589,10 +1591,10 @@ def DoubleTailedDiamond(n):
1589
1591
"""
1590
1592
n = check_int (n , 1 )
1591
1593
1592
- edges = [(i , i + 1 ) for i in range (1 , n )]
1593
- edges .extend ([(n , n + 1 ), (n , n + 2 ), (n + 1 , n + 3 ), (n + 2 , n + 3 )])
1594
- edges .extend ([(i , i + 1 ) for i in range (n + 3 , 2 * n + 2 )])
1595
- p = DiGraph ([list (range (1 , 2 * n + 3 )), edges ])
1594
+ edges = [(i , i + 1 ) for i in range (1 , n )]
1595
+ edges .extend ([(n , n + 1 ), (n , n + 2 ), (n + 1 , n + 3 ), (n + 2 , n + 3 )])
1596
+ edges .extend ([(i , i + 1 ) for i in range (n + 3 , 2 * n + 2 )])
1597
+ p = DiGraph ([list (range (1 , 2 * n + 3 )), edges ])
1596
1598
return DCompletePoset (p )
1597
1599
1598
1600
@staticmethod
@@ -1694,7 +1696,7 @@ def PermutationPatternInterval(bottom, top):
1694
1696
# Try and remove the ith element from the permutation
1695
1697
lower = list (upper )
1696
1698
j = lower .pop (i )
1697
- for k in range (len (top )- level - 1 ): # Standardize result
1699
+ for k in range (len (top ) - level - 1 ): # Standardize result
1698
1700
if lower [k ] > j :
1699
1701
lower [k ] = lower [k ] - 1
1700
1702
lower_perm = P (lower )
@@ -1749,13 +1751,13 @@ def PermutationPatternOccurrenceInterval(bottom, top, pos):
1749
1751
while len (top ) - len (bottom ) >= level + 1 :
1750
1752
elem .append ([]) # Add a new empty level
1751
1753
for upper in elem [level ]:
1752
- for i in range (len (top )- level ):
1754
+ for i in range (len (top ) - level ):
1753
1755
# Try and remove the ith element from the permutation
1754
1756
if i in upper [1 ]:
1755
1757
continue
1756
1758
lower_perm = list (upper [0 ])
1757
1759
j = lower_perm .pop (i )
1758
- for e in range (len (top )- level - 1 ):
1760
+ for e in range (len (top ) - level - 1 ):
1759
1761
if lower_perm [e ] > j :
1760
1762
lower_perm [e ] = lower_perm [e ] - 1
1761
1763
lower_pos = list (upper [1 ])
@@ -1901,9 +1903,9 @@ def _random_lattice(n, p):
1901
1903
# Look for an admissible lower cover for the next element i
1902
1904
while True :
1903
1905
# Generate a random antichain
1904
- lc_list = [i - 1 - floor (i * sqrt (random ()))]
1906
+ lc_list = [i - 1 - floor (i * sqrt (random ()))]
1905
1907
while random () < p and 0 not in lc_list :
1906
- new = i - 1 - floor (i * sqrt (random ()))
1908
+ new = i - 1 - floor (i * sqrt (random ()))
1907
1909
if any (meets [new ][lc ] in [new , lc ] for lc in lc_list ):
1908
1910
continue
1909
1911
lc_list .append (new )
0 commit comments