
    \hJU                     4   S SK Jr  S SKJr  S SKJr  S SKJrJr  S SK	J
r
  S SKJrJr  S SKJr  S SKJrJr  S S	KJr  S S
KJrJr  S SKJr  S SKJr  S SKJrJr  S SKJ r   S SK!J"r"  S SK#J$r$  S SK%J&r&J'r'  S SK(J)r)  S r*SS.S jr+ " S S\5      r, " S S\,5      r-g)    )Add)Tuple)Expr)AppliedUndefUndefinedFunction)Mul)Equality
Relational)S)SymbolDummy)sympify)piecewise_fold	Piecewise)BooleanFunction)
MatrixBase)IntervalSet)Range)Idx)flatten)siftis_sequence)sympy_deprecation_warningc                   [        U5      n[        U[        5      (       ao  [        USU06u  pVU(       a  [	        S U 5       5      (       d  [        SSSSS9  UR                  nUR                  n[        U " U/UQ70 UD6U " U/UQ70 UD65      $ U[        R                  L a  [        R                  $ U(       aX  [        USU06u  pV[        U5       H;  u  p[        U
5      S:X  d  M  UR                  U
S	   U
S
   5      n[        U
SS
 6 XY'   M=     OFUR                  n[        U5      S:w  a  [        SU-  5      eU Vs/ s H  n[        U5      PM     snSpeU [!        U5      :X  a5  [#        UR$                  5      U-   nUR&                  nU [!        U5      :X  a  M5  0 nU V	s1 s H  oS	   iM	     nn	UR)                  [*        5       H%  nUR,                  " U6 (       a  M  [/        5       X'   M'     UR1                  U5      n[3        U5      nUR1                  UR5                  5        VVs0 s H	  u  nnUU_M     snn5      nXU4$ s  snf s  sn	f s  snnf )zReturn either a special return value or the tuple,
(function, limits, orientation). This code is common to
both ExprWithLimits and AddWithLimits.discretec              3   >   #    U  H  n[        U5      S :H  v   M     g7f   Nlen).0limits     W/var/www/auris/envauris/lib/python3.13/site-packages/sympy/concrete/expr_with_limits.py	<genexpr>_common_new.<locals>.<genexpr>    s     CF5s5zQFs   ax  
                Creating a indefinite integral with an Eq() argument is
                deprecated.

                This is because indefinite integrals do not preserve equality
                due to the arbitrary constants. If you want an equality of
                indefinite integrals, use Eq(Integral(a, x), Integral(b, x))
                explicitly.
                z1.6z!deprecated-indefinite-integral-eq   )deprecated_since_versionactive_deprecations_target
stacklevel   r   N   zspecify dummy variables for %s)r   
isinstancer	   _process_limitsallr   lhsrhsr   NaN	enumerater!   subsr   free_symbols
ValueErrortypelistlimitsfunctionatomsr   hasr   xreplacer   items)clsr;   r   symbolsassumptionsr:   orientationr1   r2   ilifreesrepssymbols_of_integrationpkvs                     r$   _common_newrM      s>    x H(H%% .wJJ3CFCCC% */+N llllC9'9[9C9'9[9; 	; 155uu-wJJv&EA2w!|#==A27!2cr7O	 ' $$t9>08;= =156AuQx6 h
hoo&/$$ h
 D,23FqdF3^^I&uu,--gDG '   &Hh'H  4::<!@<41a!Q$<!@AH[((- 7 4 "As   ?I"I*I
N)r   c                 r	   / nSnU c  SnOU (       a  SnOSnU GHs  n[        U[        [        45      (       aG  U (       a  [        U5      eUR	                  [
        5      R                  5       nXeR                  5       4nO[        U[
        5      (       d  [        USS5      (       a  [        U[        5      (       ae  UR                  b  UR                  c  UR                  [        U5      5        OJUR                  [        XUR                  UR                  5      5        OUR                  [        U5      5        GM$  [        U5      (       Ga*  [        U[        5      (       Gd  [!        U5      S:X  GaG  [        US   [        5      (       Ga.  [#        U5      n[        US   [$        5      (       a4  U (       a  [        U5      eUS   R&                  US   R(                  4USS& O[        US   [*        5      (       a  U (       d  [        U5      eUS   R&                  nUS   R(                  n[-        US   R.                  5      n	U	S:X  a  Xx/USS& OjU[0        R2                  La  US	   /S	X-
  U	-  XS	   -  U-   /-   nO=US	   /S	[0        R4                  U	* US	   -  U-   /-   nO[7        U (       a  S
5      eS5      e[9        [;        U5      5      n[        US	   [
        [        45      (       d  [        US	   SS5      (       Gau  US	   n
[!        U5      S:X  a/  US   c  US   b  US-  nU
/USS  Vs/ s H	  oc  M  UPM     sn-   n[!        U5      n[        U
[        5      (       a  US:X  Ga  US:X  a  UR                  [        U6 5        GMt  US:X  a  [        U
[        5      (       aa  U
R                  U
R                  p Ub!  [=        US   U:  5      (       d  [?        S5      e Ub!  [=        US   U:*  5      (       d  [?        S5      eUR                  [        U6 5        GM
  US:X  d  US:X  a#  US   c  UR                  [        U
5      5        GM9  US:X  a   UR                  [        XS   5      5        GM_  [?        S[A        U5      -  5      e   X#4$ s  snf ! [         a     Nf = f! [         a     Nf = f)a  Process the list of symbols and convert them to canonical limits,
storing them as Tuple(symbol, lower, upper). The orientation of
the function is also returned when the upper limit is missing
so (x, 1, None) becomes (x, None, 1) and the orientation is changed.
In the case that a limit is specified as (symbol, Range), a list of
length 4 may be returned if a change of variables is needed; the
expression that should replace the symbol in the expression is
the fourth element in the list.
r-   Nzdiscrete must be True or Falsez%use Range, not Interval or Relationalz%use Interval or Relational, not Range	_diff_wrtF   r   zexpecting RangezRelational or single Intervalr   r,   r+   z%Summation will set Idx value too low.z&Summation will set Idx value too high.zInvalid limits given: %s)!r.   r
   r   	TypeErrorr<   r   popas_setgetattrr   lowerupperappendr   r   r   r!   r9   r   infsupr   absstepr   NegativeInfinityInfinityNotImplementedErrorr   r   boolr7   str)r   rA   r:   rC   err_msgVvariablelohidx	newsymbolrD   lenVs                r$   r/   r/   ]   s!    FK2	99a*o677((wwv**,H88:&A6""gae&D&D!S!!77?aggoMM%(+MM%77AGG"<=eAh'q>>*Q"4"41v{z!A$44GadH--'00aDHHadhh.AabE!e,,#'001B1BQqTYYBQw!#!"Q%7%77!"1!bg]BtGbL)I IA!"1!QZZ"QqTB)G GA .-5): :7: : 
#A!A$..'!A$U2S2SaD	q6Q;t|!(8#r)"!AB%&I%Qq%&IIA1v!)S11TQYqyeQi0 qy%i55 &/__ioo%#%>$qtrz:J:J*45\*]$]%#%>$qtrz:J:J*45]*^$^ eQi0 qyTQY1Q4<eI&67 eIt&<= 3c'lBCCg j K 'J& $- % $%
 $- % $%s0   1R;R $R%$R)
R&%R&)
R65R6c                       \ rS rSrSrS r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\S
 5       rS rS r\S 5       r\S 5       rSrg)ExprWithLimits   )is_commutativec                 \   SSK Jn  [        X/UQ7S[        X5      0UD6n[	        U[
        5      (       a  Uu  pnOU$ [        S U 5       5      (       a  [        S5      e[        R                  " U 40 UD6nU/n	U	R                  U5        [        U	5      Ul        UR                  Ul        U$ )Nr   )Productr   c              3   V   #    U  H  n[        U5      S :g  =(       d    SU;   v   M!     g7fr   r    r"   ls     r$   r%   )ExprWithLimits.__new__.<locals>.<genexpr>   s$     8As1v{'dai's   ')z:ExprWithLimits requires values for lower and upper bounds.)sympy.concrete.productsrn   rM   
issubclassr.   tupleanyr7   r   __new__extend_argsrl   )
r@   r;   rA   rB   rn   prer:   _objarglists
             r$   rw   ExprWithLimits.__new__   s    3# >' >->1<>c5!!"%HaJ 8888YZZll3.+.*v'N	%44
    c                      U R                   S   $ )zReturn the function applied across limits.

Examples
========

>>> from sympy import Integral
>>> from sympy.abc import x
>>> Integral(x**2, (x,)).function
x**2

See Also
========

limits, variables, free_symbols
r   ry   selfs    r$   r;   ExprWithLimits.function   s    " zz!}r   c                 .    U R                   R                  $ N)r;   kindr   s    r$   r   ExprWithLimits.kind   s    }}!!!r   c                      U R                   SS $ )zReturn the limits of expression.

Examples
========

>>> from sympy import Integral
>>> from sympy.abc import x, i
>>> Integral(x**i, (i, 1, 3)).limits
((i, 1, 3),)

See Also
========

function, variables, free_symbols
r-   Nr   r   s    r$   r:   ExprWithLimits.limits   s    " zz!"~r   c                 J    U R                    Vs/ s H  oS   PM	     sn$ s  snf )a1  Return a list of the limit variables.

>>> from sympy import Sum
>>> from sympy.abc import x, i
>>> Sum(x**i, (i, 1, 3)).variables
[i]

See Also
========

function, limits, free_symbols
as_dummy : Rename dummy variables
sympy.integrals.integrals.Integral.transform : Perform mapping on the dummy variable
r   )r:   r   rq   s     r$   	variablesExprWithLimits.variables
  s"      #kk*k!k***s    c                 n    U R                    Vs/ s H  n[        U5      S:w  d  M  US   PM     sn$ s  snf )ap  Return only variables that are dummy variables.

Examples
========

>>> from sympy import Integral
>>> from sympy.abc import x, i, j, k
>>> Integral(x**i, (i, 1, 3), (j, 2), k).bound_symbols
[i, j]

See Also
========

function, limits, free_symbols
as_dummy : Rename dummy variables
sympy.integrals.integrals.Integral.transform : Perform mapping on the dummy variable
r-   r   )r:   r!   r   s     r$   bound_symbolsExprWithLimits.bound_symbols  s0    & #kk9kSVq[!k999s   2	2c                 z   U R                   U R                  p!U R                   Vs0 s H-  nUS   US   R                  US   1:X  a  US   O	[        5       _M/     nnUR	                  U5      nUR                  nU Hi  nXFS      n[        U5      S:X  a  UR                  U5        M,  Xu;   a  UR                  U5        USS  H  nUR                  UR                  5        M      Mk     UR                  5        VVs0 s H  u  pXx_M	     nnnU V	s1 s H  oR                  X5      iM     sn	$ s  snf s  snnf s  sn	f )z
This method returns the symbols in the object, excluding those
that take on a specific value (i.e. the dummy symbols).

Examples
========

>>> from sympy import Sum
>>> from sympy.abc import x, y
>>> Sum(x, (x, y, 1)).free_symbols
{y}
r   r-   N)r;   r:   r6   r   r>   r!   addremoveupdater?   get)
r   r;   r:   rD   rH   isymsxabrL   rK   r{   s
             r$   r6   ExprWithLimits.free_symbols1  s"   "  ==$++& [["  !ad//AaD69aduwF  	 "$$T*%%CVA3x1}		!zQWQ^^,   "&..(-.1..!" /.s   4D-;D2D8c                 $    U R                   (       + $ )z7Return True if the Sum has no free symbols, else False.)r6   r   s    r$   	is_numberExprWithLimits.is_numberW  s     $$$$r   c                     U R                    Vs/ s H  oDS   U:w  a  UOXU4PM     nnU R                  nU R                  " U/UQ76 $ s  snf )Nr   )r:   r;   func)r   xabrD   r:   	integrands          r$   _eval_intervalExprWithLimits._eval_interval\  sN    ;?;;G;a!	1ay0;GMM	yy,V,, Hs   Ac                    U R                   [        U R                  5      pCUR                  5         [	        U[
        5      (       a+  UR                  R                  U R                  5      (       Ga  Sn[        U5       H  u  pgS[        U5      :X  a   XS   :X  a  UR                  (       a  U4nOX4n[        US   /USS  Vs/ s H  oR                  X5      PM     snQ76 XF'   [        US   R                  R                  UR                  5      5      S:w  d  M  Sn  O   [	        U[        [        45      (       a  [        U R                   5      R                  [        UR#                  [
        5      5      5      n	[        U R                   5      R                  [        UR$                  5      5      n
U	R'                  U
5      (       d  [)        S5      eSnU(       a  UR+                  X5      nOb[        U5       HS  u  pg[        U5      S:X  d  M  [        US   /USS  Vs/ s H  oR                  X5      PM     snQ76 XF'   XS   :X  d  MS    O   [        U5       HB  u  pg[        U5      S:X  d  M  US   US   -
  R,                  (       d  M2  [        US   5      XF'   MD     UR                  5         U R.                  " U/UQ76 $ s  snf s  snf )	ao  
Perform substitutions over non-dummy variables
of an expression with limits.  Also, can be used
to specify point-evaluation of an abstract antiderivative.

Examples
========

>>> from sympy import Sum, oo
>>> from sympy.abc import s, n
>>> Sum(1/n**s, (n, 1, oo)).subs(s, 2)
Sum(n**(-2), (n, 1, oo))

>>> from sympy import Integral
>>> from sympy.abc import x, a
>>> Integral(a*x**2, x).subs(x, 4)
Integral(a*x**2, (x, 4))

See Also
========

variables : Lists the integration variables
transform : Perform mapping on the dummy variable for integrals
change_index : Perform mapping on the sum and product dummy variables

Tr-   r   NFz-substitution cannot create dummy dependenciesr   rP   )r;   r9   r:   reverser.   r   r6   intersectionr4   r!   rO   r   _subsr   r   setr   r<   argsissubsetr7   r5   is_zeror   )r   oldnewr   r:   sub_into_funcrD   r   rq   sy2sy1s              r$   
_eval_subsExprWithLimits._eval_subsa  sM   6 }}d4;;&7f 	#v&&  --d.?.?@@ M#F+C=SF]}}"f"j!#a&Ps12w+Ow!GGC,=w+OP	s1v**778H8HIJaO$)M , #.?@AA$..)66s399V;L7MN$..)66s388}E||C(($GI I $yy* $F+s8q= %c!f T3qr7/S7a0A7/S TFI!f}	 ,  'FA3x1}#a&3q6/!:!:!:!#a&O	 (
 	yy'''9 ,P" 0Ts   K"Kc                     SnU R                    Ht  n[        U5      S:X  aN  [        S USS  5       5      (       a    g[        S USS  5       5      (       a  US   R                  c  SnM\  M^  M`  US   R                  b  Mr  SnMv     U(       a  gg)	a{  
Returns True if the limits are known to be finite, either by the
explicit bounds, assumptions on the bounds, or assumptions on the
variables.  False if known to be infinite, based on the bounds.
None if not enough information is available to determine.

Examples
========

>>> from sympy import Sum, Integral, Product, oo, Symbol
>>> x = Symbol('x')
>>> Sum(x, (x, 1, 8)).has_finite_limits
True

>>> Integral(x, (x, 1, oo)).has_finite_limits
False

>>> M = Symbol('M')
>>> Sum(x, (x, 1, M)).has_finite_limits

>>> N = Symbol('N', integer=True)
>>> Product(x, (x, 1, N)).has_finite_limits
True

See Also
========

has_reversed_limits

Fr   c              3   8   #    U  H  oR                   v   M     g 7fr   is_infiniterp   s     r$   r%   3ExprWithLimits.has_finite_limits.<locals>.<genexpr>  s     6g}}g   r-   Nc              3   <   #    U  H  oR                   S L v   M     g 7fr   r   rp   s     r$   r%   r     s     @1$.s   r   T)r:   r!   rv   r   )r   ret_Nonelims      r$   has_finite_limits ExprWithLimits.has_finite_limits  s    B ;;C3x1}6c!"g666 @AB@@@1v))1#' 2 A
 q6%%-#H  r   c                     SnU R                    HE  n[        U5      S:X  a3  Uu  p4nXT-
  nUR                  (       a    gUR                  (       a  MA  SnME    g   U(       a  gg)aH  
Returns True if the limits are known to be in reversed order, either
by the explicit bounds, assumptions on the bounds, or assumptions on the
variables.  False if known to be in normal order, based on the bounds.
None if not enough information is available to determine.

Examples
========

>>> from sympy import Sum, Integral, Product, oo, Symbol
>>> x = Symbol('x')
>>> Sum(x, (x, 8, 1)).has_reversed_limits
True

>>> Sum(x, (x, 1, oo)).has_reversed_limits
False

>>> M = Symbol('M')
>>> Integral(x, (x, 1, M)).has_reversed_limits

>>> N = Symbol('N', integer=True, positive=True)
>>> Sum(x, (x, 1, N)).has_reversed_limits
False

>>> Product(x, (x, 2, N)).has_reversed_limits

>>> Product(x, (x, 2, N)).subs(N, N + 2).has_reversed_limits
False

See Also
========

sympy.concrete.expr_with_intlimits.ExprWithIntLimits.has_empty_sequence

Fr   TN)r:   r!   is_extended_negativeis_extended_nonnegative)r   r   r   varr   r   difs          r$   has_reversed_limits"ExprWithLimits.has_reversed_limits  s^    J ;;C3x1}	e++00#H  r    N)__name__
__module____qualname____firstlineno__	__slots__rw   propertyr;   r   r:   r   r   r6   r   r   r   r   r   __static_attributes__r   r   r$   rj   rj      s    #I,  $ " "  $ + +" : :( #/ #/J % %-
M(^ 0 0d 3 3r   rj   c                   @    \ rS rSrSrSrS rS rS rS r	S r
S	 rSrg
)AddWithLimitsi  zNRepresents unevaluated oriented additions.
Parent class for Integral and Sum.
r   c                    SSK Jn  [        X/UQ7S[        X5      0UD6n[	        U[
        5      (       a  Uu  pnOU$ [        R                  " U 40 UD6nXq-  /n	U	R                  U5        [        U	5      Ul	        UR                  Ul
        U$ )Nr   )Sumr   )sympy.concrete.summationsr   rM   rt   r.   ru   r   rw   rx   ry   rl   )
r@   r;   rA   rB   r   rz   r:   rC   r|   r}   s
             r$   rw   AddWithLimits.__new__!  s    1# :' :):-8:c5!!,/)HkJll3.+.'(v'N	%44
r   c                     [        S [        U R                  5       5       5      (       a5  U R                  " U R                  R                  5       /U R                  Q76 $ g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   is_realr"   r   s     r$   r%   .AddWithLimits._eval_adjoint.<locals>.<genexpr>3       7"6Qyy"6r   )r0   r   r:   r   r;   adjointr   s    r$   _eval_adjointAddWithLimits._eval_adjoint2  sD    7'$++"677799T]]224Ct{{CCr   c                     [        S [        U R                  5       5       5      (       a5  U R                  " U R                  R                  5       /U R                  Q76 $ g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r   r   s     r$   r%   0AddWithLimits._eval_conjugate.<locals>.<genexpr>8  r   r   )r0   r   r:   r   r;   	conjugater   s    r$   _eval_conjugateAddWithLimits._eval_conjugate7  D    7'$++"677799T]]446EEEr   c                     [        S [        U R                  5       5       5      (       a5  U R                  " U R                  R                  5       /U R                  Q76 $ g )Nc              3   8   #    U  H  oR                   v   M     g 7fr   r   r   s     r$   r%   0AddWithLimits._eval_transpose.<locals>.<genexpr>=  r   r   )r0   r   r:   r   r;   	transposer   s    r$   _eval_transposeAddWithLimits._eval_transpose<  r   r   c                   ^  S[        T R                  5      :X  a|  T R                  R                  " S0 UD6nUR                  (       aL  [        UR                  U 4S j5      n[        US   6 T R                  " [        US   6 /T R                  Q76 -  $  T $ T R                  " T R                  /T R                  SS Q76 R                  5       nUR                  T R                  S   5      (       d1  T R                  ST R                  S   /5      R                  5       U-  $ [        U[        5      (       a-  T R                  UT R                  S   5      R                  5       $ T $ )Nr-   c                 x   > U R                   =(       a'    [        TR                  5      U R                  -  (       + $ r   )rl   r   r   r6   )wr   s    r$   <lambda>,AddWithLimits._eval_factor.<locals>.<lambda>E  s/    13C3C 4A/!..@@4Ar   TFr   r,   r   )r!   r:   r;   factoris_Mulr   r   r   r   r=   r   doitr.   )r   hintssummandouts   `   r$   _eval_factorAddWithLimits._eval_factorA  s/   DKK  mm**3U3G~~7<< *A BCItyyc%j1A ("[[(" " "   iiBAb0ABIIKG;;t~~b122yyT[[_$56;;=gEEGS))yy$++b/:AACCr   c           	        ^  T R                   R                  " S0 UD6nUR                  SS5      nUR                  (       ae  U(       d   UR                  (       aM  T R
                  SLa>  [        UR                   Vs/ s H   nT R                  " U/T R                  Q76 PM"     sn6 $ [        U[        5      (       a  UR                  U 4S j5      $ UT R                   :w  a  T R                  " U/T R                  Q76 $ T $ s  snf )NforceFc                 >   > TR                   " U /TR                  Q76 $ r   )r   r:   )r   r   s    r$   r   2AddWithLimits._eval_expand_basic.<locals>.<lambda>X  s    tyy/IT[[/Ir   r   )r;   expandr   is_Addrl   r   r   r   r   r:   r.   r   	applyfunc)r   r   r   r   rD   s   `    r$   _eval_expand_basic AddWithLimits._eval_expand_basicQ  s    --&&//		'5)NN)?)?''u4W\\J\13t{{3\JKK,,$$%IJJ%99W3t{{33 Ks   ;'C?N)r   r   r   r   __doc__r   rw   r   r   r   r   r   r   r   r   r$   r   r     s,     I"


 
r   r   ).sympy.core.addr   sympy.core.containersr   sympy.core.exprr   sympy.core.functionr   r   sympy.core.mulr   sympy.core.relationalr	   r
   sympy.core.singletonr   sympy.core.symbolr   r   sympy.core.sympifyr   $sympy.functions.elementary.piecewiser   r   sympy.logic.boolalgr   sympy.matrices.matrixbaser   sympy.sets.setsr   r   sympy.sets.fancysetsr   sympy.tensor.indexedr   sympy.utilitiesr   sympy.utilities.iterablesr   r   sympy.utilities.exceptionsr   rM   r/   rj   r   r   r   r$   <module>r     sm     '   ?  6 " + & / 0 ) & $ # 7 @D)N (, gTPT Pf
AN Ar   