+
    ifL                         ^ RI HtHtHtHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHtHtHtHt ^ RIHt ^ RIHtHt ^ RIHt ^ RIHtHt  ! R	 R
]4      t]tR# )    )SsympifyExprDummyAddMul)cacheit)Tuple)Function	PoleErrorexpand_power_base
expand_logdefault_sort_key)explog)
Complement)uniqis_sequencec                      a  ] tR t^t o RtRtRt]R 4       tRR lt	]
R 4       t]
R 4       t]
R 4       t]
R 4       tR	 tR
 tR tR t]R 4       tR tR tR tR tR tR tRtV tR# )Ordera
  Represents the limiting behavior of some function.

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

The order of a function characterizes the function based on the limiting
behavior of the function as it goes to some limit. Only taking the limit
point to be a number is currently supported. This is expressed in
big O notation [1]_.

The formal definition for the order of a function `g(x)` about a point `a`
is such that `g(x) = O(f(x))` as `x \rightarrow a` if and only if there
exists a `\delta > 0` and an `M > 0` such that `|g(x)| \leq M|f(x)|` for
`|x-a| < \delta`.  This is equivalent to `\limsup_{x \rightarrow a}
|g(x)/f(x)| < \infty`.

Let's illustrate it on the following example by taking the expansion of
`\sin(x)` about 0:

.. math ::
    \sin(x) = x - x^3/3! + O(x^5)

where in this case `O(x^5) = x^5/5! - x^7/7! + \cdots`. By the definition
of `O`, there is a `\delta > 0` and an `M` such that:

.. math ::
    |x^5/5! - x^7/7! + ....| <= M|x^5| \text{ for } |x| < \delta

or by the alternate definition:

.. math ::
    \lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| < \infty

which surely is true, because

.. math ::
    \lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| = 1/5!


As it is usually used, the order of a function can be intuitively thought
of representing all terms of powers greater than the one specified. For
example, `O(x^3)` corresponds to any terms proportional to `x^3,
x^4,\ldots` and any higher power. For a polynomial, this leaves terms
proportional to `x^2`, `x` and constants.

Examples
========

>>> from sympy import O, oo, cos, pi
>>> from sympy.abc import x, y

>>> O(x + x**2)
O(x)
>>> O(x + x**2, (x, 0))
O(x)
>>> O(x + x**2, (x, oo))
O(x**2, (x, oo))

>>> O(1 + x*y)
O(1, x, y)
>>> O(1 + x*y, (x, 0), (y, 0))
O(1, x, y)
>>> O(1 + x*y, (x, oo), (y, oo))
O(x*y, (x, oo), (y, oo))

>>> O(1) in O(1, x)
True
>>> O(1, x) in O(1)
False
>>> O(x) in O(1, x)
True
>>> O(x**2) in O(x)
True

>>> O(x)*x
O(x**2)
>>> O(x) - O(x)
O(x)
>>> O(cos(x))
O(1)
>>> O(cos(x), (x, pi/2))
O(x - pi/2, (x, pi/2))

References
==========

.. [1] `Big O notation <https://en.wikipedia.org/wiki/Big_O_notation>`_

Notes
=====

In ``O(f(x), x)`` the expression ``f(x)`` is assumed to have a leading
term.  ``O(f(x), x)`` is automatically transformed to
``O(f(x).as_leading_term(x),x)``.

    ``O(expr*f(x), x)`` is ``O(f(x), x)``

    ``O(expr, x)`` is ``O(1)``

    ``O(0, x)`` is 0.

Multivariate O is also supported:

    ``O(f(x, y), x, y)`` is transformed to
    ``O(f(x, y).as_leading_term(x,y).as_leading_term(y), x, y)``

In the multivariate case, it is assumed the limits w.r.t. the various
symbols commute.

If no symbols are passed then all symbols in the expression are used
and the limit point is assumed to be zero.

