
    Xhg                        d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlmZ erdd	lmZmZ dd
lmZ ddlmZ ddlmZmZ d"dZ G d d          Zd#dZd#dZd$dZ G d d           Zd!S )%z
Puiseux rings. These are used by the ring_series module to represented
truncated Puiseux series. Elements of a Puiseux ring are like polynomials
except that the exponents can be negative or rational rather than just
non-negative integers.
    )annotationsQQ)PolyRingPolyElement)Add)Mul)gcdlcm)TYPE_CHECKING)AnyUnpack)Expr)Domain)IterableIteratorsymbolsstr | list[Expr]domainr   return3tuple[PuiseuxRing, Unpack[tuple[PuiseuxPoly, ...]]]c                8    t          | |          }|f|j        z   S )ac  Construct a Puiseux ring.

    This function constructs a Puiseux ring with the given symbols and domain.

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.puiseux import puiseux_ring
    >>> R, x, y = puiseux_ring('x y', QQ)
    >>> R
    PuiseuxRing((x, y), QQ)
    >>> p = 5*x**QQ(1,2) + 7/y
    >>> p
    7*y**(-1) + 5*x**(1/2)
    )PuiseuxRinggens)r   r   rings      e/var/www/tools.fuzzalab.pt/emblema-extractor/venv/lib/python3.11/site-packages/sympy/polys/puiseux.pypuiseux_ringr   '   s"      w''D7TY    c                  b    e Zd ZdZddZd d	Zd!dZd"dZd#dZd$dZ	d%dZ
d&dZd&dZd'dZdS )(r   a  Ring of Puiseux polynomials.

    A Puiseux polynomial is a truncated Puiseux series. The exponents of the
    monomials can be negative or rational numbers. This ring is used by the
    ring_series module:

    >>> from sympy.polys.domains import QQ
    >>> from sympy.polys.puiseux import puiseux_ring
    >>> from sympy.polys.ring_series import rs_exp, rs_nth_root
    >>> ring, x, y = puiseux_ring('x y', QQ)
    >>> f = x**2 + y**3
    >>> f
    y**3 + x**2
    >>> f.diff(x)
    2*x
    >>> rs_exp(x, x, 5)
    1 + x + 1/2*x**2 + 1/6*x**3 + 1/24*x**4

    Importantly the Puiseux ring can represent truncated series with negative
    and fractional exponents:

    >>> f = 1/x + 1/y**2
    >>> f
    x**(-1) + y**(-2)
    >>> f.diff(x)
    -1*x**(-2)

    >>> rs_nth_root(8*x + x**2 + x**3, 3, x, 5)
    2*x**(1/3) + 1/12*x**(4/3) + 23/288*x**(7/3) + -139/20736*x**(10/3)

    See Also
    ========

    sympy.polys.ring_series.rs_series
    PuiseuxPoly
    r   r   r   r   c                |    t          ||          }|j        }|j        }| _        | _        |j         _        t           fd|j        D                        _        | _                             |j                   _                             |j	                   _	        |j
         _
        |j         _        d S )Nc                :    g | ]}                     |          S  )	from_poly).0gselfs     r   
<listcomp>z(PuiseuxRing.__init__.<locals>.<listcomp>k   s%    EEE4>>!,,EEEr   )r   r   ngens	poly_ringr   tupler   r#   zeroone
zero_monommonomial_mul)r&   r   r   r)   r(   s   `    r   __init__zPuiseuxRing.__init__`   s    Wf--	!" (EEEEinEEEFF	
NN9>22	>>)-00#.%2r   r   strc                (    d| j          d| j         dS )NzPuiseuxRing(z, ))r   r   r&   s    r   __repr__zPuiseuxRing.__repr__t   s    <dl<<dk<<<<r   otherr   boolc                z    t          |t                    st          S | j        |j        k    o| j        |j        k    S N)
isinstancer   NotImplementedr   r   r&   r5   s     r   __eq__zPuiseuxRing.__eq__w   s7    %-- 	"!!|u},L1LLr   polyr   PuiseuxPolyc                "    t          ||           S )aJ  Create a Puiseux polynomial from a polynomial.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.rings import ring
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R1, x1 = ring('x', QQ)
        >>> R2, x2 = puiseux_ring('x', QQ)
        >>> R2.from_poly(x1**2)
        x**2
        )r>   )r&   r=   s     r   r#   zPuiseuxRing.from_poly|   s     4&&&r   termsdict[tuple[int, ...], Any]c                8    t                               ||           S )a  Create a Puiseux polynomial from a dictionary of terms.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x = puiseux_ring('x', QQ)
        >>> R.from_dict({(QQ(1,2),): QQ(3)})
        3*x**(1/2)
        )r>   	from_dict)r&   r@   s     r   rC   zPuiseuxRing.from_dict   s     $$UD111r   nintc                R    |                      |                     |                    S )zCreate a Puiseux polynomial from an integer.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x = puiseux_ring('x', QQ)
        >>> R.from_int(3)
        3
        )r#   r)   r&   rD   s     r   from_intzPuiseuxRing.from_int   s"     ~~dnnQ//000r   argc                6    | j                             |          S )a  Create a new element of the domain.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x = puiseux_ring('x', QQ)
        >>> R.domain_new(3)
        3
        >>> QQ.of_type(_)
        True
        )r)   
