ó
~9­\c           @  sa  d  d l  m Z m Z d  d l m Z d  d l m Z d  d l m Z m	 Z	 m
 Z
 m Z m Z 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 d  d
 l m Z d  d l m Z d  d l m Z m Z d  d l m  Z  m! Z! 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. d  d l/ m0 Z0 d  d l1 m2 Z2 d e f d „  ƒ  YZ3 d e
 e e3 ƒ f d „  ƒ  YZ4 d e3 f d „  ƒ  YZ5 d e5 f d „  ƒ  YZ6 d e5 f d „  ƒ  YZ7 d e3 f d  „  ƒ  YZ8 e9 d! „ Z: d" e3 f d# „  ƒ  YZ; d$ e; f d% „  ƒ  YZ< d& e; f d' „  ƒ  YZ= d( S()   iÿÿÿÿ(   t   print_functiont   division(   t   Basic(   t   cacheit(   t   ranget   integer_typest   with_metaclasst   is_sequencet   iterablet   ordered(   t   Tuple(   t   call_highest_priority(   t   global_evaluate(   t   UndefinedFunction(   t   Mul(   t   Integer(   t   Eq(   t   St	   Singleton(   t   Dummyt   Symbolt   Wild(   t   sympify(   t   lcmt   factor(   t   Intervalt   Intersection(   t   simplify(   t   Idx(   t   flatten(   t   expandt   SeqBasec           B  s[  e  Z d  Z e 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 d „ Z# RS(   s   Base class for sequencesi   c         C  s7   y |  j  } Wn# t t t f k
 r2 t j } n X| S(   s[   Return start (if possible) else S.Infinity.

        adapted from Set._infimum_key
        (   t   startt   NotImplementedErrort   AttributeErrort
   ValueErrorR   t   Infinity(   t   exprR    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt
   _start_key$   s    c         C  s%   t  |  j | j ƒ } | j | j f S(   sT   Returns start and stop.

        Takes intersection over the two intervals.
        (   R   t   intervalt   inft   sup(   t   selft   otherR'   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   _intersect_interval1   s    c         C  s   t  d |  ƒ ‚ d S(   s&   Returns the generator for the sequences   (%s).genN(   R!   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   gen9   s    c         C  s   t  d |  ƒ ‚ d S(   s-   The interval on which the sequence is defineds   (%s).intervalN(   R!   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR'   >   s    c         C  s   t  d |  ƒ ‚ d S(   s:   The starting point of the sequence. This point is includeds
   (%s).startN(   R!   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR    C   s    c         C  s   t  d |  ƒ ‚ d S(   s8   The ending point of the sequence. This point is includeds	   (%s).stopN(   R!   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   stopH   s    c         C  s   t  d |  ƒ ‚ d S(   s   Length of the sequences   (%s).lengthN(   R!   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   lengthM   s    c         C  s   d S(   s-   Returns a tuple of variables that are bounded(    (    (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt	   variablesR   s    c           s   t  ‡  f d †  ˆ  j Dƒ ƒ S(   sG  
        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         3  s1   |  ]' } | j  j ˆ  j ƒ D] } | Vq q d  S(   N(   t   free_symbolst
   differenceR0   (   t   .0t   it   j(   R*   (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>e   s    (   t   sett   args(   R*   (    (   R*   s5   lib/python2.7/site-packages/sympy/series/sequences.pyR1   W   s    c         C  sG   | |  j  k  s | |  j k r: t d | |  j f ƒ ‚ n  |  j | ƒ S(   s#   Returns the coefficient at point pts   Index %s out of bounds %s(   R    R.   t
   IndexErrorR'   t   _eval_coeff(   R*   t   pt(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   coeffh   s    c         C  s   t  d |  j ƒ ‚ d  S(   Nsh   The _eval_coeff method should be added to%s to return coefficient so it is availablewhen coeff calls it.(   R!   t   func(   R*   R:   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9   o   s    c         C  sT   |  j  t j k r |  j } n	 |  j  } |  j  t j k rB d } n d } | | | S(   s†  Returns the i'th point of a sequence.

        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
        iÿÿÿÿi   (   R    R   t   NegativeInfinityR.   (   R*   R4   t   initialt   step(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt
   _ith_pointu   s    		c         C  s   d S(   s   
        Should only be used internally.

        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.
        N(   t   None(   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   _addž   s    c         C  s   d S(   s*  
        Should only be used internally.

        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.
        N(   RA   (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   _mul«   s    c         C  s   t  |  | ƒ S(   s¤  
        Should be used when ``other`` is not a sequence. Should be
        defined to define custom behaviour.

        Examples
        ========

        >>> from sympy import S, oo, SeqFormula
        >>> from sympy.abc import n
        >>> SeqFormula(n**2).coeff_mul(2)
        SeqFormula(2*n**2, (n, 0, oo))

        Notes
        =====

        '*' defines multiplication of sequences with sequences only.
        (   R   (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt	   coeff_mul¸   s    c         C  s5   t  | t ƒ s( t d t | ƒ ƒ ‚ n  t |  | ƒ S(   s;  Returns the term-wise addition of 'self' and 'other'.

        ``other`` should be a sequence.

        Examples
        ========

        >>> from sympy import S, oo, SeqFormula
        >>> from sympy.abc import n
        >>> SeqFormula(n**2) + SeqFormula(n**3)
        SeqFormula(n**3 + n**2, (n, 0, oo))
        s   cannot add sequence and %s(   t
   isinstanceR   t	   TypeErrort   typet   SeqAdd(   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __add__Ì   s    RI   c         C  s   |  | S(   N(    (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __radd__Ý   s    c         C  s6   t  | t ƒ s( t d t | ƒ ƒ ‚ n  t |  | ƒ S(   s:  Returns the term-wise subtraction of 'self' and 'other'.

        ``other`` should be a sequence.

        Examples
        ========

        >>> from sympy import S, oo, SeqFormula
        >>> from sympy.abc import n
        >>> SeqFormula(n**2) - (SeqFormula(n))
        SeqFormula(n**2 - n, (n, 0, oo))
        s   cannot subtract sequence and %s(   RE   R   RF   RG   RH   (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __sub__á   s    RK   c         C  s	   |  | S(   N(    (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __rsub__ò   s    c         C  s   |  j  d ƒ S(   sÚ   Negates the sequence.

        Examples
        ========

        >>> from sympy import S, oo, SeqFormula
        >>> from sympy.abc import n
        >>> -SeqFormula(n**2)
        SeqFormula(-n**2, (n, 0, oo))
        iÿÿÿÿ(   RD   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __neg__ö   s    c         C  s5   t  | t ƒ s( t d t | ƒ ƒ ‚ n  t |  | ƒ S(   s‚  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 S, oo, SeqFormula
        >>> from sympy.abc import n
        >>> SeqFormula(n**2) * (SeqFormula(n))
        SeqFormula(n**3, (n, 0, oo))
        s   cannot multiply sequence and %s(   RE   R   RF   RG   t   SeqMul(   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __mul__  s    RO   c         C  s   |  | S(   N(    (   R*   R+   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __rmul__  s    c         c  s;   x4 t  |  j ƒ D]# } |  j | ƒ } |  j | ƒ Vq Wd  S(   N(   R   R/   R@   R;   (   R*   R4   R:   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __iter__  s    c         C  s¼   t  | t ƒ r+ |  j | ƒ } |  j | ƒ St  | t ƒ r¸ | j | j } } | d  k rb d } n  | d  k rz |  j } n  g  t	 | | | j
 p’ d ƒ D] } |  j |  j | ƒ ƒ ^ q– Sd  S(   Ni    i   (   RE   R   R@   R;   t   sliceR    R.   RA   R/   R   R?   (   R*   t   indexR    R.   R4   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   __getitem__  s    	c         C  sÚ  d d l  m } g  |  |  D] } t t | ƒ ƒ ^ q } t | ƒ } | d k r^ | d } n t | | d ƒ } g  }	 xEt d | d ƒ D]0}
 d |
 } g  } x, t |
 ƒ D] } | j | | | |
 !ƒ q® W| | ƒ } | j	 ƒ  d k r‹ t | j
 | | |
 | !ƒ ƒ ƒ } | | k r9t | d d d … ƒ }	 Pn  g  } x3 t |
 | |
 ƒ D] } | j | | | |
 !ƒ qSW| | ƒ } | | | | | ƒ k r»t | d d d … ƒ }	 Pq»q‹ q‹ W| d k rÏ|	 St |	 ƒ }
 |
 d k rñg  d f S| |
 d | |
 d d |	 |
 d | |
 } } x t |
 d ƒ D]{ } | | | | | 7} xB t |
 | d ƒ D], } | |	 | | | | | | d 8} qhW| |	 | | | d 8} q7W|	 t t | ƒ t | ƒ ƒ f Sd S(   s›  
        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))
        iÿÿÿÿ(   t   Matrixi   i   i    N(   t   sympy.matricesRU   R   R   t   lenRA   t   minR   t   appendt   dett   LUsolveR   R   (   R*   t   nt   dt   gfvarRU   t   tt   xt   lxt   rt   coeffst   lt   l2t   mlistt   kt   mt   yR4   R5   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   find_linear_recurrence+  sJ    ")
"
5*N($   t   __name__t
   __module__t   __doc__t   Truet   is_commutativet   _op_priorityt   staticmethodR&   R,   t   propertyR-   R'   R    R.   R/   R0   R1   R   R;   R9   R@   RB   RC   RD   RI   R   RJ   RK   RL   RM   RO   RP   RQ   RT   RA   Rj   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR      s8   			)									t   EmptySequencec           B  s>   e  Z d  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   sÍ  Represents an empty sequence.

    The empty sequence is available as a
    singleton as ``S.EmptySequence``.

    Examples
    ========

    >>> from sympy import S, SeqPer, oo
    >>> from sympy.abc import x
    >>> S.EmptySequence
    EmptySequence()
    >>> SeqPer((1, 2), (x, 0, 10)) + S.EmptySequence
    SeqPer((1, 2), (x, 0, 10))
    >>> SeqPer((1, 2)) * S.EmptySequence
    EmptySequence()
    >>> S.EmptySequence.coeff_mul(-1)
    EmptySequence()
    c         C  s   t  j S(   N(   R   t   EmptySet(   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR'   ‹  s    c         C  s   t  j S(   N(   R   t   Zero(   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR/     s    c         C  s   |  S(   s"   See docstring of SeqBase.coeff_mul(    (   R*   R;   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRD   “  s    c         C  s
   t  g  ƒ S(   N(   t   iter(   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRQ   —  s    (   Rk   Rl   Rm   Rr   R'   R/   RD   RQ   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRs   v  s
   	t   SeqExprc           B  sh   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 RS(   s¯  Sequence expression class.

    Various sequences should inherit from this class.

    Examples
    ========

    >>> from sympy.series.sequences import SeqExpr
    >>> from sympy.abc import x
    >>> s = SeqExpr((1, 2, 3), (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         C  s   |  j  d S(   Ni    (   R7   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR-   ´  s    c         C  s#   t  |  j d d |  j d d ƒ S(   Ni   i   (   R   R7   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR'   ¸  s    c         C  s
   |  j  j S(   N(   R'   R(   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR    ¼  s    c         C  s
   |  j  j S(   N(   R'   R)   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR.   À  s    c         C  s   |  j  |  j d S(   Ni   (   R.   R    (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR/   Ä  s    c         C  s   |  j  d d f S(   Ni   i    (   R7   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR0   È  s    (
   Rk   Rl   Rm   Rr   R-   R'   R    R.   R/   R0   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRw   ›  s   t   SeqPerc           B  s\   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   sÝ  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
    c         C  s°  t  | ƒ } d „  } d	 \ } } } | d  k rP | | ƒ d t j } } } n  t | t ƒ r³ t | ƒ d k rƒ | \ } } } q³ t | ƒ d k r³ | | ƒ } | \ } } q³ n  t | t t	 f ƒ sá | d  k sá | d  k rú t
 d t | ƒ ƒ ‚ n  | t j k r'| t j k r't
 d ƒ ‚ n  t  | | | f ƒ } t | t ƒ rft  t t | ƒ ƒ ƒ } n t
 d | ƒ ‚ t | d | d ƒ t j k rt j St j |  | | ƒ S(
   Nc         S  s6   |  j  } t |  j  ƒ d k r( | j ƒ  St d ƒ Sd  S(   Ni   Rg   (   R1   RW   t   popR   (   t
   periodicalt   free(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   _find_x   s    	
i    i   i   s   Invalid limits given: %ss/   Both the start and end valuecannot be unboundeds6   invalid period %s should be something like e.g (1, 2) i   (   NNN(   R   RA   R   R$   R   R
   RW   RE   R   R   R#   t   strR=   t   tupleR   R   Rt   Rs   R   t   __new__(   t   clsRz   t   limitsR|   R`   R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR   ý  s.    	 .
 c         C  s   t  |  j ƒ S(   N(   RW   R-   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   period%  s    c         C  s   |  j  S(   N(   R-   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRz   )  s    c         C  s[   |  j  t j k r) |  j | |  j } n | |  j  |  j } |  j | j |  j d | ƒ S(   Ni    (   R    R   R=   R.   R‚   Rz   t   subsR0   (   R*   R:   t   idx(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9   -  s    c         C  sÄ   t  | t ƒ rÀ |  j |  j } } | j | j } } t | | ƒ } g  } xA t | ƒ D]3 } | | | }	 | | | }
 | j |	 |
 ƒ qW W|  j | ƒ \ } } t | |  j d | | f ƒ Sd S(   s   See docstring of SeqBase._addi    N(	   RE   Rx   Rz   R‚   R   R   RY   R,   R0   (   R*   R+   t   per1t   lper1t   per2t   lper2t
   per_lengtht   new_perR`   t   ele1t   ele2R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRB   4  s    c         C  sÄ   t  | t ƒ rÀ |  j |  j } } | j | j } } t | | ƒ } g  } xA t | ƒ D]3 } | | | }	 | | | }
 | j |	 |
 ƒ qW W|  j | ƒ \ } } t | |  j d | | f ƒ Sd S(   s   See docstring of SeqBase._muli    N(	   RE   Rx   Rz   R‚   R   R   RY   R,   R0   (   R*   R+   R…   R†   R‡   Rˆ   R‰   RŠ   R`   R‹   RŒ   R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRC   E  s    c         C  s@   t  | ƒ } g  |  j D] } | | ^ q } t | |  j d ƒ S(   s"   See docstring of SeqBase.coeff_muli   (   R   Rz   Rx   R7   (   R*   R;   R`   t   per(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRD   V  s     N(   Rk   Rl   Rm   RA   R   Rr   R‚   Rz   R9   RB   RC   RD   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRx   Í  s   .(			t
   SeqFormulac           B  sM   e  Z d  Z d d „ Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sa  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
    c         C  sv  t  | ƒ } d „  } d \ } } } | d  k rP | | ƒ d t j } } } n  t | t ƒ r³ t | ƒ d k rƒ | \ } } } q³ t | ƒ d k r³ | | ƒ } | \ } } q³ n  t | t t	 f ƒ sá | d  k sá | d  k rú t
 d t | ƒ ƒ ‚ n  | t j k r'| t j k r't
 d ƒ ‚ n  t  | | | f ƒ } t | d | d ƒ t j k rct j St j |  | | ƒ S(	   Nc         S  sI   |  j  } t | ƒ d k r% | j ƒ  S| s5 t d ƒ St d |  ƒ ‚ d  S(   Ni   Rg   s¦    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))(   R1   RW   Ry   R   R#   (   t   formulaR{   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR|   ˆ  s    	

i    i   i   s   Invalid limits given: %ss0   Both the start and end value cannot be unboundedi   (   NNN(   R   RA   R   R$   R   R
   RW   RE   R   R   R#   R}   R=   R   Rt   Rs   R   R   (   R€   R   R   R|   R`   R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR   …  s&    	 . c         C  s   |  j  S(   N(   R-   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR   ¬  s    c         C  s    |  j  d } |  j j | | ƒ S(   Ni    (   R0   R   Rƒ   (   R*   R:   R]   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9   °  s    c   	      C  s‚   t  | t ƒ r~ |  j |  j d } } | j | j d } } | | j | | ƒ } |  j | ƒ \ } } t | | | | f ƒ Sd S(   s   See docstring of SeqBase._addi    N(   RE   RŽ   R   R0   Rƒ   R,   (	   R*   R+   t   form1t   v1t   form2t   v2R   R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRB   ´  s    c   	      C  s‚   t  | t ƒ r~ |  j |  j d } } | j | j d } } | | j | | ƒ } |  j | ƒ \ } } t | | | | f ƒ Sd S(   s   See docstring of SeqBase._muli    N(   RE   RŽ   R   R0   Rƒ   R,   (	   R*   R+   R   R‘   R’   R“   R   R    R.   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRC   ½  s    c         C  s-   t  | ƒ } |  j | } t | |  j d ƒ S(   s"   See docstring of SeqBase.coeff_muli   (   R   R   RŽ   R7   (   R*   R;   R   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRD   Æ  s    N(   Rk   Rl   Rm   RA   R   Rr   R   R9   RB   RC   RD   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRŽ   ]  s   &'					t   RecursiveSeqc           B  sk   e  Z d  Z d	 d d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d „  Z
 e d „  ƒ Z RS(
   sF  A finite degree recursive sequence.

    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))`.

    y : function
        The name of the recursively defined sequence without argument, e.g.,
        :code:`y` if the recurrence function is :code:`y(n)`.

    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, [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

    i    c           s   t  ˆ t ƒ s' t d j ˆ ƒ ƒ ‚ n  t  | t ƒ sA | j rY t d j | ƒ ƒ ‚ n  t d d | f ƒ} d } | j ˆ ƒ } x  | D]˜ }	 t |	 j	 ƒ d k r´ t d ƒ ‚ n  |	 j	 d j
 | | ƒ | }
 |
 j ƒ  oð |
 j oð |
 d k  st d j |	 ƒ ƒ ‚ n  |
 | k rŠ |
 } qŠ qŠ W| s]g  t | ƒ D] } t d	 j | ƒ ƒ ^ q9} n  t | ƒ | k r~t d
 ƒ ‚ n  t | ƒ } t ˆ  ƒ ‰  t d „  | Dƒ Œ  } t j |  | ˆ | ƒ | ˆ  ƒ } ‡  ‡ f d †  t | ƒ Dƒ | _ ˆ  | _ | | _ ˆ | _ | | _ | | _ | S(   Ns=   recurrence sequence must be an undefined function, found `{}`s0   recurrence variable must be a symbol, found `{}`Rg   t   excludei    i   s)   Recurrence should be in a single variablesD   Recurrence should have constant, negative, integer shifts (found {})s   c_{}s)   Number of initial terms must equal degreec         s  s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R3   R`   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>=  s    c           s)   i  |  ] \ } } | ˆ ˆ  | ƒ “ q S(    (    (   R3   Rg   t   init(   R    Ri   (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys
   <dictcomp>A  s   	 (   RE   R   RF   t   formatR   t	   is_symbolR   t   findRW   R7   t   matcht   is_constantt
   is_integerR   R   R#   R   R   R
   R   t	   enumeratet   cachet   _startt   degreeRi   R\   t   _recurrence(   R€   t
   recurrenceRi   R\   R>   R    Rg   R    t   prev_yst   prev_yt   shiftt   seq(    (   R    Ri   s5   lib/python2.7/site-packages/sympy/series/sequences.pyR     sB    		!	1!"					c         C  s   |  j  S(   s:   The starting point of the sequence. This point is included(   RŸ   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR    J  s    c         C  s   t  j S(   s&   The ending point of the sequence. (oo)(   R   R$   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR.   O  s    c         C  s   |  j  t j f S(   s&   Interval on which sequence is defined.(   RŸ   R   R$   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR'   T  s    c         C  sÃ   | |  j  t |  j ƒ k  r0 |  j |  j | ƒ Sxu t t |  j ƒ | d ƒ D]W } |  j  | } |  j j i | |  j 6ƒ } | j |  j ƒ } | |  j |  j | ƒ <qM W|  j |  j |  j  | ƒ S(   Ni   (   RŸ   RW   Rž   Ri   R   R¡   t   xreplaceR\   (   R*   RS   t   currentt	   seq_indext   current_recurrencet   new_term(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9   Y  s    #c         c  s2   |  j  } x" t r- |  j | ƒ V| d 7} q Wd  S(   Ni   (   RŸ   Rn   R9   (   R*   RS   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRQ   h  s    		c         C  s   t  |  j |  j ƒ |  j ƒ S(   s   Equation defining recurrence.(   R   Ri   R\   R¡   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR¢   n  s    N(   Rk   Rl   Rm   RA   R   Rr   R    R.   R'   R9   RQ   R¢   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR”   Í  s   G4		c         C  s9   t  |  ƒ }  t |  t ƒ r( t |  | ƒ St |  | ƒ Sd S(   s   Returns appropriate sequence object.

    If ``seq`` is a sympy sequence, returns :class:`SeqPer` object
    otherwise returns :class:`SeqFormula` object.

    Examples
    ========

    >>> from sympy import sequence, SeqPer, SeqFormula
    >>> 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
    N(   R   R   R
   Rx   RŽ   (   R¦   R   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   sequencet  s    t	   SeqExprOpc           B  sh   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 RS(   sÜ  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         C  s   t  d „  |  j Dƒ ƒ S(   sj   Generator for the sequence.

        returns a tuple of generators of all the argument sequences.
        c         s  s   |  ] } | j  Vq d  S(   N(   R-   (   R3   t   a(    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>µ  s    (   R~   R7   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR-   ¯  s    c         C  s   t  d „  |  j Dƒ Œ  S(   se   Sequence is defined on the intersection
        of all the intervals of respective sequences
        c         s  s   |  ] } | j  Vq d  S(   N(   R'   (   R3   R®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>¼  s    (   R   R7   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR'   ·  s    c         C  s
   |  j  j S(   N(   R'   R(   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR    ¾  s    c         C  s
   |  j  j S(   N(   R'   R)   (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR.   Â  s    c         C  s)   t  t g  |  j D] } | j ^ q ƒ ƒ S(   s%   Cumulative of all the bound variables(   R~   R   R7   R0   (   R*   R®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR0   Æ  s    c         C  s   |  j  |  j d S(   Ni   (   R.   R    (   R*   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR/   Ë  s    (
   Rk   Rl   Rm   Rr   R-   R'   R    R.   R0   R/   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR­   —  s   RH   c           B  s/   e  Z d  Z d „  Z e d „  ƒ Z d „  Z RS(   s’  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 S, oo, SeqAdd, SeqPer, SeqFormula
    >>> from sympy.abc import n
    >>> SeqAdd(SeqPer((1, 2), (n, 0, oo)), S.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           sÓ   | j  d t d ƒ } t | ƒ } ‡  f d †  ‰  ˆ  | ƒ } g  | D] } | t j k	 rD | ^ qD } | sr t j St d „  | Dƒ Œ  t j k r˜ t j S| r« t j | ƒ St t	 | t
 j ƒ ƒ } t j |  | Œ S(   Nt   evaluatei    c           ss   t  |  t ƒ rA t  |  t ƒ r7 t t ˆ  |  j ƒ g  ƒ S|  g Sn  t |  ƒ rc t t ˆ  |  ƒ g  ƒ St d ƒ ‚ d  S(   Ns2   Input must be Sequences or  iterables of Sequences(   RE   R   RH   t   sumt   mapR7   R   RF   (   t   arg(   t   _flatten(    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR³   ô  s    
c         s  s   |  ] } | j  Vq d  S(   N(   R'   (   R3   R®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>  s    (   t   getR   t   listR   Rs   R   Rt   RH   t   reduceR	   R   R&   R   R   (   R€   R7   t   kwargsR¯   R®   (    (   R³   s5   lib/python2.7/site-packages/sympy/series/sequences.pyR   í  s    
(c         C  sü   t  } xÃ | rË x¶ t |  ƒ D]¨ \ } } t } xƒ t |  ƒ D]u \ } } | | k rY q; n  | j | ƒ } | d k	 r; g  |  D] } | | | f k r{ | ^ q{ } | j | ƒ Pq; q; W| r | }  Pq q Wq	 Wt |  ƒ d k rè |  j ƒ  St |  d t ƒSd S(   s  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``

        i   R¯   N(	   Rn   R   t   FalseRB   RA   RY   RW   Ry   RH   (   R7   t   new_argst   id1t   st   id2R_   t   new_seqR®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR¶     s$    	+
c           s   t  ‡  f d †  |  j Dƒ ƒ S(   s9   adds up the coefficients of all the sequences at point ptc         3  s   |  ] } | j  ˆ  ƒ Vq d  S(   N(   R;   (   R3   R®   (   R:   (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>7  s    (   R°   R7   (   R*   R:   (    (   R:   s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9   5  s    (   Rk   Rl   Rm   R   Rq   R¶   R9   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRH   Ð  s   	$$RN   c           B  s/   e  Z d  Z d „  Z e d „  ƒ Z d „  Z RS(   s   Represents term-wise multiplication of sequences.

    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 S, oo, SeqMul, SeqPer, SeqFormula
    >>> from sympy.abc import n
    >>> SeqMul(SeqPer((1, 2), (n, 0, oo)), S.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           s«   | j  d t d ƒ } t | ƒ } ‡  f d †  ‰  ˆ  | ƒ } | sJ t j St d „  | Dƒ Œ  t j k rp t j S| rƒ t j | ƒ St t	 | t
 j ƒ ƒ } t j |  | Œ S(   NR¯   i    c           ss   t  |  t ƒ rA t  |  t ƒ r7 t t ˆ  |  j ƒ g  ƒ S|  g Sn" t |  ƒ rc t t ˆ  |  ƒ g  ƒ St d ƒ ‚ d  S(   Ns2   Input must be Sequences or  iterables of Sequences(   RE   R   RN   R°   R±   R7   R   RF   (   R²   (   R³   (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR³   a  s    
c         s  s   |  ] } | j  Vq d  S(   N(   R'   (   R3   R®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pys	   <genexpr>q  s    (   R´   R   Rµ   R   Rs   R   Rt   RN   R¶   R	   R   R&   R   R   (   R€   R7   R·   R¯   (    (   R³   s5   lib/python2.7/site-packages/sympy/series/sequences.pyR   Z  s    
c         C  sü   t  } xÃ | rË x¶ t |  ƒ D]¨ \ } } t } xƒ t |  ƒ D]u \ } } | | k rY q; n  | j | ƒ } | d k	 r; g  |  D] } | | | f k r{ | ^ q{ } | j | ƒ Pq; q; W| r | }  Pq q Wq	 Wt |  ƒ d k rè |  j ƒ  St |  d t ƒSd S(   s  Simplify a :class:`SeqMul` 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``

        i   R¯   N(	   Rn   R   R¸   RC   RA   RY   RW   Ry   RN   (   R7   R¹   Rº   R»   R¼   R_   R½   R®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR¶   |  s$    	+
c         C  s1   d } x$ |  j  D] } | | j | ƒ 9} q W| S(   s<   multiplies the coefficients of all the sequences at point pti   (   R7   R;   (   R*   R:   t   valR®   (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyR9      s    (   Rk   Rl   Rm   R   Rq   R¶   R9   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyRN   :  s   	"$N(>   t
   __future__R    R   t   sympy.core.basicR   t   sympy.core.cacheR   t   sympy.core.compatibilityR   R   R   R   R   R	   t   sympy.core.containersR
   t   sympy.core.decoratorsR   t   sympy.core.evaluateR   t   sympy.core.functionR   t   sympy.core.mulR   t   sympy.core.numbersR   t   sympy.core.relationalR   t   sympy.core.singletonR   R   t   sympy.core.symbolR   R   R   t   sympy.core.sympifyR   t   sympy.polysR   R   t   sympy.sets.setsR   R   t   sympy.simplifyR   t   sympy.tensor.indexedR   t   sympy.utilities.iterablesR   t   sympyR   R   Rs   Rw   Rx   RŽ   R”   RA   R¬   R­   RH   RN   (    (    (    s5   lib/python2.7/site-packages/sympy/series/sequences.pyt   <module>   s<   .ÿ Y%2p§#9j