Tc           	     r  a! \        V4      pV'       gc   VP                  '       d   VP                  pVP                  o!M\	        VP
                  4      p\        P                  .\        V4      ,          o!M\	        \        V4      '       d   TMV.4      p. . upo!\        V^ ,          4      '       dH   V F@  p\	        \        \         V4      4      w  rgVP                  V4       S!P                  V4       KB  	  M:\	        \        \         V4      4      p\        P                  .\        V4      ,          o!\        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        RV,          4      h\        \	        \        V4      4      4      \        V4      8w  d   \        RV,          4      hVP                  '       d   \!        VP"                  R,          4      p\!        V4      p	\!        \%        VS!4      4      p
V
P'                  4        F7  w  rgWiP)                  4       9   d   WyV,          8w  d   \+        R4      hK3  WyV&   K9  	  \-        VP)                  4       4      \-        V	P)                  4       4      8X  d   V# \	        V	P)                  4       4      pV Uu. uF  qiV,          NK  	  upo!V\        P.                  J d   \        P.                  # \0        ;QJ d    V!3R lV 4       F  '       g   K   RM	  RM! V!3R lV 4       4      '       d   \        R	S!,          4      hV'       Ed   \0        ;QJ d    V!3R
 lS! 4       F  '       g   K   RM	  RM! V!3R
 lS! 4       4      '       d   \+        R4      hS!^ ,          \        P2                  \        P2                  \        P4                  ,          39   dt   V Uu/ uF  q^\7        4       ,          bK  	  ppVP'                  4        UUu/ uF  w  r^V,          ^V,          bK  	  pppS! Uu. uF  p\        P                  NK  	  ppEMrS!^ ,          \        P8                  \        P8                  \        P4                  ,          39   ds   V Uu/ uF  qR\7        4       ,          bK  	  ppVP'                  4        UUu/ uF  w  rRV,          RV,          bK  	  pppS! Uu. uF  p\        P                  NK  	  ppMS!^ ,          \        P                  Jd   V Uu/ uF  q\7        4       S!^ ,          ,           bK  	  ppVP'                  4        UUu/ uF2  w  rVS!^ ,          ,
          P;                  4       VS!^ ,          ,
          bK4  	  pppS! Uu. uF  p\        P                  NK  	  ppMRpRp\	        S!4      pVP=                  V4      pVP>                  '       d   VPA                  4       pV'       d1   \C        VP'                  4        Uu. uF  q^ ,          NK  	  up4      pM\C        V4      p\        V4      ^8  d   VPE                  4       pRpVV8w  Ed   TpVP>                  '       d<   VPG                  V4      p\I        V UUu. uF  w  ppVPJ                  NK  	  upp!  pKW  V'       g   Ka   VPL                  ! V!  pVPb                  '       d   \        P                  pMVPd                  ! VRR/ ^,          p\g        V4      p\i        V4      p\        V4      ^8X  g   K  V^ ,          p\	        \X        Pj                  ! VPe                  VRR7      ^,          4      4      p\m        V4       EF  w  ppVPZ                  '       g   K  VP"                  w  ppVVV) 39   d8   VPn                  '       d&   VPq                  V4      '       g   VV,          VV&   Kk  VPZ                  '       df   VP\                  Pq                  V4      '       gE   VP"                  w  ppVVV) 39   d*   VPn                  '       d   VVV,          ,          VV&   K  K  K  VPV                  '       g   K  VP"                  ^ ,          \        Pr                  J g   EK  V) pVPZ                  '       g   EK6  VP\                  Pq                  V4      '       d   EKZ  VP"                  w  ppVVV) 39   g   EKv  VPn                  '       g   EK  VVV,          ,          VV&   EK  	  \Y        V!  pEK  VP=                  V4      pVP                  '       d   VPJ                  pVPp                  ! V!  '       g#   VPb                  '       g   \        Pt                  p\!        \%        VS!4      4      p
