+
    i                        R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ R	IHtHtHt ^ R
IHtHt ^ RIHt ^ RIHt ] ! R R4      4       tR.tR# )z)Implementation of :class:`Domain` class. )annotations)Any)AlgebraicNumber)Basicsympify)ordered)GROUND_TYPES)DomainElement)lex)UnificationFailedCoercionFailedDomainError)_unify_gens_not_a_coeff)public)is_sequencec                  F   ] tR t^t$ RtRtR]R&    RtR]R&    RtR]R&    Rt	 Rt
 Rt Rt R;ttR;ttR;ttR;ttR;ttR;ttR;ttR;ttR;ttR;tt R;t!t"R;t#t$Rt%R	t&Rt'Rt(Rt)Rt* Rt+Rt,R
]R&   Rt-R
]R&   R t.R t/R t0R t1R t2]3R 4       t4R t5R t6R t7RfR lt8R t9R t:R t;R t<R t=R t>R t?R t@R tAR  tBR! tCR" tDR# tER$ tFR% tGR& tHR' tIR( tJR) tKR* tLR+ tMR, tNR- tOR. tPRfR/ ltQR0 tRR1 tSR2 tTR3 tUR4 tVR5 tWR6 tXR7]Y/R8 ltZR7]Y/R9 lt[R: t\R; t]RR/R< lt^RgR= lt_RhR> lt`R? taR@ tbRA tcRB tdRC teRD tfRE tgRF thRG tiRH tjRI tkRJ tlRK tmRL tnRM toRN tpRO tqRP trRQ tsRR ttRS tuRT tvRU twRV txRW tyRX tzRY t{RZ t|R[ t}R\ t~R] tR^ tR_ tRfR` lt]tRa tRb tRfRc ltRd tRetR# )iDomaina*  Superclass for all domains in the polys domains system.

See :ref:`polys-domainsintro` for an introductory explanation of the
domains system.

The :py:class:`~.Domain` class is an abstract base class for all of the
concrete domain types. There are many different :py:class:`~.Domain`
subclasses each of which has an associated ``dtype`` which is a class
representing the elements of the domain. The coefficients of a
:py:class:`~.Poly` are elements of a domain which must be a subclass of
:py:class:`~.Domain`.

Examples
========

The most common example domains are the integers :ref:`ZZ` and the
rationals :ref:`QQ`.

>>> from sympy import Poly, symbols, Domain
>>> x, y = symbols('x, y')
>>> p = Poly(x**2 + y)
>>> p
Poly(x**2 + y, x, y, domain='ZZ')
>>> p.domain
ZZ
>>> isinstance(p.domain, Domain)
True
>>> Poly(x**2 + y/2)
Poly(x**2 + 1/2*y, x, y, domain='QQ')

The domains can be used directly in which case the domain object e.g.
(:ref:`ZZ` or :ref:`QQ`) can be used as a constructor for elements of
``dtype``.

>>> from sympy import ZZ, QQ
>>> ZZ(2)
2
>>> ZZ.dtype  # doctest: +SKIP
<class 'int'>
>>> type(ZZ(2))  # doctest: +SKIP
<class 'int'>
>>> QQ(1, 2)
1/2
>>> type(QQ(1, 2))  # doctest: +SKIP
<class 'sympy.polys.domains.pythonrational.PythonRational'>

The corresponding domain elements can be used with the arithmetic
operations ``+,-,*,**`` and depending on the domain some combination of
``/,//,%`` might be usable. For example in :ref:`ZZ` both ``//`` (floor
division) and ``%`` (modulo division) can be used but ``/`` (true
division) cannot. Since :ref:`QQ` is a :py:class:`~.Field` its elements
can be used with ``/`` but ``//`` and ``%`` should not be used. Some
domains have a :py:meth:`~.Domain.gcd` method.

>>> ZZ(2) + ZZ(3)
5
>>> ZZ(5) // ZZ(2)
2
>>> ZZ(5) % ZZ(2)
1
>>> QQ(1, 2) / QQ(2, 3)
3/4
>>> ZZ.gcd(ZZ(4), ZZ(2))
2
>>> QQ.gcd(QQ(2,7), QQ(5,3))
1/21
>>> ZZ.is_Field
False
>>> QQ.is_Field
True

There are also many other domains including:

    1. :ref:`GF(p)` for finite fields of prime order.
    2. :ref:`RR` for real (floating point) numbers.
    3. :ref:`CC` for complex (floating point) numbers.
    4. :ref:`QQ(a)` for algebraic number fields.
    5. :ref:`K[x]` for polynomial rings.
    6. :ref:`K(x)` for rational function fields.
    7. :ref:`EX` for arbitrary expressions.

Each domain is represented by a domain object and also an implementation
class (``dtype``) for the elements of the domain. For example the
:ref:`K[x]` domains are represented by a domain object which is an
instance of :py:class:`~.PolynomialRing` and the elements are always
instances of :py:class:`~.PolyElement`. The implementation class
represents particular types of mathematical expressions in a way that is
more efficient than a normal SymPy expression which is of type
:py:class:`~.Expr`. The domain methods :py:meth:`~.Domain.from_sympy` and
:py:meth:`~.Domain.to_sympy` are used to convert from :py:class:`~.Expr`
to a domain element and vice versa.

