Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Another way (less complete than slelievre's answer but more efficient for just a quick computation) is to compute directly in the Free algebra, but instead of using the product, use the following:

def fast_product(a,b): res = 0 a = F(a) b = F(b)

data_a =[(w.to_word(), cf) for w, cf in a] data_b =[(w.to_word(), cf) for w, cf in b] for wa,cfa in data_a: for wb,cfb in data_b: if len(wb) + len(wa) <= k: res = res + cfacfbF.monomial(wa)*F.monomial(wb) return res

Another way (less complete than slelievre's answer but more efficient for just a quick computation) is to compute directly in the Free algebra, but instead of using the product, use the following:

def fast_product(a,b):  res = 0 a = F(a) b = F(b)
F(b)

data_a =[(w.to_word(), cf) for w, cf in a] data_b =[(w.to_word(), cf) for w, cf in b] for wa,cfa in data_a: data_a: for wb,cfb in data_b: if len(wb) + len(wa) <= k: res = k: res = res + cfacfbF.monomial(wa)*F.monomial(wb) return res

res

Another way (less complete than slelievre's @slelievre's answer but more efficient for just a quick computation) is to compute directly in the Free algebra, but instead of using the product, use the following:

def fast_product(a,b): 
    fast_product(a, b):
res = 0 0
a = F(a) F(a)
b = F(b) 
    F(b)
data_a =[(w.to_word(), = [(w.to_word(), cf) for w, cf in a]
    a] 
data_b =[(w.to_word(), = [(w.to_word(), cf) for w, cf in b] 
b]
for wa, cfa     for wa,cfa in data_a:
     for wb,cfb wb, cfb in data_b: 
    data_b:
        if len(wb) + len(wa) <= k:
            res += cfa * cfb * F.monomial(wa) * F.monomial(wb)     res = res + cfacfbF.monomial(wa)*F.monomial(wb)
     return res

Another way (less complete than @slelievre's answer but more efficient for just a quick computation) is to compute directly in the Free free algebra, but using the following instead of using the product, use the following:product:

def fast_product(a, b):
 res = 0
 a = F(a)
 b = F(b)
 data_a = [(w.to_word(), cf) for w, cf in a] 
 data_b = [(w.to_word(), cf) for w, cf in b]
 for wa, cfa  in data_a:
     for wb, cfb in data_b:
         if len(wb) + len(wa) <= k:
             res += cfa * cfb * F.monomial(wa) * F.monomial(wb)  
 return res

Another way (less complete than @slelievre's answer but more efficient for just a quick computation) is to compute directly in the free algebra, using the following instead of the product:

def fast_product(a, b):
    res = 0
F.zero()
    a = F(a)
    b = F(b)
    data_a = [(w.to_word(), cf) for w, cf in a] 
    data_b = [(w.to_word(), cf) for w, cf in b]
    for wa, cfa  in data_a:
        for wb, cfb in data_b:
            if len(wb) + len(wa) <= k:
                res += cfa * cfb * F.monomial(wa) * F.monomial(wb)  
    return res