+
    i&                        R t ^RIHt ^RIHtHt ^ RIHtHtH	t	H
t
 ^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ R	IHt ]R
 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]R 4       t]RR l4       t R# )z
This module implements sums and products containing the Kronecker Delta function.

References
==========

.. [1] https://mathworld.wolfram.com/KroneckerDelta.html

)product)Sum	summation)AddMulSDummy)cacheit)default_sort_key)KroneckerDelta	Piecewisepiecewise_fold)factor)Interval)solvec                   V P                   '       g   V # Rp\        p\        P                  .pV P                   Fy  pVf\   VP
                  '       dJ   \        WQ4      '       d9   RpVP                  pVP                   Uu. uF  qd^ ,          V,          NK  	  ppKb  V Uu. uF  qfV,          NK  	  ppK{  	  V! V!  # u upi u upi )z:
Expand the first Add containing a simple KroneckerDelta.
NT)is_Mulr   r   Oneargsis_Add_has_simple_deltafunc)exprindexdeltar   termshts   &&     R/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/concrete/delta.py_expand_deltar      s    
 ;;;EDUUGEYY=QXXX*;A*E*EE66D)*0A1XaZZE0E"'(%QqSS%E(E  < 1(s    B= Cc                Z   \        W4      '       g   RV 3# \        V \        4      '       d   V \        P                  3# V P
                  '       g   \        R4      hRp. pV P                   F-  pVf   \        WA4      '       d   TpK  VP                  V4       K/  	  W P                  ! V!  3# )a8  
Extract a simple KroneckerDelta from the expression.

Explanation
===========

Returns the tuple ``(delta, newexpr)`` where:

  - ``delta`` is a simple KroneckerDelta expression if one was found,
    or ``None`` if no simple KroneckerDelta expression was found.

  - ``newexpr`` is a Mul containing the remaining terms; ``expr`` is
    returned unchanged if no simple KroneckerDelta expression was found.

Examples
========

>>> from sympy import KroneckerDelta
>>> from sympy.concrete.delta import _extract_delta
>>> from sympy.abc import x, y, i, j, k
>>> _extract_delta(4*x*y*KroneckerDelta(i, j), i)
(KroneckerDelta(i, j), 4*x*y)
>>> _extract_delta(4*x*y*KroneckerDelta(i, j), k)
(None, 4*x*y*KroneckerDelta(i, j))

See Also
========

sympy.functions.special.tensor_functions.KroneckerDelta
deltaproduct
deltasummation
NzIncorrect expr)r   
isinstancer   r   r   r   
ValueErrorr   _is_simple_deltaappendr   )r   r   r   r   args   &&   r   _extract_deltar&   )   s    D T))d|$''aee};;;)**EEyy=-c99ELL	 
 99e$%%    c                J  a V P                  \        4      '       d   \        V S4      '       d   R# V P                  '       g   V P                  '       dO   \
        ;QJ d)    V3R lV P                   4       F  '       g   K   R# 	  R# ! V3R lV P                   4       4      # R# )z
Returns True if ``expr`` is an expression that contains a KroneckerDelta
that is simple in the index ``index``, meaning that this KroneckerDelta
is nonzero for a single value of the index ``index``.
Tc              3   <   <"   T F  p\        VS4      x  K  	  R # 5i)N)r   ).0r%   r   s   & r   	<genexpr>$_has_simple_delta.<locals>.<genexpr>g   s     J	(e44	s   F)hasr   r#   r   r   anyr   )r   r   s   &fr   r   r   \   si     xxD%((;;;$+++3J		J33J3J3J		JJJr'   c                
   \        V \        4      '       dm   V P                  V4      '       dV   V P                  ^ ,          V P                  ^,          ,
          P	                  V4      pV'       d   VP                  4       ^8H  # R# )zi
Returns True if ``delta`` is a KroneckerDelta and is nonzero for a single
value of the index ``index``.
F)r!   r   r-   r   as_polydegree)r   r   ps   && r   r#   r#   k   sZ     %((UYYu-=-=ZZ]UZZ]*33E:88:?"r'   c           	        V P                   '       d2   V P                  ! \        \        \        V P
                  4      4      !  # V P                  '       g   V # . p. pV P
                   Ff  p\        V\        4      '       d=   VP                  VP
                  ^ ,          VP
                  ^,          ,
          4       KU  VP                  V4       Kh  	  V'       g   V # \        VRR7      p\        V4      ^ 8X  d   \        P                  # \        V4      ^8X  d\   Y$^ ,          P                  4        UUu. uF  w  rV\        WV4      NK  	  upp,          pV P                  ! V!  pW8w  d   \	        V4      # V # u uppi )z(
