def perm2tensor(t, g, canon_bp=False):
 if (not isinstance(t, TensExpr)):
  return t
 new_tids = get_tids(t).perm2tensor(g, canon_bp)
 coeff = get_coeff(t)
 if (g[(-1)] != (len(g) - 1)):
  coeff = (- coeff)
 res = TensMul.from_TIDS(coeff, new_tids, is_canon_bp=canon_bp)
 return res

def perm2tensor ( t , g , canon_bp = False ) : if ( not isinstance ( t , TensExpr ) ) : return t new_tids = get_tids ( t ) . perm2tensor ( g , canon_bp ) coeff = get_coeff ( t ) if ( g [ ( - 1 ) ] != ( len ( g ) - 1 ) ) : coeff = ( - coeff ) res = TensMul . from_TIDS ( coeff , new_tids , is_canon_bp = canon_bp ) return res
returns the tensor corresponding to the permutation g for further details .