
    \h׊                        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  S S
KJrJr  S SKJr  S SKJr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K(J)r)J*r*J+r+   " S S\5      r, " S S\,\S9r- " S S\,5      r. " S S\.5      r/ " S S\.5      r0 " S S\,5      r1S(S! jr2 " S" S#\,5      r3 " S$ S%\35      r4 " S& S'\35      r5g ))    )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                   V   \ rS rSrSrSrSr\S 5       rS r	\
S 5       r\
S 5       r\
S	 5       r\
S
 5       r\
S 5       r\
S 5       r\
S 5       r\S 5       rS rS rS rS rS rS r\" S5      S 5       rS r\" S5      S 5       rS rS r\" S5      S 5       r S r!S r"S#S! jr#S"r$g )$SeqBase   zBase class for sequencesT   c                 b     U R                   nU$ ! [         a    [        R                  n U$ f = f)zKReturn start (if possible) else S.Infinity.

adapted from Set._infimum_key
)startNotImplementedErrorr   Infinity)exprr$   s     N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/series/sequences.py
_start_keySeqBase._start_key    s6    	JJE  # 	JJE	s    ..c                 r    [        U R                  UR                  5      nUR                  UR                  4$ )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                     [        SU -  5      e)z&Returns the generator for the sequencez(%s).genr%   r/   s    r(   genSeqBase.gen4   s     "*t"344r3   c                     [        SU -  5      e)z-The interval on which the sequence is definedz(%s).intervalr5   r6   s    r(   r,   SeqBase.interval9   s     "/D"899r3   c                     [        SU -  5      e):The starting point of the sequence. This point is includedz
(%s).startr5   r6   s    r(   r$   SeqBase.start>   s     ","566r3   c                     [        SU -  5      e)z8The ending point of the sequence. This point is includedz	(%s).stopr5   r6   s    r(   stopSeqBase.stopC   s     "+"455r3   c                     [        SU -  5      e)zLength of the sequencez(%s).lengthr5   r6   s    r(   lengthSeqBase.lengthH   s     "-$"677r3   c                     g)z-Returns a tuple of variables that are bounded rE   r6   s    r(   	variablesSeqBase.variablesM   s     r3   c                     U R                    VVs1 s H0  oR                  R                  U R                  5        H  o"iM     M2     snn$ s  snnf )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
differencerF   )r/   ijs      r(   rJ   SeqBase.free_symbolsR   sH     !II 0Iq~~Jt~~.0/! 0/I 0 	1 0s   7Ac                     XR                   :  d  XR                  :  a  [        SU< SU R                  < 35      eU R	                  U5      $ )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##r3   c                 2    [        SU R                  -  5      e)NzhThe _eval_coeff method should be added to%s to return coefficient so it is availablewhen coeff calls it.)r%   funcrR   s     r(   rQ   SeqBase._eval_coeffj   s"    ! #9 %)II#. / 	/r3   c                     U R                   [        R                  L a  U R                  nOU R                   nU R                   [        R                  L a  SnOSnX!U-  -   $ )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/   rL   initialsteps       r(   
_ith_pointSeqBase._ith_pointp   sR    @ ::+++iiGjjG::+++DD4r3   c                     g)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.
NrE   r/   r0   s     r(   _addSeqBase._add        r3   c                     g)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.
NrE   rb   s     r(   _mulSeqBase._mul   re   r3   c                     [        X5      $ )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
   rb   s     r(   	coeff_mulSeqBase.coeff_mul   s    $ 4r3   c                 p    [        U[        5      (       d  [        S[        U5      -  5      e[	        X5      $ )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SeqAddrb   s     r(   __add__SeqBase.__add__   s1     %))84;FGGd""r3   rr   c                 
    X-   $ NrE   rb   s     r(   __radd__SeqBase.__radd__   
    |r3   c                 r    [        U[        5      (       d  [        S[        U5      -  5      e[	        X* 5      $ )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 %srm   rb   s     r(   __sub__SeqBase.__sub__   s3     %))=UKLLdF##r3   rz   c                     U * U-   $ ru   rE   rb   s     r(   __rsub__SeqBase.__rsub__   s    r3   c                 $    U R                  S5      $ )zNegates the sequence.

Examples
========

>>> from sympy import SeqFormula
>>> from sympy.abc import n
>>> -SeqFormula(n**2)
SeqFormula(-n**2, (n, 0, oo))
rZ   )rj   r6   s    r(   __neg__SeqBase.__neg__   s     ~~b!!r3   c                 p    [        U[        5      (       d  [        S[        U5      -  5      e[	        X5      $ )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)rn   r    ro   rp   SeqMulrb   s     r(   __mul__SeqBase.__mul__  s1     %))=UKLLd""r3   r   c                 
    X-  $ ru   rE   rb   s     r(   __rmul__SeqBase.__rmul__  rx   r3   c              #      #    [        U R                  5       H'  nU R                  U5      nU R                  U5      v   M)     g 7fru   )rangerB   r_   rT   )r/   rL   rS   s      r(   __iter__SeqBase.__iter__  s4     t{{#A#B**R.  $s   AAc                    [        U[        5      (       a"  U R                  U5      nU R                  U5      $ [        U[        5      (       ax  UR
                  UR                  p2Uc  SnUc  U R                  n[        X#UR                  =(       d    S5       Vs/ s H"  o@R                  U R                  U5      5      PM$     sn$ g s  snf )Nr   r[   )
rn   intr_   rT   slicer$   r?   rB   r   r^   )r/   indexr$   r?   rL   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           
         SSK Jn  U SU  Vs/ s H  oT" [        U5      5      PM     nn[        U5      nUc  US-  nO[	        X'S-  5      n/ n	[        SUS-   5       H  n
SU
-  n/ n[        U
5       H  nUR                  XmX-    5        M     [        U5      nUR                  5       S:w  d  MR  U" UR                  [        XjU 5      5      5      nX{:X  a  [        USSS2   5      n	  Oa/ n[        XU
-
  5       H  nUR                  XmX-    5        M     [        U5      nX-  [        XkS 5      :X  d  M  [        USSS2   5      n	  O   Uc  U	$ [        U	5      n
U
S:X  a  / S4$ XjS-
     X:S-
  -  -  SXS-
     X:-  -  -
  p![        U
S-
  5       HQ  nXU   UU-  -  -  n[        U
U-
  S-
  5       H  nXU   UU   -  UUU-   S-   -  -  -  nM     X)U   UUS-   -  -  -  nMS     X" [        U5      [        U5      -  5      4$ s  snf )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   )simplifyN   r[   rZ   )sympy.simplifyr   r	   lenminr   appendr   detLUsolver   r   )r/   ndgfvarr   txlxrcoeffsll2mlistkmyrL   rM   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   HrE   )NN)%__name__
__module____qualname____firstlineno____doc__is_commutative_op_prioritystaticmethodr)   r1   propertyr7   r,   r$   r?   rB   rF   rJ   r   rT   rQ   r_   rc   rg   rj   rr   r   rv   rz   r}   r   r   r   r   r   r   __static_attributes__rE   r3   r(   r    r       sO   "NL	 	* 5 5 : : 7 7 6 6 8 8   1 1  $ $/* X   (#" 9% &$" 9% &"#$ 9% &!
9I=r3   r    c                   D    \ rS rSrSr\S 5       r\S 5       rS rS r	Sr
g)	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                 "    [         R                  $ ru   )r   EmptySetr6   s    r(   r,   EmptySequence.interval  s    zzr3   c                 "    [         R                  $ ru   )r   Zeror6   s    r(   rB   EmptySequence.length  s    vvr3   c                     U $ )"See docstring of SeqBase.coeff_mulrE   )r/   rT   s     r(   rj   EmptySequence.coeff_mul  s    r3   c                     [        / 5      $ ru   )iterr6   s    r(   r   EmptySequence.__iter__  s    Bxr3   rE   N)r   r   r   r   r   r   r,   rB   rj   r   r   rE   r3   r(   r   r   z  s9    (    r3   r   )	metaclassc                   x    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	rg
)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                      U R                   S   $ Nr   rI   r6   s    r(   r7   SeqExpr.gen  s    yy|r3   c                 Z    [        U R                  S   S   U R                  S   S   5      $ )Nr[   r   )r   rI   r6   s    r(   r,   SeqExpr.interval  s'    		!Q1a99r3   c                 .    U R                   R                  $ ru   r,   r-   r6   s    r(   r$   SeqExpr.start      }}   r3   c                 .    U R                   R                  $ ru   r,   r.   r6   s    r(   r?   SeqExpr.stop  r   r3   c                 :    U R                   U R                  -
  S-   $ Nr[   r?   r$   r6   s    r(   rB   SeqExpr.length      yy4::%))r3   c                 (    U R                   S   S   4$ )Nr[   r   r   r6   s    r(   rF   SeqExpr.variables  s    		!Q!!r3   rE   N)r   r   r   r   r   r   r7   r,   r$   r?   rB   rF   r   rE   r3   r(   r   r     s    2   : : ! ! ! ! * * " "r3   r   c                   Z    \ rS rSrSrSS jr\S 5       r\S 5       rS r	S r
S	 rS
 rSrg)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                    [        U5      nS nSu  pEnUc  U" U5      S[        R                  pen[        U[        5      (       a0  [        U5      S:X  a  Uu  pEnO[        U5      S:X  a  U" U5      nUu  pV[        U[        [        45      (       a  Ub  Uc  [        S[        U5      -  5      eU[        R                  L a  U[        R                  L a  [        S5      e[        XEU45      n[        U[        5      (       a  [        [        [        U5      5      5      nO[        SU-  5      e[        US	   US   5      [        R                  L a  [        R                   $ ["        R$                  " XU5      $ )
Nc                     U R                   n[        U R                   5      S:X  a  UR                  5       $ [        S5      $ )Nr[   r   )rJ   r   popr   )
periodicalfrees     r(   _find_xSeqPer.__new__.<locals>._find_x  s6    **D:**+q0xxz!Sz!r3   NNNr      r   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   r   rn   r   r   
ValueErrorstrr\   tupler   r   r   r   r   __new__)clsr   limitsr   r   r$   r?   s          r(   r   SeqPer.__new__  sQ   Z(
	" *$>$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5r3   c                 ,    [        U R                  5      $ ru   )r   r7   r6   s    r(   periodSeqPer.period+  s    488}r3   c                     U R                   $ ru   r7   r6   s    r(   r   SeqPer.periodical/      xxr3   c                    U R                   [        R                  L a  U R                  U-
  U R                  -  nOXR                   -
  U R                  -  nU R
                  U   R                  U R                  S   U5      $ r   )r$   r   r\   r?   r   r   subsrF   )r/   rS   idxs      r(   rQ   SeqPer._eval_coeff3  sc    ::+++99r>T[[0C

?dkk1Cs#(():B??r3   c                 d   [        U[        5      (       a  U R                  U R                  p2UR                  UR                  pT[	        X55      n/ n[        U5       H$  nX(U-     n	XHU-     n
UR                  X-   5        M&     U R                  U5      u  p[        XpR                  S   X45      $ gzSee docstring of SeqBase._addr   N	rn   r   r   r   r   r   r   r1   rF   r/   r0   per1lper1per2lper2
per_lengthnew_perr   ele1ele2r$   r?   s                r(   rc   SeqPer._add:      eV$$//4;;%**ELL%U*JG:&IIt{+ '
 2259KE'NN1$5u#CDD %r3   c                 d   [        U[        5      (       a  U R                  U R                  p2UR                  UR                  pT[	        X55      n/ n[        U5       H$  nX(U-     n	XHU-     n
UR                  X-  5        M&     U R                  U5      u  p[        XpR                  S   X45      $ gzSee docstring of SeqBase._mulr   Nr   r   s                r(   rg   SeqPer._mulK  r  r3   c                     [        U5      nU R                   Vs/ s H  o"U-  PM	     nn[        X0R                  S   5      $ s  snf r   r[   )r   r   r   rI   )r/   rT   r   pers       r(   rj   SeqPer.coeff_mul\  s=    "&//2/Q5y/2c99Q<(( 3s   ArE   ru   )r   r   r   r   r   r   r   r   r   rQ   rc   rg   rj   r   rE   r3   r(   r   r     sM    .`&6P    @E"E")r3   r   c                   P    \ rS rSrSrSS jr\S 5       rS rS r	S r
S	 rS
 rSrg)
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                 j   [        U5      nS nSu  pEnUc  U" U5      S[        R                  pen[        U[        5      (       a0  [        U5      S:X  a  Uu  pEnO[        U5      S:X  a  U" U5      nUu  pV[        U[        [        45      (       a  Ub  Uc  [        S[        U5      -  5      eU[        R                  L a  U[        R                  L a  [        S5      e[        XEU45      n[        US   US   5      [        R                  L a  [        R                  $ [        R                   " XU5      $ )	Nc                     U R                   n[        U5      S:X  a  UR                  5       $ U(       d  [        S5      $ [	        SU -  5      e)Nr[   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)))rJ   r   r   r   r   )formular   s     r(   r   #SeqFormula.__new__.<locals>._find_x  sN    ''D4yA~xxz!Sz! O  r3   r   r   r   r   r   z0Both the start and end value cannot be unboundedr[   )r   r   r&   r   r   r   rn   r   r   r   r   r\   r   r   r   r   r   )r   r  r   r   r   r$   r?   s          r(   r   SeqFormula.__new__  s   '"	 *$>$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2r3   c                     U R                   $ ru   r   r6   s    r(   r  SeqFormula.formula  r   r3   c                 V    U R                   S   nU R                  R                  X!5      $ r   )rF   r  r   )r/   rS   r   s      r(   rQ   SeqFormula._eval_coeff  s%    NN1||  ''r3   c                     [        U[        5      (       ag  U R                  U R                  S   p2UR                  UR                  S   pTX$R	                  XS5      -   nU R                  U5      u  px[        XcXx45      $ gr   rn   r  r  rF   r   r1   	r/   r0   form1v1form2v2r  r$   r?   s	            r(   rc   SeqFormula._add  o    eZ((dnnQ&72uq'92jj00G2259KEgE'899 )r3   c                     [        U[        5      (       ag  U R                  U R                  S   p2UR                  UR                  S   pTX$R	                  XS5      -  nU R                  U5      u  px[        XcXx45      $ gr  r  r  s	            r(   rg   SeqFormula._mul  r!  r3   c                 f    [        U5      nU R                  U-  n[        X R                  S   5      $ r  )r   r  r  rI   )r/   rT   r  s      r(   rj   SeqFormula.coeff_mul  s,    ,,&'99Q<00r3   c                 b    [        [        U R                  /UQ70 UD6U R                  S   5      $ r   )r  r	   r  rI   )r/   rI   kwargss      r(   r	   SeqFormula.expand  s*    &???1NNr3   rE   ru   )r   r   r   r   r   r   r   r  rQ   rc   rg   rj   r	   r   rE   r3   r(   r  r  c  s<    &P%3N  (::1Or3   r  c                       \ rS rSrSrSS jr\S 5       r\S 5       r\S 5       r	\S 5       r
\S	 5       r\S
 5       r\S 5       r\S 5       r\S 5       rS rS rSrg)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                 T   [        U[        5      (       d  [        SR                  U5      5      e[        U[        5      (       a  UR
                  (       d  [        SR                  U5      5      eUR                  U4:w  a  [        S5      eUR                  n[        SU4S9nSnUR                  U5      n	U	 H  n
[        U
R                  5      S:w  a  [        S5      eU
R                  S   R                  X7-   5      U   nUR                  5       (       a  UR                  (       a  US:  d  [        S	R                  U
5      5      eU* U:  d  M  U* nM     U(       d3  [        U5       Vs/ s H  n[        S
R                  U5      5      PM     nn[        U5      U:w  a  [!        S5      e[#        U5      n[%        U5      n['        S U 5       6 n[        R(                  " XX#XE5      n[+        U5       VVs0 s H  u  p}U" XW-   5      U_M     snnUl        Xl        U$ s  snf s  snnf )NzErecurrence sequence must be an applied undefined function, found `{}`z0recurrence variable must be a symbol, found `{}`z)recurrence sequence does not match symbolr   )excluder   r[   z)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   #    U  H  n[        U5      v   M     g 7fru   r   ).0r   s     r(   	<genexpr>'RecursiveSeq.__new__.<locals>.<genexpr>O  s     6g'!**g   )rn   r   ro   formatr   	is_symbolrI   rW   r   findr   matchis_constant
is_integerr   r   r   r   r   r   r   	enumeratecachedegree)r   
recurrenceynr   r]   r$   r   r   r:  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7H$c                      U R                   S   $ zEquation defining recurrence.r   r   r6   s    r(   _recurrenceRecursiveSeq._recurrenceX       yy|r3   c                 H    [        U R                  U R                  S   5      $ rD  )r   r<  rI   r6   s    r(   r;  RecursiveSeq.recurrence]  s     $''499Q<((r3   c                      U R                   S   $ )z*Applied function representing the nth termr[   r   r6   s    r(   r<  RecursiveSeq.ynb  rG  r3   c                 .    U R                   R                  $ )z3Undefined function for the nth term of the sequence)r<  rW   r6   s    r(   r   RecursiveSeq.yg  s     ww||r3   c                      U R                   S   $ )zSequence index symbolr   r   r6   s    r(   r   RecursiveSeq.nl  rG  r3   c                      U R                   S   $ )z"The initial values of the sequencer   r   r6   s    r(   r]   RecursiveSeq.initialq  rG  r3   c                      U R                   S   $ )r<      r   r6   s    r(   r$   RecursiveSeq.startv  rG  r3   c                 "    [         R                  $ )z&The ending point of the sequence. (oo))r   r&   r6   s    r(   r?   RecursiveSeq.stop{  s     zzr3   c                 :    U R                   [        R                  4$ )z&Interval on which sequence is defined.)r$   r   r&   r6   s    r(   r,   RecursiveSeq.interval  s     

AJJ''r3   c                    XR                   -
  [        U R                  5      :  a  U R                  U R                  U5         $ [	        [        U R                  5      US-   5       Hq  nU R                   U-   nU R
                  R                  U R                  U05      nUR                  U R                  5      nXPR                  U R                  U5      '   Ms     U R                  U R                  U R                   W-   5         $ r   )r$   r   r9  r   r   rE  xreplacer   )r/   r   current	seq_indexcurrent_recurrencenew_terms         r(   rQ   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7r3   c              #   X   #    U R                   n U R                  U5      v   US-  nM  7fr   )r$   rQ   )r/   r   s     r(   r   RecursiveSeq.__iter__  s0     

""5))QJE s   (*rE   r   )r   r   r   r   r   r   r   rE  r;  r<  r   r   r]   r$   r?   r,   rQ   r   r   rE   r3   r(   r*  r*    s    JX3j   ) )             ( (8r3   r*  Nc                 n    [        U 5      n [        U [        5      (       a  [        X5      $ [	        X5      $ )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(   sequencerc    s0    4 #,C3c""#&&r3   c                   x    \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	rg
)	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                 :    [        S U R                   5       5      $ )zZGenerator for the sequence.

returns a tuple of generators of all the argument sequences.
c              3   8   #    U  H  oR                   v   M     g 7fru   r   r.  as     r(   r/   SeqExprOp.gen.<locals>.<genexpr>  s     .IqUUIr1  )r   rI   r6   s    r(   r7   SeqExprOp.gen  s     .DII...r3   c                 4    [        S U R                   5       6 $ )zUSequence is defined on the intersection
of all the intervals of respective sequences
c              3   8   #    U  H  oR                   v   M     g 7fru   r,   rh  s     r(   r/  %SeqExprOp.interval.<locals>.<genexpr>  s     <)Qjj)r1  )r   rI   r6   s    r(   r,   SeqExprOp.interval  s    
 <$))<==r3   c                 .    U R                   R                  $ ru   r   r6   s    r(   r$   SeqExprOp.start  r   r3   c                 .    U R                   R                  $ ru   r   r6   s    r(   r?   SeqExprOp.stop  r   r3   c                 |    [        [        U R                   Vs/ s H  oR                  PM     sn5      5      $ s  snf )z%Cumulative of all the bound variables)r   r   rI   rF   )r/   ri  s     r(   rF   SeqExprOp.variables  s,     W499=9akk9=>??=s   9c                 :    U R                   U R                  -
  S-   $ r   r   r6   s    r(   rB   SeqExprOp.length  r   r3   rE   N)r   r   r   r   r   r   r7   r,   r$   r?   rF   rB   r   rE   r3   r(   re  re    s    0 / / > > ! ! ! ! @ @ * *r3   re  c                   4    \ rS rSrSrS r\S 5       rS rSr	g)rq   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                   ^ UR                  S[        R                  5      n[        U5      nU4S jmT" U5      nU Vs/ s H  oD[        R
                  Ld  M  UPM     nnU(       d  [        R
                  $ [        S U 5       6 [        R                  L a  [        R
                  $ U(       a  [        R                  U5      $ [        [        U[        R                  5      5      n[        R                  " U /UQ76 $ s  snf )Nevaluatec                    > [        U [        5      (       a8  [        U [        5      (       a   [        [	        TU R
                  5      / 5      $ U /$ [        U 5      (       a  [        [	        TU 5      / 5      $ [        S5      eNz2Input must be Sequences or  iterables of Sequences)rn   r    rq   summaprI   r   ro   arg_flattens    r(   r   SeqAdd.__new__.<locals>._flatten   sk    #w''c6**s8SXX6;;5L}}3x-r22 6 7 7r3   c              3   8   #    U  H  oR                   v   M     g 7fru   rn  rh  s     r(   r/  !SeqAdd.__new__.<locals>.<genexpr>2       3d**dr1  )getr   r{  listr   r   r   r   rq   reducer   r    r)   r   r   )r   rI   r'  r{  ri  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   C>C>c                 |   SnU(       a  [        U 5       Hn  u  p#Sn[        U 5       HM  u  pEX$:X  a  M  UR                  U5      nUc  M"  U  Vs/ s H  owX54;  d  M  UPM     nnUR                  U5          O   U(       d  Ml  Un   O   U(       a  M  [        U 5      S:X  a  U R	                  5       $ [        U SS9$ s  snf )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``

TFr[   r{  )r8  rc   r   r   r   rq   rI   new_argsid1sid2r   new_seqri  s           r(   r  SeqAdd.reduce=  s     #D/ 'oFCz ffQiG */3#Gt!At#G 0 . 8#D * h" t9>88:$// $H   
B9B9c                 B   ^ [        U4S jU R                   5       5      $ )z9adds up the coefficients of all the sequences at point ptc              3   D   >#    U  H  oR                  T5      v   M     g 7fru   )rT   )r.  ri  rS   s     r(   r/  %SeqAdd._eval_coeff.<locals>.<genexpr>c  s     2	1772;;	s    )r~  rI   rR   s    `r(   rQ   SeqAdd._eval_coeffa  s    2		222r3   rE   N
r   r   r   r   r   r   r   r  rQ   r   rE   r3   r(   rq   rq     s'    8")H !0 !0F3r3   rq   c                   4    \ rS rSrSrS r\S 5       rS rSr	g)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                   ^ UR                  S[        R                  5      n[        U5      nU4S jmT" U5      nU(       d  [        R
                  $ [        S U 5       6 [        R                  L a  [        R
                  $ U(       a  [        R                  U5      $ [        [        U[        R                  5      5      n[        R                  " U /UQ76 $ )Nr{  c                    > [        U [        5      (       a8  [        U [        5      (       a   [        [	        TU R
                  5      / 5      $ U /$ [        U 5      (       a  [        [	        TU 5      / 5      $ [        S5      er}  )rn   r    r   r~  r  rI   r   ro   r  s    r(   r   SeqMul.__new__.<locals>._flatten  sk    #w''c6**s8SXX6;;5L#3x-r22 6 7 7r3   c              3   8   #    U  H  oR                   v   M     g 7fru   rn  rh  s     r(   r/  !SeqMul.__new__.<locals>.<genexpr>  r  r1  )r  r   r{  r  r   r   r   r   r   r  r   r    r)   r   r   )r   rI   r'  r{  r  s       @r(   r   SeqMul.__new__  s    ::j*;*D*DE Dz		7 ~ ??"3d34

B??" ==&&GD'"4"456}}S(4((r3   c                 |   SnU(       a  [        U 5       Hn  u  p#Sn[        U 5       HM  u  pEX$:X  a  M  UR                  U5      nUc  M"  U  Vs/ s H  owX54;  d  M  UPM     nnUR                  U5          O   U(       d  Ml  Un   O   U(       a  M  [        U 5      S:X  a  U R	                  5       $ [        U SS9$ s  snf )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[   r  )r8  rg   r   r   r   r   r  s           r(   r  SeqMul.reduce  s      #D/ 'oFCz ffQiG */3#Gt!At#G 0 . 8#D * h" t9>88:$// $Hr  c                 V    SnU R                    H  nX#R                  U5      -  nM     U$ )z<multiplies the coefficients of all the sequences at point ptr[   )rI   rT   )r/   rS   valri  s       r(   rQ   SeqMul._eval_coeff  s*    A772;C 
r3   rE   Nr  rE   r3   r(   r   r   f  s(     D )D $0 $0Lr3   r   ru   )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*  rc  re  rq   r   rE   r3   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r3   