Evaluate products of KroneckerDelta's.
Tdict)r   r   listmap_remove_multiple_deltar   r   r!   r   r$   r   lenr   Zeroitems)r   eqsnewargsr%   solnskvexpr2s   &       r   r8   r8   x   s   
 {{{yy$s#9499EFGG;;;
CGyyc>**JJsxx{SXXa[01NN3	 
 #D!E
5zQvv	Uq1X^^5EF5ETQN1(5EFF		7#=)%00K	 Gs   3E6c           
     x   \        V \        4      '       d    \        V P                  ^ ,          V P                  ^,          ,
          RR7      pV'       dK   \	        V4      ^8X  d;   \        V^ ,          P                  4        UUu. uF  w  r#\        W#3!  NK  	  upp!  # V # V # u uppi   \         d     T # i ; i)z:
Rewrite a KroneckerDelta's indices in its simplest form.
Tr4   )r!   r   r   r   r9   r   r;   NotImplementedError)r   slnskeyvalues   &   r   _simplify_deltarG      s    
 $''	1		!44@DD	Q.21gmmo?.=
 ,c\:.=? @ @ K4K	?" 	K	s$   A-B* B$
B* $B* *B98B9c                Z  aaa	 S^,          S^,          ,
          ^ 8  R8X  d   \         P                  # V P                  \        4      '       g   \	        V S4      # V P
                  '       Ed   Ro. p\        V P                  \        R7       F5  pSf   \        VS^ ,          4      '       d   VoK$  VP                  V4       K7  	  V P                  ! V!  o	\        RRR7      p\        S^,          \        4      '       dx   \        S^,          \        4      '       d[   \        S	S4      \!        VVV	3R l\#        \        S^,          4      \        S^,          ^,           4      4       4       4      ,           pM\        S	S4      \%        \        S	S^ ,          S^,          V^,
          34      SP'                  S^ ,          V4      ,          \        S	S^ ,          V^,           S^,          34      ,          VS^,          S^,          3\        S	S^ ,          4      R7      ,           p\)        V4      # \+        V S^ ,          4      w  opS'       g<   \-        V S^ ,          4      pW8w  d    \/        \        VS4      4      # \	        V S4      # \)        V P'                  S^ ,          S^,          4      \        S^,          S^,          4      ,          4      \         P                  \3        \        S^,          S^,          ^,
          4      4      ,          ,           #   \0         d    \        TS4      u # i ; i)z
Handle products containing a KroneckerDelta.

See Also
========

deltasummation
sympy.functions.special.tensor_functions.KroneckerDelta
sympy.concrete.products.product
TN)rE   kprime)integerc           	   3      <"   T Fp  p\        SS^ ,          S^,          V^,
          34      SP                  S^ ,          V4      ,          \        SS^ ,          V^,           S^,          34      ,          x  Kr  	  R# 5i)    N)deltaproductsubs)r*   ikr   limitnewexprs   & r   r+   deltaproduct.<locals>.<genexpr>   sz      8Nu 9EWuUVxY^_`YacehiciNj8k

58R(9)WuQxaq&BC9D 9DNus   A8A;)no_piecewise)r   r   r-   r   r   r   sortedr   r
   r   r$   r   r   r!   intrM   sumrangedeltasummationrN   r8   r&   r   r   AssertionErrorrG   )
frP   r   r%   r?   result_gr   rQ   s
   &f      @@r   rM   rM      s    
qE!H	!d*uu55  q%  xxx!&&&67C}!23a!A!AS!	 8
 &&%.(D)eAh$$E!Hc)B)B!'51C 8NSTWX]^_X`TacfglmngorsgsctNu8 5 F
 "'51NWuQxq1q5&AB

