K iHdZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl mZdd lmZdd lmZmZdd lmZdd lmZdd lmZmZddlmZmZddlmZddZ dZ!dZ"dZ#ddZ$y)zLimits of sequences)AccumulationBounds)Add) PoleError)Pow)S)Dummy)sympify) fibonacci) factorial subfactorial)gamma)Abs)MaxMin)cossin)LimitNct|}|W|j}t|dk(r|j}n,t|dk(rtj St d|zt|}|jdus|jdur t dt|dr|j||}|r|S|j|||z|z S)aDifference 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 rzqSince there is more than one variable in the expression, a variable must be supplied to take the difference of %sFzStep should be a finite number._eval_difference_delta) r free_symbolslenpoprZero ValueError is_number is_finitehasattrrsubs)exprnstepfresults [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/series/limitseq.pydifference_deltar&s0 4=Dy    q6Q;A Vq[66M:<@AB B 4=D ~~$..E"9:;;t-.,,Q5 M 99QD !D ((ctj|jd}|d}|g}|ddD]}||z }|j}||k(r|j }t ||}|y|j r|}|g}O|tjtjfvsr|j|t|dkDry|S)aFinds 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_argsexpand gammasimpfactor limit_seqis_zerorInfinityNegativeInfinityappendr) r r!termsterm0comptrels r%dominantr;Cs: MM$++4+0 1E "IE 7D 3BZ  !G KKM 6 A aO 9 YYE7D qzz1#5#56 6 KKN  4y1} Lr'c t||tjjdS#tt f$rYywxYw)NF)deep)rrr1doitNotImplementedErrorr)r r!s r% _limit_infr@us?T1ajj)..E.::  +s *-??cBddlm}t|D] }|j|st |}||cS|j \}}|jr|js"t |j }||cSyfd||fD\}}||z j}|j|st |}||cS|j \}}t|}|yt|}|y||z j} y)NrSumc3RK|]}t|j ywN)r&r,).0r7r!s r% z_limit_seq..sH$QXXZ3Hs$') sympy.concrete.summationsrCrangehasr@as_numer_denomr>r-r;)r r!trialsrCir$numdens ` r% _limit_seqrP|s- 6]'xx}a(F! &&(Swwqz Q/F! Hc3ZHSc $$&xx}a(F! &&(SsA ;sA ;c $$&?'r'cddlm}:|j}t|dk(r|j n|s|St d|jvr|S|j ttj}|j ttt}tddd}tddd }tddd }d |jtD}t!fd |Ds|j#t$t&r|t)|j+|i||} | zt)|j+|i||} | | k7rW| j,r,| j,r t/t1| | t3| | Syt)|j+|i||} | | S|j4r?|j6D cgc]} t9| |} } t!d | Dryt;| S|j#|sGt)t=|j+|i||} | | j>rtj@Syyycc} w)aFinds 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 rrBNrzAExpression has more than one variable. Please specify a variable.r!T)integerpositive)oddrS)evenrSc3<K|]}|jywrE) as_base_exp)rFps r%rGzlimit_seq..s 7!ammo 7sc3bK|]&\}}|jxr|j(ywrE) is_negativerJ)rFbr9r!s r%rGzlimit_seq..s) :41aAMM &aeeAh & :s,/c3$K|]}|du ywrE)rFr$s r%rGzlimit_seq..s7f6T>7s)!rHrCrrrrrewriter r GoldenRatior r r ratomsranyrJrrrPxreplace is_comparablerrris_Addargsr/rrr0r)r r!rLrCfreen_n1n2powersL1L2termlimitslims ` r%r/r/s`.y   t9> AK:; ; $## # << 1== 1D << < 7D sD4 0B st ,B s -B8tzz# 7F :6 :: HHS#   q"g.F ; >DMM1b'2B?BRx##(8(8-c"bk3r2;GG  q"g.F ; ~ ;;=AYYGTia0GFG777F|##S2w!78"fEC3;;vv $/HsI )Nr)N)%__doc__!sympy.calculus.accumulationboundsrsympy.core.addrsympy.core.functionrsympy.core.powerrsympy.core.singletonrsympy.core.symbolrsympy.core.sympifyr %sympy.functions.combinatorial.numbersr (sympy.functions.combinatorial.factorialsr r 'sympy.functions.special.gamma_functionsr $sympy.functions.elementary.complexesr(sympy.functions.elementary.miscellaneousrr(sympy.functions.elementary.trigonometricrrsympy.series.limitsrr&r;r@rPr/r]r'r%rsO@) "#&;L94==%-)`/d"'J`r'