
    \h1                   @   S SK Jr  S SKJrJr  S SKJrJr  S SKJ	r	  S SK
r
SSKJrJr  SSKJrJr  SS	KJr  SS
KJrJrJr  SSKJrJrJr  SSKJr  SSKJrJr  SSKJ r   SSK!J"r"  SSK#J$r$  S SK%J&r&  S SK'J(r(J)r)J*r*  S SK+J,r,J-r-  S SK.J/r/J0r0  S SK1J2r2  \(       a  S SKJ3r3  S SK4J5r5  SSK6J7r7  S SK8J9r9  S r:\ " S S\\5      5       r; " S S\\;5      r<S r= " S  S!\;5      r>S" r? " S# S$5      r@SS%KAJBrB  SS&KCJDrD  SS'KEJFrF  SS(KGJHrHJIrI  SS)KJJKrK  SS*KLJMrM  SS+K6JNrNJOrOJPrPJQrQJRrR  g),    )annotations)TYPE_CHECKINGoverload)IterableMapping)reduceN   )sympify_sympify)BasicAtom)S)
EvalfMixinpure_complexDEFAULT_MAXPREC)call_highest_prioritysympify_method_argssympify_return)cacheit)fuzzy_or	fuzzy_not)mod_inverse)default_sort_key)
NumberKindsympy_deprecation_warning)as_int	func_name
filldedent)has_varietysift)mpf_logprec_to_dps)giant_steps)Any)Self)Number)defaultdictc                    / n/ n[         R                  " U 5       H?  nUR                  U5      nU(       d  UR                  U5        M.  UR                  U5        MA     [        U6 [        U6 4$ N)Add	make_argscoeffappend)eqccononicis         G/var/www/auris/envauris/lib/python3.13/site-packages/sympy/core/expr.py_coremr6   !   sZ    	B
C]]2WWQZJJqMIIbM  8S#Y    c                  8	  ^  \ rS rSr% SrSrS\S'   \(       ar  SS jr\	SSS jj5       r
\	SSS	 jj5       r
\	SS
 j5       r
\	SSS jj5       r
\	SSS jj5       r
\	SS j5       r
 S     SS jjr
SS jr   S           SS jjr\rSr\S 5       r\SS j5       rS rSr\S 5       r\S 5       rSS jrSS jrSS jr\" S/\5      \" S5      SS j5       5       r\" S/\5      \" S5      SS j5       5       r\" S/\5      \" S 5      SS! j5       5       r\" S/\5      \" S"5      SS# j5       5       r \" S/\5      \" S$5      SS% j5       5       r!\" S/\5      \" S&5      SS' j5       5       r"\" S/\5      \" S(5      S) 5       5       r#SSS* jjr$\" S/\5      \" S+5      SS, j5       5       r%\" S/\5      \" S-5      SS. j5       5       r&\" S/\5      \" S/5      SS0 j5       5       r'\" S/\5      \" S15      SS2 j5       5       r(\" S/\5      \" S35      SS4 j5       5       r)\" S/\5      \" S55      SS6 j5       5       r*\" S/\5      \" S75      SS8 j5       5       r+\" S/\5      \" S95      SS: j5       5       r,\" S/\5      \" S;5      SS< j5       5       r-SS= jr.SS> jr/SS? jr0\" S/\5      S@ 5       r1\" S/\5      SA 5       r2\" S/\5      SB 5       r3\" S/\5      SC 5       r4SD r5SU 4SE jjr6\7SF 5       r8\SG 5       r9SH r:SSI jr;SJ r<SSK jr=SL r>SM r?SN r@SO rASSP jrBSQ rCSR rDSS rEST rFSU rGSV rHSW rI\JSX 5       rKSSY jrLSZ rMSS[ jrNS\ rOSS] jrPSS^ jrQS_ rRSS` jrSSSa jrTSSSb jjrUSc rVSSd jrWSSe jrXSSSf jjrYSg rZSh r[SSi jr\SSj jr]SSk jr^SSl jr_SSm jr`SSn jraSo rbSSp jrcSq rd\Sr 5       reSSs jrfSSt jrgSu rhSSv jriSw rjSSx jrkSy rlSSz jrmS{ rnSS| jroSS~ jrpSS jrqS rrSS jrsSS jrtSS jruS rvSS jrw\SS}S.S j5       rxS rySS jrzSS jr{SSS jjr|SSS jjr}  SS jr~SS jrS rS r\7SS j5       r\  SS j5       rS rSS jrSS jrSS jrS rSS jrS rS rS rS rS rS rS rS rS rSS jr\rS rSrU =r$ )Expr.   aZ  
Base class for algebraic expressions.

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

Everything that requires arithmetic operations to be defined
should subclass this class, instead of Basic (which should be
used only for argument storage and expression manipulation, i.e.
pattern matching, substitutions, etc).

If you want to override the comparisons of expressions:
Should use _eval_is_ge for inequality, or _eval_is_eq, with multiple dispatch.
_eval_is_ge return true if x >= y, false if x < y, and None if the two types
are not comparable or the comparison is indeterminate

See Also
========

sympy.core.basic.Basic
 ztuple[str, ...]	__slots__c                    g r*   r;   )clsargss     r5   __new__Expr.__new__J       r7   Nc                    g r*   r;   selfarg1arg2s      r5   subs	Expr.subsM   s    adr7   c                    g r*   r;   rE   rF   rG   kwargss       r5   rH   rI   O   s    x{r7   c                    g r*   r;   rD   s      r5   rH   rI   Q   s    LOr7   c                    g r*   r;   rK   s       r5   rH   rI   S   s    rur7   c                    g r*   r;   rK   s       r5   rH   rI   U   s    z}r7   c                    g r*   r;   rK   s       r5   rH   rI   W   s    ^ar7   c                    g r*   r;   rK   s       r5   rH   rI   Z   s    r7   c                    g r*   r;   )rE   rL   s     r5   simplifyExpr.simplify^   rB   r7   c                    g r*   r;   )rE   nrH   maxnchopstrictquadverboses           r5   evalf
Expr.evalfa   s     r7   Tc                    g)av  Return True if one can differentiate with respect to this
object, else False.

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

Subclasses such as Symbol, Function and Derivative return True
to enable derivatives wrt them. The implementation in Derivative
separates the Symbol and non-Symbol (_diff_wrt=True) variables and
temporarily converts the non-Symbols into Symbols when performing
the differentiation. By default, any object deriving from Expr
will behave like a scalar with self.diff(self) == 1. If this is
not desired then the object must also set `is_scalar = False` or
else define an _eval_derivative routine.

Note, see the docstring of Derivative for how this should work
mathematically. In particular, note that expr.subs(yourclass, Symbol)
should be well-defined on a structural level, or this will lead to
inconsistent results.

Examples
========

>>> from sympy import Expr
>>> e = Expr()
>>> e._diff_wrt
False
>>> class MyScalar(Expr):
...     _diff_wrt = True
...
>>> MyScalar().diff(MyScalar())
1
>>> class MySymbol(Expr):
...     _diff_wrt = True
...     is_scalar = False
...
>>> MySymbol().diff(MySymbol())
Derivative(MySymbol(), MySymbol())
Fr;   rE   s    r5   	_diff_wrtExpr._diff_wrtj   s    R r7   c           
        U R                  5       u  p#UR                  (       aH  UR                  5       u  pEU[        R                  L a   [        S5      " U5      [        R                  pTUnO[        R                  nUR                  (       a  UR                  5       4nOUR                  (       a  [        U5      4nOqUR                  (       a  UR                  US9nO-UR                  (       a  UR                  US9nOUR                  n[!        U Vs/ s H  n[#        XqS9PM     sn5      n[%        U5      [!        U5      4nUR                  US9nUR'                  5       XeU4$ s  snf )Nexporder)as_coeff_Mulis_Powas_base_expr   Exp1FunctionOneis_Dummysort_keyis_Atomstris_Addas_ordered_termsis_Mulas_ordered_factorsr?   tupler   len	class_key)rE   re   r-   exprbaserc   r?   args           r5   rm   Expr.sort_key   s    '');;((*IDqvv~ %UOC0!%%cD%%C==MMO%D\\I<D{{,,5,9..U.;yy@DF"34FHD D	5;'lll'~~E11 Gs   E&c                    U R                   $ )ab  Return a tuple of information about self that can be used to
compute the hash. If a class defines additional attributes,
like ``name`` in Symbol, then this method should be updated
accordingly to return such relevant attributes.
Defining more than _hashable_content is necessary if __eq__ has
been defined by a class. See note about this in Basic.__eq__.)_argsr_   s    r5   _hashable_contentExpr._hashable_content   s     zzr7   g      $@c                    [         $ r*   r+   r_   s    r5   _add_handlerExpr._add_handler       
r7   c                    [         $ r*   Mulr_   s    r5   _mul_handlerExpr._mul_handler   r   r7   c                    U $ r*   r;   r_   s    r5   __pos__Expr.__pos__       r7   c                h    U R                   n[        R                  " [        R                  U 4U5      $ r*   )is_commutativer   
_from_argsr   NegativeOnerE   r0   s     r5   __neg__Expr.__neg__   s)     ~~q}}d3Q77r7   c                    SSK Jn  U" U 5      $ )Nr   )Abs)$sympy.functions.elementary.complexesr   )rE   r   s     r5   __abs__Expr.__abs__   s    <4yr7   )otherr9   __radd__c                    [        X5      $ r*   r   rE   r   s     r5   __add__Expr.__add__        4r7   r   c                    [        X5      $ r*   r   r   s     r5   r   Expr.__radd__        5r7   __rsub__c                    [        X* 5      $ r*   r   r   s     r5   __sub__Expr.__sub__   s     4  r7   r   c                    [        X* 5      $ r*   r   r   s     r5   r   Expr.__rsub__   s     5%  r7   __rmul__c                    [        X5      $ r*   r   r   s     r5   __mul__Expr.__mul__   r   r7   r   c                    [        X5      $ r*   r   r   s     r5   r   Expr.__rmul__   r   r7   __rpow__c                    [        X5      $ r*   Powr   s     r5   _pow	Expr._pow  r   r7   c           	     ^   Uc  U R                  U5      $  [        U 5      [        U5      [        U5      p!nUS:  a  [        [        X1U5      5      $ [        [	        [        X1* U5      U5      5      $ ! [
         a1    U R                  U5      n XB-  s $ ! [         a    [        s s $ f = ff = fNr   )r   r   r   powr   
ValueError	TypeErrorNotImplemented)rE   r   mod_selfpowers        r5   __pow__Expr.__pow__
  s    ;99U##	& &tfUmVC[#EzE# 677Cvs,CS IJJ 	&IIe$E&y  &%%&		&s5   :A1 A1 1B,BB,B(#B,'B((B,r   c                    [        X5      $ r*   r   r   s     r5   r   Expr.__rpow__  r   r7   __rtruediv__c                v    [        U[        R                  5      nU [        R                  L a  U$ [	        X5      $ r*   r   r   r   rk   r   rE   r   denoms      r5   __truediv__Expr.__truediv__  s/     E1==)155=Lt##r7   r   c                v    [        U [        R                  5      nU[        R                  L a  U$ [	        X5      $ r*   r   r   s      r5   r   Expr.__rtruediv__(  s/     D!--(AEE>Lu$$r7   __rmod__c                    [        X5      $ r*   Modr   s     r5   __mod__Expr.__mod__1  r   r7   r   c                    [        X5      $ r*   r   r   s     r5   r   Expr.__rmod__6  r   r7   __rfloordiv__c                "    SSK Jn  U" X-  5      $ Nr   )floor#sympy.functions.elementary.integersr   rE   r   r   s      r5   __floordiv__Expr.__floordiv__;  s     	>T\""r7   r   c                "    SSK Jn  U" X-  5      $ r   r   r   s      r5   r   Expr.__rfloordiv__A  s     	>U\""r7   __rdivmod__c                8    SSK Jn  U" X-  5      [        X5      4$ r   r   r   r   r   s      r5   