domain_newr&   rI   s     r   rK   zPuiseuxRing.domain_new   s     ~((---r   c                \    |                      | j                            |                    S )a-  Create a new element from a ground element.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring, PuiseuxPoly
        >>> R, x = puiseux_ring('x', QQ)
        >>> R.ground_new(3)
        3
        >>> isinstance(_, PuiseuxPoly)
        True
        )r#   r)   
ground_newrL   s     r   rN   zPuiseuxRing.ground_new   s&     ~~dn77<<===r   c                    t          |t                    r|                     |          S |                     |                     |                    S )a  Coerce an element into the ring.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x = puiseux_ring('x', QQ)
        >>> R(3)
        3
        >>> R({(QQ(1,2),): QQ(3)})
        3*x**(1/2)
        )r9   dictrC   r#   r)   rL   s     r   __call__zPuiseuxRing.__call__   sF     c4   	7>>#&&&>>$.."5"5666r   xc                6    | j                             |          S )a  Return the index of a generator.

        >>> from sympy.polys.domains import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x, y = puiseux_ring('x y', QQ)
        >>> R.index(x)
        0
        >>> R.index(y)
        1
        )r   index)r&   rR   s     r   rT   zPuiseuxRing.index   s     yq!!!r   N)r   r   r   r   r   r0   r5   r   r   r6   )r=   r   r   r>   )r@   rA   r   r>   rD   rE   r   r>   )rI   r   r   r   )rI   r   r   r>   )rR   r>   r   rE   )__name__
__module____qualname____doc__r/   r4   r<   r#   rC   rH   rK   rN   rQ   rT   r"   r   r   r   r   ;   s        # #H3 3 3 3(= = = =M M M M
' ' ' '	2 	2 	2 	2	1 	1 	1 	1. . . .> > > >7 7 7 7 " " " " " "r   r   r=   r   monomIterable[int]c                    | j         }|j        |                    fd|                                 D                       S )Nc                0    i | ]\  }} |          |S r"   r"   )r$   mcdivr\   s      r   
<dictcomp>z#_div_poly_monom.<locals>.<dictcomp>   )    EEE133q%==!EEEr   )r   monomial_divrC   r@   )r=   r\   r   rb   s    ` @r   _div_poly_monomrf      E    9D

C>>EEEEE

EEEFFFr   c                    | j         }|j        |                    fd|                                 D                       S )Nc                0    i | ]\  }} |          |S r"   r"   )r$   r`   ra   r\   muls      r   rc   z#_mul_poly_monom.<locals>.<dictcomp>   rd   r   )r   r.   rC   r@   )r=   r\   r   rj   s    ` @r   _mul_poly_monomrk      rg   r   rb   tuple[int, ...]c                P    t          d t          | |          D                       S )Nc              3  &   K   | ]\  }}||z
  V  d S r8   r"   r$   midis      r   	<genexpr>z_div_monom.<locals>.<genexpr>   s*      77VRb777777r   r*   zip)r\   rb   s     r   
