#NEWLINE# @ cacheit #NEWLINE# def _simplify_delta( expr ) : #NEWLINE# #INDENT# "\n    Rewrite a KroneckerDelta's indices in its simplest form.\n    " #NEWLINE# from sympy.solvers import solve #NEWLINE# if isinstance ( expr , KroneckerDelta ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# slns = solve ( ( expr . args [ 0 ] - expr . args [ 1 ] ) , dict = True ) #NEWLINE# if ( slns and ( len ( slns ) == 1 ) ) : #NEWLINE# #INDENT# return Mul ( * [ KroneckerDelta ( * ( key , value ) ) for ( key , value ) in slns [ 0 ] . items ( ) ] ) #NEWLINE# #UNINDENT# #UNINDENT# except NotImplementedError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# return expr