>>> from sympy import Symbol, ZZ, Expr
>>> x = Symbol('x')
>>> K = ZZ[x]           # polynomial ring domain
>>> K
ZZ[x]
>>> type(K)             # class of the domain
<class 'sympy.polys.domains.polynomialring.PolynomialRing'>
>>> K.dtype             # doctest: +SKIP
<class 'sympy.polys.rings.PolyElement'>
>>> p_expr = x**2 + 1   # Expr
>>> p_expr
x**2 + 1
>>> type(p_expr)
<class 'sympy.core.add.Add'>
>>> isinstance(p_expr, Expr)
True
>>> p_domain = K.from_sympy(p_expr)
>>> p_domain            # domain element
x**2 + 1
>>> type(p_domain)
<class 'sympy.polys.rings.PolyElement'>
>>> K.to_sympy(p_domain) == p_expr
True

The :py:meth:`~.Domain.convert_from` method is used to convert domain
elements from one domain to another.

>>> from sympy import ZZ, QQ
>>> ez = ZZ(2)
>>> eq = QQ.convert_from(ez, ZZ)
>>> type(ez)  # doctest: +SKIP
<class 'int'>
>>> type(eq)  # doctest: +SKIP
<class 'sympy.polys.domains.pythonrational.PythonRational'>

Elements from different domains should not be mixed in arithmetic or other
operations: they should be converted to a common domain first.  The domain
method :py:meth:`~.Domain.unify` is used to find a domain that can
represent all the elements of two given domains.

>>> from sympy import ZZ, QQ, symbols
>>> x, y = symbols('x, y')
>>> ZZ.unify(QQ)
QQ
>>> ZZ[x].unify(QQ)
QQ[x]
>>> ZZ[x].unify(QQ[y])
QQ[x,y]

If a domain is a :py:class:`~.Ring` then is might have an associated
:py:class:`~.Field` and vice versa. The :py:meth:`~.Domain.get_field` and
:py:meth:`~.Domain.get_ring` methods will find or create the associated
domain.

>>> from sympy import ZZ, QQ, Symbol
>>> x = Symbol('x')
>>> ZZ.has_assoc_Field
True
>>> ZZ.get_field()
QQ
>>> QQ.has_assoc_Ring
True
>>> QQ.get_ring()
ZZ
>>> K = QQ[x]
>>> K
QQ[x]
>>> K.get_field()
QQ(x)

See also
========

DomainElement: abstract base class for domain elements
construct_domain: construct a minimal domain for some expressions

Nztype | Nonedtyper   zerooneFTz
str | Nonerepaliasc                	    \         hNNotImplementedErrorselfs   &z/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/polys/domains/domain.py__init__Domain.__init__g  s    !!    c                	    V P                   # r   )r   r   s   &r   __str__Domain.__str__j  s    xxr"   c                	    \        V 4      # r   )strr   s   &r   __repr__Domain.__repr__m  s    4yr"   c                	X    \        V P                  P                  V P                  34      # r   )hash	__class____name__r   r   s   &r   __hash__Domain.__hash__p  s     T^^,,djj9::r"   c                	"    V P                   ! V!  # r   r   r   argss   &*r   new
Domain.news      zz4  r"   c                    V P                   # )z#Alias for :py:attr:`~.Domain.dtype`r1   r   s   &r   tp	Domain.tpv  s     zzr"   c                "    V P                   ! V!  # )z7Construct an element of ``self`` domain from ``args``. )r4   r2   s   &*r   __call__Domain.__call__{  s    xxr"   c                	"    V P                   ! V!  # r   r1   r2   s   &*r   normalDomain.normal  r6   r"   c           
        VP                   e   RVP                   ,           pMRVP                  P                  ,           p\        W4      pVe   V! W4      pVe   V# \	        RV: R\        V4      : RV: RV : 24      h)z=Convert ``element`` to ``self.dtype`` given the base domain. from_Cannot convert 	 of type z from  to )r   r,   r-   getattrr   type)r   elementbasemethod_convertresults   &&&   r   convert_fromDomain.convert_from  sp    ::!tzz)Ft~~666F4(g,F!WVZ[bVceikopqqr"   c                   Ve5   \        V4      '       d   \        RV,          4      hV P                  W4      # V P                  V4      '       d   V# \        V4      '       d   \        RV,          4      h^ RIHpHpHpHp VP                  V4      '       d   V P                  W4      # \        V\        4      '       d   V P                  V! V4      V4      # \        R8w  dY   \        WP                  4      '       d   V P                  W4      # \        WP                  4      '       d   V P                  W4      # \        V\        4      '       d    V! 4       pV P                  V! V4      V4      # \        V\        4      '       d    V! 4       pV P                  V! V4      V4      # \        V4      P                   R8X  d    V! 4       pV P                  V! V4      V4      # \        V4      P                   R8X  d    V! 4       pV P                  V! V4      V4      # \        V\"        4      '       d    V P                  WP%                  4       4      # V P&                  '       d3   \)        VRR4      '       d    V P+                  VP-                  4       4      # \        V\.        4      '       d    V P1                  V4      # \7        V4      '       g7    \9        VRR	7      p\        V\.        4      '       d   V P1                  V4      #  \        R
