K i׊ddlmZddlmZddlmZddlmZddlm Z ddl m Z m Z ddl mZddlmZdd lmZdd lmZmZdd lmZdd lmZmZmZdd lmZddlmZddl m!Z!m"Z"ddl#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+GddeZ,Gdde,eZ-Gdde,Z.Gdde.Z/Gdde.Z0Gdde,Z1d(d!Z2Gd"d#e,Z3Gd$d%e3Z4Gd&d'e3Z5y )))Basic)cacheit)Tuple)call_highest_priority)global_parameters) AppliedUndefexpandMul)Integer)Eq)S Singleton)ordered)DummySymbolWildsympify)Matrix)lcmfactor)Interval Intersection)Idx)flatten is_sequenceiterablecLeZdZdZdZdZedZdZe dZ e dZ e dZ e d Z e d Ze d Ze d Zed ZdZdZdZdZdZdZeddZdZeddZdZdZeddZdZ dZ!d!d Z"y)"SeqBasezBase class for sequencesTc` |j}|S#t$rtj}Y|SwxYw)z[Return start (if possible) else S.Infinity. adapted from Set._infimum_key )startNotImplementedErrorrInfinity)exprr#s \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/series/sequences.py _start_keyzSeqBase._start_key s6  JJE # JJE  s --crt|j|j}|j|jfS)zTReturns start and stop. Takes intersection over the two intervals. )rintervalinfsup)selfotherr*s r'_intersect_intervalzSeqBase._intersect_interval,s+   u~~>||X\\))ctd|z)z&Returns the generator for the sequencez(%s).genr$r-s r'genz SeqBase.gen4s"*t"344r0ctd|z)z-The interval on which the sequence is definedz (%s).intervalr2r3s r'r*zSeqBase.interval9s"/D"899r0ctd|z):The starting point of the sequence. This point is includedz (%s).startr2r3s r'r#z SeqBase.start>s","566r0ctd|z)z8The ending point of the sequence. This point is includedz (%s).stopr2r3s r'stopz SeqBase.stopCs"+"455r0ctd|z)zLength of the sequencez (%s).lengthr2r3s r'lengthzSeqBase.lengthHs"-$"677r0cy)z-Returns a tuple of variables that are boundedr=r3s r' variableszSeqBase.variablesMsr0c|jDchc].}|jj|jD]}|0c}}Scc}}w)aG 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 SeqFormula >>> from sympy.abc import n, m >>> SeqFormula(m*n**2, (n, 0, 5)).free_symbols {m} )args free_symbols differencer>)r-ijs r'rAzSeqBase.free_symbolsRsF!II0qq~~Jt~~.0!00 10s3Ac||jks||jkDrtd|d|j|j |S)z#Returns the coefficient at point ptzIndex z out of bounds )r#r9 IndexErrorr* _eval_coeffr-pts r'coeffz SeqBase.coeffcs>  ?b499nB NO O##r0c2td|jz)NzhThe _eval_coeff method should be added to%s to return coefficient so it is availablewhen coeff calls it.)r$funcrHs r'rGzSeqBase._eval_coeffjs"!#9%)II#./ /r0c|jtjur |j}n |j}|jtjurd}nd}|||zzS)aReturns the i'th point of a sequence. Explanation =========== If start point is negative infinity, point is returned from the end. Assumes the first point to be indexed zero. Examples ========= >>> from sympy import oo >>> from sympy.series.sequences import SeqPer bounded >>> SeqPer((1, 2, 3), (-10, 10))._ith_point(0) -10 >>> SeqPer((1, 2, 3), (-10, 10))._ith_point(5) -5 End is at infinity >>> SeqPer((1, 2, 3), (0, oo))._ith_point(5) 5 Starts at negative infinity >>> SeqPer((1, 2, 3), (-oo, 0))._ith_point(5) -5 )r#rNegativeInfinityr9)r-rCinitialsteps r' _ith_pointzSeqBase._ith_pointpsT@ ::++ +iiGjjG ::++ +DD4r0cy)aI Should only be used internally. Explanation =========== self._add(other) returns a new, term-wise added sequence if self knows how to add with other, otherwise it returns ``None``. ``other`` should only be a sequence object. Used within :class:`SeqAdd` class. Nr=r-r.s r'_addz SeqBase._addr0cy)aS Should only be used internally. Explanation =========== self._mul(other) returns a new, term-wise multiplied sequence if self knows how to multiply with other, otherwise it returns ``None``. ``other`` should only be a sequence object. Used within :class:`SeqMul` class. Nr=rUs r'_mulz SeqBase._mulrWr0ct||S)a Should be used when ``other`` is not a sequence. Should be defined to define custom behaviour. Examples ======== >>> from sympy import SeqFormula >>> from sympy.abc import n >>> SeqFormula(n**2).coeff_mul(2) SeqFormula(2*n**2, (n, 0, oo)) Notes ===== '*' defines multiplication of sequences with sequences only. r rUs r' coeff_mulzSeqBase.coeff_muls$4r0cht|tstdt|zt ||S)a4Returns the term-wise addition of 'self' and 'other'. ``other`` should be a sequence. Examples ======== >>> from sympy import SeqFormula >>> from sympy.abc import n >>> SeqFormula(n**2) + SeqFormula(n**3) SeqFormula(n**3 + n**2, (n, 0, oo)) zcannot add sequence and %s isinstancer TypeErrortypeSeqAddrUs r'__add__zSeqBase.__add__s0%)84;FG GdE""r0rbc ||zSNr=rUs r'__radd__zSeqBase.__radd__ e|r0cjt|tstdt|zt || S)a7Returns the term-wise subtraction of ``self`` and ``other``. ``other`` should be a sequence. Examples ======== >>> from sympy import SeqFormula >>> from sympy.abc import n >>> SeqFormula(n**2) - (SeqFormula(n)) SeqFormula(n**2 - n, (n, 0, oo)) zcannot subtract sequence and %sr]rUs r'__sub__zSeqBase.__sub__s2%)=U KL LdUF##r0rhc| |zSrdr=rUs r'__rsub__zSeqBase.__rsub__sr0c$|jdS)zNegates the sequence. Examples ======== >>> from sympy import SeqFormula >>> from sympy.abc import n >>> -SeqFormula(n**2) SeqFormula(-n**2, (n, 0, oo)) rN)r[r3s r'__neg__zSeqBase.__neg__s~~b!!r0cht|tstdt|zt ||S)a{Returns the term-wise multiplication of 'self' and 'other'. ``other`` should be a sequence. For ``other`` not being a sequence see :func:`coeff_mul` method. Examples ======== >>> from sympy import SeqFormula >>> from sympy.abc import n >>> SeqFormula(n**2) * (SeqFormula(n)) SeqFormula(n**3, (n, 0, oo)) zcannot multiply sequence and %s)r^r r_r`SeqMulrUs r'__mul__zSeqBase.__mul__s0%)=U KL LdE""r0roc ||zSrdr=rUs r'__rmul__zSeqBase.__rmul__rfr0c#Kt|jD]&}|j|}|j|(ywrd)ranger;rSrJ)r-rCrIs r'__iter__zSeqBase.__iter__s:t{{# !A#B**R.  !sAActt|tr"|j|}|j|St|trq|j |j }}|d}| |j}t|||jxsdDcgc]"}|j|j|$c}Sycc}w)NrrO) r^intrSrJslicer#r9r;rsrR)r-indexr#r9rCs r' __getitem__zSeqBase.__getitem__"s eS !OOE*E::e$ $ u %++uzz4E}|{{%uzzQ79qDJJtq129 9 & 9s 'B5Nc ddlm}|d|Dcgc]}|t|}}t|}||dz}nt ||dz}g} t d|dzD]} d| z} g} t | D]} | j || | | zt| }|jdk7sP||jt|| | }|| k(rt|ddd} nag} t | || z D]} | j || | | zt| }||zt|| dk(st|ddd} n|| St| } | dk(rgdfS|| dz || dz zzd| | dz || zzz }}t | dz D]Q}|||||zzz }t | |z dz D]}|| |||z|||zdzzzz}|| |||dzzzz}S| |t|t|z fScc}w)a Finds the shortest linear recurrence that satisfies the first n terms of sequence of order `\leq` ``n/2`` if possible. If ``d`` is specified, find shortest linear recurrence of order `\leq` min(d, n/2) if possible. Returns list of coefficients ``[b(1), b(2), ...]`` corresponding to the recurrence relation ``x(n) = b(1)*x(n-1) + b(2)*x(n-2) + ...`` Returns ``[]`` if no recurrence is found. If gfvar is specified, also returns ordinary generating function as a function of gfvar. Examples ======== >>> from sympy import sequence, sqrt, oo, lucas >>> from sympy.abc import n, x, y >>> sequence(n**2).find_linear_recurrence(10, 2) [] >>> sequence(n**2).find_linear_recurrence(10) [3, -3, 1] >>> sequence(2**n).find_linear_recurrence(10) [2] >>> sequence(23*n**4+91*n**2).find_linear_recurrence(10) [5, -10, 10, -5, 1] >>> sequence(sqrt(5)*(((1 + sqrt(5))/2)**n - (-(1 + sqrt(5))/2)**(-n))/5).find_linear_recurrence(10) [1, 1] >>> sequence(x+y*(-2)**(-n), (n, 0, oo)).find_linear_recurrence(30) [1/2, 1/2] >>> sequence(3*5**n + 12).find_linear_recurrence(20,gfvar=x) ([6, -5], 3*(5 - 21*x)/((x - 1)*(5*x - 1))) >>> sequence(lucas(n)).find_linear_recurrence(15,gfvar=x) ([1, 1], (x - 2)/(x**2 + x - 1)) r)simplifyNrOrN) sympy.simplifyr{r lenminrsappendrdetLUsolverr)r-ndgfvarr{txlxrcoeffsll2mlistkmyrCrDs r'find_linear_recurrencezSeqBase.find_linear_recurrence/sdD ,*.r( 3QXfQi 3 3 V 9AAAb!e Aq!A# A1BE1X ' Qq1X& 'u Auuw!|QYYva"g788$QttW-FqA+ALL1QqS*+5MQ3&23.($QttW-F# $ =MF AAv4x1veacl*Aqs E1H0D,D1qs0A1eQh&A"1Q3q5\;VAYqt^EAaCEN::;51Q3<//A 0 xq &)(;<<rArrJrGrSrVrYr[rbrrerhrjrlrorqrtryrr=r0r'r r sO"NL  *55::77668811  $ $ / * X   (#"9%&$"9%& "#$9%&! 9I=r0r c<eZdZdZedZedZdZdZy) EmptySequenceaRepresents an empty sequence. The empty sequence is also available as a singleton as ``S.EmptySequence``. Examples ======== >>> from sympy import EmptySequence, SeqPer >>> from sympy.abc import x >>> EmptySequence EmptySequence >>> SeqPer((1, 2), (x, 0, 10)) + EmptySequence SeqPer((1, 2), (x, 0, 10)) >>> SeqPer((1, 2)) * EmptySequence EmptySequence >>> EmptySequence.coeff_mul(-1) EmptySequence c"tjSrd)rEmptySetr3s r'r*zEmptySequence.intervals zzr0c"tjSrd)rZeror3s r'r;zEmptySequence.lengths vv r0c|S)"See docstring of SeqBase.coeff_mulr=)r-rJs r'r[zEmptySequence.coeff_muls r0ctgSrd)iterr3s r'rtzEmptySequence.__iter__s Bxr0N) rrrrrr*r;r[rtr=r0r'rrzs9(r0r) metaclasscpeZdZdZedZedZedZedZedZ edZ y) SeqExpraSequence expression class. Various sequences should inherit from this class. Examples ======== >>> from sympy.series.sequences import SeqExpr >>> from sympy.abc import x >>> from sympy import Tuple >>> s = SeqExpr(Tuple(1, 2, 3), Tuple(x, 0, 10)) >>> s.gen (1, 2, 3) >>> s.interval Interval(0, 10) >>> s.length 11 See Also ======== sympy.series.sequences.SeqPer sympy.series.sequences.SeqFormula c |jdSNrr@r3s r'r4z SeqExpr.gensyy|r0cZt|jdd|jddS)NrOr|)rr@r3s r'r*zSeqExpr.intervals' ! Q1a99r0c.|jjSrdr*r+r3s r'r#z SeqExpr.start}}   r0c.|jjSrdr*r,r3s r'r9z SeqExpr.stoprr0c:|j|jz dzSNrOr9r#r3s r'r;zSeqExpr.lengthyy4::%))r0c(|jddfS)NrOrrr3s r'r>zSeqExpr.variabless ! Q!!r0N) rrrrrr4r*r#r9r;r>r=r0r'rrs2::!!!!**""r0rcPeZdZdZd dZedZedZdZdZ dZ d Z y) SeqPera Represents a periodic sequence. The elements are repeated after a given period. Examples ======== >>> from sympy import SeqPer, oo >>> from sympy.abc import k >>> s = SeqPer((1, 2, 3), (0, 5)) >>> s.periodical (1, 2, 3) >>> s.period 3 For value at a particular point >>> s.coeff(3) 1 supports slicing >>> s[:] [1, 2, 3, 1, 2, 3] iterable >>> list(s) [1, 2, 3, 1, 2, 3] sequence starts from negative infinity >>> SeqPer((1, 2, 3), (-oo, 0))[0:6] [1, 2, 3, 1, 2, 3] Periodic formulas >>> SeqPer((k, k**2, k**3), (k, 0, oo))[0:6] [0, 1, 8, 3, 16, 125] See Also ======== sympy.series.sequences.SeqFormula Nct|}d}d\}}}|||dtj}}}t|tr0t |dk(r|\}}}nt |dk(r ||}|\}}t |ttfr||tdt|z|tjur|tjur tdt|||f}t|trttt|}ntd|zt|d |dtjurtj St#j$|||S) Nc|j}t|jdk(r|jStdS)NrOr)rAr~popr) periodicalfrees r'_find_xzSeqPer.__new__.._find_xs6**D:**+q0xxz!Sz!r0NNNrr|Invalid limits given: %sz/Both the start and end valuecannot be unboundedz6invalid period %s should be something like e.g (1, 2) rO)rrr%rrr~r^rr ValueErrorstrrPtuplerrrrr__new__)clsrlimitsrrr#r9s r'rzSeqPer.__new__sTZ(  "*5$ >$Z0!QZZduA vu %6{a!'5$V!J'$ t!fc]+u} 7#f+EF F A&& &41::+= "788!UD)* z5 ) wz':!; > F1Ivay )QZZ 7?? "}}S*f55r0c,t|jSrd)r~r4r3s r'periodz SeqPer.period+s488}r0c|jSrdr4r3s r'rzSeqPer.periodical/ xxr0c|jtjur|j|z |jz}n||jz |jz}|j |j |jd|Sr)r#rrPr9rrsubsr>)r-rIidxs r'rGzSeqPer._eval_coeff3se ::++ +99r>T[[0C ?dkk1Cs#(():B??r0cht|tr|j|j}}|j|j}}t ||}g}t |D]&}|||z} |||z} |j | | z(|j|\} } t||jd| | fSyzSee docstring of SeqBase._addrN r^rrrrrsrr/r> r-r.per1lper1per2lper2 per_lengthnew_perrele1ele2r#r9s r'rVz SeqPer._add: eV $//4;;%D**ELL%DUE*JG:& ,AIAItd{+ , 2259KE4'DNN1$5ud#CD D %r0cht|tr|j|j}}|j|j}}t ||}g}t |D]&}|||z} |||z} |j | | z(|j|\} } t||jd| | fSyzSee docstring of SeqBase._mulrNrrs r'rYz SeqPer._mulKrr0ct|}|jDcgc]}||z }}t||jdScc}wrrO)rrrr@)r-rJrpers r'r[zSeqPer.coeff_mul\s@"&//2Qq5y22c499Q<((3s Ard) rrrrrrrrrGrVrYr[r=r0r'rrsM.`&6P@E"E")r0rcFeZdZdZd dZedZdZdZdZ dZ d Z y) SeqFormulaaf Represents sequence based on a formula. Elements are generated using a formula. Examples ======== >>> from sympy import SeqFormula, oo, Symbol >>> n = Symbol('n') >>> s = SeqFormula(n**2, (n, 0, 5)) >>> s.formula n**2 For value at a particular point >>> s.coeff(3) 9 supports slicing >>> s[:] [0, 1, 4, 9, 16, 25] iterable >>> list(s) [0, 1, 4, 9, 16, 25] sequence starts from negative infinity >>> SeqFormula(n**2, (-oo, 0))[0:6] [0, 1, 4, 9, 16, 25] See Also ======== sympy.series.sequences.SeqPer NcPt|}d}d\}}}|||dtj}}}t|tr0t |dk(r|\}}}nt |dk(r ||}|\}}t |ttfr||tdt|z|tjur|tjur tdt|||f}t|d|dtjurtjStj |||S) Nc|j}t|dk(r|jS|s tdSt d|z)NrOrz specify dummy variables for %s. If the formula contains more than one free symbol, a dummy variable should be supplied explicitly e.g., SeqFormula(m*n**2, (n, 0, 5)))rAr~rrr)formulars r'rz#SeqFormula.__new__.._find_xsN''D4yA~xxz!Sz! Or0rrrr|rz0Both the start and end value cannot be unboundedrO)rrr%rrr~r^rrrrrPrrrrr)rrrrrr#r9s r'rzSeqFormula.__new__s'" *5$ >$W-q!**duA vu %6{a!'5$V!G$$ t!fc]+u} 7#f+EF F A&& &41::+= "788!UD)* F1Ivay )QZZ 7?? "}}S'622r0c|jSrdrr3s r'rzSeqFormula.formularr0cX|jd}|jj||Sr)r>rr)r-rIrs r'rGzSeqFormula._eval_coeffs' NN1 ||  B''r0ct|trn|j|jd}}|j|jd}}||j ||z}|j |\}}t||||fSyrr^rrr>rr/ r-r.form1v1form2v2rr#r9s r'rVzSeqFormula._addz eZ ( dnnQ&72E uq'92EejjR00G2259KE4gE4'89 9 )r0ct|trn|j|jd}}|j|jd}}||j ||z}|j |\}}t||||fSyrrrs r'rYzSeqFormula._mulrr0cht|}|j|z}t||jdSr)rrrr@)r-rJrs r'r[zSeqFormula.coeff_muls.,,&'499Q<00r0cbtt|jg|i||jdSr)rr rr@)r-r@kwargss r'r zSeqFormula.expands*&???1NNr0rd) rrrrrrrrGrVrYr[r r=r0r'rrcs<&P%3N(::1 Or0rceZdZdZddZedZedZedZedZ edZ ed Z ed Z ed Z ed Zd ZdZy) RecursiveSeqa A finite degree recursive sequence. Explanation =========== That is, a sequence a(n) that depends on a fixed, finite number of its previous values. The general form is a(n) = f(a(n - 1), a(n - 2), ..., a(n - d)) for some fixed, positive integer d, where f is some function defined by a SymPy expression. Parameters ========== recurrence : SymPy expression defining recurrence This is *not* an equality, only the expression that the nth term is equal to. For example, if :code:`a(n) = f(a(n - 1), ..., a(n - d))`, then the expression should be :code:`f(a(n - 1), ..., a(n - d))`. yn : applied undefined function Represents the nth term of the sequence as e.g. :code:`y(n)` where :code:`y` is an undefined function and `n` is the sequence index. n : symbolic argument The name of the variable that the recurrence is in, e.g., :code:`n` if the recurrence function is :code:`y(n)`. initial : iterable with length equal to the degree of the recurrence The initial values of the recurrence. start : start value of sequence (inclusive) Examples ======== >>> from sympy import Function, symbols >>> from sympy.series.sequences import RecursiveSeq >>> y = Function("y") >>> n = symbols("n") >>> fib = RecursiveSeq(y(n - 1) + y(n - 2), y(n), n, [0, 1]) >>> fib.coeff(3) # Value at a particular point 2 >>> fib[:6] # supports slicing [0, 1, 1, 2, 3, 5] >>> fib.recurrence # inspect recurrence Eq(y(n), y(n - 2) + y(n - 1)) >>> fib.degree # automatically determine degree 2 >>> for x in zip(range(10), fib): # supports iteration ... print(x) (0, 0) (1, 1) (2, 1) (3, 2) (4, 3) (5, 5) (6, 8) (7, 13) (8, 21) (9, 34) See Also ======== sympy.series.sequences.SeqFormula Nct|tstdj|t|tr |j stdj||j |fk7r td|j}td|f}d}|j|} | D]} t| j dk7r td| j dj||z|} | jr| jr| dkstd j| | |kDs| }|s0t|Dcgc]}td j|}}t||k7r t!d t#|}t%|}t'd |D}t j(||||||} t+|D cic]\}} |||z| c} }| _|| _| Scc}wcc} }w) NzErecurrence sequence must be an applied undefined function, found `{}`z0recurrence variable must be a symbol, found `{}`z)recurrence sequence does not match symbolr)excluderrOz)Recurrence should be in a single variablezDRecurrence should have constant, negative, integer shifts (found {})zc_{}z)Number of initial terms must equal degreec32K|]}t|ywrdr).0rs r' z'RecursiveSeq.__new__..Os6'!*6s)r^rr_formatr is_symbolr@rLrfindr~match is_constant is_integerrsrrr rrr enumeratecachedegree)r recurrenceynrrQr#rrrprev_ysprev_yshiftseqinits r'rzRecursiveSeq.__new__#s"l+++16":7 7!U#1;;++16!96 6 77qd?GH H GG qd # //!$ F6;;1$ KLLKKN((Q/2E%%'E,<,<!..4fVn>>v 8=f F1uV]]1-.FGF w<6 !HI I6g67mmCRGUC7@7IJGAtQuqy\4'J   GKs !G<Hc |jdSzEquation defining recurrence.rrr3s r' _recurrencezRecursiveSeq._recurrenceXyy|r0cHt|j|jdSr )r rr@r3s r'rzRecursiveSeq.recurrence]s$''499Q<((r0c |jdS)z*Applied function representing the nth termrOrr3s r'rzRecursiveSeq.ynbr r0c.|jjS)z3Undefined function for the nth term of the sequence)rrLr3s r'rzRecursiveSeq.ygsww||r0c |jdS)zSequence index symbolr|rr3s r'rzRecursiveSeq.nlr r0c |jdS)z"The initial values of the sequencerrr3s r'rQzRecursiveSeq.initialqr r0c |jdS)r7rr3s r'r#zRecursiveSeq.startvr r0c"tjS)z&The ending point of the sequence. (oo))rr%r3s r'r9zRecursiveSeq.stop{szzr0c:|jtjfS)z&Interval on which sequence is defined.)r#rr%r3s r'r*zRecursiveSeq.intervals AJJ''r0c ||jz t|jkr|j|j|St t|j|dzD]q}|j|z}|j j |j|i}|j |j}||j|j|<s|j|j|jzSr)r#r~rrrsr xreplacer)r-rxcurrent seq_indexcurrent_recurrencenew_terms r'rGzRecursiveSeq._eval_coeffs 4:: DJJ /::dffUm, ,S_eai8 5G W,I!%!1!1!:!:DFFI;N!O )224::>H,4DJJtvvi( ) 5zz$&&g!5677r0c#VK|j} |j||dz }wr)r#rG)r-rxs r'rtzRecursiveSeq.__iter__s1 ""5) ) QJEs')r)rrrrrrr rrrrrQr#r9r*rGrtr=r0r'rrsJX3j))(( 8r0rNcht|}t|tr t||St ||S)a Returns appropriate sequence object. Explanation =========== If ``seq`` is a SymPy sequence, returns :class:`SeqPer` object otherwise returns :class:`SeqFormula` object. Examples ======== >>> from sympy import sequence >>> from sympy.abc import n >>> sequence(n**2, (n, 0, 5)) SeqFormula(n**2, (n, 0, 5)) >>> sequence((1, 2, 3), (n, 0, 5)) SeqPer((1, 2, 3), (n, 0, 5)) See Also ======== sympy.series.sequences.SeqPer sympy.series.sequences.SeqFormula )rrrrr)rrs r'sequencers14 #,C3c6""#v&&r0cpeZdZdZedZedZedZedZedZ edZ y) SeqExprOpa Base class for operations on sequences. Examples ======== >>> from sympy.series.sequences import SeqExprOp, sequence >>> from sympy.abc import n >>> s1 = sequence(n**2, (n, 0, 10)) >>> s2 = sequence((1, 2, 3), (n, 5, 10)) >>> s = SeqExprOp(s1, s2) >>> s.gen (n**2, (1, 2, 3)) >>> s.interval Interval(5, 10) >>> s.length 6 See Also ======== sympy.series.sequences.SeqAdd sympy.series.sequences.SeqMul c:td|jDS)zjGenerator for the sequence. returns a tuple of generators of all the argument sequences. c34K|]}|jywrdrras r'rz SeqExprOp.gen..s.qQUU.)rr@r3s r'r4z SeqExprOp.gens .DII...r0c4td|jDS)zeSequence is defined on the intersection of all the intervals of respective sequences c34K|]}|jywrdr*r$s r'rz%SeqExprOp.interval..s)r-r%s r'r>zSeqExprOp.variabless*W499=aakk=>??=s7 c:|j|jz dzSrrr3s r'r;zSeqExprOp.lengthrr0N) rrrrrr4r*r#r9r>r;r=r0r'r!r!s0//>> !!!!@@**r0r!c,eZdZdZdZedZdZy)raaRepresents term-wise addition of sequences. Rules: * The interval on which sequence is defined is the intersection of respective intervals of sequences. * Anything + :class:`EmptySequence` remains unchanged. * Other rules are defined in ``_add`` methods of sequence classes. Examples ======== >>> from sympy import EmptySequence, oo, SeqAdd, SeqPer, SeqFormula >>> from sympy.abc import n >>> SeqAdd(SeqPer((1, 2), (n, 0, oo)), EmptySequence) SeqPer((1, 2), (n, 0, oo)) >>> SeqAdd(SeqPer((1, 2), (n, 0, 5)), SeqPer((1, 2), (n, 6, 10))) EmptySequence >>> SeqAdd(SeqPer((1, 2), (n, 0, oo)), SeqFormula(n**2, (n, 0, oo))) SeqAdd(SeqFormula(n**2, (n, 0, oo)), SeqPer((1, 2), (n, 0, oo))) >>> SeqAdd(SeqFormula(n**3), SeqFormula(n**2)) SeqFormula(n**3 + n**2, (n, 0, oo)) See Also ======== sympy.series.sequences.SeqMul c|jdtj}t|}fd|}|Dcgc]}|tj us|}}|stj St d|Dtjurtj S|rtj|Stt|tj}tj|g|Scc}w)Nevaluatect|tr3t|tr tt |j gS|gSt |rtt |gStdNz2Input must be Sequences or iterables of Sequences)r^r rasummapr@rr_arg_flattens r'r7z SeqAdd.__new__.._flatten sc#w'c6*s8SXX6;;5L}3x-r2267 7r0c34K|]}|jywrdr)r$s r'rz!SeqAdd.__new__..23!**3r&)getrr0listrrrrrareducerr r(rr)rr@rr0r%r7s @r'rzSeqAdd.__new__s::j*;*D*DEDz 7~88: $/ /$H  B#B#c@tfd|jDS)z9adds up the coefficients of all the sequences at point ptc3@K|]}|jywrd)rJ)rr%rIs r'rz%SeqAdd._eval_coeff..cs211772;2s)r3r@rHs `r'rGzSeqAdd._eval_coeffas2 222r0Nrrrrrrr<rGr=r0r'raras'8")H!0!0F3r0rac,eZdZdZdZedZdZy)rna'Represents term-wise multiplication of sequences. Explanation =========== Handles multiplication of sequences only. For multiplication with other objects see :func:`SeqBase.coeff_mul`. Rules: * The interval on which sequence is defined is the intersection of respective intervals of sequences. * Anything \* :class:`EmptySequence` returns :class:`EmptySequence`. * Other rules are defined in ``_mul`` methods of sequence classes. Examples ======== >>> from sympy import EmptySequence, oo, SeqMul, SeqPer, SeqFormula >>> from sympy.abc import n >>> SeqMul(SeqPer((1, 2), (n, 0, oo)), EmptySequence) EmptySequence >>> SeqMul(SeqPer((1, 2), (n, 0, 5)), SeqPer((1, 2), (n, 6, 10))) EmptySequence >>> SeqMul(SeqPer((1, 2), (n, 0, oo)), SeqFormula(n**2)) SeqMul(SeqFormula(n**2, (n, 0, oo)), SeqPer((1, 2), (n, 0, oo))) >>> SeqMul(SeqFormula(n**3), SeqFormula(n**2)) SeqFormula(n**5, (n, 0, oo)) See Also ======== sympy.series.sequences.SeqAdd c|jdtj}t|}fd|}|stj St d|Dtjurtj S|rtj|Stt|tj}tj|g|S)Nr0ct|tr3t|tr tt |j gS|gSt |rtt |gStdr2)r^r rnr3r4r@rr_r5s r'r7z SeqMul.__new__.._flattensc#w'c6*s8SXX6;;5L#3x-r2267 7r0c34K|]}|jywrdr)r$s r'rz!SeqMul.__new__..r9r&)r:rr0r;rrrrrnr<rr r(rr)rr@rr0r7s @r'rzSeqMul.__new__s::j*;*D*DEDz 7~?? " 3d3 4 B?? " ==& &GD'"4"456}}S(4((r0cPd}|rst|D]b\}}d}t|D]G\}}||k(r |j|}| |Dcgc] }|||fvs | }}|j|n|s`|}n|rst|dk(r|j St |dScc}w)a.Simplify a :class:`SeqMul` using known rules. Explanation =========== Iterates through all pairs and ask the constituent sequences if they can simplify themselves with any other constituent. Notes ===== adapted from ``Union.reduce`` TFrOr>)rrYrr~rrnr?s r'r<z SeqMul.reduces #D/ Q 'o FCcz ffQiG*/3#G!qAA#G#G 0 #D " t9>88: $/ /$HrEcTd}|jD]}||j|z}|S)zrbs"$'734&$-&11&!#2$DD^=e^=@ "Gy"J0"g0"fN)WN)bqOqOfB7BJ'N7*7*tg3Yg3TqYqr0