+
    i׊                        ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
HtHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHtHt ^ RIHt ^ RIHtHtHt ^ RIHt ^ RIHt ^ RI H!t!H"t" ^ RI#H$t$H%t% ^ RI&H't' ^ RI(H)t)H*t*H+t+  ! R R]4      t, ! R R],]R7      t- ! R R],4      t. ! R R].4      t/ ! R R].4      t0 ! R R],4      t1R(R! lt2 ! R" R#],4      t3 ! R$ R%]34      t4 ! R& R']34      t5R # ))    )Basic)cacheit)Tuple)call_highest_priority)global_parameters)AppliedUndefexpandMul)Integer)Eq)S	Singleton)ordered)DummySymbolWildsympify)Matrix)lcmfactor)IntervalIntersection)Idx)flattenis_sequenceiterablec                   b  a  ] tR t^t o RtRt^t]R 4       tR t	]
R 4       t]
R 4       t]
R 4       t]
R 4       t]
R	 4       t]
R
 4       t]
R 4       t]R 4       tR tR tR tR tR tR t]! R4      R 4       tR t]! R4      R 4       tR tR t]! R4      R 4       t R t!R t"R!R lt#R t$V t%R# )"SeqBasezBase class for sequencesTc                d     V P                   pV#   \         d    \        P                  p T# i ; i)zKReturn start (if possible) else S.Infinity.

adapted from Set._infimum_key
)startNotImplementedErrorr   Infinity)exprr"   s   & v/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/series/sequences.py
_start_keySeqBase._start_key    s6    	JJE  # 	JJE	s    //c                r    \        V P                  VP                  4      pVP                  VP                  3# )zDReturns start and stop.

Takes intersection over the two intervals.
)r   intervalinfsup)selfotherr*   s   && r&   _intersect_intervalSeqBase._intersect_interval,   s+    
  u~~>||X\\))    c                &    \        RV ,          4      h)z&Returns the generator for the sequencez(%s).genr#   r-   s   &r&   genSeqBase.gen4   s     "*t"344r1   c                &    \        RV ,          4      h)z-The interval on which the sequence is definedz(%s).intervalr3   r4   s   &r&   r*   SeqBase.interval9   s     "/D"899r1   c                &    \        RV ,          4      h):The starting point of the sequence. This point is includedz
(%s).startr3   r4   s   &r&   r"   SeqBase.start>   s     ","566r1   c                &    \        RV ,          4      h)z8The ending point of the sequence. This point is includedz	(%s).stopr3   r4   s   &r&   stopSeqBase.stopC   s     "+"455r1   c                &    \        RV ,          4      h)zLength of the sequencez(%s).lengthr3   r4   s   &r&   lengthSeqBase.lengthH   s     "-$"677r1   c                    R# )z-Returns a tuple of variables that are bounded rC   r4   s   &r&   	variablesSeqBase.variablesM   s	     	r1   c                    V P                    UUu0 uF/  qP                  P                  V P                  4       F  q"kK  	  K1  	  upp# u uppi )z
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
differencerD   )r-   ijs   &  r&   rH   SeqBase.free_symbolsR   sH     !II 0Iq~~Jt~~.0/! 0/I 0 	1 0s   5A	c                    WP                   8  g   WP                  8  d   \        RV: RV P                  : 24      hV P	                  V4      # )z#Returns the coefficient at point ptzIndex z out of bounds )r"   r=   
IndexErrorr*   _eval_coeffr-   pts   &&r&   coeffSeqBase.coeffc   s:     