V: R\        V4      : RV : 24      h  \2        \4        3 d     L3i ; i  \2        \4        3 d     LJi ; i)z'Convert ``element`` to ``self.dtype``. z%s is not in any domain)ZZQQ	RealFieldComplexFieldpythonmpfmpc	is_groundFT)strictrB   rC   rD   )r   r   rL   of_typesympy.polys.domainsrO   rP   rQ   rR   
isinstanceintr   r8   floatcomplexrF   r-   r	   parentis_NumericalrE   convertLCr   
from_sympy	TypeError
ValueErrorr   r   )r   rG   rH   rO   rP   rQ   rR   r^   s   &&&     r   r`   Domain.convert  s    G$$$%>%HII$$W33<<  N   !:W!DEEGG::g$$W11gs##$$R["558#'55))((55'55))((55gu%%[F$$VG_f==gw''!^F$$VG_f===!!U*[F$$VG_f===!!U*!^F$$VG_f==g}--$$Wnn.>?? +u!E!E<<

--gu%%w// w''%gd;G!'511#w77 2
 WdSZm]abcc z*  ":. s$   &L 	3L5 L21L25M	M	c                ,    \        WP                  4      # )z%Check if ``a`` is of type ``dtype``. )rZ   r8   )r   rG   s   &&r   rX   Domain.of_type  s    '77++r"   c                |     \        V4      '       d   \        hV P                  V4       R#   \         d     R# i ; i)z'Check if ``a`` belongs to this domain. FT)r   r   r`   r   as   &&r   __contains__Domain.__contains__  s:    	A$$LLO   		s   (, ;;c                    \         h)a  Convert domain element *a* to a SymPy expression (Expr).

Explanation
===========

Convert a :py:class:`~.Domain` element *a* to :py:class:`~.Expr`. Most
public SymPy functions work with objects of type :py:class:`~.Expr`.
The elements of a :py:class:`~.Domain` have a different internal
representation. It is not possible to mix domain elements with
:py:class:`~.Expr` so each domain has :py:meth:`~.Domain.to_sympy` and
:py:meth:`~.Domain.from_sympy` methods to convert its domain elements
to and from :py:class:`~.Expr`.

Parameters
==========

a: domain element
    An element of this :py:class:`~.Domain`.

Returns
=======

expr: Expr
    A normal SymPy expression of type :py:class:`~.Expr`.

Examples
========

Construct an element of the :ref:`QQ` domain and then convert it to
:py:class:`~.Expr`.

>>> from sympy import QQ, Expr
>>> q_domain = QQ(2)
>>> q_domain
2
>>> q_expr = QQ.to_sympy(q_domain)
>>> q_expr
2

Although the printed forms look similar these objects are not of the
same type.

>>> isinstance(q_domain, Expr)
False
>>> isinstance(q_expr, Expr)
True

Construct an element of :ref:`K[x]` and convert to
:py:class:`~.Expr`.

>>> from sympy import Symbol
>>> x = Symbol('x')
>>> K = QQ[x]
>>> x_domain = K.gens[0]  # generator x as a domain element
>>> p_domain = x_domain**2/3 + 1
>>> p_domain
1/3*x**2 + 1
>>> p_expr = K.to_sympy(p_domain)
>>> p_expr
x**2/3 + 1

The :py:meth:`~.Domain.from_sympy` method is used for the opposite
conversion from a normal SymPy expression to a domain element.

>>> p_domain == p_expr
False
>>> K.from_sympy(p_expr) == p_domain
True
>>> K.to_sympy(p_domain) == p_expr
True
>>> K.from_sympy(K.to_sympy(p_domain)) == p_domain
True
>>> K.to_sympy(K.from_sympy(p_expr)) == p_expr
True

The :py:meth:`~.Domain.from_sympy` method makes it easier to construct
domain elements interactively.

>>> from sympy import Symbol
>>> x = Symbol('x')
>>> K = QQ[x]
>>> K.from_sympy(x**2/3 + 1)
1/3*x**2 + 1

See also
========

from_sympy
convert_from
r   ri   s   &&r   to_sympyDomain.to_sympy  s    v "!r"   c                    \         h)aj  Convert a SymPy expression to an element of this domain.

Explanation
===========

See :py:meth:`~.Domain.to_sympy` for explanation and examples.

Parameters
==========

expr: Expr
    A normal SymPy expression of type :py:class:`~.Expr`.

Returns
=======

a: domain element
    An element of this :py:class:`~.Domain`.

See also
========

to_sympy
convert_from
r   ri   s   &&r   rb   Domain.from_sympyB  s
    4 "!r"   c                	.    \        WP                  R 7      # ))start)sumr   r2   s   &&r   rt   
