§
    OŠtj×Š  ã                   ó  — d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZ d dl m!Z!m"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+  G d„ de¦  «        Z, G d„ de,e¬¦  «        Z- G d„ de,¦  «        Z. G d„ de.¦  «        Z/ G d„ de.¦  «        Z0 G d„ de,¦  «        Z1d(d!„Z2 G d"„ d#e,¦  «        Z3 G d$„ d%e3¦  «        Z4 G d&„ d'e3¦  «        Z5d S ))é    )Ú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                   ó¨  — e Zd ZdZdZdZed„ ¦   «         Zd„ Ze	d„ ¦   «         Z
e	d„ ¦   «         Ze	d„ ¦   «         Ze	d	„ ¦   «         Ze	d
„ ¦   «         Ze	d„ ¦   «         Ze	d„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z ed¦  «        d„ ¦   «         Zd„ Z ed¦  «        d„ ¦   «         Zd„ Zd„ Z ed¦  «        d„ ¦   «         Zd„ Z d„ Z!d!d „Z"dS )"ÚSeqBasezBase class for sequencesTé   c                 óP   — 	 | j         }n# t          $ r t          j        }Y nw xY w|S )z[Return start (if possible) else S.Infinity.

        adapted from Set._infimum_key
        )ÚstartÚNotImplementedErrorr   ÚInfinity)Úexprr#   s     úT/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/series/sequences.pyÚ
_start_keyzSeqBase._start_key    s;   € ð	Ø”JˆEˆEøÝ"ð 	ð 	ð 	Ý”JˆEˆEˆEð	øøøàˆs   ‚
 Š#¢#c                 óR   — t          | j        |j        ¦  «        }|j        |j        fS )zTReturns start and stop.

        Takes intersection over the two intervals.
        )r   ÚintervalÚinfÚsup)ÚselfÚotherr*   s      r'   Ú_intersect_intervalzSeqBase._intersect_interval,   s&   € õ
   ¤¨u¬~Ñ>Ô>ˆØŒ|˜Xœ\Ð)Ð)ó    c                 ó&   — t          d| z  ¦  «        ‚)z&Returns the generator for the sequencez(%s).gen©r$   ©r-   s    r'   ÚgenzSeqBase.gen4   s   € õ " *¨tÑ"3Ñ4Ô4Ð4r0   c                 ó&   — t          d| z  ¦  «        ‚)z-The interval on which the sequence is definedz(%s).intervalr2   r3   s    r'   r*   zSeqBase.interval9   s   € õ " /°DÑ"8Ñ9Ô9Ð9r0   c                 ó&   — t          d| z  ¦  «        ‚)ú:The starting point of the sequence. This point is includedz
(%s).startr2   r3   s    r'   r#   zSeqBase.start>   s   € õ " ,°Ñ"5Ñ6Ô6Ð6r0   c                 ó&   — t          d| z  ¦  «        ‚)z8The ending point of the sequence. This point is includedz	(%s).stopr2   r3   s    r'   ÚstopzSeqBase.stopC   s   € õ " +°Ñ"4Ñ5Ô5Ð5r0   c                 ó&   — t          d| z  ¦  «        ‚)zLength of the sequencez(%s).lengthr2   r3   s    r'   ÚlengthzSeqBase.lengthH   s   € õ " -°$Ñ"6Ñ7Ô7Ð7r0   c                 ó   — dS )z-Returns a tuple of variables that are bounded© r=   r3   s    r'   Ú	variableszSeqBase.variablesM   s	   € ð ˆrr0   c                 ó*   ‡ — ˆ fd„‰ j         D ¦   «         S )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}
        c                 óX   •— h | ]&}|j                              ‰j        ¦  «        D ]}|’ŒŒ'S r=   )Úfree_symbolsÚ
differencer>   )Ú.0ÚiÚjr-   s      €r'   ú	<setcomp>z'SeqBase.free_symbols.<locals>.<setcomp>`   sI   ø€ ð 0ð 0ð 0�q¨q¬~ß’J˜tœ~Ñ.Ô.ð0ð 0¨!�ð 0ð 0ð 0ð 0r0   ©Úargsr3   s   `r'   rA   zSeqBase.free_symbolsR   s/   ø€ ð0ð 0ð 0ð 0˜DœIð 0ñ 0ô 0ð 	1r0   c                 óŒ   — || j         k     s|| j        k    rt          d|›d| j        ›�¦  «        ‚|                      |¦  «        S )z#Returns the coefficient at point ptzIndex z out of bounds )r#   r9   Ú
IndexErrorr*   Ú_eval_coeff©r-   Úpts     r'   ÚcoeffzSeqBase.coeffc   sJ   € ð �”
Š?ˆ?˜b 4¤9šn˜nÝ�*¸B¸B¸BÀÄÀÐNÑOÔOÐOØ×Ò Ñ#Ô#Ð#r0   c                 ó0   — t          d| j        z  ¦  «        ‚)NzhThe _eval_coeff method should be added to%s to return coefficient so it is availablewhen coeff calls it.)r$   ÚfuncrL   s     r'   rK   zSeqBase._eval_coeffj   s%   € Ý!ð #9ð %)¤Iñ#.ñ /ô /ð 	/r0   c                 ó†   — | j         t          j        u r| j        }n| j         }| j         t          j        u rd}nd}|||z  z   S )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   ÚNegativeInfinityr9   )r-   rD   ÚinitialÚsteps       r'   Ú
_ith_pointzSeqBase._ith_pointp   sP   € ð@ Œ:�Ô+Ð+Ð+Ø”iˆGˆGà”jˆGàŒ:�Ô+Ð+Ð+ØˆDˆDàˆDà˜˜4™ÑÐr0   c                 ó   — dS )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._addœ   ó	   € ð ˆtr0   c                 ó   — dS )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=   rY   s     r'   Ú_mulzSeqBase._mul¬   r[   r0   c                 ó"   — t          | |¦  «        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
   rY   s     r'   Ú	coeff_mulzSeqBase.coeff_mul¼   s   € õ$ �4˜ÑÔÐr0   c                 óŠ   — t          |t          ¦  «        st          dt          |¦  «        z  ¦  «        ‚t	          | |¦  «        S )a4  Returns 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ÚSeqAddrY   s     r'   Ú__add__zSeqBase.__add__Ð   sA   € õ ˜%¥Ñ)Ô)ð 	HÝÐ8½4À¹;¼;ÑFÑGÔGÐGÝ�d˜EÑ"Ô"Ð"r0   rf   c                 ó   — | |z   S ©Nr=   rY   s     r'   Ú__radd__zSeqBase.__radd__á   ó   € à�e‰|Ðr0   c                 óŒ   — t          |t          ¦  «        st          dt          |¦  «        z  ¦  «        ‚t	          | | ¦  «        S )a7  Returns 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 %sra   rY   s     r'   Ú__sub__zSeqBase.__sub__å   sC   € õ ˜%¥Ñ)Ô)ð 	MÝÐ=ÅÀUÁÄÑKÑLÔLÐLÝ�d˜U˜FÑ#Ô#Ð#r0   rl   c                 ó   — |  |z   S rh   r=   rY   s     r'   Ú__rsub__zSeqBase.__rsub__ö   s   € à�˜‰Ðr0   c                 ó,   — |                       d¦  «        S )zÓNegates the sequence.

        Examples
        ========

        >>> from sympy import SeqFormula
        >>> from sympy.abc import n
        >>> -SeqFormula(n**2)
        SeqFormula(-n**2, (n, 0, oo))
        rR   )r_   r3   s    r'   Ú__neg__zSeqBase.__neg__ú   s   € ð �~Š~˜bÑ!Ô!Ð!r0   c                 óŠ   — t          |t          ¦  «        st          dt          |¦  «        z  ¦  «        ‚t	          | |¦  «        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))
        zcannot multiply sequence and %s)rb   r    rc   rd   ÚSeqMulrY   s     r'   Ú__mul__zSeqBase.__mul__  sA   € õ ˜%¥Ñ)Ô)ð 	MÝÐ=ÅÀUÁÄÑKÑLÔLÐLÝ�d˜EÑ"Ô"Ð"r0   rs   c                 ó   — | |z  S rh   r=   rY   s     r'   Ú__rmul__zSeqBase.__rmul__  rj   r0   c              #   ó�   K  — t          | j        ¦  «        D ].}|                      |¦  «        }|                      |¦  «        V — Œ/d S rh   )Úranger;   rW   rN   )r-   rD   rM   s      r'   Ú__iter__zSeqBase.__iter__  sS   è è € Ý�t”{Ñ#Ô#ð 	!ð 	!ˆAØ—’ Ñ#Ô#ˆBØ—*’*˜R‘.”.Ð Ð Ð Ð ð	!ð 	!r0   c                 ó.  ‡ — t          |t          ¦  «        r*‰                      |¦  «        }‰                      |¦  «        S t          |t          ¦  «        r?|j        |j        }}|€d}|€‰ j        }ˆ fd„t          |||j	        pd¦  «        D ¦   «         S d S )Nr   c                 ó`   •— g | ]*}‰                      ‰                     |¦  «        ¦  «        ‘Œ+S r=   )rN   rW   )rC   rD   r-   s     €r'   ú
