
    \hH                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  SS	KJr  SS
KJrJr  SSKJr  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 jr S r!S r"S r#SS jr$g)zLimits of sequences    )AccumulationBounds)Add)	PoleError)Pow)S)Dummy)sympify)	fibonacci)	factorialsubfactorial)gamma)Abs)MaxMin)cossin)LimitNc                    [        U 5      n UcY  U R                  n[        U5      S:X  a  UR                  5       nO-[        U5      S:X  a  [        R
                  $ [        SU -  5      e[        U5      nUR                  SL d  UR                  SL a  [        S5      e[        U S5      (       a  U R                  X5      nU(       a  U$ U R                  XU-   5      U -
  $ )a  Difference Operator.

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

Discrete analog of differential operator. Given a sequence x[n],
returns the sequence x[n + step] - x[n].

Examples
========

>>> from sympy import difference_delta as dd
>>> from sympy.abc import n
>>> dd(n*(n + 1), n)
2*n + 2
>>> dd(n*(n + 1), n, 2)
4*n + 6

References
==========

.. [1] https://reference.wolfram.com/language/ref/DifferenceDelta.html
   r   zqSince there is more than one variable in the expression, a variable must be supplied to take the difference of %sFzStep should be a finite number._eval_difference_delta)r	   free_symbolslenpopr   Zero
ValueError	is_number	is_finitehasattrr   subs)exprnstepfresults        M/var/www/auris/envauris/lib/python3.13/site-packages/sympy/series/limitseq.pydifference_deltar&      s    0 4=Dyq6Q;AVq[66M :<@A B B 4=D~~$..E"9:;;t-..,,Q5M99QD!D((    c                    [         R                  " U R                  SS95      nUS   nU/nUSS  H  nX5-  nUR                  5       nXv:X  a  UR	                  5       n[        Xq5      nUc    gUR                  (       a  UnU/nMT  U[        R                  [        R                  4;  d  Mz  UR                  U5        M     [        U5      S:  a  gU$ )a7  Finds the dominant term in a sum, that is a term that dominates
every other term.

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

If limit(a/b, n, oo) is oo then a dominates b.
If limit(a/b, n, oo) is 0 then b dominates a.
Otherwise, a and b are comparable.

If there is no unique dominant term, then returns ``None``.

Examples
========

>>> from sympy import Sum
>>> from sympy.series.limitseq import dominant
>>> from sympy.abc import n, k
>>> dominant(5*n**3 + 4*n**2 + n + 1, n)
5*n**3
>>> dominant(2**n + Sum(k, (k, 0, n)), n)
2**n

See Also
========

sympy.series.limitseq.dominant
T)funcNr   )r   	make_argsexpand	gammasimpfactor	limit_seqis_zeror   InfinityNegativeInfinityappendr   )	r    r!   termsterm0comptrels	            r%   dominantr;   C   s    : MM$++4+01E"IE7D3BZGKKM6
AaO9YYE7Dqzz1#5#566KKN  4y1}Lr'   c                 ~     [        X[        R                  5      R                  SS9$ ! [        [
        4 a     g f = f)NF)deep)r   r   r1   doitNotImplementedErrorr   )r    r!   s     r%   
_limit_infr@   u   s=    Tajj)..E.::+ s   &) <<c                 n  ^ SSK Jn  [        U5       GH  nU R                  U5      (       d  [	        U T5      nUb  Us  $ U R                  5       u  pgUR                  T5      (       a  UR                  T5      (       d#  [	        U R                  5       T5      nUb  Us  $   g U4S jXg4 5       u  pgXg-  R                  5       n U R                  U5      (       d  [	        U T5      nUb  Us  $ U R                  5       u  pg[        UT5      nUc    g [        UT5      nUc    g Xg-  R                  5       n GM!     g )Nr   Sumc              3   X   >#    U  H  n[        UR                  5       T5      v   M!     g 7fN)r&   r,   ).0r7   r!   s     r%   	<genexpr>_limit_seq.<locals>.<genexpr>   s"     HZ$QXXZ33Zs   '*)	sympy.concrete.summationsrC   rangehasr@   as_numer_denomr>   r-   r;   )r    r!   trialsrC   ir$   numdens    `      r%   
_limit_seqrQ   |   s   -6]xx}}a(F!&&(wwqzz		Q/F!HcZH	$$&xx}}a(F!&&(sA;sA;	$$&? r'   c                   ^ SSK Jn  Tc@  U R                  n[        U5      S:X  a  UR	                  5       mO&U(       d  U $ [        S5      eTU R                  ;  a  U $ U R                  [        [        R                  5      n U R                  [        [        [        5      n [        SSSS9n[        SSSS	9n[        SSSS
9nS U R                  [        5       5       n[!        U4S jU 5       5      (       d  U R#                  [$        [&        5      (       a  [)        U R+                  TU05      Xb5      n	U	bc  [)        U R+                  TU05      Xr5      n
X:w  aA  U	R,                  (       a/  U
R,                  (       a  [/        [1        X5      [3        X5      5      $ gO[)        U R+                  TU05      XR5      n	U	b  U	$ U R4                  (       aG  U R6                   Vs/ s H  n[9        UTU5      PM     nn[!        S U 5       5      (       a  g[;        U6 $ U R#                  U5      (       dL  [)        [=        U R+                  TU05      5      XR5      nUb"  UR>                  (       a  [        R@                  $ gggs  snf )a
  Finds the limit of a sequence as index ``n`` tends to infinity.

Parameters
==========

expr : Expr
    SymPy expression for the ``n-th`` term of the sequence
n : Symbol, optional
    The index of the sequence, an integer that tends to positive
    infinity. If None, inferred from the expression unless it has
    multiple symbols.
trials: int, optional
    The algorithm is highly recursive. ``trials`` is a safeguard from
    infinite recursion in case the limit is not easily computed by the
    algorithm. Try increasing ``trials`` if the algorithm returns ``None``.

Admissible Terms
================

The algorithm is designed for sequences built from rational functions,
indefinite sums, and indefinite products over an indeterminate n. Terms of
alternating sign are also allowed, but more complex oscillatory behavior is
not supported.

Examples
========

>>> from sympy import limit_seq, Sum, binomial
>>> from sympy.abc import n, k, m
>>> limit_seq((5*n**3 + 3*n**2 + 4) / (3*n**3 + 4*n - 5), n)
5/3
>>> limit_seq(binomial(2*n, n) / Sum(binomial(2*k, k), (k, 1, n)), n)
3/4
>>> limit_seq(Sum(k**2 * Sum(2**m/m, (m, 1, k)), (k, 1, n)) / (2**n*n), n)
4

See Also
========

sympy.series.limitseq.dominant

References
==========

.. [1] Computing Limits of Sequences - Manuel Kauers
r   rB   Nr   zAExpression has more than one variable. Please specify a variable.r!   T)integerpositive)oddrT   )evenrT   c              3   @   #    U  H  oR                  5       v   M     g 7frE   )as_base_exp)rF   ps     r%   rG   limit_seq.<locals>.<genexpr>   s     7!mmoos   c              3   p   >#    U  H+  u  pUR                   =(       a    UR                  T5      v   M-     g 7frE   )is_negativerK   )rF   br9   r!   s      r%   rG   rZ      s'     :641AMM&aeeAh&6s   36c              3   (   #    U  H  oS L v   M
     g 7frE    )rF   r$   s     r%   rG   rZ      s     7fT>s   )!rI   rC   r   r   r   r   rewriter
   r   GoldenRatior   r   r   r   atomsr   anyrK   r   r   rQ   xreplaceis_comparabler   r   r   is_Addargsr/   r   r   r0   r   )r    r!   rM   rC   freen_n1n2powersL1L2termlimitslims    `            r%   r/   r/      s   ` .y  t9>
AK : ; ;	
$##	#<<	1==1D<<	<7D	sD4	0B	st	,B	s	-B 8tzz#7F:6:::HHS#q"g.;>DMM1b'2B?Bx##(8(8-c"k3r;GGq"g.;	~	;;=AYYGYTia0YFG7777F|# #S2w!78"EC3;;vv $/  Hs   I7)Nr   )N   )%__doc__!sympy.calculus.accumulationboundsr   sympy.core.addr   sympy.core.functionr   sympy.core.powerr   sympy.core.singletonr   sympy.core.symbolr   sympy.core.sympifyr	   %sympy.functions.combinatorial.numbersr
   (sympy.functions.combinatorial.factorialsr   r   'sympy.functions.special.gamma_functionsr   $sympy.functions.elementary.complexesr   (sympy.functions.elementary.miscellaneousr   r   (sympy.functions.elementary.trigonometricr   r   sympy.series.limitsr   r&   r;   r@   rQ   r/   r_   r'   r%   <module>r      sO     @  )   " # & ; L 9 4 = = %-)`/d"'J`r'   