-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.py
81 lines (68 loc) · 3.24 KB
/
group.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
exec(compile(source=open('element.py').read(), filename='element.py', mode='exec'))
from logicObjects import identity, Mult
from element import *
class group:
# TRUTHS for all classes - need to add more here
identity_identifier = 'e'
elements = {}
groupProperties = {}
elementProperties = {}
subGroups = []
binaryOperator = ""
groupName = ""
def __init__(self, name, binOp, additionalGroupProperties = None):
self.groupName = name
self.binaryOperator = binOp
self.elements.update({self.identity_identifier:identity(self)})
if additionalGroupProperties != None:
self.groupProperties.update(additionalGroupProperties)
# basic functions
def __repr__(self):
return "group(" + self.groupName + ")"
def __eq__(self,other):
return self.groupName == other.groupName
def __mul__(self,other): # group cartesian product. Worry about this later
newName = self.groupName + "x" + other.groupName
newProperties = list(set(self.properties) & set(other.properties)) #sadly cartesian products don't work this way :(
return group(newName, [self.binaryOperator,other.binaryOperator], newProperties)
# group functions
def newInverse(self, elementName):
if elementName in self.elements:
inverseName = '(' + elementName + ')^(-1)'
self.elements.update({inverseName:inverse(elementName,self)})
else:
print("Sorry, you cannot add the inverse of an element that does not exist!")
# declare new element in group with elementName
def newElement(self,elementName):
if elementName not in self.elements:
self.elements.update({elementName:element(elementName,self)})
else:
print("Sorry, that element already exists!")
# create new element that is elem1 operated on with elem2
def mulElements(self, elem1, elem2): # should this return an equation?
if elem1 == self.identity_identifier or elem2 == self.identity_identifier:
print("Sorry, multiplying by the identity doesn't do anything!")
else:
try:
gelem1 = self.elements[elem1]
gelem2 = self.elements[elem2]
result = Mult([gelem1 ,gelem2]) # need to specify which group we are multiplying in
self.elements.update({repr(result):result}) # is this the right?
except:
print("Sorry, one or both of these elements are not in the group!")
def subGroup(self, property):
self.subGroups.append(property)
return f'{property} is a subgroup of {self}'
def addGroupProperty(self, property, propertyName):
self.groupProperties[propertyName] = property
def deleteGroupProperty(self, propertyName):
del self.groupProperties[propertyName]
def addElementProperty(self, property, elementName):
if elementName in self.elements or elementName == self.identity_identifier:
self.elementProperties[elementName] = property
else:
print("That element doesn't exist!", property, elementName)
def contains(self, elementName):
return elementName in self.elements
def toLaTeX(self):
return self.groupName