<listcomp>z'SeqBase.__getitem__.<locals>.<listcomp>,  s=   ø€ ð 9ð 9ð 9°q�D—J’J˜tŸš¨qÑ1Ô1Ñ2Ô2ð 9ð 9ð 9r0   rS   )
rb   ÚintrW   rN   Úslicer#   r9   r;   rw   rV   )r-   Úindexr#   r9   s   `   r'   Ú__getitem__zSeqBase.__getitem__"  s´   ø€ Ý�e�SÑ!Ô!ð 
	9Ø—O’O EÑ*Ô*ˆEØ—:’:˜eÑ$Ô$Ð$Ý˜�uÑ%Ô%ð 	9Øœ+ u¤z�4ˆEØˆ}Ø�Øˆ|Ø”{�ð9ð 9ð 9ð 9Ý˜%  u¤z °QÑ7Ô7ð9ñ 9ô 9ð 9ð	9ð 	9r0   Nc           
      óê  ‡— ddl mŠ ˆfd„| d|…         D ¦   «         }t          |¦  «        }|€|dz  }nt          ||dz  ¦  «        }g }t	          d|dz   ¦  «        D �]5}d|z  }	g }
t	          |¦  «        D ]"}|
                     ||||z   …         ¦  «         Œ#t          |
¦  «        }|                     ¦   «         dk    rÒ ‰|                     t          |||	…         ¦  «        ¦  «        ¦  «        }||	k    rt          |ddd…         ¦  «        } n�g }
t	          |||z
  ¦  «        D ]"}|
                     ||||z   …         ¦  «         Œ#t          |