?b99nBNOO##r1   c                :    \        R V P                  ,          4      h)zhThe _eval_coeff method should be added to%s to return coefficient so it is availablewhen coeff calls it.)r#   funcrP   s   &&r&   rO   SeqBase._eval_coeffj   s"    ! #9 %)II#. / 	/r1   c                    V P                   \        P                  J d   V P                  pMV P                   pV P                   \        P                  J d   RpM^pW!V,          ,           # )a  Returns 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"   r   NegativeInfinityr=   )r-   rJ   initialsteps   &&  r&   
_ith_pointSeqBase._ith_pointp   sR    @ ::+++iiGjjG::+++DD4r1   c                    R# )a	  
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.
NrC   r-   r.   s   &&r&   _addSeqBase._add        r1   c                    R# )a  
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.
NrC   r_   s   &&r&   _mulSeqBase._mul   rb   r1   c                    \        W4      # )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
   r_   s   &&r&   	coeff_mulSeqBase.coeff_mul   s    $ 4r1   c                z    \        V\        4      '       g   \        R\        V4      ,          4      h\	        W4      # )zReturns 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))
zcannot add sequence and %s
isinstancer    	TypeErrortypeSeqAddr_   s   &&r&   __add__SeqBase.__add__   s1     %))84;FGGd""r1   ro   c                    W,           # NrC   r_   s   &&r&   __radd__SeqBase.__radd__   
    |r1   c                |    \        V\        4      '       g   \        R\        V4      ,          4      h\	        W) 4      # )zReturns 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))
zcannot subtract sequence and %srj   r_   s   &&r&   __sub__SeqBase.__sub__   s3     %))=UKLLdF##r1   rw   c                    V ) V,           # rr   rC   r_   s   &&r&   __rsub__SeqBase.__rsub__   s    r1   c                $    V P                  R4      # )zNegates the sequence.

Examples
========

>>> from sympy import SeqFormula
>>> from sympy.abc import n
>>> -SeqFormula(n**2)
SeqFormula(-n**2, (n, 0, oo))
rX   )rg   r4   s   &r&   __neg__SeqBase.__neg__   s     ~~b!!r1   c                z    \        V\        4      '       g   \        R\        V4      ,          4      h\	        W4      # )a3  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))
zcannot multiply sequence and %s)rk   r    rl   rm   SeqMulr_   s   &&r&   __mul__SeqBase.__mul__  s1     %))=UKLLd""r1   r   c                    W,          # rr   rC   r_   s   &&r&   __rmul__SeqBase.__rmul__  ru   r1   c              #     "   \        V P                  4       F'  pV P                  V4      pV P                  V4      x  K)  	  R # 5irr   )ranger@   r\   rR   )r-   rJ   rQ   s   &  r&   __iter__SeqBase.__iter__  s4     t{{#A#B**R.  $s   AAc                   \        V\        4      '       d#   V P                  V4      pV P                  V4      # \        V\        4      '       d{   VP
                  VP                  r2Vf   ^ pVf   V P                  p\        Y#VP                  ;'       g    ^4       Uu. uF"  q@P                  V P                  V4      4      NK$  	  up# R # u upi rr   )
rk   intr\   rR   slicer"   r=   r@   r   r[   )r-   indexr"   r=   rJ   s   &&   r&   __getitem__SeqBase.__getitem__"  s    eS!!OOE*E::e$$u%%++uzz4}|{{%uzzQ797 89JJtq1279 9 &9s   (CNc           
     b   ^ RI Hp V RV  Uu. uF  qT! \        V4      4      NK  	  pp\        V4      pVf   V^,          pM\	        W'^,          4      p. p	\        ^V^,           4       EF  p