_div_monomru      s'    77s5#777777r   c                     e Zd ZU dZded<   ded<   ded<   ded<   dLd
ZedMd            ZedMd            ZdNdZ	edOd            Z
edPd            ZedQd            ZdRdZdSdZdTdZdUdZdVd ZdTd!ZdWd#ZedXd$            ZdYd&ZedZd)            Zd[d+Zd\d-Zd]d/Zd^d0Zd^d1Zd_d2Zd_d3Zd_d4Zd_d5Z d_d6Z!d_d7Z"d_d8Z#d_d9Z$d_d:Z%d`d;Z&dad=Z'd`d>Z(dad?Z)dad@Z*d`dAZ+dadBZ,dadCZ-dbdEZ.dbdFZ/dcdGZ0d^dHZ1dddJZ2dKS )er>   aR  Puiseux polynomial. Represents a truncated Puiseux series.

    See the :class:`PuiseuxRing` class for more information.

    >>> from sympy import QQ
    >>> from sympy.polys.puiseux import puiseux_ring
    >>> R, x, y = puiseux_ring('x, y', QQ)
    >>> p = 5*x**2 + 7*y**3
    >>> p
    7*y**3 + 5*x**2

    The internal representation of a Puiseux polynomial wraps a normal
    polynomial. To support negative powers the polynomial is considered to be
    divided by a monomial.

    >>> p2 = 1/x + 1/y**2
    >>> p2.monom # x*y**2
    (1, 2)
    >>> p2.poly
    x + y**2
    >>> (y**2 + x) / (x*y**2) == p2
    True

    To support fractional powers the polynomial is considered to be a function
    of ``x**(1/nx), y**(1/ny), ...``. The representation keeps track of a
    monomial and a list of exponent denominators so that the polynomial can be
    used to represent both negative and fractional powers.

    >>> p3 = x**QQ(1,2) + y**QQ(2,3)
    >>> p3.ns
    (2, 3)
    >>> p3.poly
    x + y**2

    See Also
    ========

    sympy.polys.puiseux.PuiseuxRing
    sympy.polys.rings.PolyElement
    r   r   r   r=   tuple[int, ...] | Noner\   nsr   c                2    |                      ||d d           S r8   )_new)clsr=   r   s      r   __new__zPuiseuxPoly.__new__  s    xxdD$///r   c                h    |                      |||          \  }}}|                     ||||          S r8   )
_normalize_new_raw)r{   r   r=   r\   rx   s        r   rz   zPuiseuxPoly._new  s7     ..ub99eR||D$r222r   c                r    t                               |           }||_        ||_        ||_        ||_        |S r8   )objectr|   r   r=   r\   rx   )r{   r   r=   r\   rx   objs         r   r   zPuiseuxPoly._new_raw$  s6     nnS!!	
r   r5   r   r6   c                    t          |t                    r0| j        |j        k    o| j        |j        k    o| j        |j        k    S | j        !| j        | j                            |          S t          S r8   )r9   r>   r=   r\   rx   r<   r:   r;   s     r   r<   zPuiseuxPoly.__eq__3  ss    e[)) 		"	UZ' (J%+-(Gux'
 ZDGO9##E***!!r   Btuple[PolyElement, tuple[int, ...] | None, tuple[int, ...] | None]c                   |||d d fS |d |                                 D             }t          d t          ||          D                       rt          ||          }d }n/t	          |          r t          ||          }t          ||          }|@|                                \  }\  }|                                }||ndgt          |          z  }g }	g }
