§
    OŠtjX,  ã                   ób   — d dl mZ d dlmZ d dlmZ  G d„ de¦  «        Z G d„ de¦  «        ZdS )	é    )ÚExprWithLimits)ÚS)ÚEqc                   ó"   ‡ — e Zd ZdZˆ fd„Zˆ xZS )ÚReorderErrorzC
    Exception raised when trying to reorder dependent limits.
    c                 óV   •— t          ¦   «                              |›d|›d�¦  «         d S )Nz could not be reordered: ú.)ÚsuperÚ__init__)ÚselfÚexprÚmsgÚ	__class__s      €ú`/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/concrete/expr_with_intlimits.pyr   zReorderError.__init__	   s9   ø€ Ý‰Œ×ÒØ04°°°c°c°cÐ:ñ	<ô 	<ð 	<ð 	<ð 	<ó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú__classcell__)r   s   @r   r   r      sB   ø€ € € € € ðð ð<ð <ð <ð <ð <ð <ð <ð <ð <r   r   c                   óF   — e Zd ZdZdZd	d„Zd„ Zd„ Zd„ Ze	d„ ¦   «         Z
dS )
ÚExprWithIntLimitsz¾
    Superclass for Product and Sum.

    See Also
    ========

    sympy.concrete.expr_with_limits.ExprWithLimits
    sympy.concrete.products.Product
    sympy.concrete.summations.Sum
    © Nc                 ój  — |€|}g }| j         D �]`}|d         |k    �r;|                     |¦  «        }|                     ¦   «         dk    rt          d¦  «        ‚|                     |¦  «        }|                     t
          j        ¦  «        }|j        r’|t
          j        k    r1|                     |||d         z  |z   ||d         z  |z   f¦  «         ŒÈ|t
          j	        k    r2|                     |||d         z  |z   ||d         z  |z   f¦  «         �Œ