^V
,          p. p\        V
4       F  pVP                  WmW,            4       K  	  \        V4      pVP                  4       ^ 8w  g   K\  V! VP                  \        WjV 4      4      4      pW{8X  d   \        VRRR1,          4      p	 Mr. p\        WV
,
          4       F  pVP                  WmW,            4       K  	  \        V4      pW,          \        WkR 4      8X  g   K  \        VRRR1,          4      p	 M	  Vf   V	# \        V	4      p
V
^ 8X  d   . R3# Wj^,
          ,          W:^,
          ,          ,          ^W^,
          ,          W:,          ,          ,
          r!\        V
^,
          4       F  pWV,          VV,          ,          ,          p\        V
V,
          ^,
          4       F<  pWV,          VV,          ,          VVV,           ^,           ,          ,          ,          pK>  	  W)V,          VV^,           ,          ,          ,          pK  	  W! \        V4      \        V4      ,          4      3# u upi )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))
)simplifyNrX   )sympy.simplifyr   r	   lenminr   appendr   detLUsolver   r   )r-   ndgfvarr   txlxrcoeffsll2mlistkmyrJ   rK   s   &&&&              r&   find_linear_recurrenceSeqBase.find_linear_recurrence/  s(   D 	,*.r(3(QXfQi (3V9AAA!eAq!A#A1BE1XQX& uAuuw!|QYYva"g788$QttW-FqAALLQS* '5M3&3.($QttW-F# $ =MFAAv4x1vecl*AsEH0D,D1qsA1eQh&A"1Q3q5\AYqt^EAaCEN:: *51Q3<//A	 $
 xq	&)(;<<<M 4s   J,rC   )NN)&__name__
__module____qualname____firstlineno____doc__is_commutative_op_prioritystaticmethodr'   r/   propertyr5   r*   r"   r=   r@   rD   rH   r   rR   rO   r\   r`   rd   rg   ro   r   rs   rw   rz   r}   r   r   r   r   r   __static_attributes____classdictcell____classdict__s   @r&   r    r       sX    "NL	 	* 5 5 : : 7 7 6 6 8 8   1 1  $ $/* X   (#" 9% &$" 9% &"#$ 9% &!
9I= I=r1   r    c                   P   a  ] tR tRt o Rt]R 4       t]R 4       tR tR t	Rt
V tR# )	EmptySequenceiz  a  Represents 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                "    \         P                  # rr   )r   EmptySetr4   s   &r&   r*   EmptySequence.interval  s    zzr1   c                "    \         P                  # rr   )r   Zeror4   s   &r&   r@   EmptySequence.length  s    vvr1   c                    V # z"See docstring of SeqBase.coeff_mulrC   )r-   rR   s   &&r&   rg   EmptySequence.coeff_mul  s    r1   c                    \        . 4      # rr   )iterr4   s   &r&   r   EmptySequence.__iter__  s    Bxr1   rC   N)r   r   r   r   r   r   r*   r@   rg   r   r   r   r   s   @r&   r   r   z  sA     (     r1   r   )	metaclassc                      a  ] tR tRt o Rt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tR	tV tR
# )SeqExpri  a  Sequence 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                (    V P                   ^ ,          # r   rG   r4   s   &r&   r5   SeqExpr.gen  s    yy|r1   c                z    \        V P                  ^,          ^,          V P                  ^,          ^,          4      #    )r   rG   r4   s   &r&   r*   SeqExpr.interval  s'    		!Q1a99r1   c                .    V P                   P                  # rr   r*   r+   r4   s   &r&   r"   SeqExpr.start      }}   r1   c                .    V P                   P                  # rr   r*   r,   r4   s   &r&   r=   SeqExpr.stop  r   r1   c                J    V P                   V P                  ,
          ^,           # r   r=   r"   r4   s   &r&   r@   SeqExpr.length      yy4::%))r1   c                8    V P                   ^,          ^ ,          3# r   r   r4   s   &r&   rD   SeqExpr.variables  s    		!Q!!r1   rC   N)r   r   r   r   r   r   r5   r*   r"   r=   r@   rD   r   r   r   s   @r&   r   r     s     2   : : ! ! ! ! * * " "r1   r   c                   f   a  ] tR tRt o RtRR lt]R 4       t]R 4       tR t	R t
