Ë
    7^(hn>  ã                   ó  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZ ddlmZmZmZmZmZ dd	lmZmZmZ dd
lmZ ddlmZ e G d„ dee«      «       Zd„ Ze G d„ de«      «       Z G d„ de«      Z ed„ «       Z!y)z1Implementation of :class:`PolynomialRing` class. é    ©ÚFreeModulePolyRing)ÚCompositeDomain)ÚFractionField)ÚRing)Úmonomial_keyÚbuild_product_order)ÚDMPÚDMF)ÚGeneratorsNeededÚPolynomialErrorÚCoercionFailedÚExactQuotientFailedÚNotReversible)Údict_from_basicÚbasic_from_dictÚ_dict_reorder)Úpublic)Úiterablec                   óÐ   — 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„ 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„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!d„ Z"d „ Z#d!„ Z$y")#ÚPolynomialRingBasezí
    Base class for generalized polynomial rings.

    This base class should be used for uniform access to generalized polynomial
    rings. Subclasses only supply information about the element storage etc.

    Do not instantiate.
    TÚgrevlexc                 ój  — |st        d«      ‚t        |«      dz
  }t        |«      | _        | j                  j	                  ||«      | _        | j                  j                  ||«      | _        |x| _        | _        |x| _        | _	        |j                  dt        | j                  «      «      | _        y )Nzgenerators not specifiedé   Úorder)r   ÚlenÚngensÚdtypeÚzeroÚoneÚdomainÚdomÚsymbolsÚgensÚgetr   Údefault_orderr   )Úselfr"   r$   ÚoptsÚlevs        úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/domains/old_polynomialring.pyÚ__init__zPolynomialRingBase.__init__!   sŽ   € ÙÜ"Ð#=Ó>Ð>ä�$‹i˜!‰mˆÜ˜“YˆŒ
à—J‘J—O‘O C¨Ó-ˆŒ	Ø—:‘:—>‘> # sÓ+ˆŒà!$Ð$ˆŒ�d”hØ#'Ð'ˆŒ�t”yà—X‘X˜g¤|°D×4FÑ4FÓ'GÓHˆ�
ó    c                 óV   —  | j                   |g| j                  ¢­d| j                  iŽS )z0Return a new polynomial ring with given domain. r   )Ú	__class__r$   r   )r'   r"   s     r*   Ú
set_domainzPolynomialRingBase.set_domain0   s%   € àˆt�~‰~˜cÐ@ D§I¡IÒ@°T·Z±ZÑ@Ð@r,   c                 óh   — | j                  || j                  t        | j                  «      dz
  «      S ©Nr   )r   r"   r   r$   ©r'   Úelements     r*   ÚnewzPolynomialRingBase.new4   s&   € Ø�z‰z˜' 4§8¡8¬S°·±«^¸aÑ-?Ó@Ð@r,   c                 ó8   — | j                   j                  |«      S ©N)r    Ú
ground_newr2   s     r*   Ú_ground_newzPolynomialRingBase._ground_new7   s   € Ø�x‰x×"Ñ" 7Ó+Ð+r,   c                 óp   — t        j                  |t        | j                  «      dz
  | j                  «      S r1   )r
   Ú	from_dictr   r$   r"   r2   s     r*   Ú
_from_dictzPolynomialRingBase._from_dict:   s&   € Ü�}‰}˜W¤c¨$¯)©)£n°qÑ&8¸$¿(¹(ÓCÐCr,   c                 óè   — t        | j                  «      }|| j                  k7  rd|z   nd}t        | j                  «      dz   dj	                  t        t         | j                  «      «      z   |z   dz   S )Nz order=Ú ú[ú,ú])Ústrr   r&   r"   ÚjoinÚmapr$   )r'   Ús_orderÚorderstrs      r*   Ú__str__zPolynomialRingBase.__str__=   sb   € Ü�d—j‘j“/ˆà$+¨t×/AÑ/AÒ$AˆI˜ÒÀrð 	ä�4—8‘8‹}˜sÑ" S§X¡X¬c´#°t·y±yÓ.AÓ%BÑBÀXÑMÐPSÑSÐSr,   c                 óš   — t        | j                  j                  | j                  | j                  | j
                  | j                  f«      S r6   )Úhashr.   Ú__name__r   r"   r$   r   ©r'   s    r*   Ú__hash__zPolynomialRingBase.__hash__C   s9   € Ü�T—^‘^×,Ñ,¨d¯j©j¸$¿(¹(Ø—Y‘Y §