VPw                  \x        R7       V Uu. uF  qjV,          NK  	  upo!V3\{        \%        VS!4      !  ,           p\|        P~                  ! V .VO5!  p V # u upi u upi u uppi u upi u upi u uppi u upi u upi u uppi u upi u upi u uppi   \N         Ed    \Q        T\R        4      '       gO   \        ;QJ d&    R TP"                   4       F  '       d   K   RM	  RM! R TP"                   4       4      '       d    EL. p\C        \%        Y.4      4      pTP"                   FY  p TPL                  ! T!  pM  \N         d    Tp Mi ; iTT9  d   \U        T4      pM\U        T.TO5!  pTP                  T4       K[  	  TP>                  '       ds   \U        \I        T!  .TO5!  pTP>                  '       d>   \U        \I        TP"                   Uu. uF  qUPJ                  NK  	  Mu upi up!  .TO5!  pTPJ                  p ELTPV                  '       d,   \Y        T Uu. uF  qUPJ                  NK  	  Mu upi up!  p EL0TPZ                  '       d4   TP\                  pTP^                  p\]        T\a        T4      ,          4      p ELxi ; iu upi )r   c              3   8   "   T F  qP                   x  K  	  R # 5iN)	is_symbol).0vs   & r/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/series/order.py	<genexpr> Order.__new__.<locals>.<genexpr>   s     2	1;;	s   FTz!Variables are not symbols, got %sz3Variables are supposed to be unique symbols, got %s   NNz2Mixing Order at different points is not supported.c              3   R   <"   T F  pS F  q!VP                   9   x  K  	  K  	  R # 5ir   )free_symbols)r   xppoints   &  r   r   r       s!     EIqu!ANN"u"Is   $'zGot %s as a point.c              3   :   <"   T F  qS^ ,          8g  x  K  	  R# 5ir   N r   r&   r'   s   & r   r   r       s     0%Qa=%s   z;Multivariable orders at different points are not supported.Nc              3   B   "   T F  p\        V\        4      x  K  	  R # 5ir   )
isinstancer   )r   args   & r   r   r       s     #S#JsH$=$=s   as_Addr/   keyr*   )@r   is_Order	variablesr'   listr$   r   Zerolenr   mapappendall	TypeErrorr   
ValueErrordictargszipitemskeysNotImplementedErrorsetNaNanyInfinityImaginaryUnitr   NegativeInfinitytogethersubsis_Addfactortupleexpandextract_leading_orderr   expras_leading_termr   r-   r   r   is_Mulr   is_Powr   baser   is_zeroas_independentr   r   	make_args	enumerateis_realhasNegativeOneOnesortr   r
   r   __new__)"clsrQ   r?   kwargsr5   ar   r&   expr_vpnew_vpvpksrspsrold_exprlstefordersptsr.   ltordernew_exprbr%   margsitqobjr'   s"   &&*,                             @r   r_   Order.__new__   s   t}}}} NN	

 !2!23	Y/D 1 1v>D!2Iu47##AGQ0DA$$Q'LLO 
 !Wd!34	Y/s2	2sss2	222?)KLLtDO$%Y7RU^^__===499R=)G']Fc)U+,B
%1I~1PR R & !"1I # 7<<>"c&++-&88 /	,56IqI6155=55L3EIE333EIEEE1E9::9s0%0sss0%000)QS SQxAJJ

1??(BCC+459a%'	\95+,7795941ac1Q3h95&+,eaffe,qa00!2D2DQ__2TUU,56Iq57
]I6-.WWY7YTQbdBqDjY7&+,eaffe,q'4=>Iq%(**I>JK'')T)$!q58|--/U1X=)T&+,eaffe,%[99Q<D{{{{{}BHHJ7JqddJ78Y'9~! {{}Hd";;;44T:Cc :cFQc :;DT 7#33T:H ||| vv#22DGGJ,T2D%d+D4yA~ !G $S]] //%/@C&E !F %.e$4DAq xxx'(vv1#$QB<AIIIaeeAhh/0!tE!H%&XXXaeeiill+,66DAq'(QG|			34qs8a 9B|%&XXX!&&)q}}2L)*A'(xxx		!/0vv1+,QB<AIII781Q3xE!H %5   #E{99R=D===99Dxx##DLLL55D #i'(+, )*	1A	*wIu 566ll3&&
] 7 65,67,>T, 8" !;
 % 7%dH55 ##S#S#S#S S S !%'F"'D"6C'+yy!-),)<)<d)CB'0 !-),B!-#%T>,1"IE,1"OsOE &e 4 (1  ${{{+0f+D+D#+???/4S8==:Y=a66=:Y5Z/a]`/aH'/}}!%'*V,DVVVV,D'E!%$(HH$(II'*1s1v:=7d +s   *g5g:<g?hh