R	 tR
 tRtV tR# )SeqPeri  aj  
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
Nc                "   \        V4      pR  pRRRrepVf   V! V4      ^ \        P                  rep\        V\        4      '       d3   \        V4      ^8X  d   Vw  rEpM\        V4      ^8X  d   V! V4      pVw  rV\        V\        \        34      '       d	   Ve   Vf   \        R\        V4      ,          4      hV\        P                  J d    V\        P                  J d   \        R4      h\        WEV34      p\        V\        4      '       d   \        \        \        V4      4      4      pM\        RV,          4      h\        V^,          V^,          4      \        P                  J d   \        P                   # \"        P$                  ! WV4      # )c                     V P                   p\        V P                   4      ^8X  d   VP                  4       # \        R4      # )r   r   )rH   r   popr   )
periodicalfrees   & r&   _find_xSeqPer.__new__.<locals>._find_x  s6    **D:**+q0xxz!Sz!r1   NInvalid limits given: %sz/Both the start and end valuecannot be unboundedz6invalid period %s should be something like e.g (1, 2) )r   r   r$   r   r   r   rk   r   r   
ValueErrorstrrY   tupler   r   r   r   r   __new__)clsr   limitsr   r   r"   r=   s   &&&    r&   r   SeqPer.__new__  sS   Z(
	" tT$>$Z0!QZZdAvu%%6{a!'$V!J'$!fc]++u}7#f+EFFA&&&41::+=  "7 8 8 !D)*z5)) wz':!;<J 02<= > > F1Ivay)QZZ7??"}}Sf55r1   c                ,    \        V P                  4      # rr   )r   r5   r4   s   &r&   periodSeqPer.period+  s    488}r1   c                    V P                   # rr   r5   r4   s   &r&   r   SeqPer.periodical/      xxr1   c                6   V P                   \        P                  J d&   V P                  V,
          V P                  ,          pM#WP                   ,
          V P                  ,          pV P
                  V,          P                  V P                  ^ ,          V4      # r   )r"   r   rY   r=   r   r   subsrD   )r-   rQ   idxs   && r&   rO   SeqPer._eval_coeff3  sc    ::+++99r>T[[0C

