#NEWLINE# @ cacheit #NEWLINE# def _extract_delta( expr , index ) : #NEWLINE# #INDENT# '\n    Extract a simple KroneckerDelta from the expression.\n\n    Returns the tuple ``(delta, newexpr)`` where:\n\n      - ``delta`` is a simple KroneckerDelta expression if one was found,\n        or ``None`` if no simple KroneckerDelta expression was found.\n\n      - ``newexpr`` is a Mul containing the remaining terms; ``expr`` is\n        returned unchanged if no simple KroneckerDelta expression was found.\n\n    Examples\n    ========\n\n    >>> from sympy import KroneckerDelta\n    >>> from sympy.concrete.delta import _extract_delta\n    >>> from sympy.abc import x, y, i, j, k\n    >>> _extract_delta(4*x*y*KroneckerDelta(i, j), i)\n    (KroneckerDelta(i, j), 4*x*y)\n    >>> _extract_delta(4*x*y*KroneckerDelta(i, j), k)\n    (None, 4*x*y*KroneckerDelta(i, j))\n\n    See Also\n    ========\n\n    sympy.functions.special.tensor_functions.KroneckerDelta\n    deltaproduct\n    deltasummation\n    ' #NEWLINE# if ( not _has_simple_delta ( expr , index ) ) : #NEWLINE# #INDENT# return ( None , expr ) #NEWLINE# #UNINDENT# if isinstance ( expr , KroneckerDelta ) : #NEWLINE# #INDENT# return ( expr , S ( 1 ) ) #NEWLINE# #UNINDENT# if ( not expr . is_Mul ) : #NEWLINE# #INDENT# raise ValueError ( 'Incorrect expr' ) #NEWLINE# #UNINDENT# delta = None #NEWLINE# terms = [ ] #NEWLINE# for arg in expr . args : #NEWLINE# #INDENT# if ( ( delta is None ) and _is_simple_delta ( arg , index ) ) : #NEWLINE# #INDENT# delta = arg #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# terms . append ( arg ) #NEWLINE# #UNINDENT# #UNINDENT# return ( delta , expr . func ( * terms ) )