@cacheit
def _expand_delta(expr, index):
 if (not expr.is_Mul):
  return expr
 delta = None
 func = Add
 terms = [S(1)]
 for h in expr.args:
  if ((delta is None) and h.is_Add and _has_simple_delta(h, index)):
   delta = True
   func = h.func
   terms = [(terms[0] * t) for t in h.args]
  else:
   terms = [(t * h) for t in terms]
 return func(*terms)

@ cacheit def _expand_delta ( expr , index ) : if ( not expr . is_Mul ) : return expr delta = None func = Add terms = [ S ( 1 ) ] for h in expr . args : if ( ( delta is None ) and h . is_Add and _has_simple_delta ( h , index ) ) : delta = True func = h . func terms = [ ( terms [ 0 ] * t ) for t in h . args ] else : terms = [ ( t * h ) for t in terms ] return func ( * terms )
expand the first add containing a simple kroneckerdelta .