
    \hn>                        S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
Jr  SSKJrJr  SSKJrJrJrJrJr  SS	KJrJrJr  SS
KJr  SSKJr  \ " S S\\5      5       rS r\ " S S\5      5       r " S S\5      r \S 5       r!g)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                       \ rS rSrSrSrSrSrS rS r	S r
S rS	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S  r#S! r$S" r%S#r&g$)%PolynomialRingBase   z
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                 p   U(       d  [        S5      e[        U5      S-
  n[        U5      U l        U R                  R	                  XA5      U l        U R                  R                  XA5      U l        U=U l        U l        U=U l        U l	        UR                  S[        U R                  5      5      U l        g )Nzgenerators not specified   order)r   lenngensdtypezeroonedomaindomsymbolsgensgetr   default_orderr   )selfr#   r%   optslevs        ^/var/www/auris/envauris/lib/python3.13/site-packages/sympy/polys/domains/old_polynomialring.py__init__PolynomialRingBase.__init__!   s    "#=>>$i!mY
JJOOC-	::>>#+!$$dh#''tyXXg|D4F4F'GH
    c                 V    U R                   " U/U R                  Q7SU R                  06$ )z0Return a new polynomial ring with given domain. r   )	__class__r%   r   )r(   r#   s     r+   
set_domainPolynomialRingBase.set_domain0   s#    ~~c@DII@TZZ@@r.   c                 f    U R                  XR                  [        U R                  5      S-
  5      $ Nr   )r   r#   r   r%   r(   elements     r+   newPolynomialRingBase.new4   s$    zz'88S^a-?@@r.   c                 8    U R                   R                  U5      $ N)r!   
ground_newr5   s     r+   _ground_newPolynomialRingBase._ground_new7   s    xx""7++r.   c                 r    [         R                  " U[        U R                  5      S-
  U R                  5      $ r4   )r
   	from_dictr   r%   r#   r5   s     r+   
_from_dictPolynomialRingBase._from_dict:   s&    }}Wc$))nq&8$((CCr.   c                     [        U R                  5      nXR                  :w  a  SU-   OSn[        U R                  5      S-   SR	                  [        [         U R                  5      5      -   U-   S-   $ )Nz order= [,])strr   r'   r#   joinmapr%   )r(   s_orderorderstrs      r+   __str__PolynomialRingBase.__str__=   s`    djj/$+/A/A$AIr 	488}s"SXXc#tyy.A%BBXMPSSSr.   c                     [        U R                  R                  U R                  U R                  U R
                  U R                  45      $ r:   )hashr0   __name__r   r#   r%   r   r(   s    r+   __hash__PolynomialRingBase.__hash__C   s9    T^^,,djj$((YY

, - 	-r.   c                 "   [        U[        5      =(       ay    U R                  UR                  :H  =(       aY    U R                  UR                  :H  =(       a9    U R                  UR                  :H  =(       a    U R
                  UR
                  :H  $ )z0Returns ``True`` if two domains are equivalent. )
isinstancer   r   r#   r%   r   )r(   others     r+   __eq__PolynomialRingBase.__eq__G   sk    %!34 BJJ%++%B*.((eii*?BII#B(,

ekk(A	Br.   c                 V    U R                  U R                  R                  X5      5      $ z.Convert a Python ``int`` object to ``dtype``. r<   r#   convertK1aK0s      r+   from_ZZPolynomialRingBase.from_ZZM       ~~bffnnQ344r.   c                 V    U R                  U R                  R                  X5      5      $ rZ   r[   r]   s      r+   from_ZZ_python!PolynomialRingBase.from_ZZ_pythonQ   rc   r.   c                 V    U R                  U R                  R                  X5      5      $ z3Convert a Python ``Fraction`` object to ``dtype``. r[   r]   s      r+   from_QQPolynomialRingBase.from_QQU   rc   r.   c                 V    U R                  U R                  R                  X5      5      $ rh   r[   r]   s      r+   from_QQ_python!PolynomialRingBase.from_QQ_pythonY   rc   r.   c                 V    U R                  U R                  R                  X5      5      $ )z,Convert a GMPY ``mpz`` object to ``dtype``. r[   r]   s      r+   from_ZZ_gmpyPolynomialRingBase.from_ZZ_gmpy]   rc   r.   c                 V    U R                  U R                  R                  X5      5      $ )z,Convert a GMPY ``mpq`` object to ``dtype``. r[   r]   s      r+   from_QQ_gmpyPolynomialRingBase.from_QQ_gmpya   rc   r.   c                 V    U R                  U R                  R                  X5      5      $ )z.Convert a mpmath ``mpf`` object to ``dtype``. r[   r]   s      r+   from_RealField!PolynomialRingBase.from_RealFielde   rc   r.   c                 F    U R                   U:X  a  U R                  U5      $ g)z'Convert a ``ANP`` object to ``dtype``. N)r#   r<   r]   s      r+   from_AlgebraicField&PolynomialRingBase.from_AlgebraicFieldi   s!    66R<>>!$$ r.   c           
      p  ^ ^ T R                   TR                  :X  al  T R                  TR                  :X  a  T " [        U5      5      $ UU 4S jnT R	                  UR                  5        VVs0 s H  u  pEXC" U5      _M     snn5      $ [        UR                  5       TR                  T R                   5      u  pgT R                  TR                  :w  a6  U Vs/ s H)  nT R                  R                  UTR                  5      PM+     nnT R	                  [        [        Xg5      5      5      $ s  snnf s  snf )z/Convert a ``PolyElement`` object to ``dtype``. c                 P   > TR                   R                  U TR                   5      $ r:   )r#   convert_from)cr`   r^   s    r+   <lambda>8PolynomialRingBase.from_PolynomialRing.<locals>.<lambda>t   s    (;(;Arvv(Fr.   )
r%   r$   r#   dictr@   itemsr   to_dictr\   zip)r^   r_   r`   convert_dommr}   monomscoeffss   ` `     r+   from_PolynomialRing&PolynomialRingBase.from_PolynomialRingn   s    77bjj vv$q'{"F}}AGGI%NIDAaQ&7I%NOO*199;

BGGLNFvv>DFf266>>!RVV4fF==c&&9!:;; &O
 Gs   -D-
0D3c                    U R                   UR                   :X  aK  U R                  UR                  :w  a  UR                  U R                  5      nU " UR                  5       5      $ [	        UR                  5       UR                   U R                   5      u  p4U R                  UR                  :w  a4  U Vs/ s H'  oPR                  R                  XRR                  5      PM)     nnU " [        [        X45      5      5      $ s  snf )z'Convert a ``DMP`` object to ``dtype``. )r%   r#   r\   to_listr   r   r   r   )r^   r_   r`   r   r   r}   s         r+   from_GlobalPolynomialRing,PolynomialRingBase.from_GlobalPolynomialRing~   s    77bggvvIIbff%aiik?"*199;INFvv>DFf66>>!VV4fFd3v./00 Gs   5.C?c                 B    [        U R                  /U R                  Q76 $ )z*Returns a field associated with ``self``. )r   r#   r%   rQ   s    r+   	get_fieldPolynomialRingBase.get_field   s    TXX2		22r.   c                     [        S5      e)z*Returns a polynomial ring, i.e. ``K[X]``. nested domains not allowedNotImplementedErrorr(   r%   s     r+   	poly_ringPolynomialRingBase.poly_ring       !">??r.   c                     [        S5      e)z)Returns a fraction field, i.e. ``K(X)``. r   r   r   s     r+   
frac_fieldPolynomialRingBase.frac_field   r   r.   c                      U R                  U R                  U5      $ ! [        [        4 a    [	        SU-  5      ef = f)Nz%s is not a unit)exquor!   r   ZeroDivisionErrorr   r(   r_   s     r+   revertPolynomialRingBase.revert   sB    	8::dhh**#%67 	8 2Q 677	8s    =c                 $    UR                  U5      $ )z!Extended GCD of ``a`` and ``b``. )gcdexr(   r_   bs      r+   r   PolynomialRingBase.gcdex   s    wwqzr.   c                 $    UR                  U5      $ )z Returns GCD of ``a`` and ``b``. )gcdr   s      r+   r   PolynomialRingBase.gcd       uuQxr.   c                 $    UR                  U5      $ )z Returns LCM of ``a`` and ``b``. )lcmr   s      r+   r   PolynomialRingBase.lcm   r   r.   c                 V    U R                  U R                  R                  U5      5      $ )zReturns factorial of ``a``. )r   r#   	factorialr   s     r+   r   PolynomialRingBase.factorial   s     zz$((,,Q/00r.   c                     [         e)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_sdm!PolynomialRingBase._vector_to_sdm   s
     "!r.   c                     SSK Jn  U" U5      n[        U5       Vs/ s H  n0 PM     nnUR                  5        H  u  pxXUS      USS '   M     U$ s  snf )zHelper for _sdm_to_vector.r   )sdm_to_dictr   N)sympy.polys.distributedmodulesr   ranger   )	r(   snr   dic_reskr   s	            r+   _sdm_to_dicsPolynomialRingBase._sdm_to_dics   sX    >!n 8$8ar8$IIKDA !Iae  
 %s   Ac                 ^    U R                  X5      nU Vs/ s H
  o@" U5      PM     sn$ s  snf )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_vector!PolynomialRingBase._sdm_to_vector   s0        &!%&AQ&&&s   *c                     [        X5      $ )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_modulePolynomialRingBase.free_module   s     "$--r.   )r#   r"   r%   r   r!   r   r$   r    N)'rP   
__module____qualname____firstlineno____doc__has_assoc_Ringhas_assoc_Fieldr'   r,   r1   r7   r<   r@   rL   rR   rW   ra   re   ri   rl   ro   rr   ru   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__ 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                     SSK Jn  0 n[        U 5       H4  u  pEUR                  5       R	                  5        H  u  pgXsU4U-   '   M     M6     U" X15      $ )z=Helper method for common code in Global and Local poly rings.r   )sdm_from_dict)r   r   	enumerater   r   )r   r   r   diekeyvalues           r+   _vector_to_sdm_helperr      sO    <
A!))+++-JC!qdSjM .  ""r.   c                   Z    \ rS rSrSrS=rr\rS r	S r
S rS rS rS	 rS
 rS rS rSrg)GlobalPolynomialRing   z*A true polynomial ring, with objects DMP. Tc                 r   [        U[        5      (       a8  [        R                  " U[	        U R
                  5      S-
  U R                  5      $ XR                  ;   a*  U R                  U R                  R                  U5      5      $ U R                  XR                  [	        U R
                  5      S-
  5      $ r4   )
rU   r   r
   r?   r   r%   r#   r<   r\   r   r5   s     r+   r7   GlobalPolynomialRing.new   s    gt$$==#dii.1*<dhhGG ##DHH$4$4W$=>>::gxxTYY!1CDDr.   c                     UR                  5       R                  (       a   U R                  UR                  5       U5      $ g)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_oner   numerr]   s      r+   from_FractionField'GlobalPolynomialRing.from_FractionField   s1    , 779//	2>> r.   c                 J    [        UR                  5       /U R                  Q76 $ z!Convert ``a`` to a SymPy object. )r   to_sympy_dictr%   r   s     r+   to_sympyGlobalPolynomialRing.to_sympy  s    q0=499==r.   c                 8    [        XR                  S9u  p#UR	                  5        H"  u  pEU R
                  R                  U5      X$'   M$     [        R                  " X R                  S-
  U R
                  5      $ ! [         a    [        SU< SU < 35      ef = f))Convert SymPy's expression to ``dtype``. r%   zCannot convert z	 to type r   )
r   r%   r   r   r   r#   
from_sympyr
   r?   r   )r(   r_   repr   r   r   s         r+   r   GlobalPolynomialRing.from_sympy  s    	M$QYY7FC IIKDAXX((+CF   }}S**q.$((;;  	M 1d!KLL	Ms   A; ;Bc                 T    U R                   R                  UR                  5       5      $ )z'Returns True if ``LC(a)`` is positive. )r#   is_positiveLCr   s     r+   r    GlobalPolynomialRing.is_positive%      xx##ADDF++r.   c                 T    U R                   R                  UR                  5       5      $ )z'Returns True if ``LC(a)`` is negative. )r#   is_negativer   r   s     r+   r    GlobalPolynomialRing.is_negative)  r   r.   c                 T    U R                   R                  UR                  5       5      $ )z+Returns True if ``LC(a)`` is non-positive. )r#   is_nonpositiver   r   s     r+   r   #GlobalPolynomialRing.is_nonpositive-      xx&&qttv..r.   c                 T    U R                   R                  UR                  5       5      $ )z+Returns True if ``LC(a)`` is non-negative. )r#   is_nonnegativer   r   s     r+   r   #GlobalPolynomialRing.is_nonnegative1  r   r.   c                     [        X5      $ )z
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   #GlobalPolynomialRing._vector_to_sdm5  s     %Q..r.   r   N)rP   r   r   r   r   is_PolynomialRingis_Polyr
   r   r7   r   r   r   r   r   r   r   r   r   r   r.   r+   r   r      sC    4"&&EE?2>
<,,///r.   r   c                   F    \ rS rSrSr\rS rS rS r	S r
S rS rS	 rS
rg)GeneralizedPolynomialRingiE  z1A generalized polynomial ring, with objects DMF. c                 6   U R                  XR                  [        U R                  5      S-
  5      nUR	                  5       R                  U R                  S9S   S   S[        U R                  5      -  :w  a  SSKJn  [        SU" U5      < SU < 35      eU$ )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(   r_   r   r
  s       r+   r7   GeneralizedPolynomialRing.newJ  s    jjHHc$))nq&89 99;4::.q1!4S^8KK/ $(It"5 6 6
r.   c                      U R                  U5      nUR                  5       R                  U R                  S9S   S   S[        U R                  5      -  :H  $ ! [         a     gf = f)NFr  r   r	  )r\   r   r   r  r   r   r%   r   s     r+   __contains__&GeneralizedPolynomialRing.__contains__U  sa    	QA wwyTZZ03A6$s499~:MMM  		s   A 
A&%A&c                     [        UR                  5       R                  5       /U R                  Q76 [        UR	                  5       R                  5       /U R                  Q76 -  $ r   )r   r   r   r%   r   r   s     r+   r   "GeneralizedPolynomialRing.to_sympy\  sN    	 7 7 9FDIIF	 7 7 9FDIIFG 	Hr.   c                    UR                  5       u  p#[        X R                  S9u  pE[        X0R                  S9u  peUR                  5        H"  u  pxU R                  R                  U5      XG'   M$     UR                  5        H"  u  pxU R                  R                  U5      Xg'   M$     U " XF45      R                  5       $ )r   r   )as_numer_denomr   r%   r   r#   r   cancel)	r(   r_   pqnumr   denr   r   s	            r+   r   $GeneralizedPolynomialRing.from_sympya  s    ! 3 3IIKDAXX((+CF   IIKDAXX((+CF   SJ&&((r.   c                     X-  n U R                  UR                  UR                  45      nU$ ! [         a    [	        XU 5      ef = f)z#Exact quotient of ``a`` and ``b``. )r7   r  r  r   r   )r(   r_   r   rs       r+   r   GeneralizedPolynomialRing.exquop  sO     E	2!%%(A   	2%aD11	2s	   '/ Ac                 |    U R                  5       R                  X5      nU " UR                  UR                  45      $ r:   )r   r   r  r  )r^   r_   r`   dmfs       r+   r   ,GeneralizedPolynomialRing.from_FractionField}  s0    lln//6377CGG$%%r.   c                     U R                   R                  5       nU H  nX4R                  5       -  nM     [        U Vs/ s H&  oDR                  5       U-  UR                  5       -  PM(     snU5      $ s  snf )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   (GeneralizedPolynomialRing._vector_to_sdm  s]    ( HHNNANA $Q%GQggik!'')&;Q%GOO%Gs   -A4r   N)rP   r   r   r   r   r   r   r7   r  r   r   r   r   r   r   r   r.   r+   r  r  E  s0    ;E	NH
)&Pr.   r  c                     UR                  S[        R                  5      n[        U5      (       a  [	        X15      n[        U5      nX2S'   UR                  (       a  [        U /UQ70 UD6$ [        U /UQ70 UD6$ )a  
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&    sq    L HHW7EEFE#E0E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>r1     s    7 8 ? ? ) C ,< < Q Q " . N. N. N.b# T/- T/ T/nSP 2 SPl N= N=r.   