ó
    Š*£hŽL  ã                  óJ  • 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
  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  SSKJr   " S S\5      r " S S\5      r " S S\5      r " S S5      r " S S\\5      r\" 5       =r\l         " S S\\5      r\" 5       =r\l        g)zDomains of Gaussian type.é    )Úannotations)ÚI)ÚDMP)ÚCoercionFailed)ÚZZ)ÚQQ)ÚAlgebraicField)ÚDomain)ÚDomainElement)ÚField)ÚRingc                  óð   ^ • \ rS rSr% SrS\S'   S\S'   SrS S jr\U 4S j5       r	S	 r
S
 rS rS rS rS rS rS r\S 5       rS r\rS rS rS r\rS rS rS rS rS rS rS rS r S r!Sr"U =r#$ )!ÚGaussianElementé   z1Base class for elements of Gaussian type domains.r
   ÚbaseÚ_parent)ÚxÚyc                ój   • U R                   R                  nU R                  U" U5      U" U5      5      $ ©N)r   ÚconvertÚnew)Úclsr   r   Úconvs       Ú`/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/polys/domains/gaussiandomains.pyÚ__new__ÚGaussianElement.__new__   s*   € Ø�x‰x×ÑˆØ�w‰w‘t˜A“w¡ Q£Ó(Ð(ó    c                ó>   >• [         TU ]  U 5      nXl        X#l        U$ )z0Create a new GaussianElement of the same domain.)Úsuperr   r   r   )r   r   r   ÚobjÚ	__class__s       €r   r   ÚGaussianElement.new   s"   ø€ ô ‰g‰o˜cÓ"ˆØŒØŒØˆ
r   c                ó   • U R                   $ )z4The domain that this is an element of (ZZ_I or QQ_I))r   ©Úselfs    r   ÚparentÚGaussianElement.parent#   s   € à�|‰|Ðr   c                óD   • [        U R                  U R                  45      $ r   )Úhashr   r   r%   s    r   Ú__hash__ÚGaussianElement.__hash__'   s   € Ü�T—V‘V˜TŸV™VÐ$Ó%Ð%r   c                ó´   • [        XR                  5      (       a9  U R                  UR                  :H  =(       a    U R                  UR                  :H  $ [        $ r   )Ú
isinstancer"   r   r   ÚNotImplemented©r&   Úothers     r   Ú__eq__ÚGaussianElement.__eq__*   s<   € Ü�eŸ^™^×,Ñ,Ø—6‘6˜UŸW™WÑ$×:¨¯©°5·7±7Ñ):Ð:ä!Ð!r   c                óš   • [        U[        5      (       d  [        $ U R                  U R                  /UR                  UR                  /:  $ r   )r.   r   r/   r   r   r0   s     r   Ú__lt__ÚGaussianElement.__lt__0   s:   € Ü˜%¤×1Ñ1Ü!Ð!Ø—‘˜Ÿ™Ð 5§7¡7¨E¯G©GÐ"4Ñ4Ð4r   c                ó   • U $ r   © r%   s    r   Ú__pos__ÚGaussianElement.__pos__5   s   € Øˆr   c                óR   • U R                  U R                  * U R                  * 5      $ r   ©r   r   r   r%   s    r   Ú__neg__ÚGaussianElement.__neg__8   s   € Ø�x‰x˜Ÿ™˜ $§&¡& Ó)Ð)r   c                ón   • U R                   R                  < SU R                  < SU R                  < S3$ )NÚ(z, Ú))r   Úrepr   r   r%   s    r   Ú__repr__ÚGaussianElement.__repr__;   s!   € Ø#Ÿ|™|×/Ô/°·´¸¿¼Ð@Ð@r   c                óJ   • [        U R                  R                  U 5      5      $ r   )Ústrr   Úto_sympyr%   s    r   Ú__str__ÚGaussianElement.__str__>   s   € Ü�4—<‘<×(Ñ(¨Ó.Ó/Ð/r   c                óª   • [        X5      (       d   U R                  R                  U5      nUR                  UR
                  4$ ! [         a     gf = f)N)NN)r.   r   r   r   r   r   )r   r1   s     r   Ú_get_xyÚGaussianElement._get_xyA   sO   € ä˜%×%Ñ%ð"ØŸ™×+Ñ+¨EÓ2�ð �w‰w˜Ÿ™ÐÐøô "ó "Ù!ð"ús   ’A Á
AÁAc                ó’   • U R                  U5      u  p#Ub,  U R                  U R                  U-   U R                  U-   5      $ [        $ r   ©rK   r   r   r   r/   ©r&   r1   r   r   s       r   Ú__add__ÚGaussianElement.__add__J   ó>   € Ø�|‰|˜EÓ"‰ˆØ‰=Ø—8‘8˜DŸF™F Q™J¨¯©°©
Ó3Ð3ä!Ð!r   c                ó’   • U R                  U5      u  p#Ub,  U R                  U R                  U-
  U R                  U-
  5      $ [        $ r   rN   rO   s       r   Ú__sub__ÚGaussianElement.__sub__S   rR   r   c                óŽ   • U R                  U5      u  p#Ub*  U R                  X R                  -
  X0R                  -
  5      $ [        $ r   rN   rO   s       r   Ú__rsub__ÚGaussianElement.__rsub__Z   s:   € Ø�|‰|˜EÓ"‰ˆØ‰=Ø—8‘8˜A§¡™J¨¯F©F©
Ó3Ð3ä!Ð!r   c                óÒ   • U R                  U5      u  p#UbL  U R                  U R                  U-  U R                  U-  -
  U R                  U-  U R                  U-  -   5      $ [        $ r   rN   rO   s       r   Ú__mul__ÚGaussianElement.__mul__a   sX   € Ø�|‰|˜EÓ"‰ˆØ‰=Ø—8‘8˜DŸF™F 1™H t§v¡v¨a¡xÑ/°·±¸±¸D¿F¹FÀ1¹HÑ1DÓEÐEä!Ð!r   c                ó   • US:X  a  U R                  SS5      $ US:  a  SU -  U* pUS:X  a  U $ U nUS-  (       a  U OU R                  R                  nUS-  nU(       a   X"-  nUS-  (       a  X2-  nUS-  nU(       a  M   U$ )Nr   é   é   )r   r   Úone)r&   ÚexpÚpow2Úprods       r   Ú__pow__ÚGaussianElement.__pow__j   s�   € Ø�!‹8Ø—8‘8˜A˜q“>Ð!Ø�‹7Ø˜$™  �#Ø�!‹8ØˆKØˆØ˜Q—w‰t D§L¡L×$4Ñ$4ˆØ�‰	ˆÞØ‰LˆDØ�Q�wØ‘�Ø�A‰IˆC÷	 ˆcð
 ˆr   c                ód   • [        U R                  5      =(       d    [        U R                  5      $ r   )Úboolr   r   r%   s    r   Ú__bool__ÚGaussianElement.__bool__{   s   € Ü�D—F‘F‹|×+œt D§F¡F›|Ð+r   c                óº   • U R                   S:”  a  U R                  S:”  a  S$ S$ U R                   S:  a  U R                  S:  a  S$ S$ U R                  S:¼  a  S$ S$ )z9Return quadrant index 0-3.

0 is included in quadrant 0.
r   r]   r^   é   )r   r   r%   s    r   ÚquadrantÚGaussianElement.quadrant~   sY   € ð
 �6‰6�A‹:ØŸ™ ›
�1Ð)¨Ð)Ø�V‰V�a‹ZØŸ™ ›
�1Ð)¨Ð)àŸ™ !›�1Ð*¨Ð*r   c                óˆ   •  U R                   R                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr   )r   r   Ú
__divmod__r   r/   r0   s     r   Ú__rdivmod__ÚGaussianElement.__rdivmod__Š   sE   € ð	*Ø—L‘L×(Ñ(¨Ó/ˆEð ×#Ñ# DÓ)Ð)øô ó 	"Ü!Ò!ð	"ús   ‚. ®AÁ Ac                ó|   •  [         R                  U5      nUR                  U 5      $ ! [         a	    [        s $ f = fr   )ÚQQ_Ir   Ú__truediv__r   r/   r0   s     r   Ú__rtruediv__ÚGaussianElement.__rtruediv__’   s?   € ð	+Ü—L‘L Ó'ˆEð ×$Ñ$ TÓ*Ð*øô ó 	"Ü!Ò!ð	"ús   ‚( ¨;º;c                óD   • U R                  U5      nU[        L a  U$ US   $ ©Nr   ©rn   r/   ©r&   r1   Úqrs      r   Ú__floordiv__ÚGaussianElement.__floordiv__š   ó&   € Ø�_‰_˜UÓ#ˆØœ>Ò)ˆrÐ4¨r°!©uÐ4r   c                óD   • U R                  U5      nU[        L a  U$ US   $ rw   ©ro   r/   ry   s      r   Ú__rfloordiv__ÚGaussianElement.__rfloordiv__ž   ó(   € Ø×Ñ˜eÓ$ˆØœ>Ò)ˆrÐ4¨r°!©uÐ4r   c                óD   • U R                  U5      nU[        L a  U$ US   $ ©Nr]   rx   ry   s      r   Ú__mod__ÚGaussianElement.__mod__¢   r}   r   c                óD   • U R                  U5      nU[        L a  U$ US   $ r„   r   ry   s      r   Ú__rmod__ÚGaussianElement.__rmod__¦   r‚   r   r8   )r   )$Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú__annotations__Ú	__slots__r   Úclassmethodr   r'   r+   r2   r5   r9   r=   rC   rH   rK   rP   Ú__radd__rT   rW   rZ   Ú__rmul__rc   rg   rk   ro   rt   r{   r€   r…   rˆ   Ú__static_attributes__Ú__classcell__)r"   s   @r   r   r      s¿   ø‡ Ù;Ø
ƒLØƒOà€Iô)ð ôó ðòò&ò"ò5ò
ò*òAò0ð ñ ó ð ò"ð €Hò"ò"ò"ð €Hòò",ò
+ò*ò+ò5ò5ò5÷5ð 5r   r   c                  ó(   • \ rS rSrSr\rS rS rSr	g)ÚGaussianIntegeré«   zºGaussian integer: domain element for :ref:`ZZ_I`

>>> from sympy import ZZ_I
>>> z = ZZ_I(2, 3)
>>> z
(2 + 3*I)
>>> type(z)
<class 'sympy.polys.domains.gaussiandomains.GaussianInteger'>
c                ó2   • [         R                  U 5      U-  $ )úReturn a Gaussian rational.)rr   r   r0   s     r   rs   ÚGaussianInteger.__truediv__·   s   € ä�|‰|˜DÓ! %Ñ'Ð'r   c                óh  • U(       d  [        SR                  U 5      5      eU R                  U5      u  p#Uc  [        $ U R                  U-  U R
                  U-  -   U R                  * U-  U R
                  U-  -   pTX"-  X3-  -   nSU-  U-   SU-  -  nSU-  U-   SU-  -  n[        Xx5      n	X�X‘-  -
  4$ )Nzdivmod({}, 0)r^   )ÚZeroDivisionErrorÚformatrK   r/   r   r   r—   )
r&   r1   r   r   ÚaÚbÚcÚqxÚqyÚqs
             r   rn   ÚGaussianInteger.__divmod__»   sÁ   € ÞÜ# O×$:Ñ$:¸4Ó$@ÓAÐAØ�|‰|˜EÓ"‰ˆØ‰9Ü!Ð!ð �v‰v�a‰x˜$Ÿ&™& ™(Ñ" T§V¡V G¨A¡I°·±°q±Ñ$8ˆ1Ø‰C�!‘#‰Iˆð �‰c�A‰g˜1˜Q™3ÑˆØ�‰c�A‰g˜1˜Q™3Ñˆä˜BÓ#ˆð ˜™‘.Ð Ð r   r8   N)
rŠ   r‹   rŒ   r�   rŽ   r   r   rs   rn   r”   r8   r   r   r—   r—   «   s   † ñð €Dò(õ!r   r—   c                  ó(   • \ rS rSrSr\rS rS rSr	g)ÚGaussianRationaléÓ   zÒGaussian rational: domain element for :ref:`QQ_I`

>>> from sympy import QQ_I, QQ
>>> z = QQ_I(QQ(2, 3), QQ(4, 5))
>>> z
(2/3 + 4/5*I)
>>> type(z)
<class 'sympy.polys.domains.gaussiandomains.GaussianRational'>
c                ó(  • U(       d  [        SR                  U 5      5      eU R                  U5      u  p#Uc  [        $ X"-  X3-  -   n[	        U R
                  U-  U R                  U-  -   U-  U R
                  * U-  U R                  U-  -   U-  5      $ )rš   z{} / 0)r�   rž   rK   r/   r§   r   r   )r&   r1   r   r   r¡   s        r   rs   ÚGaussianRational.__truediv__ß   s‰   € æÜ# H§O¡O°DÓ$9Ó:Ð:Ø�|‰|˜EÓ"‰ˆØ‰9Ü!Ð!Ø‰C�!‘#‰Iˆä §¡¨¡¨D¯F©F°1©HÑ!4°aÑ 7Ø"&§&¡& ¨¡¨T¯V©V°A©XÑ!5°qÑ 8ó:ð 	:r   c                óÐ   •  U R                   R                  U5      nU(       d  [	        SR                  U 5      5      eX-  [        R                  4$ ! [         a	    [        s $ f = f)Nz{} % 0)r   r   r   r/   r�   rž   rr   Úzeror0   s     r   rn   ÚGaussianRational.__divmod__ë   s\   € ð	"Ø—L‘L×(Ñ(¨Ó/ˆEö Ü# H§O¡O°DÓ$9Ó:Ð:à‘:œtŸy™yÐ(Ð(øô ó 	"Ü!Ò!ð	"ús   ‚A ÁA%Á$A%r8   N)
rŠ   r‹   rŒ   r�   rŽ   r   r   rs   rn   r”   r8   r   r   r§   r§   Ó   s   † ñð €Dò
:õ)r   r§   c                  óŽ   • \ rS rSr% SrS\S'   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)ÚGaussianDomainéö   z Base class for Gaussian domains.r
   ÚdomTc                ó†   • U R                   R                  nU" UR                  5      [        U" UR                  5      -  -   $ )z!Convert ``a`` to a SymPy object. )r±   rG   r   r   r   )r&   rŸ   r   s      r   rG   ÚGaussianDomain.to_sympy   s0   € à�x‰x× Ñ ˆÙ�A—C‘C‹yœ1™T !§#¡#›Y™;Ñ&Ð&r   c                óP  • UR                  5       u  p#U R                  R                  U5      nU(       d  U R                  US5      $ UR	                  5       u  p#U R                  R                  U5      nU[
        L a  U R                  XE5      $ [        SR                  U5      5      e)z)Convert a SymPy object to ``self.dtype``.r   z{} is not Gaussian)Úas_coeff_Addr±   Ú
from_sympyr   Úas_coeff_Mulr   r   rž   )r&   rŸ   Úrr    r   r   s         r   r¶   ÚGaussianDomain.from_sympy  s…   € à�~‰~Ó‰ˆØ�H‰H×Ñ Ó"ˆÞØ—8‘8˜A˜q“>Ð!Ø�~‰~Ó‰ˆØ�H‰H×Ñ Ó"ˆØ”Š6Ø—8‘8˜A“>Ð!ä Ð!5×!<Ñ!<¸QÓ!?Ó@Ð@r   c                ó    • U R                   " U6 $ )z$Inject generators into this domain. )Ú	poly_ring)r&   Úgenss     r   ÚinjectÚGaussianDomain.inject  s   € à�~Š~˜tÐ$Ð$r   c                óB   • U R                   UR                  5       *    nU$ r   )Úunitsrk   )r&   ÚdÚunits      r   Úcanonical_unitÚGaussianDomain.canonical_unit  s   € Ø�z‰z˜1Ÿ:™:›<˜-Ñ(ˆØˆr   c                ó   • g©z/Returns ``False`` for any ``GaussianElement``. Fr8   ©r&   Úelements     r   Úis_negativeÚGaussianDomain.is_negative  ó   € àr   c                ó   • grÆ   r8   rÇ   s     r   Úis_positiveÚGaussianDomain.is_positive  rË   r   c                ó   • grÆ   r8   rÇ   s     r   Úis_nonnegativeÚGaussianDomain.is_nonnegative"  rË   r   c                ó   • grÆ   r8   rÇ   s     r   Úis_nonpositiveÚGaussianDomain.is_nonpositive&  rË   r   c                ó   • U " U5      $ )z%Convert a GMPY mpz to ``self.dtype``.r8   ©ÚK1rŸ   ÚK0s      r   Úfrom_ZZ_gmpyÚGaussianDomain.from_ZZ_gmpy*  ó   € á�!‹uˆr   c                ó   • U " U5      $ ©z.Convert a ZZ_python element to ``self.dtype``.r8   rÖ   s      r   Úfrom_ZZÚGaussianDomain.from_ZZ.  rÛ   r   c                ó   • U " U5      $ rÝ   r8   rÖ   s      r   Úfrom_ZZ_pythonÚGaussianDomain.from_ZZ_python2  rÛ   r   c                ó   • U " U5      $ ©z%Convert a GMPY mpq to ``self.dtype``.r8   rÖ   s      r   Úfrom_QQÚGaussianDomain.from_QQ6  rÛ   r   c                ó   • U " U5      $ rä   r8   rÖ   s      r   Úfrom_QQ_gmpyÚGaussianDomain.from_QQ_gmpy:  rÛ   r   c                ó   • U " U5      $ )z.Convert a QQ_python element to ``self.dtype``.r8   rÖ   s      r   Úfrom_QQ_pythonÚGaussianDomain.from_QQ_python>  rÛ   r   c                ó†   • UR                   R                  S   [        :X  a   U R                  UR	                  U5      5      $ g)z9Convert an element from ZZ<I> or QQ<I> to ``self.dtype``.r   N)ÚextÚargsr   r¶   rG   rÖ   s      r   Úfrom_AlgebraicFieldÚ"GaussianDomain.from_AlgebraicFieldB  s2   € à�6‰6�;‰;�q‰>œQÓØ—=‘= §¡¨Q£Ó0Ð0ð r   r8   N)rŠ   r‹   rŒ   r�   rŽ   r�   Úis_NumericalÚis_ExactÚhas_assoc_RingÚhas_assoc_FieldrG   r¶   r½   rÃ   rÉ   rÍ   rÐ   rÓ   rÙ   rÞ   rá   rå   rè   rë   rð   r”   r8   r   r   r¯   r¯   ö   sj   ‡ Ù*Ø	ƒKà€LØ€Hà€NØ€Oò'ò
Aò%òòòòòòòòòòòõ1r   r¯   c                  ój  • \ rS rSrSr\r\" \R                  \R                  \R                  /\5      r
\r\" \" S5      \" S5      5      r	\" \" S5      \" S5      5      r\" \" S5      \" S5      5      r\\\* \* 4rSrSrSrSrS rS rS	 r\S
 5       rS rS rS rS rS rS rS rS rS r Sr!g)ÚGaussianIntegerRingiH  a?	  Ring of Gaussian integers ``ZZ_I``

The :ref:`ZZ_I` domain represents the `Gaussian integers`_ `\mathbb{Z}[i]`
as a :py:class:`~.Domain` in the domain system (see
:ref:`polys-domainsintro`).

By default a :py:class:`~.Poly` created from an expression with
coefficients that are combinations of integers and ``I`` (`\sqrt{-1}`)
will have the domain :ref:`ZZ_I`.

>>> from sympy import Poly, Symbol, I
>>> x = Symbol('x')
>>> p = Poly(x**2 + I)
>>> p
Poly(x**2 + I, x, domain='ZZ_I')
>>> p.domain
ZZ_I

The :ref:`ZZ_I` domain can be used to factorise polynomials that are
reducible over the Gaussian integers.

>>> from sympy import factor
>>> factor(x**2 + 1)
x**2 + 1
>>> factor(x**2 + 1, domain='ZZ_I')
(x - I)*(x + I)

The corresponding `field of fractions`_ is the domain of the Gaussian
rationals :ref:`QQ_I`. Conversely :ref:`ZZ_I` is the `ring of integers`_
of :ref:`QQ_I`.

>>> from sympy import ZZ_I, QQ_I
>>> ZZ_I.get_field()
QQ_I
>>> QQ_I.get_ring()
ZZ_I

When using the domain directly :ref:`ZZ_I` can be used as a constructor.

>>> ZZ_I(3, 4)
(3 + 4*I)
>>> ZZ_I(5)
(5 + 0*I)

The domain elements of :ref:`ZZ_I` are instances of
:py:class:`~.GaussianInteger` which support the rings operations
``+,-,*,**``.

>>> z1 = ZZ_I(5, 1)
>>> z2 = ZZ_I(2, 3)
>>> z1
(5 + 1*I)
>>> z2
(2 + 3*I)
>>> z1 + z2
(7 + 4*I)
>>> z1 * z2
(7 + 17*I)
>>> z1 ** 2
(24 + 10*I)

Both floor (``//``) and modulo (``%``) division work with
:py:class:`~.GaussianInteger` (see the :py:meth:`~.Domain.div` method).

>>> z3, z4 = ZZ_I(5), ZZ_I(1, 3)
>>> z3 // z4  # floor division
(1 + -1*I)
>>> z3 % z4   # modulo division (remainder)
(1 + -2*I)
>>> (z3//z4)*z4 + z3%z4 == z3
True

True division (``/``) in :ref:`ZZ_I` gives an element of :ref:`QQ_I`. The
:py:meth:`~.Domain.exquo` method can be used to divide in :ref:`ZZ_I` when
exact division is possible.

>>> z1 / z2
(1 + -1*I)
>>> ZZ_I.exquo(z1, z2)
(1 + -1*I)
>>> z3 / z4
(1/2 + -3/2*I)
>>> ZZ_I.exquo(z3, z4)
Traceback (most recent call last):
    ...
ExactQuotientFailed: (1 + 3*I) does not divide (5 + 0*I) in ZZ_I

The :py:meth:`~.Domain.gcd` method can be used to compute the `gcd`_ of any
two elements.

>>> ZZ_I.gcd(ZZ_I(10), ZZ_I(2))
(2 + 0*I)
>>> ZZ_I.gcd(ZZ_I(5), ZZ_I(2, 1))
(2 + 1*I)

.. _Gaussian integers: https://en.wikipedia.org/wiki/Gaussian_integer
.. _gcd: https://en.wikipedia.org/wiki/Greatest_common_divisor

r   r]   ÚZZ_ITc                ó   • g)zFor constructing ZZ_I.Nr8   r%   s    r   Ú__init__ÚGaussianIntegerRing.__init__º  ó   � r   c                ó:   • [        U[        5      (       a  g[        $ ©z0Returns ``True`` if two domains are equivalent. T)r.   r÷   r/   r0   s     r   r2   ÚGaussianIntegerRing.__eq__½  s   € ä�eÔ0×1Ñ1Øä!Ð!r   c                ó   • [        S5      $ )úCompute hash code of ``self``. rø   ©r*   r%   s    r   r+   ÚGaussianIntegerRing.__hash__Ä  ó   € ä�F‹|Ðr   c                ó   • g©NTr8   r%   s    r   Úhas_CharacteristicZeroÚ*GaussianIntegerRing.has_CharacteristicZeroÈ  ó   € àr   c                ó   • grw   r8   r%   s    r   ÚcharacteristicÚ"GaussianIntegerRing.characteristicÌ  ó   € Ør   c                ó   • U $ ©z)Returns a ring associated with ``self``. r8   r%   s    r   Úget_ringÚGaussianIntegerRing.get_ringÏ  ó   € àˆr   c                ó   • [         $ ©z*Returns a field associated with ``self``. )rr   r%   s    r   Ú	get_fieldÚGaussianIntegerRing.get_fieldÓ  ó   € äˆr   c                óx   ^• U R                  U5      mUT-  n[        U4S jU 5       5      nU(       a  U4U-   $ U$ )zpReturn first quadrant element associated with ``d``.

Also multiply the other arguments by the same power of i.
c              3  ó,   >#   • U  H	  oT-  v •  M     g 7fr   r8   )Ú.0rŸ   rÂ   s     €r   Ú	<genexpr>Ú0GaussianIntegerRing.normalize.<locals>.<genexpr>Þ  s   øé € Ð*¢T �t–V¢Tùs   ƒ)rÃ   Útuple)r&   rÁ   rï   rÂ   s      @r   Ú	normalizeÚGaussianIntegerRing.normalize×  sA   ø€ ð
 ×"Ñ" 1Ó%ˆØ	ˆT‰	ˆÜÔ*¡TÓ*Ó*ˆÞ"�ˆt�d‰{Ð)¨Ð)r   c                óN   • U(       a  X!U-  p!U(       a  M  U R                  U5      $ )z-Greatest common divisor of a and b over ZZ_I.)r  ©r&   rŸ   r    s      r   ÚgcdÚGaussianIntegerRing.gcdá  s$   € æØ˜!‘eˆq÷ ˆaà�~‰~˜aÓ Ð r   c                óæ   • U R                   nU R                  nU R                  nU R                   nU(       a"  X-  nX!Xr-  -
  p!XCXt-  -
  pCXeXv-  -
  peU(       a  M"  U R                  XU5      u  pnX5U4$ )z6Return x, y, g such that x * a + y * b = g = gcd(a, b))r_   r¬   r  )r&   rŸ   r    Úx_aÚx_bÚy_aÚy_br¤   s           r   ÚgcdexÚGaussianIntegerRing.gcdexç  sx   € à�h‰hˆØ�i‰iˆØ�i‰iˆØ�h‰hˆÞØ‘ˆAØ˜!™%‘iˆqØ !¡'™M�Ø !¡'™M�÷	 ˆað —n‘n Q¨SÓ1‰ˆ�Ø˜ˆ{Ðr   c                ó.   • X-  U R                  X5      -  $ )z+Least common multiple of a and b over ZZ_I.)r"  r!  s      r   ÚlcmÚGaussianIntegerRing.lcmö  s   € à‘˜$Ÿ(™( 1›.Ñ(Ð(r   c                ó   • U$ )zConvert a ZZ_I element to ZZ_I.r8   rÖ   s      r   Úfrom_GaussianIntegerRingÚ,GaussianIntegerRing.from_GaussianIntegerRingú  ó   € àˆr   c                óž   • U R                  [        R                  " UR                  5      [        R                  " UR                  5      5      $ )zConvert a QQ_I element to ZZ_I.)r   r   r   r   r   rÖ   s      r   Úfrom_GaussianRationalFieldÚ.GaussianIntegerRing.from_GaussianRationalFieldþ  s+   € à�v‰v”b—j’j §¡“o¤r§z¢z°!·#±#£Ó7Ð7r   r8   N)"rŠ   r‹   rŒ   r�   rŽ   r   r±   r   r_   r¬   Úmodr—   ÚdtypeÚ	imag_unitrÀ   rB   Úis_GaussianRingÚis_ZZ_IÚis_PIDrú   r2   r+   Úpropertyr  r  r  r  r  r"  r)  r,  r/  r3  r”   r8   r   r   r÷   r÷   H  sæ   † ñbðF €CÙ
ˆr�v‰v�r—w‘w §¡Ð'¨Ó
,€CØ€EÙ‘�A“™˜1›Ó€DÙ
‘�1“‘r˜!“uÓ
€CÙ‘b˜“e™R ›UÓ#€IØ�)˜c˜T I :Ð.€Eà
€Cà€OØ€GØ€Fò%ò"òð ñó ðòòòò*ò!òò)òõ8r   r÷   c                  óf  • \ rS rSrSr\r\" \R                  \R                  \R                  /\5      r
\r\" \" S5      \" S5      5      r	\" \" S5      \" S5      5      r\" \" S5      \" S5      5      r\\\* \* 4rSrSrSrS rS rS	 r\S
 5       rS rS rS rS rS rS rS rS rS rSr g)ÚGaussianRationalFieldi  a  Field of Gaussian rationals ``QQ_I``

The :ref:`QQ_I` domain represents the `Gaussian rationals`_ `\mathbb{Q}(i)`
as a :py:class:`~.Domain` in the domain system (see
:ref:`polys-domainsintro`).

By default a :py:class:`~.Poly` created from an expression with
coefficients that are combinations of rationals and ``I`` (`\sqrt{-1}`)
will have the domain :ref:`QQ_I`.

>>> from sympy import Poly, Symbol, I
>>> x = Symbol('x')
>>> p = Poly(x**2 + I/2)
>>> p
Poly(x**2 + I/2, x, domain='QQ_I')
>>> p.domain
QQ_I

The polys option ``gaussian=True`` can be used to specify that the domain
should be :ref:`QQ_I` even if the coefficients do not contain ``I`` or are
all integers.

>>> Poly(x**2)
Poly(x**2, x, domain='ZZ')
>>> Poly(x**2 + I)
Poly(x**2 + I, x, domain='ZZ_I')
>>> Poly(x**2/2)
Poly(1/2*x**2, x, domain='QQ')
>>> Poly(x**2, gaussian=True)
Poly(x**2, x, domain='QQ_I')
>>> Poly(x**2 + I, gaussian=True)
Poly(x**2 + I, x, domain='QQ_I')
>>> Poly(x**2/2, gaussian=True)
Poly(1/2*x**2, x, domain='QQ_I')

The :ref:`QQ_I` domain can be used to factorise polynomials that are
reducible over the Gaussian rationals.

>>> from sympy import factor, QQ_I
>>> factor(x**2/4 + 1)
(x**2 + 4)/4
>>> factor(x**2/4 + 1, domain='QQ_I')
(x - 2*I)*(x + 2*I)/4
>>> factor(x**2/4 + 1, domain=QQ_I)
(x - 2*I)*(x + 2*I)/4

It is also possible to specify the :ref:`QQ_I` domain explicitly with
polys functions like :py:func:`~.apart`.

>>> from sympy import apart
>>> apart(1/(1 + x**2))
1/(x**2 + 1)
>>> apart(1/(1 + x**2), domain=QQ_I)
I/(2*(x + I)) - I/(2*(x - I))

The corresponding `ring of integers`_ is the domain of the Gaussian
integers :ref:`ZZ_I`. Conversely :ref:`QQ_I` is the `field of fractions`_
of :ref:`ZZ_I`.

>>> from sympy import ZZ_I, QQ_I, QQ
>>> ZZ_I.get_field()
QQ_I
>>> QQ_I.get_ring()
ZZ_I

When using the domain directly :ref:`QQ_I` can be used as a constructor.

>>> QQ_I(3, 4)
(3 + 4*I)
>>> QQ_I(5)
(5 + 0*I)
>>> QQ_I(QQ(2, 3), QQ(4, 5))
(2/3 + 4/5*I)

The domain elements of :ref:`QQ_I` are instances of
:py:class:`~.GaussianRational` which support the field operations
``+,-,*,**,/``.

>>> z1 = QQ_I(5, 1)
>>> z2 = QQ_I(2, QQ(1, 2))
>>> z1
(5 + 1*I)
>>> z2
(2 + 1/2*I)
>>> z1 + z2
(7 + 3/2*I)
>>> z1 * z2
(19/2 + 9/2*I)
>>> z2 ** 2
(15/4 + 2*I)

True division (``/``) in :ref:`QQ_I` gives an element of :ref:`QQ_I` and
is always exact.

>>> z1 / z2
(42/17 + -2/17*I)
>>> QQ_I.exquo(z1, z2)
(42/17 + -2/17*I)
>>> z1 == (z1/z2)*z2
True

Both floor (``//``) and modulo (``%``) division can be used with
:py:class:`~.GaussianRational` (see :py:meth:`~.Domain.div`)
but division is always exact so there is no remainder.

>>> z1 // z2
(42/17 + -2/17*I)
>>> z1 % z2
(0 + 0*I)
>>> QQ_I.div(z1, z2)
((42/17 + -2/17*I), (0 + 0*I))
>>> (z1//z2)*z2 + z1%z2 == z1
True

.. _Gaussian rationals: https://en.wikipedia.org/wiki/Gaussian_rational
r   r]   rr   Tc                ó   • g)zFor constructing QQ_I.Nr8   r%   s    r   rú   ÚGaussianRationalField.__init__‡  rü   r   c                ó:   • [        U[        5      (       a  g[        $ rþ   )r.   r=  r/   r0   s     r   r2   ÚGaussianRationalField.__eq__Š  s   € ä�eÔ2×3Ñ3Øä!Ð!r   c                ó   • [        S5      $ )r  rr   r  r%   s    r   r+   ÚGaussianRationalField.__hash__‘  r  r   c                ó   • gr  r8   r%   s    r   r  Ú,GaussianRationalField.has_CharacteristicZero•  r	  r   c                ó   • grw   r8   r%   s    r   r  Ú$GaussianRationalField.characteristic™  r  r   c                ó   • [         $ r  )rø   r%   s    r   r  ÚGaussianRationalField.get_ringœ  r  r   c                ó   • U $ r  r8   r%   s    r   r  ÚGaussianRationalField.get_field   r  r   c                ó6   • [        U R                  [        5      $ )z0Get equivalent domain as an ``AlgebraicField``. )r	   r±   r   r%   s    r   Úas_AlgebraicFieldÚ'GaussianRationalField.as_AlgebraicField¤  s   € ä˜dŸh™h¬Ó*Ð*r   c                óf   • U R                  5       nUR                  XR                  U5      -  5      $ )zGet the numerator of ``a``.)r  r   Údenom)r&   rŸ   rø   s      r   ÚnumerÚGaussianRationalField.numer¨  s'   € à�}‰}‹ˆØ�|‰|˜A§
¡
¨1£Ñ-Ó.Ð.r   c                ó   • U R                   R                  5       nU R                   nU R                  5       nUR                  " UR                  " UR                  5      UR                  " UR
                  5      5      nU" XRR                  5      $ )zGet the denominator of ``a``.)r±   r  r,  rP  r   r   r¬   )r&   rŸ   r   r   rø   Údenom_ZZs         r   rP  ÚGaussianRationalField.denom­  s_   € à�X‰X×ÑÓ ˆØ�X‰XˆØ�}‰}‹ˆØ—6’6˜"Ÿ(š( 1§3¡3›-¨¯ª°!·#±#«Ó7ˆÙ�HŸg™gÓ&Ð&r   c                óN   • U R                  UR                  UR                  5      $ )zConvert a ZZ_I element to QQ_I.r<   rÖ   s      r   r/  Ú.GaussianRationalField.from_GaussianIntegerRingµ  s   € à�v‰v�a—c‘c˜1Ÿ3™3ÓÐr   c                ó   • U$ )zConvert a QQ_I element to QQ_I.r8   rÖ   s      r   r3  Ú0GaussianRationalField.from_GaussianRationalField¹  r1  r   c                óž   • U R                  [        R                  " UR                  5      [        R                  " UR                  5      5      $ )z'Convert a ComplexField element to QQ_I.)r   r   r   ÚrealÚimagrÖ   s      r   Úfrom_ComplexFieldÚ'GaussianRationalField.from_ComplexField½  s-   € à�v‰v”b—j’j §¡Ó(¬"¯*ª*°Q·V±VÓ*<Ó=Ð=r   r8   N)!rŠ   r‹   rŒ   r�   rŽ   r   r±   r   r_   r¬   r5  r§   r6  r7  rÀ   rB   Úis_GaussianFieldÚis_QQ_Irú   r2   r+   r;  r  r  r  r  rM  rQ  rP  r/  r3  r]  r”   r8   r   r   r=  r=    sâ   † ñsðh €CÙ
ˆr�v‰v�r—w‘w §¡Ð'¨Ó
,€CØ€EÙ‘�A“™˜1›Ó€DÙ
‘�1“‘r˜!“uÓ
€CÙ‘b˜“e™R ›UÓ#€IØ�)˜c˜T I :Ð.€Eà
€CàÐØ€Gò%ò"òð ñó ðòòòò+ò/ò
'ò òõ>r   r=  N) rŽ   Ú
__future__r   Úsympy.core.numbersr   Úsympy.polys.polyclassesr   Úsympy.polys.polyerrorsr   Úsympy.polys.domains.integerringr   Ú!sympy.polys.domains.rationalfieldr   Ú"sympy.polys.domains.algebraicfieldr	   Úsympy.polys.domains.domainr
   Ú!sympy.polys.domains.domainelementr   Úsympy.polys.domains.fieldr   Úsympy.polys.domains.ringr   r   r—   r§   r¯   r÷   rø   r   r=  rr   r8   r   r   Ú<module>rl     s¦   ðÙ å "Ý  Ý 'Ý 1Ý .Ý 0Ý =Ý -Ý ;Ý +Ý )ôX5�mô X5ôv%!�oô %!ôP )�ô  )÷FO1ñ O1ôdx8˜.¨$ô x8ñt "5Ó!6Ð 6€€Ôôz>˜N¨Eô z>ñz #8Ó"9Ð 9€ÐÕr   