¦  «        }||z  t          ||	d…         ¦  «        k    rt          |ddd…         ¦  «        } n�Œ7|€|S t          |¦  «        }|dk    rg dfS ||dz
           ||dz
  z  z  d||dz
           ||z  z  z
  }}t	          |dz
  ¦  «        D ]_}|||         ||z  z  z  }t	          ||z
  dz
  ¦  «        D ]"}|||         ||         z  |||z   dz   z  z  z  }Œ#|||         ||dz   z  z  z  }Œ`| ‰t          |¦  «        t          |¦  «        z  ¦  «        fS )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   )Úsimplifyc                 ó@   •— g | ]} ‰t          |¦  «        ¦  «        ‘ŒS r=   )r	   )rC   Útr�   s     €r'   r{   z2SeqBase.find_linear_recurrence.<locals>.<listcomp>R  s)   ø€ Ð3Ð3Ð3 QˆXˆX•f˜Q‘i”iÑ Ô Ð3Ð3Ð3r0   Né   rS   rR   )Úsympy.simplifyr�   ÚlenÚminrw   Úappendr   ÚdetÚLUsolver   r   )r-   ÚnÚdÚgfvarÚxÚlxÚrÚcoeffsÚlÚl2ÚmlistÚkÚmÚyrD   rE   r�   s                   @r'   Úfind_linear_recurrencezSeqBase.find_linear_recurrence/  sÌ  ø€ ðD 	,Ð+Ð+Ð+Ð+Ð+Ø3Ð3Ð3Ð3¨$¨r°¨r¬(Ð3Ñ3Ô3ˆÝ�‰VŒVˆØˆ9Ø�A‘ˆAˆAå�A�b˜!‘e‘”ˆAØˆÝ�q˜!˜A™#‘”ð 	ñ 	ˆAØ�1‘ˆBØˆEÝ˜1‘X”Xð 'ð '�Ø—’˜Q˜q  1¡˜uœXÑ&Ô&Ð&Ð&Ý�u‘”ˆAØ�uŠu‰wŒw˜!Š|ˆ|Ø�H˜QŸYšY¥v¨a°°"°¬g¡¤Ñ7Ô7Ñ8Ô8�Ø˜’8�8Ý$ Q t t¨ t¤WÑ-Ô-�FØ�EØ�Ý˜q  A¡™œð +ð +�AØ—L’L  1 Q q¡S 5¤Ñ*Ô*Ð*Ð*Ý˜5‘M”M�Ø�Q‘3�&  2 3 3¤™.œ.Ò(Ð(Ý$ Q t t¨ t¤WÑ-Ô-�FØ�EùØˆ=ØˆMå�F‘”ˆAØ�AŠvˆvØ˜4�x�à˜˜1™”v˜e a¨¡c™lÑ*¨A°°q¸±s´¸EÀ1¹HÑ0DÑ,D�1�Ý˜q ™s™œð 0ð 0�AØ˜˜1œ˜e Q™h™Ñ&�AÝ" 1 Q¡3 q¡5™\œ\ð ;ð ;˜Ø˜V AœY q¨¤t™^¨E°A°a±C¸±E©NÑ:Ñ:˜˜Ø˜ œ 5¨1¨Q©3¡<Ñ/Ñ/�A�AØ˜x˜x­¨q©	¬	µ&¸±)´)Ñ(;Ñ<Ô<Ð<Ð<r0   )NN)#Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_commutativeÚ_op_priorityÚstaticmethodr(   r/   Úpropertyr4   r*   r#   r9   r;   r>   rA   r   rN   rK   rW   rZ   r]   r_   rf   r   ri   rl   rn   rp   rs   ru   rx   r   r˜   r=   r0   r'   r    r       sY  € € € € € Ø"Ð"à€NØ€Làð	ð 	ñ „\ð	ð*ð *ð *ð ð5ð 5ñ „Xð5ð ð:ð :ñ „Xð:ð ð7ð 7ñ „Xð7ð ð6ð 6ñ „Xð6ð ð8ð 8ñ „Xð8ð ðð ñ „Xðð ð1ð 1ñ „Xð1ð  ð$ð $ñ „Wð$ð/ð /ð /ð* ð * ð * ðXð ð ð ð ð ð  ð  ð  ð(#ð #ð #ð" Ð˜9Ñ%Ô%ðð ñ &Ô%ðð$ð $ð $ð" Ð˜9Ñ%Ô%ðð ñ &Ô%ðð"ð "ð "ð#ð #ð #ð$ Ð˜9Ñ%Ô%ðð ñ &Ô%ðð!ð !ð !ð
9ð 9ð 9ðI=ð I=ð I=ð I=ð I=ð I=r0   r    c                   óJ   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ ZdS )ÚEmptySequenceaÌ  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                 ó   — t           j        S rh   )r   ÚEmptySetr3   s    r'   r*   zEmptySequence.interval�  s
   € åŒzÐr0   c                 ó   — t           j        S rh   )r   ÚZeror3   s    r'   r;   zEmptySequence.length“  s	   € åŒvˆr0   c                 ó   — | S )ú"See docstring of SeqBase.coeff_mulr=   )r-   rN   s     r'   r_   zEmptySequence.coeff_mul—  s   € àˆr0   c                 ó    — t          g ¦  «        S rh   )Úiterr3   s    r'   rx   zEmptySequence.__iter__›  s   € Ý�B‰xŒxˆr0   N)	r™   rš   r›   rœ   r    r*   r;   r_   rx   r=   r0   r'   r¢   r¢   z  sr   € € € € € ðð ð( ðð ñ „Xðð ðð ñ „Xððð ð ðð ð ð ð r0   r¢   )Ú	metaclassc                   ó–   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
dS )	ÚSeqExpraÙ  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                 ó   — | j         d         S ©Nr   rG   r3   s    r'   r4   zSeqExpr.gen¹  s   € àŒy˜Œ|Ðr0   c                 óf   — t          | j        d         d         | j        d         d         ¦  «        S )NrS   r„   )r   rH   r3   s    r'   r*   zSeqExpr.interval½  s&   € å˜œ	 !œ Qœ¨¬°1¬°a¬Ñ9Ô9Ð9r0   c                 ó   — | j         j        S rh   ©r*   r+   r3   s    r'   r#   zSeqExpr.startÁ  ó   € àŒ}Ô Ð r0   c                 ó   — | j         j        S rh   ©r*   r,   r3   s    r'   r9   zSeqExpr.stopÅ  r³   r0   c                 ó&   — | j         | j        z
  dz   S ©NrS   ©r9   r#   r3   s    r'   r;   zSeqExpr.lengthÉ  ó   € àŒy˜4œ:Ñ%¨Ñ)Ð)r0   c                 ó*   — | j         d         d         fS )NrS   r   rG   r3   s    r'   r>   zSeqExpr.variablesÍ  s   € à”	˜!”˜Q”Ð!Ð!r0   N)r™   rš   r›   rœ   r    r4   r*   r#   r9   r;   r>   r=   r0   r'   r­   r­   Ÿ  sÀ   € € € € € ðð ð2 ðð ñ „Xðð ð:ð :ñ „Xð:ð ð!ð !ñ „Xð!ð ð!ð !ñ „Xð!ð ð*ð *ñ „Xð*ð ð"ð "ñ „Xð"ð "ð "r0   r­   c                   ó^   — e Zd ZdZd
d„Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Z	d„ Z
d	„ ZdS )Ú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
    Nc                 ó:  — t          |¦  «        }d„ }d\  }}}|€ ||¦  «        dt          j        }}}t          |t          ¦  «        r=t          |¦  «        dk    r|\  }}}n#t          |¦  «        dk    r ||¦  «        }|\  }}t          |t          t          f¦  «        r|�|€t          dt          |¦  «        z  ¦  «        ‚|t          j        u r|t          j        u rt          d¦  «        ‚t          |||f¦  «        }t          |t          ¦  «        r*t          t          t          |¦  «        ¦  «        ¦  «        }nt          d|z  ¦  «        ‚t          |d	         |d         ¦  «        t          j        u rt          j        S t#          j        | ||¦  «        S )
