# User:Hillgentleman/FiniteGroup.py

```#A SIMPLE EXERCISE, BUILDING A CLASS OF FINITE GROUPS FOR PYTHON
#STILL WORKING ON IT
class FiniteGroup:
def __init__(self,name="group",elements=[1],product={(1,1):1},inverse={1:1}, identity=1):
self.name = name
self.elements=elements
self.product=product
self.inverse=inverse
self.identity=identity

class FiniteGroupMap:
def __init__(self,name="map",fromGroup=FiniteGroup(),toGroup=FiniteGroup(),map={1:1}):
self.name=name
self.fromGroup=fromGroup
self.toGroup=toGroup
self.map=map
def fromGroup(fromGroup):
self.fromGroup = fromGroup
def toGroup(toGroup):
self.toGroup=toGroup
def map(map):
self.map=map

def isHomomorphism(self,fromGroup, toGroup, map, verbose=False):
print "fromGroup, toGroup, map=",fromGroup, toGroup, map , '\n'
self.fromGroup=fromGroup
self.toGroup=toGroup
self.map=map
for i in fromGroup.elements:
for j in fromGroup.elements:
if verbose:
print i , "." , j , "=" , fromGroup.product[(i,j)]
print map[i] , '.' , map[j] , '=' , toGroup.product[(map[i],map[j])]
if map[fromGroup.product[(i,j)]] != toGroup.product[(map[i],map[j])] :
return False
return True

if __name__ == "__main__":
A=FiniteGroup(name="soliton",elements=[1], product={(1,1):1}, inverse={1:1}, identity={1:1})
B=FiniteGroup(name="one",elements=["e"], product={('e','e'):'e'}, inverse={'e':'e'}, identity={'e':'e'})
m=FiniteGroupMap(name="1-to-'e'", fromGroup=A, toGroup=B, map={1:'e'})
print "A,B,m=", A,B,m ,'\n'
'Is' + m.name + 'a group homomorphism?'
print m.isHomomorphism(fromGroup=A,toGroup=B,map={1:'e'}, verbose=True)
```