?dkk1Cs#(():B??r1   c                   \        V\        4      '       d   V P                  V P                  r2VP                  VP                  rT\	        W54      p. p\        V4       F8  pW(V,          ,          p	WHV,          ,          p
VP                  W,           4       K:  	  V P                  V4      w  r\        WpP                  ^ ,          W34      # R# zSee docstring of SeqBase._addN	rk   r   r   r   r   r   r   r/   rD   r-   r.   per1lper1per2lper2
per_lengthnew_perr   ele1ele2r"   r=   s   &&           r&   r`   SeqPer._add:      eV$$//4;;%**ELL%U*JG:&IIt{+ '
 2259KE'NN1$5u#CDD %r1   c                   \        V\        4      '       d   V P                  V P                  r2VP                  VP                  rT\	        W54      p. p\        V4       F8  pW(V,          ,          p	WHV,          ,          p
VP                  W,          4       K:  	  V P                  V4      w  r\        WpP                  ^ ,          W34      # R# zSee docstring of SeqBase._mulNr   r   s   &&           r&   rd   SeqPer._mulK  r  r1   c                    \        V4      pV P                   Uu. uF  q"V,          NK  	  pp\        W0P                  ^,          4      # u upi r   )r   r   r   rG   )r-   rR   r   pers   &&  r&   rg   SeqPer.coeff_mul\  s?    "&//2/Q5yy/2c99Q<(( 3s   A	rC   rr   )r   r   r   r   r   r   r   r   r   rO   r`   rd   rg   r   r   r   s   @r&   r   r     sU     .`&6P    @E"E") )r1   r   c                   \   a  ] tR tRt o RtRR lt]R 4       tR tR t	R t
R	 tR
 tRtV tR# )
SeqFormulaic  a  
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
Nc                   \        V4      pR  pRRRrepVf   V! V4      ^ \        P                  rep\        V\        4      '       d3   \        V4      ^8X  d   Vw  rEpM\        V4      ^8X  d   V! V4      pVw  rV\        V\        \        34      '       d	   Ve   Vf   \        R\        V4      ,          4      hV\        P                  J d    V\        P                  J d   \        R4      h\        WEV34      p\        V^,          V^,          4      \        P                  J d   \        P                  # \        P                   ! WV4      # )c                     V P                   p\        V4      ^8X  d   VP                  4       # V'       g   \        R4      # \	        RV ,          4      h)r   r   z 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)))rH   r   r   r   r   )formular   s   & r&   r   #SeqFormula.__new__.<locals>._find_x  sN    ''D4yA~xxz!Sz! O  r1   Nr   z0Both the start and end value cannot be unbounded)r   r   r$   r   r   r   rk   r   r   r   r   rY   r   r   r   r   r   )r   r  r   r   r   r"   r=   s   &&&    r&   r   SeqFormula.__new__  s   '"	 tT$>$W-q!**dAvu%%6{a!'$V!G$$!fc]++u}7#f+EFFA&&&41::+=  "7 8 8!D)*F1Ivay)QZZ7??"}}S622r1   c                    V P                   # rr   r   r4   s   &r&   r  SeqFormula.formula  r   r1   c                ^    V P                   ^ ,          pV P                  P                  W!4      # r   )rD   r  r   )r-   rQ   r   s   && r&   rO   SeqFormula._eval_coeff  s%    NN1||  ''r1   c                   \        V\        4      '       dt   V P                  V P                  ^ ,          r2VP                  VP                  ^ ,          rTW$P	                  WS4      ,           pV P                  V4      w  rx\        WcWx34      # R# r   rk   r  r  rD   r   r/   	r-   r.   form1v1form2v2r  r"   r=   s	   &&       r&   r`   SeqFormula._add  o    eZ((dnnQ&72uq'92jj00G2259KEgE'899 )r1   c                   \        V\        4      '       dt   V P                  V P                  ^ ,          r2VP                  VP                  ^ ,          rTW$P	                  WS4      ,          pV P                  V4      w  rx\        WcWx34      # R# r  r  r  s	   &&       r&   rd   SeqFormula._mul  r  r1   c                v    \        V4      pV P                  V,          p\        W P                  ^,          4      # r   )r   r  r  rG   )r-   rR   r  s   && r&   rg   SeqFormula.coeff_mul  s,    ,,&'99Q<00r1   c                j    \        \        V P                  .VO5/ VB V P                  ^,          4      # r   )r  r	   r  rG   )r-   rG   kwargss   &*,r&   r	   SeqFormula.expand  s*    &???1NNr1   rC   rr   )r   r   r   r   r   r   r   r  rO   r`   rd   rg   r	   r   r   r   s   @r&   r  r  c  sE     &P%3N  (::1O Or1   r  c                      a  ] tR tRt o RtRR lt]R 4       t]R 4       t]R 4       t	]R 4       t
]R	 4       t]R
 4       t]R 4       t]R 4       t]R 4       tR tR tRtV tR# )RecursiveSeqi  a  
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

Nc                   \        V\        4      '       g   \        R P                  V4      4      h\        V\        4      '       d   VP
                  '       g   \        RP                  V4      4      hVP                  V38w  d   \        R4      hVP                  p\        RV3R7      p^ pVP                  V4      p	V	 F  p