Nc                 ó†   — | j         }t          | j         ¦  «        dk    r|                     ¦   «         S t          d¦  «        S )NrS   r•   )rA   r†   Úpopr   )Ú
periodicalÚfrees     r'   Ú_find_xzSeqPer.__new__.<locals>._find_x  s:   € ØÔ*ˆDÝ�:Ô*Ñ+Ô+¨qÒ0Ð0Ø—x’x‘z”zÐ!å˜S‘z”zÐ!r0   ©NNNr   é   r„   úInvalid limits given: %sz/Both the start and end valuecannot be unboundedz6invalid period %s should be something like e.g (1, 2) rS   )r   r   r%   r   r   r†   rb   r   r   Ú
ValueErrorÚstrrT   Útupler   r   r¤   r¢   r   Ú__new__)ÚclsrÀ   ÚlimitsrÂ   rŽ   r#   r9   s          r'   rÉ   zSeqPer.__new__  s¯  € Ý˜ZÑ(Ô(ˆ
ð	"ð 	"ð 	"ð *‰ˆˆ5�$Øˆ>Ø$˜W ZÑ0Ô0°!µQ´Z�dˆuˆAÝ�v�uÑ%Ô%ð 	%Ý�6‰{Œ{˜aÒÐØ!'‘��5˜$˜$Ý�V‘” Ò!Ð!Ø�G˜JÑ'Ô'�Ø$‘��tå˜!�f¥c˜]Ñ+Ô+ð 	G¨u¨}ÀÀÝÐ7½#¸f¹+¼+ÑEÑFÔFÐFà•AÔ&Ð&Ð&¨4µ1´:Ð+=Ð+=Ý ð "7ñ 8ô 8ð 8õ ˜!˜U DÐ)Ñ*Ô*ˆå�z¥5Ñ)Ô)ð 	>Ý ¥¥w¨zÑ':Ô':Ñ!;Ô!;Ñ<Ô<ˆJˆJåð 0Ø2<ñ=ñ >ô >ð >õ �F˜1”I˜v aœyÑ)Ô)­Q¬ZÐ7Ð7Ý”?Ð"åŒ}˜S *¨fÑ5Ô5Ð5r0   c                 ó*   — t          | j        ¦  «        S rh   )r†   r4   r3   s    r'   ÚperiodzSeqPer.period+  s   € å�4”8‰}Œ}Ðr0   c                 ó   — | j         S rh   ©r4   r3   s    r'   rÀ   zSeqPer.periodical/  ó	   € àŒxˆr0   c                 óÊ   — | j         t          j        u r| j        |z
  | j        z  }n|| j         z
  | j        z  }| j        |                              | j        d         |¦  «        S r¯   )r#   r   rT   r9   rÍ   rÀ   Úsubsr>   )r-   rM   Úidxs      r'   rK   zSeqPer._eval_coeff3  s\   € ØŒ:�Ô+Ð+Ð+Ø”9˜r‘> T¤[Ñ0ˆCˆCà˜œ
‘? d¤kÑ1ˆCØŒ˜sÔ#×(Ò(¨¬¸Ô):¸BÑ?Ô?Ð?r0   c                 óx  — t          |t          ¦  «        r¤| j        | j        }}|j        |j        }}t	          ||¦  «        }g }t          |¦  «        D ]0}|||z           }	|||z           }
|                     |	|
z   ¦  «         Œ1|                      |¦  «        \  }}t          || j        d         ||f¦  «        S dS ©zSee docstring of SeqBase._addr   N©	rb   r¼   rÀ   rÍ   r   rw   rˆ   r/   r>   ©r-   r.   Úper1Úlper1Úper2Úlper2Ú
per_lengthÚnew_perrŽ   Úele1Úele2r#   r9   s                r'   rZ   zSeqPer._add:  óÏ   € å�e�VÑ$Ô$ð 	EØœ/¨4¬;�%ˆDØÔ*¨E¬L�%ˆDå˜U EÑ*Ô*ˆJàˆGÝ˜:Ñ&Ô&ð ,ð ,�Ø˜A ™I”�Ø˜A ™I”�Ø—’˜t d™{Ñ+Ô+Ð+Ð+à×2Ò2°5Ñ9Ô9‰KˆE�4Ý˜' D¤N°1Ô$5°u¸dÐ#CÑDÔDÐDð	Eð 	Er0   c                 óx  — t          |t          ¦  «        r¤| j        | j        }}|j        |j        }}t	          ||¦  «        }g }t          |¦  «        D ]0}|||z           }	|||z           }
|                     |	|
z  ¦  «         Œ1|                      |¦  «        \  }}t          || j        d         ||f¦  «        S dS ©zSee docstring of SeqBase._mulr   NrÖ   r×   s                r'   r]   zSeqPer._mulK  rà   r0   c                 ó~   ‡— t          ‰¦  «        Šˆfd„| j        D ¦   «         }t          || j        d         ¦  «        S )r¨   c                 ó   •— g | ]}|‰z  ‘ŒS r=   r=   )rC   rŽ   rN   s     €r'   r{   z$SeqPer.coeff_mul.<locals>.<listcomp>_  s   ø€ Ð2Ð2Ð2˜Qˆq�5‰yÐ2Ð2Ð2r0   rS   )r   rÀ   r¼   rH   )r-   rN   Úpers    ` r'   r_   zSeqPer.coeff_mul\  s?   ø€ å˜‘”ˆØ2Ð2Ð2Ð2 $¤/Ð2Ñ2Ô2ˆÝ�c˜4œ9 Qœ<Ñ(Ô(Ð(r0   rh   )r™   rš   r›   rœ   rÉ   r    rÍ   rÀ   rK   rZ   r]   r_   r=   r0   r'   r¼   r¼   Ò  s¯   € € € € € ð.ð .ð`&6ð &6ð &6ð &6ðP ðð ñ „Xðð ðð ñ „Xðð@ð @ð @ðEð Eð Eð"Eð Eð Eð")ð )ð )ð )ð )r0   r¼   c                   óN   — e Zd ZdZd
d„Zed„ ¦   «         Zd„ Zd„ Zd„ Z	d„ Z
d	„ ZdS )Ú
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
    Nc                 ó˜  — t          |¦  «        }d„ }d\  }}}|€ ||¦  «        dt          j        }}}t          |t          ¦  «        r=t          |¦  «        dk    r|\  }}}n#t          |¦  «        dk    r ||¦  «        }|\  }}t          |t          t          f¦  «        r|�|€t          dt          |¦  «        z  ¦  «        ‚|t          j        u r|t          j        u rt          d¦  «        ‚t          |||f¦  «        }t          |d         |d         ¦  «        t          j        u rt          j        S t          j        | ||¦  «        S )	Nc                 ó¤   — | j         }t          |¦  «        dk    r|                     ¦   «         S |st          d¦  «        S t	          d| z  ¦  «        ‚)NrS   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)))rA   r†   r¿   r   rÆ   )ÚformularÁ   s     r'   rÂ   z#SeqFormula.__new__.<locals>._find_x�  s]   € ØÔ'ˆDÝ�4‰yŒy˜AŠ~ˆ~Ø—x’x‘z”zÐ!Øð Ý˜S‘z”zÐ!å ðOð ññô ð r0   rÃ   r   rÄ   r„   rÅ   z0Both the start and end value cannot be unboundedrS   )r   r   r%   r   r   r†   rb   r   r   rÆ   rÇ   rT   r   r¤   r¢   r   rÉ   )rÊ   rê   rË   rÂ   rŽ   r#   r9   s          r'   rÉ   zSeqFormula.__new__Œ  s[  € Ý˜'Ñ"Ô"ˆð	ð 	ð 	ð *‰ˆˆ5�$Øˆ>Ø$˜W WÑ-Ô-¨qµ!´*�dˆuˆAÝ�v�uÑ%Ô%ð 	%Ý�6‰{Œ{˜aÒÐØ!'‘��5˜$˜$Ý�V‘” Ò!Ð!Ø�G˜GÑ$Ô$�Ø$‘��tå˜!�f¥c˜]Ñ+Ô+ð 	G¨u¨}ÀÀÝÐ7½#¸f¹+¼+ÑEÑFÔFÐFà•AÔ&Ð&Ð&¨4µ1´:Ð+=Ð+=Ý ð "7ñ 8ô 8ð 8å˜!˜U DÐ)Ñ*Ô*ˆå�F˜1”I˜v aœyÑ)Ô)­Q¬ZÐ7Ð7Ý”?Ð"åŒ}˜S '¨6Ñ2Ô2Ð2r0   c                 ó   — | j         S rh   rÏ   r3   s    r'   rê   zSeqFormula.formula³  rÐ   r0   c                 óR   — | j         d         }| j                             ||¦  «        S r¯   )r>   rê   rÒ   )r-   rM   rŒ   s      r'   rK   zSeqFormula._eval_coeff·  s&   € ØŒN˜1ÔˆØŒ|× Ò   BÑ'Ô'Ð'r0   c                 ó  — t          |t          ¦  «        rl| j        | j        d         }}|j        |j        d         }}||                     ||¦  «        z   }|                      |¦  «        \  }}t          ||||f¦  «        S dS rÕ   ©rb   rç   rê   r>   rÒ   r/   ©	r-   r.   Úform1Úv1Úform2Úv2rê   r#   r9   s	            r'   rZ   zSeqFormula._add»  óˆ   € å�e�ZÑ(Ô(ð 	:Øœ d¤n°QÔ&7�2ˆEØœ u¤°qÔ'9�2ˆEØ˜eŸjšj¨¨RÑ0Ô0Ñ0ˆGØ×2Ò2°5Ñ9Ô9‰KˆE�4Ý˜g¨¨E°4Ð'8Ñ9Ô9Ð9ð	:ð 	:r0   c                 ó  — t          |t          ¦  «        rl| j        | j        d         }}|j        |j        d         }}||                     ||¦  «        z  }|                      |¦  «        \  }}t          ||||f¦  «        S dS râ   rî   rï   s	            r'   r]   zSeqFormula._mulÄ  rô   r0   c                 ój   — t          |¦  «        }| j        |z  }t          || j        d         ¦  «        S )r¨   rS   )r   rê   rç   rH   )r-   rN   rê   s      r'   r_   zSeqFormula.coeff_mulÍ  s/   € å˜‘”ˆØ”, Ñ&ˆÝ˜' 4¤9¨Q¤<Ñ0Ô0Ð0r0   c                 ó^   — t          t          | j        g|¢R i |¤Ž| j        d         ¦  «        S r·   )rç   r	   rê   rH   )r-   rH   Úkwargss      r'   r	   zSeqFormula.expandÓ  s2   € Ý�& ¤Ð?°Ð?Ð?Ð?¸Ð?Ð?ÀÄÈ1ÄÑNÔNÐNr0   rh   )r™   rš   r›   rœ   rÉ   r    rê   rK   rZ   r]   r_   r	   r=   r0   r'   rç   rç   c  sŸ   € € € € € ð&ð &ðP%3ð %3ð %3ð %3ðN ðð ñ „Xðð(ð (ð (ð:ð :ð :ð:ð :ð :ð1ð 1ð 1ðOð Oð Oð Oð Or0   rç   c                   óì   — e Zd ZdZdd„Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed	„ ¦   «         Z