¡
ð,ó -ð 	-r,   c                 óú   — t        |t        «      xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j
                  |j
                  k(  S )z0Returns ``True`` if two domains are equivalent. )Ú
isinstancer   r   r"   r$   r   )r'   Úothers     r*   Ú__eq__zPolynomialRingBase.__eq__G   sk   € ä˜%Ô!3Ó4ò BØ�J‰J˜%Ÿ+™+Ñ%òBØ*.¯(©(°e·i±iÑ*?òBà�I‰I˜Ÿ™Ñ#òBà(,¯
©
°e·k±kÑ(Að	Br,   c                 óX   — | j                  | j                  j                  ||«      «      S ©z.Convert a Python ``int`` object to ``dtype``. ©r8   r"   Úconvert©ÚK1ÚaÚK0s      r*   Úfrom_ZZzPolynomialRingBase.from_ZZM   ó    € à�~‰~˜bŸf™fŸn™n¨Q°Ó3Ó4Ð4r,   c                 óX   — | j                  | j                  j                  ||«      «      S rQ   rR   rT   s      r*   Úfrom_ZZ_pythonz!PolynomialRingBase.from_ZZ_pythonQ   rY   r,   c                 óX   — | j                  | j                  j                  ||«      «      S ©z3Convert a Python ``Fraction`` object to ``dtype``. rR   rT   s      r*   Úfrom_QQzPolynomialRingBase.from_QQU   rY   r,   c                 óX   — | j                  | j                  j                  ||«      «      S r]   rR   rT   s      r*   Úfrom_QQ_pythonz!PolynomialRingBase.from_QQ_pythonY   rY   r,   c                 óX   — | j                  | j                  j                  ||«      «      S )z,Convert a GMPY ``mpz`` object to ``dtype``. rR   rT   s      r*   Úfrom_ZZ_gmpyzPolynomialRingBase.from_ZZ_gmpy]   rY   r,   c                 óX   — | j                  | j                  j                  ||«      «      S )z,Convert a GMPY ``mpq`` object to ``dtype``. rR   rT   s      r*   Úfrom_QQ_gmpyzPolynomialRingBase.from_QQ_gmpya   rY   r,   c                 óX   — | j                  | j                  j                  ||«      «      S )z.Convert a mpmath ``mpf`` object to ``dtype``. rR   rT   s      r*   Úfrom_RealFieldz!PolynomialRingBase.from_RealFielde   rY   r,   c                 óD   — | j                   |k(  r| j                  |«      S y)z'Convert a ``ANP`` object to ``dtype``. N)r"   r8   rT   s      r*   Úfrom_AlgebraicFieldz&PolynomialRingBase.from_AlgebraicFieldi   s!   € à�6‰6�RŠ<Ø—>‘> !Ó$Ð$ð r,   c           
      ód  ‡ ‡— ‰ j                   ‰j                  k(  ri‰ j                  ‰j                  k(  r ‰ t        |«      «      S ˆˆ fd„}‰ j	                  |j                  «       D ��ci c]  \  }}| ||«      “Œ c}}«      S t        |j                  «       ‰j                  ‰ j                   «      \  }}‰ j                  ‰j                  k7  r3|D �cg c](  }‰ j                  j                  |‰j                  «      ‘Œ* }}‰ j	                  t        t        ||«      «      «      S c c}}w c c}w )z/Convert a ``PolyElement`` object to ``dtype``. c                 óP   •— ‰j                   j                  | ‰j                   «      S r6   )r"   Úconvert_from)ÚcrW   rU   s    €€r*   ú<lambda>z8PolynomialRingBase.from_PolynomialRing.<locals>.<lambda>t   s   ø€ ¨¯©×(;Ñ(;¸A¸r¿v¹vÓ(F€ r,   )