\        V
P                  4      ^8w  d   \        R4      hV
P                  ^ ,          P                  W7,           4      V,          pVP                  4       '       d   VP                  '       d   V^ 8  g   \        RP                  V
4      4      hV) V8  g   K  V) pK  	  V'       g3   \        V4       Uu. uF  p\        RP                  V4      4      NK  	  pp\        V4      V8w  d   \!        R4      h\#        V4      p\%        V4      p\'        R	 V 4       !  p\        P(                  ! WW#WE4      p\+        V4       UUu/ uF  w  r}V! WW,           4      VbK  	  uppVn        Wn        V# u upi u uppi )
zErecurrence sequence must be an applied undefined function, found `{}`z0recurrence variable must be a symbol, found `{}`z)recurrence sequence does not match symbolr   )excludez)Recurrence should be in a single variablezDRecurrence should have constant, negative, integer shifts (found {})zc_{}z)Number of initial terms must equal degreec              3   8   "   T F  p\        V4      x  K  	  R # 5irr   r   ).0r   s   & r&   	<genexpr>'RecursiveSeq.__new__.<locals>.<genexpr>O  s     6g'!**g   )rk   r   rl   formatr   	is_symbolrG   rU   r   findr   matchis_constant
is_integerr   r   r   r   r   r   r   	enumeratecachedegree)r   
recurrenceynr   rZ   r"   r   r   r7  prev_ysprev_yshiftseqinits   &&&&&&        r&   r   RecursiveSeq.__new__#  s   "l++ ++16":7 7 !U##1;;; ++16!96 6 77qd?GHHGGqd# //!$F6;;1$ KLLKKN((/2E%%''E,<,<,< !..4fVn> > v  8=fF1uV]]1-.GFw<6!HII6g67mmCRGC7@7IJ7IGAQuy\4'7IJ	

 G Ks   #H<Ic                (    V P                   ^ ,          # zEquation defining recurrence.r   r4   s   &r&   _recurrenceRecursiveSeq._recurrenceX       yy|r1   c                P    \        V P                  V P                  ^ ,          4      # rA  )r   r9  rG   r4   s   &r&   r8  RecursiveSeq.recurrence]  s     $''499Q<((r1   c                (    V P                   ^,          # )z*Applied function representing the nth termr   r4   s   &r&   r9  RecursiveSeq.ynb  rD  r1   c                .    V P                   P                  # )z3Undefined function for the nth term of the sequence)r9  rU   r4   s   &r&   r   RecursiveSeq.yg  s     ww||r1   c                (    V P                   ^,          # )zSequence index symbolr   r4   s   &r&   r   RecursiveSeq.nl  rD  r1   c                (    V P                   ^,          # )z"The initial values of the sequencer   r4   s   &r&   rZ   RecursiveSeq.initialq  rD  r1   c                (    V P                   ^,          # )r:   r   r4   s   &r&   r"   RecursiveSeq.startv  rD  r1   c                "    \         P                  # )z&The ending point of the sequence. (oo))r   r$   r4   s   &r&   r=   RecursiveSeq.stop{  s     zzr1   c                :    V P                   \        P                  3# )z&Interval on which sequence is defined.)r"   r   r$   r4   s   &r&   r*   RecursiveSeq.interval  s     

AJJ''r1   c                >   WP                   ,
          \        V P                  4      8  d#   V P                  V P                  V4      ,          # \	        \        V P                  4      V^,           4       Fu  pV P                   V,           pV P
                  P                  V P                  V/4      pVP                  V P                  4      pWPP                  V P                  V4      &   Kw  	  V P                  V P                  V P                   X,           4      ,          # r   )r"   r   r6  r   r   rB  xreplacer   )r-   r   current	seq_indexcurrent_recurrencenew_terms   &&    r&   rO   RecursiveSeq._eval_coeff  s    ::DJJ/::dffUm,,S_eai8G 

W,I!%!1!1!:!:DFFI;N!O)224::>H,4JJtvvi() 9 zz$&&g!5677r1   c              #  `   "   V P                   p V P                  V4      x  V^,          pK  5i)T)r"   rO   )r-   r   s   & r&   r   RecursiveSeq.__iter__  s+     

""5))QJEs   ,.rC   )Nr   )r   r   r   r   r   r   r   rB  r8  r9  r   r   rZ   r"   r=   r*   rO   r   r   r   r   s   @r&   r'  r'    s     JX3j   ) )             ( (8 r1   r'  Nc                p    \        V 4      p \        V \        4      '       d   \        W4      # \	        W4      # )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
)r   r   r   r   r  )r=  r   s   &&r&   sequencer_    s0    4 #,C3c""#&&r1   c                      a  ] tR tRt o Rt]R 4       t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tR	tV tR
# )	SeqExprOpi  a  
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                    \         ;QJ d    . R V P                   4       F  NK  	  5# ! R V P                   4       4      # )zZGenerator for the sequence.