ed
„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ ZdS )Ú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

    Nr   c                 ó,  ‡‡— t          |t          ¦  «        s"t          d                     |¦  «        ¦  «        ‚t          |t          ¦  «        r|j        s"t          d                     |¦  «        ¦  «        ‚|j        |fk    rt          d¦  «        ‚|j        Št          d|f¬¦  «        }d}| 	                    ‰¦  «        }|D ]Ÿ}	t          |	j        ¦  «        dk    rt          d¦  «        ‚|	j        d                              ||z   ¦  «        |         }
|
                     ¦   «         r|
j        r|
dk     s"t          d	                     |	¦  «        ¦  «        ‚|
 |k    r|
 }Œ |sd
„ t          |¦  «        D ¦   «         }t          |¦  «        |k    rt          d¦  «        ‚t!          |¦  «        }t#          ‰¦  «        Št%          d„ |D ¦   «         Ž }t	          j        | ||||‰¦  «        }ˆˆfd„t)          |¦  «        D ¦   «         |_        ||_        |S )NzErecurrence sequence must be an applied undefined function, found `{}`z0recurrence variable must be a symbol, found `{}`z)recurrence sequence does not match symbolr•   )Úexcluder   rS   z)Recurrence should be in a single variablezDRecurrence should have constant, negative, integer shifts (found {})c                 óR   — g | ]$}t          d                      |¦  «        ¦  «        ‘Œ%S )zc_{})r   Úformat)rC   r•   s     r'   r{   z(RecursiveSeq.__new__.<locals>.<listcomp>G  s,   € ÐFÐFÐF°1•u˜VŸ]š]¨1Ñ-Ô-Ñ.Ô.ÐFÐFÐFr0   z)Number of initial terms must equal degreec              3   ó4   K  — | ]}t          |¦  «        V — Œd S rh   r   )rC   rŽ   s     r'   ú	<genexpr>z'RecursiveSeq.__new__.<locals>.<genexpr>O  s(   è è € Ð6Ð6¨�' !™*œ*Ð6Ð6Ð6Ð6Ð6Ð6r0   c                 ó4   •— i | ]\  }} ‰‰|z   ¦  «        |“ŒS r=   r=   )rC   r•   Úinitr#   r—   s      €€r'   ú
<dictcomp>z(RecursiveSeq.__new__.<locals>.<dictcomp>S  s+   ø€ ÐJÐJÐJ©G¨A¨t�Q�Q�u˜q‘y‘\”\ 4ÐJÐJÐJr0   )rb   r   rc   rþ   r   Ú	is_symbolrH   rP   r   Úfindr†   ÚmatchÚis_constantÚ
is_integerrw   rÆ   r   r   r   rÉ   Ú	enumerateÚcacheÚdegree)rÊ   Ú
recurrenceÚynr‹   rU   r#   r•   r  Úprev_ysÚprev_yÚshiftÚseqr—   s        `      @r'   rÉ   zRecursiveSeq.__new__#  s6  øø€ Ý˜"�lÑ+Ô+ð 	7Ýð +ß+1ª6°"©:¬:ñ7ô 7ð 7õ ˜!�UÑ#Ô#ð 	6¨1¬;ð 	6Ýð +ß+1ª6°!©9¬9ñ6ô 6ð 6ð Œ7�q�dŠ?ˆ?ÝÐGÑHÔHÐHàŒGˆå�˜q˜dÐ#Ñ#Ô#ˆØˆð —/’/ !Ñ$Ô$ˆØð 	 ð 	 ˆFÝ�6”;ÑÔ 1Ò$Ð$ÝÐ KÑLÔLÐLà”K ”N×(Ò(¨¨Q©Ñ/Ô/°Ô2ˆEØ×%Ò%Ñ'Ô'ð >¨EÔ,<ð >ÀÈÂÀÝð !.ç.4ªf°V©n¬nñ>ô >ð >ð ˆv˜ŠˆØ˜�øàð 	GØFÐF½¸f¹¼ÐFÑFÔFˆGåˆw‰<Œ<˜6Ò!Ð!ÝÐHÑIÔIÐIå˜‘”ˆÝ˜‘”ˆåÐ6Ð6¨gÐ6Ñ6Ô6Ð7ˆåŒm˜C ¨R°°G¸UÑCÔCˆàJÐJÐJÐJÐJµyÀÑ7IÔ7IÐJÑJÔJˆŒ	ØˆŒ
àˆ
r0   c                 ó   — | j         d         S ©zEquation defining recurrence.r   rG   r3   s    r'   Ú_recurrencezRecursiveSeq._recurrenceX  ó   € ð Œy˜Œ|Ðr0   c                 óB   — t          | j        | j        d         ¦  «        S r  )r   r  rH   r3   s    r'   r  zRecursiveSeq.recurrence]  s   € õ �$”'˜4œ9 Qœ<Ñ(Ô(Ð(r0   c                 ó   — | j         d         S )z*Applied function representing the nth termrS   rG   r3   s    r'   r  zRecursiveSeq.ynb  r  r0   c                 ó   — | j         j        S )z3Undefined function for the nth term of the sequence)r  rP   r3   s    r'   r—   zRecursiveSeq.yg  s   € ð ŒwŒ|Ðr0   c                 ó   — | j         d         S )zSequence index symbolr„   rG   r3   s    r'   r‹   zRecursiveSeq.nl  r  r0   c                 ó   — | j         d         S )z"The initial values of the sequencerÄ   rG   r3   s    r'   rU   zRecursiveSeq.initialq  r  r0   c                 ó   — | j         d         S )r7   é   rG   r3   s    r'   r#   zRecursiveSeq.startv  r  r0   c                 ó   — t           j        S )z&The ending point of the sequence. (oo))r   r%   r3   s    r'   r9   zRecursiveSeq.stop{  s   € õ ŒzÐr0   c                 ó(   — | j         t          j        fS )z&Interval on which sequence is defined.)r#   r   r%   r3   s    r'   r*   zRecursiveSeq.interval€  s   € ð ”
�AœJÐ'Ð'r0   c                 óæ  — || j         z
  t          | j        ¦  «        k     r | j        |                      |¦  «                 S t	          t          | j        ¦  «        |dz   ¦  «        D ]d}| j         |z   }| j                             | j        |i¦  «        }|                     | j        ¦  «        }|| j        |                      |¦  «        <   Œe| j        |                      | j         |z   ¦  «                 S r·   )r#   r†   r
  r—   rw   r  Úxreplacer‹   )r-   r~   ÚcurrentÚ	seq_indexÚcurrent_recurrenceÚnew_terms         r'   rK   zRecursiveSeq._eval_coeff…  sÔ   € Ø�4”:Ñ¥ D¤J¡¤Ò/Ð/Ø”:˜dŸfšf U™mœmÔ,Ð,å�S ¤™_œ_¨e°a©iÑ8Ô8ð 	5ð 	5ˆGð œ
 WÑ,ˆIØ!%Ô!1×!:Ò!:¸D¼FÀIÐ;NÑ!OÔ!OÐØ)×2Ò2°4´:Ñ>Ô>ˆHà,4ˆDŒJ�t—v’v˜iÑ(Ô(Ñ)Ð)àŒz˜$Ÿ&š& ¤¨gÑ!5Ñ6Ô6Ô7Ð7r0   c              #   óP   K  — | j         }	 |                      |¦  «        V — |dz  }Œ)NTrS   )r#   rK   )r-   r~   s     r'   rx   zRecursiveSeq.__iter__”  s:   è è € Ø”
