K iJU2ddlmZddlmZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZmZdd lmZdd lmZmZdd lmZdd lmZdd lmZmZddlm Z ddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'ddl(m)Z)dZ*dddZ+GddeZ,Gdde,Z-y))Add)Tuple)Expr) AppliedUndefUndefinedFunction)Mul)Equality Relational)S)SymbolDummy)sympify)piecewise_fold Piecewise)BooleanFunction) MatrixBase)IntervalSet)Range)Idx)flatten)sift is_sequence)sympy_deprecation_warningcft|}t|trit|d|i\}}|rt d|Dst dddd|j }|j}t||g|i|||g|i|S|tjurtjS|rWt|d|i\}}t|D]:\} } t| dk(s|j| d | d }t| d d || <<nC|j} t| d k7rtd |z| D cgc] } t| c} d }}|t!|k(r3t#|j$|z}|j&}|t!|k(r3i} |D chc]} | d  }} |j)t*D]}|j,|rt/| |<!|j1| }t3|}|j1| j5Dcic]\}}|| c}}}|||fScc} wcc} wcc}}w)zReturn either a special return value or the tuple, (function, limits, orientation). This code is common to both ExprWithLimits and AddWithLimits.discretec38K|]}t|dk(ywNlen).0limits e/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/concrete/expr_with_limits.py z_common_new.. sC5s5zQCax Creating a indefinite integral with an Eq() argument is deprecated. This is because indefinite integrals do not preserve equality due to the arbitrary constants. If you want an equality of indefinite integrals, use Eq(Integral(a, x), Integral(b, x)) explicitly. z1.6z!deprecated-indefinite-integral-eq)deprecated_since_versionactive_deprecations_target stacklevelrNzspecify dummy variables for %s)r isinstancer _process_limitsallrlhsrhsr NaN enumerater!subsr free_symbols ValueErrortypelistlimitsfunctionatomsrhasr xreplaceritems)clsr;rsymbols assumptionsr: orientationr1r2ilifreesrepssymbols_of_integrationpkvs r$ _common_newrMsHx H(H%.wJJ 3CFCC %*/+N llllC9'9[9C9'9[9; ;155uu -wJJ v& ,EAr2w!|#==A27!2cr7Oq  , $$ t9>08;= =156AuQx6  h hoo&/$$ h  D,23qad33 ^^I &quu,-gDG  &Hh'H  4::*Q"41v{z!A$4GadH-'00aDHHadhh.AabE!e,#'001B1BQqTYYBQw!#R!"Q%7%77!"1!b2g]BqtGbL)I IA!"1!QZZ"QqTB)G GA.-5)::7:: #A!A$ .'!A$ U2SaD q6Q;t|!(8#r) " !AB%&IQ1=q&IIA1v!)S1TQYqy eQi0 qy%i5&/__iooB%#%>$qtrz:J*45\*]$]%#%>$qtrz:J*45]*^$^ eQi0 qyTQY1Q4< eI&67  eIqt&<= 3c'lBCCgSDj ; K'J&$-% $% $-% $%s0P$PP 8P/ P,+P,/ P;:P;ceZdZdZdZedZedZedZedZ edZ edZ ed Z d Z d Zed Zed Zy)ExprWithLimits)is_commutativecLddlm}t||g|dt||i|}t |t r|\}}}n|St d|Dr tdtj|fi|}|g} | j|t | |_ |j|_ |S)Nr)Productrc3DK|]}t|dk7xsd|vywrr r"ls r$r%z)ExprWithLimits.__new__..s$8As1v{'dai'8s z:ExprWithLimits requires values for lower and upper bounds.) sympy.concrete.productsrmrM issubclassr.tupleanyr7r__new__extend_argsrk) r@r;rArBrmprer:_objarglists r$ruzExprWithLimits.__new__s3#x>'>W->1<> c5 !"% HfaJ 88 8YZ Zll3.+.*v'N %44 c |jdS)a%Return the function applied across limits. Examples ======== >>> from sympy import Integral >>> from sympy.abc import x >>> Integral(x**2, (x,)).function x**2 See Also ======== limits, variables, free_symbols rrwselfs r$r;zExprWithLimits.functions"zz!}r|c.|jjSN)r;kindrs r$rzExprWithLimits.kinds}}!!!r|c |jddS)a+Return the limits of expression. Examples ======== >>> from sympy import Integral >>> from sympy.abc import x, i >>> Integral(x**i, (i, 1, 3)).limits ((i, 1, 3),) See Also ======== function, variables, free_symbols r-Nr~rs r$r:zExprWithLimits.limitss"zz!"~r|cF|jDcgc]}|d c}Scc}w)aReturn a list of the limit variables. >>> from sympy import Sum >>> from sympy.abc import x, i >>> Sum(x**i, (i, 1, 3)).variables [i] See Also ======== function, limits, free_symbols as_dummy : Rename dummy variables sympy.integrals.integrals.Integral.transform : Perform mapping on the dummy variable r)r:rrps r$ variableszExprWithLimits.variables s #kk*!***s cd|jDcgc]}t|dk7s|dc}Scc}w)aReturn only variables that are dummy variables. Examples ======== >>> from sympy import Integral >>> from sympy.abc import x, i, j, k >>> Integral(x**i, (i, 1, 3), (j, 2), k).bound_symbols [i, j] See Also ======== function, limits, free_symbols as_dummy : Rename dummy variables sympy.integrals.integrals.Integral.transform : Perform mapping on the dummy variable r-r)r:r!rs r$ bound_symbolszExprWithLimits.bound_symbolss*&#kk9SVq[!999s--cd|j|j}}|jDcic]+}|d|dj|dhk(r|dn t-}}|j |}|j}|D]d}||d}t |dk(r|j |+||vr|j||ddD]}|j|jf|jDcic]\}}|| }}}|D chc]} |j| | c} Scc}wcc}}wcc} w)a4 This method returns the symbols in the object, excluding those that take on a specific value (i.e. the dummy symbols). Examples ======== >>> from sympy import Sum >>> from sympy.abc import x, y >>> Sum(x, (x, y, 1)).free_symbols {y} rr-N) r;r:r6r r>r!addremoveupdater?get) rr;r:rDrHisymsxabrLrKrys r$r6zExprWithLimits.free_symbols1s2" ==$++&[["!ad//AaD69aduwF""$$T*%% -CSV A3x1} ! Ez QW - Q^^, - -"&.A1..(-.1A..!"/.s0D"2 D'D-c|j S)z7Return True if the Sum has no free symbols, else False.)r6rs r$ is_numberzExprWithLimits.is_numberWs$$$$r|c|jDcgc]}|d|k7r|n|||f}}|j}|j|g|Scc}w)Nr)r:r;func)rxabrDr: integrands r$_eval_intervalzExprWithLimits._eval_interval\sS;?;;Ga! 11ay0GGMM tyy,V,,HsAc N|jt|j}}|jt |t r&|j j|j rjd}t|D]\}}dt|k(r||dk(r|jr|f}n||f}t|dg|ddDcgc]}|j||c}||<t|dj j|j dk7sd}nt |ttfrt|j jt|j#t } t|j jt|j$} | j'| s t)dd}|rr|j+||}n_t|D]Q\}}t|dk(st|dg|ddDcgc]}|j||c}||<||dk(sQnt|D];\}}t|dk(s|d|dz j,s+t|d||<=|j|j.|g|Scc}wcc}w) a Perform substitutions over non-dummy variables of an expression with limits. Also, can be used to specify point-evaluation of an abstract antiderivative. Examples ======== >>> from sympy import Sum, oo >>> from sympy.abc import s, n >>> Sum(1/n**s, (n, 1, oo)).subs(s, 2) Sum(n**(-2), (n, 1, oo)) >>> from sympy import Integral >>> from sympy.abc import x, a >>> Integral(a*x**2, x).subs(x, 4) Integral(a*x**2, (x, 4)) See Also ======== variables : Lists the integration variables transform : Perform mapping on the dummy variable for integrals change_index : Perform mapping on the sum and product dummy variables Tr-rNFz-substitution cannot create dummy dependenciesrrP)r;r9r:reverser.r r6 intersectionr4r!rOr_subsrrsetrr<argsissubsetr7r5is_zeror) roldnewrr: sub_into_funcrDrrpsy2sy1s r$ _eval_subszExprWithLimits._eval_subsasd6}}d4;;&7f #v&  --d.?.?@ M#F+ 3C=SCF]}}"f"Cj!#a&Ps12w+O!AGGC,=+OPq s1v**778H8HIJaO$)M # .?@A$..)66s399V;L7MN$..)66s388}E||C($GII $ yyc*$F+ 3s8q= %c!f T3qr7/SaS0A/S TF1Ic!f}    ' ,FAs3x1}#a&3q6/!:!:!#a&Oq  , tyy'''9,P"0Ts 6J J" cd}|jD]b}t|dk(r@td|ddDrytd|ddDs>|djNd}Q|djad}d|ryy) a# Returns True if the limits are known to be finite, either by the explicit bounds, assumptions on the bounds, or assumptions on the variables. False if known to be infinite, based on the bounds. None if not enough information is available to determine. Examples ======== >>> from sympy import Sum, Integral, Product, oo, Symbol >>> x = Symbol('x') >>> Sum(x, (x, 1, 8)).has_finite_limits True >>> Integral(x, (x, 1, oo)).has_finite_limits False >>> M = Symbol('M') >>> Sum(x, (x, 1, M)).has_finite_limits >>> N = Symbol('N', integer=True) >>> Product(x, (x, 1, N)).has_finite_limits True See Also ======== has_reversed_limits Frc34K|]}|jywr is_infiniteros r$r%z3ExprWithLimits.has_finite_limits..s6q}}6r-Nc38K|]}|jduywrrros r$r%z3ExprWithLimits.has_finite_limits..s@1$.@r&rT)r:r!rtr)rret_Nonelims r$has_finite_limitsz ExprWithLimits.has_finite_limitssB;; $C3x1}6c!"g66 @AB@@1v))1#'q6%%-#H $ r|cd}|jD]:}t|dk(r)|\}}}||z }|jry|jr7d}:y|ryy)a Returns True if the limits are known to be in reversed order, either by the explicit bounds, assumptions on the bounds, or assumptions on the variables. False if known to be in normal order, based on the bounds. None if not enough information is available to determine. Examples ======== >>> from sympy import Sum, Integral, Product, oo, Symbol >>> x = Symbol('x') >>> Sum(x, (x, 8, 1)).has_reversed_limits True >>> Sum(x, (x, 1, oo)).has_reversed_limits False >>> M = Symbol('M') >>> Integral(x, (x, 1, M)).has_reversed_limits >>> N = Symbol('N', integer=True, positive=True) >>> Sum(x, (x, 1, N)).has_reversed_limits False >>> Product(x, (x, 2, N)).has_reversed_limits >>> Product(x, (x, 2, N)).subs(N, N + 2).has_reversed_limits False See Also ======== sympy.concrete.expr_with_intlimits.ExprWithIntLimits.has_empty_sequence FrTN)r:r!is_extended_negativeis_extended_nonnegative)rrrvarrrdifs r$has_reversed_limitsz"ExprWithLimits.has_reversed_limitssgJ;; C3x1} Q!e++00#H  r|N)__name__ __module__ __qualname__ __slots__rupropertyr;rr:rrr6rrrrrr|r$rjrjs#I,$""$++"::(#/#/J%%- M(^00d33r|rjc8eZdZdZdZdZdZdZdZdZ dZ y ) AddWithLimitszZRepresents unevaluated oriented additions. Parent class for Integral and Sum. rcddlm}t||g|dt||i|}t |t r|\}}}n|St j|fi|}||zg} | j|t | |_ |j|_ |S)Nr)Sumr) sympy.concrete.summationsrrMrrr.rsrrurvrwrk) r@r;rArBrrxr:rCrzr{s r$ruzAddWithLimits.__new__!s1#x:':S):-8: c5 !,/ )HfkJll3.+.x'(v'N %44 r|ctdt|jDr5|j|jj g|jSy)Nc34K|]}|jywris_realr"rs r$r%z.AddWithLimits._eval_adjoint..37Qqyy7r)r0rr:rr;adjointrs r$ _eval_adjointzAddWithLimits._eval_adjoint2sC 7'$++"67 7499T]]224Ct{{C Cr|ctdt|jDr5|j|jj g|jSy)Nc34K|]}|jywrrrs r$r%z0AddWithLimits._eval_conjugate..8rr)r0rr:rr; conjugaters r$_eval_conjugatezAddWithLimits._eval_conjugate7C 7'$++"67 7499T]]446EE Er|ctdt|jDr5|j|jj g|jSy)Nc34K|]}|jywrrrs r$r%z0AddWithLimits._eval_transpose..=rr)r0rr:rr; transposers r$_eval_transposezAddWithLimits._eval_transpose<rr|c dtjk(rujjdi|}|jrKt |j fd}t|djt|dgjzSSjjgjddj}|jjds1jdjdgj|zSt|tr-j|jdjSS)Nr-cf|jxr#tj|jz Sr)rkrrr6)wrs r$z,AddWithLimits._eval_factor..Es.13C3C4A/!..@@r|TFrr,r) r!r:r;factoris_Mulrrrrr=rdoitr.)rhintssummandouts` r$ _eval_factorzAddWithLimits._eval_factorAs* DKK *dmm**3U3G~~7<<*ABCIytyyc%j1A("[[("""  dii B Ab0ABIIKG;;t~~b12yyT[[_$56;;=gEEGS)yy$++b/:AACC r|c jjdi|}|jdd}|jrW|s|jrIj dur;t |jDcgc]}j|gj!c}St|tr|jfdS|jk7rj|gjSScc}w)NforceFc>j|gjSr)rr:)rrs r$rz2AddWithLimits._eval_expand_basic..Xsytyy/IT[[/Ir|r) r;expandris_Addrkrrrrr:r.r applyfunc)rrrrrDs` r$_eval_expand_basicz AddWithLimits._eval_expand_basicQs&$--&&// '5) NN)?)?''u4W\\J13t{{3JK K  ,$$%IJ J  %499W3t{{3 3 Ks+$C%N) rrr__doc__rrurrrrrrr|r$rrs,I"    r|r).sympy.core.addrsympy.core.containersrsympy.core.exprrsympy.core.functionrrsympy.core.mulrsympy.core.relationalr r sympy.core.singletonr sympy.core.symbolr r sympy.core.sympifyr$sympy.functions.elementary.piecewiserrsympy.logic.boolalgrsympy.matrices.matrixbasersympy.sets.setsrrsympy.sets.fancysetsrsympy.tensor.indexedrsympy.utilitiesrsympy.utilities.iterablesrrsympy.utilities.exceptionsrrMr/rjrrr|r$rsm' ?6"+&/0)&$#7@D)N(,gTPTPf ANAr|