ó
¡¼™\c           @  sj  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
 d  d l m Z d  d l m Z 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 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 „  Z& d „  Z' d e
 f d „  ƒ  YZ( d e( f d „  ƒ  YZ) d S(   iÿÿÿÿ(   t   print_functiont   division(   t   Add(   t   is_sequence(   t   Tuple(   t   Expr(   t   Mul(   t   Equalityt
   Relational(   t   S(   t   Symbolt   Dummy(   t   sympify(   t   piecewise_foldt	   Piecewise(   t   BooleanFunction(   t   Matrix(   t   Idx(   t   Interval(   t   flatten(   t   siftc         O  sÄ  t  | ƒ } t | d ƒ ra t | t ƒ ra | j } | j } t |  | | | Ž |  | | | Ž ƒ S| t j k rw t j S| r’ t | Œ  \ } } nT | j	 } t
 | ƒ d k rÀ t d | ƒ ‚ n  g  | D] }	 t |	 ƒ ^ qÇ d } } x2 |  t | ƒ k rt | j ƒ | } | j } qé Wi  }
 t g  | D] } | d ^ q+ƒ } x6 | j t ƒ D]% } | j | Œ  sTt ƒ  |
 | <qTqTW| j |
 ƒ } t | ƒ } | j d „  |
 j ƒ  Dƒ ƒ } | | | f S(   s™   Return either a special return value or the tuple,
    (function, limits, orientation). This code is common to
    both ExprWithLimits and AddWithLimits.t   funci   s   specify dummy variables for %si    c         S  s   i  |  ] \ } } | | “ q S(    (    (   t   .0t   kt   v(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pys
   <dictcomp>A   s   	 (   R   t   hasattrt
   isinstanceR   t   lhst   rhsR	   t   NaNt   _process_limitst   free_symbolst   lent
   ValueErrorR   t   typet   listt   limitst   functiont   sett   atomsR   t   hasR   t   xreplaceR   t   items(   t   clsR%   t   symbolst   assumptionsR   R   R$   t   orientationt   freet   st   repst   it   symbols_of_integrationt   p(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _common_new   s6    			&#c          G  s¡  g  } d } xˆ|  D]€} t  | t t f ƒ rX | j t ƒ j ƒ  } | | j ƒ  f } n  t  | t ƒ sy t | d t ƒ r÷ t  | t	 ƒ rÞ | j
 d
 k s¦ | j d
 k r¼ | j t | ƒ ƒ qñ | j t | | j
 | j ƒ ƒ q | j t | ƒ ƒ q n†t | t ƒ r}t t | ƒ ƒ } t  | d t t	 f ƒ sGt | d d t ƒ r}| d } t | ƒ d k r—t  | d t ƒ r—| d j | d j g | d )n  t | ƒ d k rø| d d
 k rÙ| d d
 k	 rÙ| d g } nm | d d
 k	 r| d d
 k r| d 9} | d g } n3 | d d
 k r<| d d
 k r<g  } n
 | d } | j t | | Œ ƒ t  | d t	 ƒ r | d j
 d
 k	 r¯t | d | d j
 k ƒ r¯t d ƒ ‚ n  | d j d
 k	 ròt | d | d j k ƒ ròt d ƒ ‚ qòq q qzt | ƒ d k s,t | ƒ d k rE| d d
 k rE| j t | ƒ ƒ q qzt | ƒ d k rz| j t | | d ƒ ƒ q qzq}n  t d	 t |  ƒ ƒ ‚ q W| | f S(   s  Process the list of symbols and convert them to canonical limits,
    storing them as Tuple(symbol, lower, upper). The orientation of
    the function is also returned when the upper limit is missing
    so (x, 1, None) becomes (x, None, 1) and the orientation is changed.
    i   t	   _diff_wrti    i   i   iÿÿÿÿs"   Summation exceeds Idx lower range.s"   Summation exceeds Idx upper range.s   Invalid limits given: %sN(   R   R   R   R'   R
   t   popt   as_sett   getattrt   FalseR   t   lowert   Nonet   uppert   appendR   R   R   R   R    R   t   startt   endt   boolR!   t   str(   R,   R$   R.   t   Vt   variablet	   newsymbolt   nlim(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyR   F   sV    !"/
%!  
 	
114t   ExprWithLimitsc           B  s†   e  Z d  g Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z d	 „  Z RS(
   t   is_commutativec   	      O  s©   t  |  | | | Ž } t | ƒ t k r9 | \ } } } n | St d „  | Dƒ ƒ rb t d ƒ ‚ n  t j |  |  } | g } | j | ƒ t | ƒ | _ | j	 | _	 | S(   Nc         s  s-   |  ]# } t  | ƒ d  k p$ d | k Vq d S(   i   N(   R    R<   (   R   t   l(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pys	   <genexpr>Œ   s    s:   ExprWithLimits requires values for lower and upper bounds.(
   R5   R"   t   tuplet   anyR!   R   t   __new__t   extendt   _argsRH   (	   R+   R%   R,   R-   t   preR$   t   _t   objt   arglist(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyRL   ƒ   s    	c         C  s   |  j  d S(   s%  Return the function applied across limits.

        Examples
        ========

        >>> from sympy import Integral
        >>> from sympy.abc import x
        >>> Integral(x**2, (x,)).function
        x**2

        See Also
        ========

        limits, variables, free_symbols
        i    (   RN   (   t   self(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyR%   —   s    c         C  s   |  j  d S(   s+  Return the limits of expression.

        Examples
        ========

        >>> from sympy import Integral
        >>> from sympy.abc import x, i
        >>> Integral(x**i, (i, 1, 3)).limits
        ((i, 1, 3),)

        See Also
        ========

        function, variables, free_symbols
        i   (   RN   (   RS   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyR$   ª   s    c         C  s   g  |  j  D] } | d ^ q
 S(   s^  Return a list of the limit variables.

        >>> from sympy import Sum
        >>> from sympy.abc import x, i
        >>> Sum(x**i, (i, 1, 3)).variables
        [i]

        See Also
        ========

        function, limits, free_symbols
        as_dummy : Rename dummy variables
        transform : Perform mapping on the dummy variable
        i    (   R$   (   RS   RI   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt	   variables½   s    c         C  s0   g  |  j  D]" } t | ƒ d k r
 | d ^ q
 S(   s­  Return only variables that are dummy variables.

        Examples
        ========

        >>> from sympy import Integral
        >>> from sympy.abc import x, i, j, k
        >>> Integral(x**i, (i, 1, 3), (j, 2), k).bound_symbols
        [i, j]

        See Also
        ========

        function, limits, free_symbols
        as_dummy : Rename dummy variables
        transform : Perform mapping on the dummy variable
        i   i    (   R$   R    (   RS   RI   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   bound_symbolsÏ   s    c         C  s£   |  j  |  j } } | j } x€ | D]x } t | ƒ d k rR | j | d ƒ q# n  | d | k rv | j | d ƒ n  x" | d D] } | j | j ƒ q Wq# W| S(   s4  
        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 Sum
        >>> from sympy.abc import x, y
        >>> Sum(x, (x, y, 1)).free_symbols
        {y}
        i   i    (   R%   R$   R   R    t   addt   removet   update(   RS   R%   R$   t   isymst   xabR2   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyR   ä   s    	c         C  s   |  j  S(   s7   Return True if the Sum has no free symbols, else False.(   R   (   RS   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt	   is_number  s    c         C  sT   g  |  j  D]+ } | d | k r& | n | | | f ^ q
 } |  j } |  j | | Œ S(   Ni    (   R$   R%   R   (   RS   t   xt   at   bR2   R$   t	   integrand(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_interval  s    ;	c         C  sÐ  d d l  m } m } |  j t |  j ƒ } } | j ƒ  t | t ƒ s^ | j	 j
 |  j	 ƒ rÛt } xÉ t | ƒ D]» \ } }	 d t |	 ƒ k rÃ | |	 d k rÃ | j r´ | f }	 qÃ | | f }	 n  t |	 d g  |	 d D] }
 |
 j | | ƒ ^ qØ Œ | | <t |	 d j	 j
 | j	 ƒ ƒ d k rq t } Pqq qq Wt | | ƒ sNt | | ƒ r½t |  j ƒ j
 t | j t ƒ ƒ ƒ } t |  j ƒ j
 t | j ƒ ƒ } | j | ƒ s´t d ƒ ‚ n  t } n  | r[| j | | ƒ } q[n€ x} t | ƒ D]o \ } }	 t |	 ƒ d k rèt |	 d g  |	 d D] }
 |
 j | | ƒ ^ qŒ | | <| |	 d k rWPqWqèqèWxX t | ƒ D]J \ } }	 t |	 ƒ d k rh|	 d |	 d j rht |	 d ƒ | | <qhqhW| j ƒ  |  j | | Œ S(   s  
        Perform substitutions over non-dummy variables
        of an expression with limits.  Also, can be used
        to specify point-evaluation of an abstract antiderivative.

        Examples
        ========

        >>> from sympy import Sum, oo
        >>> from sympy.abc import s, n
        >>> Sum(1/n**s, (n, 1, oo)).subs(s, 2)
        Sum(n**(-2), (n, 1, oo))

        >>> from sympy import Integral
        >>> from sympy.abc import x, a
        >>> Integral(a*x**2, x).subs(x, 4)
        Integral(a*x**2, (x, 4))

        See Also
        ========

        variables : Lists the integration variables
        transform : Perform mapping on the dummy variable for integrals
        change_index : Perform mapping on the sum and product dummy variables

        iÿÿÿÿ(   t   AppliedUndeft   UndefinedFunctioni   i    s.   substitution can not create dummy dependenciesi   i   (   t   sympy.core.functionRa   Rb   R%   R#   R$   t   reverseR   R
   R   t   intersectiont   Truet	   enumerateR    R6   R   t   _subsR:   R&   RT   R'   t   argst   issubsetR!   t   subst   is_zeroR   (   RS   t   oldt   newRa   Rb   R   R$   t   sub_into_funcR2   RZ   RI   t   sy2t   sy1(    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt
   _eval_subs  sD    
"	:%'!	:'
(   t   __name__t
   __module__t	   __slots__RL   t   propertyR%   R$   RT   RU   R   R[   R`   Rr   (    (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyRG   €   s   			t   AddWithLimitsc           B  sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sZ   Represents unevaluated oriented additions.
        Parent class for Integral and Sum.
    c   	      O  sˆ   t  |  | | | Ž } t | ƒ t k r9 | \ } } } n | St j |  |  } | | g } | j | ƒ t | ƒ | _ | j | _ | S(   N(   R5   R"   RJ   R   RL   RM   RN   RH   (	   R+   R%   R,   R-   RO   R$   R.   RQ   RR   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyRL   c  s    c         C  sK   t  g  t |  j ƒ D] } | j ^ q ƒ rG |  j |  j j ƒ  |  j Œ Sd  S(   N(   t   allR   R$   t   is_realR   R%   t   adjointR<   (   RS   R\   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_adjointr  s    +c         C  sK   t  g  t |  j ƒ D] } | j ^ q ƒ rG |  j |  j j ƒ  |  j Œ Sd  S(   N(   Rx   R   R$   Ry   R   R%   t	   conjugateR<   (   RS   R\   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_conjugatew  s    +c         C  sK   t  g  t |  j ƒ D] } | j ^ q ƒ rG |  j |  j j ƒ  |  j Œ Sd  S(   N(   Rx   R   R$   Ry   R   R%   t	   transposeR<   (   RS   R\   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_transpose|  s    +c           s  d t  ˆ  j ƒ k ry ˆ  j j |   } | j rt | j ‡  f d †  ƒ } t | t Œ  ˆ  j	 t | t
 Œ  ˆ  j Œ Sn‹ ˆ  j	 ˆ  j ˆ  j d d !Œ j ƒ  } | j ˆ  j d ƒ sØ ˆ  j	 d ˆ  j d g ƒ j ƒ  | St | t ƒ rˆ  j	 | ˆ  j d ƒ j ƒ  Sˆ  S(   Ni   c           s   |  j  o t ˆ  j ƒ |  j @S(   N(   RH   R&   RT   R   (   t   w(   RS   (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   <lambda>…  s   	i    iÿÿÿÿ(   R    R$   R%   t   factort   is_MulR   Ri   R   Rf   R   R:   R(   RT   t   doitR   (   RS   t   hintst   summandt   out(    (   RS   s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_factor  s    	 %$c         K  sÀ   |  j  j |   } | j rS | j rS t g  | j D] } |  j | |  j Œ ^ q1 Œ  S| j rš t	 j
 | j | j g  | j D] } |  j | |  j Œ ^ qx ƒ S| |  j  k r¼ |  j | |  j Œ S|  S(   N(   R%   t   expandt   is_AddRH   R   Ri   R   R$   t	   is_MatrixR   t   _newt   rowst   colst   _mat(   RS   R…   R†   R2   (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   _eval_expand_basic‘  s    /	,(	   Rs   Rt   t   __doc__RL   R{   R}   R   Rˆ   R   (    (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyRw   ^  s   					N(*   t
   __future__R    R   t   sympy.core.addR   t   sympy.core.compatibilityR   t   sympy.core.containersR   t   sympy.core.exprR   t   sympy.core.mulR   t   sympy.core.relationalR   R   t   sympy.core.singletonR	   t   sympy.core.symbolR
   R   t   sympy.core.sympifyR   t$   sympy.functions.elementary.piecewiseR   R   t   sympy.logic.boolalgR   t   sympy.matricesR   t   sympy.tensor.indexedR   t   sympy.sets.setsR   t   sympy.utilitiesR   t   sympy.utilities.iterablesR   R5   R   RG   Rw   (    (    (    s>   lib/python2.7/site-packages/sympy/concrete/expr_with_limits.pyt   <module>   s(   	0	:Þ