r$   r#   r"   Údictr;   Úitemsr   Úto_dictrS   Úzip)rU   rV   rW   Úconvert_domÚmrl   ÚmonomsÚcoeffss   ` `     r*   Úfrom_PolynomialRingz&PolynomialRingBase.from_PolynomialRingn   sà   ù€ à�7‰7�b—j‘jÒ Ø�v‰v˜Ÿ™ÒÙœ$˜q›'“{Ð"äF�Ø—}‘}ÀAÇGÁGÃI×%N¹D¸A¸q a©°Q«Ñ&7Ó%NÓOÐOä*¨1¯9©9«;¸¿
¹
ÀBÇGÁGÓL‰NˆF�Fà�v‰v˜Ÿ™ÒØ>DÖF¸˜2Ÿ6™6Ÿ>™>¨!¨R¯V©VÕ4ÐF�ÐFà—=‘=¤¤c¨&°&Ó&9Ó!:Ó;Ð;ùó &Oùò
 Gs   Á*D'
Ã-D-c                 ó  — | j                   |j                   k(  rJ| j                  |j                  k7  r|j                  | j                  «      } | |j                  «       «      S t	        |j                  «       |j                   | j                   «      \  }}| j                  |j                  k7  r3|D �cg c](  }| j                  j                  ||j                  «      ‘Œ* }} | t        t        ||«      «      «      S c c}w )z'Convert a ``DMP`` object to ``dtype``. )r$   r"   rS   Úto_listr   rp   rn   rq   )rU   rV   rW   rt   ru   rl   s         r*   Úfrom_GlobalPolynomialRingz,PolynomialRingBase.from_GlobalPolynomialRing~   s·   € à�7‰7�b—g‘gÒØ�v‰v˜Ÿ™ÒØ—I‘I˜bŸf™fÓ%�Ù�a—i‘i“k“?Ð"ä*¨1¯9©9«;¸¿¹ÀÇÁÓI‰NˆF�Fà�v‰v˜Ÿ™ÒØ>DÖF¸˜2Ÿ6™6Ÿ>™>¨!¨R¯V©VÕ4ÐF�ÐFá”dœ3˜v vÓ.Ó/Ó0Ð0ùò Gs   Â3-C=c                 óB   — t        | j                  g| j                  ¢­Ž S )z*Returns a field associated with ``self``. )r   r"   r$   rJ   s    r*   Ú	get_fieldzPolynomialRingBase.get_fieldŒ   s   € ä˜TŸX™XÐ2¨¯	©	Ò2Ð2r,   c                 ó   — t        d«      ‚)z*Returns a polynomial ring, i.e. ``K[X]``. únested domains not allowed©ÚNotImplementedError©r'   r$   s     r*   Ú	poly_ringzPolynomialRingBase.poly_ring�   ó   € ä!Ð">Ó?Ð?r,   c                 ó   — t        d«      ‚)z)Returns a fraction field, i.e. ``K(X)``. r}   r~   r€   s     r*   Ú
frac_fieldzPolynomialRingBase.frac_field”   r‚   r,   c                 ó~   — 	 | j                  | j                  |«      S # t        t        f$ r t	        d|z  «      ‚w xY w)Nz%s is not a unit)Úexquor    r   ÚZeroDivisionErrorr   ©r'   rV   s     r*   ÚrevertzPolynomialRingBase.revert˜   sB   € ð	8Ø—:‘:˜dŸh™h¨Ó*Ð*øÜ#Ô%6Ð7ò 	8ÜÐ 2°QÑ 6Ó7Ð7ð	8ús   ‚ ž<c                 ó$   — |j                  |«      S )z!Extended GCD of ``a`` and ``b``. )Úgcdex©r'   rV   Úbs      r*   r‹   zPolynomialRingBase.gcdexž   s   € à�w‰w�q‹zÐr,   c                 ó$   — |j                  |«      S )z Returns GCD of ``a`` and ``b``. )ÚgcdrŒ   s      r*   r�   zPolynomialRingBase.gcd¢   ó   € à�u‰u�Q‹xˆr,   c                 ó$   — |j                  |«      S )z Returns LCM of ``a`` and ``b``. )ÚlcmrŒ   s      r*   r’   zPolynomialRingBase.lcm¦   r�   r,   c                 óV   — | j                  | j                  j                  |«      «      S )zReturns factorial of ``a``. )r   r"   Ú	factorialrˆ   s     r*   r”   zPolynomialRingBase.factorialª   s    € à�z‰z˜$Ÿ(™(×,Ñ,¨QÓ/Ó0Ð0r,   c                 ó   — t         ‚)z 
        For internal use by the modules class.

        Convert an iterable of elements of this ring into a sparse distributed
        module element.
        r~   ©r'   Úvr   s      r*   Ú_vector_to_sdmz!PolynomialRingBase._vector_to_sdm®   s
   € ô "Ð!r,   c                 ó¨   — ddl m}  ||«      }t        |«      D �cg c]  }i ‘Œ }}|j                  «       D ]  \  }}|||d      |dd <   Œ |S c c}w )zHelper for _sdm_to_vector.r   )Úsdm_to_dictr   N)Úsympy.polys.distributedmodulesrš   Úrangero   )	r'   ÚsÚnrš   ÚdicÚ_ÚresÚkr—   s	            r*   Ú_sdm_to_dicszPolynomialRingBase._sdm_to_dics·   s`   € å>Ù˜!‹nˆÜ  ›8Ö$�aŠrÐ$ˆÐ$Ø—I‘I“Kò 	!‰DˆAˆqØ ˆC��!‘‰I�a˜˜�eÒð	!àˆ