Domain.sum^  s    4yy))r"   c                    R# z.Convert ``ModularInteger(int)`` to ``dtype``. N K1rj   K0s   &&&r   from_FFDomain.from_FFa      r"   c                    R# rw   rx   ry   s   &&&r   from_FF_pythonDomain.from_FF_pythone  r~   r"   c                    R# )z.Convert a Python ``int`` object to ``dtype``. Nrx   ry   s   &&&r   from_ZZ_pythonDomain.from_ZZ_pythoni  r~   r"   c                    R# )z3Convert a Python ``Fraction`` object to ``dtype``. Nrx   ry   s   &&&r   from_QQ_pythonDomain.from_QQ_pythonm  r~   r"   c                    R# )z.Convert ``ModularInteger(mpz)`` to ``dtype``. Nrx   ry   s   &&&r   from_FF_gmpyDomain.from_FF_gmpyq  r~   r"   c                    R# )z,Convert a GMPY ``mpz`` object to ``dtype``. Nrx   ry   s   &&&r   from_ZZ_gmpyDomain.from_ZZ_gmpyu  r~   r"   c                    R# )z,Convert a GMPY ``mpq`` object to ``dtype``. Nrx   ry   s   &&&r   from_QQ_gmpyDomain.from_QQ_gmpyy  r~   r"   c                    R# )z,Convert a real element object to ``dtype``. Nrx   ry   s   &&&r   from_RealFieldDomain.from_RealField}  r~   r"   c                    R# )z(Convert a complex element to ``dtype``. Nrx   ry   s   &&&r   from_ComplexFieldDomain.from_ComplexField  r~   r"   c                    R# )z*Convert an algebraic number to ``dtype``. Nrx   ry   s   &&&r   from_AlgebraicFieldDomain.from_AlgebraicField  r~   r"   c                v    VP                   '       d'   V P                  VP                  VP                  4      # R# z#Convert a polynomial to ``dtype``. N)rV   r`   ra   domry   s   &&&r   from_PolynomialRingDomain.from_PolynomialRing  s)    ;;;::addBFF++ r"   c                    R# )z*Convert a rational function to ``dtype``. Nrx   ry   s   &&&r   from_FractionFieldDomain.from_FractionField  r~   r"   c                N    V P                  VP                  VP                  4      # )z.Convert an ``ExtensionElement`` to ``dtype``. )rL   r   ringry   s   &&&r   from_MonogenicFiniteExtension$Domain.from_MonogenicFiniteExtension  s    quubgg..r"   c                8    V P                  VP                  4      # z&Convert a ``EX`` object to ``dtype``. )rb   exry   s   &&&r   from_ExpressionDomainDomain.from_ExpressionDomain  s    }}QTT""r"   c                $    V P                  V4      # r   )rb   ry   s   &&&r   from_ExpressionRawDomainDomain.from_ExpressionRawDomain  s    }}Qr"   c                    VP                  4       ^ 8:  d+   V P                  VP                  4       VP                  4      # R# r   )degreer`   ra   r   ry   s   &&&r   from_GlobalPolynomialRing Domain.from_GlobalPolynomialRing  s/    88:?::addfbff-- r"   c                	$    V P                  W4      # r   )r   ry   s   &&&r   from_GeneralizedPolynomialRing%Domain.from_GeneralizedPolynomialRing  s    $$Q++r"   c           
     	Z   V P                   '       d,   \        V P                  4      \        V4      ,          '       g>   VP                   '       dM   \        VP                  4      \        V4      ,          '       d"   \        R V : RV: R\	        V4      : R24      hV P                  V4      # )Cannot unify  with z, given z generators)is_Compositesetsymbolsr   tupleunify)r{   rz   r   s   &&&r   unify_with_symbolsDomain.unify_with_symbols  sp    OOORZZ3w<!?!?booo[^_a_i_i[jmpqxmy[y[y#VXZ\^cdk^l$mnnxx|r"   c                   V P                   '       d   V P                  MT pVP                   '       d   VP                  MTpV P                   '       d   V P                  MRpVP                   '       d   VP                  MRpVP                  V4      p\	        WE4      pV P                   '       d   V P
                  MVP
                  pV P                  '       d   VP                  '       g%   VP                  '       dk   V P                  '       dY   VP                  '       d   VP                  '       g5   VP                  '       d#   VP                  '       d   VP                  4       pV P                   '       dD   VP                   '       d%   V P                  '       g   VP                  '       d   V P                  p	MVP                  p	^ RIHp
 W8X  d	   V	! Wg4      # V	! WgV4      # )z2Unify two domains where at least one is composite.)GlobalPolynomialRingrx   )r   r   r   r   r   orderis_FractionFieldis_PolynomialRingis_Fieldhas_assoc_Ringget_ringr,   &sympy.polys.domains.old_polynomialringr   )r{   rz   	K0_ground	K1_ground
K0_symbols
K1_symbolsdomainr   r   clsr   s   &&         r   unify_compositeDomain.unify_composite  sA    oooBFF2	 oooBFF2	#%???RZZ
#%???RZZ
+j5OOO    R%9%9%9   R%9%9%9$$$I,>,>,>FOOO&&&__&F???BOOOr7J7J7JbNbNbNb,,C,,C
 	P&v''6E**r"   c                	   Ve   V P                  W4      # W8X  d   V # V P                  '       d   VP                  '       gH   V P                  4       VP                  4       8w  d   \        RV : RV: 24      hV P	                  V4      # V P
                  '       d   V # VP
                  '       d   V# V P                  '       d   V # VP                  '       d   V# V P                  '       g   VP                  '       d   VP                  '       d   YrVP                  '       dT   \        \        V P                  VP                  .4      4      ^,          V P                  8X  d   YrVP                  V 4      # VP                  V P                  4      pV P                  P                  V4      pV P                  V4      # V P                   '       g   VP                   '       d   V P	                  V4      # VP"                  '       d   YrV P"                  '       d]   VP"                  '       g   VP$                  '       d7   V P&                  VP&                  8  d   V # ^ RIHp V! VP&                  R7      # V # VP$                  '       d   YrV P$                  '       dq   VP$                  '       d    V P&                  VP&                  8  d   V # V# VP,                  '       g   VP.                  '       d   ^ RIHp V! V P&                  R7      # V # VP0                  '       d   YrV P0                  '       d   VP,                  '       d   VP3                  4       pVP.                  '       d   VP5                  4       pVP0                  '       dV   V P6                  ! V P8                  P                  VP8                  4      .\;        V P<                  VP<                  4      O5!  # V # V P.                  '       d   V # VP.                  '       d   V# V P,                  '       d%   VP>                  '       d   V P3                  4       p V # VP,                  '       d%   V P>                  '       d   VP3                  4       pV# V P>                  '       d   V # VP>                  '       d   V# V P@                  '       d   V # VP@                  '       d   V# ^ RI!H"p V# )z