g }t          ||||          D ]w\  }}}}|dk    rt          ||          }nt          |||          }|	
                    ||z             |

                    ||z             |
                    ||z             xt	          d |D                       r|                    |          }|}|t          |
          }t          d |	D                       rd }nt          |	          }|||fS )Nc                .    g | ]}t          |d           S )r   max)r$   ds     r   r'   z*PuiseuxPoly._normalize.<locals>.<listcomp>J  s     ;;;!C1II;;;r   c              3  (   K   | ]\  }}||k    V  d S r8   r"   )r$   rq   rp   s      r   rr   z)PuiseuxPoly._normalize.<locals>.<genexpr>K  s*      ;;B28;;;;;;r   r   c              3  "   K   | ]
}|d k    V  dS    Nr"   )r$   infls     r   rr   z)PuiseuxPoly._normalize.<locals>.<genexpr>b  s&      334!8333333r   c              3  "   K   | ]
}|d k    V  dS r   r"   r$   rD   s     r   rr   z)PuiseuxPoly._normalize.<locals>.<genexpr>j  s&      **a16******r   )tail_degreesallrt   rf   anyru   deflatedegreeslenr
   appendinflater*   )r{   r=   r\   rx   degs	factors_dpoly_dr   monom_dns_new	monom_new
inflationsfinirq   rp   r%   s                    r   r~   zPuiseuxPoly._normalize?  s    =RZt##;;t'8'8':':;;;D;;#dE*:*:;;;;; 0&tU33T 0&tT22"5$//>"&,,..IxllnnG$0eeqcCLL6HGFIJ"%iWg"F"F + +BB77BAABBAbAg&&&  q)))!!"'****33
33333 4
33D i((**6***** #6]]UBr   rl   dmonomtuple[Any, ...]c                0   |*|(t          d t          |||          D                       S |'t          d t          ||          D                       S |'t          d t          ||          D                       S t          d |D                       S )Nc              3  D   K   | ]\  }}}t          ||z
  |          V  d S r8   r   r$   rp   rq   r   s       r   rr   z-PuiseuxPoly._monom_fromint.<locals>.<genexpr>y  s4      RRZRRBGRRRRRRRr   c              3  @   K   | ]\  }}t          ||z
            V  d S r8   r   ro   s      r   rr   z-PuiseuxPoly._monom_fromint.<locals>.<genexpr>{  s0      FFRBGFFFFFFr   c              3  <   K   | ]\  }}t          ||          V  d S r8   r   r$   rp   r   s      r   rr   z-PuiseuxPoly._monom_fromint.<locals>.<genexpr>}  s.      AABBAAAAAAr   c              3  4   K   | ]}t          |          V  d S r8   r   r$   rp   s     r   rr   z-PuiseuxPoly._monom_fromint.<locals>.<genexpr>  s(      00BB000000r   rs   r{   r\   r   rx   s       r   _monom_fromintzPuiseuxPoly._monom_fromintq  s     ".RR3ufb;Q;QRRRRRRFF3uf3E3EFFFFFF^AA#eR..AAAAAA00%000000r   c                0   |*|(t          d t          |||          D                       S |'t          d t          ||          D                       S |'t          d t          ||          D                       S t          d |D                       S )Nc              3  R   K   | ]"\  }}}t          ||z  j        |z             V  #d S r8   rE   	numeratorr   s       r   rr   z+PuiseuxPoly._monom_toint.<locals>.<genexpr>  sM        2<"b"R"W'",--     r   c              3  J   K   | ]\  }}t          |j        |z             V  d S r8   r   ro   s      r   rr   z+PuiseuxPoly._monom_toint.<locals>.<genexpr>  s5      QQFBR\B.//QQQQQQr   c              3  J   K   | ]\  }}t          ||z  j                  V  d S r8   r   r   s      r   rr   z+PuiseuxPoly._monom_toint.<locals>.<genexpr>  s5      OOfb"b2g011OOOOOOr   c              3  >   K   | ]}t          |j                  V  d S r8   r   r   s     r   rr   z+PuiseuxPoly._monom_toint.<locals>.<genexpr>  s,      ;;rR\**;;;;;;r   rs   r   s       r   _monom_tointzPuiseuxPoly._monom_toint  s     ".  @CE6SU@V@V      QQc%>P>PQQQQQQ^OOE2OOOOOO;;U;;;;;;r   Iterator[tuple[Any, ...]]c              #     K   | j         | j        }}| j                                        D ]}|                     |||          V  dS )a@  Iterate over the monomials of a Puiseux polynomial.

        >>> from sympy import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x, y = puiseux_ring('x, y', QQ)
        >>> p = 5*x**2 + 7*y**3
        >>> list(p.itermonoms())
        [(2, 0), (0, 3)]
        >>> p[(2, 0)]
        5
        N)r\   rx   r=   
