-
Notifications
You must be signed in to change notification settings - Fork 3
/
cgpalg_dense_tm.py
executable file
·187 lines (156 loc) · 5.16 KB
/
cgpalg_dense_tm.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/python -Wall
# ================================================================
# Please see LICENSE.txt in the same directory as this file.
# John Kerl
# kerl.john.r@gmail.com
# 2007-05-31
# ================================================================
import sys
import re
import copy
# ================================================================
# Type module for complex group algebras CG, with dense storage.
#
# Initial attempt at complex group algebras CG for small finite groups G. This
# could, conceivably, be generalized to FG (for arbitrary user-specified
# fields) or RG (for arbitrary user-specified rings).
#
# There are two possible storage representations for an element of CG:
# * Sparse: Keep a list of non-zero coefficients, with their
# corresponding group elements.
# * Dense: Keep a list of group elements, with another list of coefficients.
#
# For now I will attempt the latter. Good hygiene would require me to make
# the following checks (which I will not):
# * A's coef-array length = A's group-elements-array length
# * B's coef-array length = B's group-elements-array length
# * A's coef-array length = B's coef-array length
# * A's group-elements-array length = B's group-elements-array length
#
# ================================================================
# John Kerl
# 2007-05-08
# ================================================================
class cgpalg_t:
def __init__(self, coef_array, gp_elt_array):
#self.check_lengths(len(coef_array), len(gp_elt_array), "coefs", "gp_elts")
self.coefs = copy.copy(coef_array)
self.gp_elts = copy.copy(gp_elt_array)
def __add__(a,b):
#a.check_lengths(len(a.gp_elts), len(b.gp_elts), "coefs", "gp_elts")
c = cgpalg_t(a.coefs, a.gp_elts)
for i in range (0, len(a.coefs)):
c.coefs[i] = a.coefs[i] + b.coefs[i]
return c
def __sub__(a,b):
#a.check_lengths(len(a.gp_elts), len(b.gp_elts), "coefs", "gp_elts")
c = cgpalg_t(a.coefs, a.gp_elts)
for i in range (0, len(a.coefs)):
c.coefs[i] = a.coefs[i] - b.coefs[i]
return c
def index_of(self, g):
for k in range(0, len(self.gp_elts)):
if (g == self.gp_elts[k]):
return k
print "cgpalg_t: Couldn't find [", g, "] in gp_elts array."
sys.exit(1)
def __mul__(a,b):
#a.check_lengths(len(a.gp_elts), len(b.gp_elts), "coefs", "gp_elts")
c = cgpalg_t(a.coefs, a.gp_elts)
# XXX XXX XXX
zero = a.coefs[0] - a.coefs[0]
for i in range (0, len(a.coefs)):
c.coefs[i] = zero
for i in range (0, len(a.coefs)):
for j in range (0, len(b.coefs)):
k = c.index_of(a.gp_elts[i] * b.gp_elts[j])
c.coefs[k] += a.coefs[i] * b.coefs[j]
return c
def __eq__(a,b):
if (len(a.coefs) != len(b.coefs)):
return 0
n = len(a.coefs)
for i in range(0, n):
if (a.coefs[i] != b.coefs[i]):
return 0
return 1
def __ne__(a,b):
return not (a == b)
def __neg__(a):
c = cgpalg_t(a.coefs, a.gp_elts)
for i in range(0, len(a.gp_elts)):
c.coefs[i] = -a.coefs[i]
return c
# def scan(self, res_string, cgpalg_array):
# res_strings = re.split(',', res_string)
# #self.check_lengths(len(res_strings), len(cgpalg_array), res_strings,
# str(cgpalg_strings))
# n = len(res_strings)
# coef_array = range(0, n)
# for i in range(0, n):
# coef_array[i] = int(res_strings[i])
# self.__init__(coef_array, gp_elt_array)
def __str__(self):
string = ""
for i in range(0, len(self.coefs)):
if (i > 0):
string += " "
string += "["
string += str(self.coefs[i])
string += "]*["
string += str(self.gp_elts[i])
string += "]"
return string
def __repr__(self):
return self.__str__()
# def check_length(self, length, desc):
# if (length < 1):
# print desc, "length", str(length), "< 1"
# raise RuntimeError
# def check_lengths(self, len1, len2, desc1, desc2):
# self.check_length(len1, desc1)
# self.check_length(len2, desc2)
# if (len1 != len2):
# print desc1, "length", str(len1), "!=", desc2, "length", len2
# raise RuntimeError
#def params_from_string(params_string):
# if (len(params_string) == 0):
# print "Modadd requires non-empty parameter string"
# sys.exit(1)
# cgpalg_strings = re.split(',', params_string)
# n = len(cgpalg_strings)
# cgpalg_array = range(0, n)
# for i in range(0, n):
# cgpalg_array[i] = int(cgpalg_strings[i])
# return cgpalg_array
#def from_string(value_string, params_string):
# cgpalg_array = params_from_string(params_string)
# obj = cgpalg_t([1], [1])
# obj.scan(value_string, cgpalg_array)
# return obj
# ================================================================
import unittest
if __name__ == '__main__':
class test_cases(unittest.TestCase):
def test___init__(self):
pass # to be implemented
def test___add__(self):
pass # to be implemented
def test___sub__(self):
pass # to be implemented
def test_index_of(self):
pass # to be implemented
def test___mul__(self):
pass # to be implemented
def test___eq__(self):
pass # to be implemented
def test___ne__(self):
pass # to be implemented
def test___neg__(self):
pass # to be implemented
def test___str__(self):
pass # to be implemented
def test___repr__(self):
pass # to be implemented
# ----------------------------------------------------------------
unittest.main()