# User:Hillgentleman/LieAlgebra.py

```#defining a class (category) of Lie algebras, using the sympy package
#c.f.http://docs.sympy.org/guide.html#guide
#c.f.http://wiki.sympy.org/wiki/Main_Page

from sympy.abc import a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z
class LieAlgebra:

def __init__(self,name="sl(2)",generators=[e,f,h],product={(e,f):h, (e,h):2*e, (f,h):-2*f}, verbose=False):
self.name = name
self.generators=generators
self.product=product
if verbose: print "\n-----------------\n", name , "\n----------------\n"
signs=[-2,-1,0,+1,+2]
#GENERATE THE FIRST FEW BRACKETS FROM THE BASIC RELATIONS
for i in generators:
for j in generators:
if i == j: break  #j is always smaller than i, in the order e,f,h
product[(isign*i, jsign*j)] = (-1)*isign*jsign*product[(j,i)]
product[(jsign*j, isign*i)] = isign*jsign*product[(j,i)] #need this for stuff like [-f,-h]
if verbose: print "[",isign*i, ",", jsign*j, "]=", product[(isign*i, jsign*j)]

class LieAlgebraMap:
def __init__(self,name="I", fromAlg=LieAlgebra(), toAlg=LieAlgebra()
, map={e:-f, f:-e, h:-h}, verbose=False):
self.name=name
self.fromAlg=fromAlg
self.toAlg=toAlg
self.map=map
#GENERATE THE FIRST FEW MAPPING POINTS FROM LINEARITY
signs=[-2,-1,0,+1,+2]
if verbose:
print "\n----\n", name, ":", fromAlg.name, "--->", toAlg.name
for i in fromAlg.generators:
map[isign*i] = isign*map[i]
if verbose:
print isign*i, "|--->", isign*map[i]

def isHomomorphism(self, verbose=False):
fromAlg=self.fromAlg
toAlg=self.toAlg
map=self.map
name=self.name
for i in fromAlg.generators:
for j in fromAlg.generators:
if i==j : break
if verbose:
print '[',j,',',i,'] = ', fromAlg.product[(j,i)]
print name,'[', j, ',', i, ']=' ,map[fromAlg.product[(j,i)]]
print '[', name, j, ',', name, i, '] = ', toAlg.product[(map[j], map[i])]
if map[fromAlg.product[(j,i)]] != toAlg.product[(map[j], map[i])]:
return False
else:
print "ok..."
return True

if __name__=='__main__':
A = LieAlgebra(verbose=True)
B = LieAlgebra()
m = LieAlgebraMap(verbose=True)
print "\n---------------------------\n"
print m.name, ":", A.name, "--->" , B.name
print "....Is it a Lie Algebra homomorphism?\n"
print m.isHomomorphism(verbose=True)
```