__divmod__Expr.__divmod__H  s     	>T\"C$444r7   r   c                8    SSK Jn  U" X-  5      [        X5      4$ r   r   r   s      r5   r   Expr.__rdivmod__N  s     	>U\"C$444r7   c                0   U R                   (       d  [        S5      eU R                  S5      nUR                  (       d  [        S5      eU[        R
                  [        R                  [        R                  4;   a  [        SU-  5      e[        U5      nU(       d  U$ [        U5      (       ag  X:  [        R                  L a  U$ X:  [        R                  L a  US-
  $ U R                  U5      nUc  [        S5      eU(       a  U$ X"S:  a  S-
  $ S-
  $ U$ )	NzCannot convert symbols to int   zCannot convert complex to intzCannot convert %s to intr	   z#cannot compute int value accuratelyr   )	is_numberr   round	is_Numberr   NaNInfinityNegativeInfinityint
int_valuedtrueequals)rE   rr3   oks       r5   __int__Expr.__int__T  s    ~~;<<JJqM{{;<<

A$6$6776:;;FHa==QVV#QVV#1uQBz EFFU++++r7   c                    U R                  5       nUR                  (       a  [        U5      $ UR                  (       a#  UR	                  5       S   (       a  [        S5      e[        S5      e)Nr	   zCannot convert complex to floatz"Cannot convert expression to float)r\   r   floatr   as_real_imagr   )rE   results     r5   	__float__Expr.__float__n  sS     =  3 3 5a 8=>><==r7   c                    U R                  5       nUR                  5       u  p#[        [        U5      [        U5      5      $ r*   )r\   r   complexr   )rE   r   reims       r5   __complex__Expr.__complex__y  s2    $$&uRy%),,r7   c                    SSK Jn  U" X5      $ )Nr	   )GreaterThan)
relationalr  )rE   r   r  s      r5   __ge__Expr.__ge__~  s    +4''r7   c                    SSK Jn  U" X5      $ )Nr	   )LessThan)r  r  )rE   r   r  s      r5   __le__Expr.__le__  s    ($$r7   c                    SSK Jn  U" X5      $ )Nr	   )StrictGreaterThan)r  r  )rE   r   r  s      r5   __gt__Expr.__gt__  s    1 --r7   c                    SSK Jn  U" X5      $ )Nr	   )StrictLessThan)r  r  )rE   r   r  s      r5   __lt__Expr.__lt__  s    .d**r7   c                P    U R                   (       d  [        S5      e[        U 5      $ )Nz'Cannot truncate symbols and expressions)r   r   Integerr_   s    r5   	__trunc__Expr.__trunc__  s    ~~EFF4= r7   c                Z  > U R                   (       a  [        R                  " SU5      nU(       am  [        UR	                  S5      5      nU R                  U5      nUR                  (       a  [        [        U5      U5      $ UR                  (       a  [        XA5      $ [        TU ])  U5      $ )Nz\+?\d*\.(\d+)fr	   )r   r   matchr   groupr   
is_Integerformatis_Floatsuper
__format__)rE   format_specmtprecrounded	__class__s        r5   r  Expr.__format__  s|    >>+[9B288A;'**T*%%!#g,<<##!'77w!+..r7   c                <   [        U S5      (       a!  [        R                  " U R                  U5      $ [        U S5      (       aO  U R                  u  p#[        R                  " X!5      n[        R                  " X15      [
        R                  -  nX#-   $ [        S5      e)N_mpf__mpc_z#expected mpmath number (mpf or mpc))hasattrFloat_newr&  r'  r   ImaginaryUnitr   )xr!  r   r   s       r5   _from_mpmathExpr._from_mpmath  st    1g::aggt,,Q  WWFBB%BB%aoo5B7NABBr7   c                :    [        S U R                   5       5      $ )a  Returns True if ``self`` has no free symbols and no
undefined functions (AppliedUndef, to be precise). It will be
faster than ``if not self.free_symbols``, however, since
``is_number`` will fail as soon as it hits a free symbol
or undefined function.

Examples
========

>>> from sympy import Function, Integral, cos, sin, pi
>>> from sympy.abc import x
>>> f = Function('f')

>>> x.is_number
False
>>> f(1).is_number
False
>>> (2*x).is_number
False
>>> (2 + Integral(2, x)).is_number
False
>>> (2 + Integral(2, (x, 1, 2))).is_number
True

Not all numbers are Numbers in the SymPy sense:

>>> pi.is_number, pi.is_Number
(True, False)

If something is a number it should evaluate to a number with
real and imaginary parts that are Numbers; the result may not
be comparable, however, since the real and/or imaginary part
of the result may not have precision.

>>> cos(1).is_number and cos(1).is_comparable
True

>>> z = cos(1)**2 + sin(1)**2 - 1
>>> z.is_number
True
>>> z.is_comparable
False

See Also
========

sympy.core.basic.Basic.is_comparable
c              3  8   #    U  H  oR                   v   M     g 7fr*   )r   ).0objs     r5   	<genexpr>!Expr.is_number.<locals>.<genexpr>  s     6IS==I   )allr?   r_   s    r5   r   Expr.is_number  s    d 6DII666r7   c                l   U R                   nUSL a  gU R                  (       d  gU R                  5       u  p#UR                  (       d#  UR	                  S5      nUR                  (       d  gUR                  (       d#  UR	                  S5      nUR                  (       d  gU(       a  gUR
                  S:g  $ )NFr   r	   )is_extended_realr   r   r   r\   _prec)rE   r9  rV   r3   s       r5   _eval_is_comparableExpr._eval_is_comparable  s      00u$~~   "{{
A;;{{
A;;
 77a<r7   c                x   U R                   nSnU(       a]  SSKJn  X$X54u  pp[        [	        [        UU Vs/ s H  nU" XXSS9PM     sn5      5      5      n [        U R                  SUS95      nO0 n[        U R                  S5      5      n[        US	5      (       d  gUR                  S:X  aA  [        S[        5       H-  n[        U R                  X~S95      nUR                  S:w  d  M-    O   UR                  S:w  a  Uc  [        US
5      nU R                  XS9$ gs  snf ! [        [        4 a     gf = f)a  Return self evaluated, if possible, replacing free symbols with
random complex values, if necessary.

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

The random complex value for each free symbol is generated
by the random_complex_number routine giving real and imaginary
parts in the range given by the re_min, re_max, im_min, and im_max
values. The returned value is evaluated to a precision of n
(if given) else the maximum of 15 and the precision needed
to get more than 1 digit of precision. If the expression
could not be evaluated to a number, or could not be evaluated
to more than 1 digit of precision, then None is returned.

Examples
========

>>> from sympy import sqrt
>>> from sympy.abc import x, y
>>> x._random()                         # doctest: +SKIP
0.0392918155679172 + 0.916050214307199*I
>>> x._random(2)                        # doctest: +SKIP
-0.77 - 0.87*I
>>> (x + y/2)._random(2)                # doctest: +SKIP
-0.57 + 0.16*I
>>> sqrt(2)._random(2)
1.4

See Also
========

sympy.core.random.random_complex_number
r	   r   )random_complex_numberTrationalr   rH   Nr:     )free_symbolssympy.core.randomr>  dictlistzipabsr\   r   r   r(  r:  r$   r   max)rE   rV   re_minim_minre_maxim_maxfreer!  r>  ar0   bdzirepsnmags                   r5   _randomExpr._random  sB   H   ?7JA!S%)(+%)r )>aASW(X%)(+ , - .D4::ad:34 Dtzz!}%DtW%%::?
 $A74::d:67::? 8
 ::?ybM::a:++ G(+ 	*  s   D!D& &D98D9c                   UR                  SS5      nU R                  (       a  gU R                  nU(       d  g[        U5      nU(       a
  X-  (       d  gU=(       d    UnU nU(       a  UR	                  5       nUR
                  (       a  gU Vs1 s H  ofR                  [        L d  M  UiM     nnSnXt:X  Ga   UR                  [        [        US/[        U5      -  5      5      SS9n	U	[        R                  L a  UR                  SSSSS5      n	U	Gb(  U	[        R                  LGa   UR                  [        [        US/[        U5      -  5      5      SS9n
U
[        R                  L a  UR                  SSSSS5      n
U
b(  U
[        R                  La  U
R!                  U	5      SL a  gUR                  SSSSS5      n
U
b(  U
[        R                  La  U
R!                  U	5      SL a  gUR                  5       n
U
b=  U
[        R                  La*  U
R!                  U	5      SL a  gU	R                  (       a  U	OU
nU H]  nUR#                  U5      nU(       a  UR	                  5       nUS:w  d  M3  [%        USS	9(       d  UR                  S
S5      (       a  Us  $   g   SSKJn  [+        [-        S U" U 5       5       5      5      $ s  snf ! [         a    Sn	 GNf = f! [         a    Sn
 GNlf = f)a	  Return True if self is constant, False if not, or None if
the constancy could not be determined conclusively.

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

If an expression has no free symbols then it is a constant. If
there are free symbols it is possible that the expression is a
constant, perhaps (but not necessarily) zero. To test such
expressions, a few strategies are tried:

1) numerical evaluation at two random points. If two such evaluations
give two different values and the values have a precision greater than
1 then self is not constant. If the evaluations agree or could not be
obtained with any precision, no decision is made. The numerical testing
is done only if ``wrt`` is different than the free symbols.

2) differentiation with respect to variables in 'wrt' (or all free
symbols if omitted) to see if the expression is constant or not. This
will not always lead to an expression that is zero even though an
expression is constant (see added test in test_expr.py). If
all derivatives are zero then self is constant with respect to the
given symbols.

3) finding out zeros of denominator expression with free_symbols.
It will not be constant if there are zeros. It gives more negative
answers for expression that are not constant.

If neither evaluation nor differentiation can prove the expression is
constant, None is returned unless two numerical values happened to be
the same and the flag ``failing_number`` is True -- in that case the
numerical value will be returned.

If flag simplify=False is passed, self will not be simplified;
the default is True since self should be simplified before testing.

Examples
========

>>> from sympy import cos, sin, Sum, S, pi
>>> from sympy.abc import a, n, x, y
>>> x.is_constant()
False
>>> S(2).is_constant()
True
>>> Sum(x, (x, 1, 10)).is_constant()
True
>>> Sum(x, (x, 1, n)).is_constant()
False
>>> Sum(x, (x, 1, n)).is_constant(y)
True
>>> Sum(x, (x, 1, n)).is_constant(n)
False
>>> Sum(x, (x, 1, n)).is_constant(x)
True
>>> eq = a*cos(x)**2 + a*sin(x)**2 - a
>>> eq.is_constant()
True
>>> eq.subs({x: pi, a: 2}) == eq.subs({x: pi, a: 3}) == 0
True

>>> (0**x).is_constant()
False
>>> x.is_constant()
False
>>> (x**x).is_constant()
False
>>> one = cos(x)**2 + sin(x)**2
>>> one.is_constant()
True
>>> ((one - 1)**(x + 1)).is_constant() in (True, False) # could be 0 or 1
True
rS   TNr   )simultaneousr	   Fr   or_realfailing_number)denomsc              3  8   #    U  H  oR                   v   M     g 7fr*   )is_zero)r1  dens     r5   r3  #Expr.is_constant.<locals>.<genexpr>  s     !F#++r5  )getr   rC  setrS   r^  kindr   rH   rF  rG  ru   r   r   rU  ZeroDivisionErrorr   diffr   sympy.solvers.solversr\  r   r   )rE   wrtflagsrS   rN  rw   sym
wrt_numberr[  rO  rP  wderivr\  s                 r5   is_constantExpr.is_constantT  s   V 99Z.>>   #hszkT ==?D
 << &)CScHH
,BcS
C IId3taST]#;<!%  ':T1aA6A }!%%		$s4!SY'?"@%) " +AAEEz LLq!Q: =Qaee^u8L LLr1a3=Qaee^u8L LLN=Qaee^xx{e+$*+++Q1N AIIaLE(z$UD9yy!1599--  	1!F!FFGGe D %  ) As2   K)K:AK +AK  KK K0/K0c                j  ^^^^ SSK JmJm  SSKJn  SSKJn  SSKJn  [        U5      n[        U[        5      (       d  gX:X  a  g[        T" X-
  5      SS9nU(       d  gUR                  [        [        5      (       d  gUR!                  5       S	   n[#        U5      S	:  a1  U Vs/ s H  oR%                  S5      PM     n	nS
U	;  a  ['        U	5      $ UR)                  SSS9n
U
SL a  gUR*                  (       d  U
c  g
U
SL a)  UR-                  5       nU(       a  UR.                  (       a  gUR*                  (       Ga2  UR1                  [2        5       Vs/ s H$  oR4                  S   R6                  (       d  M"  UPM&     snmTR9                  S S9  T H  m U" UTSS9nU(       a  TU;   a    g[;        S U 5       5      (       a    g[;        S U 5       5      (       a    g['        U4S jU 5       5      (       a    g['        UUU4S jU 5       5      (       a    gTR<                  (       a   ['        UUU4S jU 5       5      (       a    gM  M  M       U" U5      nUR@                  (       a  ggU
S;  a  U
S:w  a  gU(       a  U$ g
s  snf s  snf ! [>         a     GM
  f = f! U[>        4 a     NAf = f)aW  Return True if self == other, False if it does not, or None. If
failing_expression is True then the expression which did not simplify
to a 0 will be returned instead of None.

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

If ``self`` is a Number (or complex number) that is not zero, then
the result is False.

If ``self`` is a number and has not evaluated to zero, evalf will be
used to test whether the expression evaluates to zero. If it does so
and the result has significance (i.e. the precision is either -1, for
a Rational result, or is greater than 1) then the evalf value will be
used to return True or False.

r   )	nsimplifyrS   )solveNotAlgebraicminimal_polynomialFT)radicalr	   N)rS   r[  c                "    U R                   S   * $ r   )r?   )r,  s    r5   <lambda>Expr.equals.<locals>.<lambda>H  s    affQiZr7   key)rS   c              3  8   #    U  H  oR                   v   M     g 7fr*   )r  )r1  sis     r5   r3  Expr.equals.<locals>.<genexpr>U  s     ;s}}sr5  c              3  <   #    U  H  oR                   S L v   M     g7f)FN)is_algebraic)r1  r3   s     r5   r3  r~  Y  s     D1~~6s   c              3  ,   >#    U  H	  oT;   v   M     g 7fr*   r;   )r1  r}  surdss     r5   r3  r~  \  s     9SrU{Ss   c              3  j   >#    U  H(  nT" TU-
  5      S :H  =(       a    T" TU-
  5      S :H  v   M*     g7f)r   Nr;   r1  r}  rp  srS   s     r5   r3  r~  `  sB      E@C"  )R0A5  6 (R 0A 5 6@Cs   03c              3  b   >#    U  H$  nT" UT/5      T:H  =(       a    T" U5      T:H  v   M&     g 7fr*   r;   r  s     r5   r3  r~  d  s7      #3.1 $-R!#5#:#Px|q?P#P.1s   ,/)TN)!sympy.simplify.simplifyrp  rS   rf  rq  sympy.polys.polyerrorsrs  sympy.polys.numberfieldsru  r
   
isinstancer9   factor_termshasr+   r   as_coeff_mulru   r   anyrm  r   rU  is_comparableatomsr   r?   r  sortr6  is_realNotImplementedError	is_Symbol)rE   r   failing_expressionrq  rs  ru  re  factorsfacfac_zeroconstantndiffr  solmprp  rS   r  s               `  @@@r5   r   Expr.equals  s   $ 	@/7?%&&= HT\2DAxxS!! ##%a(w<!189#

1H98#8}$##U4#Hu~~ tLLNE ,," >>> $

3H166!93G3GQHEJJ/J0  a%8C8#';s;;; $)DDDD#(9S999 $) E@CE E E#'99" #3.1#3  3  3'+ 3 %%  F +D1B||#  <'HMKA :R IB +  %&9: sT   &J!J:JJ0J	J"J>J-JJ# 
J J #J21J2c                R   SSK Jn  SSKJn  U R                  (       Gag   U R                  S5      nUc  g [        USS5      S:X  a  g U[        R                  L a  g U R                  S5      nUR                  (       a  U[        R                  4nO[        U5      nUc  gUu  pxUR                  (       a  UR                  (       d  gUR                  S:w  a<  UR                  S:w  a,  [!        U(       + =(       a    U(       a	  US:  5      $ US:  5      $ UR                  S:X  ac  U(       a  UR                  S:X  aK  U R#                  5       (       a5  U R%                  [&        5      (       d   U" U 5      R(                  (       a  gg g g g g g ! [         a     g f = f! U[*        4 a     g f = f)Nr   rt  rr  r   r:  r	   F)r  ru  r  rs  r   _eval_evalfr   getattrr   r   r\   r  Zeror   r   r:  bool_eval_is_algebraicr  rj   r  r  )	rE   positiveru  rs  n2fr  r   r3   s	            r5   #_eval_is_extended_positive_negative(Expr._eval_is_extended_positive_negative  se   ?7>>>%%a( zr7A&!+QUU{

1Azz166	$Q}DAKKAKKww!|1EH(AIIQIIAqAGGqL++--dhhx6H6H)$/99$ : 7I- -99   4 %&9: s#   F )F 
FFF&%F&c                     U R                  SS9$ )NTr  r  r_   s    r5   _eval_is_extended_positiveExpr._eval_is_extended_positive  s    777FFr7   c                     U R                  SS9$ )NFr  r  r_   s    r5   _eval_is_extended_negativeExpr._eval_is_extended_negative  s    777GGr7   c           	       ^ ^^^^^^ SSK Jm  SSKJn  SSKJmJm  SSKJn  SSK	J
n  Tc  Tc  [        S5      eUUUUUU U4S jnTT:X  a  [        R                  $ U" S	S
9nU[        R                  L a  U$ U" SS
9n	T=(       a    Tc  X-
  $ X-
  n
TR                  (       Ga  TR                  (       Ga  TT:  a
  U" TT5      nO	U" TT5      nU" T R!                  5       R#                  5       S   TUS9nT R%                  U5       H  nX" UR&                  S   TUS9-  nM      U H  nU
[        R                  L a    U
$ UR                  (       d  M,  TU:  UT:  s=:X  a  S	:X  a   O  OU
T" T TUS5      * T" T TUS5      -   -  n
M_  TU:  UT:  s=:X  a  S	:X  d  Mt  O  Mx  U
T" T TUS5      T" T TUS5      -
  -  n
M      U
$ U
$ ! [(         a     U
$ f = f)a&  
Returns evaluation over an interval.  For most functions this is:

self.subs(x, b) - self.subs(x, a),

possibly using limit() if NaN is returned from subs, or if
singularities are found between a and b.

If b or a is None, it only evaluates -self.subs(x, a) or self.subs(b, x),
respectively.

r   AccumBoundslog)limitLimit)Interval)solvesetz"Both interval ends cannot be None.c                  > U (       a  TOTnUc  [         R                  $ TR                  T	U5      nUR                  [         R                  [         R
                  [         R                  [         R                  T5      (       aL  TT:  S:w  a  T" TT	X(       a  SOS5      nOT" TT	X(       a  SOS5      n[        UT5      (       a  [        S5      eU$ )NF+-zCould not compute limit)
r   r  rH   r  r   r   r   ComplexInfinityr  r  )
leftr0   Cr  r  rO  rP  r  rE   r,  s
      r5   _eval_endpoint+Expr._eval_interval.<locals>._eval_endpoint  s    qAyvvIIaO55

A,>,>**K9 9A%'!$1TcsC!$1TcsC!!U++12KLLHr7   T)r  Fr	   )domainr  r  )!sympy.calculus.accumulationboundsr  &sympy.functions.elementary.exponentialr  sympy.series.limitsr  r  sympy.sets.setsr  sympy.solvers.solvesetr  r   r   r  r   r  cancelas_numer_denomr  r?   r   )rE   r,  rO  rP  r  r  r  r  ABvaluer  singularitieslogtermr  r  r  r  s   ````           @@@r5   _eval_intervalExpr._eval_interval  s    	B>4,3I!)ABB	 	" 666M%:H&G!5L???q1u!!Q!!Q %T[[]%A%A%CA%FM::c? -a!!1# !# +&A~  ?? A1q51T1%aC"8!85q!S;Q!QQa%QU3t33tQ3!7%aC:P!PP ' u  s   $G ?AG "G 
GGc                    g r*   r;   )rE   expts     r5   _eval_powerExpr._eval_power  s     r7   c                R    U R                   (       a  U $ U R                  (       a  U * $ g r*   )r9  is_imaginaryr_   s    r5   _eval_conjugateExpr._eval_conjugate  s%      K5L r7   c                    SSK Jn  U" U 5      $ )z(Returns the complex conjugate of 'self'.r   	conjugate)r   r  r   s     r5   r  Expr.conjugate  s    Gwr7   c                b   U R                   (       a  [        R                  $ SSKJn  [        R                  nU nU(       a  U[        R
                  -  nUR                  U5      nUR                  US5      nU[        R                  L a  UR                  US5      nU[        R                  L a;   UR                  U5      u  pgUR                  U" U5      5      (       a
  [        5       e U[        R                  :w  a  O	U(       a  M  WX$-  -  $ ! [         a    UR                  US5      n NCf = f)Nr   r  )r^  r   r  r  r  rk   re  rH   r   r  r  leadtermr  r   )rE   r,  cdirr  minexpry   r-   _s           r5   dirExpr.dir  s    <<66M>aeeOF((1+CHHQNE~		!Q))),"||AHEyyQ(((l* )  c T\!!	 " ,IIaOE,s   09D D.-D.c                    SSK Jn  U R                  (       a  U $ U R                  (       a  U" U 5      $ U R                  (       a	  U" U 5      * $ g )Nr   r  )r   r  r   is_hermitianis_antihermitian)rE   r  s     r5   _eval_transposeExpr._eval_transpose$  sA    BKT?"""dO## #r7   c                    SSK Jn  U" U 5      $ )Nr   )	transpose)r   r  )rE   r  s     r5   r  Expr.transpose-  s    Br7   c                    SSK JnJn  U R                  (       a  U $ U R                  (       a  U * $ U R                  5       nUb  U" U5      $ U R                  5       nUb  U" U5      $ g )Nr   )r  r  )r   r  r  r  r  r  r  )rE   r  r  r2  s       r5   _eval_adjointExpr._eval_adjoint1  sb    MK""5L""$?S>!""$?S>! r7   c                    SSK Jn  U" U 5      $ )Nr   )adjoint)r   r  )rE   r  s     r5   r  Expr.adjoint>  s    @t}r7   c                   ^^^ SSK Jn  [        TSS5      nUc  SnOU" S5      nU(       a  TSS mU" T5      mU4S jmUUU4S	 jnXT4$ )
z+Parse and configure the ordering of terms. r   )monomial_key
startswithNFzrev-   c           	        > [        U  Vs/ s H#  n[        U[         5      (       a  T" U5      OU* PM%     sn5      $ s  snf r*   )rt   r  )monommnegs     r5   r  Expr._parse_order.<locals>.negQ  s7    %P%QJq%$8$8#a&qb@%PQQPs   *<c           	        > U u  nu  u  p#pET	" T" U5      5      n[        U Vs/ s H  ofR                  T
S9PM     sn5      n[        U5      U4X#44nXEU4$ s  snf )Nrd   )rt   rm   r  )termr  r   r   r  ncparter-   	monom_keyr  re   s           r5   r{  Expr._parse_order.<locals>.keyT  sj    +/(A(%	%()EVDVJJUJ3VDEF2h^bX.E%'' Es   A)sympy.polys.orderingsr  r  )r>   re   r  r  reverser{  r  r  s    `    @@r5   _parse_orderExpr._parse_orderB  sX     	7UL$7
G (Gab	 '		R	( |r7   c                    U /$ )z4Return list of ordered factors (if Mul) else [self].r;   )rE   re   s     r5   rs   Expr.as_ordered_factors_  s	    vr7   c                z    SSK JnJn  SSKJn   U" U /UQ70 UD6nUR
                  (       d  gU$ ! X44 a     gf = f)aL  Converts ``self`` to a polynomial or returns ``None``.

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

>>> from sympy import sin
>>> from sympy.abc import x, y

>>> print((x**2 + x*y).as_poly())
Poly(x**2 + x*y, x, y, domain='ZZ')

>>> print((x**2 + x*y).as_poly(x, y))
Poly(x**2 + x*y, x, y, domain='ZZ')

>>> print((x**2 + sin(y)).as_poly(x, y))
None

r   )PolynomialErrorGeneratorsNeeded)PolyN)r  r  r	  sympy.polys.polytoolsr
  is_Poly)rE   gensr?   r  r	  r
  polys          r5   as_polyExpr.as_polyc  sJ    & 	M.
	,t,t,D<<2 	 	s   0 0 ::c                n  ^^ SSK JmJm  Uc  U R                  (       a  UU4S jn[	        [
        R                  " U 5      US9n[        U5      S:X  a  [        US   TT45      (       a  [        US   [        5      (       an  [	        [        R                  " US   5      US9n[        U5      S:X  a>  [        US   T5      (       a*  US   R                  (       a  US   R                  (       a  U$ U R                  U5      u  p6U R                  5       u  px[        S U 5       5      (       d  [	        XsUS9n	OZ/ / pU H<  u  pUR                  (       d  U
R!                  X45        M*  UR!                  X45        M>     [	        XS	S9[	        XS	S9-   n	U(       a  X4$ U	 VVs/ s H  u  pUPM	     snn$ s  snnf )
z
Transform an expression to an ordered list of terms.

Examples
========

>>> from sympy import sin, cos
>>> from sympy.abc import x

>>> (sin(x)**2*cos(x) + sin(x)**2 + 1).as_ordered_terms()
[sin(x)**2*cos(x), sin(x)**2, 1]

r	   )r'   NumberSymbolc                *   > [        U TT45      (       + $ r*   )r  )r,  r'   r  s    r5   rx  'Expr.as_ordered_terms.<locals>.<lambda>  s    z!fl-CDDr7   rz  r   r   c              3  >   #    U  H  u  pUR                   v   M     g 7fr*   )is_Order)r1  r  r  s      r5   r3  (Expr.as_ordered_terms.<locals>.<genexpr>  s     6WT4==s   )r{  r  T)numbersr'   r  rp   sortedr+   r,   ru   r  r   is_positiveis_negativer  as_termsr  r  r.   )rE   re   datar{  add_argsmul_argsr  termsr  ordered_terms_orderr  reprr  r'   r  s                  @@r5   rq   Expr.as_ordered_terms  sn    	2=T[[ ECcmmD1s;HH"x{V\,BCCx{C00!#--"<#FMQ&"8A;77 // //#O((/mmo6666UW=GF#
}}MM4,/MM4,/	 $ Vd;$78G = (/0WTD000s   F1c                z   SSK Jn  [        5       / p2[        R                  " U 5       H  nUR                  5       u  pV[        U5      n0 / pU[        R                  La  [        R                  " U5       Hh  n	U	R                  (       a   U[        U	5      -  nM%  U	R                  (       a!  U" U	5      u  pXU
'   UR                  U
5        MW  UR                  U	5        Mj     UR                   UR"                  4n[%        U5      nUR                  XEXx445        M     ['        U[(        S9n[+        U5      0 p[-        U5       H	  u  pXU'   M     / nU HM  u  nu  pWnS/U-  nUR/                  5        H  u  pUUX   '   M     UR                  XE[%        U5      U445        MO     UU4$ ! [        [        4 a     GN f = f)z,Transform an expression to a list of terms. r	   )decompose_powerrz  r   )	exprtoolsr'  rb  r+   r,   rf   r   r   rk   r   r   r   r   r   addr.   realimagrt   r  r   ru   	enumerateitems)rE   r'  r  r   r  r-   _termcpartr  factorrx   rc   kindicesr3   gr   r  s                     r5   r  Expr.as_terms  s   .eReMM$'D,,.LEENE6AEE!!mmE2F''%!WV_4E %,,$3F$;	&)df- 3" JJ

*E6]FLL$ 6787 (: d 01Y7dODAAJ $ ,1(D(5CEE"[[]	'*gm$ + MM4uv!>?@ -2 t|G !*:6 ! !s   	F&&F:9F:c                    U $ )z1Removes the additive O(..) symbol if there is oner;   r_   s    r5   removeOExpr.removeO  s    r7   c                    g)z=Returns the additive O(..) symbol if there is one, else None.Nr;   r_   s    r5   getO	Expr.getO  s    r7   c           	     <   U R                  5       nUc  gUR                  (       Gai  UR                  nU[        R                  L a  [        R
                  $ UR                  (       a  [        R                  $ UR                  (       a  UR                  S   $ UR                  (       a  UR                   H  nUR                  (       a  [        R                  s  $ UR                  (       d  M9  SSK
JnJn  UR                  U5      n[        U5      S:X  d  Mc  UR                  5       nUR!                  Xc" SSS95      nUR"                  R                  (       d  M  UR$                  R&                  (       d  M  [)        UR$                  5      s  $    [+        SU-  5      e)a  
Returns the order of the expression.

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

The order is determined either from the O(...) term. If there
is no O(...) term, it returns None.

Examples
========

>>> from sympy import O
>>> from sympy.abc import x
>>> (1 + x + O(x**2)).getn()
2
>>> (1 + x).getn()

Nr	   DummySymbolr,  Tr  znot sure of order of %s)r9  r  rw   r   rk   r  r  rg   r?   rr   symbolr=  r>  r  ru   poprH   rx   rc   is_RationalrH  r  )rE   ooir=  r>  symsr,  s          r5   getn	Expr.getn  s   ( IIK9ZZZAAEEzvv{{uuxxvvay xx&&B|| uuyyy9!xx/t9> $
A!#E#,E!FB!ww000RVV5G5G5G'*266{ 2 ! "";a"?@@r7   c                    SSK Jn  U" X5      $ )Nr	   )	count_ops)functionrH  )rE   visualrH  s      r5   rH  Expr.count_ops'  s    '&&r7   c           	        [        [        R                  " U 5      5      n[        U5       H!  u  pVUR                  (       a  M  USU nXES n  O   Un/ nU(       a^  U(       aW  US   R
                  (       aC  US   R                  (       a/  US   [        R                  La  [        R                  US   * /USS& U(       a|  [        U5      n	[        U5      nU	(       a_  U(       aX  [        U5      U	:w  aI  [        SU V
s/ s H/  n
[        U R                  5      R                  U
5      S:  d  M-  U
PM1     sn
-  5      eXx/$ s  sn
f )a  Return [commutative factors, non-commutative factors] of self.

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

self is treated as a Mul and the ordering of the factors is maintained.
If ``cset`` is True the commutative factors will be returned in a set.
If there were repeated factors (as may happen with an unevaluated Mul)
then an error will be raised unless it is explicitly suppressed by
setting ``warn`` to False.

Note: -1 is always separated from a Number unless split_1 is False.

Examples
========

>>> from sympy import symbols, oo
>>> A, B = symbols('A B', commutative=0)
>>> x, y = symbols('x y')
>>> (-2*x*y).args_cnc()
[[-1, 2, x, y], []]
>>> (-2.5*x).args_cnc()
[[-1, 2.5, x], []]
>>> (-2*x*A*B*y).args_cnc()
[[-1, 2, x, y], [A, B]]
>>> (-2*x*A*B*y).args_cnc(split_1=False)
[[-2, x, y], [A, B]]
>>> (-2*x*y).args_cnc(cset=True)
[{-1, 2, x, y}, []]

The arg is always treated as a Mul:

>>> (-2 + x + A).args_cnc()
[[], [x - 2 + A]]
>>> (-oo).args_cnc() # -oo is a singleton
[[-1, oo], []]
Nr   r	   z"repeated commutative arguments: %s)rF  r   r,   r,  r   r   is_extended_negativer   r   ru   rb  r   r?   count)rE   csetwarnsplit_1r?   r3   mir0   ncclenr4   s              r5   args_cncExpr.args_cnc+  s   L CMM$'(t_EA$$$!H"X	 % ABaDNNaD%%!AMM)]]QqTE*AbqEq6DAAQ4 !E/0!RqDO4I4I"4MPQ4Q"q!R"S T Tw "Ss   =,D?
-D?
c                  ^^ [        U5      n[        U[        5      (       d  [        R                  $ [        U5      nU(       d  [        R                  $ X:X  a&  US:X  a  [        R                  $ [        R                  $ U[        R                  L aj  [        R                  " U 5       Vs/ s H*  oUR                  5       S   [        R                  L d  M(  UPM,     nnU(       d  [        R                  $ [        U6 $ US:X  a  UR                  (       a  U R                  (       a  U R                  XS9nU(       d  [        R                  $ U(       d2  U [        [        R                  " U5       Vs/ s H  oUU-  PM	     sn6 -
  $ U [        [        R                  " U5       Vs/ s H  oQU-  PM	     sn6 -
  $ U R                  USS9S   $ X-  nS nSS jn	/ n/ m[        R                  " U 5      n
U R                  nUR                  nU(       a  U(       d  [        R                  $ U(       Ga0  U R                  (       Ga  U(       Gd  U(       Gd  [        R                  " U5      n[        [        R                  " U R                  U5      S   5       V^s/ s H!  m[        U4S jU 5       5      (       d  M  TPM#     sn6 nUR                  XS	S
9nUR                  (       a  U(       d  U$ [!        UR"                   Vs/ s H  oR%                  5       PM     sn6 u  nn['        U5      (       a  U$ [        U Vs/ s H  n[        R(                  " U5      PM     sn6 $ U=(       d    UnUR%                  S[+        U(       + 5      S9u  nnU
 H  nUR%                  S[+        U(       + 5      S9u  nnUc  / n[-        U5      [-        U5      :  a  MC  UR/                  U5      n[-        U5      [-        U5      -   [-        U5      :X  d  Mz  U(       a%  UR1                  [        [3        U5      U-   6 5        M  TR1                  UU45        M     U(       a&  U/ :X  a  [        R                  $ U(       a  [        U6 $ gT(       d  [        R                  $ [        U4S jT 5       5      (       at  U	" TS   S   UU5      nUba  U(       d=  [        [        T VVs/ s H  u  nn[        U6 PM     snn6 [        TS   S   SU 6 5      $ [        TS   S   U[-        U5      -   S 6 $ [5        US T 5       5      nU(       a  U	" UUU5      nUb  U(       d[  TS   S   n[7        S[-        T5      5       H#  mUR9                  TT   S   5      nU(       a  M#    O   [        [3        U5      USU -   6 $ U[-        U5      -   n[        T VVs/ s H  u  nn[        [3        U5      UUS -   6 PM     snn6 $ [3        [;        [5        US T 5       5      5      5      nU(       ak  U	" UUU5      nUb^  U(       d@  [        T VVs/ s H*  u  nn[        [3        U5      US[-        U5      * U-    -   6 PM,     snn6 $ [        UU[-        U5      -   S 6 $ Sn[=        T5       H5  u  mu  nnU	" UUU5      nUc  M  U(       d  UUU4nM&    [        R                  $    U(       a;  Uu  nnnU(       d  [        [3        U5      USU -   6 $ [        UU[-        U5      -   S 6 $ [        R                  $ s  snf s  snf s  snf s  snf s  snf s  snf s  snnf s  snnf s  snnf )a
  
Returns the coefficient from the term(s) containing ``x**n``. If ``n``
is zero then all terms independent of ``x`` will be returned.

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

When ``x`` is noncommutative, the coefficient to the left (default) or
right of ``x`` can be returned. The keyword 'right' is ignored when
``x`` is commutative.

Examples
========

>>> from sympy import symbols
>>> from sympy.abc import x, y, z

You can select terms that have an explicit negative in front of them:

>>> (-x + 2*y).coeff(-1)
x
>>> (x - 2*y).coeff(-1)
2*y

You can select terms with no Rational coefficient:

>>> (x + 2*y).coeff(1)
x
>>> (3 + 2*x + 4*x**2).coeff(1)
0

You can select terms independent of x by making n=0; in this case
expr.as_independent(x)[0] is returned (and 0 will be returned instead
of None):

>>> (3 + 2*x + 4*x**2).coeff(x, 0)
3
>>> eq = ((x + 1)**3).expand() + 1
>>> eq
x**3 + 3*x**2 + 3*x + 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 2]
>>> eq -= 2
>>> [eq.coeff(x, i) for i in reversed(range(4))]
[1, 3, 3, 0]

You can select terms that have a numerical term in front of them:

>>> (-x - 2*y).coeff(2)
-y
>>> from sympy import sqrt
>>> (x + sqrt(2)*x).coeff(sqrt(2))
x

The matching is exact:

>>> (3 + 2*x + 4*x**2).coeff(x)
2
>>> (3 + 2*x + 4*x**2).coeff(x**2)
4
>>> (3 + 2*x + 4*x**2).coeff(x**3)
0
>>> (z*(x + y)**2).coeff((x + y)**2)
z
>>> (z*(x + y)**2).coeff(x + y)
0

In addition, no factoring is done, so 1 + z*(1 + y) is not obtained
from the following:

>>> (x + z*(x + x*y)).coeff(x)
1

If such factoring is desired, factor_terms can be used first:

>>> from sympy import factor_terms
>>> factor_terms(x + z*(x + x*y)).coeff(x)
z*(y + 1) + 1

>>> n, m, o = symbols('n m o', commutative=False)
>>> n.coeff(n)
1
>>> (3*n).coeff(n)
3
>>> (n*m + m*n*m).coeff(n) # = (1 + m)*n*m
1 + m
>>> (n*m + m*n*m).coeff(n, right=True) # = (1 + m)*n*m
m

If there is more than one possible coefficient 0 is returned:

>>> (n*m + m*n).coeff(n)
0

If there is only one possible coefficient, it is returned:

>>> (n*m + x*m*n).coeff(m*n)
x
>>> (n*m + x*m*n).coeff(m*n, right=1)
1

See Also
========

as_coefficient: separate the expression into a coefficient and factor
as_coeff_Add: separate the additive constant from an expression
as_coeff_Mul: separate the multiplicative constant from an expression
as_independent: separate x-dependent terms/factors from others
sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used
r	   r   )rightT)as_Addc                    U (       a  U(       d  / $ [        [        U 5      [        U5      5      n[        U5       H  nX   X   :w  d  M  U S U s  $    U S S  $ r*   )minru   range)l1l2rV   r3   s       r5   incommonExpr.coeff.<locals>.incommon  sO    R	CGSW%A1X5BE>bq6M  a5Lr7   c                  ^ ^^ T(       a  T (       a  [        T5      [        T 5      :  a  g[        T5      nU(       d   T R                  5         TR                  5         [        [        T 5      U-
  S-   5       H*  m[        UU U4S j[        U5       5       5      (       d  M*    O   SmU(       d   T R                  5         TR                  5         Tb  U(       d  [        T 5      TU-   -
  mT$ )a&  Find where list sub appears in list l. When ``first`` is True
the first occurrence from the left is returned, else the last
occurrence is returned. Return None if sub is not in l.

Examples
========

>> l = range(5)*2
>> find(l, [2, 3])
2
>> find(l, [2, 3], first=0)
7
>> find(l, [2, 4])
None

Nr	   c              3  @   >#    U  H  nTTU-      TU   :H  v   M     g 7fr*   r;   )r1  jr3   lsubs     r5   r3  +Expr.coeff.<locals>.find.<locals>.<genexpr>  s"     <8aqQx3q6)8s   )ru   r  r\  r6  )rd  re  firstrV   r3   s   ``  @r5   findExpr.coeff.<locals>.find  s    " a3s8c!f#4CA		3q6A:>*<58<<< + 		}UFa!e$Hr7   c              3  T   >#    U  H  o[         R                  " T5      ;   v   M     g 7fr*   )r   r,   )r1  xir3   s     r5   r3  Expr.coeff.<locals>.<genexpr>4  s     >"S]]1--s   %(F)rX  _first)rO  rP  Nc              3  >   >#    U  H  u  pUTS    S   :H  v   M     g7f)r   r	   Nr;   )r1  r   rV   r1   s      r5   r3  rl  U  s     0RTQ11a=Rs   c              3  *   #    U  H	  oS    v   M     g7fr	   Nr;   r1  rV   s     r5   r3  rl  \  s     #5"QaD"s   c              3  P   #    U  H  n[        [        US    5      5      v   M     g7frp  )rF  reversedrq  s     r5   r3  rl  k  s      !C1$x!~"6"6s   $&T)r
   r  r   r   r  r   rk   r+   r,   rf   rp   r-   as_independentr   r   r6  rG  r?   rU  r    r   r  ru   
differencer.   rF  r   r\  intersectionrs  r,  ) rE   r,  rV   rX  rm  rO  co2r0   r_  rh  r?   self_cx_cxargsr3   rQ  rvc_partnc_partone_cnxmargsrS  residiir   beggcdcr  endhitr1   s                  `                @r5   r-   
Expr.coeffj  s9   ` AJ!U##66M1I66M9Avuu66M :!mmD1R1^^5Ea5HAEE5Q11CRvv96xxDKKJJqJ.66M#S]]15E'F5E!5E'F"GGGcq1A#B1AAaC1A#BCCC&&q&6q99 D	!	F 13}}T"$$#66Mdkkk&MM!$Et/B/B1/Ea/H!I @!IA>>> !I @ AA6B99E	!"''#B'QJJL'#BCOFG6""	G<Gq*G<==#JJDtG}J=	rA

4F
3C
DIE2z5zCJ&$$U+E5zCJ&#e*4JJsT%[2%578IIubk*  byvvCy   vv0R000"Q%(B.> "3R(@RTQaR(@#A31aQTRTCVWW"BqE!HR#b'\]$;<<#5"#56C#r5)> !!uQx!&q#b'!2A#'#4#4RU1X#>D#'4 % "3  #T$Z#cr(%:<<RL"$LAS47QqrU?%<$LMMxx!C!CDF GC#r5)> "VX$YVXdaQRS47QS	B5G+G%IVX$YZZ"CSW$677C&r]	6Aq!R'> !Qh 66M + "HB1 "T!Wq"v%577"Ab3r7lm$45566Ms S (G#Bx@
 $C =< )A  %M %ZsB   +'\\0\
"\
\"7\">\'9 \,\1;$\7
.1\=
c                    U $ )z
Convert a polynomial to a SymPy expression.

Examples
========

>>> from sympy import sin
>>> from sympy.abc import x, y

>>> f = (x**2 + x*y).as_poly(x, y)
>>> f.as_expr()
x**2 + x*y

>>> sin(x).as_expr()
sin(x)

r;   )rE   r  s     r5   as_exprExpr.as_expr  s	    $ r7   c                d    U R                  U5      nU(       a  UR                  U5      (       d  U$ g)a  
Extracts symbolic coefficient at the given expression. In
other words, this functions separates 'self' into the product
of 'expr' and 'expr'-free coefficient. If such separation
is not possible it will return None.

Examples
========

>>> from sympy import E, pi, sin, I, Poly
>>> from sympy.abc import x

>>> E.as_coefficient(E)
1
>>> (2*E).as_coefficient(E)
2
>>> (2*sin(E)*E).as_coefficient(E)

Two terms have E in them so a sum is returned. (If one were
desiring the coefficient of the term exactly matching E then
the constant from the returned expression could be selected.
Or, for greater precision, a method of Poly can be used to
indicate the desired term from which the coefficient is
desired.)

>>> (2*E + x*E).as_coefficient(E)
x + 2
>>> _.args[0]  # just want the exact match
2
>>> p = Poly(2*E + x*E); p
Poly(x*E + 2*E, x, E, domain='ZZ')
>>> p.coeff_monomial(E)
2
>>> p.nth(0, 1)
2

Since the following cannot be written as a product containing
E as a factor, None is returned. (If the coefficient ``2*x`` is
desired then the ``coeff`` method should be used.)

>>> (2*E*x + x).as_coefficient(E)
>>> (2*E*x + x).coeff(E)
2*x

>>> (E*(x + 1) + x).as_coefficient(E)

>>> (2*pi*I).as_coefficient(pi*I)
2
>>> (2*I).as_coefficient(pi*I)

See Also
========

coeff: return sum of terms have a given factor
as_coeff_Add: separate the additive constant from an expression
as_coeff_Mul: separate the multiplicative constant from an expression
as_independent: separate x-dependent terms/factors from others
sympy.polys.polytools.Poly.coeff_monomial: efficiently find the single coefficient of a monomial in Poly
sympy.polys.polytools.Poly.nth: like coeff_monomial but powers of monomial terms are used


N)extract_multiplicativelyr  )rE   rw   r   s      r5   as_coefficientExpr.as_coefficient  s,    @ ))$/QUU4[[Hr7   c                N  ^^ SSK Jn  SSKJn  SSKJn  U [        R                  L a  X 4$ U R                  nUR                  S[        U [        5      5      (       a  [        nO[        n[        5       m/ mU H7  n[        X5      (       a  TR                  U5        M&  TR                  U5        M9     UU4S jn	XvLd  U[        La1  U[        La(  U	" U 5      (       a  UR                  U 4$ XR                  4$ U[        L a  [!        U R"                  5      n
OU R%                  5       u  p['        X5      nUS   nUS   nU[        L a  [        U6 U" U6 4$ [)        W5       H8  u  pU	" U5      (       a  UR+                  XS	 5          OUR                  U5        M:     [        U6 U" U6 4$ )
a  
A mostly naive separation of a Mul or Add into arguments that are not
are dependent on deps. To obtain as complete a separation of variables
as possible, use a separation method first, e.g.:

* separatevars() to change Mul, Add and Pow (including exp) into Mul
* .expand(mul=True) to change Add or Mul into Add
* .expand(log=True) to change log expr into an Add

The only non-naive thing that is done here is to respect noncommutative
ordering of variables and to always return (0, 0) for `self` of zero
regardless of hints.

For nonzero `self`, the returned tuple (i, d) has the
following interpretation:

* i will has no variable that appears in deps
* d will either have terms that contain variables that are in deps, or
  be equal to 0 (when self is an Add) or 1 (when self is a Mul)
* if self is an Add then self = i + d
* if self is a Mul then self = i*d
* otherwise (self, S.One) or (S.One, self) is returned.

To force the expression to be treated as an Add, use the hint as_Add=True

Examples
========

-- self is an Add

>>> from sympy import sin, cos, exp
>>> from sympy.abc import x, y, z

>>> (x + x*y).as_independent(x)
(0, x*y + x)
>>> (x + x*y).as_independent(y)
(x, x*y)
>>> (2*x*sin(x) + y + x + z).as_independent(x)
(y + z, 2*x*sin(x) + x)
>>> (2*x*sin(x) + y + x + z).as_independent(x, y)
(z, 2*x*sin(x) + x + y)

-- self is a Mul

>>> (x*sin(x)*cos(y)).as_independent(x)
(cos(y), x*sin(x))

non-commutative terms cannot always be separated out when self is a Mul

>>> from sympy import symbols
>>> n1, n2, n3 = symbols('n1 n2 n3', commutative=False)
>>> (n1 + n1*n2).as_independent(n2)
(n1, n1*n2)
>>> (n2*n1 + n1*n2).as_independent(n2)
(0, n1*n2 + n2*n1)
>>> (n1*n2*n3).as_independent(n1)
(1, n1*n2*n3)
>>> (n1*n2*n3).as_independent(n2)
(n1, n2*n3)
>>> ((x-n1)*(x-y)).as_independent(x)
(1, (x - y)*(x - n1))

-- self is anything else:

>>> (sin(x)).as_independent(x)
(1, sin(x))
>>> (sin(x)).as_independent(y)
(sin(x), 1)
>>> exp(x+y).as_independent(x)
(1, exp(x + y))

-- force self to be treated as an Add:

>>> (3*x).as_independent(x, as_Add=True)
(0, 3*x)

-- force self to be treated as a Mul:

>>> (3+x).as_independent(x, as_Add=False)
(1, x + 3)
>>> (-3+x).as_independent(x, as_Add=False)
(1, x - 3)

Note how the below differs from the above in making the
constant on the dep term positive.

>>> (y*(-3+x)).as_independent(x)
(y, x - 3)

-- use .as_independent() for true independence testing instead
   of .has(). The former considers only symbols in the free
   symbols while the latter considers all symbols

>>> from sympy import Integral
>>> I = Integral(x, (x, 1, 2))
>>> I.has(x)
True
>>> x in I.free_symbols
False
>>> I.as_independent(x) == (I, 1)
True
>>> (I + x).as_independent(x) == (I, x)
True

Note: when trying to get independent terms, a separation method
might need to be used first. In this case, it is important to keep
track of what you send to this routine so you know how to interpret
the returned values

>>> from sympy import separatevars, log
>>> separatevars(exp(x+y)).as_independent(x)
(exp(y), exp(x))
>>> (x + x*y).as_independent(y)
(x, x*y)
>>> separatevars(x + x*y).as_independent(y)
(x, y + 1)
>>> (x*(1 + y)).as_independent(y)
(x, y + 1)
>>> (x*(1 + y)).expand(mul=True).as_independent(y)
(x, x*y)
>>> a, b=symbols('a b', positive=True)
>>> (log(a*b).expand(log=True)).as_independent(b)
(log(a), log(b))

See Also
========

separatevars
expand_log
sympy.core.add.Add.as_two_terms
sympy.core.mul.Mul.as_two_terms
as_coeff_mul
r	   )r>  _unevaluated_Add_unevaluated_MulrY  c                ~   > U R                   " T6 nT(       d  U$ U=(       d    U R                   " U R                  T-  6 $ )zvreturn the standard has() if there are no literal symbols, else
check to see that symbol-deps are in the free symbols.)r  rC  )r  	has_otherr   ri  s     r5   r   Expr.as_independent.<locals>.has~  s8     uI  >(< >>r7   TFN)r?  r>  r)  r  mulr  r   r  funcra  r  r+   r   rb  r.   identityrF  r?   rU  r!   r,  extend)rE   depshintr>  r  r  r  wantrQ  r  r?   rS  dependindepr3   rV   r   ri  s                   @@r5   ru  Expr.as_independent  sk   L 	#))166><yy88Hjs355DD eA!$$
Q	 	? CDO4yyt,,mm,,s{DII==?O4%3;K!16!:;;!"q66MM"R&)Q	 &
 ; 0& 999r7   c                ^    UR                  S5      U :X  a  gSSKJnJn  U" U 5      U" U 5      4$ )a5  Performs complex expansion on 'self' and returns a tuple
containing collected both real and imaginary parts. This
method cannot be confused with re() and im() functions,
which does not perform complex expansion at evaluation.

However it is possible to expand both re() and im()
functions and get exactly the same results as with
a single call to this function.

>>> from sympy import symbols, I

>>> x, y = symbols('x,y', real=True)

>>> (x + y*I).as_real_imag()
(x, y)

>>> from sympy.abc import z, w

>>> (z + w*I).as_real_imag()
(re(z) - im(w), re(w) + im(z))

ignoreNr   )r   r   )ra  r   r   r   )rE   deephintsr   r   s        r5   r   Expr.as_real_imag  s.    . 99X$&CtHbh''r7   c                d    [        [        5      nUR                  U R                  5       /5        U$ )ag  Return self as a dictionary of factors with each factor being
treated as a power. The keys are the bases of the factors and the
values, the corresponding exponents. The resulting dictionary should
be used with caution if the expression is a Mul and contains non-
commutative factors since the order that they appeared will be lost in
the dictionary.

See Also
========
as_ordered_factors: An alternative for noncommutative applications,
                    returning an ordered list of factors.
args_cnc: Similar to as_ordered_factors, but guarantees separation
          of commutative and noncommutative factors.
)r(   r   updaterh   )rE   rQ  s     r5   as_powers_dictExpr.as_powers_dict  s+     	$""$%&r7   c                   [        [        5      nU(       d  [        R                  " U 5       H(  nUR	                  5       u  pEX%   R                  U5        M*     UR                  5        H'  u  pg[        U5      S:X  a	  US   X&'   M  [        U6 X&'   M)     GOU R                  " USS06u  p[        R                  " U	5       H  n
U
R                  (       a[  U
R                  " U6 u  pKU[        R                  L a  X*   R                  U5        MM  X*R                  " U6    R                  U5        Mo  U
(       d  Mx  X*   R                  [        R                  5        M     U Vs0 s H  of[        X&   6 _M     nnU[        R                  La!  UR                  [        R                  U05        [        [         5      nUR                  U5        U$ s  snf )a  Return a dictionary mapping terms to their Rational coefficient.
Since the dictionary is a defaultdict, inquiries about terms which
were not present will return a coefficient of 0.

If symbols ``syms`` are provided, any multiplicative terms
independent of them will be considered a coefficient and a
regular dictionary of syms-dependent generators as keys and
their corresponding coefficients as values will be returned.

Examples
========

>>> from sympy.abc import a, x, y
>>> (3*x + a*x + 4).as_coefficients_dict()
{1: 4, x: 3, a*x: 1}
>>> _[a]
0
>>> (3*a*x).as_coefficients_dict()
{a*x: 3}
>>> (3*a*x).as_coefficients_dict(x)
{x: 3*a}
>>> (3*a*x).as_coefficients_dict(y)
{1: 3*a*x}

r	   r   rY  T)r(   rF  r+   r,   rf   r.   r-  ru   ru  rr   r  r   rk   _new_rawargsr  r  r   )rE   rD  rQ  air0   r  r1  vinddepr3   r,  dis                r5   as_coefficients_dictExpr.as_coefficients_dict  s]   4 mmD)(A * 	q6Q;Q4AD7AD	 " **D>>HC]]3'88>>40DAAEEzA..!,-44Q7QDKK& ( )**1CJA*!&& !%%&
		!	 +s   !Gc                &    U [         R                  4$ r*   r   rk   r_   s    r5   rh   Expr.as_base_exp  s    QUU{r7   c                f    U(       a  U R                   " U6 (       d  U S4$ [        R                  U 44$ )a  Return the tuple (c, args) where self is written as a Mul, ``m``.

c should be a Rational multiplied by any factors of the Mul that are
independent of deps.

args should be a tuple of all other factors of m; args is empty
if self is a Number or if self is independent of deps (when given).

This should be used when you do not know if self is a Mul or not but
you want to treat self as a Mul or if you want to process the
individual arguments of the tail of self as a Mul.

- if you know self is a Mul and want only the head, use self.args[0];
- if you do not want to process the arguments of the tail but need the
  tail then use self.as_two_terms() which gives the head and tail;
- if you want to split self into an independent and dependent parts
  use ``self.as_independent(*deps)``

>>> from sympy import S
>>> from sympy.abc import x, y
>>> (S(3)).as_coeff_mul()
(3, ())
>>> (3*x*y).as_coeff_mul()
(3, (x, y))
>>> (3*x*y).as_coeff_mul(x)
(3*y, (x,))
>>> (3*y).as_coeff_mul(x)
(3*y, ())
r;   )r  r   rk   )rE   r  rL   s      r5   r  Expr.as_coeff_mul	  s+    < 88T?Rxuutg~r7   c                f    U(       a  U R                   " U6 (       d  U S4$ [        R                  U 44$ )a  Return the tuple (c, args) where self is written as an Add, ``a``.

c should be a Rational added to any terms of the Add that are
independent of deps.

args should be a tuple of all other terms of ``a``; args is empty
if self is a Number or if self is independent of deps (when given).

This should be used when you do not know if self is an Add or not but
you want to treat self as an Add or if you want to process the
individual arguments of the tail of self as an Add.

- if you know self is an Add and want only the head, use self.args[0];
- if you do not want to process the arguments of the tail but need the
  tail then use self.as_two_terms() which gives the head and tail.
- if you want to split self into an independent and dependent parts
  use ``self.as_independent(*deps)``

>>> from sympy import S
>>> from sympy.abc import x, y
>>> (S(3)).as_coeff_add()
(3, ())
>>> (3 + x).as_coeff_add()
(3, (x,))
>>> (3 + x + y).as_coeff_add(x)
(y + 3, (x,))
>>> (3 + y).as_coeff_add(x)
(y + 3, ())

r;   )has_freer   r  )rE   r  s     r5   as_coeff_addExpr.as_coeff_add,  s,    > ==$'Rxvvwr7   c                    U (       d   [         R                  [         R                  4$ U R                  SS9u  pUR                  (       a  U* U* p!X4$ )a  Return the positive Rational that can be extracted non-recursively
from every term of self (i.e., self is treated like an Add). This is
like the as_coeff_Mul() method but primitive always extracts a positive
Rational (never a negative or a Float).

Examples
========

>>> from sympy.abc import x
>>> (3*(x + 1)**2).primitive()
(3, (x + 1)**2)
>>> a = (6*x + 2); a.primitive()
(2, 3*x + 1)
>>> b = (x/2 + 3); b.primitive()
(1/2, x + 6)
>>> (a*b).primitive() == (1, a*b)
True
Tr?  )r   rk   r  rf   r  )rE   r0   r   s      r5   	primitiveExpr.primitiveP  sG    & 55!&&=   $ /==2rqtr7   c                &    [         R                  U 4$ )a  This method should recursively remove a Rational from all arguments
and return that (content) and the new self (primitive). The content
should always be positive and ``Mul(*foo.as_content_primitive()) == foo``.
The primitive need not be in canonical form and should try to preserve
the underlying structure if possible (i.e. expand_mul should not be
applied to self).

Examples
========

>>> from sympy import sqrt
>>> from sympy.abc import x, y, z

>>> eq = 2 + 2*x + 2*y*(3 + 3*y)

The as_content_primitive function is recursive and retains structure:

>>> eq.as_content_primitive()
(2, x + 3*y*(y + 1) + 1)

Integer powers will have Rationals extracted from the base:

>>> ((2 + 6*x)**2).as_content_primitive()
(4, (3*x + 1)**2)
>>> ((2 + 6*x)**(2*y)).as_content_primitive()
(1, (2*(3*x + 1))**(2*y))

Terms may end up joining once their as_content_primitives are added:

>>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
(11, x*(y + 1))
>>> ((3*(x*(1 + y)) + 2*x*(3 + 3*y))).as_content_primitive()
(9, x*(y + 1))
>>> ((3*(z*(1 + y)) + 2.0*x*(3 + 3*y))).as_content_primitive()
(1, 6.0*x*(y + 1) + 3*z*(y + 1))
>>> ((5*(x*(1 + y)) + 2*x*(3 + 3*y))**2).as_content_primitive()
(121, x**2*(y + 1)**2)
>>> ((x*(1 + y) + 0.4*x*(3 + 3*y))**2).as_content_primitive()
(1, 4.84*x**2*(y + 1)**2)

Radical content can also be factored out of the primitive:

>>> (2*sqrt(2) + 4*sqrt(10)).as_content_primitive(radical=True)
(2, sqrt(2)*(1 + 2*sqrt(5)))

If clear=False (default is True) then content will not be removed
from an Add if it can be distributed to leave one or more
terms with integer coefficients.

>>> (x/2 + y).as_content_primitive()
(1/2, x + 2*y)
>>> (x/2 + y).as_content_primitive(clear=False)
(1, x/2 + y)
r  )rE   rv  clears      r5   as_content_primitiveExpr.as_content_primitivej  s    n uud{r7   c                &    U [         R                  4$ )zReturn the numerator and the denominator of an expression.

expression -> a/b -> a, b

This is just a stub that should be defined by
an object's class methods to get anything else.

See Also
========

normal: return ``a/b`` instead of ``(a, b)``

r  r_   s    r5   r  Expr.as_numer_denom  s     QUU{r7   c                    SSK Jn  U R                  5       u  p#U[        R                  L a  U$ UR
                  (       a  U" USU-  5      $ X#-  $ )zReturn the expression as a fraction.

expression -> a/b

See Also
========

as_numer_denom: return ``(a, b)`` instead of ``a/b``

r	   r  )r  r  r  r   rk   r   )rE   r  rV   rQ  s       r5   normalExpr.normal  sF     	*""$:H;;#Aqs++3Jr7   c                   SSK Jn  SSKJn  [	        U5      nU [
        R                  L a  gU[
        R                  L a  U $ X:X  a  [
        R                  $ UR                  (       a/  UR                  5       u  pEU[
        R                  La
  [        XESS9nUR                  (       a9  UR                  5       u  pgU R                  U5      nUb  UR                  U5      $ U$ X-  n	U R                  (       Ga  U [
        R                  L a#  UR                   (       a  [
        R                  $  gU [
        R"                  L aD  UR$                  (       a  [
        R                  $ UR                   (       a  [
        R"                  $  gU [
        R&                  L a#  UR(                  (       d  [
        R&                  $  gU R*                  (       a7  U	R*                  (       d  gU R                   (       a  U	R$                  (       a  gU	$ U R,                  (       a7  U	R,                  (       d  gU R                   (       a  U	R$                  (       a  gU	$ U R.                  (       a7  U	R.                  (       d  gU R                   (       a  U	R$                  (       a  gU	$  gU R0                  (       d$  U R2                  (       d  U [
        R4                  L a  U	R                  (       ak  [7        U	R8                  5      S:X  aR  U	R8                  S   R*                  (       a3  U	R8                  S   R                   (       a  U	R8                  S   U :X  a  U	$ gU	R*                  (       a  UR                  (       a  U	$ gU R                  (       Ga  U R                  5       u  pUR                  (       ai  U[
        R:                  LaV  U
[
        R                  LaB  UR$                  (       a  U
R                  U* 5      nUb  U* nOU
R                  U5      nUb  X-  $ gX:X  a  U
$ / nUR8                   H*  nUR                  U5      nUc    gUR=                  U5        M,     U
[
        R                  La  U Vs/ s H  nU
U-  PM
     nnU" U6 $ [>        R@                  " U5      $ U R                  (       aN  [C        U R8                  5      n[E        U5       H)  u  nnUR                  U5      nUc  M  UUU'   [        U6 s  $    gU RF                  (       d  [I        X5      (       at  U RK                  5       u  nnURK                  5       u  nnUU:X  a"  URM                  U5      nUb  [O        UU5      $  gUU:X  a   URM                  S5      nUb  [O        UU5      $ gs  snf )	a  Return None if it's not possible to make self in the form
c * something in a nice way, i.e. preserving the properties
of arguments of self.

Examples
========

>>> from sympy import symbols, Rational

>>> x, y = symbols('x,y', real=True)

>>> ((x*y)**3).extract_multiplicatively(x**2 * y)
x*y**2

>>> ((x*y)**3).extract_multiplicatively(x**4 * y)

>>> (2*x).extract_multiplicatively(2)
x

>>> (2*x).extract_multiplicatively(3)

>>> (Rational(1, 2)*x).extract_multiplicatively(3)
x/6

r   )rc   r	   r  NF)evaluater   )(r  rc   r)  r  r
   r   r   rk   rp   r  r   rr   as_two_termsr  r   r   r  r   r  r  r^  r  rA  r  is_NumberSymbolr  r+  ru   r?   r   r.   r+   r   rF  r,  rg   r  rh   extract_additivelyr   )rE   r0   rc   r  ccpcrO  rP  r,  quotientcspsxcnewargsry   newargtr?   r3   sbsecbcenew_exps                           r5   r  Expr.extract_multiplicatively  se   4 	?)AJ155=:KY55L88[[]FB/88>>#DA--a0A}11!448>>>qzz!==::% !n k +++==::%]]--- #d a ***yy,,, !^ [ **%%(*>*>#O!!++%%(*>*>#O((%%(*>*>#O ~ q !!T^^tq7N3x}}#5#:==#..8==3C3O3OT\TaTabcTdhlTl#Oj i $$f e [[[^^%FB{{q5QUU?}}88!<>"$B88;~!uw	Gww55a8>v&	 
 &-.g1g.'..~~g..[[#DIID#D/355a8%$DG:%	 *"  [[Jt11%%'FB]]_FBRx//3&r7++ '  b//2&r7++1 /s   !Vc                   [        U5      nU [        R                  L a  gUR                  (       a  U $ X:X  a  [        R                  $ U [        R                  :X  a  gU R
                  (       a=  UR
                  (       d  gU nX!-
  nUS:  a  US:  a  X2:  d  US:  a  US::  a  X2:  a  U$ gUR
                  (       a+  U R                  5       u  p$UR                  U5      nUc  gXT-   $ UR                  (       a  UR                  S   R
                  (       a  U R                  U5      nUR                  S5      =(       d    SU-  nU(       a,  XU-  -
  nXcR                  U5      =(       d    U-   =(       d    S$ UR                  5       u  ptU R                  5       u  pUR                  U5      nUc  gU	R                  U5      n
U
c  gXZ-   $ [        X5      u  p#UR                  S5      =(       d    SU-  nU(       a%  XcR                  U5      =(       d    U-   =(       d    S$ / n[        R                  " U5       Hv  nUR                  5       u  pU R                  U5      nU(       d    gUR                  5       u  nnUR                  U5      nUc    gXU-  -  n UR                  UU-   U-  5        Mx     UR                  U 5        [        U6 $ )a  Return self - c if it's possible to subtract c from self and
make all matching coefficients move towards zero, else return None.

Examples
========

>>> from sympy.abc import x, y
>>> e = 2*x + 3
>>> e.extract_additively(x + 1)
x + 2
>>> e.extract_additively(3*x)
>>> e.extract_additively(4)
>>> (y*(x + 1)).extract_additively(x + 1)
>>> ((x + 1)*(x + 2*y + 1) + 3).extract_additively(x + 1)
(x + 1)*(x + 2*y) + 3

See Also
========
extract_multiplicatively
coeff
as_coefficient

Nr   r	   )r
   r   r   r^  r  r   as_coeff_Addr  rp   r?   r-   r6   r+   r,   rf   r.   )rE   r0   r1   re  r  xaxa0hshstxa2coeffsrO  acatcoccots                    r5   r  Expr.extract_additivelyT	  sa   2 AJ155=99KY66MQVV^>>;;B6DQ419FtqyTY;;%%'EB&&q)Bz6M
 88q	++AB((+0q!3Cd{66q9ATBKtK>>#DA&&(FB&&q)Bz''*C{8O $?$$Q',1a/2215=>G4Gq!A^^%FBBB(HC''+BzrEMDMM38R-( " 	dF|r7   c                    [        SSSS9  U R                   VVs1 s H  oR                    H  o"iM     M     snn$ s  snnf )a  
Like ``free_symbols``, but returns the free symbols only if
they are contained in an expression node.

Examples
========

>>> from sympy.abc import x, y
>>> (x + y).expr_free_symbols # doctest: +SKIP
{x, y}

If the expression is contained in a non-expression object, do not return
the free symbols. Compare:

>>> from sympy import Tuple
>>> t = Tuple(x + y)
>>> t.expr_free_symbols # doctest: +SKIP
set()
>>> t.free_symbols
{x, y}

        The expr_free_symbols property is deprecated. Use free_symbols to get
        the free symbols of an expression.
        1.9deprecated-expr-free-symbolsdeprecated_since_versionactive_deprecations_target)r   r?   expr_free_symbols)rE   r3   rc  s      r5   r  Expr.expr_free_symbols	  sE    . 	" # &+'E	G  99B9a.A.A.A9BBBs   =c                    g)ak  Return True if self has -1 as a leading factor or has
more literal negative signs than positive signs in a sum,
otherwise False.

Examples
========

>>> from sympy.abc import x, y
>>> e = x - y
>>> {i.could_extract_minus_sign() for i in (e, -e)}
{False, True}

Though the ``y - x`` is considered like ``-(x - y)``, since it
is in a product without a leading factor of -1, the result is
false below:

>>> (x*(y - x)).could_extract_minus_sign()
False

To put something in canonical form wrt to sign, use `signsimp`:

>>> from sympy import signsimp
>>> signsimp(x*(y - x))
-x*(x - y)
>>> _.could_extract_minus_sign()
True
Fr;   r_   s    r5   could_extract_minus_signExpr.could_extract_minus_sign	  s    8 r7   c                   SSK Jn  SSKJn  [        R
                  n[        R                  n[        R                  " U 5      n/ nU H(  n[        X5      (       a  XxR                  /-  nM$  XX-  nM*     [        R
                  n	/ n
[        R                  [        R                  -  nU(       aj  UR                  5       nUR                  (       a  X|R                  -  nM8  UR                   (       a  UR#                  U5      nUb  X-  n	Mc  X/-  n
U(       a  Mj  U	R$                  (       a  U	nSnOU	R&                  " U	R(                  6 u  pU" US-  [        R*                  -
  5      S-  nXOS-  -  nX-
  nU(       a)  UR-                  S5      nUb  U[        R*                  -  nUnU[/        U4U-   6 -  [/        U
6 -   nUS:w  a
  XR" U5      -  nXT4$ )a  
Try to write self as ``exp_polar(2*pi*I*n)*z`` in a nice way.
Return (z, n).

>>> from sympy import exp_polar, I, pi
>>> from sympy.abc import x, y
>>> exp_polar(I*pi).extract_branch_factor()
(exp_polar(I*pi), 0)
>>> exp_polar(2*I*pi).extract_branch_factor()
(1, 1)
>>> exp_polar(-pi*I).extract_branch_factor()
(exp_polar(I*pi), -1)
>>> exp_polar(3*pi*I + x).extract_branch_factor()
(exp_polar(x + I*pi), 1)
>>> (y*exp_polar(-5*pi*I)*exp_polar(3*pi*I + 2*pi*x)).extract_branch_factor()
(y*exp_polar(2*pi*x), -1)
>>> exp_polar(-I*pi/2).extract_branch_factor()
(exp_polar(-I*pi/2), 0)

If allow_half is True, also extract exp_polar(I*pi):

>>> exp_polar(I*pi).extract_branch_factor(allow_half=True)
(1, 1/2)
>>> exp_polar(2*I*pi).extract_branch_factor(allow_half=True)
(1, 1)
>>> exp_polar(3*I*pi).extract_branch_factor(allow_half=True)
(1, 3/2)
>>> exp_polar(-I*pi).extract_branch_factor(allow_half=True)
(1, -1/2)
r   )	exp_polarceilingr;   r   r	   )r  r  r   r  r   r  rk   r   r,   r  rc   Pir+  r@  rp   r?   rr   r  r   r  rC  Halfr  r+   )rE   
allow_halfr  r  rV   resr?   expsry   piimultextrasipirc   r-   tail
branchfactr0   rS  newexps                      r5   extract_branch_factorExpr.extract_branch_factor	  s   > 	E?FFee}}T"C#))	!
	 
 &&dd1??"((*Czz zz**3/$$GeOF d ED!..0D0DEKEU1Wqvv-.q0
	\%%a(B~QVVSA54<))CL8Q;9V$$Cvr7   c                    U(       a  [        [        [        U5      5      nOU R                  nU(       d  gU R	                  U5      $ )a:  
Return True if self is a polynomial in syms and False otherwise.

This checks if self is an exact polynomial in syms.  This function
returns False for expressions that are "polynomials" with symbolic
exponents.  Thus, you should be able to apply polynomial algorithms to
expressions for which this returns True, and Poly(expr, \*syms) should
work if and only if expr.is_polynomial(\*syms) returns True. The
polynomial does not have to be in expanded form.  If no symbols are
given, all free symbols in the expression will be used.

This is not part of the assumptions system.  You cannot do
Symbol('z', polynomial=True).

Examples
========

>>> from sympy import Symbol, Function
>>> x = Symbol('x')
>>> ((x**2 + 1)**4).is_polynomial(x)
True
>>> ((x**2 + 1)**4).is_polynomial()
True
>>> (2**x + 1).is_polynomial(x)
False
>>> (2**x + 1).is_polynomial(2**x)
True
>>> f = Function('f')
>>> (f(x) + 1).is_polynomial(x)
False
>>> (f(x) + 1).is_polynomial(f(x))
True
>>> (1/f(x) + 1).is_polynomial(f(x))
False

>>> n = Symbol('n', nonnegative=True, integer=True)
>>> (x**n + 1).is_polynomial(x)
False

This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be a polynomial to
become one.

>>> from sympy import sqrt, factor, cancel
>>> y = Symbol('y', positive=True)
>>> a = sqrt(y**2 + 2*y + 1)
>>> a.is_polynomial(y)
False
>>> factor(a)
y + 1
>>> factor(a).is_polynomial(y)
True

>>> b = (y**2 + 2*y + 1)/(y + 1)
>>> b.is_polynomial(y)
False
>>> cancel(b)
y + 1
>>> cancel(b).is_polynomial(y)
True

See also .is_rational_function()

T)rb  mapr
   rC  _eval_is_polynomialrE   rD  s     r5   is_polynomialExpr.is_polynomial=
  s;    B s7D)*D$$D''--r7   c                :    X;   a  gU R                   " U6 (       d  gg NTr  r  s     r5   r
  Expr._eval_is_polynomial
  s    <}}d#r7   c                    U(       a  [        [        [        U5      5      nOU R                  nU(       d	  U [        ;  $ U R                  U5      $ )a  
Test whether function is a ratio of two polynomials in the given
symbols, syms. When syms is not given, all free symbols will be used.
The rational function does not have to be in expanded or in any kind of
canonical form.

This function returns False for expressions that are "rational
functions" with symbolic exponents.  Thus, you should be able to call
.as_numer_denom() and apply polynomial algorithms to the result for
expressions for which this returns True.

This is not part of the assumptions system.  You cannot do
Symbol('z', rational_function=True).

Examples
========

>>> from sympy import Symbol, sin
>>> from sympy.abc import x, y

>>> (x/y).is_rational_function()
True

>>> (x**2).is_rational_function()
True

>>> (x/sin(y)).is_rational_function(y)
False

>>> n = Symbol('n', integer=True)
>>> (x**n + 1).is_rational_function(x)
False

This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be a rational function
to become one.

>>> from sympy import sqrt, factor
>>> y = Symbol('y', positive=True)
>>> a = sqrt(y**2 + 2*y + 1)/y
>>> a.is_rational_function(y)
False
>>> factor(a)
(y + 1)/y
>>> factor(a).is_rational_function(y)
True

See also is_algebraic_expr().

)rb  r	  r
   rC  _illegal_eval_is_rational_functionr  s     r5   is_rational_functionExpr.is_rational_function
  sC    f s7D)*D$$D8++..t44r7   c                >    X;   a  gU R                  U5      (       d  gg r  )	has_xfreer  s     r5   r  Expr._eval_is_rational_function
  s    <~~d##r7   c                    UR                   (       d  [        SR                  U5      5      e[        U5      nU R	                  X5      $ )aq  
This tests whether an expression is meromorphic as
a function of the given symbol ``x`` at the point ``a``.

This method is intended as a quick test that will return
None if no decision can be made without simplification or
more detailed analysis.

Examples
========

>>> from sympy import zoo, log, sin, sqrt
>>> from sympy.abc import x

>>> f = 1/x**2 + 1 - 2*x**3
>>> f.is_meromorphic(x, 0)
True
>>> f.is_meromorphic(x, 1)
True
>>> f.is_meromorphic(x, zoo)
True

>>> g = x**log(3)
>>> g.is_meromorphic(x, 0)
False
>>> g.is_meromorphic(x, 1)
True
>>> g.is_meromorphic(x, zoo)
False

>>> h = sin(1/x)*x**2
>>> h.is_meromorphic(x, 0)
False
>>> h.is_meromorphic(x, 1)
True
>>> h.is_meromorphic(x, zoo)
True

Multivalued functions are considered meromorphic when their
branches are meromorphic. Thus most functions are meromorphic
everywhere except at essential singularities and branch points.
In particular, they will be meromorphic also on branch cuts
except at their endpoints.

>>> log(x).is_meromorphic(x, -1)
True
>>> log(x).is_meromorphic(x, 0)
False
>>> sqrt(x).is_meromorphic(x, -1)
True
>>> sqrt(x).is_meromorphic(x, 0)
False

z{} should be of symbol type)	is_symbolr   r  r
   _eval_is_meromorphicrE   r,  rO  s      r5   is_meromorphicExpr.is_meromorphic
  s=    n {{9@@CDDAJ((..r7   c                >    X:X  a  gU R                  U5      (       d  gg r  r  r  s      r5   r  Expr._eval_is_meromorphic  s    9}}Qr7   c                    U(       a  [        [        [        U5      5      nOU R                  nU(       d  gU R	                  U5      $ )a  
This tests whether a given expression is algebraic or not, in the
given symbols, syms. When syms is not given, all free symbols
will be used. The rational function does not have to be in expanded
or in any kind of canonical form.

This function returns False for expressions that are "algebraic
expressions" with symbolic exponents. This is a simple extension to the
is_rational_function, including rational exponentiation.

Examples
========

>>> from sympy import Symbol, sqrt
>>> x = Symbol('x', real=True)
>>> sqrt(1 + x).is_rational_function()
False
>>> sqrt(1 + x).is_algebraic_expr()
True

This function does not attempt any nontrivial simplifications that may
result in an expression that does not appear to be an algebraic
expression to become one.

>>> from sympy import exp, factor
>>> a = sqrt(exp(x)**2 + 2*exp(x) + 1)/(exp(x) + 1)
>>> a.is_algebraic_expr(x)
False
>>> factor(a).is_algebraic_expr()
True

See Also
========

is_rational_function

References
==========

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

T)rb  r	  r
   rC  _eval_is_algebraic_exprr  s     r5   is_algebraic_exprExpr.is_algebraic_expr  s;    V s7D)*D$$D++D11r7   c                :    X;   a  gU R                   " U6 (       d  gg r  r  r  s     r5   r#  Expr._eval_is_algebraic_exprM  s    <}}d#r7   r   c           	       ^^^^^ Tc?  U R                   nU(       d  U $ [        U5      S:  a  [        S5      eUR                  5       mSSKJnJn	  [        TU	5      (       a  TU R                   ;   n
O&U" 5       nXR                  TU05      R                   ;   n
U
(       d  Uc
  S U 4 5       $ U $ [        U5      S:w  d  US;  a  [        S5      eUb  [        U5      nUS:  a  [        S5      e[        T5      m[        T5      mSS	KJnJn  TR                  (       dC  TR                  (       a  TR                   (       a  S
OSnOU" T5      R                   (       a  S
OSnOT(       a(  TR"                  (       a  U" T5      R%                  5       mOd['        U5      S
:X  a  [(        R*                  mOD['        U5      S:X  a  [(        R,                  mO$T[(        R.                  :X  a  [(        R*                  mT[1        T5      -  mT(       ab  TR"                  (       aQ  SSKJn   U R7                  TTT-  5      R9                  TUS
SS9nUc  UU4S jU 5       $ UR7                  TTT-  5      $ T(       d  TS:w  aX  U R7                  TTTT-  -   05      R9                  TSUS
USS9nUc  UUU4S jU 5       $ UR7                  TTT-  TT-  -
  05      $ TR                   TR<                  s=L a  b  O  TR>                  SLaL  U" SSS9mU R7                  TT5      R9                  TTX4UTS9nUc  UU4S jU 5       $ UR7                  TT5      $ SSK J!m  UGb  U RE                  TX5TS9nURG                  5       =(       d    [(        R.                  nU(       GaN  URI                  5       nUU:  a6  US:w  a#  UUR7                  TT[K        UU5      -  5      -  nOUT" ST5      -  nOUU:  a  SSK&J'n  [Q        SS5       H  nU RE                  TUU-   UTS9nURI                  5       nUU:w  d  M0  UU" UU-
  U-  UU-
  -  5      -   nU RE                  TUUTS9nURI                  5       U:  a-  U RE                  TUUTS9nUS-  nURI                  5       U:  a  M-    O   [        S['        U5      < SU < 35      eUT" TU-  T5      -  nURG                  5       nURS                  5       nO\URU                  T5      (       a  U$ T" TU-  T5      nURW                  5       n UU-   RS                  5       U:X  a  [(        R.                  n SSK-J.n  U" UT5      U-   $ UU4S jnU" U RS                  5       R_                  TUTS95      $ ! U a;    U R7                  TTT-  5      R;                  TUS9nUR7                  TTT-  5      s $ f = f! [X         a    Us $ f = f! [X         a    UU-   s $ f = f)av  
Series expansion of "self" around ``x = x0`` yielding either terms of
the series one by one (the lazy series given when n=None), else
all the terms at once when n != None.

Returns the series expansion of "self" around the point ``x = x0``
with respect to ``x`` up to ``O((x - x0)**n, x, x0)`` (default n is 6).

If ``x=None`` and ``self`` is univariate, the univariate symbol will
be supplied, otherwise an error will be raised.

Parameters
==========

expr : Expression
       The expression whose series is to be expanded.

x : Symbol
    It is the variable of the expression to be calculated.

x0 : Value
     The value around which ``x`` is calculated. Can be any value
     from ``-oo`` to ``oo``.

n : Value
    The value used to represent the order in terms of ``x**n``,
    up to which the series is to be expanded.

dir : String, optional
      The series-expansion can be bi-directional. If ``dir="+"``,
      then (x->x0+). If ``dir="-", then (x->x0-). For infinite
      ``x0`` (``oo`` or ``-oo``), the ``dir`` argument is determined
      from the direction of the infinity (i.e., ``dir="-"`` for
      ``oo``).

logx : optional
       It is used to replace any log(x) in the returned series with a
       symbolic value rather than evaluating the actual value.

cdir : optional
       It stands for complex direction, and indicates the direction
       from which the expansion needs to be evaluated.

Examples
========

>>> from sympy import cos, exp, tan
>>> from sympy.abc import x, y
>>> cos(x).series()
1 - x**2/2 + x**4/24 + O(x**6)
>>> cos(x).series(n=4)
1 - x**2/2 + O(x**4)
>>> cos(x).series(x, x0=1, n=2)
cos(1) - (x - 1)*sin(1) + O((x - 1)**2, (x, 1))
>>> e = cos(x + exp(y))
>>> e.series(y, n=2)
cos(x + 1) - y*sin(x + 1) + O(y**2)
>>> e.series(x, n=2)
cos(exp(y)) - x*sin(exp(y)) + O(x**2)

If ``n=None`` then a generator of the series terms will be returned.

>>> term=cos(x).series(n=None)
>>> [next(term) for i in range(2)]
[1, -x**2/2]

For ``dir=+`` (default) the series is calculated from the right and
for ``dir=-`` the series from the left. For smooth functions this
flag will not alter the results.

>>> abs(x).series(dir="+")
x
>>> abs(x).series(dir="-")
-x
>>> f = tan(x)
>>> f.series(x, 2, 6, "+")
tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +
(x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +
5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +
2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))

>>> f.series(x, 2, 3, "-")
tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))
+ O((x - 2)**3, (x, 2))

For rational expressions this method may return original expression without the Order term.
>>> (1/x).series(x, n=8)
1/x

Returns
=======

Expr : Expression
    Series expansion of the expression about x0

Raises
======

TypeError
    If "n" and "x0" are infinity objects

PoleError
    If "x0" is an infinity object

r	   z+x must be given for multivariate functions.r<  c              3  $   #    U  H  ov   M     g 7fr*   r;   )r1  r  s     r5   r3  Expr.series.<locals>.<genexpr>  s     *6a6s   z+-zDir must be '+' or '-'r   z%Number of terms should be nonnegative)r   signr  r  	PoleError)rV   r  r  c              3  L   >#    U  H  oR                  TTT-  5      v   M     g 7fr*   rA  )r1  r}  r  r,  s     r5   r3  r*    s!     ;2GGAtAv..s   !$)rV   )x0rV   r  logxr  c              3  Z   >#    U  H   oR                  TTT-  TT-  -
  05      v   M"     g 7fr*   rA  )r1  r}  r  r,  r/  s     r5   r3  r*    s-     C2AdFRW$4 566s   (+Tr,  r  r0  r  c              3  F   >#    U  H  oR                  TT5      v   M     g 7fr*   rA  )r1  r  r,  xposs     r5   r3  r*    s     4AtQs   !OrderrV   r0  r  r  	   zCould not calculate z terms for collectc              3  ~  >#    U  H  nUR                   (       d  Uv   M  SnT" UT5      T-  nSn[        UR                  5      n X-
  U-   R                  5       nUT-  nU(       a  UR                  (       a  M5  UR                   (       a  U[        UR                  5      -  nOUS-  nUv   XE:X  a  M  X&-  nMt     g7f)z&Return terms of lseries one at a time.r   r	   N)rp   ru   r?   r6  r  )	r  r}  yieldedrB  ndidndodor6  r,  s	          r5   yield_lseries"Expr.series.<locals>.yield_lseriesI  s     B99    Gb!QADbgg,C lQ.779Q!R[[$99 CL0D AID ;!  s   B:B=)0rC  ru   r   r@  r?  r=  r>  r  xreplacer   r
   r   r   r+  r^  r  r  is_infiniterS   ro   r   rk   r   r  rH  rI  r-  rH   seriesaseriesr  r  sympy.series.orderr6  _eval_nseriesr9  rE  Rationalr   r  r\  r6  r  doitr  sympy.simplify.radsimpr:  _eval_lseries)rE   r,  r/  rV   r  r0  r  rD  r=  r>  r  rQ  r   r+  r-  r  r|  s1rB  ngotr  morenewnr>  s1doner:  r@  r6  r4  s    ``   `                    @@r5   rD  Expr.seriesY  sc   T 9$$DTQ !NOO
A)a  t(((CA}}aV,999Cy*D6**s8q=CtO566=AA1u !HIIR[t}A||||!--c3X11csbnnBx((*SSuuSS}}uuCI~"..+)IIaa(//QCa/H9;;;vvaa(( 		1b46k*+221aStZ[2\AyCCC661afr$w./00 ==AMM11Q[[5Lt,D1d#**4Q$T*RBy444wwtQ'',=##AD#AB	#QVVAvvx!8 AvaffQ8At+<(<==eAqk)AX
 L %a!//QXDt/T!wwy4<"#gq4xotd{.K&L"LC!%!3!3A4d!3!SB"$'')a-%)%7%7StRV%7%W #q #%'')a- " !, ),/FD*: ; ;%1a.(BGGIZZ\	!Q$N
++-7FF:r1~))
&6 !!=!=adQU!=!VWWS  )IIaa(00a08vvaa(()H + I ' Avs<   4U: U: 'V> <W :>V;:V;>WWW"!W"c                  ^ SSK Jn  UR                  UR                  s=L a  c:  O  O7U" SSS9nU R	                  X5      R                  XbX45      R	                  Xa5      $ SSKJn  SSKJ	nJ
n	   U" X5      u  pSS	KJnJn  SS
KJn  X;   as  U R	                  X" U5      5      R                  XX45      R	                  X" U5      5      nUR!                  5       (       a   X" SX-  -  U["        R$                  45      -   $ U$ U" SSS9mU	" XUT5      u  nnX
;   a  US::  a  U $ U R                  R                  XUS9nUR&                  " UR(                   Vs/ s H  nUR+                  5       PM     sn6 n U" UR	                  USU-  5      R-                  U5      R	                  USU-  5      5      nU" U R(                  S   UR(                  S   -
  5      T-  nU" SU-  5      nUR/                  TSU5      nSSKJn  U" U5      nU(       a  UR	                  TU" U5      5      $ UR!                  5       n[5        [6        R8                  " UR+                  5       5      U4S jS9n["        R:                  nSnU H  nUR=                  T5      u  nnUR?                  U5      (       aU  UR                  XUS-
  S9nU(       a  UR!                  5       (       a    O-UR!                  5       (       a  SnUUTU-  -  -  nM  UU-  nM     U(       a  U(       a  UR	                  TU" U5      5      $ UU-   R	                  TU" U5      5      $ ! U a    U s $ f = fs  snf ! U a    U n GNf = f)a
  Asymptotic Series expansion of self.
This is equivalent to ``self.series(x, oo, n)``.

Parameters
==========

self : Expression
       The expression whose series is to be expanded.

x : Symbol
    It is the variable of the expression to be calculated.

n : Value
    The value used to represent the order in terms of ``x**n``,
    up to which the series is to be expanded.

hir : Boolean
      Set this parameter to be True to produce hierarchical series.
      It stops the recursion at an early level and may provide nicer
      and more useful results.

bound : Value, Integer
        Use the ``bound`` parameter to give limit on rewriting
        coefficients in its normalised form.

Examples
========

>>> from sympy import sin, exp
>>> from sympy.abc import x

>>> e = sin(1/x + exp(-x)) - sin(1/x)

>>> e.aseries(x)
(1/(24*x**4) - 1/(2*x**2) + 1 + O(x**(-6), (x, oo)))*exp(-x)

>>> e.aseries(x, n=3, hir=True)
-exp(-2*x)*sin(1/x)/2 + exp(-x)*cos(1/x) + O(exp(-3*x), (x, oo))

>>> e = exp(exp(x)/(1 - 1/x))

>>> e.aseries(x)
exp(exp(x)/(1 - 1/x))

>>> e.aseries(x, bound=3) # doctest: +SKIP
exp(exp(x)/x**2)*exp(exp(x)/x)*exp(-exp(x) + exp(x)/(1 - 1/x) - exp(x)/x - exp(x)/x**2)*exp(exp(x))

For rational expressions this method may return original expression without the Order term.
>>> (1/x).aseries(x, n=8)
1/x

Returns
=======

Expr
    Asymptotic series expansion of the expression.

Notes
=====

This algorithm is directly induced from the limit computational algorithm provided by Gruntz.
It majorly uses the mrv and rewrite sub-routines. The overall idea of this algorithm is first
to look for the most rapidly varying subexpression w of a given expression f and then expands f
in a series in w. Then same thing is recursively done on the leading coefficient
till we get constant coefficients.

If the most rapidly varying subexpression of a given expression f is f itself,
the algorithm tries to find a normalised representation of the mrv set and rewrites f
using this normalised representation.

If the expansion contains an order term, it will be either ``O(x ** (-n))`` or ``O(w ** (-n))``
where ``w`` belongs to the most rapidly varying expression of ``self``.

References
==========

.. [1] Gruntz, Dominik. A new algorithm for computing asymptotic series.
       In: Proc. 1993 Int. Symp. Symbolic and Algebraic Computation. 1993.
       pp. 239-244.
.. [2] Gruntz thesis - p90
.. [3] https://en.wikipedia.org/wiki/Asymptotic_expansion

See Also
========

Expr.aseries: See the docstring of this function for complete details of this wrapper.
r	   r=  r,  Tr  r,  r   )mrvrewrite)rc   r  r5  r1  )bound)
expand_mulc                >   > [        U R                  T5      S   5      $ )Nr	   )r   as_coeff_exponent)r3   r1  s    r5   rx  Expr.aseries.<locals>.<lambda>  s    QEXEXYZE[\]E^A_r7   rz  F) r?  r=  r  r  rH   rE  rI  r-  sympy.series.gruntzrT  rU  r  rc   r  rF  r6  r9  r   r   r  r?   r6  as_leading_termrD  sympy.core.functionrW  r  r+   r,   r  rY  r  )rE   r,  rV   rV  hirr=  r4  r-  rT  rU  omr  rc   r  r6  r  r  logwr  r  rW  rB  r   has_ordr-   exposnewr1  s                              @r5   rE  Expr.aseriesf  s   r 	"==AMM11t,D99Q%--duBGGPP'4	4|HB 	D,7		!SV$,,Q5>CCAs1vNAvvxx514!QZZ999H#%Tq!,
d:z""1u"5Aaff5ff56A!&&AaC.88;@@AaCHI tyy|chhqk12Q6Dqu:DKK1a 2qM66!SY''FFHs}}QYY[17_`FF A--a0KE4yy||}}Qq}9tyy{{YY[["GdQWn%Q  G66!SY''A||As4y))}  	K	0 6  s*   .
M M2=M MMM! M!c                    SSK Jn  SSKJn  [	        U5      nU" S5      nU R                  X&5      R                  Xa5      R                  Xb5      R                  US5      X!-  -  U" U5      -  $ )zGeneral method for the taylor term.

This method is slow, because it differentiates n-times. Subclasses can
redefine it to make it faster by using the "previous_terms".
r	   rS  r   )	factorialr,  )r?  r=  (sympy.functions.combinatorial.factorialsrf  r
   rH   re  )rE   rV   r,  previous_termsr=  rf  _xs          r5   taylor_termExpr.taylor_term  s_     	"FAJ3Zyy$$R+007<<QBQTIIVWLXXr7   c           	     &    U R                  XSX4US9$ )a!  
Wrapper for series yielding an iterator of the terms of the series.

Note: an infinite series will yield an infinite iterator. The following,
for exaxmple, will never terminate. It will just keep printing terms
of the sin(x) series::

  for term in sin(x).lseries(x):
      print term

The advantage of lseries() over nseries() is that many times you are
just interested in the next term in the series (i.e. the first term for
example), but you do not know how many you should ask for in nseries()
using the "n" parameter.

See also nseries().
N)rV   r  r0  r  )rD  )rE   r,  r/  r  r0  r  s         r5   lseriesExpr.lseries  s    $ {{1Dc4{HHr7   c              #    #    SnU R                  XX#S9nUR                  (       a(  US-  nU R                  XX#S9nUR                  (       a  M(  UR                  5       nUv   U[        R                  L a  g   US-  nU R                  XX#S9R                  5       nXe:w  a  O&XP-
  R                  5       [        R                  L a  g MO  XV-
  v   UnMZ  7f)Nr   r7  r	   )rG  r  r6  r   r  r  )rE   r,  r0  r  rV   rD  r  s          r5   rK  Expr._eval_lseries,  s      ##A#AooFA''T'EF ooo NN;Q++A+IQQS;M))+qvv5  *A s   A
CBCc                    U(       a  XR                   ;  a  U $ Ub  U(       d  US:w  a  U R                  XX4US9$ U R                  XXVS9$ )a  
Wrapper to _eval_nseries if assumptions allow, else to series.

If x is given, x0 is 0, dir='+', and self has x, then _eval_nseries is
called. This calculates "n" terms in the innermost expressions and
then builds up the final series just by "cross-multiplying" everything
out.

The optional ``logx`` parameter can be used to replace any log(x) in the
returned series with a symbolic value to avoid evaluating log(x) at 0. A
symbol to use in place of log(x) should be provided.

Advantage -- it's fast, because we do not have to determine how many
terms we need to calculate in advance.

Disadvantage -- you may end up with less terms than you may have
expected, but the O(x**n) term appended will always be correct and
so the result, though perhaps shorter, will also be correct.

If any of those assumptions is not met, this is treated like a
wrapper to series which will try harder to return the correct
number of terms.

See also lseries().

Examples
========

>>> from sympy import sin, log, Symbol
>>> from sympy.abc import x, y
>>> sin(x).nseries(x, 0, 6)
x - x**3/6 + x**5/120 + O(x**6)
>>> log(x+1).nseries(x, 0, 5)
x - x**2/2 + x**3/3 - x**4/4 + O(x**5)

Handling of the ``logx`` parameter --- in the following example the
expansion fails since ``sin`` does not have an asymptotic expansion
at -oo (the limit of log(x) as x approaches 0):

>>> e = sin(log(x))
>>> e.nseries(x, 0, 6)
Traceback (most recent call last):
...
PoleError: ...
...
>>> logx = Symbol('logx')
>>> e.nseries(x, 0, 6, logx=logx)
sin(logx)

In the following example, the expansion works but only returns self
unless the ``logx`` parameter is used:

>>> e = x**y
>>> e.nseries(x, 0, 2)
x**y
>>> e.nseries(x, 0, 2, logx=logx)
exp(logx*y)

r  )r  r7  )rC  rD  rG  )rE   r,  r/  rV   r  r0  r  s          r5   nseriesExpr.nseriesI  sP    x +++K9cSj;;qa4;88%%a4%CCr7   c                D    [        [        SU R                  -  5      5      e)a  
Return terms of series for self up to O(x**n) at x=0
from the positive direction.

This is a method that should be overridden in subclasses. Users should
never call this method directly (use .nseries() instead), so you do not
have to write docstrings for _eval_nseries().
z
                     The _eval_nseries method should be added to
                     %s to give terms up to O(x**n) at x=0
                     from the positive direction so it is available when
                     nseries calls it.)r  r   r  rE   r,  rV   r0  r  s        r5   rG  Expr._eval_nseries  s+     "* .* -1II	.6 #7  	r7   c                     SSK Jn  U" XX#5      $ )zCompute limit x->xlim.
        r   )r  )r  r  )rE   r,  xlimr  r  s        r5   r  
Expr.limit  s     	.Td((r7   r2  c               h   [        U5      S:  a  U nU H  nUR                  XQUS9nM     U$ U(       d  U $ [        US   5      n[        U5      nUR                  (       d  [	        SU-  5      eXPR
                  ;  a  U $ U R                  XQUS9nUb  SSKJn  U" USSS9$ [        S	U < S
U< S35      e)a8  
Returns the leading (nonzero) term of the series expansion of self.

The _eval_as_leading_term routines are used to do this, and they must
always return a non-zero value.

Examples
========

>>> from sympy.abc import x
>>> (1 + x + x**2).as_leading_term(x)
1
>>> (1/x**2 + x + x**2).as_leading_term(x)
x**(-2)

r	   r2  r   zexpecting a Symbol but got %spowsimpTrc   )r  combinezas_leading_term(, ))
ru   r\  r
   r  r   rC  _eval_as_leading_termsympy.simplify.powsimpr|  r  )rE   r0  r  symbolsr0   r,  r2  r|  s           r5   r\  Expr.as_leading_term  s    $ w<!A%%a%> HKGAJt}{{<q@AA%%%K((D(A?63T599!tQ"GHHr7   c                    U $ r*   r;   )rE   r,  r0  r  s       r5   r  Expr._eval_as_leading_term  r   r7   c                    SSK Jn  U" X5      nUR                  U5      u  pE[        U5      S:X  a  US   R	                  5       u  pgXa:X  a  XG4$ U[
        R                  4$ )zB``c*x**e -> c,e`` where x can be any symbolic expression.
        r   r9  r	   )rJ  r:  r  ru   rh   r   r  )rE   r,  r:  r  r0   prP  r  s           r5   rY  Expr.as_coeff_exponent  sZ     	3D~~a q6Q;Q4##%DAvt!&&yr7   c                r   SSK Jn  SSKJn  U R	                  XUS9nU" S5      nUR                  U" U5      5      (       a  UR                  U" U5      U5      nUR                  U5      u  pXR                  ;   a$  [        [        SU < SU< S	U< S
U< 35      5      eUR                  Xu" U5      5      nX4$ )z
Returns the leading term a*x**b as a tuple (a, b).

Examples
========

>>> from sympy.abc import x
>>> (1+x+x**2).leadterm(x)
(1, 0)
>>> (1/x**2+x+x**2).leadterm(x)
(1, -2)

r	   rS  r   r  r2  r0  z)
                cannot compute leadterm(r~  z<). The coefficient
                should have been free of z	 but got )r?  r=  r  r  r\  r  rH   rY  rC  r   r   )
rE   r,  r0  r  r=  r  rd  rQ  r0   r  s
             r5   r  Expr.leadterm  s     	">  D 9&M55Q==s1vq!A""1%Z=A1a)L M N N FF1c!ftr7   c                &    [         R                  U 4$ )z1Efficiently extract the coefficient of a product.r  rE   r@  s     r5   rf   Expr.as_coeff_Mul  s    uud{r7   c                &    [         R                  U 4$ )z3Efficiently extract the coefficient of a summation.)r   r  r  s     r5   r  Expr.as_coeff_Add  s    vvt|r7   c           
     $    SSK Jn  U" XX#XEXg5      $ )z
Compute formal power power series of self.

See the docstring of the :func:`fps` function in sympy.series.formal for
more information.
r   )fps)sympy.series.formalr  )	rE   r,  r/  r  hyperre   r@  fullr  s	            r5   r  Expr.fps  s     	,4BU8BBr7   c                    SSK Jn  U" X5      $ )zCompute fourier sine/cosine series of self.

See the docstring of the :func:`fourier_series` in sympy.series.fourier
for more information.
r   )fourier_series)sympy.series.fourierr  )rE   limitsr  s      r5   r  Expr.fourier_series  s     	8d++r7   c                D    UR                  SS5        [        U /UQ70 UD6$ )Nr  T)
setdefault_derivative_dispatch)rE   r  assumptionss      r5   re  	Expr.diff  s'    z40#DB7BkBBr7   c                V    U R                   " S0 UD6u  p#U[        R                  U-  -   $ )Nr;   )r   r   r+  )rE   r  r*  r+  s       r5   _eval_expand_complexExpr._eval_expand_complex  s+    &&//
aood***r7   c                f   SnU(       a|  [        U SS5      (       aj  U R                  (       dY  / nU R                   H1  n[        R                  " Xa40 UD6u  pgXG-  nUR                  U5        M3     U(       a  U R                  " U6 n [        X5      (       a  [        X5      " S0 UD6nX:w  a  US4$ X4$ )z
Helper for ``expand()``.  Recursively calls ``expr._eval_expand_hint()``.

Returns ``(expr, hit)``, where expr is the (possibly) expanded
``expr`` and ``hit`` is ``True`` if ``expr`` was truly expanded and
``False`` otherwise.
Fr?   r;   T)r  rn   r?   r9   _expand_hintr.   r  r(  )	rw   r  r  r  r  sargsry   arghitnewexprs	            r5   r  Expr._expand_hint#  s      GD&"--dllEyy"//CUCS! !
 yy%(4d)2E2G&{r7   c	           	       ^	^ SSK Jm  T	R                  X4UXgUS9  U n
UU	4S jnT	R                  SS5      (       a1  U" U 5       Vs/ s H  nUR                  " SXS.T	D6PM     snu  pX-  $ T	R                  SS5      (       a   U" U 5      u  pXR                  " SXS.T	D6-  $ T	R                  S	S5      (       a!  U" U 5      u  pUR                  " SXS.T	D6U-  $ S
 n[        T	R                  5       US9 H3  nT	U   nU(       d  M  SU-   n[        R                  " U
U4SU0T	D6u  n
nM5      U
nT	R                  SS5      (       a  [        R                  " U
S4SU0T	D6u  n
nT	R                  SS5      (       a  [        R                  " U
S4SU0T	D6u  n
nT	R                  SS5      (       a  [        R                  " U
S4SU0T	D6u  n
nU
U:X  a  OM  Ub  [        U5      nUR                  (       a  US::  a  [        SU-  5      e/ n[        R                  " U
5       H7  nUR                  SS9u  nnUU-  nU(       d  M#  UR!                  UU-  5        M9     [        U6 n
U
$ s  snf )z}
Expand an expression using hints.

See the docstring of the expand() function in sympy.core.function for
more information.

r   )fraction)
power_base	power_expr  r  multinomialbasicc                6   > T" U TR                  SS5      5      $ )NexactF)ra  )r,  r  r  s    r5   rx  Expr.expand.<locals>.<lambda>R  s    hq%))GU*CDr7   fracF)r  modulusr   numerc                    U S:X  a  gU $ )z Make multinomial come before mulr  mulzr;   )r  s    r5   _expand_hint_key%Expr.expand.<locals>._expand_hint_keyn  s    u}Kr7   rz  _eval_expand_r  Tr  _eval_expand_multinomialr  _eval_expand_mulr  _eval_expand_logz*modulus must be a positive integer, got %sr?  r;   )rJ  r  r  r@  expandr  keysr9   r  ra  r
   r  r   r+   r,   rf   r.   )rE   r  r  r  r  r  r  r  r  r  rw   	_fractionrO  rV   rQ  r  r  use_hintr  wasr  r   r  r-   r  r  s            `               @r5   r  Expr.expandA  s    	4
S5 	 	: D	99VU##&t_., HHA$A5A,.DA3JYYw&&T?DAXXB4BEBBBYYw&&T?DA88@@%@BB$	 5::<-=>DT{Hx&- --dDMtMuM	c	 ? Cyy..++4J;?JCHJayy&&++,B37B;@Bayy&&++,B37B;@Bas{  g&G%%A @7JL L Ed+"///>t 5LLt, , ;DO.s   I%c                &    SSK Jn  U" U /UQ70 UD6$ )z-See the integrate function in sympy.integralsr   )	integrate)sympy.integrals.integralsr  )rE   r?   rL   r  s       r5   r  Expr.integrate  s    7////r7   c                     SSK Jn  U" XX#5      $ )z,See the nsimplify function in sympy.simplifyr   )rp  )r  rp  )rE   	constants	tolerancer  rp  s        r5   rp  Expr.nsimplify  s    5)::r7   c                    SSK Jn  U" XUS9$ )z+See the separate function in sympy.simplifyr	   )expand_power_base)r  force)rI  r  )rE   r  r  r  s       r5   separateExpr.separate  s    / >>r7   c                "    SSK Jn  U" XX#XE5      $ )z*See the collect function in sympy.simplifyr   r9  )rJ  r:  )rE   rD  r  r  r  distribute_order_termr:  s          r5   r:  Expr.collect  s    2t45PPr7   c                &    SSK Jn  U" U /UQ70 UD6$ )z(See the together function in sympy.polysr   )together)sympy.polys.rationaltoolsr  )rE   r?   rL   r  s       r5   r  Expr.together  s    6.t.v..r7   c                     SSK Jn  U" X40 UD6$ )z%See the apart function in sympy.polysr   )apart)sympy.polys.partfracr  )rE   r,  r?   r  s       r5   r  
Expr.apart  s    .T%%%r7   c                    SSK Jn  U" U 5      $ )z*See the ratsimp function in sympy.simplifyr   )ratsimp)sympy.simplify.ratsimpr  )rE   r  s     r5   r  Expr.ratsimp  s    2t}r7   c                     SSK Jn  U" U 40 UD6$ )z+See the trigsimp function in sympy.simplifyr   )trigsimp)sympy.simplify.trigsimpr  )rE   r?   r  s      r5   r  Expr.trigsimp  s    4%%%r7   c                     SSK Jn  U" U 40 UD6$ )z*See the radsimp function in sympy.simplifyr   )radsimp)rJ  r  )rE   rL   r  s      r5   r  Expr.radsimp  s    2t&v&&r7   c                &    SSK Jn  U" U /UQ70 UD6$ )z*See the powsimp function in sympy.simplifyr   r{  )r  r|  )rE   r?   rL   r|  s       r5   r|  Expr.powsimp  s    2t-d-f--r7   c                    SSK Jn  U" U 5      $ )z+See the combsimp function in sympy.simplifyr   )combsimp)sympy.simplify.combsimpr  )rE   r  s     r5   r  Expr.combsimp  s    4~r7   c                    SSK Jn  U" U 5      $ )z,See the gammasimp function in sympy.simplifyr   )	gammasimp)sympy.simplify.gammasimpr  )rE   r  s     r5   r  Expr.gammasimp  s    6r7   c                &    SSK Jn  U" U /UQ70 UD6$ )z2See the factor() function in sympy.polys.polytoolsr   )r0  )r  r0  )rE   r  r?   r0  s       r5   r0  Expr.factor      0d*T*T**r7   c                &    SSK Jn  U" U /UQ70 UD6$ )z&See the cancel function in sympy.polysr   )r  )r  r  )rE   r  r?   r  s       r5   r  Expr.cancel  r  r7   c                    U R                   (       a  [        USS5      (       a  [        X5      $ SSKJn  U" X/UQ70 UD6$ )zReturn the multiplicative inverse of ``self`` mod ``g``
where ``self`` (and ``g``) may be symbolic expressions).

See Also
========
sympy.core.intfunc.mod_inverse, sympy.polys.polytools.invert
r   Tr   )invert)r   r  r   r  r  )rE   r3  r  r?   r  s        r5   r  Expr.invert  s<     >>gad;;t''0d----r7   c                :   U nUR                   (       d  [        S5      eUR                  (       d6  [        UR	                  S5      SS9(       d  [        S[        U5      -  5      eOU[        ;   a  U$ UR                  =n(       dr  UR                  5       u  pEUSL a4  UR                  U5      [        R                  UR                  U5      -  -   $ UR                  S5      (       a  UR                  U5      $ U(       d  Uc  [        R                  $ U$ [        U=(       d    S5      nUR                  (       a  [!        [        [#        U5      U5      5      $ [%        U5      nXv-   nUR'                  [(        5       V	s/ s H  oR*                  PM     n
n	U
(       a  [-        [/        U
5      5      OSnUc  [/        S	U5      nO[1        X5      nU* U-   nS
nUR	                  X-   5      [3        SU5      -  nUR4                  (       a<  UR*                  S
:X  a,  UR                  S5      (       a  [)        S5      $ [7        S5      e[!        U5      nUS:  a  S
OSnUX-
  R	                  U5      -  nUS:  a  [9        S5      eUS:  a  UU-  nOUS:X  a  XS-  (       a  UOU* -  nXl-
  n[        UR:                  U5      n[=        U[3        SU5      5      nUR                  (       a  Uc  U$ [)        [?        U5      U5      $ U(       d  UU :  a  US
-  n[)        UU5      $ s  sn	f )ad  Return x rounded to the given decimal place.

If a complex number would results, apply round to the real
and imaginary components of the number.

Examples
========

>>> from sympy import pi, E, I, S, Number
>>> pi.round()
3
>>> pi.round(2)
3.14
>>> (2*pi + E*I).round()
6 + 3*I

The round method has a chopping effect:

>>> (2*pi + I/10).round()
6
>>> (pi/10 + 2*I).round()
2*I
>>> (pi/10 + E*I).round(2)
0.31 + 2.72*I

Notes
=====

The Python ``round`` function uses the SymPy ``round`` method so it
will always return a SymPy number (not a Python float or int):

>>> isinstance(round(S(123), -2), Number)
True
z Cannot round symbolic expressionr   TrY  zExpected a number but got %s:Fr   NrB  r	   
   znot computing with precisionr   z)not expecting int(x) to round away from 0g      ?) r   r   rn   r   rV   r   r  r9  r   r   r   r+  r   r  r   r  r  r   _magr  r)  r:  r#   rI  r[  r   r   r   r  r  rH  ro   )rE   rV   r,  xrr   r3   r  digits_to_decimalallowr  precsdpsshiftextraxfrk  r+  dif2ipr|  s                       r5   r   
Expr.round  s   F {{>??yyA53ilBD D 6 (]H((((>>#DAU{wwqzAOOAGGAJ$>>>xx{{wwqz!Y166-A-16N<<5Q+,, G!%"#''%.1.Q.1).k#e*%D; b%.COE #"S(^ SSc"en,<<BHHMxx{{Qx;<<R[ EqrRWKK&&!8%;= ="9$JBRZQ$$TE)BY244_b#b%.)==y	R#&&R$Y
U##w 2s   <Lc                x    SSK Jn  U" [        R                  [        R                  /U R	                  U5      S9/$ )Nr   )_LeftRightArgs)higher)"sympy.matrices.expressions.matexprr  r   rk   _eval_derivative)rE   r,  r  s      r5   _eval_derivative_matrix_lines"Expr._eval_derivative_matrix_lines  s,    Equu~d6K6KA6NOPPr7   )r?   r   returnr&   r*   )rF   z(Mapping[Basic | complex, Expr | complex]rG   Noner  r9   )rF   z0Iterable[tuple[Basic | complex, Expr | complex]]rG   r  rL   r%   r  r9   )rF   Expr | complexrG   r  r  r9   )rF   z)Mapping[Basic | complex, Basic | complex]rG   r  rL   r%   r  r   )rF   z1Iterable[tuple[Basic | complex, Basic | complex]]rG   r  rL   r%   r  r   )rF   Basic | complexrG   r  rL   r%   r  r   )rF   z;Mapping[Basic | complex, Basic | complex] | Basic | complexrG   zBasic | complex | NonerL   r%   r  r   )r  r9   )rB  Nd   FFNF)rV   r   rH   z!dict[Basic, Basic | float] | NonerW   r   rX   r  rY   r  rZ   z
str | Noner[   r  r  r9   )r  ztuple[Expr, Expr])r  r   )r  r   )r  r   )r  ro   )Nr   r   r	   r	   )F)r  Expr | None)NF)FTT)r	   FT)r,  r9   )rw   r9   r  r  rt  )r  ztuple[Expr, tuple[Expr, ...]])r  ztuple[Number, Expr])FT)r0   r9   r  r  )r  r  )r  zbool | None)Nr      r  Nr   )Nr  r   F)Nr   r  Nr   r   )r  )r@  r  r  tuple['Number', Expr])r  r  )Nr   r	   Tr  TF)TNTTTTTT)r;   NF)FF)NTFT)__name__
__module____qualname____firstlineno____doc__r<   __annotations__r   r@   r   rH   rS   r\   rV   	is_scalarpropertyr`   r   rm   r}   _op_priorityr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  staticmethodr-  r   r;  rU  rm  r   r  r  r  r  r  r  r  r  r  r  r  r  classmethodr  rs   r  rq   r  r6  r9  rE  rH  rU  r-   r  r  ru  r   r  r  rh   r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  r  r  r$  r#  rD  rE  rj  rm  rK  rr  rG  r  r\  r  rY  r  rf   r  r  r  re  r  r  r  r  rp  r  r:  r  r  r  r  r  r|  r  r  r0  r  r  r   	__round__r  __static_attributes____classcell__r#  s   @r5   r9   r9   .   sD   , "$I#	 
d 
d	{ 
{	O 
O	u 
u	} 
}	a 
a 15	-	@C	HM		 PTGL;@		)-	?C	"	48	EI	
 I( (T !2 !2F, L   8 &'8:&  ' 9  &'89%  & 9  &'8:&! ' 9! &'89%! & 9! &'8:&  ' 9  &'89%  & 9  &'8:&  ' 9 &  &'89%  & 9  &'8>*$ + 9$ &'8=)% * 9% &'8:&  ' 9  &'89%  & 9  &'8?+# , 9# &'8>*# + 9#
 &'8=)5 * 95 &'8<(5 ) 954	>-
 &'8( 9( &'8% 9% &'8. 9. &'8+ 9+!
/ 	C 	C 17 17f  DL\XHtOb%NGHOb

".$"  8 D41l4l,A\'=~Zx(DL}:~(:&4l!F"H47r (KZ]~ C C<<KZH.T:5x;/z22hKXZb*JYI(:ADF ) -1 "I "IH
8 FJ
C,C+  : IM8<Y Y~0
;
?
Q
/
&

&
'
.


+
+
.X$t IQ Qr7   r9   c                  p   ^  \ 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 rSS jr\S 5       rSrU =r$ )
AtomicExpri  z
A parent class for object which are both atoms and Exprs.

For example: Symbol, Number, Rational, Integer, ...
But not: Add, Mul, Pow, ...
FTr;   c                L    X:X  a  [         R                  $ [         R                  $ r*   )r   rk   r  )rE   r  s     r5   r
  AtomicExpr._eval_derivative  s    955Lvvr7   c                   > SSK Jn  SSKJn  SSKJn  [        XU[        U45      (       a  [        TU ]%  X5      $ SSK
Jn  SSKJn  X:X  a  U" X" US5      4SU" US5      4S5      $ U" X" US5      4S5      $ )	Nr	   )Tupler   )
MatrixExpr)
MatrixBase)Eq)	Piecewise)r   T)
containersr)  r	  r*  sympy.matrices.matrixbaser+  r  r   r  _eval_derivative_n_timesr  r,  $sympy.functions.elementary.piecewiser-  )	rE   r  rV   r)  r*  r+  r,  r-  r#  s	           r5   r0  #AtomicExpr._eval_derivative_n_times  sw    %A8aeXzBCC73A99"B9dBq!H-2a8}iHHdBq!H-y99r7   c                    gr  r;   r  s     r5   r
  AtomicExpr._eval_is_polynomial      r7   c                    U [         ;  $ r*   )r  r  s     r5   r  %AtomicExpr._eval_is_rational_function  s    8##r7   c                    SSK Jn  U R                  (       + =(       d    U R                  =(       a    [	        X5      (       + $ )Nr   r  )r  r  r   	is_finiter  )rE   r,  rO  r  s       r5   r  AtomicExpr._eval_is_meromorphic  s(    ANN"4dnn[j>[:[[r7   c                    gr  r;   r  s     r5   r#  "AtomicExpr._eval_is_algebraic_expr  r5  r7   c                    U $ r*   r;   ru  s        r5   rG  AtomicExpr._eval_nseries  r   r7   c                    [        SSSS9  U 1$ )Nr  r  r  r  r   r_   s    r5   r  AtomicExpr.expr_free_symbols  s!    ! # &+'E	G vr7   )r   )r  r  r  r  r  r   rn   r<   r
  r0  r
  r  r  r#  rG  r  r  r!  r"  r#  s   @r5   r%  r%    sQ     IGI
:$\  r7   r%  c                   SSK JnJnJn  [	        U R                  5       5      nU(       d  [        R                  $  [        U" U" U5      5      5      nU[        S5      U-  -  S:  a&  SU[        S5      U-  -  s=::  a  S:  d   e   eUS-  nU$ ! [        [        4 a:    [        U" [        [        UR                  S5      5      U" S5      -  5      5      n Nf = f)zReturn integer $i$ such that $0.1 \le x/10^i < 1$

Examples
========

>>> from sympy.core.expr import _mag
>>> from sympy import Float
>>> _mag(Float(.1))
0
>>> _mag(Float(.01))
-1
>>> _mag(Float(1234))
4
r   )log10ceilr  5   r  r	   )mathrB  rC  r  rH  rV   r   r  r   r   OverflowErrorr)  r"   r&  )r,  rB  rC  r  r4  mag_first_digs         r5   r  r    s     &%qssu:DvvJDt-. 	QrUM!!a'T!B%..4"44444 & JDwtzz2'>!?B!GHIJs   B ACCc                  $    \ rS rSrSrS rS rSrg)UnevaluatedExpri  z
Expression that is not evaluated unless released.

Examples
========

>>> from sympy import UnevaluatedExpr
>>> from sympy.abc import x
>>> x*(1/x)
1
>>> x*UnevaluatedExpr(1/x)
x*1/x

c                J    [        U5      n[        R                  " X40 UD6nU$ r*   )r   r9   r@   )r>   ry   rL   r2  s       r5   r@   UnevaluatedExpr.__new__  s#    smll3.v.
r7   c                    UR                  SS5      (       a  U R                  S   R                  " S0 UD6$ U R                  S   $ )Nr  Tr   r;   )ra  r?   rI  )rE   r  s     r5   rI  UnevaluatedExpr.doit  s=    99VT""99Q<$$-u--99Q<r7   r;   N)r  r  r  r  r  r@   rI  r!  r;   r7   r5   rI  rI    s    
 r7   rI  c                V    U " U6 nUR                   U :H  =(       a    UR                  U:H  $ )aw  Return True if `func` applied to the `args` is unchanged.
Can be used instead of `assert foo == foo`.

Examples
========

>>> from sympy import Piecewise, cos, pi
>>> from sympy.core.expr import unchanged
>>> from sympy.abc import x

>>> unchanged(cos, 1)  # instead of assert cos(1) == cos(1)
True

>>> unchanged(cos, pi)
False

Comparison of args uses the builtin capabilities of the object's
arguments to test for equality so args can be defined loosely. Here,
the ExprCondPair arguments of Piecewise compare as equal to the
tuples that can be used to create the Piecewise:

>>> unchanged(Piecewise, (x, x > 1), (0, True))
True
)r  r?   )r  r?   r  s      r5   	unchangedrO  	  s(    2 	dA66T>,affn,r7   c                  Z    \ rS rSrSS jr\S 5       rS rSS jrSS jr	S r
S	 rS
 rSrg)ExprBuilderi&  Nc                    [        US5      (       d  [        SR                  U5      5      eXl        Uc  / U l        OX l        X0l        Ub  U(       a  U R                  5         g g g )N__call__zop {} needs to be callable)r(  r   r  opr?   	validatorvalidate)rE   rT  r?   rU  checks        r5   __init__ExprBuilder.__init__'  sZ    r:&&8??CDD<DII"!uMMO (-!r7   c                |    U  Vs/ s H*  n[        U[        5      (       a  UR                  5       OUPM,     sn$ s  snf r*   )r  rQ  build)r?   r3   s     r5   _build_argsExprBuilder._build_args3  s1    HLM1Z;77	Q>MMMs   19c                t    U R                   c  g U R                  U R                  5      nU R                   " U6   g r*   )rU  r\  r?   )rE   r?   s     r5   rV  ExprBuilder.validate7  s/    >>!		*r7   c                    U R                  U R                  5      nU R                  (       a  U(       a  U R                  " U6   U R                  " U6 $ r*   )r\  r?   rU  rT  )rE   rW  r?   s      r5   r[  ExprBuilder.build=  s9    		*>>eNND!ww~r7   c                    U R                   R                  U5        U R                  (       a"  U(       a  U R                  " U R                   6   g g g r*   )r?   r.   rU  rV  )rE   ry   rW  s      r5   append_argumentExprBuilder.append_argumentC  s4    		>>eMM499% $>r7   c                J    US:X  a  U R                   $ U R                  US-
     $ )Nr   r	   )rT  r?   )rE   items     r5   __getitem__ExprBuilder.__getitem__H  s%    1977N99T!V$$r7   c                4    [        U R                  5       5      $ r*   )ro   r[  r_   s    r5   __repr__ExprBuilder.__repr__N  s    4::<  r7   c                    [        U R                  5       HU  u  p#[        U[        5      (       a  UR	                  U5      nUb  U4U-   s  $ M8  [        U5      [        U5      :X  d  MR  U4s  $    g r*   )r,  r?   r  rQ  search_indexid)rE   elemr3   ry   rets        r5   search_elementExprBuilder.search_elementQ  sf    		*FA#{++&&t,?4#:% #CBtH$t + r7   )r?   rT  rU  )NNTrt  )r  r  r  r  rX  r  r\  rV  r[  rc  rg  rj  rq  r!  r;   r7   r5   rQ  rQ  &  s;    
 N N&
%!r7   rQ  r   r   r   )rj   r  r   )r  )r)  r  rH  r  r   )S
__future__r   typingr   r   collections.abcr   r   	functoolsr   r   r
   r   r  r   r   	singletonr   r\   r   r   r   
decoratorsr   r   r   cacher   logicr   r   intfuncr   sortingr   rc  r   sympy.utilities.exceptionsr   sympy.utilities.miscr   r   r   sympy.utilities.iterablesr    r!   mpmath.libmpr"   r#   mpmath.libmp.libintmathr$   r%   typing_extensionsr&   r  r'   collectionsr(   r6   r9   r%  r  rI  rO  rQ  r  r   r)  r+   r   r   rI  rj   r  r   r   r(  r  r)  r  rH  r  r   r;   r7   r5   <module>r     s    " * -  	 &   < < R R  &   %  @ > > 7 - / & #
 c=Q5* c=Q c=QL{6t 6r< d  :-:3 3l    4  # C Cr7   