Construct a minimal domain that contains elements of ``K0`` and ``K1``.

Known domains (from smallest to largest):

- ``GF(p)``
- ``ZZ``
- ``QQ``
- ``RR(prec, tol)``
- ``CC(prec, tol)``
- ``ALG(a, b, c)``
- ``K[x, y, z]``
- ``K(x, y, z)``
- ``EX``

r   r   )rR   )prec)EX)#r   has_CharacteristicZerocharacteristicr   r   is_EXRAWis_EXis_FiniteExtensionlistr   modulus
set_domaindropsymbolr   r   r   is_ComplexFieldis_RealField	precision sympy.polys.domains.complexfieldrR   is_GaussianRingis_GaussianFieldis_AlgebraicField	get_fieldas_AlgebraicFieldr,   r   r   orig_extis_RationalFieldis_IntegerRingrY   r   )r{   rz   r   rR   r   s   &&&  r   r   Domain.unify  s   " ((558I)))b.G.G.G  "b&7&7&99'R(LMM
 %%b))
 ;;;I;;;I888I888I   B$9$9$9$$$B$$$ RZZ 89:1=K}}R(( WWRYY'YY__R(}}R((???booo%%b))!!!R___<<2<</IM'R\\::	??????<<2<</II###r':':':I#66	!!!\\^"""))+###||BFFLL$8a;r{{TVT_T_;`aa	II"""\\^I"""\\^IIIII*	r"   c                d    \        V\        4      ;'       d    V P                  VP                  8H  # )z0Returns ``True`` if two domains are equivalent. )rZ   r   r   r   others   &&r   __eq__Domain.__eq__N  s&     %(FFTZZ5;;-FFr"   c                    W8X  * # )z1Returns ``False`` if two domains are equivalent. rx   r   s   &&r   __ne__Domain.__ne__S  s      r"   c                    . pV FR  p\        V\        4      '       d#   VP                  V P                  V4      4       K;  VP                  V ! V4      4       KT  	  V# )z5Rersively apply ``self`` to all elements of ``seq``. )rZ   r   appendmap)r   seqrK   elts   &&  r   r   
Domain.mapW  sI    C#t$$dhhsm,d3i(	  r"   c                &    \        RV ,          4      h)z)Returns a ring associated with ``self``. z#there is no ring associated with %sr   r   s   &r   r   Domain.get_ringc  s    ?$FGGr"   c                &    \        RV ,          4      h)z*Returns a field associated with ``self``. z$there is no field associated with %sr   r   s   &r   r   Domain.get_fieldg  s    @4GHHr"   c                    V # )z2Returns an exact domain associated with ``self``. rx   r   s   &r   	get_exactDomain.get_exactk  s    r"   c                h    \        VR4      '       d   V P                  ! V!  # V P                  V4      # )z0The mathematical way to make a polynomial ring. __iter__)hasattr	poly_ringr   r   s   &&r   __getitem__Domain.__getitem__o  s-    7J''>>7++>>'**r"   r   c                    ^ RI Hp V! WV4      # z(Returns a polynomial ring, i.e. `K[X]`. )PolynomialRing)"sympy.polys.domains.polynomialringr	  )r   r   r   r	  s   &$* r   r  Domain.poly_ringv  s    EdU33r"   c                    ^ RI Hp V! WV4      # z'Returns a fraction field, i.e. `K(X)`. )FractionField)!sympy.polys.domains.fractionfieldr  )r   r   r   r  s   &$* r   
frac_fieldDomain.frac_field{  s    CTE22r"   c                &    ^ RI Hp V! V .VO5/ VB # r  )r   r	  )r   r   kwargsr	  s   &*, r   old_poly_ringDomain.old_poly_ring  s    Id7W777r"   c                &    ^ RI Hp V! V .VO5/ VB # r  )%sympy.polys.domains.old_fractionfieldr  )r   r   r  r  s   &*, r   old_frac_fieldDomain.old_frac_field  s    GT6G6v66r"   c               &    \        RV ,          4      h)z6Returns an algebraic field, i.e. `K(\alpha, \ldots)`. z%Cannot create algebraic field over %sr   )r   r   	extensions   &$*r   algebraic_fieldDomain.algebraic_field  s    ADHIIr"   c                Z    ^ RI Hp V! W4      p\        WRR7      pV P                  WbR7      # )a  
Convenience method to construct an algebraic extension on a root of a
polynomial, chosen by root index.

Parameters
==========

poly : :py:class:`~.Poly`
    The polynomial whose root generates the extension.
alias : str, optional (default=None)
    Symbol name for the generator of the extension.
    E.g. "alpha" or "theta".
root_index : int, optional (default=-1)
    Specifies which root of the polynomial is desired. The ordering is
    as defined by the :py:class:`~.ComplexRootOf` class. The default of
    ``-1`` selects the most natural choice in the common cases of
    quadratic and cyclotomic fields (the square root on the positive
    real or imaginary axis, resp. $\mathrm{e}^{2\pi i/n}$).

Examples
========

>>> from sympy import QQ, Poly
>>> from sympy.abc import x
>>> f = Poly(x**2 - 2)
>>> K = QQ.alg_field_from_poly(f)
>>> K.ext.minpoly == f
True
>>> g = Poly(8*x**3 - 6*x - 1)
>>> L = QQ.alg_field_from_poly(g, "alpha")
>>> L.ext.minpoly == g
True
>>> L.to_sympy(L([1, 1, 1]))
alpha**2 + alpha + 1

)CRootOf)r   )sympy.polys.rootoftoolsr  r   r  )r   polyr   
root_indexr  rootalphas   &&&&   r   alg_field_from_polyDomain.alg_field_from_poly  s0    J 	4t(2##E#77r"   c                v    ^ RI Hp V'       d   V\        V4      ,          pV P                  V! W4      VVR7      # )a  
Convenience method to construct a cyclotomic field.

Parameters
==========

n : int
    Construct the nth cyclotomic field.
ss : boolean, optional (default=False)
    If True, append *n* as a subscript on the alias string.
alias : str, optional (default="zeta")
    Symbol name for the generator.
gen : :py:class:`~.Symbol`, optional (default=None)
    Desired variable for the cyclotomic polynomial that defines the
    field. If ``None``, a dummy variable will be used.
root_index : int, optional (default=-1)
    Specifies which root of the polynomial is desired. The ordering is
    as defined by the :py:class:`~.ComplexRootOf` class. The default of
    ``-1`` selects the root $\mathrm{e}^{2\pi i/n}$.

Examples
========

>>> from sympy import QQ, latex
>>> K = QQ.cyclotomic_field(5)
>>> K.to_sympy(K([-1, 1]))
1 - zeta
>>> L = QQ.cyclotomic_field(7, True)
>>> a = L.to_sympy(L([-1, 1]))
>>> print(a)
1 - zeta7
>>> print(latex(a))
1 - \zeta_{7}

)cyclotomic_poly)r   r"  )sympy.polys.specialpolysr(  r'   r%  )r   nssr   genr"  r(  s   &&&&&& r   cyclotomic_fieldDomain.cyclotomic_field  s<    H 	=SVOE''(?u3= ( ? 	?r"   c                    \         h)z$Inject generators into this domain. r   r  s   &*r   injectDomain.inject      !!r"   c                6    V P                   '       d   V # \        h)z"Drop generators from this domain. )	is_Simpler   r  s   &*r   r   Domain.drop  s    >>>K!!r"   c                    V'       * # )zReturns True if ``a`` is zero. rx   ri   s   &&r   is_zeroDomain.is_zero  s	    ur"   c                    WP                   8H  # )zReturns True if ``a`` is one. )r   ri   s   &&r   is_oneDomain.is_one  s    HH}r"   c                    V^ 8  # )z#Returns True if ``a`` is positive. rx   ri   s   &&r   is_positiveDomain.is_positive      1ur"   c                    V^ 8  # )z#Returns True if ``a`` is negative. rx   ri   s   &&r   is_negativeDomain.is_negative  r?  r"   c                    V^ 8*  # )z'Returns True if ``a`` is non-positive. rx   ri   s   &&r   is_nonpositiveDomain.is_nonpositive      Avr"   c                    V^ 8  # )z'Returns True if ``a`` is non-negative. rx   ri   s   &&r   is_nonnegativeDomain.is_nonnegative   rF  r"   c                	b    V P                  V4      '       d   V P                  ) # V P                  # r   )rA  r   ri   s   &&r   canonical_unitDomain.canonical_unit  s(    AHH988Or"   c                    \        V4      # )z.Absolute value of ``a``, implies ``__abs__``. )absri   s   &&r   rN  
Domain.abs
  s    1vr"   c                    V) # )z,Returns ``a`` negated, implies ``__neg__``. rx   ri   s   &&r   neg
Domain.neg  	    r	r"   c                    V5# )z-Returns ``a`` positive, implies ``__pos__``. rx   ri   s   &&r   pos
Domain.pos  rS  r"   c                    W,           # )z.Sum of ``a`` and ``b``, implies ``__add__``.  rx   r   rj   bs   &&&r   add
Domain.add  	    ur"   c                    W,
          # )z5Difference of ``a`` and ``b``, implies ``__sub__``.  rx   rX  s   &&&r   sub
Domain.sub  r\  r"   c                    W,          # )z2Product of ``a`` and ``b``, implies ``__mul__``.  rx   rX  s   &&&r   mul
Domain.mul  r\  r"   c                    W,          # )z2Raise ``a`` to power ``b``, implies ``__pow__``.  rx   rX  s   &&&r   pow
Domain.pow"  s	    vr"   c                    \         h)a  Exact quotient of *a* and *b*. Analogue of ``a / b``.

Explanation
===========

This is essentially the same as ``a / b`` except that an error will be
raised if the division is inexact (if there is any remainder) and the
result will always be a domain element. When working in a
:py:class:`~.Domain` that is not a :py:class:`~.Field` (e.g. :ref:`ZZ`
or :ref:`K[x]`) ``exquo`` should be used instead of ``/``.

The key invariant is that if ``q = K.exquo(a, b)`` (and ``exquo`` does
not raise an exception) then ``a == b*q``.

Examples
========

We can use ``K.exquo`` instead of ``/`` for exact division.

>>> from sympy import ZZ
>>> ZZ.exquo(ZZ(4), ZZ(2))
2
>>> ZZ.exquo(ZZ(5), ZZ(2))
Traceback (most recent call last):
    ...
ExactQuotientFailed: 2 does not divide 5 in ZZ

Over a :py:class:`~.Field` such as :ref:`QQ`, division (with nonzero
divisor) is always exact so in that case ``/`` can be used instead of
:py:meth:`~.Domain.exquo`.

>>> from sympy import QQ
>>> QQ.exquo(QQ(5), QQ(2))
5/2
>>> QQ(5) / QQ(2)
5/2

Parameters
==========

a: domain element
    The dividend
b: domain element
    The divisor

Returns
=======

q: domain element
    The exact quotient

Raises
======

ExactQuotientFailed: if exact division is not possible.
ZeroDivisionError: when the divisor is zero.

See also
========

quo: Analogue of ``a // b``
rem: Analogue of ``a % b``
div: Analogue of ``divmod(a, b)``

Notes
=====

Since the default :py:attr:`~.Domain.dtype` for :ref:`ZZ` is ``int``
(or ``mpz``) division as ``a / b`` should not be used as it would give
a ``float`` which is not a domain element.

>>> ZZ(4) / ZZ(2) # doctest: +SKIP
2.0
>>> ZZ(5) / ZZ(2) # doctest: +SKIP
2.5

On the other hand with `SYMPY_GROUND_TYPES=flint` elements of :ref:`ZZ`
are ``flint.fmpz`` and division would raise an exception:

>>> ZZ(4) / ZZ(2) # doctest: +SKIP
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for /: 'fmpz' and 'fmpz'

Using ``/`` with :ref:`ZZ` will lead to incorrect results so
:py:meth:`~.Domain.exquo` should be used instead.

r   rX  s   &&&r   exquoDomain.exquo&  s    r "!r"   c                    \         h)a  Quotient of *a* and *b*. Analogue of ``a // b``.

``K.quo(a, b)`` is equivalent to ``K.div(a, b)[0]``. See
:py:meth:`~.Domain.div` for more explanation.

See also
========

rem: Analogue of ``a % b``
div: Analogue of ``divmod(a, b)``
exquo: Analogue of ``a / b``
r   rX  s   &&&r   quo
Domain.quo  
     "!r"   c                    \         h)a  Modulo division of *a* and *b*. Analogue of ``a % b``.

