
    \hX,                     T    S SK Jr  S SKJr  S SKJr   " S S\5      r " S S\5      rg)	    )ExprWithLimits)S)Eqc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )ReorderError   z;
Exception raised when trying to reorder dependent limits.
c                 4   > [         TU ]  U< SU< S35        g )Nz could not be reordered: .)super__init__)selfexprmsg	__class__s      Z/var/www/auris/envauris/lib/python3.13/site-packages/sympy/concrete/expr_with_intlimits.pyr   ReorderError.__init__	   s    04c:	<     )__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classcell__)r   s   @r   r   r      s    < <r   r   c                   H    \ rS rSrSrSrS
S jrS rS rS r	\
S	 5       rSrg)ExprWithIntLimits   z
Superclass for Product and Sum.

See Also
========

sympy.concrete.expr_with_limits.ExprWithLimits
sympy.concrete.products.Product
sympy.concrete.summations.Sum
r   Nc                 (   Uc  Un/ nU R                    GH6  nUS   U:X  Ga  UR                  U5      nUR                  5       S:w  a  [        S5      eUR	                  U5      nUR	                  [
        R                  5      nUR                  (       a  U[
        R                  :X  a&  UR                  X7US   -  U-   XuS   -  U-   45        M  U[
        R                  :X  a&  UR                  X7US   -  U-   XuS   -  U-   45        M  [        S5      eUR                  X7US   -  U-   XuS   -  U-   45        GM%  UR                  U5        GM9     U R                  R                  XW-
  W-  5      n	U	R                  X5      n	U R                  " U	/UQ76 $ )aw	  
Change index of a Sum or Product.

Perform a linear transformation `x \mapsto a x + b` on the index variable
`x`. For `a` the only values allowed are `\pm 1`. A new variable to be used
after the change of index can also be specified.

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

``change_index(expr, var, trafo, newvar=None)`` where ``var`` specifies the
index variable `x` to transform. The transformation ``trafo`` must be linear
and given in terms of ``var``. If the optional argument ``newvar`` is
provided then ``var`` gets replaced by ``newvar`` in the final expression.

Examples
========

>>> from sympy import Sum, Product, simplify
>>> from sympy.abc import x, y, a, b, c, d, u, v, i, j, k, l

>>> S = Sum(x, (x, a, b))
>>> S.doit()
-a**2/2 + a/2 + b**2/2 + b/2

>>> Sn = S.change_index(x, x + 1, y)
>>> Sn
Sum(y - 1, (y, a + 1, b + 1))
>>> Sn.doit()
-a**2/2 + a/2 + b**2/2 + b/2

>>> Sn = S.change_index(x, -x, y)
>>> Sn
Sum(-y, (y, -b, -a))
>>> Sn.doit()
-a**2/2 + a/2 + b**2/2 + b/2

>>> Sn = S.change_index(x, x+u)
>>> Sn
Sum(-u + x, (x, a + u, b + u))
>>> Sn.doit()
-a**2/2 - a*u + a/2 + b**2/2 + b*u + b/2 - u*(-a + b + 1) + u
>>> simplify(Sn.doit())
-a**2/2 + a/2 + b**2/2 + b/2

>>> Sn = S.change_index(x, -x - u, y)
>>> Sn
Sum(-u - y, (y, -b - u, -a - u))
>>> Sn.doit()
-a**2/2 - a*u + a/2 + b**2/2 + b*u + b/2 - u*(-a + b + 1) + u
>>> simplify(Sn.doit())
-a**2/2 + a/2 + b**2/2 + b/2

>>> P = Product(i*j**2, (i, a, b), (j, c, d))
>>> P
Product(i*j**2, (i, a, b), (j, c, d))
>>> P2 = P.change_index(i, i+3, k)
>>> P2
Product(j**2*(k - 3), (k, a + 3, b + 3), (j, c, d))
>>> P3 = P2.change_index(j, -j, l)
>>> P3
Product(l**2*(k - 3), (k, a + 3, b + 3), (l, -d, -c))

When dealing with symbols only, we can make a
general linear transformation:

>>> Sn = S.change_index(x, u*x+v, y)
>>> Sn
Sum((-v + y)/u, (y, b*u + v, a*u + v))
>>> Sn.doit()
-v*(a*u - b*u + 1)/u + (a**2*u**2/2 + a*u*v + a*u/2 - b**2*u**2/2 - b*u*v + b*u/2 + v)/u
>>> simplify(Sn.doit())
a**2*u/2 + a/2 - b**2*u/2 + b/2

However, the last result can be inconsistent with usual
summation where the index increment is always 1. This is
obvious as we get back the original value only for ``u``
equal +1 or -1.

See Also
========

sympy.concrete.expr_with_intlimits.ExprWithIntLimits.index,
reorder_limit,
sympy.concrete.expr_with_intlimits.ExprWithIntLimits.reorder,
sympy.concrete.summations.Sum.reverse_order,
sympy.concrete.products.Product.reverse_order
r      z"Index transformation is not linear   z>Linear transformation results in non-linear summation stepsize)limitsas_polydegree
ValueErrorcoeff_monomialr   One	is_numberappendNegativeOnefunctionsubsfunc)
r   vartrafonewvarr"   limitpalphabetar+   s
             r   change_indexExprWithIntLimits.change_index   sq   r >F[[EQx3MM#&88:?$%IJJ((-''.??~vU1X~/DeRSHnW[F[&\]!--/vU1X~/DeRSHnW[F[&\]()ijj MM6q>D+@%a.SWBW"XYe$% !( ==%%c$J+=>==-yy+F++r   c                     U R                    Vs/ s H  o"S   PM	     nnUR                  U5      S:w  a  [        U S5      eUR                  U5      $ s  snf )a  
Return the index of a dummy variable in the list of limits.

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

``index(expr, x)``  returns the index of the dummy variable ``x`` in the
limits of ``expr``. Note that we start counting with 0 at the inner-most
limits tuple.

Examples
========

>>> from sympy.abc import x, y, a, b, c, d
>>> from sympy import Sum, Product
>>> Sum(x*y, (x, a, b), (y, c, d)).index(x)
0
>>> Sum(x*y, (x, a, b), (y, c, d)).index(y)
1
>>> Product(x*y, (x, a, b), (y, c, d)).index(x)
0
>>> Product(x*y, (x, a, b), (y, c, d)).index(y)
1

See Also
========

reorder_limit, reorder, sympy.concrete.summations.Sum.reverse_order,
sympy.concrete.products.Product.reverse_order
r   r    z0Number of instances of variable not equal to one)r"   countr%   index)r   xr1   	variabless       r   r9   ExprWithIntLimits.index   sQ    > ,0;;7;%1X;	7??1"T#UVV??1%% 8s   Ac                 8   U nU H  n[        U5      S:w  a  [        US5      eUS   nUS   n[        US   [        5      (       d  U R	                  US   5      n[        US   [        5      (       d  U R	                  US   5      nUR                  XE5      nM     U$ )a  
Reorder limits in a expression containing a Sum or a Product.

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

``expr.reorder(*arg)`` reorders the limits in the expression ``expr``
according to the list of tuples given by ``arg``. These tuples can
contain numerical indices or index variable names or involve both.

Examples
========

>>> from sympy import Sum, Product
>>> from sympy.abc import x, y, z, a, b, c, d, e, f

>>> Sum(x*y, (x, a, b), (y, c, d)).reorder((x, y))
Sum(x*y, (y, c, d), (x, a, b))

>>> Sum(x*y*z, (x, a, b), (y, c, d), (z, e, f)).reorder((x, y), (x, z), (y, z))
Sum(x*y*z, (z, e, f), (y, c, d), (x, a, b))

>>> P = Product(x*y*z, (x, a, b), (y, c, d), (z, e, f))
>>> P.reorder((x, y), (x, z), (y, z))
Product(x*y*z, (z, e, f), (y, c, d), (x, a, b))

We can also select the index variables by counting them, starting
with the inner-most one:

>>> Sum(x**2, (x, a, b), (x, c, d)).reorder((0, 1))
Sum(x**2, (x, c, d), (x, a, b))

And of course we can mix both schemes:

>>> Sum(x*y, (x, a, b), (y, c, d)).reorder((y, x))
Sum(x*y, (y, c, d), (x, a, b))
>>> Sum(x*y, (x, a, b), (y, c, d)).reorder((y, 0))
Sum(x*y, (y, c, d), (x, a, b))

See Also
========

reorder_limit, index, sympy.concrete.summations.Sum.reverse_order,
sympy.concrete.products.Product.reverse_order
r!   zInvalid number of argumentsr   r    )lenr%   
isinstanceintr9   reorder_limit)r   argnew_exprrindex1index2s         r   reorderExprWithIntLimits.reorder   s    \ A1v{ $ABBqTFqTFadC((AaD)adC((AaD)--f=H  r   c                 8   U R                    Vs1 s H  o3S   iM	     nnU R                   U   nU R                   U   n[        [        US   R                  5      R	                  U5      5      S:X  Ga  [        [        US   R                  5      R	                  U5      5      S:X  a  [        [        US   R                  5      R	                  U5      5      S:X  a  [        [        US   R                  5      R	                  U5      5      S:X  a}  / n[        U R                   5       HF  u  pX:X  a  UR                  U5        M  X:X  a  UR                  U5        M5  UR                  U5        MH     [        U 5      " U R                  /UQ76 $ [        U S5      es  snf )a}  
Interchange two limit tuples of a Sum or Product expression.

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

``expr.reorder_limit(x, y)`` interchanges two limit tuples. The
arguments ``x`` and ``y`` are integers corresponding to the index
variables of the two limits which are to be interchanged. The
expression ``expr`` has to be either a Sum or a Product.

Examples
========

>>> from sympy.abc import x, y, z, a, b, c, d, e, f
>>> from sympy import Sum, Product

>>> Sum(x*y*z, (x, a, b), (y, c, d), (z, e, f)).reorder_limit(0, 2)
Sum(x*y*z, (z, e, f), (y, c, d), (x, a, b))
>>> Sum(x**2, (x, a, b), (x, c, d)).reorder_limit(1, 0)
Sum(x**2, (x, c, d), (x, a, b))

>>> Product(x*y*z, (x, a, b), (y, c, d), (z, e, f)).reorder_limit(0, 2)
Product(x*y*z, (z, e, f), (y, c, d), (x, a, b))

See Also
========

index, reorder, sympy.concrete.summations.Sum.reverse_order,
sympy.concrete.products.Product.reverse_order
r   r    r!   z.could not interchange the two limits specified)
r"   r>   setfree_symbolsintersection	enumerater)   typer+   r   )	r   r:   yr1   r.   limit_xlimit_yr"   is	            r   rA   ExprWithIntLimits.reorder_limit   sJ   @ &*[[1[EQx[1++a.++a.GAJ++,99#>?1DGAJ++,99#>?1DGAJ++,99#>?1DGAJ++,99#>?1DF%dkk26MM'*VMM'*MM%( 3 :dmm5f55t%UVV) 2s   Fc                     SnU R                    H,  nUS   US   -
  n[        US5      nUS:X  a    gUS:X  a  M*  SnM.     U(       a  gg)a  
Returns True if the Sum or Product is computed for an empty sequence.

Examples
========

>>> from sympy import Sum, Product, Symbol
>>> m = Symbol('m')
>>> Sum(m, (m, 1, 0)).has_empty_sequence
True

>>> Sum(m, (m, 1, 1)).has_empty_sequence
False

>>> M = Symbol('M', integer=True, positive=True)
>>> Product(m, (m, 1, M)).has_empty_sequence
False

>>> Product(m, (m, 2, M)).has_empty_sequence

>>> Product(m, (m, M + 1, M)).has_empty_sequence
True

>>> N = Symbol('N', integer=True, positive=True)
>>> Sum(m, (m, N, M)).has_empty_sequence

>>> N = Symbol('N', integer=True, negative=True)
>>> Sum(m, (m, N, M)).has_empty_sequence
False

See Also
========

has_reversed_limits
has_finite_limits

Fr    r!   TN)r"   r   )r   ret_Nonelimdifeqs        r   has_empty_sequence$ExprWithIntLimits.has_empty_sequence.  sX    N ;;Ca&3q6/CCBTzu  r   )N)r   r   r   r   r   	__slots__r5   r9   rG   rA   propertyrY   r   r   r   r   r   r      s<    	 It,n$&L>B4Wl 3 3r   r   N)	sympy.concrete.expr_with_limitsr   sympy.core.singletonr   sympy.core.relationalr   NotImplementedErrorr   r   r   r   r   <module>ra      s)    : " $<& <U Ur   