0hh!h8hh% h*=h/
(h5 ,p45,p1"p1 $p1(%p1kp1k/,p1.k//A	p19>p17np1+p1=	p1o
p1(p1:3p10p1c                    V # r   r*   )selfr%   nlogxcdirs   &&&&&r   _eval_nseriesOrder._eval_nseries>          c                (    V P                   ^ ,          # r   r?   r|   s   &r   rQ   
Order.exprA  s    yy|r   c                    V P                   R ,          '       dO   \        ;QJ d%    . R V P                   R ,           4       F  NK  	  5# ! R V P                   R ,           4       4      # R# )r!   c              3   2   "   T F  q^ ,          x  K  	  R# 5ir)   r*   r   r%   s   & r   r   "Order.variables.<locals>.<genexpr>H       5}!1}   r*   r?   rN   r   s   &r   r5   Order.variablesE  F    99R==55tyy}55555tyy}555Ir   c                    V P                   R ,          '       dO   \        ;QJ d%    . R V P                   R ,           4       F  NK  	  5# ! R V P                   R ,           4       4      # R# )r!   c              3   2   "   T F  q^,          x  K  	  R# 5ir"   Nr*   r   s   & r   r   Order.point.<locals>.<genexpr>O  r   r   r*   r   r   s   &r   r'   Order.pointL  r   r   c                b    V P                   P                  \        V P                  4      ,          # r   )rQ   r$   rD   r5   r   s   &r   r$   Order.free_symbolsS  s     yy%%DNN(;;;r   c                    VP                   '       dI   VP                  '       d7   V P                  ! V P                  V,          .V P                  R ,          O5!  # V\        ^4      8X  d   V # R# r!   N)	is_Numberis_nonnegativefuncrQ   r?   O)rt   rm   s   &&r   _eval_powerOrder._eval_powerW  sM    ;;;1+++66!&&A+3r
33!9Hr   c                $  a a Sf   S P                   R,          oEM_\        ;QJ d    V3R lS 4       F  '       d   K   RM	  RM! V3R lS 4       4      '       gq   \        ;QJ d)    V 3R lS P                   4       F  '       d   K   RM	  RM! V 3R lS P                   4       4      '       g   \        RS P                  ,          4      hS'       d2   S^ ,          ^,          S P                  ^ ,          8w  d   \        R4      h\	        S4      o\	        S P                   R,          4      P                  4        F!  w  r#VSP                  4       9  g   K  VSV&   K#  	  \        SP                  4       R R	7      oS P                  \        S4      3# )
Nr!   c              3   V   <"   T F  q^,          S^ ,          ^,          8H  x  K   	  R# 5ir   r*   )r   oorder_symbolss   & r   r   *Order.as_expr_variables.<locals>.<genexpr>b  s"     K]!a 0 33]s   &)FTc              3   N   <"   T F  qSP                   ^ ,          8H  x  K  	  R# 5ir)   )r'   )r   r&   r|   s   & r   r   r   c  s     C
1A.
   "%zDOrder at points other than 0 or oo not supported, got %s as a point.z7Multiplying Order at different points is not supported.c                 &    \        V ^ ,          4      # r   r   )r%   s   &r   <lambda>)Order.as_expr_variables.<locals>.<lambda>m  s    HXYZ[\Y]H^r   r1   )
r?   r;   r'   rC   r>   rA   rB   sortedrQ   rN   )r|   r   rg   r&   s   ff  r   as_expr_variablesOrder.as_expr_variables^  s"     IIbMMCK]KCCCK]KKKC

CC

CCC) +>@D

+K L Lq!1!!4