``K.rem(a, b)`` is equivalent to ``K.div(a, b)[1]``. See
:py:meth:`~.Domain.div` for more explanation.

See also
========

quo: Analogue of ``a // b``
div: Analogue of ``divmod(a, b)``
exquo: Analogue of ``a / b``
r   rX  s   &&&r   rem
Domain.rem  rl  r"   c                    \         h)a{  Quotient and remainder for *a* and *b*. Analogue of ``divmod(a, b)``

Explanation
===========

This is essentially the same as ``divmod(a, b)`` except that is more
consistent when working over some :py:class:`~.Field` domains such as
:ref:`QQ`. When working over an arbitrary :py:class:`~.Domain` the
:py:meth:`~.Domain.div` method should be used instead of ``divmod``.

The key invariant is that if ``q, r = K.div(a, b)`` then
``a == b*q + r``.

The result of ``K.div(a, b)`` is the same as the tuple
``(K.quo(a, b), K.rem(a, b))`` except that if both quotient and
remainder are needed then it is more efficient to use
:py:meth:`~.Domain.div`.

Examples
========

We can use ``K.div`` instead of ``divmod`` for floor division and
remainder.

>>> from sympy import ZZ, QQ
>>> ZZ.div(ZZ(5), ZZ(2))
(2, 1)