ˆð	Ø×"Ò" 5Ñ)Ô)Ð)Ð)Ð)Ø�Q‰JˆEð	r0   r¯   )r™   rš   r›   rœ   rÉ   r    r  r  r  r—   r‹   rU   r#   r9   r*   rK   rx   r=   r0   r'   rú   rú   Ö  sG  € € € € € ðJð JðX3ð 3ð 3ð 3ðj ðð ñ „Xðð ð)ð )ñ „Xð)ð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ðð ñ „Xðð ð(ð (ñ „Xð(ð8ð 8ð 8ðð ð ð ð r0   rú   Nc                 óŠ   — t          | ¦  «        } t          | t          ¦  «        rt          | |¦  «        S t	          | |¦  «        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
    )r   r   r   r¼   rç   )r  rË   s     r'   Úsequencer'  ›  sA   € õ4 �#‰,Œ,€Cå�3�ÑÔð 'Ý�c˜6Ñ"Ô"Ð"å˜#˜vÑ&Ô&Ð&r0   c                   ó–   — e Zd ZdZed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Zed„ ¦   «         Z	ed„ ¦   «         Z
dS )	Ú	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                 ó>   — t          d„ | j        D ¦   «         ¦  «        S )zjGenerator for the sequence.

        returns a tuple of generators of all the argument sequences.
        c              3   ó$   K  — | ]}|j         V — Œd S rh   rÏ   ©rC   Úas     r'   r   z SeqExprOp.gen.<locals>.<genexpr>á  s$   è è € Ð.Ð.˜q�Q”UÐ.Ð.Ð.Ð.Ð.Ð.r0   )rÈ   rH   r3   s    r'   r4   zSeqExprOp.genÛ  s#   € õ Ð.Ð. D¤IÐ.Ñ.Ô.Ñ.Ô.Ð.r0   c                 ó2   — t          d„ | j        D ¦   «         Ž S )zeSequence is defined on the intersection
        of all the intervals of respective sequences
        c              3   ó$   K  — | ]}|j         V — Œd S rh   ©r*   r,  s     r'   r   z%SeqExprOp.interval.<locals>.<genexpr>è  s$   è è € Ð<Ð<¨Q˜aœjÐ<Ð<Ð<Ð<Ð<Ð<r0   )r   rH   r3   s    r'   r*   zSeqExprOp.intervalã  s    € õ
 Ð<Ð<°$´)Ð<Ñ<Ô<Ð=Ð=r0   c                 ó   — | j         j        S rh   r²   r3   s    r'   r#   zSeqExprOp.startê  r³   r0   c                 ó   — | j         j        S rh   rµ   r3   s    r'   r9   zSeqExprOp.stopî  r³   r0   c                 óX   — t          t          d„ | j        D ¦   «         ¦  «        ¦  «        S )z%Cumulative of all the bound variablesc                 ó   — g | ]	}|j         ‘Œ