58Q'(WuQxQa&ABC E!HeAh'.waA5 F &f--aq*HE1!U1X&6.l1e455 q%  !!&&q58"<^ERSHV[\]V^=_"_`	onU1XuQx!|DEEF F	 " .#Au--.s   #L L*)L*c                   V^,          V^,          ,
          ^ 8  R8X  d   \         P                  # V P                  \        4      '       g   \	        W4      # V^ ,          p\        W4      pVP                  '       d>   \        VP                  ! VP                   Uu. uF  p\        WQV4      NK  	  up!  4      # \        WC4      w  rgVeO   VP                  eA   VP                  w  rV^,          V,
          ^ 8*  R8X  d   V^,          V	,
          ^ 8  R8X  d   RpV'       g   \	        W4      # \        VP                  ^ ,          VP                  ^,          ,
          V4      p
\        V
4      ^ 8X  d   \         P                  # \        V
4      ^8w  d   \        W4      # V
^ ,          pV'       d   VP!                  W;4      # \#        VP!                  W;4      \%        VR,          !  P'                  V4      3\         P                  R34      # u upi )a  
Handle summations containing a KroneckerDelta.

Explanation
===========

The idea for summation is the following:

- If we are dealing with a KroneckerDelta expression, i.e. KroneckerDelta(g(x), j),
  we try to simplify it.

  If we could simplify it, then we sum the resulting expression.
  We already know we can sum a simplified expression, because only
  simple KroneckerDelta expressions are involved.

  If we could not simplify it, there are two cases:

  1) The expression is a simple expression: we return the summation,
     taking care if we are dealing with a Derivative or with a proper
     KroneckerDelta.

  2) The expression is not simple (i.e. KroneckerDelta(cos(x))): we can do
     nothing at all.

- If the expr is a multiplication expr having a KroneckerDelta term:

  First we expand it.

  If the expansion did work, then we try to sum the expansion.

  If not, we try to extract a simple KroneckerDelta term, then we have two
  cases:

  1) We have a simple KroneckerDelta term, so we return the summation.

  2) We did not have a simple term, but we do have an expression with
     simplified KroneckerDelta terms, so we sum this expression.

Examples
========

>>> from sympy import oo, symbols
>>> from sympy.abc import k
>>> i, j = symbols('i, j', integer=True, finite=True)
>>> from sympy.concrete.delta import deltasummation
>>> from sympy import KroneckerDelta
>>> deltasummation(KroneckerDelta(i, k), (k, -oo, oo))
1
>>> deltasummation(KroneckerDelta(i, k), (k, 0, oo))
Piecewise((1, i >= 0), (0, True))
>>> deltasummation(KroneckerDelta(i, k), (k, 1, 3))
Piecewise((1, (i >= 1) & (i <= 3)), (0, True))
>>> deltasummation(k*KroneckerDelta(i, j)*KroneckerDelta(j, k), (k, -oo, oo))
j*KroneckerDelta(i, j)
>>> deltasummation(j*KroneckerDelta(i, j), (j, -oo, oo))
i
>>> deltasummation(i*KroneckerDelta(i, j), (i, -oo, oo))
j

See Also
========

deltaproduct
sympy.functions.special.tensor_functions.KroneckerDelta
sympy.concrete.sums.summation
T:      N)r   r:   r-   r   r   r   r   r   r   r   rX   r&   delta_ranger   r9   r   rN   r   r   as_relational)rZ   rP   rS   xr]   r   r   r   dinfdsupr>   rF   s   &&&         r   rX   rX      s   H 
qE!H	!d*vv55  ""aAaAxxxFFQVVLV^Al;VLMO 	O !&KE 1 1 =&&
!HtOq T)uQx$!/C.LL""%**Q-%**Q-/3E
5zQvv	Uq1}!HEyy""	1	hc
3AA%HI	
 + Ms   HN)F)!__doc__productsr   
summationsr   r   
sympy.corer   r   r   r   sympy.core.cacher	   sympy.core.sortingr
   sympy.functionsr   r   r   sympy.polys.polytoolsr   sympy.sets.setsr   sympy.solvers.solversr   r   r&   r   r#   r8   rG   rM   rX    r'   r   <module>rq      s     & ) ) $ / E E ( $ ' 	 	& 	/& 	/&d 	 	 		 		 	 	8 	 	 	7F 	7Ft 	f 	fr'   