@cacheit
def _get_contractions(string1, keep_only_fully_contracted=False):
 if (keep_only_fully_contracted and string1):
  result = []
 else:
  result = [NO(Mul(*string1))]
 for i in range((len(string1) - 1)):
  for j in range((i + 1), len(string1)):
   c = contraction(string1[i], string1[j])
   if c:
    sign = (((j - i) + 1) % 2)
    if sign:
     coeff = (S.NegativeOne * c)
    else:
     coeff = c
    oplist = (string1[(i + 1):j] + string1[(j + 1):])
    if oplist:
     result.append((coeff * NO((Mul(*string1[:i]) * _get_contractions(oplist, keep_only_fully_contracted=keep_only_fully_contracted)))))
    else:
     result.append((coeff * NO(Mul(*string1[:i]))))
  if keep_only_fully_contracted:
   break
 return Add(*result)

@ cacheit def _get_contractions ( string1 , keep_only_fully_contracted = False ) : if ( keep_only_fully_contracted and string1 ) : result = [ ] else : result = [ NO ( Mul ( * string1 ) ) ] for i in range ( ( len ( string1 ) - 1 ) ) : for j in range ( ( i + 1 ) , len ( string1 ) ) : c = contraction ( string1 [ i ] , string1 [ j ] ) if c : sign = ( ( ( j - i ) + 1 ) % 2 ) if sign : coeff = ( S . NegativeOne * c ) else : coeff = c oplist = ( string1 [ ( i + 1 ) : j ] + string1 [ ( j + 1 ) : ] ) if oplist : result . append ( ( coeff * NO ( ( Mul ( * string1 [ : i ] ) * _get_contractions ( oplist , keep_only_fully_contracted = keep_only_fully_contracted ) ) ) ) ) else : result . append ( ( coeff * NO ( Mul ( * string1 [ : i ] ) ) ) ) if keep_only_fully_contracted : break return Add ( * result )
returns add-object with contracted terms .