1!E)QS S /MTYYr]+113M..00'(M!$ 4 #=#6#6#8>^_Myy%...r   c                "    \         P                  # r   )r   r7   r   s   &r   removeOOrder.removeOp  s    vvr   c                    V # r   r*   r   s   &r   getO
Order.getOs  r   r   c                
  a aa \        S4      oSP                  '       d   R# S\        P                  J d   R# S P                  '       d   S P                  ^ ,          M\        P
                  oSP                  '       Ed   \        ;QJ d)    V3R lSP                   4       F  '       g   K   RM	  RM! V3R lSP                   4       4      '       gU   \        ;QJ d)    V3R lS P                   4       F  '       g   K   RM	  RM! V3R lS P                   4       4      '       d   R# SP                  S P                  8X  d]   \        ;QJ d0    V 3R lSP                  R,           4       F  '       d   K   R# 	  R# ! V 3R lSP                  R,           4       4      # SP                  P                  '       dc   \        ;QJ d3    V 3R lSP                  P                   4       F  '       d   K   R# 	  R# ! V 3R lSP                  P                   4       4      # S P                  P                  '       dw   SP                  '       de   \        ;QJ d4    VV 3R	 lS P                  P                   4       F  '       g   K   R# 	  R# ! VV 3R	 lS P                  P                   4       4      # S P                  '       dK   SP                  '       d9   \        S P                   Uu. uF  q"SP                  9   g   K  VNK  	  up4      pM+S P                  '       d   S P                  pMSP                  pV'       g   R# S P                  P                  '       Ed9   \        S P                  4      ^8X  Ed   S P                  SP                  8X  Ed   S P                  ^ ,          pSP                  P!                  VRR
7      ^,          pVP                  '       d   VP"                  V8X  d   S P                  P"                  V8X  d   SP                  '       d2   S P                  P$                  VP$                  ,
          P&                  pSP(                  '       d2   S P                  P$                  VP$                  ,
          P*                  pXe   V# ^ RIHp RpS P                  SP                  ,          p	V! V	RRR7      p	V FL  p^ RIHp
 V
! WS4      P5                  RR7      p\7        W4      '       g   V^ 8g  pMRpVf   TpKC  W8w  g   KK   R# 	  V# S P                  P                  '       Ed   \        S P                  4      ^8X  d   S P                  ^ ,          pSP!                  VRR
7      ^,          pVP                  '       d   VP"                  V8X  d   S P                  P"                  V8X  d   SP                  '       d2   S P                  P$                  VP$                  ,
          P&                  pSP(                  '       d2   S P                  P$                  VP$                  ,
          P*                  pXe   V# S P8                  ! S.S P                  R,          O5!  pS P;                  V4      # u upi )z
Return True if expr belongs to Order(self.expr, \*self.variables).
Return False if self belongs to expr.
Return None if the inclusion relation cannot be determined
(e.g. when self and expr have different symbols).
TFc              3   ,   <"   T F	  qS8g  x  K  	  R # 5ir   r*   r+   s   & r   r   !Order.contains.<locals>.<genexpr>  s     3
1J
   c              3   ,   <"   T F	  qS8g  x  K  	  R # 5ir   r*   r+   s   & r   r   r     s     6:aEz:r   Nc              3   N   <"   T F  qSP                   R ,          9   x  K  	  R# 5ir   r   r   r%   r|   s   & r   r   r     s     E}!		"-}r   r!   c              3   F   <"   T F  pSP                  V4      x  K  	  R # 5ir   )containsr   s   & r   r   r     s     D^4==++^s   !c              3      <"   T F9  pSP                   ! V.SP                  R ,          O5!  P                  S4      x  K;  	  R# 5ir   )r   r?   r   )r   r%   rQ   r|   s   & r   r   r     s<      5%3  99Q727@@FF%3s   AAr0   )powsimpr   )deepcombine)Limit)
heuristics)r   rV   r   rE   r'   r7   r4   rF   rQ   r;   r?   rL   r5   rN   rT   r8   rW   rU   r   is_nonpositiveis_infiniter   sympy.simplify.powsimpr   sympy.series.limitsr   doitr-   r   r   )r|   rQ   rg   common_symbolssymbolotherrvr   rj   ratior   lry   r'   s   ff           @r   r   Order.containsv  s@    t}<<<155=!%

1===3

33