S r=   )r>   r,  s     r'   r{   z'SeqExprOp.variables.<locals>.<listcomp>õ  s   € Ð=Ð=Ð=¨a˜aœkÐ=Ð=Ð=r0   )rÈ   r   rH   r3   s    r'   r>   zSeqExprOp.variablesò  s+   € õ •WÐ=Ð=°4´9Ð=Ñ=Ô=Ñ>Ô>Ñ?Ô?Ð?r0   c                 ó&   — | j         | j        z
  dz   S r·   r¸   r3   s    r'   r;   zSeqExprOp.length÷  r¹   r0   N)r™   rš   r›   rœ   r    r4   r*   r#   r9   r>   r;   r=   r0   r'   r)  r)  Â  sÃ   € € € € € ðð ð0 ð/ð /ñ „Xð/ð ð>ð >ñ „Xð>ð ð!ð !ñ „Xð!ð ð!ð !ñ „Xð!ð ð@ð @ñ „Xð@ð ð*ð *ñ „Xð*ð *ð *r0   r)  c                   ó4   — e Zd ZdZd„ Zed„ ¦   «         Zd„ ZdS )re   aš  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                 ó¶  ‡— |                      dt          j        ¦  «        }t          |¦  «        }ˆfd„Š ‰|¦  «        }d„ |D ¦   «         }|st          j        S t          d„ |D ¦   «         Ž t          j        u rt          j        S |rt           	                    |¦  «        S t          t          |t          j        ¦  «        ¦  «        }t          j        | g|¢R Ž S )NÚevaluatec                 ó  •— t          | t          ¦  «        r;t          | t          ¦  «        r#t          t	          ‰| j        ¦  «        g ¦  «        S | gS t          | ¦  «        rt          t	          ‰| ¦  «        g ¦  «        S t          d¦  «        ‚©Nz2Input must be Sequences or  iterables of Sequences)rb   r    re   ÚsumÚmaprH   r   rc   ©ÚargÚ_flattens    €r'   r?  z SeqAdd.__new__.<locals>._flatten   s‰   ø€ Ý˜#�wÑ'Ô'ð !Ý˜c¥6Ñ*Ô*ð !Ý�s 8¨S¬XÑ6Ô6¸Ñ;Ô;Ð;à˜5�LÝ˜‰}Œ}ð 3Ý�3˜x¨Ñ-Ô-¨rÑ2Ô2Ð2Ýð 6ñ 7ô 7ð 7r0   c                 ó.   — g | ]}|t           j        u¯|‘ŒS r=   )r   r¢   r,  s     r'   r{   z"SeqAdd.__new__.<locals>.<listcomp>,  s$   € Ð<Ð<Ð<�a 1­A¬OÐ#;Ð#;�Ð#;Ð#;Ð#;r0   c              3   ó$   K  — | ]}|j         V — Œd S rh   r0  r,  s     r'   r   z!SeqAdd.__new__.<locals>.<genexpr>2  ó$   è è € Ð3Ð3¨˜!œ*Ð3Ð3Ð3Ð3Ð3Ð3r0   )Úgetr   r8  Úlistr   r¢   r   r¤   re   Úreducer   r    r(   r   rÉ   ©rÊ   rH   rø   r8  r?  s       @r'   rÉ   zSeqAdd.__new__  së   ø€ Ø—:’:˜jÕ*;Ô*DÑEÔEˆõ �D‰zŒzˆð		7ð 		7ð 		7ð 		7ð 		7ð ˆx˜‰~Œ~ˆà<Ð<˜4Ð<Ñ<Ô<ˆð ð 	#Ý”?Ð"åÐ3Ð3¨dÐ3Ñ3Ô3Ð4½¼
