§
    ¬³ÙgI  ã                   ó  — d Z ddlmZmZ ddlmZ ddlmZmZm	Z	m
Z
 ddlmZ ddlmZmZ ddlmZ ddlmZmZ edd
„¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z! G d„ d¦  «        Z"e G d„ de¦  «        ¦   «         Z#d	S )z@Tools and arithmetics for monomials of distributed polynomials. é    )Úcombinations_with_replacementÚproduct)Údedent)ÚMulÚSÚTupleÚsympify)ÚExactQuotientFailed)ÚPicklableWithSlotsÚdict_from_expr)Úpublic)Úis_sequenceÚiterableNc           	   #   óX  ‡‡‡K  — t          | ¦  «        }t          ‰¦  «        r–t          ‰¦  «        |k    rt          d¦  «        ‚‰€dg|z  Šnht          ‰¦  «        st          d¦  «        ‚t          ‰¦  «        |k    rt          d¦  «        ‚t          d„ ‰D ¦   «         ¦  «        rt          d¦  «        ‚d}n5‰}|dk     rt          d¦  «        ‚‰€d}n‰dk     rt          d	¦  «        ‚‰}d
}|�r�||k    rdS | r|dk    rt          j        V — dS t          | ¦  «        t          j        gz   } t          d„ | D ¦   «         ¦  «        r£g }t          | |¦  «        D ]y}t           
                    | d¦  «        }	|D ]}
|
dk    r|	|
xx         dz  cc<   Œt          |	                     ¦   «         ¦  «        |k    r|                     t          |Ž ¦  «         Œzt          |¦  «        E d{V —† dS g }t!          | |¬¦  «        D ]y}t           
                    | d¦  «        }	|D ]}
