def substitute_indices(t, *index_tuples):
 if (not isinstance(t, TensExpr)):
  return t
 free = t.free
 free1 = []
 for (j, ipos, cpos) in free:
  for (i, v) in index_tuples:
   if ((i._name == j._name) and (i._tensortype == j._tensortype)):
    if (i._is_up == j._is_up):
     free1.append((v, ipos, cpos))
    else:
     free1.append(((- v), ipos, cpos))
    break
  else:
   free1.append((j, ipos, cpos))
 t = TensMul.from_data(t.coeff, t.components, free1, t.dum)
 return t

def substitute_indices ( t , * index_tuples ) : if ( not isinstance ( t , TensExpr ) ) : return t free = t . free free1 = [ ] for ( j , ipos , cpos ) in free : for ( i , v ) in index_tuples : if ( ( i . _name == j . _name ) and ( i . _tensortype == j . _tensortype ) ) : if ( i . _is_up == j . _is_up ) : free1 . append ( ( v , ipos , cpos ) ) else : free1 . append ( ( ( - v ) , ipos , cpos ) ) break else : free1 . append ( ( j , ipos , cpos ) ) t = TensMul . from_data ( t . coeff , t . components , free1 , t . dum ) return t
return a tensor with free indices substituted according to index_tuples index_types list of tuples note: this method will neither raise or lower the indices .