ÐBÐBÝ”?Ð"ð ð 	'Ý—=’= Ñ&Ô&Ð&å•G˜D¥'Ô"4Ñ5Ô5Ñ6Ô6ˆåŒ}˜SÐ( 4Ð(Ð(Ð(Ð(r0   c                 ón  ‡‡— d}|rxt          | ¦  «        D ]f\  }Šd}t          | ¦  «        D ]I\  }Š||k    rŒ‰                     ‰¦  «        }|�&ˆˆfd„| D ¦   «         }|                     |¦  «          nŒJ|r|}  nŒg|°xt          | ¦  «        dk    r|                      ¦   «         S t          | d¬¦  «        S )a  Simplify :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``

        TFNc                 ó    •— g | ]
}|‰‰fv¯|‘ŒS r=   r=   ©rC   r-  Úsrƒ   s     €€r'   r{   z!SeqAdd.reduce.<locals>.<listcomp>U  ó"   ø€ Ð#GÐ#GÐ#G¨!°qÀÀAÀ°° A°°°r0   rS   ©r8  )r	  rZ   rˆ   r†   r¿   re   ©rH   Únew_argsÚid1Úid2Únew_seqrJ  rƒ   s        @@r'   rE  zSeqAdd.reduce=  sú   øø€ ð ˆØð 	Ý# D™/œ/ð ð ‘��QØ �Ý'¨™oœoð 	ð 	‘F�C˜Ø˜c’z�zØ ØŸfšf Q™iœi�Gð Ð*Ø#GÐ#GÐ#GÐ#GÐ#G¨tÐ#GÑ#GÔ#G˜Ø Ÿš¨Ñ0Ô0Ð0Ø˜ð +ð ð Ø#�DØ�Eðð ð 	õ" ˆt‰9Œ9˜Š>ˆ>Ø—8’8‘:”:Ðå˜$¨Ð/Ñ/Ô/Ð/r0   c                 óD   ‡— t          ˆfd„| j        D ¦   «         ¦  «        S )z9adds up the coefficients of all the sequences at point ptc              3   óB   •K  — | ]}|                      ‰¦  «        V — Œd S rh   )rN   )rC   r-  rM   s     €r'   r   z%SeqAdd._eval_coeff.<locals>.<genexpr>c  s-   øè è € Ð2Ð2 1�1—7’7˜2‘;”;Ð2Ð2Ð2Ð2Ð2Ð2r0   )r;  rH   rL   s    `r'   rK   zSeqAdd._eval_coeffa  s(   ø€ åÐ2Ð2Ð2Ð2¨¬	Ð2Ñ2Ô2Ñ2Ô2Ð2r0   N©r™   rš   r›   rœ   rÉ   rŸ   rE  rK   r=   r0   r'   re   re   ü  sY   € € € € € ðð ð8")ð ")ð ")ðH ð!0ð !0ñ „\ð!0ðF3ð 3ð 3ð 3ð 3r0   re   c                   ó4   — e Zd ZdZd„ Zed„ ¦   «         Zd„ ZdS )rr   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                 óž  ‡— |                      dt          j        ¦  «        }t          |¦  «        }ˆfd„Š ‰|¦  «        }|st          j        S t          d„ |D ¦   «         Ž t          j        u rt          j        S |rt           	                    |¦  «        S t          t          |t          j        ¦  «        ¦  «        }t          j        | g|¢R Ž S )Nr8  c                 ó  •— t          | t          ¦  «        r;t          | t          ¦  «        r#t          t	          ‰| j        ¦  «        g ¦  «        S | gS t          | ¦  «        rt          t	          ‰| ¦  «        g ¦  «        S t          d¦  «        ‚r:  )rb   r    rr   r;  r<  rH   r   rc   r=  s    €r'   r?  z SeqMul.__new__.<locals>._flatten�  s‰   ø€ Ý˜#�wÑ'Ô'ð 3Ý˜c¥6Ñ*Ô*ð !Ý�s 8¨S¬XÑ6Ô6¸Ñ;Ô;Ð;à˜5�LÝ˜#‘”ð 3Ý�3˜x¨Ñ-Ô-¨rÑ2Ô2Ð2Ýð 6ñ 7ô 7ð 7r0   c              3   ó$   K  — | ]}|j         V — Œd S rh   r0  r,  s     r'   r   z!SeqMul.__new__.<locals>.<genexpr>   rB  r0   )rC  r   r8  rD  r   r¢   r   r¤   rr   rE  r   r    r(   r   rÉ   rF  s       @r'   rÉ   zSeqMul.__new__‰  sØ   ø€ Ø—:’:˜jÕ*;Ô*DÑEÔEˆõ �D‰zŒzˆð		7ð 		7ð 		7ð 		7ð 		7ð ˆx˜‰~Œ~ˆð ð 	#Ý”?Ð"åÐ3Ð3¨dÐ3Ñ3Ô3Ð4½¼
ÐBÐBÝ”?Ð"ð ð 	'Ý—=’= Ñ&Ô&Ð&å•G˜D¥'Ô"4Ñ5Ô5Ñ6Ô6ˆåŒ}˜SÐ( 4Ð(Ð(Ð(Ð(r0   c                 ón  ‡‡— d}|rxt          | ¦  «        D ]f\  }Šd}t          | ¦  «        D ]I\  }Š||k    rŒ‰                     ‰¦  «        }|�&ˆˆfd„| D ¦   «         }|                     |¦  «          nŒJ|r|}  nŒg|°xt          | ¦  «        dk    r|                      ¦   «         S t          | d¬¦  «        S )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``

        TFNc                 ó    •— g | ]
}|‰‰fv¯|‘ŒS r=   r=   rI  s     €€r'   r{   z!SeqMul.reduce.<locals>.<listcomp>Æ  rK  r0   rS   rL  )r	  r]   rˆ   r†   r¿   rr   rM  s        @@r'   rE  zSeqMul.reduce«  sú   øø€ ð  ˆØð 	Ý# D™/œ/ð ð ‘��QØ �Ý'¨™oœoð 	ð 	‘F�C˜Ø˜c’z�zØ ØŸfšf Q™iœi�Gð Ð*Ø#GÐ#GÐ#GÐ#GÐ#G¨tÐ#GÑ#GÔ#G˜Ø Ÿš¨Ñ0Ô0Ð0Ø˜ð +ð ð Ø#�DØ�Eðð ð 	õ" ˆt‰9Œ9˜Š>ˆ>Ø—8’8‘:”:Ðå˜$¨Ð/Ñ/Ô/Ð/r0   c                 óN   — d}| j         D ]}||                     |¦  «        z  }Œ|S )z<multiplies the coefficients of all the sequences at point ptrS   )rH   rN   )r-   rM   Úvalr-  s       r'   rK   zSeqMul._eval_coeffÒ  s3   € àˆØ”ð 	ð 	ˆAØ�1—7’7˜2‘;”;ÑˆCˆCØˆ
r0   NrT  r=   r0   r'   rr   rr   f  sZ   € € € € € ð ð  ðD )ð  )ð  )ðD ð$0ð $0ñ „\ð$0ðLð ð ð ð r0   rr   rh   )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'  r)  re   rr   r=   r0   r'   ú<module>ro     s[  ðØ "Ð "Ð "Ð "Ð "Ð "Ø $Ð $Ð $Ð $Ð $Ð $Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø $Ð $Ð $Ð $Ð $Ð $Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø &Ð &Ð &Ð &Ð &Ð &Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø &Ð &Ð &Ð &Ð &Ð &Ø !Ð !Ð !Ð !Ð !Ð !Ø #Ð #Ð #Ð #Ð #Ð #Ð #Ð #Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø $Ð $Ð $Ð $Ð $Ð $Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ DÐ Dð^=ð ^=ð ^=ð ^=ð ^=ˆeñ ^=ô ^=ð ^=ð@"ð "ð "ð "ð "�G yð "ñ "ô "ð "ðJ0"ð 0"ð 0"ð 0"ð 0"ˆgñ 0"ô 0"ð 0"ðfN)ð N)ð N)ð N)ð N)ˆWñ N)ô N)ð N)ðbqOð qOð qOð qOð qO�ñ qOô qOð qOðfBð Bð Bð Bð B�7ñ Bô Bð BðJ'ð 'ð 'ð 'ðN7*ð 7*ð 7*ð 7*ð 7*�ñ 7*ô 7*ð 7*ðtg3ð g3ð g3ð g3ð g3ˆYñ g3ô g3ð g3ðTqð qð qð qð qˆYñ qô qð qð qð qr0   