|
dk    r|	|
xx         dz  cc<   Œt          |	                     ¦   «         ¦  «        |k    r|                     t          |Ž ¦  «         Œzt          |¦  «        E d{V —† dS t          ˆˆfd„t#          |¦  «        D ¦   «         ¦  «        rt          d¦  «        ‚g }t%          | ‰‰¦  «        D ]8\  Š}}|                     ˆfd„t#          ||dz   ¦  «        D ¦   «         ¦  «         Œ9t!          |Ž D ]}	t          |	Ž V — ŒdS )a‚  
    ``max_degrees`` and ``min_degrees`` are either both integers or both lists.
    Unless otherwise specified, ``min_degrees`` is either ``0`` or
    ``[0, ..., 0]``.

    A generator of all monomials ``monom`` is returned, such that
    either
    ``min_degree <= total_degree(monom) <= max_degree``,
    or
    ``min_degrees[i] <= degree_list(monom)[i] <= max_degrees[i]``,
    for all ``i``.

    Case I. ``max_degrees`` and ``min_degrees`` are both integers
    =============================================================

    Given a set of variables $V$ and a min_degree $N$ and a max_degree $M$
    generate a set of monomials of degree less than or equal to $N$ and greater
    than or equal to $M$. The total number of monomials in commutative
    variables is huge and is given by the following formula if $M = 0$:

        .. math::
            \frac{(\#V + N)!}{\#V! N!}

    For example if we would like to generate a dense polynomial of
    a total degree $N = 50$ and $M = 0$, which is the worst case, in 5
    variables, assuming that exponents and all of coefficients are 32-bit long
    and stored in an array we would need almost 80 GiB of memory! Fortunately
    most polynomials, that we will encounter, are sparse.

    Consider monomials in commutative variables $x$ and $y$
    and non-commutative variables $a$ and $b$::

        >>> from sympy import symbols
        >>> from sympy.polys.monomials import itermonomials
        >>> from sympy.polys.orderings import monomial_key
        >>> from sympy.abc import x, y

        >>> sorted(itermonomials([x, y], 2), key=monomial_key('grlex', [y, x]))
        [1, x, y, x**2, x*y, y**2]

        >>> sorted(itermonomials([x, y], 3), key=monomial_key('grlex', [y, x]))
        [1, x, y, x**2, x*y, y**2, x**3, x**2*y, x*y**2, y**3]

        >>> a, b = symbols('a, b', commutative=False)
        >>> set(itermonomials([a, b, x], 2))
        {1, a, a**2, b, b**2, x, x**2, a*b, b*a, x*a, x*b}

        >>> sorted(itermonomials([x, y], 2, 1), key=monomial_key('grlex', [y, x]))
        [x, y, x**2, x*y, y**2]

    Case II. ``max_degrees`` and ``min_degrees`` are both lists
    ===========================================================

    If ``max_degrees = [d_1, ..., d_n]`` and
    ``min_degrees = [e_1, ..., e_n]``, the number of monomials generated
    is:

    .. math::
        (d_1 - e_1 + 1) (d_2 - e_2 + 1) \cdots (d_n - e_n + 1)

    Let us generate all monomials ``monom`` in variables $x$ and $y$
    such that ``[1, 2][i] <= degree_list(monom)[i] <= [2, 4][i]``,
    ``i = 0, 1`` ::

        >>> from sympy import symbols
        >>> from sympy.polys.monomials import itermonomials
        >>> from sympy.polys.orderings import monomial_key
        >>> from sympy.abc import x, y

        >>> sorted(itermonomials([x, y], [2, 4], [1, 2]), reverse=True, key=monomial_key('lex', [x, y]))
        [x**2*y**4, x**2*y**3, x**2*y**2, x*y**4, x*y**3, x*y**2]
    zArgument sizes do not matchNr   zmin_degrees is not a listc              3   ó"   K  — | ]
}|d k     V — ŒdS ©r   N© ©Ú.0Úis     úK/granary/edev/quantum/lib/python3.11/site-packages/sympy/polys/monomials.pyú	<genexpr>z itermonomials.<locals>.<genexpr>b   s&   è è € Ð.Ð.˜Q�1�q’5Ð.Ð.Ð.Ð.Ð.Ð.ó    z+min_degrees cannot contain negative numbersFzmax_degrees cannot be negativezmin_degrees cannot be negativeTc              3   ó$   K  — | ]}|j         V — Œd S ©N)Úis_commutative)r   Úvariables     r   r   z itermonomials.<locals>.<genexpr>x   s%   è è € ÐAÐA¨8ˆxÔ&ÐAÐAÐAÐAÐAÐAr   é   )Úrepeatc              3   ó<   •K  — | ]}‰|         ‰|         k    V — Œd S r   r   )r   r   Úmax_degreesÚmin_degreess     €€r   r   z itermonomials.<locals>.<genexpr>�   s0   øè è € ÐAÐA°1ˆ{˜1Œ~ ¨A¤Ò.ÐAÐAÐAÐAÐAÐAr   z2min_degrees[i] must be <= max_degrees[i] for all ic                 ó   •— g | ]}‰|z  ‘ŒS r   r   )r   r   Úvars     €r   ú
<listcomp>z!itermonomials.<locals>.<listcomp>‘   s   ø€ ÐHÐHÐH¨1  Q¡ÐHÐHÐHr   )Úlenr   Ú
ValueErrorÚanyr   ÚOneÚlistÚallr   ÚdictÚfromkeysÚsumÚvaluesÚappendr   Úsetr   ÚrangeÚzip)Ú	variablesr!   r"   ÚnÚtotal_degreeÚ
max_degreeÚ
min_degreeÚmonomials_list_commÚitemÚpowersr   Úmonomials_list_non_commÚpower_listsÚmin_dÚmax_dr$   s    ``            @r   Úitermonomialsr@      sä  øøøè è € õT 	ˆI‰Œ€AÝ�;ÑÔð Ýˆ{ÑÔ˜qÒ Ð ÝÐ:Ñ;Ô;Ð;ØÐØ˜#˜a™%ˆKˆKÝ˜[Ñ)Ô)ð 	PÝÐ8Ñ9Ô9Ð9å�;ÑÔ 1Ò$Ð$Ý Ð!>Ñ?Ô?Ð?ÝÐ.Ð. +Ð.Ñ.Ô.Ñ.Ô.ð PÝ Ð!NÑOÔOÐOØˆˆà ˆ
Ø˜Š>ˆ>ÝÐ=Ñ>Ô>Ð>ØÐØˆJˆJà˜QŠˆÝ Ð!AÑBÔBÐBØ$ˆJØˆØñ #Ø˜
Ò"Ð"ØˆFØð 	˜J¨!šO˜OÝ”%ˆKˆKˆKØˆFå˜‘O”O¥q¤u gÑ-ˆ	ÝÐAÐA°yÐAÑAÔAÑAÔAð 	4Ø"$ÐÝ5°iÀÑLÔLð ;ð ;�ÝŸš y°!Ñ4Ô4�Ø $ð .ð .�HØ 1’}�}Ø˜xÐ(Ð(Ô(¨AÑ-Ð(Ð(Ñ(øÝ�v—}’}‘”Ñ'Ô'¨:Ò5Ð5Ø'×.Ò.­s°D¨zÑ:Ô:Ð:øÝÐ.Ñ/Ô/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/Ð/à&(Ð#Ý 	°*Ð=Ñ=Ô=ð ?ð ?�ÝŸš y°!Ñ4Ô4�Ø $ð .ð .�HØ 1’}�}Ø˜xÐ(Ð(Ô(¨AÑ-Ð(Ð(Ñ(øÝ�v—}’}‘”Ñ'Ô'¨:Ò5Ð5Ø+×2Ò2µ3¸°:Ñ>Ô>Ð>øÝÐ2Ñ3Ô3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3åÐAÐAÐAÐAÐA½¸a¹¼ÐAÑAÔAÑAÔAð 	SÝÐQÑRÔRÐRØˆÝ!$ Y°¸[Ñ!IÔ!Ið 	Jð 	JÑˆC�˜Ø×ÒÐHÐHÐHÐHµ°e¸UÀQ¹YÑ0GÔ0GÐHÑHÔHÑIÔIÐIÐIÝ˜{Ð+ð 	ð 	ˆFÝ�v�,ÐÐÐÐð	ð 	r   c                 óZ   — ddl m}  || |z   ¦  «         || ¦  «        z   ||¦  «        z  S )aW  
    Computes the number of monomials.

    The number of monomials is given by the following formula:

    .. math::

        \frac{(\#V + N)!}{\#V! N!}

    where `N` is a total degree and `V` is a set of variables.

    Examples
    ========

    >>> from sympy.polys.monomials import itermonomials, monomial_count
    >>> from sympy.polys.orderings import monomial_key
    >>> from sympy.abc import x, y

    >>> monomial_count(2, 2)
    6

    >>> M = list(itermonomials([x, y], 2))

    >>> sorted(M, key=monomial_key('grlex', [y, x]))
    [1, x, y, x**2, x*y, y**2]
    >>> len(M)
    6

    r   )Ú	factorial)Ú(sympy.functions.combinatorial.factorialsrB   )ÚVÚNrB   s      r   Úmonomial_countrF   •   sE   € ð< CÐBÐBÐBÐBÐBØˆ9�Q˜‘UÑÔ˜i˜i¨™lœlÑ*¨Y¨Y°q©\¬\Ñ9Ð9r   c                 óP   — t          d„ t          | |¦  «        D ¦   «         ¦  «        S )a%  
    Multiplication of tuples representing monomials.

    Examples
    ========

    Lets multiply `x**3*y**4*z` with `x*y**2`::

        >>> from sympy.polys.monomials import monomial_mul

        >>> monomial_mul((3, 4, 1), (1, 2, 0))
        (4, 6, 1)

    which gives `x**4*y**5*z`.

    c                 ó   — g | ]