ùò %s   œ	Ac                 ó\   — | j                  ||«      }|D �cg c]
  } | |«      ‘Œ c}S c c}w )aÝ  
        For internal use by the modules class.

        Convert a sparse distributed module into a list of length ``n``.

        Examples
        ========

        >>> from sympy import QQ, ilex
        >>> from sympy.abc import x, y
        >>> R = QQ.old_poly_ring(x, y, order=ilex)
        >>> L = [((1, 1, 1), QQ(1)), ((0, 1, 0), QQ(1)), ((0, 0, 1), QQ(2))]
        >>> R._sdm_to_vector(L, 2)
        [DMF([[1], [2, 0]], [[1]], QQ), DMF([[1, 0], []], [[1]], QQ)]
        )r£   )r'   r�   rž   ÚdicsÚxs        r*   Ú_sdm_to_vectorz!PolynomialRingBase._sdm_to_vectorÀ   s.   € ð  × Ñ   AÓ&ˆà!%Ö&˜A‘�Q•Ò&Ð&ùÒ&s   —)c                 ó   — t        | |«      S )zñ
        Generate a free module of rank ``rank`` over ``self``.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import QQ
        >>> QQ.old_poly_ring(x).free_module(2)
        QQ[x]**2
        r   )r'   Úranks     r*   Úfree_modulezPolynomialRingBase.free_moduleÔ   s   € ô " $¨Ó-Ð-r,   N)%rI   Ú