If ``K`` is a :py:class:`~.Field` then the division is always exact
with a remainder of :py:attr:`~.Domain.zero`.

>>> QQ.div(QQ(5), QQ(2))
(5/2, 0)

Parameters
==========

a: domain element
    The dividend
b: domain element
    The divisor

Returns
=======

(q, r): tuple of domain elements
    The quotient and remainder

Raises
======

ZeroDivisionError: when the divisor is zero.

See also
========

quo: Analogue of ``a // b``
rem: Analogue of ``a % b``
exquo: Analogue of ``a / b``

Notes
=====

If ``gmpy`` is installed then the ``gmpy.mpq`` type will be used as
the :py:attr:`~.Domain.dtype` for :ref:`QQ`. The ``gmpy.mpq`` type
defines ``divmod`` in a way that is undesirable so
:py:meth:`~.Domain.div` should be used instead of ``divmod``.

>>> a = QQ(1)
>>> b = QQ(3, 2)
>>> a               # doctest: +SKIP
mpq(1,1)
>>> b               # doctest: +SKIP
mpq(3,2)
>>> divmod(a, b)    # doctest: +SKIP
(mpz(0), mpq(1,1))
>>> QQ.div(a, b)    # doctest: +SKIP
(mpq(2,3), mpq(0,1))

Using ``//`` or ``%`` with :ref:`QQ` will lead to incorrect results so
:py:meth:`~.Domain.div` should be used instead.