returns a tuple of generators of all the argument sequences.
c              3   8   "   T F  qP                   x  K  	  R # 5irr   r   r+  as   & r&   r,   SeqExprOp.gen.<locals>.<genexpr>  s     .IqUUIr.  )r   rG   r4   s   &r&   r5   SeqExprOp.gen  s.     u.DII.u.u.DII...r1   c                6    \        R V P                   4       !  # )zUSequence is defined on the intersection
of all the intervals of respective sequences
c              3   8   "   T F  qP                   x  K  	  R # 5irr   r*   rd  s   & r&   r,  %SeqExprOp.interval.<locals>.<genexpr>  s     <)Qjj)r.  )r   rG   r4   s   &r&   r*   SeqExprOp.interval  s    
 <$))<==r1   c                .    V P                   P                  # rr   r   r4   s   &r&   r"   SeqExprOp.start  r   r1   c                .    V P                   P                  # rr   r   r4   s   &r&   r=   SeqExprOp.stop  r   r1   c                z    \        \        V P                   Uu. uF  qP                  NK  	  up4      4      # u upi )z%Cumulative of all the bound variables)r   r   rG   rD   )r-   re  s   & r&   rD   SeqExprOp.variables  s,     W499=9akk9=>??=s   8c                J    V P                   V P                  ,
          ^,           # r   r   r4   s   &r&   r@   SeqExprOp.length  r   r1   rC   N)r   r   r   r   r   r   r5   r*   r"   r=   rD   r@   r   r   r   s   @r&   ra  ra    s     0 / / > > ! ! ! ! @ @ * *r1   ra  c                   @   a  ] tR tRt o RtR t]R 4       tR tRt	V t
R# )rn   i  aF  Represents 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                  a VP                  R \        P                  4      p\        V4      pV3R loS! V4      pV Uu. uF  qD\        P
                  Jg   K  VNK  	  ppV'       g   \        P
                  # \        R V 4       !  \        P                  J d   \        P
                  # V'       d   \        P                  V4      # \        \        V\        P                  4      4      p\        P                  ! V .VO5!  # u upi )evaluatec                   < \        V \        4      '       d:   \        V \        4      '       d!   \        \	        SV P
                  4      . 4      # V .# \        V 4      '       d   \        \	        SV 4      . 4      # \        R 4      hz2Input must be Sequences or  iterables of Sequences)rk   r    rn   summaprG   r   rl   arg_flattens   &r&   r~   SeqAdd.__new__.<locals>._flatten   sk    #w''c6**s8SXX6;;5L}}3x-r22 6 7 7r1   c              3   8   "   T F  qP                   x  K  	  R # 5irr   rj  rd  s   & r&   r,  !SeqAdd.__new__.<locals>.<genexpr>2       3d**dr.  )getr   rw  listr   r   r   r   rn   reducer   r    r'   r   r   )r   rG   r$  rw  re  r~  s   &*,  @r&   r   SeqAdd.__new__  s    ::j*;*D*DE Dz		7 ~<4aAOO#;4< ??"3d34

B??" ==&&GD'"4"456}}S(4(( =s   DDc                   RpV'       d   \        V 4       Fr  w  r#Rp\        V 4       FO  w  rEW$8X  d   K  VP                  V4      pVf   K$  V  Uu. uF  qwW539  g   K  VNK  	  ppVP                  V4        M	  V'       g   Ko  Tp  K  	  K  \        V 4      ^8X  d   V P	                  4       # \        V RR7      # u upi )zSimplify :class:`SeqAdd` using known rules.

Iterates through all pairs and ask the constituent
sequences if they can simplify themselves with any other constituent.

Notes
=====

adapted from ``Union.reduce``