itermonomsr   )r&   r\   rx   r`   s       r   r   zPuiseuxPoly.itermonoms  s]       Jr%%'' 	4 	4A%%a333333	4 	4r   list[tuple[Any, ...]]c                D    t          |                                           S )z7Return a list of the monomials of a Puiseux polynomial.)listr   r3   s    r   monomszPuiseuxPoly.monoms  s    DOO%%&&&r   %Iterator[tuple[tuple[Any, ...], Any]]c                *    |                                  S r8   )r   r3   s    r   __iter__zPuiseuxPoly.__iter__  s       r   c                ^    |                      || j        | j                  }| j        |         S r8   )r   r\   rx   r=   )r&   r\   s     r   __getitem__zPuiseuxPoly.__getitem__  s*    !!%TW==yr   rE   c                *    t          | j                  S r8   )r   r=   r3   s    r   __len__zPuiseuxPoly.__len__  s    49~~r   c              #     K   | j         | j        }}| j                                        D ]"\  }}|                     |||          }||fV  #dS )a%  Iterate over the terms of a Puiseux polynomial.

        >>> from sympy import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x, y = puiseux_ring('x, y', QQ)
        >>> p = 5*x**2 + 7*y**3
        >>> list(p.iterterms())
        [((2, 0), 5), ((0, 3), 7)]
        N)r\   rx   r=   	itertermsr   )r&   r\   rx   r`   coeffmqs         r   r   zPuiseuxPoly.iterterms  sf       Jr	++-- 	 	HAu$$Qr22Be)OOOO	 	r   !list[tuple[tuple[Any, ...], Any]]c                D    t          |                                           S )z3Return a list of the terms of a Puiseux polynomial.)r   r   r3   s    r   r@   zPuiseuxPoly.terms      DNN$$%%%r   c                    | j         j        S )z7Return True if the Puiseux polynomial is a single term.)r=   is_termr3   s    r   r   zPuiseuxPoly.is_term  s     y  r   rA   c                D    t          |                                           S )z;Return a dictionary representation of a Puiseux polynomial.)rP   r   r3   s    r   to_dictzPuiseuxPoly.to_dict  r   r   r@   dict[tuple[Any, ...], Any]c                   	 dg|j         z  }dg|j         z  }|D ]6}d t          ||          D             }d t          ||          D             }7t          |          sdn't          d t          ||          D                       t	          d |D                       rd	nt          |          	 	fd|                                D             }|j                            |          }                     ||	          S )	a^  Create a Puiseux polynomial from a dictionary of terms.

        >>> from sympy import QQ
        >>> from sympy.polys.puiseux import puiseux_ring, PuiseuxPoly
        >>> R, x = puiseux_ring('x', QQ)
        >>> PuiseuxPoly.from_dict({(QQ(1,2),): QQ(3)}, R)
        3*x**(1/2)
        >>> R.from_dict({(QQ(1,2),): QQ(3)})
        3*x**(1/2)
        r   r   c                >    g | ]\  }}t          ||j                  S r"   )r   denominator)r$   rD   r`   s      r   r'   z)PuiseuxPoly.from_dict.<locals>.<listcomp>  s(    @@@DAq#a''@@@r   c                4    g | ]\  }}t          ||          S r"   )minr$   r`   rD   s      r   r'   z)PuiseuxPoly.from_dict.<locals>.<listcomp>  s$    666A3q!99666r   Nc              3  L   K   | ]\  }}t          ||z  j                   V   d S r8   r   r   s      r   rr   z(PuiseuxPoly.from_dict.<locals>.<genexpr>  s8      KKda3A0111KKKKKKr   c              3  "   K   | ]
}|d k    V  dS r   r"   r   s     r   rr   z(PuiseuxPoly.from_dict.<locals>.<genexpr>  s&      ""!qAv""""""r   c                F    i | ]\  }}                     |          |S r"   )r   )r$   r`   r   r{   r\   ns_finals      r   rc   z)PuiseuxPoly.from_dict.<locals>.<dictcomp>  s1    ]]]81e3##Auh77]]]r   )	r(   rt   r   r*   r   itemsr)   rC   rz   )
r{   r@   r   rx   monmoterms_pr=   r\   r   s
   `       @@r   rC   zPuiseuxPoly.from_dict  s)    S4:cDJ 	7 	7B@@CBKK@@@B66R666CC3xx 	LEEKKc#rllKKKKKE""r""""" 	!HHRyyH]]]]]]u{{}}]]]~''00xxdE8444r   r   c                J   | j         }|j        }|j        }g }|                                 D ]o\  }}|                    |          }g }t          |          D ]#\  }	}
|                    ||	         |
z             $|                    t          |g|R             pt          | S )aO  Convert a Puiseux polynomial to :class:`~sympy.core.expr.Expr`.

        >>> from sympy import QQ, Expr
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x = puiseux_ring('x', QQ)
        >>> p = 5*x**2 + 7*x**3
        >>> p.as_expr()
        7*x**3 + 5*x**2
        >>> isinstance(_, Expr)
        True
        )	r   r   r   r   to_sympy	enumerater   r	   r   )r&   r   domr   r@   r\   r   
coeff_exprmonoms_exprir`   s              r   as_exprzPuiseuxPoly.as_expr  s     yk, NN,, 	8 	8LE5e,,JK!%(( 4 41""71:?3333LLZ6+6667777E{r   r0   c                   dd| j         }|j        }d |j        D             }g }t          |                                           D ]\  }}d                    fd	t          ||          D                       }||j        k    r.|r|                    |           W|                    d
           m|s#|                    t          |                     |                    | d|            d                    |          S )Nbaser0   exprE   r   c                b    |dk    r| S |dk    rt          |          |k    r|  d| S |  d| dS )Nr   r   z**z**(r2   )rE   )r   r   s     r   format_powerz*PuiseuxPoly.__repr__.<locals>.format_power  sR    axxc#hh#oo''#'''))3))))r   c                ,    g | ]}t          |          S r"   )r0   )r$   ss     r   r'   z(PuiseuxPoly.__repr__.<locals>.<listcomp>  s    ---1A---r   *c              3  :   K   | ]\  }}| ||          V  d S r8   r"   )r$   r   er   s      r   rr   z'PuiseuxPoly.__repr__.<locals>.<genexpr>  s9       V V1TU Va!3!3 V V V V V Vr   1z + )r   r0   r   rE   r   r0   )
