-
Notifications
You must be signed in to change notification settings - Fork 0
/
csf.py
166 lines (138 loc) · 4.55 KB
/
csf.py
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# -*- coding: utf-8 -*-
r"""
Code for computing chromatic symmetric functions.
"""
import itertools as it
from path import *
from perm import *
from util import *
# ---------------------------------------------------------
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
# ---------------------------------------------------------
def compute_csfs(n):
r"""
Compute the coefficients of the q-csf for everything of size n,
in the monomial basis.
"""
logger.info('starting size %d', n)
paths = list(iter_path(n))
perms = list(iter_blist(n))
parts = list(partitions(n))
for k, path in enumerate(paths):
logger.info('doing size %d path %d', n, k)
csf = {
part: [0]*(n*(n-1)//2+1)
for part in parts
}
for perm in perms:
degree = inversions(path, perm)
for part in parts:
if contractible(path, perm, part):
csf[part][degree] += 1
yield path, csf
logger.info('done with size %d', n)
# ---------------------------------------------------------
def contractible(path, perm, composition):
r"""
Check whether contracting a permutation colouring according to
a composition gives a valid chain colouring for a Dyck path.
`path` describes a unit interval order
`perm` gives a colouring of the poset
`composition` gives chain lengths for the contracted colouring
>>> any(contractible((0, 0, 0), perm, (2, 1))
... for perm in it.permutations(range(3)))
False
>>> contractible((0, 0, 1), (0, 1, 2), (2, 1))
False
>>> contractible((0, 0, 1), (0, 2, 1), (2, 1))
True
>>> contractible((0, 0, 1), (1, 0, 2), (2, 1))
False
>>> contractible((0, 0, 1), (1, 2, 0), (2, 1))
False
>>> contractible((0, 0, 1), (2, 0, 1), (2, 1))
False
>>> contractible((0, 0, 1), (2, 1, 0), (2, 1))
False
>>> contractible((0, 1, 2), (0, 1, 2), (3,))
True
>>> contractible((0, 1, 2), (0, 2, 1), (3,))
False
>>> contractible((0, 1, 2), (1, 0, 2), (3,))
False
>>> contractible((0, 1, 2), (1, 2, 0), (3,))
False
>>> contractible((0, 1, 2), (2, 0, 1), (3,))
False
>>> contractible((0, 1, 2), (2, 1, 0), (3,))
False
"""
n = len(path)
# assert is_path(path)
# assert is_blist(perm) and len(perm) == n
assert isinstance(composition, tuple) and sum(composition) == n
comparable = boxes_under_path(path)
total = 0
for part in composition:
for col1 in range(total, total+part-1):
col2 = col1 + 1
pos1 = perm.index(col1)
pos2 = perm.index(col2)
if pos1 > pos2 or (pos1, pos2) in comparable:
return False
total += part
return True
# ---------------------------------------------------------
def doctest():
import doctest
doctest.testmod(verbose=False)
# ---------------------------------------------------------
def setup_logging():
handler = logging.StreamHandler()
handler.setFormatter(
logging.Formatter(
'%(module)s (elapsed time %(relativeCreated)d): %(message)s'))
logger.addHandler(handler)
# ---------------------------------------------------------
def argparse():
import argparse
parser = argparse.ArgumentParser(
description='Compute graded chromatic symmetric functions for all unit interval orders of size n.',
)
parser.add_argument(
'n',
type=int,
choices=range(1, 11),
metavar='n',
help='The size of unit interval orders to consider (from 1 to 10).',
)
args = parser.parse_args()
return args.n
# ---------------------------------------------------------
output_header = r"""csf[{path}] = m.sum(
m.term(Partition(index), R(coeffs))
for index, coeffs in [
"""
output_footer = r""" ])
"""
def save(path, csf):
filename = 'output/csf-' + ''.join(map(str, path)) + '.py'
with open(filename, 'w') as f:
f.write(output_header.format(path=path))
for index, coeffs in sorted(csf.iteritems()):
while coeffs and coeffs[-1] == 0:
coeffs.pop()
if coeffs:
f.write(" ({}, {}),\n".format(list(index), coeffs))
f.write(output_footer)
# ---------------------------------------------------------
if __name__ == '__main__':
doctest()
setup_logging()
n = argparse()
for path, csf in compute_csfs(n):
save(path, csf)
# ---------------------------------------------------------