TFrw  )r5  r`   r   r   r   rn   rG   new_argsid1sid2r   new_seqre  s   &       r&   r  SeqAdd.reduce=  s     #D/ 'oFCz ffQiG */3#Gt!AAt#G 0 . 8#D *  t9>88:$// $H   	B;B;c                B   a \        V3R lV P                   4       4      # )z9adds up the coefficients of all the sequences at point ptc              3   D   <"   T F  qP                  S4      x  K  	  R # 5irr   )rR   )r+  re  rQ   s   & r&   r,  %SeqAdd._eval_coeff.<locals>.<genexpr>c  s     2	1772;;	s    )rz  rG   rP   s   &fr&   rO   SeqAdd._eval_coeffa  s    2		222r1   rC   Nr   r   r   r   r   r   r   r  rO   r   r   r   s   @r&   rn   rn     s/     8")H !0 !0F3 3r1   rn   c                   @   a  ] tR tRt o RtR t]R 4       tR tRt	V t
R# )r   if  a  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                  a VP                  R \        P                  4      p\        V4      pV3R loS! V4      pV'       g   \        P
                  # \        R V 4       !  \        P                  J d   \        P
                  # V'       d   \        P                  V4      # \        \        V\        P                  4      4      p\        P                  ! V .VO5!  # )rw  c                   < \        V \        4      '       d:   \        V \        4      '       d!   \        \	        SV P
                  4      . 4      # V .# \        V 4      '       d   \        \	        SV 4      . 4      # \        R 4      hry  )rk   r    r   rz  r{  rG   r   rl   r|  s   &r&   r~   SeqMul.__new__.<locals>._flatten  sk    #w''c6**s8SXX6;;5L#3x-r22 6 7 7r1   c              3   8   "   T F  qP                   x  K  	  R # 5irr   rj  rd  s   & r&   r,  !SeqMul.__new__.<locals>.<genexpr>  r  r.  )r  r   rw  r  r   r   r   r   r   r  r   r    r'   r   r   )r   rG   r$  rw  r~  s   &*, @r&   r   SeqMul.__new__  s    ::j*;*D*DE Dz		7 ~ ??"3d34

B??" ==&&GD'"4"456}}S(4((r1   c                   RpV'       d   \        V 4       Fr  w  r#Rp\        V 4       FO  w  rEW$8X  d   K  VP                  V4      pVf   K$  V  Uu. uF  qwW539  g   K  VNK  	  ppVP                  V4        M	  V'       g   Ko  Tp  K  	  K  \        V 4      ^8X  d   V P	                  4       # \        V RR7      # u upi )zSimplify 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``

TFr  )r5  rd   r   r   r   r   r  s   &       r&   r  SeqMul.reduce  s      #D/ 'oFCz ffQiG */3#Gt!AAt#G 0 . 8#D *  t9>88:$// $Hr  c                ^    ^pV P                    F  pW#P                  V4      ,          pK  	  V# )z<multiplies the coefficients of all the sequences at point pt)rG   rR   )r-   rQ   valre  s   &&  r&   rO   SeqMul._eval_coeff  s*    A772;C 
r1   rC   Nr  r   s   @r&   r   r   f  s0      D )D $0 $0L r1   r   rr   )6sympy.core.basicr   sympy.core.cacher   sympy.core.containersr   sympy.core.decoratorsr   sympy.core.parametersr   sympy.core.functionr   r	   sympy.core.mulr   sympy.core.numbersr   sympy.core.relationalr   sympy.core.singletonr   r   sympy.core.sortingr   sympy.core.symbolr   r   r   sympy.core.sympifyr   sympy.matricesr   sympy.polysr   r   sympy.sets.setsr   r   sympy.tensor.indexedr   sympy.utilities.iterablesr   r   r   r    r   r   r   r  r'  r_  ra  rn   r   rC   r1   r&   <module>r     s    " $ ' 7 3 4  & $ - & 1 1 & ! # 2 $ D D^=e ^=@"Gy "J0"g 0"fN)W N)bqO qOfB7 BJ'N7* 7*tg3Y g3TqY qr1   