__module__Ú__qualname__Ú__doc__Úhas_assoc_RingÚhas_assoc_Fieldr&   r+   r/   r4   r8   r;   rF   rK   rO   rX   r[   r^   r`   rb   rd   rf   rh   rv   ry   r{   r�   r„   r‰   r‹   r�   r’   r”   r˜   r£   r§   rª   © r,   r*   r   r      s¶   „ ñð €NØ€Oà€MòIòAòAò,òDòTò-òBò5ò5ò5ò5ò5ò5ò5ò%ò
<ò 1ò3ò@ò@ò8òòòò1ò"òò'ó(.r,   r   c                 ó¨   — ddl m} i }t        | «      D ]4  \  }}|j                  «       j	                  «       D ]  \  }}|||f|z   <   Œ Œ6  |||«      S )z=Helper method for common code in Global and Local poly rings.r   )Úsdm_from_dict)r›   r²   Ú	enumeraterp   ro   )r—   r   r²   ÚdÚiÚeÚkeyÚvalues           r*   Ú_vector_to_sdm_helperr¹   ã   sa   € å<Ø
€AÜ˜!“ò "‰ˆˆ1ØŸ)™)›+×+Ñ+Ó-ò 	"‰JˆC�Ø!ˆAˆqˆd�S‰jŠMñ	"ð"ñ ˜˜EÓ"Ð"r,   c                   óR   — e Zd ZdZdxZZeZd„ Zd„ Z	d„ Z
d„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zy)ÚGlobalPolynomialRingz*A true polynomial ring, with objects DMP. Tc                 óf  — t        |t        «      r7t        j                  |t	        | j
                  «      dz
  | j                  «      S || j                  v r*| j                  | j                  j                  |«      «      S | j                  || j                  t	        | j
                  «      dz
  «      S r1   )
rM   rn   r
   r:   r   r$   r"   r8   rS   r   r2   s     r*   r4   zGlobalPolynomialRing.newô   s€   € Ü�gœtÔ$Ü—=‘= ¬#¨d¯i©i«.¸1Ñ*<¸d¿h¹hÓGÐGØ˜Ÿ™Ñ Ø×#Ñ# D§H¡H×$4Ñ$4°WÓ$=Ó>Ð>à—:‘:˜g t§x¡x´°T·Y±Y³À!Ñ1CÓDÐDr,   c                 óx   — |j                  «       j                  r | j                  |j                  «       |«      S y)a  
        Convert a ``DMF`` object to ``DMP``.

        Examples
        ========

        >>> from sympy.polys.polyclasses import DMP, DMF
        >>> from sympy.polys.domains import ZZ
        >>> from sympy.abc import x

        >>> f = DMF(([ZZ(1), ZZ(1)], [ZZ(1)]), ZZ)
        >>> K = ZZ.old_frac_field(x)

        >>> F = ZZ.old_poly_ring(x).from_FractionField(f, K)

        >>> F == DMP([ZZ(1), ZZ(1)], ZZ)
        True
        >>> type(F)  # doctest: +SKIP
        <class 'sympy.polys.polyclasses.DMP_Python'>

        N)ÚdenomÚis_onery   ÚnumerrT   s      r*   Úfrom_FractionFieldz'GlobalPolynomialRing.from_FractionFieldü   s1   € ð, �7‰7‹9×ÒØ×/Ñ/°·±³	¸2Ó>Ð>ð r,   c                 óJ   — t        |j                  «       g| j                  ¢­Ž S ©z!Convert ``a`` to a SymPy object. )r   Úto_sympy_dictr$   rˆ   s     r*   Úto_sympyzGlobalPolynomialRing.to_sympy  s   € ä˜qŸ™Ó0Ð=°4·9±9Ò=Ð=r,   c                 ó<  — 	 t        || j                  ¬«      \  }}|j	                  «       D ]#  \  }}| j
                  j                  |«      ||<   Œ% t        j                  || j                  dz
  | j
                  «      S # t        $ r t        d|›d| ›�«      ‚w xY w)ú)Convert SymPy's expression to ``dtype``. ©r$   zCannot convert z	 to type r   )
r   r$   r   r   ro   r"   Ú
from_sympyr
   r:   r   )r'   rV   Úrepr    r¢   r—   s         r*   rÉ   zGlobalPolynomialRing.from_sympy  s“   € ð	MÜ$ Q¨T¯Y©YÔ7‰FˆC�ð —I‘I“Kò 	,‰DˆAˆqØ—X‘X×(Ñ(¨Ó+ˆC�ŠFð	,ô �}‰}˜S $§*¡*¨q¡.°$·(±(Ó;Ð;øô ò 	MÝ Â1ÁdÐ!KÓLÐLð	Mús   ‚B  Â Bc                 óT   — | j                   j                  |j                  «       «      S )z'Returns True if ``LC(a)`` is positive. )r"   Úis_positiveÚLCrˆ   s     r*   rÌ   z GlobalPolynomialRing.is_positive%  ó   € à�x‰x×#Ñ# A§D¡D£FÓ+Ð+r,   c                 óT   — | j                   j                  |j                  «       «      S )z'Returns True if ``LC(a)`` is negative. )r"   Úis_negativerÍ   rˆ   s     r*   rÐ   z GlobalPolynomialRing.is_negative)  rÎ   r,   c                 óT   — | j                   j                  |j                  «       «      S )z+Returns True if ``LC(a)`` is non-positive. )r"   Úis_nonpositiverÍ   rˆ   s     r*   rÒ   z#GlobalPolynomialRing.is_nonpositive-  ó   € à�x‰x×&Ñ& q§t¡t£vÓ.Ð.r,   c                 óT   — | j                   j                  |j                  «       «      S )z+Returns True if ``LC(a)`` is non-negative. )r"   Úis_nonnegativerÍ   rˆ   s     r*   rÕ   z#GlobalPolynomialRing.is_nonnegative1  rÓ   r,   c                 ó   — t        ||«      S )aG  
        Examples
        ========

        >>> from sympy import lex, QQ
        >>> from sympy.abc import x, y
        >>> R = QQ.old_poly_ring(x, y)
        >>> f = R.convert(x + 2*y)
        >>> g = R.convert(x * y)
        >>> R._vector_to_sdm([f, g], lex)
        [((1, 1, 1), 1), ((0, 1, 0), 1), ((0, 0, 1), 2)]
        )r¹   r–   s      r*   r˜   z#GlobalPolynomialRing._vector_to_sdm5  s   € ô % Q¨Ó.Ð.r,   N)rI   r«   r¬   r­   Úis_PolynomialRingÚis_Polyr
   r   r4   rÁ   rÅ   rÉ   rÌ   rÐ   rÒ   rÕ   r˜   r°   r,   r*   r»   r»   í   sC   „ á4à"&Ð&Ð˜Ø€EòEò?ò2>ò
<ò,ò,ò/ò/ó/r,   r»   c                   ó>   — e Zd ZdZeZd„ Zd„ Zd„ Zd„ Z	d„ Z
d„ Zd„ Zy	)
ÚGeneralizedPolynomialRingz1A generalized polynomial ring, with objects DMF. c                 ó8  — | j                  || j                  t        | j                  «      dz
  «      }|j	                  «       j                  | j                  ¬«      d   d   dt        | j                  «      z  k7  rddlm} t        d ||«      ›d| ›�«      ‚|S )z4Construct an element of ``self`` domain from ``a``. r   ©r   r   ©r   )Ússtrzdenominator z not allowed in )
r   r"   r   r$   r¾   Útermsr   Úsympy.printing.strrÞ   r   )r'   rV   r¡   rÞ   s       r*   r4   zGeneralizedPolynomialRing.newJ  s�   € à�j‰j˜˜DŸH™H¤c¨$¯)©)£n°qÑ&8Ó9ˆð �9‰9‹;×Ñ 4§:¡:ÐÓ.¨qÑ1°!Ñ4¸¼SÀÇÁ»^Ñ8KÒKÝ/Ý Ù$(¨¥I©tð"5ó 6ð 6àˆ
r,   c                 óÖ   — 	 | j                  |«      }|j                  «       j                  | j                  ¬«      d   d   dt        | j                  «      z  k(  S # t        $ r Y yw xY w)NFrÜ   r   rÝ   )rS   r   r¾   rß   r   r   r$   rˆ   s     r*   Ú__contains__z&GeneralizedPolynomialRing.__contains__U  sa   € ð	Ø—‘˜Q“ˆAð �w‰w‹y�‰ T§Z¡ZˆÓ0°Ñ3°AÑ6¸$¼sÀ4Ç9Á9»~Ñ:MÑMÐMøô ò 	Ùð	ús   ‚A Á	A(Á'A(c                 óÌ   — t        |j                  «       j                  «       g| j                  ¢­Ž t        |j	                  «       j                  «       g| j                  ¢­Ž z  S rÃ   )r   rÀ   rÄ   r$   r¾   rˆ   s     r*   rÅ   z"GeneralizedPolynomialRing.to_sympy\  sN   € ä §¡£	× 7Ñ 7Ó 9ÐF¸D¿I¹IÒFÜ §¡£	× 7Ñ 7Ó 9ÐF¸D¿I¹IÒFñGð 	Hr,   c                 ó˜  — |j                  «       \  }}t        || j                  ¬«      \  }}t        || j                  ¬«      \  }}|j                  «       D ]#  \  }}| j                  j                  |«      ||<   Œ% |j                  «       D ]#  \  }}| j                  j                  |«      ||<   Œ%  | ||f«      j                  «       S )rÇ   rÈ   )Úas_numer_denomr   r$   ro   r"   rÉ   Úcancel)	r'   rV   ÚpÚqÚnumr    Údenr¢   r—   s	            r*   rÉ   z$GeneralizedPolynomialRing.from_sympya  sº   € à×ÑÓ!‰ˆˆ1ä  ¨¯©Ô3‰ˆˆQÜ  ¨¯©Ô3‰ˆˆQà—I‘I“Kò 	,‰DˆAˆqØ—X‘X×(Ñ(¨Ó+ˆC�ŠFð	,ð —I‘I“Kò 	,‰DˆAˆqØ—X‘X×(Ñ(¨Ó+ˆC�ŠFð	,ñ �S˜#�JÓ×&Ñ&Ó(Ð(r,   c                 ó”   — ||z  }	 | j                  |j                  |j                  f«      }|S # t        $ r t	        ||| «      ‚w xY w)z#Exact quotient of ``a`` and ``b``. )r4   ré   rê   r   r   )r'   rV   r�   Úrs       r*   r†   zGeneralizedPolynomialRing.exquop  sS   € ð �‰Eˆð	2Ø—‘˜!Ÿ%™% §¡˜Ó(ˆAð ˆøô ò 	2Ü% a¨¨DÓ1Ð1ð	2ús	   ‡'0 °Ac                 ó~   — | j                  «       j                  ||«      } | |j                  |j                  f«      S r6   )r{   rÁ   ré   rê   )rU   rV   rW   Údmfs       r*   rÁ   z,GeneralizedPolynomialRing.from_FractionField}  s2   € Ø�l‰l‹n×/Ñ/°°2Ó6ˆÙ�3—7‘7˜CŸG™GÐ$Ó%Ð%r,   c                 óì   — | j                   j                  «       }|D ]  }||j                  «       z  }Œ t        |D �cg c]&  }|j                  «       |z  |j                  «       z  ‘Œ( c}|«      S c c}w )a  
        Turn an iterable into a sparse distributed module.

        Note that the vector is multiplied by a unit first to make all entries
        polynomials.

        Examples
        ========

        >>> from sympy import ilex, QQ
        >>> from sympy.abc import x, y
        >>> R = QQ.old_poly_ring(x, y, order=ilex)
        >>> f = R.convert((x + 2*y) / (1 + x))
        >>> g = R.convert(x * y)
        >>> R._vector_to_sdm([f, g], ilex)
        [((0, 0, 1), 2), ((0, 1, 0), 1), ((1, 1, 1), 1), ((1,
          2, 1), 1)]
        )r    rÀ   r¾   r¹   )r'   r—   r   Úur¦   s        r*   r˜   z(GeneralizedPolynomialRing._vector_to_sdm�  sb   € ð( �H‰H�N‰NÓˆØò 	ˆAØ�—‘“‰N‰Að	ä$ÀQÖ%GÀ a§g¡g£i°¡k°!·'±'³)Ó&;Ò%GÈÓOÐOùÒ%Gs   ¾+A1N)rI   r«   r¬   r­   r   r   r4   râ   rÅ   rÉ   r†   rÁ   r˜   r°   r,   r*   rÚ   rÚ   E  s0   „ Ù;à€Eò	òNòHò
)òò&óPr,   rÚ   c                 óä   — |j                  dt        j                  «      }t        |«      rt	        ||«      }t        |«      }||d<   |j                  rt        | g|¢­i |¤ŽS t        | g|¢­i |¤ŽS )ay  
    Create a generalized multivariate polynomial ring.

    A generalized polynomial ring is defined by a ground field `K`, a set
    of generators (typically `x_1, \ldots, x_n`) and a monomial order `<`.
    The monomial order can be global, local or mixed. In any case it induces
    a total ordering on the monomials, and there exists for every (non-zero)
    polynomial `f \in K[x_1, \ldots, x_n]` a well-defined "leading monomial"
    `LM(f) = LM(f, >)`. One can then define a multiplicative subset
    `S = S_> = \{f \in K[x_1, \ldots, x_n] | LM(f) = 1\}`. The generalized
    polynomial ring corresponding to the monomial order is
    `R = S^{-1}K[x_1, \ldots, x_n]`.

    If `>` is a so-called global order, that is `1` is the smallest monomial,
    then we just have `S = K` and `R = K[x_1, \ldots, x_n]`.

    Examples
    ========

    A few examples may make this clearer.

    >>> from sympy.abc import x, y
    >>> from sympy import QQ

    Our first ring uses global lexicographic order.

    >>> R1 = QQ.old_poly_ring(x, y, order=(("lex", x, y),))

    The second ring uses local lexicographic order. Note that when using a
    single (non-product) order, you can just specify the name and omit the
    variables:

    >>> R2 = QQ.old_poly_ring(x, y, order="ilex")

    The third and fourth rings use a mixed orders:

    >>> o1 = (("ilex", x), ("lex", y))
    >>> o2 = (("lex", x), ("ilex", y))
    >>> R3 = QQ.old_poly_ring(x, y, order=o1)
    >>> R4 = QQ.old_poly_ring(x, y, order=o2)

    We will investigate what elements of `K(x, y)` are contained in the various
    rings.

    >>> L = [x, 1/x, y/(1 + x), 1/(1 + y), 1/(1 + x*y)]
    >>> test = lambda R: [f in R for f in L]

    The first ring is just `K[x, y]`:

    >>> test(R1)
    [True, False, False, False, False]

    The second ring is R1 localised at the maximal ideal (x, y):

    >>> test(R2)
    [True, False, True, True, True]

    The third ring is R1 localised at the prime ideal (x):

    >>> test(R3)
    [True, False, True, False, True]

    Finally the fourth ring is R1 localised at `S = K[x, y] \setminus yK[y]`:

    >>> test(R4)
    [True, False, False, True, False]
    r   )r%   rÚ   r&   r   r	   r   Ú	is_globalr»   )r"   r$   r(   r   s       r*   ÚPolynomialRingró   ›  ss   € ðL �H‰H�WÔ7×EÑEÓF€EÜ�„Ü# E¨4Ó0ˆÜ˜Ó€EØ€Dˆ�Mà‡‚Ü# CÐ7¨$Ò7°$Ñ7Ð7ä(¨Ð<¨tÒ<°tÑ<Ð<r,   N)"r­   Úsympy.polys.agca.modulesr   Ú#sympy.polys.domains.compositedomainr   Ú%sympy.polys.domains.old_fractionfieldr   Úsympy.polys.domains.ringr   Úsympy.polys.orderingsr   r	   Úsympy.polys.polyclassesr
   r   Úsympy.polys.polyerrorsr   r   r   r   r   Úsympy.polys.polyutilsr   r   r   Úsympy.utilitiesr   Úsympy.utilities.iterablesr   r   r¹   r»   rÚ   ró   r°   r,   r*   ú<module>rþ      s    ðÙ 7õ 8Ý ?Ý ?Ý )ß Cß ,÷<õ <ç QÑ QÝ "Ý .ð ôN.˜˜ó N.ó ðN.òb#ð ôT/Ð-ó T/ó ðT/ônSPÐ 2ô SPðl ñN=ó ñN=r,   