r   rX  s   &&&r   div
Domain.div  s    h "!r"   c                    \         h)z5Returns inversion of ``a mod b``, implies something. r   rX  s   &&&r   invertDomain.invert  r2  r"   c                    \         h)z!Returns ``a**(-1)`` if possible. r   ri   s   &&r   revertDomain.revert  r2  r"   c                    \         h)zReturns numerator of ``a``. r   ri   s   &&r   numerDomain.numer  r2  r"   c                    \         h)zReturns denominator of ``a``. r   ri   s   &&r   denomDomain.denom  r2  r"   c                0    V P                  W4      w  r4pW53# )z&Half extended GCD of ``a`` and ``b``. )gcdex)r   rj   rY  sths   &&&   r   
half_gcdexDomain.half_gcdex  s    **Q"atr"   c                    \         h)z!Extended GCD of ``a`` and ``b``. r   rX  s   &&&r   r  Domain.gcdex
  r2  r"   c                p    V P                  W4      pV P                  W4      pV P                  W#4      pW4V3# )z.Returns GCD and cofactors of ``a`` and ``b``. )gcdrj  )r   rj   rY  r  cfacfbs   &&&   r   	cofactorsDomain.cofactors  s5    hhqnhhqhhq}r"   c                    \         h)z Returns GCD of ``a`` and ``b``. r   rX  s   &&&r   r  
Domain.gcd  r2  r"   c                    \         h)z Returns LCM of ``a`` and ``b``. r   rX  s   &&&r   lcm
Domain.lcm  r2  r"   c                    \         h)z#Returns b-base logarithm of ``a``. r   rX  s   &&&r   log
Domain.log  r2  r"   c                    \         h)a  Returns a (possibly inexact) square root of ``a``.

Explanation
===========
There is no universal definition of "inexact square root" for all
domains. It is not recommended to implement this method for domains
other then :ref:`ZZ`.

See also
========
exsqrt
r   ri   s   &&r   sqrtDomain.sqrt!  rl  r"   c                    \         h)a>  Returns whether ``a`` is a square in the domain.

Explanation
===========
Returns ``True`` if there is an element ``b`` in the domain such that
``b * b == a``, otherwise returns ``False``. For inexact domains like
:ref:`RR` and :ref:`CC`, a tiny difference in this equality can be
tolerated.

See also
========
exsqrt
r   ri   s   &&r   	is_squareDomain.is_square0  s
     "!r"   c                    \         h)a  Principal square root of a within the domain if ``a`` is square.

Explanation
===========
The implementation of this method should return an element ``b`` in the
domain such that ``b * b == a``, or ``None`` if there is no such ``b``.
For inexact domains like :ref:`RR` and :ref:`CC`, a tiny difference in
this equality can be tolerated. The choice of a "principal" square root
should follow a consistent rule whenever possible.

See also
========
sqrt, is_square
r   ri   s   &&r   exsqrtDomain.exsqrt@  s
     "!r"   c                F    V P                  V4      P                  ! V3/ VB # )z*Returns numerical approximation of ``a``. )rn   evalf)r   rj   r   optionss   &&&,r   r  Domain.evalfQ  s!    }}Q%%d6g66r"   c                	    V# r   rx   ri   s   &&r   realDomain.realW  s    r"   c                	    V P                   # r   )r   ri   s   &&r   imagDomain.imagZ  s    yyr"   c                
    W8H  # )z+Check if ``a`` and ``b`` are almost equal. rx   )r   rj   rY  	tolerances   &&&&r   almosteqDomain.almosteq]  s	    vr"   c                    \        R4      h)z*Return the characteristic of this domain. zcharacteristic()r   r   s   &r   r   Domain.characteristica  s    !"455r"   rx   r   )N)FzetaNr  )r-   
__module____qualname____firstlineno____doc__r   __annotations__r   r   is_Ringr   r   has_assoc_Fieldis_FiniteFieldis_FFr   is_ZZr   is_QQr   is_ZZ_Ir   is_QQ_Ir   is_RRr   is_CCr   is_Algebraicr   is_Polyr   is_Fracis_SymbolicDomainr   is_SymbolicRawDomainr   r   is_Exactr_   r4  r   is_PIDr   r   r   r    r$   r(   r.   r4   propertyr8   r;   r>   rL   r`   rX   rk   rn   rb   rt   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
   r  r  r  r  r  r%  r-  r0  r   r7  r:  r=  rA  rD  rH  rK  rN  rQ  rU  rZ  r^  ra  rd  rg  rj  rn  rq  rt  rw  rz  r}  r  r  r  r  r  r  r  r  r  r  r*  r  r  r  r   __static_attributes__rx   r"   r   r   r      s   hT E;, D# CO G$ H" N  O  #"NU""NU$$u %%Og!&&w  L5##Oe',,"''!&&w %%&++8HLILF" #CE:";!  !r"AdF,	["z"8*,
/# .
,+BBG
!
HI+4 4
3 3
8
7
J J(8T(?T""Y"v""T"l""""
"""""" ""7 	A6r"   r   N)r  
__future__r   typingr   sympy.core.numbersr   
sympy.corer   r   sympy.core.sortingr   sympy.external.gmpyr   !sympy.polys.domains.domainelementr	   sympy.polys.orderingsr
   sympy.polys.polyerrorsr   r   r   sympy.polys.polyutilsr   r   sympy.utilitiesr   sympy.utilities.iterablesr   r   __all__rx   r"   r   <module>r     sU    / "  . % & , ; % Q Q ; " 1 P6 P6 P6f* *r"   