K idZddlmZddlmZmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZdd lmZdd lmZeGd d e ee ZeZy )z/Implementation of :class:`ComplexField` class. ) SYMPY_INTS)FloatI)CharacteristicZero)FieldQQ_I) SimpleDomain) DomainErrorCoercionFailed)public) MPContextc.eZdZdZdZdxZZdZdZdZ dZ dZ e dZ e dZe dZe d Zd(d Ze d Zd)d ZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%d Z&d!Z'd"Z(d#Z)d$Z*d*d%Z+d&Z,d'Z-y )+ ComplexFieldz+Complex numbers up to the given precision. CCTF5c4|j|jk(SN) precision_default_precisionselfs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/domains/complexfield.pyhas_default_precisionz"ComplexField.has_default_precision s~~!8!888c.|jjSr)_contextprecrs rrzComplexField.precision$s}}!!!rc.|jjSr)rdpsrs rr zComplexField.dps(s}}   rc|jSr) _tolerancers r tolerancezComplexField.tolerance,s rNct}|||j|_n|||_n|||_n t d||_|j |_|jd|_ |jd|_ td|jzdzd|_ |j|jz |_ y)NzCannot set both prec and dpsrc)rrrr TypeErrorrmpc_dtypedtypezeroonemax _max_denomr")rrr tolcontexts r__init__zComplexField.__init__0s+ >U__3TTrcnt|jj|j|jfSr)hash __class____name__r+rrs r__hash__zComplexField.__hash__^s&T^^,,dkk4>>JKKrct|j|jtt|j|jzzS)z%Convert ``element`` to SymPy number. )rrealr rimagrelements rto_sympyzComplexField.to_sympyas0W\\488,qw||TXX1N/NNNrc|j|j}|j\}}|jr|jr|j ||St d|z)z%Convert SymPy's number to ``dtype``. )nzexpected complex number, got %s)evalfr as_real_imag is_Numberr,r )rexprnumberrDrEs r from_sympyzComplexField.from_sympyesWdhh'((* d >>dnn::dD) ) !BT!IJ Jrc$|j|Srr,rrGbases rfrom_ZZzComplexField.from_ZZozz'""rc6|jt|Sr)r,r8rSs r from_ZZ_gmpyzComplexField.from_ZZ_gmpyrszz#g,''rc$|j|SrrRrSs rfrom_ZZ_pythonzComplexField.from_ZZ_pythonurVrcv|jt|jt|jz Srr,r8 numerator denominatorrSs rfrom_QQzComplexField.from_QQx,zz#g//01C8K8K4LLLrcR|j|j|jz Sr)r,r]r^rSs rfrom_QQ_pythonzComplexField.from_QQ_python{s"zz'++,w/B/BBBrcv|jt|jt|jz Srr\rSs r from_QQ_gmpyzComplexField.from_QQ_gmpy~r`rcr|jt|jt|jSr)r,r8r9r:rSs rfrom_GaussianIntegerRingz%ComplexField.from_GaussianIntegerRings#zz#gii.#gii.99rc|j}|j}|jt|jt|j z |jdt|jt|j z zS)Nr)r9r:r,r8r]r^)rrGrTr9r:s rfrom_GaussianRationalFieldz'ComplexField.from_GaussianRationalFieldsh II II 3q{{+,s1==/AA 1c!++./#amm2DDE Frct|j|j|j|jSr)rPrHrKr rSs rfrom_AlgebraicFieldz ComplexField.from_AlgebraicFields)t}}W5;;DHHEFFrc$|j|SrrRrSs rfrom_RealFieldzComplexField.from_RealFieldrVrc$|j|SrrRrSs rfrom_ComplexFieldzComplexField.from_ComplexFieldrVrctd|z)z)Returns a ring associated with ``self``. z#there is no ring associated with %s)r rs rget_ringzComplexField.get_rings?$FGGrctS)z2Returns an exact domain associated with ``self``. rrs r get_exactzComplexField.get_exacts rcyz.Returns ``False`` for any ``ComplexElement``. FrFs r is_negativezComplexField.is_negativercyrtrurFs r is_positivezComplexField.is_positiverwrcyrtrurFs ris_nonnegativezComplexField.is_nonnegativerwrcyrtrurFs ris_nonpositivezComplexField.is_nonpositiverwrc|jS)z Returns GCD of ``a`` and ``b``. )r.rabs rgcdzComplexField.gcds xxrc ||zS)z Returns LCM of ``a`` and ``b``. rurs rlcmzComplexField.lcms s rc<|jj|||S)z+Check if ``a`` and ``b`` are almost equal. )ralmosteq)rrrr#s rrzComplexField.almosteqs}}%%aI66rcy)zAReturns ``True``. Every complex number has a complex square root.Trurrs r is_squarezComplexField.is_squaresrc |dzS)a,Returns the principal complex square root of ``a``. Explanation =========== The argument of the principal square root is always within $(-\frac{\pi}{2}, \frac{\pi}{2}]$. The square root may be slightly inaccurate due to floating point rounding error. g?rurs rexsqrtzComplexField.exsqrts Cxr)NNN)rr).rA __module__ __qualname____doc__repis_ComplexFieldis_CCis_Exact is_Numericalhas_assoc_Ringhas_assoc_Fieldrpropertyrrr r#r3r5r,r=rBrHrPrUrXrZr_rbrdrfrhrjrlrnrprrrvryr{r}rrrrrrurrrrs&5 C""OeHLNO 99""!!52!ULOK#(#MCM:F G##H7 rrN)rsympy.external.gmpyrsympy.core.numbersrr&sympy.polys.domains.characteristiczerorsympy.polys.domains.fieldr#sympy.polys.domains.gaussiandomainsr sympy.polys.domains.simpledomainr sympy.polys.polyerrorsr r sympy.utilitiesr mpmathrrrrurrrsR5+'E+49>"s5,lssj^r