333364::633364::666yyDII%sEtyy}EssEsEsEtyy}EEEyysDTYY^^DssDsDsDTYY^^DDDyyEMMMs 5%)YY^^5ss 5s 5s 5%)YY^^5 5 5~~~$...!& $F1t~~2EQQF"H!%!%!		   S%8A%=NNdnn4!^^A.F II44VE4J1MEv)=		&0$}}}&*iimmeii&?%O%O$000&*iimmeii&?%O%O!~')	6AIIdii'EEe<E#5%E*//5/A!!++QAA9Av $ H99DNN 3q 8^^A&F''u'=a@Ev!5		&(}}}"iimmeii7GG((("iimmeii7GG~!	ii-tyy}-}}S!!g Gs   )Z  Z c                F    V P                  V4      pVf   \        R4      hV# )Nz#contains did not evaluate to a bool)r   r<   )r|   r   results   && r   __contains__Order.__contains__  s&    u%>ABBr   c                F   WP                   9   Ed   V P                  P                  W4      pV P                   P                  V4      p\	        V P                   4      p\	        V P
                  4      pVP                  '       d   W%V&   EMVP                  p\        V4      ^8X  g   W9   Ed   W9   d   V P                   V,          pMVP                  4       p^ RI
Hp	 VP                  \        4      '       d   V	! VP                  4       P                  WP                  4       P
                  ^ ,          4      V P
                  V,          8X  d;   VP                  4       P
                  ^ ,          p
\        V.\        V.V
.4      O5!  # VP                  WP
                  V,          4      p
WP
                  V,          8w  d   ^ RIHp \%        4       pV! WP                  W4      ,
          V4      p\'        V\(        4      '       dB   VP*                  ^ ,          pVP*                  ^,          p\-        V4      \-        V4      ,
          p\/        \        V3V4      4      .pVP                  V^ ,          4      P                  WP
                  V,          4      p
WV&   WV&   MmW9  df   WT Wd V'       gY   W P
                  V,          8X  dB   VP1                  V4       VP1                  \2        P4                  .\        V4      ,          4       MR# \        V.\        WV4      O5!  # R# )r"   )limit)solvesetN)r5   rQ   rK   indexr6   r'   r   r$   r8   popsympyr   r[   r   r   r@   sympy.solvers.solvesetr   r   r-   r   r?   rD   r>   extendr   r7   )r|   oldnewnewexprrv   newvarsnewptsymsvarr   r'   r   dsole1e2ress   &&&              r   
_eval_subsOrder._eval_subs  s:   .. iinnS.G$$S)A4>>*G$E}}} 
''t9>S[{"nnQ/"hhj ,wwu~~%
hhjFVFVWXFY*Z^b^h^hij^k*k #
 0 0 3$WCsC55'/BCC #jjm <

1-C!G&sXXc-='=qA%c:66!$!B!$!B"%b'CG"3C#CsO45 !s1v 4 4S**Q- H!$AJ$!H_
EHC::a=$8t,affXc$i%7873w#677U !r   c                    V P                   P                  4       pVe&   V P                  ! V.V P                  R,          O5!  # R # Nr!   )rQ   _eval_conjugater   r?   r|   rQ   s   & r   r   Order._eval_conjugate  ;    yy((*99T2DIIbM22 r   c                    V P                   ! V P                  P                  V4      .V P                  R ,          O5!  ;'       g    T # )r!   )r   rQ   diffr?   )r|   r%   s   &&r   _eval_derivativeOrder._eval_derivative  s3    yy*;TYYr];CCtCr   c                    V P                   P                  4       pVe&   V P                  ! V.V P                  R,          O5!  # R # r   )rQ   _eval_transposer   r?   r   s   & r   r   Order._eval_transpose  r   r   c                    V # r   r*   r   s   &r   __neg__Order.__neg__  r   r   r*   Nr   )__name__
__module____qualname____firstlineno____doc__r4   	__slots__r	   r_   r   propertyrQ   r5   r'   r$   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r      s     pd HIy yv       < </$ N" N"`+8Z3
D3
 r   r   N)
sympy.corer   r   r   r   r   r   sympy.core.cacher	   sympy.core.containersr
   sympy.core.functionr   r   r   r   sympy.core.sortingr   &sympy.functions.elementary.exponentialr   r   sympy.sets.setsr   sympy.utilities.iterablesr   r   r   r   r*   r   r   <module>r     s9    8 8 $ ' R R / ; & 7}D }~ 
r   