
    \h%                   X   S SK Jr  S SKJr  S SKrS SKrS SKrS SKrSSKJ	r	  SSK
JrJrJ
r
JrJrJr  SSKJrJr  SSKJr  SS	KJrJr  SS
KJr  SSKJrJr  SSKJr  SSKJ r J!r!J"r"J#r#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  S SK+J,r,J-r-J.r.  S SK/J0r0  S SK1r1S SK2J3r4  S SK2J5r5J6r7  S SK8J9r9  S SK2J:r:J;r;J<r<J=r=  S SK>J?r?  S SK@JArBJCrDJErFJGrGJHrIJJrJJKrK  S SKLJMrM  S SKNJOrO  SSKPJQrQ  \R                  " S5      rSSdS jrTS rUSS0rVSeS  jrWS! rXS" rY\ZR                  \\R                  S#5      5      r^S$ r_ " S% S&\5      r` " S' S(\`5      ra\a=\\b'   \\R                  '   \ard " S) S*\`5      re " S+ S,\e5      rf\f\\g'    " S- S.\5      rh " S/ S0\e5      ri " S1 S2\f5      rj " S3 S4\j\S59rk " S6 S7\j\S59rl " S8 S9\j\S59rm " S: S;\i\S59rn " S< S=\`\S59ro\R                  rp " S> S?\`\S59rq " S@ SA\`\S59rr\R                  rs\0" \r\5      SB 5       rt " SC SD\\S59ru\R                  rv " SE SF\5      rw " SG SH\w\S59rx\R                  ry " SI SJ\w\S59rz\R                  r{ " SK SL\w\S59r| " SM SN\w\S59r} " SO SP\w\S59r~ " SQ SR\w\S59r " SS ST\\S59r\GR                   rSU rSV rSfSW jr\0" \	\`5      SX 5       rtSY r\\\GR                  '   \-b?  SZ rS[ r\\\" \-GR                  " S5      5      '   \\\" \-GR                  " SS5      5      '   \.b?  S\ rS] r\\\" \.GR                  " S5      5      '   \\\" \.GR                  " SS5      5      '   S^ r\\\?'   S_ r\\\'   SS`KJr  SSaKJr  \l" 5       \l        SSbKJr  \k" 5       \l        Sc r\" 5         \R                  \R                  \R                  \R                  4rg)g    )annotations)overloadN   )Tuple)SympifyError_sympy_convertersympify_convert_numpy_types_sympify_is_numpy_instance)S	Singleton)Basic)Expr
AtomicExpr)pure_complex)cacheitclear_cache)
_sympifyit)
num_digitsigcdilcmmod_inverseinteger_nthroot)	fuzzy_not)
NumberKind)ordered)
SYMPY_INTSgmpyflint)dispatch)bitcountround_nearestMPZ)mpf_powmpf_pimpf_e	phi_fixed)	mpnumeric)finffninffnanfzero
_normalizeprec_to_dpsdps_to_prec)debug)sympy_deprecation_warning)global_parameters   c                   [        U[        5      (       a(  [        U SS9(       d  [        S5      e[        U 5      U:H  $ U (       d  XpU (       d  gU(       Gd  XpCUS:X  a  [        U5      [        U5      :H  $ UGc  [	        U5      [	        U5      pC[        S X44 5       5      (       d  [        S5      eUR                  [        5      nUR                  [        5      nU(       d  U(       d  X4:H  $ [        S5       HW  n[        USS9nU(       a  M  U(       a6  UR                  [        [        S U 5       5      5      5      n[        USS9n  OXepeXCpCMY     [        U5      n	U	(       d;  U(       a4  UR                  [        [        S	 U 5       5      5      5      n[        USS9n	W(       a6  U	(       a/  US
   (       d
  U	S
   (       a  [        S [        X5       5       5      $ S[        [        UR                  [        USUR                  5      5      5      -  n[        [!        X4-
  5      U-  5      S:*  $ [!        X-
  5      n
[!        U 5      nU(       a  US
:  a  X-  U:*  $ X:*  $ )a  Return a bool indicating whether the error between z1 and z2
is $\le$ ``tol``.

Examples
========

If ``tol`` is ``None`` then ``True`` will be returned if
:math:`|z1 - z2|\times 10^p \le 5` where $p$ is minimum value of the
decimal precision of each value.

>>> from sympy import comp, pi
>>> pi4 = pi.n(4); pi4
3.142
>>> comp(_, 3.142)
True
>>> comp(pi4, 3.141)
False
>>> comp(pi4, 3.143)
False

A comparison of strings will be made
if ``z1`` is a Number and ``z2`` is a string or ``tol`` is ''.

>>> comp(pi4, 3.1415)
True
>>> comp(pi4, 3.1415, '')
False

When ``tol`` is provided and $z2$ is non-zero and
:math:`|z1| > 1` the error is normalized by :math:`|z1|`:

>>> abs(pi4 - 3.14)/pi4
0.000509791731426756
>>> comp(pi4, 3.14, .001)  # difference less than 0.1%
True
>>> comp(pi4, 3.14, .0005)  # difference less than 0.1%
False

When :math:`|z1| \le 1` the absolute error is used:

>>> 1/pi4
0.3183
>>> abs(1/pi4 - 0.3183)/(1/pi4)
3.07371499106316e-5
>>> abs(1/pi4 - 0.3183)
9.78393554684764e-6
>>> comp(1/pi4, 0.3183, 1e-5)
True

To see if the absolute error between ``z1`` and ``z2`` is less
than or equal to ``tol``, call this as ``comp(z1 - z2, 0, tol)``
or ``comp(z1 - z2, tol=tol)``:

>>> abs(pi4 - 3.14)
0.00160156249999988
>>> comp(pi4 - 3.14, 0, .002)
True
>>> comp(pi4 - 3.14, 0, .001)
False
T)or_realz$when z2 is a str z1 must be a Number c              3  8   #    U  H  oR                   v   M     g 7fN)	is_number.0is     J/var/www/auris/envauris/lib/python3.13/site-packages/sympy/core/numbers.py	<genexpr>comp.<locals>.<genexpr>u   s     3Fq{{F   zexpecting 2 numbersr5   c              3  8   #    U  H  oR                   v   M     g 7fr:   _precr<   s     r?   r@   rA      s     /DArB   c              3  8   #    U  H  oR                   v   M     g 7fr:   rD   r<   s     r?   r@   rA      s     '<ArB   r   c              3  <   #    U  H  u  p[        X5      v   M     g 7fr:   )comp)r=   r>   js      r?   r@   rA      s     >+$!4::+s   
   rE      )
isinstancestrr   
ValueErrorr	   allatomsFloatrangenr0   minziprE   getattrintabs)z1z2tolabfafb_cacbdiffaz1s               r?   rH   rH   *   s   z "cB-CDD2w"}B1"9q6SV##;1:wqzq3QF333 !677BBbv1X!!T2rCCC/D/D,D EF)!T:!#B 1  aB"CCC'<'<$<=>!!T2bber!u>#b+>>>k#aggwq'177/K"LMMCs15z#~&!++rw<D
b'C	cAgx3{    c                x    U u  p#pEU(       d  U(       d  [         $ U $ SSKJn  [        X&" U5      XEU[        5      nU$ )aA  Return the mpf tuple normalized appropriately for the indicated
precision after doing a check to see if zero should be returned or
not when the mantissa is 0. ``mpf_normlize`` always assumes that this
is zero, but it may not be since the mantissa for mpf's values "+inf",
"-inf" and "nan" have a mantissa of zero, too.

Note: this is not intended to validate a given mpf tuple, so sending
mpf tuples that were not created by mpmath may produce bad results. This
is only a wrapper to ``mpf_normalize`` which provides the check for non-
zero mpfs that have a 0 for the mantissa.
r   r$   )r.   mpmath.libmp.backendr%   mpf_normalizernd)mpfprecsignmanexptbcr%   rvs           r?   mpf_normrq      sB     Dt L J )	tSXts	;BIre   divideFc                F    [         S   U :w  a  [        5         U [         S'   gg)z
Should SymPy raise an exception on 0/0 or return a nan?

divide == True .... raise an exception
divide == False ... return nan
rr   N)_errdictr   )rr   s    r?   seterrru      s%     V## $re   c                    [        U S[        R                  " U 5      R                  5      u  pp4SS/US-     U-  n US:  a  SU* -  nO
SnU SU-  -  n [	        U 5      [	        U5      4$ )N_mpf_r   r5   r   )rV   mpmathrj   rw   rW   )pneg_powrm   rn   r`   qs         r?   _as_integer_ratior}      sp    #Aw

10C0CDG$	
B!S AaxuH	QWq63q6>re   c                :   U R                  5       (       d  [        SU -  5      eU R                  5       u  pn[        U5      nUS:  a  [	        [        U 5      5      nXT4$ SU-  n[        S [        [        U5      5       5       5      n[        X-  SU* -  5      nXT4$ )z3Convert an ordinary decimal instance to a Rational.zdec must be finite, got %s.r   rx   c              3  6   #    U  H  u  pUS U-  -  v   M     g7f)rJ   N )r=   r>   dis      r?   r@   ,_decimal_to_Rational_prec.<locals>.<genexpr>   s     =&<UQ2q5&<s   rJ   )
	is_finite	TypeErroras_tuplelenIntegerrW   sum	enumeratereversedRational)decsderk   rp   s         r?   _decimal_to_Rational_precr      s    ==??5;<<llnGA!q6DAvSX
 8O !G=i&<==ac2r6"8Ore   
1234567890c                :   U R                  S5      n[        U5      S:  a  g[        U5      S:X  a1  Uu  p#UR                  [        S5      5      (       a  USS nU(       d  gOU Sp2UR                  S5      n[        U5      S:  a  g[        U5      S:X  a  Uu  pEOUSpTU(       d  U(       d  gU(       a  US	   S;   a  USS nU(       d  SnU=(       d    SnXEU4 H?  nUR                  S
5       H'  nU(       a  UR	                  [
        5      (       d  M&      g   MA     g)a9  return True if s is space-trimmed number literal else False

Python allows underscore as digit separators: there must be a
digit on each side. So neither a leading underscore nor a
double underscore are valid as part of a number. A number does
not have to precede the decimal point, but there must be a
digit before the optional "e" or "E" that begins the signs
exponent of the number which must be an integer, perhaps with
underscore separators.

SymPy allows space as a separator; if the calling routine replaces
them with underscores then the same semantics will be enforced
for them as for underscores: there can only be 1 *between* digits.

We don't check for error from float(s) because we don't know
whether s is malicious or not. A regex for this could maybe
be written but will it be understood by most who read it?
r   r5   Fz+-r   N1.r   r`   T)splitr   
startswithtuple	translate_dig)r   partsmr   r>   frS   gs           r?   _literal_floatr      s   ( GGCLE
5zA~
5zQ<<d$$!"A  #1GGCLE
5zA~	Uq1#1QQqTT\abE	SAAYAD))   re   c                    ^  \ rS rSrSrSrS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S rS rS rS rS rS r\S 5       r\S0S j5       rS1S jr \!S2S j5       r"\!S3S j5       r"\#" S\$5      S4S j5       r"\#" S\$5      S 5       r%\#" S\$5      S 5       r&\#" S\$5      S 5       r'S  r(S! r)S" r*S# r+S$ r,S% r-U 4S& jr.S' r/SS(.S) jr0S* r1S5S+ jr2S5S, jr3S- r4S. r5S/ r6Sr7U =r8$ )6Numberi  a  Represents atomic numbers in SymPy.

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

Floating point numbers are represented by the Float class.
Rational numbers (of any size) are represented by the Rational class.
Integer numbers (of any size) are represented by the Integer class.
Float and Rational are subclasses of Number; Integer is a subclass
of Rational.

For example, ``2/3`` is represented as ``Rational(2, 3)`` which is
a different object from the floating point number obtained with
Python division ``2/3``. Even for numbers that are exactly
represented in binary, there is a difference between how two forms,
such as ``Rational(1, 2)`` and ``Float(0.5)``, are used in SymPy.
The rational form is to be preferred in symbolic computations.

Other kinds of numbers, such as algebraic numbers ``sqrt(2)`` or
complex numbers ``3 + 4*I``, are not instances of Number class as
they are not atomic.

See Also
========

Float, Integer, Rational
Tr   rx   c                   [        U5      S:X  a  US   n[        U[        5      (       a  U$ [        U[        5      (       a  [	        U5      $ [        U[
        5      (       a  [        U5      S:X  a  [        U6 $ [        U[        [        R                  [        R                  45      (       a  [        U5      $ [        U[        5      (       a  UR                  5       nUS:X  a  [        R                   $ US:X  a  [        R"                  $ US:X  a  [        R"                  $ US:X  a  [        R$                  $ ['        U5      n[        U[        5      (       a  U$ [)        SU-  5      eS	n[+        U[-        U5      R.                  -  5      e)
Nr   r   r5   naninf+inf-infz$String "%s" does not denote a Numberz<expected str|int|long|float|Decimal|Number object but got %r)r   rL   r   r   r   r   r   floatry   rj   decimalDecimalrQ   rM   lowerr   NaNInfinityNegativeInfinityr	   rN   r   type__name__)clsobj_objvalmsgs        r?   __new__Number.__new__@  s.   s8q=a&Cc6""Jc:&&3<c5!!c#h!mS>!cE6::w?@@:c399;Du}uuzz!zz!)))#,C#v&&
 !G#!MNNLd3i00011re   c                ,    [        U R                  5      $ r:   )boolis_extended_negativeselfs    r?   could_extract_minus_signNumber.could_extract_minus_sign^  s    D--..re   c                `    SSK Jn  [        USS5      (       a  [        X5      $ U" X/UQ70 UD6$ )Nr   )invertr;   T)sympy.polys.polytoolsr   rV   r   )r   othergensargsr   s        r?   r   Number.inverta  s4    05+t,,t++d1D1D11re   c                P   SSK Jn   [        U5      nU R                  (       d  [        R
                  X4;   a   [        R
                  [        R
                  4$  U(       d  [        S5      eU R                  (       a7  UR                  (       a&  [        [        U R                  UR                  5      6 $ [        U[        5      (       a  U [        U5      -  nOX-  nUR                   (       ar  US:  a  [#        U5      O[#        U5      S-
  nXU-  -
  nU[        U5      :X  a  US-  nSn[        U [        5      (       d  [        U[        5      (       a  [        U5      nO(U (       a  U" U 5      U" U5      :X  a  SOSnU(       a  UOU n[        XE5      $ ! [         a	    [        s $ f = f)Nr   )rl   zmodulo by zeror   rx   )$sympy.functions.elementary.complexesrl   r   is_infiniter   r   r   NotImplementedZeroDivisionError
is_Integerr   divmodrz   rL   rQ   r   r   rW   )r   r   rl   ratwrs         r?   
__divmod__Number.__divmod__g  sF   =	"5ME155TM#9quu~% $: #$455??u//&122u%%x&C*C??1HC#c(Q,AQwAE%L Q$&&*UE*B*B!H$t*U";"AAQ{+  	"!!	"s   AF F%$F%c                \     [        U5      n[        X5      $ ! [         a	    [        s $ f = fr:   )r   r   r   r   r   r   s     r?   __rdivmod__Number.__rdivmod__  s4    	"5ME e""  	"!!	"s    ++c                F    [        SU R                  R                  -  5      e)z7Evaluation of mpf tuple accurate to at least prec bits.z%s needs ._as_mpf_val() methodNotImplementedError	__class__r   r   rk   s     r?   _as_mpf_valNumber._as_mpf_val  s$    !"B^^$$#& ' 	're   c                L    [         R                  U R                  U5      U5      $ r:   rQ   _newr   r   s     r?   _eval_evalfNumber._eval_evalf      zz$**40$77re   c                R    [        XR                  5      nU R                  U5      U4$ r:   )maxrE   r   r   s     r?   
_as_mpf_opNumber._as_mpf_op  s&    4$%t++re   c                L    [         R                  " U R                  S5      5      $ )N5   )mlibto_floatr   r   s    r?   	__float__Number.__float__  s    }}T--b122re   c                F    [        SU R                  R                  -  5      e)Nz%s needs .floor() methodr   r   s    r?   floorNumber.floor  s$    !"<^^$$#& ' 	're   c                F    [        SU R                  R                  -  5      e)Nz%s needs .ceiling() methodr   r   s    r?   ceilingNumber.ceiling  s$    !">^^$$#& ' 	're   c                "    U R                  5       $ r:   r   r   s    r?   	__floor__Number.__floor__      zz|re   c                "    U R                  5       $ r:   r   r   s    r?   __ceil__Number.__ceil__      ||~re   c                    U $ r:   r   r   s    r?   _eval_conjugateNumber._eval_conjugate      re   c                <    SSK Jn  U" [        R                  /UQ76 $ )Nr   )Order)sympy.series.orderr   r   One)r   symbolsr   s      r?   _eval_orderNumber._eval_order  s    ,QUU%W%%re   c                    X* :X  a  U* $ U $ r:   r   r   oldnews      r?   
_eval_subsNumber._eval_subs  s    %<4Kre   c                    g)N)r   r   r   r   r   s    r?   	class_keyNumber.class_key  s    re   c                *    U R                  5       SSU 4$ )N)r   r   r   )r  )r   orders     r?   sort_keyNumber.sort_key  s    ~~"d22re   c                    [         er:   r   r   s    r?   __neg__Number.__neg__  s    !!re   r   c                    g r:   r   r   s     r?   __add__Number.__add__  s    >Are   c                    g r:   r   r   s     r?   r  r    s    ,/re   c                T   [        U[        5      (       a~  [        R                  (       ai  U[        R
                  L a  [        R
                  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ [        R                  " X5      $ r:   )
rL   r   r4   evaluater   r   r   r   r   r  r   s     r?   r  r    sm    eV$$):)C)C~uu!**$zz!!,,,)))!!$..re   c                T   [        U[        5      (       a~  [        R                  (       ai  U[        R
                  L a  [        R
                  $ U[        R                  L a  [        R                  $ U[        R                  L a  [        R                  $ [        R                  " X5      $ r:   )
rL   r   r4   r  r   r   r   r   r   __sub__r   s     r?   r  Number.__sub__  sm    eV$$):)C)C~uu!**$)))!,,,zz!!!$..re   c                   [        U[        5      (       Ga  [        R                  (       a  U[        R
                  L a  [        R
                  $ U[        R                  L aR  U R                  (       a  [        R
                  $ U R                  (       a  [        R                  $ [        R                  $ U[        R                  L aR  U R                  (       a  [        R
                  $ U R                  (       a  [        R                  $ [        R                  $ O[        U[        5      (       a  [        $ [        R                  " X5      $ r:   )rL   r   r4   r  r   r   r   is_zerois_positiver   r   r   r   __mul__r   s     r?   r$  Number.__mul__  s    eV$$):)C)C~uu!**$<<55L%%::%---!,,,<<55L%%---::% - u%%!!!!$..re   c                0   [        U[        5      (       al  [        R                  (       aW  U[        R
                  L a  [        R
                  $ U[        R                  [        R                  4;   a  [        R                  $ [        R                  " X5      $ r:   )rL   r   r4   r  r   r   r   r   Zeror   __truediv__r   s     r?   r(  Number.__truediv__  s]    eV$$):)C)C~uu1::q'9'9::vv%%d22re   c                F    [        SU R                  R                  -  5      e)Nz%s needs .__eq__() methodr   r   s     r?   __eq__Number.__eq__  $    !"=^^$$#& ' 	're   c                F    [        SU R                  R                  -  5      e)Nz%s needs .__ne__() methodr   r   s     r?   __ne__Number.__ne__   r-  re   c                     [        U5      n[        SU R                  R
                  -  5      e! [         a    [        SU < SU< 35      ef = f)NInvalid comparison z < z%s needs .__lt__() methodr   r   r   r   r   r   r   s     r?   __lt__Number.__lt__  sX    	JUOE ""=^^$$#& ' 	'  	JD%HII	J	   / Ac                     [        U5      n[        SU R                  R
                  -  5      e! [         a    [        SU < SU< 35      ef = f)Nr2  z <= z%s needs .__le__() methodr3  r   s     r?   __le__Number.__le__  sX    	KUOE ""=^^$$#& ' 	'  	KT5IJJ	Kr6  c                     [        U5      n[        U5      R                  U 5      $ ! [         a    [        SU < SU< 35      ef = f)Nr2  z > )r   r   r   r4  r   s     r?   __gt__Number.__gt__  sK    	JUOE %%d++  	JD%HII	J	   ' Ac                     [        U5      n[        U5      R                  U 5      $ ! [         a    [        SU < SU< 35      ef = f)Nr2  z >= )r   r   r   r8  r   s     r?   __ge__Number.__ge__  sK    	KUOE %%d++  	KT5IJJ	Kr=  c                    > [         TU ]  5       $ r:   super__hash__r   r   s    r?   rD  Number.__hash__"      w!!re   c                    g)NTr   )r   wrtflagss      r?   is_constantNumber.is_constant%      re   rationalc                   U R                   (       d  U(       d  U S4$ U R                  (       a  [        R                  U * 44$ [        R                  U 44$ Nr   )is_Rationalis_negativer   NegativeOner  )r   rO  depskwargss       r?   as_coeff_mulNumber.as_coeff_mul(  sB    88O==D5(**uutg~re   c                R    U R                   (       a  U S4$ [        R                  U 44$ rQ  )rR  r   r'  )r   rU  s     r?   as_coeff_addNumber.as_coeff_add0  s$    8Ovvwre   c                X    U(       d  U [         R                  4$ [         R                  U 4$ z1Efficiently extract the coefficient of a product.r   r  r   rO  s     r?   as_coeff_MulNumber.as_coeff_Mul6  s!    ;uud{re   c                X    U(       d  U [         R                  4$ [         R                  U 4$ z3Efficiently extract the coefficient of a summation.r   r'  r_  s     r?   as_coeff_AddNumber.as_coeff_Add<  s!    <vvt|re   c                    SSK Jn  U" X5      $ )z#Compute GCD of `self` and `other`. r   )gcd)r   rh  )r   r   rh  s      r?   rh  
Number.gcdB      -4re   c                    SSK Jn  U" X5      $ )z#Compute LCM of `self` and `other`. r   )lcm)r   rl  )r   r   rl  s      r?   rl  
Number.lcmG  rj  re   c                    SSK Jn  U" X5      $ )z1Compute GCD and cofactors of `self` and `other`. r   )	cofactors)r   ro  )r   r   ro  s      r?   ro  Number.cofactorsL  s    3%%re   r:   )returnr   )r   zNumber | int | floatrq  r   )r   r   rq  r   )rq  r   F)9r   
__module____qualname____firstlineno____doc__is_commutativer;   	is_Number	__slots__rE   r   kindr   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  classmethodr  r   r  r  r   r  r   r   r  r$  r(  r+  r/  r4  r8  r;  r?  rD  rK  rW  rZ  r`  re  rh  rl  ro  __static_attributes____classcell__r   s   @r?   r   r     s   6 NIII ED2</2<#'
8,3''&

   3 3" A A/ /(/ )/ (/ )/ (/ )/, (3 )3'''',," ,0  
 
& &re   r   c                      \ rS rSr% SrSrS\S'   SrSrSr	Sr
SrSr\R                  \R!                  S5      5      rS3S	 jr\S4S
 j5       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&S r'S r(\)" S\*5      S 5       r+\)" S\*5      S  5       r,\)" S\*5      S! 5       r-\)" S\*5      S" 5       r.\)" S\*5      S# 5       r/\)" S\*5      S$ 5       r0S% r1S& r2S' r3S( r4S) r5S* r6S+ r7S, r8S- r9S. r:S/ r;S5S0 jr<S1 r=S2r>g)6rQ   iR  aa  Represent a floating-point number of arbitrary precision.

Examples
========

>>> from sympy import Float
>>> Float(3.5)
3.50000000000000
>>> Float(3)
3.00000000000000

Creating Floats from strings (and Python ``int`` and ``long``
types) will give a minimum precision of 15 digits, but the
precision will automatically increase to capture all digits
entered.

>>> Float(1)
1.00000000000000
>>> Float(10**20)
100000000000000000000.
>>> Float('1e20')
100000000000000000000.

However, *floating-point* numbers (Python ``float`` types) retain
only 15 digits of precision:

>>> Float(1e20)
1.00000000000000e+20
>>> Float(1.23456789123456789)
1.23456789123457

It may be preferable to enter high-precision decimal numbers
as strings:

>>> Float('1.23456789123456789')
1.23456789123456789

The desired number of digits can also be specified:

>>> Float('1e-3', 3)
0.00100
>>> Float(100, 4)
100.0

Float can automatically count significant figures if a null string
is sent for the precision; spaces or underscores are also allowed. (Auto-
counting is only allowed for strings, ints and longs).

>>> Float('123 456 789.123_456', '')
123456789.123456
>>> Float('12e-3', '')
0.012
>>> Float(3, '')
3.

If a number is written in scientific notation, only the digits before the
exponent are considered significant if a decimal appears, otherwise the
"e" signifies only how to move the decimal:

>>> Float('60.e2', '')  # 2 digits significant
6.0e+3
>>> Float('60e2', '')  # 4 digits significant
6000.
>>> Float('600e-2', '')  # 3 digits significant
6.00

Notes
=====

Floats are inexact by their nature unless their value is a binary-exact
value.

>>> approx, exact = Float(.1, 1), Float(.125, 1)

For calculation purposes, evalf needs to be able to change the precision
but this will not increase the accuracy of the inexact value. The
following is the most accurate 5-digit approximation of a value of 0.1
that had only 1 digit of precision:

>>> approx.evalf(5)
0.099609

By contrast, 0.125 is exact in binary (as it is in base 10) and so it
can be passed to Float or evalf to obtain an arbitrary precision with
matching accuracy:

>>> Float(exact, 5)
0.12500
>>> exact.evalf(20)
0.12500000000000000000

Trying to make a high-precision Float from a float is not disallowed,
but one must keep in mind that the *underlying float* (not the apparent
decimal value) is being obtained with high precision. For example, 0.3
does not have a finite binary representation. The closest rational is
the fraction 5404319552844595/2**54. So if you try to obtain a Float of
0.3 to 20 digits of precision you will not see the same thing as 0.3
followed by 19 zeros:

>>> Float(0.3, 20)
0.29999999999999998890

If you want a 20-digit value of the decimal 0.3 (not the floating point
approximation of 0.3) you should send the 0.3 as a string. The underlying
representation is still binary but a higher precision than Python's float
is used:

>>> Float('0.3', 20)
0.30000000000000000000

Although you can increase the precision of an existing Float using Float
it will not increase the accuracy -- the underlying value is not changed:

>>> def show(f): # binary rep of Float
...     from sympy import Mul, Pow
...     s, m, e, b = f._mpf_
...     v = Mul(int(m), Pow(2, int(e), evaluate=False), evaluate=False)
...     print('%s at prec=%s' % (v, f._prec))
...
>>> t = Float('0.3', 3)
>>> show(t)
4915/2**14 at prec=13
>>> show(Float(t, 20)) # higher prec, not higher accuracy
4915/2**14 at prec=70
>>> show(Float(t, 2)) # lower prec
307/2**10 at prec=10

The same thing happens when evalf is used on a Float:

>>> show(t.evalf(20))
4915/2**14 at prec=70
>>> show(t.evalf(2))
307/2**10 at prec=10

Finally, Floats can be instantiated with an mpf tuple (n, c, p) to
produce the number (-1)**n*c*2**p:

>>> n, c, p = 1, 5, 0
>>> (-1)**n*c*2**p
-5
>>> Float((1, 5, 0))
-5.00000000000000

An actual mpf tuple also contains the number of bits in c as the last
element of the tuple:

>>> _._mpf_
(1, 5, 0, 3)

This is not needed for instantiation and is not the same thing as the
precision. The mpf tuple and the precision are two separate quantities
that Float tracks.

In SymPy, a Float is a number that can be computed with arbitrary
precision. Although floating point 'inf' and 'nan' are not such
numbers, Float can create these numbers:

>>> Float('-inf')
-oo
>>> _.is_Float
False

Zero in Float only has a single value. Values are not separate for
positive and negative zeroes.
rw   rE   ztuple[int, int, int, int]rw   NTz-+_.c           	        Ub  Ub  [        S5      e[        U[        5      (       a  UR                  5       =pAUR	                  SS5      R                  5       nUR                  S5      (       a  [        U5      S:  a  SU-   nGO!UR                  S5      (       a  [        U5      S:  a
  S	USS  -   nGOUS
;   a  [        R                  $ US:X  a  [        R                  $ US:X  a  [        R                  $ [        U5      (       d  [        SU-  5      eGO[        U[        5      (       a
  US:X  a  SnGOq[        U[        5      (       a  U[        S5      :X  a  [        R                  $ [        U[        5      (       a  U[        S5      :X  a  [        R                  $ [        U[        5      (       a+  [        R                  " U5      (       a  [        R                  $ [        U[         ["        45      (       a  [        U5      nOU[        R                  L a  U$ U[        R                  L a  U$ U[        R                  L a  U$ [%        U5      (       a  ['        U5      nOG[        U[(        R*                  5      (       a(  Uc  Uc  UR,                  R.                  nUR0                  nUc  Uc  Sn[        U[2        5      (       a  U$ [        U[        5      (       an   [4        R6                  " U5      nSU;  n[9        U5      u  pUR:                  (       a  U(       a  [=        U[?        U5      5      n[=        SU5      n[A        U5      nOOUS:X  a  Ub	  Uc  US:X  a  [        U[        5      (       d  [        S5      e [4        R6                  " U5      nSU;  n[9        U5      u  pUR:                  (       a'  U(       a   [=        U[?        U5      5      n[A        U5      nUb  US:X  a  [A        U5      n[E        U5      n[        U[        5      (       a  [F        RH                  " X[J        5      nGOl[        U[        5      (       a  [F        RL                  " X[J        5      nGO:[        U[4        R6                  5      (       a  URO                  5       (       a'  [F        RL                  " [        U5      U[J        5      nGOURQ                  5       (       a  [        R                  $ URS                  5       (       a&  US:  a  [        R                  $ [        R                  $ [        S[        U5      -  5      e[        U[T        5      (       Ga  [        U5      S;   a  [        US   [        5      (       aO  [W        U5      nUS   RY                  S5      R[                  S5      US'   []        US   S5      US'   [U        U5      nO[        U5      S:X  a  [2        R_                  X5      $ [a        US   S;   US   S:  [a        S U 5       5      45      (       d  [        SU< 35      e[2        R_                  US   US   US   [c        US   5      4U5      $ [        U[d        [f        45      (       a  URi                  U5      nO[(        R*                  " XS9R0                  nU R_                  XsSS9$ ! [4        RB                   a     GNf = f! [4        RB                   a    [        SU-  5      ef = f) Nz=Both decimal and binary precision supplied. Supply only one.  r`   r   r   0z-.r5   z-0.)r   r   r   r   zstring-float not recognized: %sr   r      r8   z^The null string can only be used when the number to Float is passed as a string or an integer.z*string-float not recognized by Decimal: %szunexpected decimal value %s)      0xL   r  )r   r   c              3  R   #    U  H  n[        U5      [        [        4;   v   M     g 7fr:   )r   rW   r<   s     r?   r@    Float.__new__.<locals>.<genexpr>  s     Cs!QC: 5ss   %'zmalformed mpf: )rk   F)zero)5rN   rL   rM   stripreplacer   r   r   r   r   r   r   r   r   mathisnanr   r   r   r
   ry   rj   contextrk   rw   rQ   r   r   r   r   r   r   r1   InvalidOperationrW   r   
from_floatri   from_strr   is_nanr   r   listremoveprefixremovesuffixr%   r   rO   r"   r   NumberSymbolr   )r   numdps	precision_numNumisintrw   s           r?   r   Float.__new__  s   ?y4 1 2 2 c3$D++c3'--/C~~c""s3x!|Ci%%#c(Q,c!"go'zz!)))uu#C(( !BT!IJJ )U##qCU##uU|(;::U##uV}(<%%%U##

355Lj'233c(CAJJJA&&&JAEE\J$$&s+CVZZ(( ; # 0 0I))C;9,C#u%%
#s##1!//#.C  sNE8=HC~~% "#z#7b#,C +C 0I $ "_	0AcRic3''  "K L L
1ooc* 34S9>>ec:c?3C +C 0I 	R#C(I	N	c5!!OOCC8ES!!MM##6EW__--}}c#h	3?uu""7::%))) !>S!IJJU##CF(:#a&#&&3i Q,,T2??DASVRAc
s8q= ::c55Ff,FaKCsCC   
 ))EFF !::QQQ#a&1AB!# # fl344OOI.EJJs399Exxux55s // " ++ U !MPS!STTUs   Z( ;[ ([ ?[ #[&c                <   U(       a  U[         :X  a  [        R                  $ U[        :X  a  [        R                  $ U[
        :X  a  [        R                  $ U[        :X  a  [        R                  $ [        R                  " U 5      n[        X5      Ul        X$l        U$ r:   )r.   r   r'  _mpf_nanr   _mpf_infr   	_mpf_ninfr   r   r   rq   rw   rE   )r   rw   rE   r  r   s        r?   r   
Float._new  sq     EUN66Mh55Lh::i%%%ll3U*		
re   c                h    U R                   u  pp4U[        U5      SS  X44nSU R                  0nU4U4$ )Nr5   r  )rw   hexrE   )r   rl   rm   expro   argrV  s          r?   __getnewargs_ex__Float.__getnewargs_ex__  sA    !ZZ3SXab\3+tzz*re   c                2    U R                   U R                  4$ r:   r  r   s    r?   _hashable_contentFloat._hashable_content  s    

DJJ''re   c           
         [        [        [        R                  " [        R                  " U R
                  U R                  5      5      5      5      $ r:   )r   rW   r   to_int	mpf_floorrw   rE   r   s    r?   r   Float.floor  s7    s4;;NN4::tzz24 5 6 	6re   c           
         [        [        [        R                  " [        R                  " U R
                  U R                  5      5      5      5      $ r:   )r   rW   r   r  mpf_ceilrw   rE   r   s    r?   r   Float.ceiling  s7    s4;;MM$**djj13 4 5 	5re   c                "    U R                  5       $ r:   r   r   s    r?   r   Float.__floor__  r   re   c                "    U R                  5       $ r:   r   r   s    r?   r   Float.__ceil__  r   re   c                B    [         R                  " U R                  5      $ r:   )ry   rj   rw   r   s    r?   r  	Float.num  s    zz$**%%re   c                    [        U R                  U5      nX R                  :w  a&  U R                  U:X  a  [        U R                  U5        U$ r:   )rq   rw   rE   r2   r   rk   rp   s      r?   r   Float._as_mpf_val  s:    djj$'

d 2$**b!	re   c                D    U R                   [        XR                  5      4$ r:   )rw   r   rE   r   s     r?   r   Float._as_mpf_op  s    zz3tZZ000re   c                :    U R                   [        [        4;   a  gg)NFTrw   r  r  r   s    r?   _eval_is_finiteFloat._eval_is_finite  s    ::(I..re   c                :    U R                   [        [        4;   a  ggNTFr  r   s    r?   _eval_is_infiniteFloat._eval_is_infinite  s    ::(I..re   c                P    U R                   [        :X  a  g[        U 5      (       d  gg r  )rw   r.   
int_valuedr   s    r?   _eval_is_integerFloat._eval_is_integer  s$    ::$  re   c                V    U R                   [        [        4;   a  gU R                  S:  $ NFr   rw   r  r  r  r   s    r?   _eval_is_negativeFloat._eval_is_negative  $    ::)X..xx!|re   c                V    U R                   [        [        4;   a  gU R                  S:  $ r  r  r   s    r?   _eval_is_positiveFloat._eval_is_positive  r  re   c                t    U R                   [        :X  a  gU R                   [        :X  a  gU R                  S:  $ NTFr   r  r   s    r?   _eval_is_extended_negative Float._eval_is_extended_negative  s.    ::"::!xx!|re   c                t    U R                   [        :X  a  gU R                   [        :X  a  gU R                  S:  $ r  )rw   r  r  r  r   s    r?   _eval_is_extended_positive Float._eval_is_extended_positive  s.    ::!::"xx!|re   c                (    U R                   [        :H  $ r:   rw   r.   r   s    r?   _eval_is_zeroFloat._eval_is_zero      zzU""re   c                (    U R                   [        :g  $ r:   r  r   s    r?   __bool__Float.__bool__  r  re   c                    U (       d  U $ [         R                  [        R                  " U R                  5      U R
                  5      $ r:   )rQ   r   r   mpf_negrw   rE   r   s    r?   r  Float.__neg__  s,    Kzz$,,tzz2DJJ??re   r   c                .   [        U[        5      (       al  [        R                  (       aW  UR	                  U R
                  5      u  p#[        R                  [        R                  " U R                  X#[        5      U5      $ [        R                  X5      $ r:   )rL   r   r4   r  r   rE   rQ   r   r   mpf_addrw   ri   r  r   r   rhsrk   s       r?   r  Float.__add__  _    eV$$):)C)C((4IC::dll4::s#FMM~~d**re   c                .   [        U[        5      (       al  [        R                  (       aW  UR	                  U R
                  5      u  p#[        R                  [        R                  " U R                  X#[        5      U5      $ [        R                  X5      $ r:   )rL   r   r4   r  r   rE   rQ   r   r   mpf_subrw   ri   r  r  s       r?   r  Float.__sub__	  r  re   c                .   [        U[        5      (       al  [        R                  (       aW  UR	                  U R
                  5      u  p#[        R                  [        R                  " U R                  X#[        5      U5      $ [        R                  X5      $ r:   )rL   r   r4   r  r   rE   rQ   r   r   mpf_mulrw   ri   r$  r  s       r?   r$  Float.__mul__  r  re   c                :   [        U[        5      (       ar  US:w  al  [        R                  (       aW  UR	                  U R
                  5      u  p#[        R                  [        R                  " U R                  X#[        5      U5      $ [        R                  X5      $ Nr   )rL   r   r4   r  r   rE   rQ   r   r   mpf_divrw   ri   r(  r  s       r?   r(  Float.__truediv__  sg    eV$$!8I8R8R((4IC::dll4::s#FMM!!$..re   c                   [        U[        5      (       aV  UR                  S:w  aF  [        R                  (       a1  [        [        R                  [        U 5      U5      U R                  S9$ [        U[
        5      (       aQ  [        R                  (       a<  X-  n[        U5      (       a(  [        S[        U R                  UR                  5      S9$ [        U[        5      (       al  [        R                  (       aW  UR                  U R                  5      u  p4[
        R                  [        R                  " U R                  X4[         5      U5      $ [        R                  X5      $ )Nr   r  r   )rL   r   r|   r4   r  rQ   __mod__rE   r  r   r   r   r   r   mpf_modrw   ri   )r   r   r   r  rk   s        r?   r  Float.__mod__  s    eX&&577a<<M<V<V))(4.%@#'::/ /eU##(9(B(B
A!}}Q#djj%++*FGGeV$$):)C)C((4IC::dll4::s#FMM~~d**re   c                   [        U[        5      (       a&  [        R                  (       a  UR	                  U 5      $ [        U[
        5      (       al  [        R                  (       aW  UR                  U R                  5      u  p#[        R                  [        R                  " X R                  U[        5      U5      $ [
        R                  X5      $ r:   )rL   rQ   r4   r  r  r   r   rE   r   r   r  rw   ri   __rmod__r  s       r?   r  Float.__rmod__-  s    eU##(9(B(B==&&eV$$):)C)C((4IC::dll3

D#FMMt++re   c                   [        U S5      (       a4  UR                  (       a  U $ UR                  (       a  [        R                  $ [        U[        5      (       Ga,  [        U[        5      (       aQ  U R                  n[        R                  [        R                  " U R                  UR                  U[        5      U5      $ [        U[         5      (       aa  UR                  S:X  aQ  UR"                  S-  (       a=  U R$                  (       a,  ['        [        R(                  USS9U * R+                  U5      -  $ UR-                  U R                  5      u  pU R                  n [/        X1U[        5      n[        R                  XB5      $ g! [        R0                   aj    [        R2                  " U[4        4U[4        4U[        5      u  pV[        R                  XR5      [        R                  Xb5      [        R6                  -  -   s $ f = f)z
expt is symbolic object but not equal to 0, 1

(-p)**r -> exp(r*log(-p)) -> exp(r*(log(p) + I*Pi)) ->
          -> p**r*(sin(Pi*r) + cos(Pi*r)*I)
r   r   r5   Fr  N)equal_valuedis_extended_positiver   r   ComplexInfinityrL   r   r   rE   rQ   r   r   mpf_pow_intrw   rz   ri   r   r|   rS  PowrT  _eval_powerr   r&   ComplexResultmpc_powr.   ImaginaryUnit)r   rn   rk   mpfselfyreims          r?   r  Float._eval_power6  s    a  (((((((dF##$((zzzz$$TZZsCTK KD(++FFaKDFFQJ43C3C1==$?E;;t,- -4JDjjG9G45zz!** $ %% 9e$tUmT3@zz"+JJr(89 99s   "%F	 	A;HHc                ~    [         R                  [        R                  " U R                  5      U R
                  5      $ r:   )rQ   r   r   mpf_absrw   rE   r   s    r?   __abs__Float.__abs__V  s$    zz$,,tzz2DJJ??re   c                ~    U R                   [        :X  a  g[        [        R                  " U R                   5      5      $ r  )rw   r.   rW   r   r  r   s    r?   __int__Float.__int__Y  s)    ::4;;tzz*++re   c                n    [        U[        5      (       a  [        U5      n[        R                  " X5      $ r:   )rL   r   rQ   r   r+  r   s     r?   r+  Float.__eq__^  s'    eU##%LE||D((re   c                H    U R                  U5      nU[        L a  U$ U(       + $ r:   )r+  r   )r   r   eqs      r?   r/  Float.__ne__c  s$    [[I6Mre   c                    [        U 5      n[        R                  " U5      (       d  [        U5      $ [        R
                  " U 5      $ r:   )r   r  isinfhashr   rD  )r   	float_vals     r?   rD  Float.__hash__j  s3    $K	zz)$$	?"~~d##re   c           
     T    [        U5      nUR                  (       az   [        R
                  " U R                  [        R                  " UR                  5      5      n[        R                  " UR                  5      n[        [        U" X45      5      5      $ UR                  (       a/  [        [        U" U R                  UR                  5      5      5      $ UR                  (       a  U[        R                  [        R                  4;  a  UR!                  [#        U R$                  5      5      nUR$                  S:  aP  UR&                  (       a>  [        [        U" U R                  UR)                  U R$                  5      5      5      5      $ g g g g ! [         a	    [        s $ f = fNr   )r   r   r   rR  r   r  rw   from_intr|   rz   r   is_Floatis_comparabler   r   r   evalfr0   rE   rx  r   )r   r   opsmpfompfs        r?   _FrelFloat._Frelp  s@   	"UOE  <<

DMM%'',BCD==)DDD011^^D4::u{{35 6 6  U

A..30 &0KKDJJ 78E{{Q??#D4::u'8'8'DE%G H H # &0 %  	"!!	"s   F F'&F'c                    [        U[        5      (       a  UR                  U 5      $ U R                  U[        R
                  5      nUc  [        R                  " X5      $ U$ r:   )rL   r  r4  r*  r   mpf_gtr   r;  r   r   rp   s      r?   r;  Float.__gt__  K    e\**<<%%ZZt{{+:;;t++	re   c                    [        U[        5      (       a  UR                  U 5      $ U R                  U[        R
                  5      nUc  [        R                  " X5      $ U$ r:   )rL   r  r8  r*  r   mpf_ger   r?  r.  s      r?   r?  Float.__ge__  r0  re   c                    [        U[        5      (       a  UR                  U 5      $ U R                  U[        R
                  5      nUc  [        R                  " X5      $ U$ r:   )rL   r  r;  r*  r   mpf_ltr   r4  r.  s      r?   r4  Float.__lt__  r0  re   c                    [        U[        5      (       a  UR                  U 5      $ U R                  U[        R
                  5      nUc  [        R                  " X5      $ U$ r:   )rL   r  r?  r*  r   mpf_ler   r8  r.  s      r?   r8  Float.__le__  r0  re   c                4    [        X-
  5      [        U5      :  $ r:   )rX   rQ   )r   r   epsilons      r?   
epsilon_eqFloat.epsilon_eq  s    4< 5>11re   c                T    [        [        R                  " [        U 5      5      U5      $ r:   )formatr   r   rM   )r   format_specs     r?   
__format__Float.__format__  s    gooc$i0+>>re   r   NNT)z1e-15)?r   rs  rt  ru  rv  ry  __annotations__is_rationalis_irrationalr;   is_realis_extended_realr$  rM   	maketransdictfromkeys_remove_non_digitsr   r{  r   r  r  r   r   r   r   propertyr  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/  rD  r*  r;  r?  r4  r8  r<  rA  r|  r   re   r?   rQ   rQ   R  s   dJ #I$$ KMIGHt}}V'<=L6\    (65 & &1



##@
 (+ )+ (+ )+ (+ )+ (/ )/ (+ )+ (, ),9@@,
)
$H:2?re   rQ   c                    ^  \ rS rSr% SrSrSrSrSrSr	S\
S'   S\
S'   Sr\S6S	 j5       r\S7S
 j5       r\S8S j5       rS9S jrS rS rS rS rS r\" S\5      S 5       r\r\" S\5      S 5       r\" S\5      S 5       r\" S\5      S 5       r\r\" S\5      S 5       r\" S\5      S 5       r \" S\5      S 5       r!\" S\5      S 5       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( r0S) r1S* r2U 4S+ jr3  S:S, jr4\5S- 5       r6\5S. 5       r7\" S\5      S/ 5       r8\" S\5      S0 5       r9S1 r:S;S2 jr;S<S3 jr<S<S4 jr=S5r>U =r?$ )=r   i  a}  Represents rational numbers (p/q) of any size.

Examples
========

>>> from sympy import Rational, nsimplify, S, pi
>>> Rational(1, 2)
1/2

Rational is unprejudiced in accepting input. If a float is passed, the
underlying value of the binary representation will be returned:

>>> Rational(.5)
1/2
>>> Rational(.2)
3602879701896397/18014398509481984

If the simpler representation of the float is desired then consider
limiting the denominator to the desired value or convert the float to
a string (which is roughly equivalent to limiting the denominator to
10**12):

>>> Rational(str(.2))
1/5
>>> Rational(.2).limit_denominator(10**12)
1/5

An arbitrarily precise Rational is obtained when a string literal is
passed:

>>> Rational("1.23")
123/100
>>> Rational('1e-2')
1/100
>>> Rational(".1")
1/10
>>> Rational('1e-2/3.2')
1/320

The conversion of other types of strings can be handled by
the sympify() function, and conversion of floats to expressions
or simple fractions can be handled with nsimplify:

>>> S('.[3]')  # repeating digits in brackets
1/3
>>> S('3**2/10')  # general expressions
9/10
>>> nsimplify(.3)  # numbers that have a simple form
3/10

But if the input does not reduce to a literal Rational, an error will
be raised:

>>> Rational(pi)
Traceback (most recent call last):
...
TypeError: invalid input: pi


Low-level
---------

Access numerator and denominator as .p and .q:

>>> r = Rational(3, 4)
>>> r
3/4
>>> r.p
3
>>> r.q
4

Note that p and q return integers (not SymPy Integers) so some care
is needed when using them in expressions:

>>> r.p/r.q
0.75

See Also
========
sympy.core.sympify.sympify, sympy.simplify.simplify.nsimplify
TFrz   r|   rW   rz   r|   c                   UGci  [        U[        5      (       a  U$ [        U[        5      (       a  GO9[        U[        [        45      (       a  [        [        U5      6 $ [        U[        5      (       d   [        U5      nOUR                  S5      S:  a  [        SU-  5      eUR                  SS5      nUR                  SS5      n[        U5      S:X  a4  Uu  p[        R                   " U5      n[        R                   " U5      nXV-  n [        R                   " U5      nU R#                  UR$                  UR&                  S5      $ [        U[        5      (       d  [        SU-  5      eSnSn[        U[        5      (       d&  [        U5      nXqR*                  -  nUR,                  nO[/        U5      n[        U[        5      (       d(  [        U5      nXR*                  -  nXrR,                  -  nOU[/        U5      -  nUnUb  [1        SSS	S
S9  U R#                  XU5      $ U R#                  X5      $ ! [        [        4 a     Nf = f! [(         a     GNf = f)N/r   zinvalid input: %sr  r8   r5   z4gcd is deprecated in Rational, use nsimplify insteadz1.11zdeprecated-rational-gcdr  )deprecated_since_versionactive_deprecations_target
stacklevel)rL   r   r   r   rQ   r}   rM   r	   r   SyntaxErrorcountr   r  rsplitr   	fractionsFractionr   	numeratordenominatorrN   r|   rz   rW   r3   )r   rz   r|   rh  pqfpfqQs           r?   r   Rational.__new__  s   9!X&&!Z((a%00#%6q%9::!!S))#AJ wws|a''(;a(?@@		#r*A#q)B2w!|!&//2&//2EG%..q1  #xxQ]]AFF!!X..#$7!$;<<A!Z((AHAAAA!Z((AHAHAQKA?%F)/+D	 88A#&& xx~g )+6  & s$   5H5 I 5II
IIc                   US:X  a?  US:X  a)  [         S   (       a  [        S5      e[        R                  $ [        R                  $ US:  a  U* nU* nUc  [        [        U5      U5      nUS:  a  X-  nX#-  nU R                  X5      $ )Nr   rr   zIndeterminate 0/0r   )rt   rN   r   r   r  r   rX   from_coprime_ints)r   rz   r|   rh  s       r?   r   Rational._new^  s    6AvH%$%89955L$$$q5AA;s1vq/C7IAIA$$Q**re   c                    US:X  a  [        U5      $ US:X  a  US:X  a  [        R                  $ [        R                  " U 5      nXl        X#l        U$ )au  Create a Rational from a pair of coprime integers.

Both ``p`` and ``q`` should be strictly of type ``int``.

The caller should ensure that ``gcd(p,q) == 1`` and ``q > 0``.

This may be more efficient than ``Rational(p, q)``. The validity of the
arguments may or may not be checked so it should not be relied upon to
pass unvalidated or invalid arguments to this function.
r   r5   )r   r   Halfr   r   rz   r|   )r   rz   r|   r   s       r?   rc  Rational.from_coprime_intsu  sH     61:6a1f66Mll3
re   c           	         [         R                  " U R                  U R                  5      n[	        UR                  [         R                  " [        U5      5      5      5      $ )zClosest Rational to self with denominator at most max_denominator.

Examples
========

>>> from sympy import Rational
>>> Rational('3.141592653589793').limit_denominator(10)
22/7
>>> Rational('3.141592653589793').limit_denominator(100)
311/99

)rY  rZ  rz   r|   r   limit_denominatorrW   )r   max_denominatorr   s      r?   ri  Rational.limit_denominator  sD     tvvtvv.++I,>,>s??S,TUVVre   c                2    U R                   U R                  4$ r:   rP  r   s    r?   __getnewargs__Rational.__getnewargs__      re   c                2    U R                   U R                  4$ r:   rP  r   s    r?   r  Rational._hashable_content  ro  re   c                     U R                   S:  $ r  rz   r   s    r?   r  Rational._eval_is_positive  s    vvzre   c                     U R                   S:H  $ r  rs  r   s    r?   r  Rational._eval_is_zero  s    vv{re   c                D    [        U R                  * U R                  5      $ r:   )r   rz   r|   r   s    r?   r  Rational.__neg__  s    ((re   r   c                8   [         R                  (       a  [        U[        5      (       aE  [        R                  U R                  U R                  UR                  -  -   U R                  S5      $ [        U[        5      (       aT  [	        U R                  UR                  -  U R                  UR                  -  -   U R                  UR                  -  5      $ [        U[        5      (       a  X-   $ [        R                  X5      $ [        R                  X5      $ r"  )r4   r  rL   r   r   r   rz   r|   rQ   r   r  r   s     r?   r  Rational.__add__  s    %%%))}}TVVdffUWWn%<dffaHHE8,,uww ?PPE5))|#~~d22~~d**re   c                <   [         R                  (       a  [        U[        5      (       aE  [        R                  U R                  U R                  UR                  -  -
  U R                  S5      $ [        U[        5      (       aT  [	        U R                  UR                  -  U R                  UR                  -  -
  U R                  UR                  -  5      $ [        U[        5      (       a  U* U -   $ [        R                  X5      $ [        R                  X5      $ r"  )r4   r  rL   r   r   r   rz   r|   rQ   r   r  r   s     r?   r  Rational.__sub__  s    %%%))}}TVVdffUWWn%<dffaHHE8,,uww ?PPE5))v}$~~d22~~d**re   c                <   [         R                  (       a  [        U[        5      (       aE  [        R                  U R                  UR                  -  U R                  -
  U R                  S5      $ [        U[        5      (       aT  [	        U R                  UR                  -  U R                  UR                  -  -
  U R                  UR                  -  5      $ [        U[        5      (       a  U * U-   $ [        R                  X5      $ [        R                  X5      $ r"  )r4   r  rL   r   r   r   r|   rz   rQ   r   __rsub__r   s     r?   r~  Rational.__rsub__  s    %%%))}}TVVEGG^dff%<dffaHHE8,,uww ?PPE5))uu}$t33t++re   c           	        [         R                  (       Ga2  [        U[        5      (       aV  [        R                  U R                  UR                  -  U R                  [        UR                  U R                  5      5      $ [        U[        5      (       a  [        R                  U R                  UR                  -  U R                  UR                  -  [        U R                  UR                  5      [        U R                  UR                  5      -  5      $ [        U[        5      (       a  X-  $ [        R                  X5      $ [        R                  X5      $ r:   )r4   r  rL   r   r   r   rz   r|   r   rQ   r   r$  r   s     r?   r$  Rational.__mul__  s    %%%%))}}TVVEGG^TVVT%''466=RSSE8,,}}TVVEGG^TVVEGG^T$&&RWRYRYEZ[_`d`f`fhmhoho[pEpqqE5))z!~~d22~~d**re   c           	     B   [         R                  (       Gau  [        U[        5      (       a  U R                  (       a.  UR                  [
        R                  :X  a  [
        R                  $ [        R                  U R                  U R                  UR                  -  [        U R                  UR                  5      5      $ [        U[        5      (       a  [        R                  U R                  UR                  -  U R                  UR                  -  [        U R                  UR                  5      [        U R                  UR                  5      -  5      $ [        U[        5      (       a  U SU-  -  $ [        R                  X5      $ [        R                  X5      $ r"  )r4   r  rL   r   rz   r   r'  r  r   r   r|   r   rQ   r   r(  r   s     r?   r(  Rational.__truediv__  s   %%%%))66egg/,,,#==dffeggAVWWE8,,}}TVVEGG^TVVEGG^T$&&RWRYRYEZ[_`d`f`fhmhoho[pEpqqE5))QuW~%))$66!!$..re   c           	        [         R                  (       Ga6  [        U[        5      (       aV  [        R                  UR                  U R                  -  U R                  [        U R                  UR                  5      5      $ [        U[        5      (       a  [        R                  UR                  U R                  -  UR                  U R                  -  [        U R                  UR                  5      [        U R                  UR                  5      -  5      $ [        U[        5      (       a  USU -  -  $ [        R                  X5      $ [        R                  X5      $ r"  )r4   r  rL   r   r   r   rz   r|   r   rQ   r   __rtruediv__r   s     r?   r  Rational.__rtruediv__  s    %%%%))}}UWWTVV^TVVT$&&%''=RSSE8,,}}UWWTVV^UWWTVV^T$&&RWRYRYEZ[_`d`f`fhmhoho[pEpqqE5))af~%**477""4//re   c                >   [         R                  (       a  [        U[        5      (       a  U R                  UR
                  -  UR                  U R
                  -  -  n[        U R                  UR
                  -  X!R                  -  U R
                  -  -
  U R
                  UR
                  -  5      $ [        U[        5      (       a,  [        U R                  [        U5      5      UR                  S9$ [        R                  X5      $ [        R                  X5      $ )Nr  )
r4   r  rL   r   rz   r|   rQ   r  rE   r   )r   r   rS   s      r?   r  Rational.__mod__  s    %%%**VVEGG^8uww774661A A466%''>RR%''T\\(5/:',{{4 4>>$..~~d**re   c                    [        U[        5      (       a  [        R                  X5      $ [        R	                  X5      $ r:   )rL   r   r  r   r  r   s     r?   r  Rational.__rmod__  s/    eX&&##E00t++re   c                   [        U[        5      (       Ga  [        U[        5      (       a  U R                  UR                  5      U-  $ UR
                  (       a  U* nU[        R                  L a   [        U R                  U R                  5      $ U R                  (       a8  [        R                  U-  [        U R                  U R                  * 5      U-  -  $ [        U R                  U R                  5      U-  $ U[        R                  L a  U R                  U R                  :  a  [        R                  $ U R                  U R                  * :  a2  [        R                  [        R                  [        R                  -  -   $ [        R                  $ [        U[         5      (       aE  [        R#                  U R                  UR                  -  U R                  UR                  -  S5      $ [        U[        5      (       Ga  UR                  UR                  -  nU(       a  US-  nX1R                  -  UR                  -
  n[        XAR                  5      nU R                  S:w  aV  [!        U R                  5      U-  [!        U R                  5      U-  -  [        R#                  SU R                  U-  S5      -  $ [!        U R                  5      U-  [        R#                  SU R                  U-  S5      -  $ UR                  UR                  -
  n[        XAR                  5      nU R                  S:w  aS  [!        U R                  5      U-  [!        U R                  5      U-  -  [        R#                  SU R                  S5      -  $ [!        U R                  5      U-  [        R#                  SU R                  S5      -  $ U R
                  (       a  UR$                  (       a  U * U-  $ g r"  )rL   r   rQ   r   rE   r   r   r  r   r|   rz   rS  rT  r   r
  r'  r   r   is_even)r   rn   neintpartremfracpartratfracparts         r?   r  Rational._eval_power  s   dF##$&&''

3T99((U!%%K#DFFDFF33##==$.x/H"/LLL#DFFDFF3R77qzz!66DFF?::%66TVVG#::

1??(BBBvv$((}}TVVTVV^TVVTVV^QGG$))&&DFF*qLG")&&.466"9K"*;"?Kvv{&tvv4WTVV_k5QQRZR_R_`acgcicikrcrtuRvvv"466?K7aQXZ[8\\\"&&&466/K"*;"?Kvv{&tvv4WTVV_k5QQRZR_R_`acgciciklRmmm"466?K7aQR8SSS$$ED= re   c                d    [         R                  " U R                  U R                  U[        5      $ r:   )r   from_rationalrz   r|   ri   r   s     r?   r   Rational._as_mpf_val;  s!    !!$&&$&&$<<re   c                    [         R                  " [        R                  " U R                  U R
                  X5      5      $ r:   )ry   make_mpfr   r  rz   r|   r   rk   ri   s      r?   _mpmath_Rational._mpmath_>  s(    t11$&&$&&$LMMre   c                T    [        [        U R                  5      U R                  5      $ r:   )r   rX   rz   r|   r   s    r?   r  Rational.__abs__A  s    DFFTVV,,re   c                v    U R                   U R                  p!US:  a  [        U* U-  5      * $ [        X-  5      $ r  )rz   r|   rW   )r   rz   r|   s      r?   r  Rational.__int__D  s6    vvtvv1q5AJ;14yre   c                F    [        U R                  U R                  -  5      $ r:   r   rz   r|   r   s    r?   r   Rational.floorJ  s    tvv'((re   c                J    [        U R                  * U R                  -  5      * $ r:   r  r   s    r?   r   Rational.ceilingM  s    466)***re   c                "    U R                  5       $ r:   r   r   s    r?   r   Rational.__floor__P  r   re   c                "    U R                  5       $ r:   r   r   s    r?   r   Rational.__ceil__S  r   re   c                p    [        U5      n[        U[        5      (       d  gUR
                  (       a#  UR                  (       a  gUR                  U 5      $ UR                  (       a9  U R                  UR                  :H  =(       a    U R                  UR                  :H  $ g! [         a	    [        s $ f = fNF)r   r   r   rL   r   is_NumberSymbolrG  r+  rR  rz   r|   r   s     r?   r+  Rational.__eq__V  s    	"UOE %((   ""<<%% 66UWW$:577)::  	"!!	"s   B" "B54B5c                    X:X  + $ r:   r   r   s     r?   r/  Rational.__ne__i        re   c                R    [        U5      nUR                  (       a  S nXpTUR                  (       a  [        XR5      nO|UR                  (       a  [        XR5      nO_UR                  (       aN  [        UR                  UR                  -  5      [        UR                  UR                  -  5      pT[        XR5      nU(       a  U" U5      $ UR                  (       a6  UR                  (       a$  [        UR                  5      UR                  U-  4$ g g g ! [         a	    [        s $ f = fr:   )r   r   r   rx  r  rV   r$  rR  r   rz   r|   r;   rI  )r   r   attrr'  r   os         r?   _RrelRational._Rrell  s    	"UOE ??Bq$$Q%Q%""qss133w'QSS)91Q%!u{{q11qss|QSSU**  2{   	"!!	"s   D D&%D&c                    U R                  US5      nUc  X4nO[        U[        5      (       d  U$ [        R                  " U6 $ )Nr4  )r  rL   r   r   r;  r.  s      r?   r;  Rational.__gt__  ?    ZZx(:BB&&I{{Bre   c                    U R                  US5      nUc  X4nO[        U[        5      (       d  U$ [        R                  " U6 $ )Nr8  )r  rL   r   r   r?  r.  s      r?   r?  Rational.__ge__  r  re   c                    U R                  US5      nUc  X4nO[        U[        5      (       d  U$ [        R                  " U6 $ )Nr;  )r  rL   r   r   r4  r.  s      r?   r4  Rational.__lt__  r  re   c                    U R                  US5      nUc  X4nO[        U[        5      (       d  U$ [        R                  " U6 $ )Nr?  )r  rL   r   r   r8  r.  s      r?   r8  Rational.__le__  r  re   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  Rational.__hash__  rG  re   c           	     <    SSK Jn  U" XUX4US9R                  5       $ )zA wrapper to factorint which return factors of self that are
smaller than limit (or cheap to compute). Special methods of
factoring are disabled by default so that only trial division is used.
r   )	factorrat)limit	use_trialuse_rhouse_pm1verbose)sympy.ntheory.factor_r  copy)r   r  r  r  r  r  visualr  s           r?   factorsRational.factors  s%     	4i%%''+tv	.re   c                    U R                   $ r:   rs  r   s    r?   r[  Rational.numerator      vvre   c                    U R                   $ r:   )r|   r   s    r?   r\  Rational.denominator  r  re   c                   [        U[        5      (       a^  U[        R                  :X  a  U$ [        [	        U R
                  UR
                  5      [        U R                  UR                  5      5      $ [        R                  X5      $ r:   )
rL   r   r   r'  r   rz   r   r|   r   rh  r   s     r?   rh  Rational.gcd  sa    eX&&TVVUWW%TVVUWW%' ' zz$&&re   c                   [        U[        5      (       ab  [        U R                  [        U R                  UR                  5      -  UR                  -  [        U R                  UR                  5      5      $ [
        R                  X5      $ r:   )rL   r   rz   r   r|   r   rl  r   s     r?   rl  Rational.lcm  sc    eX&&$tvvuww//%''9TVVUWW%' ' zz$&&re   c                V    [        U R                  5      [        U R                  5      4$ r:   r  r   s    r?   as_numer_denomRational.as_numer_denom  s    tvv//re   c                    U (       a6  U R                   (       a  U [        R                  4$ U * [        R                  4$ [        R                  U 4$ )zReturn the tuple (R, self/R) where R is the positive Rational
extracted from self.

Examples
========

>>> from sympy import S
>>> (S(-3)/2).as_content_primitive()
(3/2, -1)

See docstring of Expr.as_content_primitive for more examples.
)r#  r   r  rT  )r   radicalclears      r?   as_content_primitiveRational.as_content_primitive  s=     QUU{"5!--''uud{re   c                &    U [         R                  4$ r]  r^  r_  s     r?   r`  Rational.as_coeff_Mul  s    QUU{re   c                &    U [         R                  4$ rc  rd  r_  s     r?   re  Rational.as_coeff_Add  s    QVV|re   r   rC  r:   )rz   rW   r|   rW   rq  r   )i@B NTFFFF)FTrr  )@r   rs  rt  ru  rv  rH  
is_integerrF  r;   ry  rE  rR  r   r   r{  r   rc  ri  rm  r  r  r  r  r   r   r  __radd__r  r~  r$  __rmul__r(  r  r  r  r  r   r  r  r  r   r   r   r   r+  r/  r  r;  r?  r4  r8  rD  r  rN  r[  r\  rh  rl  r  r  r`  re  r|  r}  r~  s   @r?   r   r     sN   Qd GJKII
F
FKA AF + +,  *W   ) (+ )+ H(
+ )
+ (
, )
, (
+ )
+ H(/ )/ (
0 )
0 (
+ )
+ (, ),
+Z=N-)+&!+*    " ;@5:
.     (' )' (' )'0( re   r   c                  v  ^  \ rS rSrS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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(U 4S$ jr)S% r*S& r+S' r,\-" S(\.5      S) 5       r/S* r0S+ r1S, r2S- r3S. r4S/ r5S0 r6S1 r7S2 r8S3 r9S4 r:S5 r;Sr<U =r=$ )6r   i  a"  Represents integer numbers of any size.

Examples
========

>>> from sympy import Integer
>>> Integer(3)
3

If a float or a rational is passed to Integer, the fractional part
will be discarded; the effect is of rounding toward zero.

>>> Integer(3.8)
3
>>> Integer(-3.8)
-3

A string is acceptable input if it can be parsed as an integer:

>>> Integer("9" * 20)
99999999999999999999

It is rarely needed to explicitly instantiate an Integer, because
Python integers are automatically converted to Integer when they
are used in SymPy expressions.
r   Tr   c                N    [         R                  " U R                  U[        5      $ r:   )r   r#  rz   ri   r   s     r?   r   Integer._as_mpf_val  s    }}TVVT3//re   c                L    [         R                  " U R                  U5      5      $ r:   )ry   r  r   r  s      r?   r  Integer._mpmath_  s    t//566re   c                `   [        U[        5      (       a  UR                  SS5      n [        U5      nUS:X  a  [
        R                  $ US:X  a  [
        R                  $ US:X  a  [
        R                  $ [        R                  " U 5      nX#l        U$ ! [         a    [	        SU-  5      ef = f)Nr  r8   z6Argument of Integer should be of numeric type, got %s.r   rx   r   )rL   rM   r  rW   r   r   r  rT  r'  r   r   rz   )r   r>   ivalr   s       r?   r   Integer.__new__  s    a		#r"A	Nq6D 1955L2:== 1966Mll3
  	NH1LN N	Ns   B B-c                    U R                   4$ r:   rs  r   s    r?   rm  Integer.__getnewargs__.  s    yre   c                    U R                   $ r:   rs  r   s    r?   r  Integer.__int__2      vvre   c                ,    [        U R                  5      $ r:   r   rz   r   s    r?   r   Integer.floor5      tvvre   c                ,    [        U R                  5      $ r:   r  r   s    r?   r   Integer.ceiling8  r  re   c                "    U R                  5       $ r:   r   r   s    r?   r   Integer.__floor__;  r   re   c                "    U R                  5       $ r:   r   r   s    r?   r   Integer.__ceil__>  r   re   c                .    [        U R                  * 5      $ r:   r  r   s    r?   r  Integer.__neg__A      wre   c                R    U R                   S:  a  U $ [        U R                   * 5      $ r  )rz   r   r   s    r?   r  Integer.__abs__D  s#    66Q;KDFF7##re   c                    [        U[        5      (       a;  [        R                  (       a&  [	        [        U R                  UR                  5      6 $ [        R                  X5      $ r:   )	rL   r   r4   r  r   r   rz   r   r   r   s     r?   r   Integer.__divmod__J  sC    eW%%*;*D*D6$&&%''244$$T11re   c                `   [        U[        5      (       a0  [        R                  (       a  [	        [        XR                  5      6 $  [        U5      n[        R                  X5      $ ! [         a<    Sn[        U5      R                  n[        U 5      R                  n[        X#U4-  5      ef = f)Nz7unsupported operand type(s) for divmod(): '%s' and '%s')rL   rW   r4   r  r   r   rz   r   r   r   r   r   )r   r   r   onamesnames        r?   r   Integer.__rdivmod__P  s    eS!!&7&@&@6%0226u $$U11  6OU,,T
++en 455	6s   A' 'AB-c                   [         R                  (       a  [        U[        5      (       a  [	        U R
                  U-   5      $ [        U[        5      (       a"  [	        U R
                  UR
                  -   5      $ [        U[        5      (       aE  [        R                  U R
                  UR                  -  UR
                  -   UR                  S5      $ [        R                  X5      $ [        X5      $ r"  )r4   r  rL   rW   r   rz   r   r   r|   r  Addr   s     r?   r  Integer.__add__^  s    %%%%%tvv~..E7++tvv/00E8,,}}TVVEGG^egg%=uwwJJ##D00t##re   c                   [         R                  (       a  [        U[        5      (       a  [	        XR
                  -   5      $ [        U[        5      (       aE  [        R                  UR
                  U R
                  UR                  -  -   UR                  S5      $ [        R                  X5      $ [        R                  X5      $ r"  )
r4   r  rL   rW   r   rz   r   r   r|   r  r   s     r?   r  Integer.__radd__j      %%%%%uvv~..E8,,}}UWWtvvegg~%=uwwJJ$$T11  --re   c                   [         R                  (       a  [        U[        5      (       a  [	        U R
                  U-
  5      $ [        U[        5      (       a"  [	        U R
                  UR
                  -
  5      $ [        U[        5      (       aE  [        R                  U R
                  UR                  -  UR
                  -
  UR                  S5      $ [        R                  X5      $ [        R                  X5      $ r"  )
r4   r  rL   rW   r   rz   r   r   r|   r  r   s     r?   r  Integer.__sub__s  s    %%%%%tvv~..E7++tvv/00E8,,}}TVVEGG^egg%=uwwJJ##D00,,re   c                   [         R                  (       a  [        U[        5      (       a  [	        XR
                  -
  5      $ [        U[        5      (       aE  [        R                  UR
                  U R
                  UR                  -  -
  UR                  S5      $ [        R                  X5      $ [        R                  X5      $ r"  )
r4   r  rL   rW   r   rz   r   r   r|   r~  r   s     r?   r~  Integer.__rsub__~  r
  re   c                   [         R                  (       a  [        U[        5      (       a  [	        U R
                  U-  5      $ [        U[        5      (       a"  [	        U R
                  UR
                  -  5      $ [        U[        5      (       aV  [        R                  U R
                  UR
                  -  UR                  [        U R
                  UR                  5      5      $ [        R                  X5      $ [        R                  X5      $ r:   )r4   r  rL   rW   r   rz   r   r   r|   r   r$  r   s     r?   r$  Integer.__mul__  s    %%%%%tvve|,,E7++tvvegg~..E8,,}}TVVEGG^UWWd466577>STT##D00,,re   c                   [         R                  (       a  [        U[        5      (       a  [	        XR
                  -  5      $ [        U[        5      (       aV  [        R                  UR
                  U R
                  -  UR                  [        U R
                  UR                  5      5      $ [        R                  X5      $ [        R                  X5      $ r:   )r4   r  rL   rW   r   rz   r   r   r|   r   r  r   s     r?   r  Integer.__rmul__  s    %%%%%uVV|,,E8,,}}UWWTVV^UWWd466577>STT$$T11  --re   c                H   [         R                  (       ay  [        U[        5      (       a  [	        U R
                  U-  5      $ [        U[        5      (       a"  [	        U R
                  UR
                  -  5      $ [        R                  X5      $ [        R                  X5      $ r:   )r4   r  rL   rW   r   rz   r   r  r   s     r?   r  Integer.__mod__  sr    %%%%%tvv~..E7++tvv/00##D00,,re   c                F   [         R                  (       ax  [        U[        5      (       a  [	        XR
                  -  5      $ [        U[        5      (       a"  [	        UR
                  U R
                  -  5      $ [        R                  X5      $ [        R                  X5      $ r:   )r4   r  rL   rW   r   rz   r   r  r   s     r?   r  Integer.__rmod__  sp    %%%%%uvv~..E7++uww/00$$T11  --re   c                    [        U[        5      (       a  U R                  U:H  $ [        U[        5      (       a  U R                  UR                  :H  $ [        R                  X5      $ r:   )rL   rW   rz   r   r   r+  r   s     r?   r+  Integer.__eq__  sL    eS!!FFeO$w''FFegg%&t++re   c                    X:X  + $ r:   r   r   s     r?   r/  Integer.__ne__  r  re   c                     [        U5      nUR                  (       a"  [        U R                  UR                  :  5      $ [
        R                  X5      $ ! [         a	    [        s $ f = fr:   )r   r   r   r   rz   r   r;  r   s     r?   r;  Integer.__gt__  Y    	"UOE DFFUWW,--t++	  	"!!	"   A A('A(c                     [        U5      nUR                  (       a"  [        U R                  UR                  :  5      $ [
        R                  X5      $ ! [         a	    [        s $ f = fr:   )r   r   r   r   rz   r   r4  r   s     r?   r4  Integer.__lt__  r  r  c                     [        U5      nUR                  (       a"  [        U R                  UR                  :  5      $ [
        R                  X5      $ ! [         a	    [        s $ f = fr:   )r   r   r   r   rz   r   r?  r   s     r?   r?  Integer.__ge__  Y    	"UOE DFFegg-..t++	  	"!!	"r  c                     [        U5      nUR                  (       a"  [        U R                  UR                  :*  5      $ [
        R                  X5      $ ! [         a	    [        s $ f = fr:   )r   r   r   r   rz   r   r8  r   s     r?   r8  Integer.__le__  r#  r  c                ,    [        U R                  5      $ r:   )r  rz   r   s    r?   rD  Integer.__hash__  s    DFF|re   c                    U R                   $ r:   rs  r   s    r?   	__index__Integer.__index__  r  re   c                2    [        U R                  S-  5      $ Nr5   )r   rz   r   s    r?   _eval_is_oddInteger._eval_is_odd  s    DFFQJre   c           
       > SSK Jn  U[        R                  L a`  U R                  [        R
                  :  a  [        R                  $ [        R                  [        R                  [        R                  -  -   $ U[        R                  L a(  [        R                  SU S5      [        R                  -  $ [        U[        5      (       d(  U R                  (       a  UR                  (       a  U * U-  $ [        U[        5      (       a  [        TU ]A  U5      $ [        U[        5      (       d  gU[        R"                  L a/  U R                  (       a  [        R                  [%        U * U5      -  $ UR                  (       aq  U* nU R                  (       a9  [        R&                  U-  [        R                  SU R                  * S5      U-  -  $ [        R                  SU R                  S5      U-  $ [)        [+        U R                  5      UR,                  5      u  pEU(       aJ  [/        U[+        UR                  5      -  5      nU R                  (       a  U[        R&                  U-  -  nU$ [1        [+        U R                  5      5      nU" U5      nUSLa  [1        US   5      [1        US   5      0n	O[/        U5      R3                  SS9n	Sn
SnSnSn0 nU	R5                  5        H  u  nnUUR                  -  n[7        UUR,                  5      u  nnUS:  a  XU-  -  n
US:  d  MC  [9        UUR,                  5      nUS:w  a6  U[%        U[        R                  UU-  UR,                  U-  S5      5      -  nM  UX'   M     UR5                  5        H$  u  nnUS:X  a  UnM  [9        UU5      nUS:X  d  M$    O   UR5                  5        H  u  nnUUUU-  -  -  nM     X:X  a  U
S:X  a
  US:X  a  SnU$ X-  [%        U[        XR,                  5      5      -  nU R                  (       a  U[%        [        R&                  U5      -  nU$ )a  
Tries to do some simplifications on self**expt

Returns None if no further simplifications can be done.

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

When exponent is a fraction (so we have for example a square root),
we try to find a simpler representation by factoring the argument
up to factors of 2**15, e.g.

  - sqrt(4) becomes 2
  - sqrt(-4) becomes 2*I
  - (2**(3+7)*3**(6+7))**Rational(1,7) becomes 6*18**(3/7)

Further simplification would require a special call to factorint on
the argument which is not done here for sake of speed.

r   )perfect_powerr   NFi   )r  )r  r0  r   r   rz   r  r
  r   r   r   rL   r   rS  r  rQ   rC  r  rf  r  rT  r   rX   r|   r   rW   r  itemsr   r   )r   rn   r0  r  xxexactresultb_posrz   rK  out_intout_radsqr_intsqr_gcdsqr_dictprimeexponentdiv_ediv_mr   exkvr   s                          r?   r  Integer._eval_power  sx   * 	81::vv~zz!::

 :::1%%%==D!,ajj88$'' DLL}$dE""7&t,,$))166>d..??3ud#333B}}d*8==TVVGQ+G+KKK}}Q2B66#CK8	QDFF^,F!----M CK % E> !Is1Q4y)D5>)))6D #zz|OE8H!(DFF3LE5qy%<'qy '6s5(--q$&&!)Q*OPPG&+HO  , ^^%EAr!|w+a< & NN$DAqq1g:&G %1AF
  _S(7FF2K%LLF#ammT22re   c                    SSK Jn  U" U 5      $ )Nr   )isprime)sympy.ntheory.primetestrD  )r   rD  s     r?   _eval_is_primeInteger._eval_is_primeT  s    3t}re   c                :    U S:  a  [        U R                  5      $ g)Nr   F)r   is_primer   s    r?   _eval_is_compositeInteger._eval_is_compositeY  s    !8T]]++re   c                &    U [         R                  4$ r:   r^  r   s    r?   r  Integer.as_numer_denom_  s    QUU{re   r   c                    [        U[        5      (       d  [        $ [        U[        5      (       a  [        U R                  U-  5      $ [        X5      S   $ r  )rL   r   r   r   rz   r   r   s     r?   __floordiv__Integer.__floordiv__b  sE    %&&!!eW%%466U?++d"1%%re   c                X    [        [        U5      R                  U R                  -  5      $ r:   r  r   s     r?   __rfloordiv__Integer.__rfloordiv__j  s     wu~''466122re   c                    [        U[        [        [        R                  45      (       a!  [        U R
                  [        U5      -  5      $ [        $ r:   rL   rW   r   numbersIntegralrz   r   r   s     r?   
__lshift__Integer.__lshift__t  :    ec7G,<,<=>>466SZ/00!!re   c                    [        U[        [        R                  45      (       a!  [	        [        U5      U R
                  -  5      $ [        $ r:   rL   rW   rV  rW  r   rz   r   r   s     r?   __rlshift__Integer.__rlshift__z  8    ec7#3#34553u:/00!!re   c                    [        U[        [        [        R                  45      (       a!  [        U R
                  [        U5      -	  5      $ [        $ r:   rU  r   s     r?   
__rshift__Integer.__rshift__  rZ  re   c                    [        U[        [        R                  45      (       a!  [	        [        U5      U R
                  -	  5      $ [        $ r:   r\  r   s     r?   __rrshift__Integer.__rrshift__  r_  re   c                    [        U[        [        [        R                  45      (       a!  [        U R
                  [        U5      -  5      $ [        $ r:   rU  r   s     r?   __and__Integer.__and__  :    ec7G,<,<=>>466CJ.//!!re   c                    [        U[        [        R                  45      (       a!  [	        [        U5      U R
                  -  5      $ [        $ r:   r\  r   s     r?   __rand__Integer.__rand__  8    ec7#3#34553u:.//!!re   c                    [        U[        [        [        R                  45      (       a!  [        U R
                  [        U5      -  5      $ [        $ r:   rU  r   s     r?   __xor__Integer.__xor__  ri  re   c                    [        U[        [        R                  45      (       a!  [	        [        U5      U R
                  -  5      $ [        $ r:   r\  r   s     r?   __rxor__Integer.__rxor__  rm  re   c                    [        U[        [        [        R                  45      (       a!  [        U R
                  [        U5      -  5      $ [        $ r:   rU  r   s     r?   __or__Integer.__or__  ri  re   c                    [        U[        [        R                  45      (       a!  [	        [        U5      U R
                  -  5      $ [        $ r:   r\  r   s     r?   __ror__Integer.__ror__  rm  re   c                .    [        U R                  ) 5      $ r:   r  r   s    r?   
__invert__Integer.__invert__  r  re   )>r   rs  rt  ru  rv  r|   r  r;   r   ry  r   r  r   r   rm  r  r   r   r   r   r  r  r   r   r  r  r  r~  r$  r  r  r  r+  r/  r;  r4  r?  r8  rD  r)  r-  r  rF  rJ  r  r   r   rO  rR  rX  r]  ra  rd  rg  rk  ro  rr  ru  rx  r{  r|  r}  r~  s   @r?   r   r     s:   4 	
AJIJI07  4 $22
$.	-.	-.-.,!,,,,
 l\
 (& )&3""""""""""   re   r   c                     ^  \ rS rSr% SrSrSrSrSr\	r
\" 5       rS\S'   SS jrU 4S jrS	 r\S
 5       rSS jrSS jrS rS rS rS rS r\S 5       rS rSS jrS rSS jrSrU =r $ )AlgebraicNumberi  a   
Class for representing algebraic numbers in SymPy.

Symbolically, an instance of this class represents an element
$\alpha \in \mathbb{Q}(\theta) \hookrightarrow \mathbb{C}$. That is, the
algebraic number $\alpha$ is represented as an element of a particular
number field $\mathbb{Q}(\theta)$, with a particular embedding of this
field into the complex numbers.

Formally, the primitive element $\theta$ is given by two data points: (1)
its minimal polynomial (which defines $\mathbb{Q}(\theta)$), and (2) a
particular complex number that is a root of this polynomial (which defines
the embedding $\mathbb{Q}(\theta) \hookrightarrow \mathbb{C}$). Finally,
the algebraic number $\alpha$ which we represent is then given by the
coefficients of a polynomial in $\theta$.
)reprootaliasminpoly_own_minpolyTz
set[Basic]free_symbolsc                   SSK JnJn  SSKJn  [        U5      nSnSn	[        U[        [        45      (       a$  Uu  pU
R                  (       d  SSK
Jn  U" U
5      n
OZUR                  (       a2  UR                  UR                  UR                  UR                   4u  ppOU" XR#                  S5      SS9UpU
R%                  5       nUbm  [        X%5      (       d%  UR'                  [        U5      SU5      n[        U6 nOYUR)                  UR+                  5       SU5      n[        UR+                  5       6 nO!UR)                  S	S/SU5      n[        S	S5      nUbG  SS
KJn  U" UR+                  5       UR+                  5       U5      nUR)                  USU5      n[        U6 nUR1                  5       U
R1                  5       :  a  UR3                  U
R                  5      nX4nU=(       d    U	nUb%  S	SKJn  [        UU5      (       d  U" U5      nUU4-   n[8        R:                  " U /UQ76 nUUl        UUl        UUl        U
Ul        SUl        U$ )aE  
Construct a new algebraic number $\alpha$ belonging to a number field
$k = \mathbb{Q}(\theta)$.

There are four instance attributes to be determined:

===========  ============================================================================
Attribute    Type/Meaning
===========  ============================================================================
``root``     :py:class:`~.Expr` for $\theta$ as a complex number
``minpoly``  :py:class:`~.Poly`, the minimal polynomial of $\theta$
``rep``      :py:class:`~sympy.polys.polyclasses.DMP` giving $\alpha$ as poly in $\theta$
``alias``    :py:class:`~.Symbol` for $\theta$, or ``None``
===========  ============================================================================

See Parameters section for how they are determined.

Parameters
==========

expr : :py:class:`~.Expr`, or pair $(m, r)$
    There are three distinct modes of construction, depending on what
    is passed as *expr*.

    **(1)** *expr* is an :py:class:`~.AlgebraicNumber`:
    In this case we begin by copying all four instance attributes from
    *expr*. If *coeffs* were also given, we compose the two coeff
    polynomials (see below). If an *alias* was given, it overrides.

    **(2)** *expr* is any other type of :py:class:`~.Expr`:
    Then ``root`` will equal *expr*. Therefore it
    must express an algebraic quantity, and we will compute its
    ``minpoly``.

    **(3)** *expr* is an ordered pair $(m, r)$ giving the
    ``minpoly`` $m$, and a ``root`` $r$ thereof, which together
    define $\theta$. In this case $m$ may be either a univariate
    :py:class:`~.Poly` or any :py:class:`~.Expr` which represents the
    same, while $r$ must be some :py:class:`~.Expr` representing a
    complex number that is a root of $m$, including both explicit
    expressions in radicals, and instances of
    :py:class:`~.ComplexRootOf` or :py:class:`~.AlgebraicNumber`.

coeffs : list, :py:class:`~.ANP`, None, optional (default=None)
    This defines ``rep``, giving the algebraic number $\alpha$ as a
    polynomial in $\theta$.

    If a list, the elements should be integers or rational numbers.
    If an :py:class:`~.ANP`, we take its coefficients (using its
    :py:meth:`~.ANP.to_list()` method). If ``None``, then the list of
    coefficients defaults to ``[1, 0]``, meaning that $\alpha = \theta$
    is the primitive element of the field.

    If *expr* was an :py:class:`~.AlgebraicNumber`, let $g(x)$ be its
    ``rep`` polynomial, and let $f(x)$ be the polynomial defined by
    *coeffs*. Then ``self.rep`` will represent the composition
    $(f \circ g)(x)$.

alias : str, :py:class:`~.Symbol`, None, optional (default=None)
    This is a way to provide a name for the primitive element. We
    described several ways in which the *expr* argument can define the
    value of the primitive element, but none of these methods gave it
    a name. Here, for example, *alias* could be set as
    ``Symbol('theta')``, in order to make this symbol appear when
    $\alpha$ is printed, or rendered as a polynomial, using the
    :py:meth:`~.as_poly()` method.

Examples
========

Recall that we are constructing an algebraic number as a field element
$\alpha \in \mathbb{Q}(\theta)$.

>>> from sympy import AlgebraicNumber, sqrt, CRootOf, S
>>> from sympy.abc import x

Example (1): $\alpha = \theta = \sqrt{2}$

>>> a1 = AlgebraicNumber(sqrt(2))
>>> a1.minpoly_of_element().as_expr(x)
x**2 - 2
>>> a1.evalf(10)
1.414213562

Example (2): $\alpha = 3 \sqrt{2} - 5$, $\theta = \sqrt{2}$. We can
either build on the last example:

>>> a2 = AlgebraicNumber(a1, [3, -5])
>>> a2.as_expr()
-5 + 3*sqrt(2)

or start from scratch:

>>> a2 = AlgebraicNumber(sqrt(2), [3, -5])
>>> a2.as_expr()
-5 + 3*sqrt(2)

Example (3): $\alpha = 6 \sqrt{2} - 11$, $\theta = \sqrt{2}$. Again we
can build on the previous example, and we see that the coeff polys are
composed:

>>> a3 = AlgebraicNumber(a2, [2, -1])
>>> a3.as_expr()
-11 + 6*sqrt(2)

reflecting the fact that $(2x - 1) \circ (3x - 5) = 6x - 11$.

Example (4): $\alpha = \sqrt{2}$, $\theta = \sqrt{2} + \sqrt{3}$. The
easiest way is to use the :py:func:`~.to_number_field()` function:

>>> from sympy import to_number_field
>>> a4 = to_number_field(sqrt(2), sqrt(2) + sqrt(3))
>>> a4.minpoly_of_element().as_expr(x)
x**2 - 2
>>> a4.to_root()
sqrt(2)
>>> a4.primitive_element()
sqrt(2) + sqrt(3)
>>> a4.coeffs()
[1/2, 0, -9/2, 0]

but if you already knew the right coefficients, you could construct it
directly:

>>> a4 = AlgebraicNumber(sqrt(2) + sqrt(3), [S(1)/2, 0, S(-9)/2, 0])
>>> a4.to_root()
sqrt(2)
>>> a4.primitive_element()
sqrt(2) + sqrt(3)

Example (5): Construct the Golden Ratio as an element of the 5th
cyclotomic field, supposing we already know its coefficients. This time
we introduce the alias $\zeta$ for the primitive element of the field:

>>> from sympy import cyclotomic_poly
>>> from sympy.abc import zeta
>>> a5 = AlgebraicNumber(CRootOf(cyclotomic_poly(5), -1),
...                  [-1, -1, 0, 0], alias=zeta)
>>> a5.as_poly().as_expr()
-zeta**3 - zeta**2
>>> a5.evalf()
1.61803398874989

(The index ``-1`` to ``CRootOf`` selects the complex root with the
largest real and imaginary parts, which in this case is
$\mathrm{e}^{2i\pi/5}$. See :py:class:`~.ComplexRootOf`.)

Example (6): Building on the last example, construct the number
$2 \phi \in \mathbb{Q}(\phi)$, where $\phi$ is the Golden Ratio:

>>> from sympy.abc import phi
>>> a6 = AlgebraicNumber(a5.to_root(), coeffs=[2, 0], alias=phi)
>>> a6.as_poly().as_expr()
2*phi
>>> a6.primitive_element().evalf()
1.61803398874989

Note that we needed to use ``a5.to_root()``, since passing ``a5`` as
the first argument would have constructed the number $2 \phi$ as an
element of the field $\mathbb{Q}(\zeta)$:

>>> a6_wrong = AlgebraicNumber(a5, coeffs=[2, 0])
>>> a6_wrong.as_poly().as_expr()
-2*zeta**3 - 2*zeta**2
>>> a6_wrong.primitive_element().evalf()
0.309016994374947 + 0.951056516295154*I

r   )ANPDMP)minimal_polynomialNPolygenTpolysr   )dup_compose)Symbol)sympy.polys.polyclassesr  r  sympy.polys.numberfieldsr  r	   rL   r   r   is_Polyr   r  is_AlgebraicNumberr  r  r  r  get
get_domainfrom_sympy_list	from_listto_listsympy.polys.densetoolsr  degreeremsymbolr  r   r   r  )r   exprcoeffsr  r   r  r  r  rep0alias0r  r  r  domr  scoeffsr  csargsr  r   s                        r?   r   AlgebraicNumber.__new__  s   R 	5?t}dUEN++ MG??6w-$$+/<<+/88TZZ+A'G4 /hhuoT348    "f**))'&/1cB.mmFNN$4a=!12 --A3/CAqkG:CKKM4<<>3?A--1c*CQiG::<7>>++'''++&C&eV,,uUH$Ell3''	
re   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  AlgebraicNumber.__hash__	  rG  re   c                @    U R                  5       R                  U5      $ r:   )as_expr_evalfr   s     r?   r   AlgebraicNumber._eval_evalf	  s    ||~$$T**re   c                    U R                   SL$ )z'Returns ``True`` if ``alias`` was set. N)r  r   s    r?   
is_aliasedAlgebraicNumber.is_aliased	  s     zz%%re   c                   SSK JnJn  Ub  UR                  U R                  U5      $ U R
                  b&  UR                  U R                  U R
                  5      $ SSKJn  UR                  U R                  U" S5      5      $ )z&Create a Poly instance from ``self``. r   )r  PurePolyr   Dummyr2  )r   r  r  r	  r  r  r  r  )r   r2  r  r  r  s        r?   as_polyAlgebraicNumber.as_poly	  s^    8=88DHHa((zz%xx$**55)||DHHeCj99re   c                    U R                  U=(       d    U R                  5      R                  5       R                  5       $ )z)Create a Basic expression from ``self``. )r  r  r  expand)r   r2  s     r?   r  AlgebraicNumber.as_expr	  s+    ||AN+335<<>>re   c                    U R                   R                  5        Vs/ s H'  oR                   R                  R                  U5      PM)     sn$ s  snf )z7Returns all SymPy coefficients of an algebraic number. )r  
all_coeffsr  to_sympyr   r  s     r?   r  AlgebraicNumber.coeffs	  s:    37883F3F3HJ3Ha&&q)3HJJJs   .Ac                6    U R                   R                  5       $ )z8Returns all native coefficients of an algebraic number. )r  r  r   s    r?   native_coeffsAlgebraicNumber.native_coeffs	  s    xx""$$re   c                v   SSK Jn  U R                  nUR                  5       S:X  a  U $ UR                  5       UR	                  5       S-
  -  nUR                  U" UR                  UR                  5       -  5      5      nXC-  nUR                  5       U R                  -  n[        XV4U R                  5       5      $ )z*Convert ``self`` to an algebraic integer. r   r  r   )
r   r  r  LCr  composer  r  r~  r  )r   r  r   coeffpolyr  r  s          r?   to_algebraic_integer$AlgebraicNumber.to_algebraic_integer	  s    .LL446Q;Ka(yyaeeADDFl+,*ttvdii>>re   c                b   SSK Jn  SSKJn  US   US   pTU R                  R	                  5        Vs/ s H  ofR
                  U:w  d  M  UPM     sn HT  nU" U R                  U-
  5      R                  (       d  M)  U" U5      XT" U R                  5      -  :  d  MI  [        U5      s  $    U $ s  snf )Nr   )CRootOfr  measureratio)	sympy.polys.rootoftoolsr  sympy.polysr  	all_rootsfuncr  	is_Symbolr~  )r   rV  r  r  r  r  r   s          r?   _eval_simplifyAlgebraicNumber._eval_simplify	  s    3'	*F7O!\\335K579J!5KAtyy1}%///1:gdii&8 88*1--	 L
  Ls   B,	B,c                V    [        U R                  U R                  4XR                  S9$ )at  
Form another element of the same number field.

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

If we represent $\alpha \in \mathbb{Q}(\theta)$, form another element
$\beta \in \mathbb{Q}(\theta)$ of the same number field.

Parameters
==========

coeffs : list, :py:class:`~.ANP`
    Like the *coeffs* arg to the class
    :py:meth:`constructor<.AlgebraicNumber.__new__>`, defines the
    new element as a polynomial in the primitive element.

    If a list, the elements should be integers or rational numbers.
    If an :py:class:`~.ANP`, we take its coefficients (using its
    :py:meth:`~.ANP.to_list()` method).

Examples
========

>>> from sympy import AlgebraicNumber, sqrt
>>> a = AlgebraicNumber(sqrt(5), [-1, 1])
>>> b = a.field_element([3, 2])
>>> print(a)
1 - sqrt(5)
>>> print(b)
2 + 3*sqrt(5)
>>> print(b.primitive_element() == a.primitive_element())
True

See Also
========

AlgebraicNumber
)r  r  )r~  r  r  r  )r   r  s     r?   field_elementAlgebraicNumber.field_element	  s*    P \\499%fJJH 	Hre   c                \    U R                  5       nUSS/:H  =(       d    XR                  /:H  $ )z}
Say whether this algebraic number $\alpha \in \mathbb{Q}(\theta)$ is
equal to the primitive element $\theta$ for its field.
r   r   )r  r  r  s     r?   is_primitive_element$AlgebraicNumber.is_primitive_element)
  s+     KKMQF{.aII;..re   c                N    U R                   (       a  U $ U R                  SS/5      $ )z
Get the primitive element $\theta$ for the number field
$\mathbb{Q}(\theta)$ to which this algebraic number $\alpha$ belongs.

Returns
=======

AlgebraicNumber

r   r   )r  r  r   s    r?   primitive_element!AlgebraicNumber.primitive_element3
  s'     $$K!!1a&))re   c                ~    U R                   (       a  U $ U R                  5       nU R                  US9n[        X#45      $ )a  
Convert ``self`` to an :py:class:`~.AlgebraicNumber` instance that is
equal to its own primitive element.

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

If we represent $\alpha \in \mathbb{Q}(\theta)$, $\alpha \neq \theta$,
construct a new :py:class:`~.AlgebraicNumber` that represents
$\alpha \in \mathbb{Q}(\alpha)$.

Examples
========

>>> from sympy import sqrt, to_number_field
>>> from sympy.abc import x
>>> a = to_number_field(sqrt(2), sqrt(2) + sqrt(3))

The :py:class:`~.AlgebraicNumber` ``a`` represents the number
$\sqrt{2}$ in the field $\mathbb{Q}(\sqrt{2} + \sqrt{3})$. Rendering
``a`` as a polynomial,

>>> a.as_poly().as_expr(x)
x**3/2 - 9*x/2

reflects the fact that $\sqrt{2} = \theta^3/2 - 9 \theta/2$, where
$\theta = \sqrt{2} + \sqrt{3}$.

``a`` is not equal to its own primitive element. Its minpoly

>>> a.minpoly.as_poly().as_expr(x)
x**4 - 10*x**2 + 1

is that of $\theta$.

Converting to a primitive element,

>>> a_prim = a.to_primitive_element()
>>> a_prim.minpoly.as_poly().as_expr(x)
x**2 - 2

we obtain an :py:class:`~.AlgebraicNumber` whose ``minpoly`` is that of
the number itself.

Parameters
==========

radicals : boolean, optional (default=True)
    If ``True``, then we will try to return an
    :py:class:`~.AlgebraicNumber` whose ``root`` is an expression
    in radicals. If that is not possible (or if *radicals* is
    ``False``), ``root`` will be a :py:class:`~.ComplexRootOf`.

Returns
=======

AlgebraicNumber

See Also
========

is_primitive_element

radicals)r  minpoly_of_elementto_rootr~  )r   r  r   r   s       r?   to_primitive_element$AlgebraicNumber.to_primitive_elementB
  s>    B $$K##%LL(L+v&&re   c                    U R                   c_  U R                  (       a  U R                  U l         U R                   $ SSKJn  U R	                  5       nU" U R                  U5      SS9U l         U R                   $ )a;  
Compute the minimal polynomial for this algebraic number.

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

Recall that we represent an element $\alpha \in \mathbb{Q}(\theta)$.
Our instance attribute ``self.minpoly`` is the minimal polynomial for
our primitive element $\theta$. This method computes the minimal
polynomial for $\alpha$.

r   r  Tr  )r  r  r   sympy.polys.numberfields.minpolyr  r  )r   r  thetas      r?   r  "AlgebraicNumber.minpoly_of_element
  sk     $(($(LL!
     E..0$+DLL,?t$L!   re   c                Z   U R                   (       a+  [        U R                  [        5      (       d  U R                  $ U=(       d    U R	                  5       nUR                  US9n[        U5      S:X  a  US   $ U R                  5       nU H  nUR                  Xe5      (       d  M  Us  $    g)a3  
Convert to an :py:class:`~.Expr` that is not an
:py:class:`~.AlgebraicNumber`, specifically, either a
:py:class:`~.ComplexRootOf`, or, optionally and where possible, an
expression in radicals.

Parameters
==========

radicals : boolean, optional (default=True)
    If ``True``, then we will try to return the root as an expression
    in radicals. If that is not possible, we will return a
    :py:class:`~.ComplexRootOf`.

minpoly : :py:class:`~.Poly`
    If the minimal polynomial for `self` has been pre-computed, it can
    be passed in order to save time.

r  r   r   N)	r  rL   r  r~  r  r  r   r  	same_root)r   r  r  r   rootsr?  r]   s          r?   r  AlgebraicNumber.to_root
  s    ( $$Z		?-S-S990t..0X.u:?8O\\^A{{1!! re   )r  rC  r:   rD  )TN)!r   rs  rt  ru  rv  ry  r  is_algebraicr;   r   rz  setr  rE  r   rD  r   rN  r  r  r  r  r  r  r  r  r  r  r  r  r  r|  r}  r~  s   @r?   r~  r~    s    " DILI D
  #uL*$fP"+ & &
:?K%?"	)HV / /*E'N!, re   r~  c                  "    \ rS rSrSrSrS rSrg)RationalConstanti
  z
Abstract base class for rationals with specific behaviors

Derived classes must define class attributes p and q and should probably all
be singletons.
r   c                .    [         R                  " U 5      $ r:   r   r   r  s    r?   r   RationalConstant.__new__
      !!#&&re   N)r   rs  rt  ru  rv  ry  r   r|  r   re   r?   r  r  
  s     I're   r  c                      \ rS rSrSrS rSrg)IntegerConstanti
  r   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   IntegerConstant.__new__
  r  re   N)r   rs  rt  ru  ry  r   r|  r   re   r?   r  r  
  s    I're   r  c                  p    \ 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	 5       r\S
 5       rS rS rS rSrg)r'  i
  zThe number zero.

Zero is a singleton, and can be accessed by ``S.Zero``

Examples
========

>>> from sympy import S, Integer
>>> Integer(0) is S.Zero
True
>>> 1/S.Zero
zoo

References
==========

.. [1] https://en.wikipedia.org/wiki/Zero
r   r   FTr   c                    grQ  r   r   s    r?   rm  Zero.__getnewargs__
      re   c                 "    [         R                  $ r:   rd  r   re   r?   r  Zero.__abs__
      vvre   c                 "    [         R                  $ r:   rd  r   re   r?   r  Zero.__neg__
  r  re   c                   UR                   (       a  U $ UR                  (       a  [        R                  $ UR                  SL a  [        R
                  $ UR                  (       a  [        R                  $ UR                  5       u  p#UR                  (       a  [        R                  U-  $ U[        R                  La  X-  $ g r  )
r  r   r   r  rI  r   r"  r  r`  rS  )r   rn   r  termss       r?   r  Zero._eval_power
  s    $$K$$$$$  E)55L<<55L
 ((*$$e++; re   c                    U $ r:   r   r   r  s     r?   r  Zero._eval_order      re   c                    gr  r   r   s    r?   r  Zero.__bool__  s    re   N)r   rs  rt  ru  rv  rz   r|   r#  rS  r"  r;   r%  ry  rm  staticmethodr  r  r  r  r  r|  r   re   r?   r'  r'  
  sm    & 	
A	AKKGIMI    &re   r'  )	metaclassc                  v    \ rS rSrSrSrSrSrSrSr	S r
\S 5       r\S 5       rS	 rS
 r\  SS j5       rSrg)r  i  zThe number one.

One is a singleton, and can be accessed by ``S.One``.

Examples
========

>>> from sympy import S, Integer
>>> Integer(1) is S.One
True

References
==========

.. [1] https://en.wikipedia.org/wiki/1_%28number%29
Tr   r   c                    grQ  r   r   s    r?   rm  One.__getnewargs__0  r  re   c                 "    [         R                  $ r:   r^  r   re   r?   r  One.__abs__3      uure   c                 "    [         R                  $ r:   )r   rT  r   re   r?   r  One.__neg__7  s    }}re   c                    U $ r:   r   r   rn   s     r?   r  One._eval_power;  r   re   c                    g r:   r   r  s     r?   r  One._eval_order>  s    re   Nc                4    U(       a  [         R                  $ 0 $ r:   r^  )r  r  r  r  r  r  s         r?   r  One.factorsA  s     55LIre   r  )r   rs  rt  ru  rv  r;   r#  rz   r|   ry  rm  r	  r  r  r  r  r  r|  r   re   r?   r  r    ss      IK	A	AI     CH&+ re   r  c                  T    \ rS rSrSrSrSrSrSrS r	\
S 5       r\
S	 5       rS
 rSrg)rT  iJ  a)  The number negative one.

NegativeOne is a singleton, and can be accessed by ``S.NegativeOne``.

Examples
========

>>> from sympy import S, Integer
>>> Integer(-1) is S.NegativeOne
True

See Also
========

One

References
==========

.. [1] https://en.wikipedia.org/wiki/%E2%88%921_%28number%29

Trx   r   r   c                    grQ  r   r   s    r?   rm  NegativeOne.__getnewargs__h  r  re   c                 "    [         R                  $ r:   r^  r   re   r?   r  NegativeOne.__abs__k  r  re   c                 "    [         R                  $ r:   r^  r   re   r?   r  NegativeOne.__neg__o  r  re   c                   UR                   (       a  [        R                  $ UR                  (       a  [        R                  $ [        U[        5      (       Ga.  [        U[        5      (       a  [        S5      U-  $ U[        R                  L a  [        R                  $ U[        R                  [        R                  4;   a  [        R                  $ U[        R                  L a  [        R                  $ [        U[        5      (       a|  UR                  S:X  a&  [        R                  [        UR                   5      -  $ [#        UR                   UR                  5      u  p#U(       a  X-  U [        X1R                  5      -  -  $ g )Ng      r5   )is_oddr   rT  r  r  rL   r   rQ   r   r   r   rf  r
  r   r|   r   rz   r   )r   rn   r>   r   s       r?   r  NegativeOne._eval_powers  s    ;;== <<55LdF##$&&T{D((quu}uu

A$6$677uuqvv~&$))66Q;??GDFFO;;dffdff-74!VV)<#<<<re   N)r   rs  rt  ru  rv  r;   rz   r|   ry  rm  r	  r  r  r  r|  r   re   r?   rT  rT  J  sO    , I
A	AI    re   rT  c                  >    \ rS rSrSrSrSrSrSrS r	\
S 5       rSrg	)
rf  i  zThe rational number 1/2.

Half is a singleton, and can be accessed by ``S.Half``.

Examples
========

>>> from sympy import S, Rational
>>> Rational(1, 2) is S.Half
True

References
==========

.. [1] https://en.wikipedia.org/wiki/One_half
Tr   r5   r   c                    grQ  r   r   s    r?   rm  Half.__getnewargs__  r  re   c                 "    [         R                  $ r:   )r   rf  r   re   r?   r  Half.__abs__  r  re   N)r   rs  rt  ru  rv  r;   rz   r|   ry  rm  r	  r  r|  r   re   r?   rf  rf    s6      I	A	AI  re   rf  c                    ^  \ 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S	 jrSS
 jr\" S\5      S 5       r\r\" S\5      S 5       r\" S\5      S 5       r\" S\5      S 5       r\r\" S\5      S 5       rS rS rS rS rU 4S jr S r!S r"\#RH                  r$\#RJ                  r%\#RL                  r&\#RN                  r'\" S\5      S 5       r(\(r)S r*S r+Sr,U =r-$ )r   i  a[  Positive infinite quantity.

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

In real analysis the symbol `\infty` denotes an unbounded
limit: `x\to\infty` means that `x` grows without bound.

Infinity is often used not only to define a limit but as a value
in the affinely extended real number system.  Points labeled `+\infty`
and `-\infty` can be added to the topological space of the real numbers,
producing the two-point compactification of the real numbers.  Adding
algebraic properties to this gives us the extended real numbers.

Infinity is a singleton, and can be accessed by ``S.Infinity``,
or can be imported as ``oo``.

Examples
========

>>> from sympy import oo, exp, limit, Symbol
>>> 1 + oo
oo
>>> 42/oo
0
>>> x = Symbol('x')
>>> limit(exp(x), x, oo)
oo

See Also
========

NegativeInfinity, NaN

References
==========

.. [1] https://en.wikipedia.org/wiki/Infinity
TFr   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   Infinity.__new__  r  re   c                    g)Nz\inftyr   r   printers     r?   _latexInfinity._latex      re   c                    X:X  a  U$ g r:   r   r  s      r?   r
  Infinity._eval_subs      ;J re   c                    [        S5      $ Nr   rQ   r   s     r?   r   Infinity._eval_evalf  s    U|re   c                $    U R                  U5      $ r:   r   r   rk   optionss      r?   r&  Infinity.evalf      %%re   r   c                    [        U[        5      (       aK  [        R                  (       a6  U[        R
                  [        R                  4;   a  [        R                  $ U $ [        R                  X5      $ r:   )rL   r   r4   r  r   r   r   r  r   s     r?   r  Infinity.__add__  L    eV$$):)C)C++QUU33uuK~~d**re   c                    [        U[        5      (       aK  [        R                  (       a6  U[        R
                  [        R                  4;   a  [        R                  $ U $ [        R                  X5      $ r:   )rL   r   r4   r  r   r   r   r  r   s     r?   r  Infinity.__sub__  J    eV$$):)C)CQUU++uuK~~d**re   c                &    U * R                  U5      $ r:   r  r   s     r?   r~  Infinity.__rsub__      u%%re   c                .   [        U[        5      (       al  [        R                  (       aW  UR                  (       d  U[
        R                  L a  [
        R                  $ UR                  (       a  U $ [
        R                  $ [        R                  X5      $ r:   )
rL   r   r4   r  r"  r   r   r  r   r$  r   s     r?   r$  Infinity.__mul__  s[    eV$$):)C)C}}uu))%%%~~d**re   c                X   [        U[        5      (       a  [        R                  (       al  U[        R
                  L d&  U[        R                  L d  U[        R                  L a  [        R                  $ UR                  (       a  U $ [        R                  $ [        R                  X5      $ r:   
rL   r   r4   r  r   r   r   r   is_extended_nonnegativer(  r   s     r?   r(  Infinity.__truediv__  sq    eV$$):)C)C

"+++QUUNuu,,%%%!!$..re   c                "    [         R                  $ r:   r   r   r   s    r?   r  Infinity.__abs__      zzre   c                "    [         R                  $ r:   )r   r   r   s    r?   r  Infinity.__neg__  s    !!!re   c                \   UR                   (       a  [        R                  $ UR                  (       a  [        R                  $ U[        R
                  L a  [        R
                  $ U[        R                  L a  [        R
                  $ UR                  SL a  UR                  (       a  SSK	J
n  U" U5      nUR                  (       a  [        R                  $ UR                  (       a  [        R                  $ UR                  (       a  [        R
                  $ XR                  5       -  $ gg)au  
``expt`` is symbolic object but not equal to 0 or 1.

================ ======= ==============================
Expression       Result  Notes
================ ======= ==============================
``oo ** nan``    ``nan``
``oo ** -p``     ``0``   ``p`` is number, ``oo``
================ ======= ==============================

See Also
========
Pow
NaN
NegativeInfinity

Fr   )r  N)r  r   r   r   r'  r   r  rI  r;   r   r  r#  rS  r"  r&  )r   rn   r  	expt_reals       r?   r  Infinity._eval_power   s    $ $$::$$66M155=55L1$$$55L  E)dnn?4I$$((($$vv  uu%% /=)re   c                "    [         R                  $ r:   )r   r+   r   s     r?   r   Infinity._as_mpf_valF  s    yyre   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  Infinity.__hash__I  rG  re   c                P    U[         R                  L =(       d    U[        S5      :H  $ r6  r   r   r   r   s     r?   r+  Infinity.__eq__L  s    

";euU|&;;re   c                P    U[         R                  L=(       a    U[        S5      :g  $ r6  r]  r   s     r?   r/  Infinity.__ne__O  s    AJJ&@5E%L+@@re   c                X    [        U[        5      (       d  [        $ [        R                  $ r:   rL   r   r   r   r   r   s     r?   r  Infinity.__mod__W      %&&!!uure   c                    U $ r:   r   r   s    r?   r   Infinity.floor_  r   re   c                    U $ r:   r   r   s    r?   r   Infinity.ceilingb  r   re   r:   ).r   rs  rt  ru  rv  rw  r;   
is_complexrI  r   r%  r  rI  ry  r   r/  r
  r   r&  r   r   r  r  r  r~  r$  r  r(  r  r  r  r   rD  r+  r/  r   r;  r?  r4  r8  r  r  r   r   r|  r}  r~  s   @r?   r   r     s^   &P NIJKMHI'& (+ )+ H(+ )+ (& )& (+ )+ H(	/ )	/"$&L"<A [[F[[F[[F[[F( )
 H re   r   c                    ^  \ 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S	 jrSS
 jr\" S\5      S 5       r\r\" S\5      S 5       r\" S\5      S 5       r\" S\5      S 5       r\r\" S\5      S 5       rS rS rS rS rU 4S jr S r!S r"\#RH                  r$\#RJ                  r%\#RL                  r&\#RN                  r'\" S\5      S 5       r(\(r)S r*S r+S r,Sr-U =r.$ )r   ih  zNegative infinite quantity.

NegativeInfinity is a singleton, and can be accessed
by ``S.NegativeInfinity``.

See Also
========

Infinity
TFr   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   NegativeInfinity.__new__  r  re   c                    g)Nz-\inftyr   r-  s     r?   r/  NegativeInfinity._latex  s    re   c                    X:X  a  U$ g r:   r   r  s      r?   r
  NegativeInfinity._eval_subs  r4  re   c                    [        S5      $ Nr   r7  r   s     r?   r   NegativeInfinity._eval_evalf  s    V}re   c                $    U R                  U5      $ r:   r:  r;  s      r?   r&  NegativeInfinity.evalf  r>  re   r   c                    [        U[        5      (       aK  [        R                  (       a6  U[        R
                  [        R                  4;   a  [        R                  $ U $ [        R                  X5      $ r:   )rL   r   r4   r  r   r   r   r  r   s     r?   r  NegativeInfinity.__add__  rD  re   c                    [        U[        5      (       aK  [        R                  (       a6  U[        R
                  [        R                  4;   a  [        R                  $ U $ [        R                  X5      $ r:   )rL   r   r4   r  r   r   r   r  r   s     r?   r  NegativeInfinity.__sub__  rA  re   c                &    U * R                  U5      $ r:   rF  r   s     r?   r~  NegativeInfinity.__rsub__  rH  re   c                .   [        U[        5      (       al  [        R                  (       aW  UR                  (       d  U[
        R                  L a  [
        R                  $ UR                  (       a  U $ [
        R                  $ [        R                  X5      $ r:   )
rL   r   r4   r  r"  r   r   r  r   r$  r   s     r?   r$  NegativeInfinity.__mul__  sY    eV$$):)C)C}}uu))::~~d**re   c                X   [        U[        5      (       a  [        R                  (       al  U[        R
                  L d&  U[        R                  L d  U[        R                  L a  [        R                  $ UR                  (       a  U $ [        R
                  $ [        R                  X5      $ r:   rL  r   s     r?   r(  NegativeInfinity.__truediv__  so    eV$$):)C)C

"+++QUUNuu,,::!!$..re   c                "    [         R                  $ r:   rP  r   s    r?   r  NegativeInfinity.__abs__  rR  re   c                "    [         R                  $ r:   rP  r   s    r?   r  NegativeInfinity.__neg__  rR  re   c                x   UR                   (       Ga(  U[        R                  L d&  U[        R                  L d  U[        R                  L a  [        R                  $ [        U[        5      (       aB  UR                  (       a1  UR                  (       a  [        R                  $ [        R                  $ [        R                  U-  n[        R                  U-  nUS:X  a  UR                  (       a  U$ U[        R                  L a2  UR                  (       a!  UR                  (       d  [        R                  $ X2-  $ g)a  
``expt`` is symbolic object but not equal to 0 or 1.

================ ======= ==============================
Expression       Result  Notes
================ ======= ==============================
``(-oo) ** nan`` ``nan``
``(-oo) ** oo``  ``nan``
``(-oo) ** -oo`` ``nan``
``(-oo) ** e``   ``oo``  ``e`` is positive even integer
``(-oo) ** o``   ``-oo`` ``o`` is positive odd integer
================ ======= ==============================

See Also
========

Infinity
Pow
NaN

r   N)r;   r   r   r   r   rL   r   r  r"  rT  r   r  r"  )r   rn   inf_parts_parts       r?   r  NegativeInfinity._eval_power  s    , >>>quu}

"A...uu$((T-F-F;;---::%zz4'H]]D(F1}!1!1A---$$V^^(((?"' re   c                "    [         R                  $ r:   )r   r,   r   s     r?   r   NegativeInfinity._as_mpf_val  s    zzre   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  NegativeInfinity.__hash__  rG  re   c                P    U[         R                  L =(       d    U[        S5      :H  $ rr  r   r   r   r   s     r?   r+  NegativeInfinity.__eq__  s!    ***DeuV}.DDre   c                P    U[         R                  L=(       a    U[        S5      :g  $ rr  r  r   s     r?   r/  NegativeInfinity.__ne__  s!    A...I5E&M3IIre   c                X    [        U[        5      (       d  [        $ [        R                  $ r:   rb  r   s     r?   r  NegativeInfinity.__mod__  rd  re   c                    U $ r:   r   r   s    r?   r   NegativeInfinity.floor  r   re   c                    U $ r:   r   r   s    r?   r   NegativeInfinity.ceiling  r   re   c                F    [         R                  S[         R                  S0$ r"  )r   rT  r   r   s    r?   as_powers_dictNegativeInfinity.as_powers_dict  s    q!**a00re   r:   )/r   rs  rt  ru  rv  rI  ri  rw  r   r%  r   r;   rI  ry  r   r/  r
  r   r&  r   r   r  r  r  r~  r$  r  r(  r  r  r  r   rD  r+  r/  r   r;  r?  r4  r8  r  r  r   r   r  r|  r}  r~  s   @r?   r   r   h  sc   	 JNKMIHI'& (+ )+ H(+ )+ (& )& (+ )+ H(	/ )	/)#V"EJ [[F[[F[[F[[F( )
 H1 1re   r   c                  p  ^  \ 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
\5      S 5       r\" S
\5      S 5       r\" S
\5      S 5       r\" S
\5      S 5       rS rS rS rU 4S jr S r!S r"\#RH                  r$\#RJ                  r%\#RL                  r&\#RN                  r'Sr(U =r)$ )r   i  a  
Not a Number.

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

This serves as a place holder for numeric values that are indeterminate.
Most operations on NaN, produce another NaN.  Most indeterminate forms,
such as ``0/0`` or ``oo - oo` produce NaN.  Two exceptions are ``0**0``
and ``oo**0``, which all produce ``1`` (this is consistent with Python's
float).

NaN is loosely related to floating point nan, which is defined in the
IEEE 754 floating point standard, and corresponds to the Python
``float('nan')``.  Differences are noted below.

NaN is mathematically not equal to anything else, even NaN itself.  This
explains the initially counter-intuitive results with ``Eq`` and ``==`` in
the examples below.

NaN is not comparable so inequalities raise a TypeError.  This is in
contrast with floating point nan where all inequalities are false.

NaN is a singleton, and can be accessed by ``S.NaN``, or can be imported
as ``nan``.

Examples
========

>>> from sympy import nan, S, oo, Eq
>>> nan is S.NaN
True
>>> oo - oo
nan
>>> nan + 1
nan
>>> Eq(nan, nan)   # mathematical equality
False
>>> nan == nan     # structural equality
True

References
==========

.. [1] https://en.wikipedia.org/wiki/NaN

TNFr   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   NaN.__new__P  r  re   c                    g)Nz
\text{NaN}r   r-  s     r?   r/  
NaN._latexS  s    re   c                    U $ r:   r   r   s    r?   r  NaN.__neg__V  r   re   r   c                    U $ r:   r   r   s     r?   r  NaN.__add__Y  r  re   c                    U $ r:   r   r   s     r?   r  NaN.__sub__]  r  re   c                    U $ r:   r   r   s     r?   r$  NaN.__mul__a  r  re   c                    U $ r:   r   r   s     r?   r(  NaN.__truediv__e  r  re   c                    U $ r:   r   r   s    r?   r   	NaN.floori  r   re   c                    U $ r:   r   r   s    r?   r   NaN.ceilingl  r   re   c                    [         $ r:   )r  r   s     r?   r   NaN._as_mpf_valo  s    re   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  NaN.__hash__r  rG  re   c                &    U[         R                  L $ r:   r   r   r   s     r?   r+  
NaN.__eq__u  s    ~re   c                &    U[         R                  L$ r:   r  r   s     r?   r/  
NaN.__ne__y  s    AEE!!re   )*r   rs  rt  ru  rv  rw  rI  rH  rF  r  is_transcendentalr  r%  r   r"  rI  r#  rS  r;   ry  r   r/  r  r   r   r  r  r$  r(  r   r   r   rD  r+  r/  r   r;  r?  r4  r8  r|  r}  r~  s   @r?   r   r     s   .^ NGKLJMIGHKKII' ( ) ( ) ( ) ( )"" [[F[[F[[F[[Fre   r   c                    gr  r   )r\   r]   s     r?   _eval_is_eqr        re   c                  v    \ rS rSrSrSrSrSrSrSr	Sr
\rSrS rS r\S 5       rS	 rS
 r\S 5       rS rSrg)r  i  a  Complex infinity.

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

In complex analysis the symbol `\tilde\infty`, called "complex
infinity", represents a quantity with infinite magnitude, but
undetermined complex phase.

ComplexInfinity is a singleton, and can be accessed by
``S.ComplexInfinity``, or can be imported as ``zoo``.

Examples
========

>>> from sympy import zoo
>>> zoo + 42
zoo
>>> 42/zoo
0
>>> zoo + zoo
nan
>>> zoo*zoo
zoo

See Also
========

Infinity
TFr   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   ComplexInfinity.__new__  r  re   c                    g)Nz\tilde{\infty}r   r-  s     r?   r/  ComplexInfinity._latex  s     re   c                 "    [         R                  $ r:   rP  r   re   r?   r  ComplexInfinity.__abs__  s    zzre   c                    U $ r:   r   r   s    r?   r   ComplexInfinity.floor  r   re   c                    U $ r:   r   r   s    r?   r   ComplexInfinity.ceiling  r   re   c                 "    [         R                  $ r:   )r   r  r   re   r?   r  ComplexInfinity.__neg__  s       re   c                   U[         R                  L a  [         R                  $ [        U[        5      (       aR  UR
                  (       a  [         R                  $ UR                  (       a  [         R                  $ [         R                  $ g r:   )r   r  r   rL   r   r"  r#  r'  r  s     r?   r  ComplexInfinity._eval_power  sY    1$$$55LdF##||uu##,,,66M $re   N)r   rs  rt  ru  rv  rw  r   r;   rI  ri  rI  r   rz  ry  r   r/  r	  r  r   r   r  r  r|  r   re   r?   r  r    ss    > NKIHJDI'!   ! !"re   r  c                  p   ^  \ rS rSrSrSrSrSrSr\	r
S rS rS rS rS rS	 rS
 rS rU 4S jrSrU =r$ )r  i  Tr   c                .    [         R                  " U 5      $ r:   r  r  s    r?   r   NumberSymbol.__new__  r  re   c                    g)z|Return an interval with number_cls endpoints
that contains the value of NumberSymbol.
If not implemented, then return None.
Nr   r   
number_clss     r?   approximationNumberSymbol.approximation  s    re   c                L    [         R                  U R                  U5      U5      $ r:   r   r   s     r?   r   NumberSymbol._eval_evalf  r   re   c                     [        U5      nXL a  gUR                  (       a  U R                  (       a  gg! [         a	    [        s $ f = fr  )r   r   r   rx  rG  r   s     r?   r+  NumberSymbol.__eq__  sF    	"UOE =??t11  	"!!	"s   6 A	A	c                    X:X  + $ r:   r   r   s     r?   r/  NumberSymbol.__ne__  r  re   c                V    XL a  [         R                  $ [        R                  " X5      $ r:   )r   truer   r8  r   s     r?   r8  NumberSymbol.__le__       =66M{{4''re   c                V    XL a  [         R                  $ [        R                  " X5      $ r:   )r   r  r   r?  r   s     r?   r?  NumberSymbol.__ge__  r  re   c                    [         er:   r  r   s    r?   r  NumberSymbol.__int__
  s    !!re   c                    > [         TU ]  5       $ r:   rB  rE  s    r?   rD  NumberSymbol.__hash__  rG  re   )r   rs  rt  ru  rw  r   r;   ry  r  r   rz  r   r  r   r+  r/  r8  r?  r  rD  r|  r}  r~  s   @r?   r  r    sS    NIIIOD'8
!(
(
"" "re   r  c                  x    \ 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 5       rS rS	 rS
 rS rS rS rS rSrg)Exp1i  a  The `e` constant.

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

The transcendental number `e = 2.718281828\ldots` is the base of the
natural logarithm and of the exponential function, `e = \exp(1)`.
Sometimes called Euler's number or Napier's constant.

Exp1 is a singleton, and can be accessed by ``S.Exp1``,
or can be imported as ``E``.

Examples
========

>>> from sympy import exp, log, E
>>> E is exp(1)
True
>>> log(E)
1

References
==========

.. [1] https://en.wikipedia.org/wiki/E_%28mathematical_constant%29
TFr   c                    g)Nr   r   r-  s     r?   r/  Exp1._latex8  rM  re   c                 "    [         R                  $ r:   )r   r  r   re   r?   r  Exp1.__abs__;  r  re   c                    gr,  r   r   s    r?   r  Exp1.__int__?      re   c                    [        U5      $ r:   )r(   r   s     r?   r   Exp1._as_mpf_valB  s    T{re   c                    [        U[        5      (       a  [        S5      [        S5      4$ [        U[        5      (       a  g g )Nr5   r  
issubclassr   r   r  s     r?   approximation_intervalExp1.approximation_intervalE  s7    j'**AJ
++
H-- .re   c                j    [         R                  (       a  U R                  U5      $ SSKJn  U" U5      $ )Nr   )r  )r4   
exp_is_pow_eval_power_exp_is_pow&sympy.functions.elementary.exponentialr  )r   rn   r  s      r?   r  Exp1._eval_powerK  s)    ''..t44Bt9re   c                   UR                   (       a*  U[        L a  [        $ U[        * :X  a  [        R                  $ SSKJn  [        X5      (       a  UR                  S   $ UR                  (       Gd  [        [        -  nXU* 4;   a  [        $ UR                  [        [        -  5      nU(       Ga  SU-  R                  (       a  UR                  (       a  [        R                  $ UR                   (       a  [        R"                  $ U[        R$                  -   R                  (       a  [        * $ U[        R$                  -   R                   (       a  [        $ O[UR&                  (       aJ  US-  nUS:  a  US-  nXT:w  a5  [        R(                  U[        R*                  -  [        R,                  -  -  $ UR/                  5       u  pFU[        [        * 4;   a  g U/S p[0        R2                  " U5       HM  n	[        X5      (       a  Uc  U	R                  S   nM'    g U	R4                  (       a  UR7                  U	5        MM    g    U(       a  U[1        U6 -  $ S $ UR                  (       a  / n
/ nSnUR                   H  nU[        R                  L a  UR7                  U5        M)  X-  n[        U[8        5      (       aQ  UR:                  U L aB  UR<                  U:w  a  UR7                  UR<                  5        SnM  UR7                  U5        M  U
R7                  U5        M     U
(       d  U(       a  [1        U
6 [9        U [?        U6 SS9-  $ g UR@                  (       a  UR=                  5       $ g )Nr   )logr5   r   FTr  )!rx  oor   r'  r  r  rL   r   is_AddIr   r  pir  r  r  r"  rT  rf  rR  r  Pir
  r`  Mul	make_argsr%  appendr  baser  r  	is_Matrix)r   r  r  Ioor  ncoeffr  r  log_termtermoutadd
argchangedr\   newas                  r?   r  Exp1._eval_power_exp_is_powR  s   ==by	vv>c88A; B$CSDk!
IIbdOEeG''}} uu }},!&&.11 !r	!&&.00  1&&"QYFz! vvqttAOO(CDD ++-LE bS	! %wHe,d(('#'99Q<''MM$' - .68S&\)?4?ZZCCJXX:JJqMwdC((TYY$->xx1}

488,%)


1JJt$  jCyT39u!EEE !]]779 re   c                v    SSK Jn  U" [        [        R                  S-  -   5      [        U" [        5      -  -
  $ )Nr   )sinr5   )(sympy.functions.elementary.trigonometricr  r  r   r  )r   rV  r  s      r?   _eval_rewrite_as_sinExp1._eval_rewrite_as_sin  s(    @1qttAv:3q6))re   c                v    SSK Jn  U" [        5      [        U" [        [        R                  S-  -   5      -  -   $ )Nr   )cosr5   )r  r  r  r   r  )r   rV  r  s      r?   _eval_rewrite_as_cosExp1._eval_rewrite_as_cos  s)    @1v#a!$$q&j/)))re   N)r   rs  rt  ru  rv  rH  r#  rS  rG  r;   r  r  ry  r/  r	  r  r  r   r  r  r  r  r  r|  r   re   r?   r  r    sp    6 GKKMILI  N`**re   r  c                  `    \ 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 5       rS rS	 rS
 rSrg)r  i  a  The `\pi` constant.

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

The transcendental number `\pi = 3.141592654\ldots` represents the ratio
of a circle's circumference to its diameter, the area of the unit circle,
the half-period of trigonometric functions, and many other things
in mathematics.

Pi is a singleton, and can be accessed by ``S.Pi``, or can
be imported as ``pi``.

Examples
========

>>> from sympy import S, pi, oo, sin, exp, integrate, Symbol
>>> S.Pi
pi
>>> pi > 3
True
>>> pi.is_irrational
True
>>> x = Symbol('x')
>>> sin(x + 2*pi)
sin(x)
>>> integrate(exp(-x**2), (x, -oo, oo))
sqrt(pi)

References
==========

.. [1] https://en.wikipedia.org/wiki/Pi
TFr   c                    g)Nz\pir   r-  s     r?   r/  	Pi._latex  s    re   c                 "    [         R                  $ r:   )r   r  r   re   r?   r  
Pi.__abs__  s    ttre   c                    g)Nr  r   r   s    r?   r  
Pi.__int__  r  re   c                    [        U5      $ r:   )r'   r   s     r?   r   Pi._as_mpf_val  s    d|re   c                    [        U[        5      (       a  [        S5      [        S5      4$ [        U[        5      (       a  [        SSS5      [        SSS5      4$ g )Nr  r     G   r         r  r  s     r?   r  Pi.approximation_interval  sQ    j'**AJ
++
H--S"a((2q!*<== .re   N)r   rs  rt  ru  rv  rH  r#  rS  rG  r;   r  r  ry  r/  r	  r  r  r   r  r|  r   re   r?   r  r    s[    !F GKKMILI  >re   r  c                  Z    \ 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\rSrg)GoldenRatioi  a3  The golden ratio, `\phi`.

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

`\phi = \frac{1 + \sqrt{5}}{2}` is an algebraic number.  Two quantities
are in the golden ratio if their ratio is the same as the ratio of
their sum to the larger of the two quantities, i.e. their maximum.

GoldenRatio is a singleton, and can be accessed by ``S.GoldenRatio``.

Examples
========

>>> from sympy import S
>>> S.GoldenRatio > 1
True
>>> S.GoldenRatio.expand(func=True)
1/2 + sqrt(5)/2
>>> S.GoldenRatio.is_irrational
True

References
==========

.. [1] https://en.wikipedia.org/wiki/Golden_ratio
TFr   c                    g)Nz\phir   r-  s     r?   r/  GoldenRatio._latex  s    re   c                    gr"  r   r   s    r?   r  GoldenRatio.__int__  r  re   c                f    [         R                  " [        US-   5      U* S-
  5      n[        X!5      $ NrJ   )r   from_man_expr)   rq   r  s      r?   r   GoldenRatio._as_mpf_val  s.    y3dURZ@!!re   c                b    SSK Jn  [        R                  [        R                  U" S5      -  -   $ )Nr   )sqrtrK   )(sympy.functions.elementary.miscellaneousr.  r   rf  )r   hintsr.  s      r?   _eval_expand_funcGoldenRatio._eval_expand_func#  s     AvvtAw&&re   c                    [        U[        5      (       a  [        R                  [	        S5      4$ [        U[        5      (       a  g g r,  r  r   r   r  r   r  s     r?   r  "GoldenRatio.approximation_interval'  7    j'**EE8A;''
H-- .re   N)r   rs  rt  ru  rv  rH  r#  rS  rG  r;   r  r  ry  r/  r  r   r1  r  _eval_rewrite_as_sqrtr|  r   re   r?   r$  r$    sS    8 GKKMILI"
' .re   r$  c                  `    \ 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\rSrg)TribonacciConstanti0  a  The tribonacci constant.

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

The tribonacci numbers are like the Fibonacci numbers, but instead
of starting with two predetermined terms, the sequence starts with
three predetermined terms and each term afterwards is the sum of the
preceding three terms.

The tribonacci constant is the ratio toward which adjacent tribonacci
numbers tend. It is a root of the polynomial `x^3 - x^2 - x - 1 = 0`,
and also satisfies the equation `x + x^{-3} = 2`.

TribonacciConstant is a singleton, and can be accessed
by ``S.TribonacciConstant``.

Examples
========

>>> from sympy import S
>>> S.TribonacciConstant > 1
True
>>> S.TribonacciConstant.expand(func=True)
1/3 + (19 - 3*sqrt(33))**(1/3)/3 + (3*sqrt(33) + 19)**(1/3)/3
>>> S.TribonacciConstant.is_irrational
True
>>> S.TribonacciConstant.n(20)
1.8392867552141611326

References
==========

.. [1] https://en.wikipedia.org/wiki/Generalizations_of_Fibonacci_numbers#Tribonacci_numbers
TFr   c                    g)Nz\text{TribonacciConstant}r   r-  s     r?   r/  TribonacciConstant._latex_  s    +re   c                    gr"  r   r   s    r?   r  TribonacciConstant.__int__b  r  re   c                8    U R                  U5      R                  $ r:   )r   rw   r   s     r?   r   TribonacciConstant._as_mpf_vale  s    %+++re   c                V    U R                  SS9R                  US-   5      n[        X!S9$ )NT)functionr  r  )r1  r   rQ   r  s      r?   r   TribonacciConstant._eval_evalfh  s/    ##T#2>>taxHR((re   c                p    SSK JnJn  SU" SSU" S5      -  -
  5      -   U" SSU" S5      -  -   5      -   S-  $ )Nr   )cbrtr.  r      r  !   )r/  rD  r.  )r   r0  rD  r.  s       r?   r1  $TribonacciConstant._eval_expand_funcl  s<    GDaRj))DaRj,AAQFFre   c                    [        U[        5      (       a  [        R                  [	        S5      4$ [        U[        5      (       a  g g r,  r4  r  s     r?   r  )TribonacciConstant.approximation_intervalp  r6  re   N)r   rs  rt  ru  rv  rH  r#  rS  rG  r;   r  r  ry  r/  r  r   r   r1  r  r7  r|  r   re   r?   r9  r9  0  sZ    "H GKKMILI,,)G .re   r9  c                  H    \ 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)
EulerGammaiy  a  The Euler-Mascheroni constant.

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

`\gamma = 0.5772157\ldots` (also called Euler's constant) is a mathematical
constant recurring in analysis and number theory.  It is defined as the
limiting difference between the harmonic series and the
natural logarithm:

.. math:: \gamma = \lim\limits_{n\to\infty}
          \left(\sum\limits_{k=1}^n\frac{1}{k} - \ln n\right)

EulerGamma is a singleton, and can be accessed by ``S.EulerGamma``.

Examples
========

>>> from sympy import S
>>> S.EulerGamma.is_irrational
>>> S.EulerGamma > 0
True
>>> S.EulerGamma > 1
False

References
==========

.. [1] https://en.wikipedia.org/wiki/Euler%E2%80%93Mascheroni_constant
TFNr   c                    g)Nz\gammar   r-  s     r?   r/  EulerGamma._latex  r1  re   c                    gr  r   r   s    r?   r  EulerGamma.__int__  r  re   c                    [         R                  R                  US-   5      n[         R                  " X!* S-
  5      n[	        X15      $ r*  )r   libhypereuler_fixedr+  rq   r   rk   rA  rp   s       r?   r   EulerGamma._as_mpf_val  s;    MM%%dRi0q%"*-!!re   c                    [        U[        5      (       a   [        R                  [        R                  4$ [        U[
        5      (       a  [        R                  [        SSS5      4$ g )Nr  rK   r   )r  r   r   r'  r  r   rf  r  s     r?   r  !EulerGamma.approximation_interval  sK    j'**FFAEE?"
H--FFHQ1-.. .re   )r   rs  rt  ru  rv  rH  r#  rS  rG  r;   ry  r/  r  r   r  r|  r   re   r?   rK  rK  y  s;    > GKKMII"/re   rK  c                  R    \ 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S
 jrS rSrg)Catalani  a  Catalan's constant.

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

$G = 0.91596559\ldots$ is given by the infinite series

.. math:: G = \sum_{k=0}^{\infty} \frac{(-1)^k}{(2k+1)^2}

Catalan is a singleton, and can be accessed by ``S.Catalan``.

Examples
========

>>> from sympy import S
>>> S.Catalan.is_irrational
>>> S.Catalan > 0
True
>>> S.Catalan > 1
False

References
==========

.. [1] https://en.wikipedia.org/wiki/Catalan%27s_constant
TFNr   c                    gr  r   r   s    r?   r  Catalan.__int__  r  re   c                ~    [         R                  " US-   5      n[         R                  " X!* S-
  5      n[        X15      $ r*  )r   catalan_fixedr+  rq   rS  s       r?   r   Catalan._as_mpf_val  s7    tby)q%"*-!!re   c                    [        U[        5      (       a   [        R                  [        R                  4$ [        U[
        5      (       a  [        SSS5      [        R                  4$ g )N	   rJ   r   )r  r   r   r'  r  r   r  s     r?   r  Catalan.approximation_interval  sK    j'**FFAEE?"
H--QA&.. .re   c                    Uc  Ub  U $ SSK Jn  SSKJn  U" SSSS9nU" [        R
                  U-  SU-  S-   S-  -  US[        R                  45      $ )	Nr   r  r   )Sumr@  T)integernonnegativer5   )r  r  sympy.concrete.summationsrb  r   rT  r   )r   k_symr  r0  r  rb  r@  s          r?   _eval_rewrite_as_SumCatalan._eval_rewrite_as_Sum  sX    7#6K!1#t61==!#qs1uqj01a2DEEre   c                    g)NGr   r-  s     r?   r/  Catalan._latex  s    re   rC  )r   rs  rt  ru  rv  rH  r#  rS  rG  r;   ry  r  r   r  rg  r/  r|  r   re   r?   rX  rX    sA    6 GKKMII"/Fre   rX  c                  v    \ rS rSrSrSrSrSrSrSr	Sr
\rSrS r\S 5       rS rS	 rS
 rS r\S 5       rSrg)r
  i  a  The imaginary unit, `i = \sqrt{-1}`.

I is a singleton, and can be accessed by ``S.I``, or can be
imported as ``I``.

Examples
========

>>> from sympy import I, sqrt
>>> sqrt(-1)
I
>>> I*I
-1
>>> 1/I
-I

References
==========

.. [1] https://en.wikipedia.org/wiki/Imaginary_unit
TFr   c                     UR                   S   $ )Nimaginary_unit_latex)	_settingsr-  s     r?   r/  ImaginaryUnit._latex  s      !788re   c                 "    [         R                  $ r:   r^  r   re   r?   r  ImaginaryUnit.__abs__  r  re   c                    U $ r:   r   r   s     r?   r   ImaginaryUnit._eval_evalf  r   re   c                $    [         R                  * $ r:   )r   r
  r   s    r?   r   ImaginaryUnit._eval_conjugate  s    re   c                   [        U[        5      (       a^  US-  nUS:X  a  [        R                  $ US:X  a  [        R                  $ US:X  a  [        R
                  $ US:X  a  [        R                  * $ [        U[        5      (       aL  [        US5      u  p#[        [        R                  USS9nUS-  (       a  [        [        R
                  USS9$ U$ g)	z
b is I = sqrt(-1)
e is symbolic object but not equal to 0, 1

I**r -> (-1)**(r/2) -> exp(r/2*Pi*I) -> sin(Pi*r/2) + cos(Pi*r/2)*I, r is decimal
I**0 mod 4 -> 1
I**1 mod 4 -> I
I**2 mod 4 -> -1
I**3 mod 4 -> -I
r  r   r   r5   r  Fr  N)
rL   r   r   r  r
  rT  r   r   r  r  )r   rn   r>   r   rp   s        r?   r  ImaginaryUnit._eval_power"  s     dG$$!8Dqyuu&}}$''dH%%$?DAQ__a%8B1u1=="u==I &re   c                B    [         R                  [         R                  4$ r:   )r   rT  rf  r   s    r?   as_base_expImaginaryUnit.as_base_exp?  s    }}aff$$re   c                V    [        S5      R                  [        S5      R                  4$ )Nr   r   )rQ   rw   r   s    r?   _mpc_ImaginaryUnit._mpc_B  s    aa//re   N)r   rs  rt  ru  rv  rw  is_imaginaryr   r;   r  r  r   rz  ry  r/  r	  r  r   r   r  rz  rN  r}  r|  r   re   r?   r
  r
    ss    , NLIILDI9   :% 0 0re   r
  c                    [        U [        [        45      (       a  g[        U 5      [        L a  U R                  5       $ [        U [        5      (       a  g[        U [        5      (       a  U R                  S   S:  $ g)zreturn True only for a literal Number whose internal
representation as a fraction has a denominator of 1,
else False, i.e. integer, with no fractional part.
Tr5   r   F)	rL   r   rW   r   r   r  r   rQ   rw   r2  s    r?   r  r  J  sc    
 !j#&''Aw%||~!W!UwwqzQre   c                   [        U 5      n [        U5      nU R                  (       d  UR                  (       d  X:H  $ U R                  (       a*  UR                  (       a  U R                  UR                  :H  $ U R                  (       a  XpU R                  (       d  gUR                  u  p#pEU R                  U R
                  pvU(       a  U* nUS:X  a  US:H  =(       a    X6:H  $ US:  a4  US:w  a  gUR                  5       UR                  5       U-   :w  a  gX4-  U:H  $ Xc:w  a  gU* nUR                  5       S-
  U:w  a  gSU-  U:H  $ )a*  Compare expressions treating plain floats as rationals.

Examples
========

>>> from sympy import S, symbols, Rational, Float
>>> from sympy.core.numbers import equal_valued
>>> equal_valued(1, 2)
False
>>> equal_valued(1, 1)
True

In SymPy expressions with Floats compare unequal to corresponding
expressions with rationals:

>>> x = symbols('x')
>>> x**2 == x**2.0
False

However an individual Float compares equal to a Rational:

>>> Rational(1, 2) == Float(0.5)
False

In a future version of SymPy this might change so that Rational and Float
compare unequal. This function provides the behavior currently expected of
``==`` so that it could still be used if the behavior of ``==`` were to
change in future.

>>> equal_valued(1, 1.0) # Float vs Rational
True
>>> equal_valued(S(1).n(3), S(1).n(5)) # Floats of different precision
True

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

In future SymPy versions Float and Rational might compare unequal and floats
with different precisions might compare unequal. In that context a function
is needed that can check if a number is equal to 1 or 0 etc. The idea is
that instead of testing ``if x == 1:`` if we want to accept floats like
``1.0`` as well then the test can be written as ``if equal_valued(x, 1):``
or ``if equal_valued(x, 2):``. Since this function is intended to be used
in situations where one or both operands are expected to be concrete
numbers like 1 or 0 the function does not recurse through the args of any
compound expression to compare any nested floats.

References
==========

.. [1] https://github.com/sympy/sympy/pull/20033
Fr   r   )r   r$  rw   rR  rz   r|   
bit_length)	r2  r  rl   rm   r  r`   rz   r|   neg_exps	            r?   r  r  [  s   j 	AA ::ajjv	


ww!''!!	
1== Ds33qd
axAv"#("	q6<<>S^^-33zQ 8$<<>A(W""re   c                v   ^^^^^^^ [         [        4mUU4S jmUUUU4S jmUU4S jmUUU4S jmT" X5      $ )ay  Return True if expr1 and expr2 are numerically close.

The expressions must have the same structure, but any Rational, Integer, or
Float numbers they contain are compared approximately using rtol and atol.
Any other parts of expressions are compared exactly. However, allowance is
made to allow for the additive and multiplicative identities.

Relative tolerance is measured with respect to expr2 so when used in
testing expr2 should be the expected correct answer.

Examples
========

>>> from sympy import exp
>>> from sympy.abc import x, y
>>> from sympy.core.numbers import all_close
>>> expr1 = 0.1*exp(x - y)
>>> expr2 = exp(x - y)/10
>>> expr1
0.1*exp(x - y)
>>> expr2
exp(x - y)/10
>>> expr1 == expr2
False
>>> all_close(expr1, expr2)
True

Identities are automatically supplied:

>>> all_close(x, x + 1e-10)
True
>>> all_close(x, 1.0*x)
True
>>> all_close(x, 1.0*x + 1e-10)
True

c                  > [        U 5      [        U5      :X  aR  [        U [        [        45      (       a7  [	        U 5      [	        U5      :w  a  g[        U4S j[        X5       5       5      $ T" [        U 5      [        U5      5      $ )NFc              3  8   >#    U  H  u  pT" X5      v   M     g 7fr:   r   )r=   e1e2
_all_closes      r?   r@   0all_close.<locals>._all_close.<locals>.<genexpr>  s     Hfbz"))   )r   rL   r  r   r   rO   rU   r   )obj1obj2r  _all_close_exprs     r?   r  all_close.<locals>._all_close  s`    :d#
4$(G(G4yCI%HDHHH"8D>8D>BBre   c                  > [        U T5      n[        UT5      nX#:w  a  gU(       a  T" X5      $ U R                  (       d3  U R                  (       d"  UR                  (       d  UR                  (       a  T" X5      $ U R                  UR                  :w  d,  [	        U R
                  5      [	        UR
                  5      :w  a  g[        U R
                  UR
                  5      n[        U4S jU 5       5      $ )NFc              3  8   >#    U  H  u  pT" X5      v   M     g 7fr:   r   )r=   a1a2r  s      r?   r@   5all_close.<locals>._all_close_expr.<locals>.<genexpr>  s     >vr?2**r  )rL   r  is_Mulr  r   r   rU   rO   )	expr1expr2num1num2r   	NUM_TYPES_all_close_acr  
_close_nums	        r?   r  "all_close.<locals>._all_close_expr  s    %+%+<e++<<5<<5<<5<< ..::#s5::#ejj/'I5::uzz*>>>>re   c                T   > [        [        X-
  5      TT[        U5      -  -   :*  5      $ r:   )r   rX   )r  r  atolrtols     r?   r  all_close.<locals>._close_num  s'    C$tCI~(==>>re   c                  > U R                   (       d  UR                   (       Ga  U R                  SS9u  p#UR                  SS9u  pET" X$5      (       d  g[        U5      n[        U5      nXg-  nXh-  nXx-  nU(       d  g[        S Xg4 5       5      (       d  g[	        U5       V	s/ s H  oR                  5       PM     nn	[	        U5       V	s/ s H  oR                  5       PM     nn	[        [        [        U5      5      5      n
U H1  nU
 H(  n	Xy   nT" X5      (       d  M  U
R                  U	5          M/       g   U
(       + $ U R                  (       d  UR                  (       d   eU R                  5       nUR                  5       nT" US   US   5      (       d  g[        U5      [        U5      :w  a  g[        U5       H8  nX;   d  M
  T" UR                  U5      UR                  U5      5      (       a  M8    g   U(       d  gU H4  nU H+  nT" UU5      (       d  M  T" UU   UU   5      (       d      g  M2       g   gs  sn	f s  sn	f )NFrN  Tc              3  \   #    U  H"  o  H  o"R                  [        5      v   M     M$     g 7fr:   )hasrQ   )r=   rI   r>   s      r?   r@   3all_close.<locals>._all_close_ac.<locals>.<genexpr>  s      AXq!uuU||q|Xs   *,r   )r  rW  r  anyr   rz  r  rR   r   remover  as_coefficients_dictpop)r  r  c1r  c2r  s1s2commonr>   	unmatchedbe1be2cd1cd2r@  k1k2r  r  r  s                     r?   r   all_close.<locals>._all_close_ac  s	    <<5<<<'''7FB'''7FBb%%RBRBWFLBLBAbXAAA ,32;7;a--/;B7+22;7;a--/;B7U3r7^,I"A%C!#++!((+	 # !  !>!||u||++((*((* #a&#a&))s8s3xcAx!#''!*cggaj99   B"2r** &c"gs2w77$    [ 87s   %H?I)r   rQ   )	r  r  r  r  r  r  r  r  r  s	     ``@@@@@r?   	all_closer    s9    L 5!IC? ??BH e##re   c                    gr  r   r   s     r?   r  r  D  r  re   c                X    [         R                  U R                  U R                  S5      $ r"  )r   r   r[  r\  )r   s    r?   sympify_fractionsr  I  s    ==ammQ77re   c                *    [        [        U 5      5      $ r:   r   rW   r  s    r?   sympify_mpzr  Q      s1vre   c                f    [        [        U R                  5      [        U R                  5      5      $ r:   r   rW   r[  r\  r  s    r?   sympify_mpqr  T  !    AKK(#amm*<==re   c                *    [        [        U 5      5      $ r:   r  r  s    r?   sympify_fmpzr  ]  r  re   c                f    [        [        U R                  5      [        U R                  5      5      $ r:   r  r  s    r?   sympify_fmpqr  `  r  re   c                V    [         R                  " X R                  R                  5      $ r:   )r   _from_mpmathr  rk   r  s    r?   sympify_mpmathr  g  s    Q		//re   c                    [        [        [        U R                  U R                  45      5      u  pU[
        R                  U-  -   $ r:   )r  mapr	   realimagr   r
  )r\   r  r  s      r?   sympify_complexr  m  s6    c'AFFAFF#345JD!//$&&&re   )r  )r  )r  c                    [         R                  R                  [        5        [         R                  R                  [        5        [         R
                  R                  [
        5        [         R                  R                  [        5        g r:   )rV  r   registerRealrQ   r   rW  r   r   re   r?   _register_classesr  z  sN    NNF#LL% h'g&re   r:   rr  )gh㈵>g:0yE>)
__future__r   typingr   rV  r   rY  r  
containersr   r	   r   r   r
   r   r   	singletonr   r   basicr   r  r   r   r&  r   cacher   r   
decoratorsr   intfuncr   r   r   r   r   logicr   rz  r   sortingr   sympy.external.gmpyr   r   r    sympy.multipledispatchr!   ry   mpmath.libmplibmpr   r"   r#   ri   rg   r%   r&   r'   r(   r)   mpmath.ctx_mp_pythonr*   mpmath.libmp.libmpfr+   r  r,   r  r-   r  r.   r/   rh   r0   r1   sympy.utilities.miscr2   sympy.utilities.exceptionsr3   
parametersr4   r  _LOG2rH   rq   rt   ru   r}   r   rM   rJ  rK  rL  r   r   r   rQ   r   r   
RealNumberr   r   rW   r~  r  r  r'  r  rT  rf  r   r  r   r   r   r  r  zoor  r  Er  r  r$  r9  rK  rX  r
  r  r  r  r  r  rZ  r  r  r   mpzmpqr  r  fmpzfmpqr  r  complexpowerr  mulr  identityr  r  r  _illegalr   re   r?   <module>r     s   "      , , #  "  ' " I I    7 7 +   7 $ : : *   ' @ )jZ< e	$ }}T]]<013tv&Z v&r	_	?F _	?F ?D C  *7??; 
lv l^G h G T    Ed EP
'x 
''g 'A?i AH0/Y 0f=/Y =@y @yv yv ZZd1v d1Nq&I qf ee	#t J"jI J"Z 6": 6"rV*<9 V*p FF?> ?>B TT<.,) <.~F. F.R8/ 8/v<li <~Q0J) Q0h OO"^#BE$P 
% 8 (9 ## $ > +6T$((1+&'-8T$((1a.)* 	> -9T%**Q-()/;T%**Q*+,0 -  ' ,    u v'  EE1::q1113D3DEre   