-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdes_cover.sage
149 lines (122 loc) · 2.76 KB
/
des_cover.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def circular_descents(w):
w = Permutation(w)
n = len(w)
foo = []
for i in range(1,n):
if w(i) > w(i+1):
foo.append(i)
if w(n) > w(1):
foo.append(n)
return foo
def cdes(w):
w = Permutation(w)
return len(circular_descents(w))
def cdes_ij(w, i, j):
n = len(w)
while i > n:
i -= n
while j > n:
j -= n
if i == j:
return 0
foo = 0
if i < j:
for k in range(i,j):
if w(k) > w(k+1):
foo += 1
if w(j) > w(i):
foo += 1
return foo
if i > j:
for k in range(i,n):
if w(k) > w(k+1):
foo += 1
if w(n) > w(1):
foo += 1
if j > 1:
for k in range(1,j):
if w(k) > w(k+1):
foo += 1
if w(j) > w(i):
foo += 1
return foo
def icdes_ij(w, i, j):
u = w.inverse()
return cdes_ij(u,i,j)
def icdes(w):
w = Permutation(w)
u = w.inverse()
return cdes(u)
def cover(w):
w = Permutation(w)
n = len(w)
foo = [i for i in range(1,n-1) if w(i+1)>w(i)+1]
temp = len(foo)
if w(1) == 1:
return temp
else:
return temp+1
def perm_icdes(n,k):
cycle = list(range(2,n+1))
cycle.append(1)
cyclc = Permutation(cycle)
return [Permutation(w).left_action_product(cycle) for w in CyclicPermutations(range(1,n+1)) if icdes(w) == k]
def perm_cdes(n,k):
cycle = list(range(2,n+1))
cycle.append(1)
cyclc = Permutation(cycle)
return [Permutation(w).left_action_product(cycle) for w in CyclicPermutations(range(1,n+1)) if cdes(w) == k]
def perm_ides(n,k):
return [Permutation(w) for w in Permutations(n) if w.number_of_idescents() == k]
def perm_cover(n,k):
temp = {}
for w in perm_ides(n-1,k-1):
c = cover(w)
temp.setdefault(c, [])
temp[c].append(w.inverse())
return temp
def no_perm_cover(n,k):
return {key: len(value) for (key, value) in perm_cover(n,k).items()}
def perm_cover_polynomial(n,k):
R.<t> = PolynomialRing(QQ)
temp = no_perm_cover(n,k)
return sum([value*t^key for (key, value) in temp.items()])
def completion(w):
n = len(w)
return Permutation(w+[n+1])
def decompl(w):
n = len(w)
ww = list(w).copy()
i = ww.index(n)
if i == n:
ww.pop()
return Permutation(ww)
else:
ww = ww[i+1:]+ww[:i]
return Permutation(ww)
def ls_to_str(l):
return ''.join(map(str,l))
def graphDict(n,k):
d = {}
for w in Permutations(n-1):
if w.number_of_idescents() == k-1:
s = ls_to_str(w)
d[s] = []
for i in range(1,n-1):
v = w.apply_simple_reflection_right(i)
if v.number_of_idescents() == k-1:
d[s].append(ls_to_str(v))
v = Permutation([w(n-1)]+w[:n-2])
if v.number_of_idescents() == k-1:
d[s].append(ls_to_str(v))
v = Permutation(w[1:]+[w[0]])
if v.number_of_idescents() == k-1:
d[s].append(ls_to_str(v))
return d
def genGraph(n,k):
G = Graph(graphDict(n,k))
#G.show(method='js')
GP = G.graphplot(vertex_color='white')
GP.show()
#G.show3d(edge_size=0.01, vertex_size=0.01)
return