r   r   r   sortedr@   joinrt   r,   r   r0   )	r&   r   r   syms	terms_strr\   r   	monom_strr   s	           @r   r4   zPuiseuxPoly.__repr__	  s3   	* 	* 	* 	* yk-----	"4::<<00 
	9 
	9LE5 V V V VD%@P@P V V VVVI *$$Y////$$S)))) 9  U,,,,  E!7!7I!7!78888zz)$$$r   Otuple[PolyElement, PolyElement, tuple[int, ...] | None, tuple[int, ...] | None]c                   | j         | j        | j        }}}|j         |j        |j        }}}||k    r||k    r||||fS ||k    r|}nd||t          d t	          ||          D                       }d t	          ||          D             }	d t	          ||          D             }
|                    |	          }|                    |
          }|'t          d t	          ||	          D                       }|'t          d t	          ||
          D                       }n|A|}|                    |          }|'t          d t	          ||          D                       }nE|A|}|                    |          }|'t          d t	          ||          D                       }nJ ||k    r|}n|f|dt          d
 t	          ||          D                       }t          |t          ||                    }t          |t          ||                    }n,||}t          ||          }n||}t          ||          }nJ ||||fS )z7Bring two Puiseux polynomials to a common monom and ns.Nc              3  <   K   | ]\  }}t          ||          V  d S r8   )r   )r$   n1n2s      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>5  s.      ??vr2s2r{{??????r   c                    g | ]
\  }}||z  S r"   r"   )r$   rD   r   s      r   r'   z&PuiseuxPoly._unify.<locals>.<listcomp>6       444ea!r'444r   c                    g | ]
\  }}||z  S r"   r"   )r$   rD   r   s      r   r'   z&PuiseuxPoly._unify.<locals>.<listcomp>7  r   r   c              3  &   K   | ]\  }}||z  V  d S r8   r"   r$   r`   fs      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>;  *      AAAq1uAAAAAAr   c              3  &   K   | ]\  }}||z  V  d S r8   r"   r   s      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>=  r  r   c              3  &   K   | ]\  }}||z  V  d S r8   r"   r   s      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>B  r  r   c              3  &   K   | ]\  }}||z  V  d S r8   r"   r   s      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>G  r  r   Fc              3  <   K   | ]\  }}t          ||          V  d S r8   r   )r$   m1m2s      r   rr   z%PuiseuxPoly._unify.<locals>.<genexpr>N  s.      HH&"b#b"++HHHHHHr   )r=   r\   rx   r*   rt   r   rk   ru   )r&   r5   poly1monom1ns1poly2monom2ns2rx   f1f2r\   s               r   _unifyzPuiseuxPoly._unify&  s    "Y
DGsv"ZehsvVs

%,,#::BB_??S#?????B44s2s||444B44s2s||444BMM"%%EMM"%%E!AAVRAAAAA!AAVRAAAAA_BMM"%%E!AAVRAAAAA_BMM"%%E!AAVRAAAAALVEEF$6HHC4G4GHHHHHE#E:eV+D+DEEE#E:eV+D+DEEEEE#E622EEE#E622EELeUB&&r   c                    | S r8   r"   r3   s    r   __pos__zPuiseuxPoly.__pos__\  s    r   c                \    |                      | j        | j         | j        | j                  S r8   r   r   r=   r\   rx   r3   s    r   __neg__zPuiseuxPoly.__neg___  s$    }}TY
DJHHHr   c                   t          |t                    r4| j        |j        k    rt          d          |                     |          S | j        j        }t          |t                    r;|                     |                    t          |          t                              S |
                    |          r|                     |          S t          S )Nz3Cannot add Puiseux polynomials from different rings)r9   r>   r   
