#NEWLINE# @ cacheit #NEWLINE# def deltaproduct( f , limit ) : #NEWLINE# #INDENT# '\n    Handle products containing a KroneckerDelta.\n\n    See Also\n    ========\n\n    deltasummation\n    sympy.functions.special.tensor_functions.KroneckerDelta\n    sympy.concrete.products.product\n    ' #NEWLINE# from sympy.concrete.products import product #NEWLINE# if ( ( ( limit [ 2 ] - limit [ 1 ] ) < 0 ) == True ) : #NEWLINE# #INDENT# return S . One #NEWLINE# #UNINDENT# if ( not f . has ( KroneckerDelta ) ) : #NEWLINE# #INDENT# return product ( f , limit ) #NEWLINE# #UNINDENT# if f . is_Add : #NEWLINE# #INDENT# delta = None #NEWLINE# terms = [ ] #NEWLINE# for arg in sorted ( f . args , key = default_sort_key ) : #NEWLINE# #INDENT# if ( ( delta is None ) and _has_simple_delta ( arg , limit [ 0 ] ) ) : #NEWLINE# #INDENT# delta = arg #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# terms . append ( arg ) #NEWLINE# #UNINDENT# #UNINDENT# newexpr = f . func ( * terms ) #NEWLINE# k = Dummy ( 'kprime' , integer = True ) #NEWLINE# if ( isinstance ( limit [ 1 ] , int ) and isinstance ( limit [ 2 ] , int ) ) : #NEWLINE# #INDENT# result = ( deltaproduct ( newexpr , limit ) + sum ( [ ( ( deltaproduct ( newexpr , ( limit [ 0 ] , limit [ 1 ] , ( ik - 1 ) ) ) * delta . subs ( limit [ 0 ] , ik ) ) * deltaproduct ( newexpr , ( limit [ 0 ] , ( ik + 1 ) , limit [ 2 ] ) ) ) for ik in range ( int ( limit [ 1 ] ) , int ( ( limit [ 2 ] + 1 ) ) ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# result = ( deltaproduct ( newexpr , limit ) + deltasummation ( ( ( deltaproduct ( newexpr , ( limit [ 0 ] , limit [ 1 ] , ( k - 1 ) ) ) * delta . subs ( limit [ 0 ] , k ) ) * deltaproduct ( newexpr , ( limit [ 0 ] , ( k + 1 ) , limit [ 2 ] ) ) ) , ( k , limit [ 1 ] , limit [ 2 ] ) , no_piecewise = _has_simple_delta ( newexpr , limit [ 0 ] ) ) ) #NEWLINE# #UNINDENT# return _remove_multiple_delta ( result ) #NEWLINE# #UNINDENT# ( delta , _ ) = _extract_delta ( f , limit [ 0 ] ) #NEWLINE# if ( not delta ) : #NEWLINE# #INDENT# g = _expand_delta ( f , limit [ 0 ] ) #NEWLINE# if ( f != g ) : #NEWLINE# #INDENT# from sympy import factor #NEWLINE# try : #NEWLINE# #INDENT# return factor ( deltaproduct ( g , limit ) ) #NEWLINE# #UNINDENT# except AssertionError : #NEWLINE# #INDENT# return deltaproduct ( g , limit ) #NEWLINE# #UNINDENT# #UNINDENT# return product ( f , limit ) #NEWLINE# #UNINDENT# from sympy import Eq #NEWLINE# c = Eq ( limit [ 2 ] , ( limit [ 1 ] - 1 ) ) #NEWLINE# return ( _remove_multiple_delta ( ( f . subs ( limit [ 0 ] , limit [ 1 ] ) * KroneckerDelta ( limit [ 2 ] , limit [ 1 ] ) ) ) + ( S . One * _simplify_delta ( KroneckerDelta ( limit [ 2 ] , ( limit [ 1 ] - 1 ) ) ) ) )