Ticket #5931: e.patch

File e.patch, 1.4 KB (added by jdc, 10 years ago)
  • sage/combinat/symmetric_group_algebra.py

    # HG changeset patch
    # User Dan Christensen <jdc@uwo.ca>
    # Date 1240969172 14400
    # Node ID 9c4fea38b4c35b8fff068eddc544734a09539211
    # Parent  5c0961ff033d04c42cc1d920b97d191b5ab44c0e
    Greatly speed up sage.combinat.symmetric_group_algebra.e
    The old code essentially reimplemented the multiplication in
    the group algebra.  The new code accumulates the symmetrizers
    and antisymmetrizers separately, and then does one multiply
    at the end.  This probably results in the same number of
    operations, but it avoids creating many intermediate objects,
    so it is about 10x faster.
    
    diff -r 5c0961ff033d -r 9c4fea38b4c3 sage/combinat/symmetric_group_algebra.py
    a b  
    428428    permutation_options['mult'] = 'l2r'
    429429   
    430430    if t in e_cache:
    431         res =  e_cache[t]
     431        res = e_cache[t]
    432432    else:
    433433        rs = t.row_stabilizer()
    434434        cs = t.column_stabilizer()
     
    436436
    437437        QSn = SymmetricGroupAlgebra(QQ, n)
    438438
    439         res = 0
     439        sym = 0
    440440        for h in rs:
    441             for v in cs:
    442                 res += v.sign() * QSn( (h*v).list() )
     441            sym += QSn(h.list())
     442        antisym = 0
     443        for v in cs:
     444            antisym += v.sign() * QSn(v.list())
     445        res = antisym*sym
    443446        e_cache[t] = res
    444447
    445448    permutation_options['mult'] = mult