Example #1
0
 def compose(self,F):        
     Operation.check_compose(self,F)
     (f,g) = tuple(F)        
     if self.idem and f==g:
         return f
     h = dict()
     for x in product(range(self.dom),repeat=f.arity):            
         h[x] = self[(f[x],g[x])]
     if f.arity == 2:
         commutes = True
         for (a,b) in combinations(range(self.dom),2):
             if h[(a,b)] != h[(b,a)]:
                 commutes = False
         if commutes:
             for (a,b) in combinations(range(self.dom),2):
                 del h[(b,a)]
         idempotent = True
         for a in range(self.dom):
             if h[(a,a)] != a:
                 idempotent = False
         if idempotent:
             for a in range(self.dom):
                 del h[(a,a)]
         return BinaryOperation(self.dom,h,commutes,idempotent)
     else:
         return ExplicitOperation(f,arity,self.dom,h)
Example #2
0
 def __getitem__(self,x):
     Operation.check_input(self,x)
     (a,b) = x
     if self.idem and a==b:
         return a
     if self.comm and b < a:
         tmp = a
         a = b
         b = tmp
     return self.f[(a,b)]