\  }}||z   ‘ŒS r   r   ©r   ÚaÚbs      r   r%   z monomial_mul.<locals>.<listcomp>Ç   ó    € Ð0Ð0Ð0™T˜Q �1�q‘5Ð0Ð0Ð0r   ©Útupler3   ©ÚAÚBs     r   Úmonomial_mulrR   ¶   s)   € õ" Ð0Ð0¥S¨¨A¡Y¤YÐ0Ñ0Ô0Ñ1Ô1Ð1r   c                 óv   — t          | |¦  «        }t          d„ |D ¦   «         ¦  «        rt          |¦  «        S dS )aœ  
    Division of tuples representing monomials.

    Examples
    ========

    Lets divide `x**3*y**4*z` by `x*y**2`::

        >>> from sympy.polys.monomials import monomial_div

        >>> monomial_div((3, 4, 1), (1, 2, 0))
        (2, 2, 1)

    which gives `x**2*y**2*z`. However::

        >>> monomial_div((3, 4, 1), (1, 2, 2)) is None
        True

    `x*y**2*z**2` does not divide `x**3*y**4*z`.

    c              3   ó"   K  — | ]
}|d k    V — ŒdS r   r   )r   Úcs     r   r   zmonomial_div.<locals>.<genexpr>á   s&   è è € Ð
Ð
�aˆ1�Š6Ð
Ð
Ð
Ð
Ð
Ð
r   N)Úmonomial_ldivr+   rN   )rP   rQ   ÚCs      r   Úmonomial_divrX   É   sB   € õ, 	�a˜ÑÔ€Aå
Ð
Ð
˜1Ð
Ñ
Ô
ÑÔð Ý�Q‰xŒxˆàˆtr   c                 óP   — t          d„ t          | |¦  «        D ¦   «         ¦  «        S )a…  
    Division of tuples representing monomials.

    Examples
    ========

    Lets divide `x**3*y**4*z` by `x*y**2`::

        >>> from sympy.polys.monomials import monomial_ldiv

        >>> monomial_ldiv((3, 4, 1), (1, 2, 0))
        (2, 2, 1)

    which gives `x**2*y**2*z`.

        >>> monomial_ldiv((3, 4, 1), (1, 2, 2))
        (2, 2, -1)

    which gives `x**2*y**2*z**-1`.

    c                 ó   — g | ]