ValueError_addr   rE   _add_groundconvert_fromr   of_typer:   r&   r5   r   s      r   __add__zPuiseuxPoly.__add__b  s    e[)) 	$yEJ&& !VWWW99U###!eS!! 	"##F$7$75		2$F$FGGG^^E"" 	"##E***!!r   c                   | j         j        }t          |t                    r;|                     |                    t          |          t                              S |                    |          r|                     |          S t          S r8   )	r   r   r9   rE   r  r  r   r  r:   r  s      r   __radd__zPuiseuxPoly.__radd__o  v    !eS!! 	"##F$7$75		2$F$FGGG^^E"" 	"##E***!!r   c                   t          |t                    r4| j        |j        k    rt          d          |                     |          S | j        j        }t          |t                    r;|                     |                    t          |          t                              S |
                    |          r|                     |          S t          S )Nz8Cannot subtract Puiseux polynomials from different rings)r9   r>   r   r  _subr   rE   _sub_groundr  r   r  r:   r  s      r   __sub__zPuiseuxPoly.__sub__x      e[)) 	$yEJ&& N   99U###!eS!! 	"##F$7$75		2$F$FGGG^^E"" 	"##E***!!r   c                   | j         j        }t          |t                    r;|                     |                    t          |          t                              S |                    |          r|                     |          S t          S r8   )	r   r   r9   rE   _rsub_groundr  r   r  r:   r  s      r   __rsub__zPuiseuxPoly.__rsub__  sv    !eS!! 	"$$V%8%8EB%G%GHHH^^E"" 	"$$U+++!!r   c                   t          |t                    r4| j        |j        k    rt          d          |                     |          S | j        j        }t          |t                    r;|                     |                    t          |          t                              S |
                    |          r|                     |          S t          S )Nz8Cannot multiply Puiseux polynomials from different rings)r9   r>   r   r  _mulr   rE   _mul_groundr  r   r  r:   r  s      r   __mul__zPuiseuxPoly.__mul__  r%  r   c                   | j         j        }t          |t                    r;|                     |                    t          |          t                              S |                    |          r|                     |          S t          S r8   )	r   r   r9   rE   r+  r  r   r  r:   r  s      r   __rmul__zPuiseuxPoly.__rmul__  r   r   c                    t          |t                    r1|dk    r|                     |          S |                     |           S t	          j        |          r|                     |          S t          S )Nr   )r9   rE   	_pow_pint	_pow_nintr   r  _pow_rationalr:   r;   s     r   __pow__zPuiseuxPoly.__pow__  so    eS!! 	"zz~~e,,,~~uf---Z 	"%%e,,,!!r   c                   t          |t                    rF| j        |j        k    rt          d          |                     |                                          S | j        j        }t          |t                    r<|                     |	                    t          d|          t                              S |                    |          r|                     |          S t          S )Nz6Cannot divide Puiseux polynomials from different ringsr   )r9   r>   r   r  r*  _invr   rE   r+  r  r   r  _div_groundr:   r  s      r   __truediv__zPuiseuxPoly.__truediv__  s    e[)) 	+yEJ&& L   99UZZ\\***!eS!! 	"##F$7$71eb$I$IJJJ^^E"" 	"##E***!!r   c                t   t          |t                    rW|                                                     | j        j                            t          |          t                              S | j        j                            |          r'|                                                     |          S t          S r8   )
r9   rE   r5  r+  r   r   r  r   r  r:   r;   s     r   __rtruediv__zPuiseuxPoly.__rtruediv__  s    eS!! 	"99;;**49+;+H+HETV+W+WXXXY%%e,, 	"99;;**5111!!r   c                v    |                      |          \  }}}}|                     | j        ||z   ||          S r8   r  rz   r   r&   r5   r  r  r\   rx   s         r   r  zPuiseuxPoly._add  :    "&++e"4"4ueRyyEEM5"===r   groundc                \    |                      | j                            |                    S r8   )r  r   rN   r&   r>  s     r   r  zPuiseuxPoly._add_ground  $    yy--f55666r   c                v    |                      |          \  }}}}|                     | j        ||z
  ||          S r8   r;  r<  s         r   r"  zPuiseuxPoly._sub  r=  r   c                \    |                      | j                            |                    S r8   )r"  r   rN   r@  s     r   r#  zPuiseuxPoly._sub_ground  rA  r   c                \    | j                             |                              |           S r8   )r   rN   r"  r@  s     r   r'  zPuiseuxPoly._rsub_ground  s&    y##F++00666r   c                    |                      |          \  }}}}|t          d |D                       }|                     | j        ||z  ||          S )Nc              3      K   | ]	}d |z  V  
