
    \hg                       S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SSKJr  \(       a  SS	KJrJr  SS
KJr  SSKJr  SSKJrJr        SS jr " S S5      rSS jrSS jrSS jr " S S5      rg)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Iteratorc                8    [        X5      nU4UR                  -   $ )a;  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)symbolsdomainrings      K/var/www/auris/envauris/lib/python3.13/site-packages/sympy/polys/puiseux.pypuiseux_ringr   '   s      w'D7TYY    c                  |    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSrg)r   ;   aT  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
c                   [        X5      nUR                  nUR                  nX0l        X l        UR                  U l        [        UR                   Vs/ s H  oPR                  U5      PM     sn5      U l        X@l        U R                  UR                  5      U l        U R                  UR                  5      U l	        UR                  U l
        UR                  U l        g s  snf N)r   r   ngens	poly_ringr   tupler   	from_polyzeroone
zero_monommonomial_mul)selfr   r   r!   r    gs         r   __init__PuiseuxRing.__init__`   s    W-	!!" ((innEn>>!,nEF	
NN9>>2	>>)--0#..%22 Fs   C#c                <    SU R                    SU R                   S3$ )NzPuiseuxRing(z, ))r   r   r(   s    r   __repr__PuiseuxRing.__repr__t   s    dll^2dkk]!<<r   c                    [        U[        5      (       d  [        $ U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r   )
isinstancer   NotImplementedr   r   r(   others     r   __eq__PuiseuxRing.__eq__w   s:    %--!!||u}},L1LLr   c                    [        X5      $ )a
  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
)PuiseuxPoly)r(   polys     r   r#   PuiseuxRing.from_poly|   s     4&&r   c                ,    [         R                  X5      $ )zCreate 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)
)r9   	from_dict)r(   termss     r   r=   PuiseuxRing.from_dict   s     $$U11r   c                B    U R                  U R                  U5      5      $ )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(   ns     r   from_intPuiseuxRing.from_int   s     ~~dnnQ/00r   c                8    U R                   R                  U5      $ )zCreate 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(   args     r   rF   PuiseuxRing.domain_new   s     ~~((--r   c                V    U R                  U R                  R                  U5      5      $ )zCreate 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_newrG   s     r   rK   PuiseuxRing.ground_new   s"     ~~dnn77<==r   c                    [        U[        5      (       a  U R                  U5      $ U R                  U R	                  U5      5      $ )zCoerce 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)
)r2   dictr=   r#   r!   rG   s     r   __call__PuiseuxRing.__call__   s8     c4  >>#&&>>$.."566r   c                8    U R                   R                  U5      $ )zReturn 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(   xs     r   rR   PuiseuxRing.index   s     yyq!!r   )	r   r   r'   r    r%   r!   r   r$   r&   N)r   str | list[Expr]r   r   returnstrr5   r   rW   bool)r:   r   rW   r9   )r>   dict[tuple[int, ...], Any]rW   r9   rB   intrW   r9   )rH   r   rW   r   )rH   r   rW   r9   )rS   r9   rW   r]   )__name__
__module____qualname____firstlineno____doc__r*   r/   r6   r#   r=   rC   rF   rK   rO   rR   __static_attributes__ r   r   r   r   ;   s;    #H3(=M
'	2	1.>7 "r   r   c           
         U R                   nUR                  nUR                  U R                  5        VVs0 s H  u  pEU" XA5      U_M     snn5      $ s  snnf r   )r   monomial_divr=   r>   )r:   monomr   divmcs         r   _div_poly_monomrk      H    99D


C>>

E3q=!+EFFE   A
c           
         U R                   nUR                  nUR                  U R                  5        VVs0 s H  u  pEU" XA5      U_M     snn5      $ s  snnf r   )r   r'   r=   r>   )r:   rg   r   mulri   rj   s         r   _mul_poly_monomrp      rl   rm   c                8    [        S [        X5       5       5      $ )Nc              3  .   #    U  H  u  pX-
  v   M     g 7fr   rd   .0midis      r   	<genexpr>_div_monom.<locals>.<genexpr>   s     7VR   r"   zip)rg   rh   s     r   
_div_monomr|      s    7s5777r   c                     \ rS rSr% SrS\S'   S\S'   S\S'   S\S	'   S8S
 jr\          S9S j5       r\          S9S j5       r	S:S jr
\        S;S j5       r\        S<S j5       r\        S=S j5       rS>S jrS?S jrS@S jrSAS jrSBS jrS@S jrSCS jr\SDS j5       rSES jr\      SFS j5       rSGS jrSHS jr    SIS jrSJS jrSJS jrSKS  jrSKS! jrSKS" jr SKS# jr!SKS$ jr"SKS% jr#SKS& jr$SKS' jr%SKS( jr&SLS) jr'SMS* jr(SLS+ jr)SMS, jr*SMS- jr+SLS. jr,SMS/ jr-SMS0 jr.SNS1 jr/SNS2 jr0SOS3 jr1SJS4 jr2SPS5 jr3S6r4g7)Qr9      a  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, ...] | Nonerg   nsc                (    U R                  X!S S 5      $ r   )_new)clsr:   r   s      r   __new__PuiseuxPoly.__new__  s    xxD$//r   c                P    U R                  X#U5      u  p#nU R                  XX45      $ r   )
_normalize_new_raw)r   r   r:   rg   r   s        r   r   PuiseuxPoly._new  s)     ..b9R||D22r   c                `    [         R                  U 5      nXl        X%l        X5l        XEl        U$ r   )objectr   r   r:   rg   r   )r   r   r:   rg   r   objs         r   r   PuiseuxPoly._new_raw$  s+     nnS!	
r   c                T   [        U[        5      (       aY  U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ U R                  c(  U R                  c  U R                  R                  U5      $ [        $ r   )r2   r9   r:   rg   r   r6   r3   r4   s     r   r6   PuiseuxPoly.__eq__3  s}    e[))		UZZ' (JJ%++-(GGuxx'
 ZZDGGO99##E**!!r   c                P   Uc  Uc  US S 4$ Ub~  UR                  5        Vs/ s H  n[        US5      PM     nn[        S [        XR5       5       5      (       a  [	        X5      nS nO&[        U5      (       a  [	        X5      n[        X%5      nUGb  UR                  5       u  nu  nUR                  5       nUb  UOS/[        U5      -  n	/ n
/ n/ n[        XcX5       Hb  u  pnnUS:X  a  [        UU5      nO[        XU5      nU
R                  UU-  5        UR                  UU-  5        UR                  UU-  5        Md     [        S U 5       5      (       a  UR                  U5      nUnUb  [        U5      n[        S U
 5       5      (       a  S nO[        U
5      nXU4$ s  snf )Nr   c              3  .   #    U  H  u  pX:  v   M     g 7fr   rd   )rt   rv   ru   s      r   rw   )PuiseuxPoly._normalize.<locals>.<genexpr>K  s     ;*:28*:ry   c              3  *   #    U  H	  oS :  v   M     g7f   Nrd   )rt   infls     r   rw   r   b  s     3
!8
   c              3  *   #    U  H	  oS :H  v   M     g7fr   rd   rt   rB   s     r   rw   r   j  s     *6a66r   )tail_degreesmaxallr{   rk   anyr|   deflatedegreeslenr
   appendinflater"   )r   r:   rg   r   ddegs	factors_dpoly_dr   monom_dns_new	monom_new
inflationsfinirv   ru   r)   s                     r   r   PuiseuxPoly._normalize?  s    =RZt##'+'8'8':;':!C1I':D;;#d*:;;;&t3T&t2"5/>"&,,.IxllnG$0eqcCL6HGFIJ"%iW"FB7BABBAbAg&  q)!!"'* #G 3
333
3D i(*6***6]BK <s   F#c                    Ub  Ub  [        S [        XU5       5       5      $ Ub  [        S [        X5       5       5      $ Ub  [        S [        X5       5       5      $ [        S U 5       5      $ )Nc              3  D   #    U  H  u  pn[        X-
  U5      v   M     g 7fr   r   rt   ru   rv   r   s       r   rw   -PuiseuxPoly._monom_fromint.<locals>.<genexpr>y  s      R;QZRRBGR;Qs    c              3  @   #    U  H  u  p[        X-
  5      v   M     g 7fr   r   rs   s      r   rw   r   {  s     F3EBG3Es   c              3  <   #    U  H  u  p[        X5      v   M     g 7fr   r   rt   ru   r   s      r   rw   r   }  s     A.B.   c              3  8   #    U  H  n[        U5      v   M     g 7fr   r   rt   ru   s     r   rw   r     s     0%BB%s   rz   r   rg   dmonomr   s       r   _monom_fromintPuiseuxPoly._monom_fromintq  sm     ".R3ub;QRRRF3u3EFFF^A#e.AAA0%000r   c                    Ub  Ub  [        S [        XU5       5       5      $ Ub  [        S [        X5       5       5      $ Ub  [        S [        X5       5       5      $ [        S U 5       5      $ )Nc              3  \   #    U  H"  u  pn[        X-  R                  U-   5      v   M$     g 7fr   r]   	numeratorr   s       r   rw   +PuiseuxPoly._monom_toint.<locals>.<genexpr>  s-      @V*""RW''",--@Vs   *,c              3  V   #    U  H  u  p[        UR                  U-   5      v   M!     g 7fr   r   rs   s      r   rw   r     s%     Q>PFBR\\B.//>P   ')c              3  T   #    U  H  u  p[        X-  R                  5      v   M      g 7fr   r   r   s      r   rw   r     s"     Ofbbg0011s   &(c              3  L   #    U  H  n[        UR                  5      v   M     g 7fr   r   r   s     r   rw   r     s     ;UrR\\**Us   "$rz   r   s       r   _monom_tointPuiseuxPoly._monom_toint  sy     ". @CESU@V   Qc%>PQQQ^OEOOO;U;;;r   c              #     #    U R                   U R                  p!U R                  R                  5        H  nU R	                  X1U5      v   M     g7f)zIterate 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)rg   r   r:   
itermonomsr   )r(   rg   r   ri   s       r   r   PuiseuxPoly.itermonoms  s@      JJr%%'A%%a33 (s   AAc                4    [        U R                  5       5      $ )z7Return a list of the monomials of a Puiseux polynomial.)listr   r.   s    r   monomsPuiseuxPoly.monoms  s    DOO%&&r   c                "    U R                  5       $ r   )r   r.   s    r   __iter__PuiseuxPoly.__iter__  s      r   c                l    U R                  XR                  U R                  5      nU R                  U   $ r   )r   rg   r   r:   )r(   rg   s     r   __getitem__PuiseuxPoly.__getitem__  s+    !!%TWW=yyr   c                ,    [        U R                  5      $ r   )r   r:   r.   s    r   __len__PuiseuxPoly.__len__  s    499~r   c              #     #    U R                   U R                  p!U R                  R                  5        H  u  p4U R	                  X1U5      nXT4v   M     g7f)zIterate 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)rg   r   r:   	itertermsr   )r(   rg   r   ri   coeffmqs         r   r   PuiseuxPoly.iterterms  sH      JJr		++-HA$$Qr2B)O .s   AAc                4    [        U R                  5       5      $ )z3Return a list of the terms of a Puiseux polynomial.)r   r   r.   s    r   r>   PuiseuxPoly.terms      DNN$%%r   c                .    U R                   R                  $ )z7Return True if the Puiseux polynomial is a single term.)r:   is_termr.   s    r   r   PuiseuxPoly.is_term  s     yy   r   c                4    [        U R                  5       5      $ )z;Return a dictionary representation of a Puiseux polynomial.)rN   r   r.   s    r   to_dictPuiseuxPoly.to_dict  r   r   c           	        S/UR                   -  nS/UR                   -  nU H]  n[        X55       VVs/ s H  u  pg[        XgR                  5      PM     nnn[        XT5       VVs/ s H  u  pv[	        Xv5      PM     nnnM_     [        U5      (       d  SnO[        S [        XC5       5       5      n[        S U 5       5      (       a  Sn	O[        U5      n	UR                  5        VV
s0 s H  u  pzU R                  XxU	5      U
_M     nnn
UR                  R                  U5      nU R                  X,X5      $ s  snnf s  snnf s  sn
nf )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   Nc              3  V   #    U  H  u  p[        X-  R                  5      * v   M!     g 7fr   r   rt   ri   rB   s      r   rw   (PuiseuxPoly.from_dict.<locals>.<genexpr>  s"     Klda30011lr   c              3  *   #    U  H	  oS :H  v   M     g7fr   rd   r   s     r   rw   r     s     "r!Avrr   )r    r{   r   denominatorminr   r"   r   itemsr   r!   r=   r   )r   r>   r   r   monmorB   ri   rg   ns_finalr   terms_pr:   s                r   r=   PuiseuxPoly.from_dict  s    S4::cDJJB47K@KDA#a'KB@),R63q9C6C  3xxEKc#lKKE"r"""HRyHOT{{}]}813##Ah7>}]~~''0xxE44# A6 ^s   !D9&D?*Ec                @   U R                   nUR                  nUR                  n/ nU R                  5        H]  u  pVUR	                  U5      n/ n[        U5       H  u  pUR                  X9   U
-  5        M     UR                  [        U/UQ76 5        M_     [        U6 $ )a  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>   rg   r   
coeff_exprmonoms_expriri   s              r   as_exprPuiseuxPoly.as_expr  s     yykk,, NN,LEe,JK!%(""7:?3 )LLZ6+67 - E{r   c                .  ^	 SS jm	U R                   nUR                  nUR                   Vs/ s H  n[        U5      PM     nn/ n[	        U R                  5       5       H  u  pgSR                  U	4S j[        XF5       5       5      nXrR                  :X  a-  U(       a  UR                  U5        MR  UR                  S5        Me  U(       d  UR                  [        U5      5        M  UR                  U SU 35        M     SR                  U5      $ s  snf )Nc                Z    US:X  a  U $ US:  a  [        U5      U:X  a  U  SU 3$ U  SU S3$ )Nr   r   z**z**(r-   )r]   )baseexps     r   format_power*PuiseuxPoly.__repr__.<locals>.format_power  sC    axc#h#or#''s3%q))r   *c              3  J   >#    U  H  u  pU(       d  M  T" X5      v   M     g 7fr   rd   )rt   ser   s      r   rw   'PuiseuxPoly.__repr__.<locals>.<genexpr>  s#      V@PTU!3a!3!3@Ps   ##1z + )r   rX   r   r]   rW   rX   )
r   r   r   rX   sortedr>   joinr{   r%   r   )
r(   r   r   r  syms	terms_strrg   r   	monom_strr   s
            @r   r/   PuiseuxPoly.__repr__	  s    	* yykk $-1A-	"4::<0LE VD@P VVI$$Y/$$S)  U,  E7!I;!78 1 zz)$$ .s   Dc                (   U R                   U R                  U R                  pCnUR                   UR                  UR                  pvnX6:X  a	  XG:X  a  X%X44$ XG:X  a  UnGO.Ub  Ub  [        S [	        XG5       5       5      n[	        X5       V	V
s/ s H	  u  pX-  PM     nn	n
[	        X5       V	Vs/ s H	  u  pX-  PM     nn	nUR                  U5      nUR                  U5      nUb  [        S [	        X;5       5       5      nUb  [        S [	        Xm5       5       5      nOlUb2  UnUR                  U5      nUb  [        S [	        X85       5       5      nO7Ub2  UnUR                  U5      nUb  [        S [	        Xh5       5       5      nO eX6:X  a  UnOpUbI  UbF  [        S [	        X65       5       5      n[        U[        X5      5      n[        U[        X5      5      nO$Ub  Un[        X&5      nOUb  Un[        XS5      nO eX%X4$ s  sn
n	f s  snn	f )z7Bring two Puiseux polynomials to a common monom and ns.c              3  <   #    U  H  u  p[        X5      v   M     g 7fr   )r   )rt   n1n2s      r   rw   %PuiseuxPoly._unify.<locals>.<genexpr>5  s     ?vrs2{{r   c              3  .   #    U  H  u  pX-  v   M     g 7fr   rd   rt   ri   fs      r   rw   r  ;       Aqury   c              3  .   #    U  H  u  pX-  v   M     g 7fr   rd   r  s      r   rw   r  =  r  ry   c              3  .   #    U  H  u  pX-  v   M     g 7fr   rd   r   s      r   rw   r  B  r  ry   c              3  .   #    U  H  u  pX-  v   M     g 7fr   rd   r   s      r   rw   r  G  r  ry   c              3  <   #    U  H  u  p[        X5      v   M     g 7fr   )r   )rt   m1m2s      r   rw   r  N  s     H4G&"#b++4Gr   )r:   rg   r   r"   r{   r   rp   r|   )r(   r5   poly1monom1ns1poly2monom2ns2r   rB   r  f1r  f2rg   s                  r   _unifyPuiseuxPoly._unify&  s    "YY

DGGs"ZZehhs
,,:B_?S??B'*2|4|ea!'|B4'*2|4|ea!'|B4MM"%EMM"%E!AVAA!AVAA_BMM"%E!AVAA_BMM"%E!AVAA5EF$6HC4GHHE#E:e+DEE#E:e+DEEE#E2EE#E2E5U&&I 54s   H.Hc                    U $ r   rd   r.   s    r   __pos__PuiseuxPoly.__pos__\  s    r   c                |    U R                  U R                  U R                  * U R                  U R                  5      $ r   r   r   r:   rg   r   r.   s    r   __neg__PuiseuxPoly.__neg___  s)    }}TYY
DJJHHr   c                   [        U[        5      (       a6  U R                  UR                  :w  a  [        S5      eU R	                  U5      $ U R                  R
                  n[        U[        5      (       a.  U R                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R                  U5      $ [        $ )Nz3Cannot add Puiseux polynomials from different rings)r2   r9   r   
ValueError_addr   r]   _add_groundconvert_fromr   of_typer3   r(   r5   r   s      r   __add__PuiseuxPoly.__add__b  s    e[))yyEJJ& !VWW99U##!!eS!!##F$7$75	2$FGG^^E""##E**!!r   c                   U R                   R                  n[        U[        5      (       a.  U R	                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R	                  U5      $ [        $ r   )	r   r   r2   r]   r0  r1  r   r2  r3   r3  s      r   __radd__PuiseuxPoly.__radd__o  f    !!eS!!##F$7$75	2$FGG^^E""##E**!!r   c                   [        U[        5      (       a6  U R                  UR                  :w  a  [        S5      eU R	                  U5      $ U R                  R
                  n[        U[        5      (       a.  U R                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R                  U5      $ [        $ )Nz8Cannot subtract Puiseux polynomials from different rings)r2   r9   r   r.  _subr   r]   _sub_groundr1  r   r2  r3   r3  s      r   __sub__PuiseuxPoly.__sub__x      e[))yyEJJ& N  99U##!!eS!!##F$7$75	2$FGG^^E""##E**!!r   c                   U R                   R                  n[        U[        5      (       a.  U R	                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R	                  U5      $ [        $ r   )	r   r   r2   r]   _rsub_groundr1  r   r2  r3   r3  s      r   __rsub__PuiseuxPoly.__rsub__  sf    !!eS!!$$V%8%8EB%GHH^^E""$$U++!!r   c                   [        U[        5      (       a6  U R                  UR                  :w  a  [        S5      eU R	                  U5      $ U R                  R
                  n[        U[        5      (       a.  U R                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R                  U5      $ [        $ )Nz8Cannot multiply Puiseux polynomials from different rings)r2   r9   r   r.  _mulr   r]   _mul_groundr1  r   r2  r3   r3  s      r   __mul__PuiseuxPoly.__mul__  r?  r   c                   U R                   R                  n[        U[        5      (       a.  U R	                  UR                  [        U5      [        5      5      $ UR                  U5      (       a  U R	                  U5      $ [        $ r   )	r   r   r2   r]   rF  r1  r   r2  r3   r3  s      r   __rmul__PuiseuxPoly.__rmul__  r9  r   c                    [        U[        5      (       a)  US:  a  U R                  U5      $ U R                  U* 5      $ [        R
                  " U5      (       a  U R                  U5      $ [        $ )Nr   )r2   r]   	_pow_pint	_pow_nintr   r2  _pow_rationalr3   r4   s     r   __pow__PuiseuxPoly.__pow__  s\    eS!!z~~e,,~~uf--ZZ%%e,,!!r   c                   [        U[        5      (       aD  U R                  UR                  :w  a  [        S5      eU R	                  UR                  5       5      $ U R                  R                  n[        U[        5      (       a/  U R                  UR                  [        SU5      [        5      5      $ UR                  U5      (       a  U R                  U5      $ [        $ )Nz6Cannot divide Puiseux polynomials from different ringsr   )r2   r9   r   r.  rE  _invr   r]   rF  r1  r   r2  _div_groundr3   r3  s      r   __truediv__PuiseuxPoly.__truediv__  s    e[))yyEJJ& L  99UZZ\**!!eS!!##F$7$71eb$IJJ^^E""##E**!!r   c                j   [        U[        5      (       aP  U R                  5       R                  U R                  R
                  R                  [        U5      [        5      5      $ U R                  R
                  R                  U5      (       a  U R                  5       R                  U5      $ [        $ r   )
r2   r]   rS  rF  r   r   r1  r   r2  r3   r4   s     r   __rtruediv__PuiseuxPoly.__rtruediv__  sz    eS!!99;**499+;+;+H+HETV+WXXYY%%e,,99;**511!!r   c                h    U R                  U5      u  p#pEU R                  U R                  X#-   XE5      $ r   r$  r   r   r(   r5   r  r  rg   r   s         r   r/  PuiseuxPoly._add  .    "&++e"4eyyEM5==r   c                V    U R                  U R                  R                  U5      5      $ r   )r/  r   rK   r(   grounds     r   r0  PuiseuxPoly._add_ground       yy--f566r   c                h    U R                  U5      u  p#pEU R                  U R                  X#-
  XE5      $ r   r[  r\  s         r   r;  PuiseuxPoly._sub  r^  r   c                V    U R                  U R                  R                  U5      5      $ r   )r;  r   rK   r`  s     r   r<  PuiseuxPoly._sub_ground  rc  r   c                V    U R                   R                  U5      R                  U 5      $ r   )r   rK   r;  r`  s     r   rA  PuiseuxPoly._rsub_ground  s"    yy##F+0066r   c                    U R                  U5      u  p#pEUb  [        S U 5       5      nU R                  U R                  X#-  XE5      $ )Nc              3  ,   #    U  H
  nS U-  v   M     g7f)   Nrd   )rt   r  s     r   rw   #PuiseuxPoly._mul.<locals>.<genexpr>  s     /A!a%s   )r$  r"   r   r   r\  s         r   rE  PuiseuxPoly._mul  sD    "&++e"4e///EyyEM5==r   c                    U R                  U R                  U R                  U-  U R                  U R                  5      $ r   r*  r`  s     r   rF  PuiseuxPoly._mul_ground  ,    }}TYY		F(:DJJPPr   c                    U R                  U R                  U R                  U-  U R                  U R                  5      $ r   r*  r`  s     r   rT  PuiseuxPoly._div_ground  rq  r   c                   ^ TS:  d   eU R                   nUb  [        U4S jU 5       5      nU R                  U R                  U R                  T-  X R
                  5      $ )Nr   c              3  ,   >#    U  H	  oT-  v   M     g 7fr   rd   r   s     r   rw   (PuiseuxPoly._pow_pint.<locals>.<genexpr>  s     /Aa%   )rg   r"   r   r   r:   r   )r(   rB   rg   s    ` r   rM  PuiseuxPoly._pow_pint  sP    Avv

///EyyDIIqL%AAr   c                @    U R                  5       R                  U5      $ r   )rS  rM  rA   s     r   rN  PuiseuxPoly._pow_nint  s    yy{$$Q''r   c                H  ^ U R                   (       d  [        S5      eU R                  5       u  u  p#U R                  R                  nUR                  U5      (       d  [        S5      e[        U4S jU 5       5      nU R                  R                  X$R                  05      $ )Nz0Only monomials can be raised to a rational powerc              3  ,   >#    U  H	  oT-  v   M     g 7fr   rd   r   s     r   rw   ,PuiseuxPoly._pow_rational.<locals>.<genexpr>  s     +U!eUrw  )	r   r.  r>   r   r   is_oner"   r=   r%   )r(   rB   rg   r   r   s    `   r   rO  PuiseuxPoly._pow_rational  s|    ||OPP::<%!!}}U##OPP+U++yy""E::#677r   c                X   U R                   (       d  [        S5      eU R                  5       u  u  pU R                  R                  nUR
                  (       d!  UR                  U5      (       d  [        S5      e[        S U 5       5      nSU-  nU R                  R                  X05      $ )NzOnly terms can be invertedz"Cannot invert non-unit coefficientc              3  &   #    U  H  o* v   M	     g 7fr   rd   )rt   ri   s     r   rw   #PuiseuxPoly._inv.<locals>.<genexpr>  s     (%Qb%s   r   )	r   r.  r>   r   r   is_Fieldr~  r"   r=   )r(   rg   r   r   s       r   rS  PuiseuxPoly._inv  s    ||9::::<%!!v}}U';';ABB(%((E	yy""E>22r   c                    U R                   nUR                  U5      n0 nU R                  5        H9  u  pVXS   nU(       d  M  [        U5      nX==   S-  ss'   Xg-  U[	        U5      '   M;     U" U5      $ )zDifferentiate 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   rR   r   r   r"   )	r(   rS   r   r   r)   expvr   rB   r  s	            r   diffPuiseuxPoly.diff  sl     yyJJqM>>+KDAqJ	#i%( , Awr   rd   N)r:   r   r   r   rW   r9   )
r   r   r:   r   rg   r   r   r   rW   r9   rY   )r:   r   rg   r   r   r   rW   zBtuple[PolyElement, tuple[int, ...] | None, tuple[int, ...] | None])rg   tuple[int, ...]r   r   r   r   rW   tuple[Any, ...])rg   r  r   r   r   r   rW   r  )rW   zIterator[tuple[Any, ...]])rW   zlist[tuple[Any, ...]])rW   z%Iterator[tuple[tuple[Any, ...], Any]])rg   r  rW   r   )rW   r]   )rW   z!list[tuple[tuple[Any, ...], Any]])rW   rZ   )rW   r[   )r>   zdict[tuple[Any, ...], Any]r   r   rW   r9   )rW   r   rV   )r5   r9   rW   zOtuple[PolyElement, PolyElement, tuple[int, ...] | None, tuple[int, ...] | None])rW   r9   )r5   r   rW   r9   )r5   r9   rW   r9   )ra  r   rW   r9   r\   )rB   r   rW   r9   )rS   r9   rW   r9   )5r^   r_   r`   ra   rb   __annotations__r   classmethodr   r   r6   r   r   r   r   r   r   r   r   r   r>   propertyr   r   r=   r   r/   r$  r'  r+  r4  r7  r=  rB  rG  rJ  rP  rU  rX  r/  r0  r;  r<  rA  rE  rF  rT  rM  rN  rO  rS  r  rc   rd   r   r   r9   r9      sk   'R 
!!0 33 3 &	3
 #3 
3 3   &	
 # 
 
" // &/ #	/
 
L/ /b 11 '1 #	1
 
1 1 << '< #	<
 
< <"4 '! & ! !& !5.!56A!5	!5 !5F0%:4' 4'
4'lI""""""	""">7>77>QQB(8	3r   r9   N)r   rU   r   r   rW   z3tuple[PuiseuxRing, Unpack[tuple[PuiseuxPoly, ...]]])r:   r   rg   Iterable[int]rW   r   )rg   r  rh   r  rW   r  )rb   
__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   rk   rp   r|   r9   rd   r   r   <module>r     s{   & # " 3   ( ! "$*2'-8(Y" Y"xGG8t tr   