-
Notifications
You must be signed in to change notification settings - Fork 0
/
symPoly.py
135 lines (116 loc) · 5 KB
/
symPoly.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
#Symetric Polynomial classes
import scipy
import numpy
import characterTables
from usefulTools import generatePartitions
class symetricPowerSumPoly:
def __init__(self, partition, coeficient):
self.partition = tuple(sorted([i for i in partition if not (i == 0)]))
self.coeficient = coeficient
def __add__(self, otherPoly):
if type(otherPoly) is symetricPowerSumPoly:
if self.partition == otherPoly.partition:
return symetricPowerSumPoly(self.partition, self.coeficient + otherPoly.coeficient)
else:
return genralSymPoly([self, otherPoly])
else:
return otherPoly + self
def __mul__(self, otherObj):
if type(otherObj) is symetricPowerSumPoly:
return symetricPowerSumPoly(self.partition + otherObj.partition, self.coeficient*otherObj.coeficient)
elif type(otherObj) is genralSymPoly:
return otherObj*self
else:
return symetricPowerSumPoly(self.partition, self.coeficient*otherObj)
def convertToShur(self, N):
partitions = generatePartitions(sum(self.partition))
resultPoly = genralSymPolySchur([schurPoly(p, self.coeficient*characterTables.characterTab(p, self.partition)) for p in partitions if len(p) <= N])
return resultPoly
def __str__(self):
return str(self.coeficient) + "*" + str(self.partition)
class schurPoly:
def __init__(self, partition, coeficient):
self.partition = tuple(sorted(partition))
self.coeficient = coeficient
def __add__(self, otherPoly):
if type(otherPoly) is schurPoly:
if self.partition == otherPoly.partition:
return schurPoly(self.partition, self.coeficient + otherPoly.coeficient)
else:
return genralSymPolySchur([self, otherPoly])
else:
return otherPoly + self
def __mul__(self, otherObj):
return schurPoly(self.partition, self.coeficient*otherObj)
def __str__(self):
return str(self.coeficient) + "*" + str(self.partition)
class genralSymPoly:
def __init__(self, listOfPowerSums):
self.powerSums = [s for s in listOfPowerSums if not (s.coeficient == 0)]
def __add__(self, otherObj):
if type(otherObj) is symetricPowerSumPoly:
listOfPartitions = [x.partition for x in self.powerSums]
listOfPowerSums = [x for x in self.powerSums]
if otherObj.partition in listOfPartitions:
for i in range(len(listOfPowerSums)):
if listOfPowerSums[i].partition == otherObj.partition:
listOfPowerSums[i] = listOfPowerSums[i] + otherObj
return genralSymPoly(listOfPowerSums)
else:
return genralSymPoly(listOfPowerSums + [otherObj])
else:
resultPoly = self
for s in otherObj.powerSums:
resultPoly = resultPoly + s
return resultPoly
def __mul__(self, otherObj):
if type(otherObj) is genralSymPoly:
resultPoly = genralSymPoly([])
for s in otherObj.powerSums:
resultPoly = resultPoly + self*s
return resultPoly
else:
return genralSymPoly([s*otherObj for s in self.powerSums])
def __pow__(self, n):
resultPoly = self
for i in range(n-1):
resultPoly = resultPoly*self
return resultPoly
def convertToShurBasis(self, N):
resultPoly = genralSymPolySchur([])
for s in self.powerSums:
resultPoly = resultPoly + s.convertToShur(N)
return resultPoly
def __str__(self):
resultString = ""
for i in range(len(self.powerSums)-1):
resultString += str(self.powerSums[i]) + " + "
resultString += str(self.powerSums[-1])
return resultString
class genralSymPolySchur:
def __init__(self, listOfShurs):
self.schurs = [s for s in listOfShurs if not (s.coeficient == 0)]
def __add__(self, otherObj):
if type(otherObj) is schurPoly:
listOfPartitions = [x.partition for x in self.schurs]
listOfSchurs = [x for x in self.schurs]
if otherObj.partition in listOfPartitions:
for i in range(len(listOfSchurs)):
if listOfSchurs[i].partition == otherObj.partition:
listOfSchurs[i] = listOfSchurs[i] + otherObj
return genralSymPolySchur(listOfSchurs)
else:
return genralSymPolySchur(listOfSchurs + [otherObj])
else:
resultPoly = self
for s in otherObj.schurs:
resultPoly = resultPoly + s
return resultPoly
def __mul__(self, otherObj):
return genralSymPolySchur([s*otherObj for s in self.schurs])
def __str__(self):
resultString = ""
for i in range(len(self.schurs)-1):
resultString += str(self.schurs[i]) + " + "
resultString += str(self.schurs[-1])
return resultString