dS )   Nr"   )r$   r   s     r   rr   z#PuiseuxPoly._mul.<locals>.<genexpr>  s&      //A!a%//////r   )r  r*   rz   r   r<  s         r   r*  zPuiseuxPoly._mul  s\    "&++e"4"4ueR///////EyyEEM5"===r   c                `    |                      | j        | j        |z  | j        | j                  S r8   r  r@  s     r   r+  zPuiseuxPoly._mul_ground  '    }}TY	F(:DJPPPr   c                `    |                      | j        | j        |z  | j        | j                  S r8   r  r@  s     r   r6  zPuiseuxPoly._div_ground  rI  r   rD   c                    dk    sJ | j         }|t          fd|D                       }|                     | j        | j        z  || j                  S )Nr   c              3  "   K   | ]	}|z  V  
d S r8   r"   r   s     r   rr   z(PuiseuxPoly._pow_pint.<locals>.<genexpr>  s'      //A!a%//////r   )r\   r*   rz   r   r=   rx   )r&   rD   r\   s    ` r   r0  zPuiseuxPoly._pow_pint  sa    Avvvv
/////////EyyDIqL%AAAr   c                P    |                                                      |          S r8   )r5  r0  rG   s     r   r1  zPuiseuxPoly._pow_nint  s    yy{{$$Q'''r   c                :   | j         st          d          |                                 \  \  }}| j        j        }|                    |          st          d          t          fd|D                       }| j                            ||j        i          S )Nz0Only monomials can be raised to a rational powerc              3  "   K   | ]	}|z  V  
d S r8   r"   r   s     r   rr   z,PuiseuxPoly._pow_rational.<locals>.<genexpr>  s'      ++a!e++++++r   )	r   r  r@   r   r   is_oner*   rC   r,   )r&   rD   r\   r   r   s    `   r   r2  zPuiseuxPoly._pow_rational  s    | 	QOPPP::<<%!}}U## 	QOPPP++++U+++++y""E6:#6777r   c                B   | j         st          d          |                                 \  \  }}| j        j        }|j        s$|                    |          st          d          t          d |D                       }d|z  }| j                            ||i          S )NzOnly terms can be invertedz"Cannot invert non-unit coefficientc              3     K   | ]}| V  d S r8   r"   )r$   r`   s     r   rr   z#PuiseuxPoly._inv.<locals>.<genexpr>  s$      ((Qqb((((((r   r   )	r   r  r@   r   r   is_FieldrP  r*   rC   )r&   r\   r   r   s       r   r5  zPuiseuxPoly._inv  s    | 	;9:::::<<%! 	Cv}}U';'; 	CABBB((%(((((E	y""E5>222r   rR   c                   | j         }|                    |          }i }|                                 D ]C\  }}||         }|r4t          |          }||xx         dz  cc<   ||z  |t	          |          <   D ||          S )a:  Differentiate a Puiseux polynomial with respect to a variable.

        >>> from sympy import QQ
        >>> from sympy.polys.puiseux import puiseux_ring
        >>> R, x, y = puiseux_ring('x, y', QQ)
        >>> p = 5*x**2 + 7*y**3
        >>> p.diff(x)
        10*x
        >>> p.diff(y)
        21*y**2
        r   )r   rT   r   r   r*   )	r&   rR   r   r   r%   expvr   rD   r   s	            r   diffzPuiseuxPoly.diff  s     yJJqMM>>++ 	( 	(KD%QA (JJ!	#ai%((tAwwr   N)r=   r   r   r   r   r>   )
r   r   r=   r   r\   rw   rx   rw   r   r>   rV   )r=   r   r\   rw   rx   rw   r   r   )r\   rl   r   rw   rx   rw   r   r   )r\   r   r   rw   rx   rw   r   rl   )r   r   )r   r   )r   r   )r\   rl   r   r   )r   rE   )r   r   )r   r6   )r   rA   )r@   r   r   r   r   r>   )r   r   rU   )r5   r>   r   r   )r   r>   )r5   r   r   r>   )r5   r>   r   r>   )r>  r   r   r>   rW   )rD   r   r   r>   )rR   r>   r   r>   )3rX   rY   rZ   r[   __annotations__r|   classmethodrz   r   r<   r~   r   r   r   r   r   r   r   r   r@   propertyr   r   rC   r   r4   r  r  r  r  r  r$  r(  r,  r.  r3  r7  r9  r  r  r"  r#  r'  r*  r+  r6  r0  r1  r2  r5  rV  r"   r   r   r>   r>      s*        ' 'R !!!!0 0 0 0 3 3 3 [3    [
" 
" 
" 
" / / / [/b 1 1 1 [1 < < < [<"4 4 4 4 ' ' ' '! ! ! !             & & & & ! ! ! X!& & & & !5 !5 !5 [!5F   0% % % %:4' 4' 4' 4'l   I I I I" " " "" " " "" " " "" " " "" " " "" " " "	" 	" 	" 	"" " " "" " " "> > > >7 7 7 7> > > >7 7 7 77 7 7 7> > > >Q Q Q QQ Q Q QB B B B( ( ( (8 8 8 8	3 	3 	3 	3     r   r>   N)r   r   r   r   r   r   )r=   r   r\   r]   r   r   )r\   r]   rb   r]   r   rl   )r[   
__future__r   sympy.polys.domainsr   sympy.polys.ringsr   r   sympy.core.addr   sympy.core.mulr	   sympy.external.gmpyr
   r   typingr   r   r   sympy.core.exprr   r   collections.abcr   r   r   r   rf   rk   ru   r>   r"   r   r   <module>rc     s   & # " " " " " " " " " " " 3 3 3 3 3 3 3 3             ( ( ( ( ( ( ( ( !            3""""""""$$$$$$******22222222   (Y" Y" Y" Y" Y" Y" Y" Y"xG G G GG G G G8 8 8 8t t t t t t t t t tr   