\  }}||z
  ‘ŒS r   r   rI   s      r   r%   z!monomial_ldiv.<locals>.<listcomp>ü   rL   r   rM   rO   s     r   rV   rV   æ   s)   € õ, Ð0Ð0¥S¨¨A¡Y¤YÐ0Ñ0Ô0Ñ1Ô1Ð1r   c                 ó:   ‡— t          ˆfd„| D ¦   «         ¦  «        S )z%Return the n-th pow of the monomial. c                 ó   •— g | ]}|‰z  ‘ŒS r   r   )r   rJ   r5   s     €r   r%   z monomial_pow.<locals>.<listcomp>   s   ø€ Ð#Ð#Ð#˜1�1�Q‘3Ð#Ð#Ð#r   )rN   )rP   r5   s    `r   Úmonomial_powr]   þ   s&   ø€ åÐ#Ð#Ð#Ð# Ð#Ñ#Ô#Ñ$Ô$Ð$r   c                 óP   — t          d„ t          | |¦  «        D ¦   «         ¦  «        S )a.  
    Greatest common divisor of tuples representing monomials.

    Examples
    ========

    Lets compute GCD of `x*y**4*z` and `x**3*y**2`::

        >>> from sympy.polys.monomials import monomial_gcd

        >>> monomial_gcd((1, 4, 1), (3, 2, 0))
        (1, 2, 0)

    which gives `x*y**2`.

    c                 ó4   — g | ]\  }}t          ||¦  «        ‘ŒS r   )ÚminrI   s      r   r%   z monomial_gcd.<locals>.<listcomp>  ó$   € Ð4Ð4Ð4¡  A•3�q˜!‘9”9Ð4Ð4Ð4r   rM   rO   s     r   Úmonomial_gcdrb     ó)   € õ" Ð4Ð4­¨Q°©¬Ð4Ñ4Ô4Ñ5Ô5Ð5r   c                 óP   — t          d„ t          | |¦  «        D ¦   «         ¦  «        S )a1  
    Least common multiple of tuples representing monomials.

    Examples
    ========

    Lets compute LCM of `x*y**4*z` and `x**3*y**2`::

        >>> from sympy.polys.monomials import monomial_lcm

        >>> monomial_lcm((1, 4, 1), (3, 2, 0))
        (3, 4, 1)

    which gives `x**3*y**4*z`.

    c                 ó4   — g | ]\  }}t          ||¦  «        ‘ŒS r   )ÚmaxrI   s      r   r%   z monomial_lcm.<locals>.<listcomp>&  ra   r   rM   rO   s     r   Úmonomial_lcmrg     rc   r   c                 óP   — t          d„ t          | |¦  «        D ¦   «         ¦  «        S )zö
    Does there exist a monomial X such that XA == B?

    Examples
    ========

    >>> from sympy.polys.monomials import monomial_divides
    >>> monomial_divides((1, 2), (3, 4))
    True
    >>> monomial_divides((1, 2), (0, 2))
    False
    c              3   ó(   K  — | ]\  }}||k    V — Œd S r   r   rI   s      r   r   z#monomial_divides.<locals>.<genexpr>5  s*   è è € Ð,Ð,™$˜!˜Qˆq�AŠvÐ,Ð,Ð,Ð,Ð,Ð,r   )r+   r3   rO   s     r   Úmonomial_dividesrj   (  s)   € õ Ð,Ð,¥# a¨¡)¤)Ð,Ñ,Ô,Ñ,Ô,Ð,r   c                  óÀ   — t          | d         ¦  «        }| dd…         D ]0}t          |¦  «        D ]\  }}t          ||         |¦  «        ||<   ŒŒ1t          |¦  «        S )a‘  
    Returns maximal degree for each variable in a set of monomials.

    Examples
    ========

    Consider monomials `x**3*y**4*z**5`, `y**5*z` and `x**6*y**3*z**9`.
    We wish to find out what is the maximal degree for each of `x`, `y`
    and `z` variables::

        >>> from sympy.polys.monomials import monomial_max

        >>> monomial_max((3,4,5), (0,5,1), (6,3,9))
        (6, 5, 9)

    r   r   N)r*   Ú	enumeraterf   rN   ©ÚmonomsÚMrE   r   r5   s        r   Úmonomial_maxrp   7  ól   € õ" 	ˆV�AŒY‰Œ€Aà�A�B�BŒZð  ð  ˆÝ˜a‘L”Lð 	 ð 	 ‰DˆAˆqÝ�q˜”t˜Q‘<”<ˆAˆa‰DˆDð	 õ �‰8Œ8€Or   c                  óÀ   — t          | d         ¦  «        }| dd…         D ]0}t          |¦  «        D ]\  }}t          ||         |¦  «        ||<   ŒŒ1t          |¦  «        S )a‘  
    Returns minimal degree for each variable in a set of monomials.

    Examples
    ========

    Consider monomials `x**3*y**4*z**5`, `y**5*z` and `x**6*y**3*z**9`.
    We wish to find out what is the minimal degree for each of `x`, `y`
    and `z` variables::

        >>> from sympy.polys.monomials import monomial_min

        >>> monomial_min((3,4,5), (0,5,1), (6,3,9))
        (0, 3, 1)

    r   r   N)r*   rl   r`   rN   rm   s        r   Úmonomial_minrs   P  rq   r   c                 ó    — t          | ¦  «        S )zÍ
    Returns the total degree of a monomial.

    Examples
    ========

    The total degree of `xy^2` is 3:

    >>> from sympy.polys.monomials import monomial_deg
    >>> monomial_deg((1, 2))
    3
    )r.   )ro   s    r   Úmonomial_degru   i  s   € õ ˆq‰6Œ6€Mr   c                 ó¾   — | \  }}|\  }}t          ||¦  «        }|j        r|�||                     ||¦  «        fS dS |�||z  s||                     ||¦  «        fS dS )z,Division of two terms in over a ring/field. N)rX   Úis_FieldÚquo)rJ   rK   ÚdomainÚa_lmÚa_lcÚb_lmÚb_lcÚmonoms           r   Úterm_divr   x  s|   € à�J€Dˆ$Ø�J€Dˆ$å˜˜tÑ$Ô$€Eà„ð 	ØÐØ˜&Ÿ*š* T¨4Ñ0Ô0Ð0Ð0à�4à� ¨¡�Ø˜&Ÿ*š* T¨4Ñ0Ô0Ð0Ð0à�4r   c                   óN   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ ZdS )ÚMonomialOpsz6Code generator of fast monomial arithmetic functions. c                 ó   — || _         d S r   )Úngens)Úselfrƒ   s     r   Ú__init__zMonomialOps.__init__�  s   € ØˆŒ
ˆ
ˆ
r   c                 ó6   — i }t          ||¦  «         ||         S r   )Úexec)r„   ÚcodeÚnameÚnss       r   Ú_buildzMonomialOps._build�  s   € ØˆÝˆT�2‰ŒˆØ�$Œxˆr   c                 óD   ‡— ˆfd„t          | j        ¦  «        D ¦   «         S )Nc                 ó   •— g | ]}‰›|›�‘Œ	S r   r   )r   r   r‰   s     €r   r%   z%MonomialOps._vars.<locals>.<listcomp>–  s"   ø€ Ð@Ð@Ð@¨˜4˜4  Ð#Ð@Ð@Ð@r   )r2   rƒ   )r„   r‰   s    `r   Ú_varszMonomialOps._vars•  s'   ø€ Ø@Ð@Ð@Ð@­U°4´:Ñ->Ô->Ð@Ñ@Ô@Ð@r   c                 ó^  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          ||¦  «        D ¦   «         }||d                     |¦  «        d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )NrR   ús        def %(name)s(A, B):
            (%(A)s,) = A
            (%(B)s,) = B
            return (%(AB)s,)
        rJ   rK   c                 ó"   — g | ]\  }}|›d |›�‘ŒS )ú + r   rI   s      r   r%   z#MonomialOps.mul.<locals>.<listcomp>¢  ó'   € Ð9Ð9Ð9¡d a¨˜A˜A˜A˜q˜qÐ!Ð9Ð9Ð9r   ú, ©r‰   rP   rQ   ÚAB©r   rŽ   r3   Újoinr‹   ©r„   r‰   ÚtemplaterP   rQ   r–   rˆ   s          r   ÚmulzMonomialOps.mul˜  s¤   € ØˆÝð ñ ô ˆð �JŠJ�s‰OŒOˆØ�JŠJ�s‰OŒOˆØ9Ð9­c°!°Q©i¬iÐ9Ñ9Ô9ˆØ 4¨d¯iªi¸©l¬lÀÇÂÈ1ÁÄÐUY×U^ÒU^Ð_aÑUbÔUbÐcÐcÑcˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 óð   — d}t          d¦  «        }|                      d¦  «        }d„ |D ¦   «         }||d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )Nr]   zZ        def %(name)s(A, k):
            (%(A)s,) = A
            return (%(Ak)s,)
        rJ   c                 ó   — g | ]}d |z  ‘ŒS )z%s*kr   )r   rJ   s     r   r%   z#MonomialOps.pow.<locals>.<listcomp>®  s   € Ð&Ð&Ð&˜aˆv˜‰zÐ&Ð&Ð&r   r”   )r‰   rP   ÚAk)r   rŽ   r˜   r‹   )r„   r‰   rš   rP   rž   rˆ   s         r   ÚpowzMonomialOps.pow¦  s{   € ØˆÝð ñ ô ˆð
 �JŠJ�s‰OŒOˆØ&Ð& 1Ð&Ñ&Ô&ˆØ 4¨d¯iªi¸©l¬lÀ$Ç)Â)ÈBÁ-Ä-ÐPÐPÑPˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 ó^  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          ||¦  «        D ¦   «         }||d                     |¦  «        d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )NÚmonomial_mulpowzw        def %(name)s(A, B, k):
            (%(A)s,) = A
            (%(B)s,) = B
            return (%(ABk)s,)
        rJ   rK   c                 ó$   — g | ]\  }}|›d |›d�‘ŒS )r’   z*kr   rI   s      r   r%   z&MonomialOps.mulpow.<locals>.<listcomp>¼  s)   € Ð<Ð<Ð<©¨¨A˜q˜q˜q ! ! !Ð$Ð<Ð<Ð<r   r”   )r‰   rP   rQ   ÚABkr—   )r„   r‰   rš   rP   rQ   r£   rˆ   s          r   ÚmulpowzMonomialOps.mulpow²  s¤   € Ø ˆÝð ñ ô ˆð �JŠJ�s‰OŒOˆØ�JŠJ�s‰OŒOˆØ<Ð<µ°Q¸±´Ð<Ñ<Ô<ˆØ 4¨d¯iªi¸©l¬lÀÇÂÈ1ÁÄÐVZ×V_ÒV_Ð`cÑVdÔVdÐeÐeÑeˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 ó^  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          ||¦  «        D ¦   «         }||d                     |¦  «        d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )NrV   r�   rJ   rK   c                 ó"   — g | ]\  }}|›d |›�‘ŒS )z - r   rI   s      r   r%   z$MonomialOps.ldiv.<locals>.<listcomp>Ê  r“   r   r”   r•   r—   r™   s          r   ÚldivzMonomialOps.ldivÀ  s¤   € ØˆÝð ñ ô ˆð �JŠJ�s‰OŒOˆØ�JŠJ�s‰OŒOˆØ9Ð9­c°!°Q©i¬iÐ9Ñ9Ô9ˆØ 4¨d¯iªi¸©l¬lÀÇÂÈ1ÁÄÐUY×U^ÒU^Ð_aÑUbÔUbÐcÐcÑcˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 ó¸  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          | j        ¦  «        D ¦   «         }|                      d¦  «        }||d                     |¦  «        d                     |¦  «        d                     |¦  «        d                     |¦  «        d	œz  }|                      ||¦  «        S )
NrX   z†        def %(name)s(A, B):
            (%(A)s,) = A
            (%(B)s,) = B
            %(RAB)s
            return (%(R)s,)
        rJ   rK   c                 ó   — g | ]	}d d|iz  ‘Œ
S )z7r%(i)s = a%(i)s - b%(i)s
    if r%(i)s < 0: return Noner   r   r   s     r   r%   z#MonomialOps.div.<locals>.<listcomp>Ù  s$   € ÐrÐrÐrÐZ[ÐJÈcÐSTÈXÑUÐrÐrÐrr   Úrr”   z
    )r‰   rP   rQ   ÚRABÚR)r   rŽ   r2   rƒ   r˜   r‹   )r„   r‰   rš   rP   rQ   r«   r¬   rˆ   s           r   ÚdivzMonomialOps.divÎ  sÊ   € ØˆÝð ñ ô ˆð �JŠJ�s‰OŒOˆØ�JŠJ�s‰OŒOˆØrÐrÕ_dÐeiÔeoÑ_pÔ_pÐrÑrÔrˆØ�JŠJ�s‰OŒOˆØ 4¨d¯iªi¸©l¬lÀÇÂÈ1ÁÄÐV^×VcÒVcÐdgÑVhÔVhÐos×oxÒoxÐyzÑo{Ôo{Ð|Ð|Ñ|ˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 ó^  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          ||¦  «        D ¦   «         }||d                     |¦  «        d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )Nrg   r�   rJ   rK   c           	      ó.   — g | ]\  }}|›d |›d|›d|›�‘ŒS )ú if z >= ú else r   rI   s      r   r%   z#MonomialOps.lcm.<locals>.<listcomp>è  ó3   € ÐNÐNÐN¹4¸1¸a¨1¨1¨1¨a¨a¨a°°°°A°AÐ6ÐNÐNÐNr   r”   r•   r—   r™   s          r   ÚlcmzMonomialOps.lcmÞ  ó¤   € ØˆÝð ñ ô ˆð �JŠJ�s‰OŒOˆØ�JŠJ�s‰OŒOˆØNÐNÅ3ÀqÈ!Á9Ä9ÐNÑNÔNˆØ 4¨d¯iªi¸©l¬lÀÇÂÈ1ÁÄÐUY×U^ÒU^Ð_aÑUbÔUbÐcÐcÑcˆØ�{Š{˜4 Ñ&Ô&Ð&r   c                 ó^  — d}t          d¦  «        }|                      d¦  «        }|                      d¦  «        }d„ t          ||¦  «        D ¦   «         }||d                     |¦  «        d                     |¦  «        d                     |¦  «        dœz  }|                      ||¦  «        S )Nrb   r�   rJ   rK   c           	      ó.   — g | ]\  }}|›d |›d|›d|›�‘ŒS )r°   z <= r±   r   rI   s      r   r%   z#MonomialOps.gcd.<locals>.<listcomp>ö  r²   r   r”   r•   r—   r™   s          r   ÚgcdzMonomialOps.gcdì  r´   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r…   r‹   rŽ   r›   rŸ   r¤   r§   r­   r³   r·   r   r   r   r�   r�   Š  s³   € € € € € Ø@Ð@ðð ð ðð ð ð
Að Að Að'ð 'ð 'ð
'ð 
'ð 
'ð'ð 'ð 'ð'ð 'ð 'ð'ð 'ð 'ð 'ð 'ð 'ð'ð 'ð 'ð 'ð 'r   r�   c                   óx   — e Zd ZdZdZdd„Zdd„Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Zd„ Zd„ Zd„ ZeZd„ Zd„ Zd„ ZdS )ÚMonomialz9Class representing a monomial, i.e. a product of powers. )Ú	exponentsÚgensNc                 óÒ  — t          |¦  «        s©t          t          |¦  «        |¬¦  «        \  }}t          |¦  «        dk    rSt	          |                     ¦   «         ¦  «        d         dk    r(t	          |                     ¦   «         ¦  «        d         }n"t          d                     |¦  «        ¦  «        ‚t          t          t          |¦  «        ¦  «        | _        || _        d S )N)r¿   r   r   zExpected a monomial got {})r   r   r	   r&   r*   r/   Úkeysr'   ÚformatrN   ÚmapÚintr¾   r¿   )r„   r~   r¿   Úreps       r   r…   zMonomial.__init__   s¶   € Ý˜‰Œð 	MÝ&¥w¨u¡~¤~¸DÐAÑAÔA‰IˆC�Ý�3‰xŒx˜1Š}ˆ}¥ c§j¢j¡l¤lÑ!3Ô!3°AÔ!6¸!Ò!;Ð!;Ý˜SŸXšX™ZœZÑ(Ô(¨Ô+��å Ð!=×!DÒ!DÀUÑ!KÔ!KÑLÔLÐLå�s¥3¨™œÑ/Ô/ˆŒØˆŒ	ˆ	ˆ	r   c                 ó<   — |                       ||p| j        ¦  «        S r   )Ú	__class__r¿   )r„   r¾   r¿   s      r   ÚrebuildzMonomial.rebuild  s   € Ø�~Š~˜i¨Ð):°´Ñ;Ô;Ð;r   c                 ó*   — t          | j        ¦  «        S r   )r&   r¾   ©r„   s    r   Ú__len__zMonomial.__len__  s   € Ý�4”>Ñ"Ô"Ð"r   c                 ó*   — t          | j        ¦  «        S r   )Úiterr¾   rÊ   s    r   Ú__iter__zMonomial.__iter__  s   € Ý�D”NÑ#Ô#Ð#r   c                 ó   — | j         |         S r   )r¾   )r„   r:   s     r   Ú__getitem__zMonomial.__getitem__  s   € ØŒ~˜dÔ#Ð#r   c                 óN   — t          | j        j        | j        | j        f¦  «        S r   )ÚhashrÇ   r¸   r¾   r¿   rÊ   s    r   Ú__hash__zMonomial.__hash__  s    € Ý�T”^Ô,¨d¬n¸d¼iÐHÑIÔIÐIr   c                 ó¬   — | j         r7d                     d„ t          | j         | j        ¦  «        D ¦   «         ¦  «        S | j        j        ›d| j        ›d�S )NÚ*c                 ó"   — g | ]\  }}|›d |›�‘ŒS )z**r   ©r   ÚgenÚexps      r   r%   z$Monomial.__str__.<locals>.<listcomp>  s'   € ÐdÐdÐd¹¸¸S¨#¨#¨#¨s¨sÐ3ÐdÐdÐdr   ú(ú))r¿   r˜   r3   r¾   rÇ   r¸   rÊ   s    r   Ú__str__zMonomial.__str__  sZ   € ØŒ9ð 	HØ—8’8ÐdÐdÅCÈÌ	ÐSWÔSaÑDbÔDbÐdÑdÔdÑeÔeÐeà#œ~Ô6Ð6Ð6¸¼¸¸ÐGÐGr   c                 óˆ   — |p| j         }|st          d| z  ¦  «        ‚t          d„ t          || j        ¦  «        D ¦   «         Ž S )z3Convert a monomial instance to a SymPy expression. z5Cannot convert %s to an expression without generatorsc                 ó   — g | ]
\  }}||z  ‘ŒS r   r   r×   s      r   r%   z$Monomial.as_expr.<locals>.<listcomp>(  s    € ÐJÐJÐJ¡8 3¨�c˜3‘hÐJÐJÐJr   )r¿   r'   r   r3   r¾   )r„   r¿   s     r   Úas_exprzMonomial.as_expr   s\   € àÐ �t”yˆàð 	PÝØGÈ$ÑNñPô Pð Põ ÐJÐJ­s°4¸¼Ñ/HÔ/HÐJÑJÔJÐKÐKr   c                 ó”   — t          |t          ¦  «        r|j        }n!t          |t          t          f¦  «        r|}ndS | j        |k    S )NF)Ú
isinstancer½   r¾   rN   r   ©r„   Úotherr¾   s      r   Ú__eq__zMonomial.__eq__*  sL   € Ý�e�XÑ&Ô&ð 	ØœˆIˆIÝ˜¥¥u˜~Ñ.Ô.ð 	ØˆIˆIà�5àŒ~ Ò*Ð*r   c                 ó   — | |k     S r   r   )r„   rã   s     r   Ú__ne__zMonomial.__ne__4  s   € Ø˜5’=Ð Ð r   c                 óØ   — t          |t          ¦  «        r|j        }n&t          |t          t          f¦  «        r|}nt
          ‚|                      t          | j        |¦  «        ¦  «        S r   )rá   r½   r¾   rN   r   ÚNotImplementedErrorrÈ   rR   râ   s      r   Ú__mul__zMonomial.__mul__7  s^   € Ý�e�XÑ&Ô&ð 	&ØœˆIˆIÝ˜¥¥u˜~Ñ.Ô.ð 	&ØˆIˆIå%Ð%à�|Š|�L¨¬¸ÑCÔCÑDÔDÐDr   c                 ó  — t          |t          ¦  «        r|j        }n&t          |t          t          f¦  «        r|}nt
          ‚t          | j        |¦  «        }|�|                      |¦  «        S t          | t          |¦  «        ¦  «        ‚r   )	rá   r½   r¾   rN   r   rè   rX   rÈ   r
   )r„   rã   r¾   Úresults       r   Ú__truediv__zMonomial.__truediv__A  s   € Ý�e�XÑ&Ô&ð 	&ØœˆIˆIÝ˜¥¥u˜~Ñ.Ô.ð 	&ØˆIˆIå%Ð%å˜dœn¨iÑ8Ô8ˆàÐØ—<’< Ñ'Ô'Ð'å% d­H°U©O¬OÑ<Ô<Ð<r   c                 ó    — t          |¦  «        }|dk     rt          d|z  ¦  «        ‚|                      t          | j        |¦  «        ¦  «        S )Nr   z'a non-negative integer expected, got %s)rÄ   r'   rÈ   r]   r¾   )r„   rã   r5   s      r   Ú__pow__zMonomial.__pow__R  sH   € Ý�‰JŒJˆØˆqŠ5ˆ5ÝÐFÈÑNÑOÔOÐOØ�|Š|�L¨¬¸Ñ;Ô;Ñ<Ô<Ð<r   c                 óî   — t          |t          ¦  «        r|j        }n1t          |t          t          f¦  «        r|}nt          d|z  ¦  «        ‚|                      t          | j        |¦  «        ¦  «        S )z&Greatest common divisor of monomials. ú.an instance of Monomial class expected, got %s)rá   r½   r¾   rN   r   Ú	TypeErrorrÈ   rb   râ   s      r   r·   zMonomial.gcdX  óy   € å�e�XÑ&Ô&ð 	JØœˆIˆIÝ˜¥¥u˜~Ñ.Ô.ð 	JØˆIˆIåØ@À5ÑHñJô Jð Jð �|Š|�L¨¬¸ÑCÔCÑDÔDÐDr   c                 óî   — t          |t          ¦  «        r|j        }n1t          |t          t          f¦  «        r|}nt          d|z  ¦  «        ‚|                      t          | j        |¦  «        ¦  «        S )z$Least common multiple of monomials. rð   )rá   r½   r¾   rN   r   rñ   rÈ   rg   râ   s      r   r³   zMonomial.lcmd  rò   r   r   )r¸   r¹   rº   r»   Ú	__slots__r…   rÈ   rË   rÎ   rÐ   rÓ   rÜ   rß   rä   ræ   ré   rì   Ú__floordiv__rî   r·   r³   r   r   r   r½   r½   ú  s%  € € € € € àCÐCà%€Ið	ð 	ð 	ð 	ð<ð <ð <ð <ð#ð #ð #ð$ð $ð $ð$ð $ð $ðJð Jð JðHð Hð HðLð Lð Lð+ð +ð +ð!ð !ð !ðEð Eð Eð=ð =ð =ð €Lð=ð =ð =ð
Eð 
Eð 
Eð
Eð 
Eð 
Eð 
Eð 
Er   r½   r   )$r»   Ú	itertoolsr   r   Útextwrapr   Ú
sympy.corer   r   r   r	   Úsympy.polys.polyerrorsr
   Úsympy.polys.polyutilsr   r   Úsympy.utilitiesr   Úsympy.utilities.iterablesr   r   r@   rF   rR   rX   rV   r]   rb   rg   rj   rp   rs   ru   r   r�   r½   r   r   r   ú<module>rý      s  ðØ FÐ Fð =Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø Ð Ð Ð Ð Ð à -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ "Ð "Ð "Ð "Ð "Ð "Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;àðEð Eð Eñ „ðEðN:ð :ð :ðB2ð 2ð 2ð&ð ð ð:2ð 2ð 2ð0%ð %ð %ð6ð 6ð 6ð&6ð 6ð 6ð&-ð -ð -ðð ð ð2ð ð ð2ð ð ðð ð ð$n'ð n'ð n'ð n'ð n'ñ n'ô n'ð n'ð` ðsEð sEð sEð sEð sEÐ!ñ sEô sEñ „ðsEð sEð sEr   