t          d¦  «        ‚|                     |||d         z  |z   ||d         z  |z   f¦  «         �ŒK|                     |¦  «         �Œb| j
                             |||z
  |z  ¦  «        }	|	                     ||¦  «        }	 | j        |	g|¢R Ž S )a¯  
        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
        Nr   é   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_indexzExprWithIntLimits.change_index   sÈ  € ðr ˆ>ØˆFàˆØ”[ð 	%ñ 	%ˆEØ�QŒx˜3Š‰Ø—M’M #Ñ&Ô&�Ø—8’8‘:”: ’?�?Ý$Ð%IÑJÔJÐJØ×(Ò(¨Ñ-Ô-�Ø×'Ò'­¬Ñ.Ô.�Ø”?ð 	ZØ¥¤’~�~ØŸš v¨u°U¸1´X©~ÀÑ/DÀeÈEÐRSÌHÁnÐW[ÑF[Ð&\Ñ]Ô]Ð]Ð]Ø¥!¤-Ò/Ð/ØŸš v¨u°U¸1´X©~ÀÑ/DÀeÈEÐRSÌHÁnÐW[ÑF[Ð&\Ñ]Ô]Ð]Ñ]å(Ð)iÑjÔjÐjð —M’M 6¨5°°q´©>¸DÑ+@À%ÈÈaÌÁ.ÐSWÑBWÐ"XÑYÔYÐYÑYà—’˜eÑ$Ô$Ð$Ñ$à”=×%Ò% c¨C°$©J¸Ñ+=Ñ>Ô>ˆØ—=’=  fÑ-Ô-ˆàˆtŒy˜Ð+ FÐ+Ð+Ð+Ð+r   c                 ó    — d„ | j         D ¦   «         }|                     |¦  «        dk    rt          | d¦  «        ‚|                     |¦  «        S )aX  
        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
        c                 ó   — g | ]
}|d          ‘ŒS ©r   r   ©Ú.0r,   s     r   ú
<listcomp>z+ExprWithIntLimits.index.<locals>.<listcomp>°   s   € Ð7Ð7Ð7 %�U˜1”XÐ7Ð7Ð7r   r   z0Number of instances of variable not equal to one)r   Úcountr    Úindex)r   ÚxÚ	variabless      r   r8   zExprWithIntLimits.index‘   sS   € ð> 8Ð7¨4¬;Ð7Ñ7Ô7ˆ	à�?Š?˜1ÑÔ Ò"Ð"Ý˜TÐ#UÑVÔVÐVà—?’? 1Ñ%Ô%Ð%r   c                 ó~  — | }|D ]·}t          |¦  «        dk    rt          |d¦  «        ‚|d         }|d         }t          |d         t          ¦  «        s|                      |d         ¦  «        }t          |d         t          ¦  «        s|                      |d         ¦  «        }|                     ||¦  «        }Œ¸|S )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Úintr8   Úreorder_limit)r   ÚargÚnew_exprÚrÚindex1Úindex2s         r   ÚreorderzExprWithIntLimits.reorder·   s½   € ð\ ˆàð 	>ð 	>ˆAÝ�1‰vŒv˜Š{ˆ{Ý  Ð$AÑBÔBÐBà�q”TˆFØ�q”TˆFå˜a œd¥CÑ(Ô(ð *ØŸš A a¤DÑ)Ô)�Ý˜a œd¥CÑ(Ô(ð *ØŸš A a¤DÑ)Ô)�à×-Ò-¨f°fÑ=Ô=ˆHˆHàˆr   c                 ót  — d„ | j         D ¦   «         }| j         |         }| j         |         }t          t          |d         j        ¦  «                             |¦  «        ¦  «        dk    �r?t          t          |d         j        ¦  «                             |¦  «        ¦  «        dk    �r t          t          |d         j        ¦  «                             |¦  «        ¦  «        dk    rÂt          t          |d         j        ¦  «                             |¦  «        ¦  «        dk    r„g }t          | j         ¦  «        D ]R\  }}||k    r|                     |¦  «         Œ!||k    r|                     |¦  «         Œ=|                     |¦  «         ŒS t          | ¦  «        | j        g|¢R Ž S t          | d¦  «        ‚)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
        c                 ó   — h | ]
}|d          ’ŒS r3   r   r4   s     r   ú	<setcomp>z2ExprWithIntLimits.reorder_limit.<locals>.<setcomp>  s   € Ð1Ð1Ð1˜Eˆu�QŒxÐ1Ð1Ð1r   r   r   r   z.could not interchange the two limits specified)
r   r<   ÚsetÚfree_symbolsÚintersectionÚ	enumerater$   Útyper&   r   )	r   r9   Úyr)   Úlimit_xÚlimit_yr   Úir,   s	            r   r?   zExprWithIntLimits.reorder_limitø   s”  € ð@ 2Ð1 T¤[Ð1Ñ1Ô1ˆØ”+˜a”.ˆØ”+˜a”.ˆå•�G˜A”JÔ+Ñ,Ô,×9Ò9¸#Ñ>Ô>Ñ?Ô?À1ÒDÑDÝ•�G˜A”JÔ+Ñ,Ô,×9Ò9¸#Ñ>Ô>Ñ?Ô?À1ÒDÑDÝ•�G˜A”JÔ+Ñ,Ô,×9Ò9¸#Ñ>Ô>Ñ?Ô?À1ÒDÐDÝ•�G˜A”JÔ+Ñ,Ô,×9Ò9¸#Ñ>Ô>Ñ?Ô?À1ÒDÐDàˆFÝ% d¤kÑ2Ô2ð )ð )‘��5Ø˜’6�6Ø—M’M 'Ñ*Ô*Ð*Ð*Ø˜!’V�VØ—M’M 'Ñ*Ô*Ð*Ð*à—M’M %Ñ(Ô(Ð(Ð(à•4˜‘:”:˜dœmÐ5¨fÐ5Ð5Ð5Ð5å˜tÐ%UÑVÔVÐVr   c                 óŒ   — d}| j         D ]5}|d         |d         z
  }t          |d¦  «        }|dk    r dS |dk    rŒ3d}Œ6|rdS dS )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_sequencez$ExprWithIntLimits.has_empty_sequence.  sn   € ðN ˆØ”;ð 	 ð 	 ˆCØ�a”&˜3˜qœ6‘/ˆCÝ�C˜‘”ˆBØ�TŠzˆzØ�t�tØ�u’�Øà��àð 	Ø�4Øˆur   )N)r   r   r   r   Ú	__slots__r0   r8   rE   r?   ÚpropertyrW   r   r   r   r   r      sŒ   € € € € € ð	ð 	ð €Iðt,ð t,ð t,ð t,ðn$&ð $&ð $&ðL>ð >ð >ðB4Wð 4Wð 4Wðl ð3ð 3ñ „Xð3ð 3ð 3r   r   N)	Úsympy.concrete.expr_with_limitsr   Úsympy.core.singletonr   Úsympy.core.relationalr   ÚNotImplementedErrorr   r   r   r   r   ú<module>r^      s¤   ðØ :Ð :Ð :Ð :Ð :Ð :Ø "Ð "Ð "Ð "Ð "Ð "Ø $Ð $Ð $Ð $Ð $Ð $ð<ð <ð <ð <ð <Ð&ñ <ô <ð <ðUð Uð Uð Uð U˜ñ Uô Uð Uð Uð Ur   