ó
”¼\c           @  sr   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   Z d   Z d S(	   i’’’’(   t   print_functiont   division(   t   Mul(   t
   DiracDeltat	   Heaviside(   t   default_sort_key(   t   Sc   	      C  sĆ  g  } d } |  j   \ } } t | d t } | j |  x | D] } | j r t | j t  r | j	 | j
 | j | j d   | j } n  | d k rĒ t | t  rĒ | j |  rĒ | } qD | j	 |  qD W| s³g  } x | D] } t | t  r"| j	 | j d t d |   qė | j rqt | j t  rq| j	 | j
 | j j d t d |  | j   qė | j	 |  qė W| | k r£t |   j   } n d } d | f S| t |   f S(   s  change_mul(node, x)

       Rearranges the operands of a product, bringing to front any simple
       DiracDelta expression.

       If no simple DiracDelta expression was found, then all the DiracDelta
       expressions are simplified (using DiracDelta.expand(diracdelta=True, wrt=x)).

       Return: (dirac, new node)
       Where:
         o dirac is either a simple DiracDelta expression or None (if no simple
           expression was found);
         o new node is either a simplified DiracDelta expressions or None (if it
           could not be simplified).

       Examples
       ========

       >>> from sympy import DiracDelta, cos
       >>> from sympy.integrals.deltafunctions import change_mul
       >>> from sympy.abc import x, y
       >>> change_mul(x*y*DiracDelta(x)*cos(x), x)
       (DiracDelta(x), x*y*cos(x))
       >>> change_mul(x*y*DiracDelta(x**2 - 1)*cos(x), x)
       (None, x*y*cos(x)*DiracDelta(x - 1)/2 + x*y*cos(x)*DiracDelta(x + 1)/2)
       >>> change_mul(x*y*DiracDelta(cos(x))*cos(x), x)
       (None, None)

       See Also
       ========

       sympy.functions.special.delta_functions.DiracDelta
       deltaintegrate
    t   keyi   t
   diracdeltat   wrtN(   t   Nonet   args_cnct   sortedR   t   extendt   is_Powt
   isinstancet   baseR   t   appendt   funct   expt	   is_simplet   expandt   TrueR   (	   t   nodet   xt   new_argst   diract   ct   nct   sorted_argst   argt   nnode(    (    s=   lib/python2.7/site-packages/sympy/integrals/deltafunctions.pyt
   change_mul	   s2    $#*	"4
c         C  sÄ  |  j  t  s d Sd d l m } m } d d l m } |  j t k r|  j	 d t
 d |  } | |  k rš |  j |  rt |  j  d k s£ |  j d d k r“ t |  j d  St |  j d |  j d d  |  j d j   j   SqqĄ| | |  } | Snŗ|  j s|  j rĄ|  j	   } |  | k rb| | |  } | d k	 r½t | |  r½| SqĄt |  |  \ } }	 | s|	 r½| |	 |  } | SqĄ| j	 d t
 d |  } | j rÜt | |  \ } }
 |	 |
 }	 n  | | j d |  d } t | j  d k rd n
 | j d } d } x | d k rµd | |	 j | |  j | |  } | t j k r| d 8} | d 7} q'| d k r| t | |  S| t | | d  Sq'Wt j Sn  d S(	   sÉ  
    deltaintegrate(f, x)

    The idea for integration is the following:

    - If we are dealing with a DiracDelta expression, i.e. DiracDelta(g(x)),
      we try to simplify it.

      If we could simplify it, then we integrate the resulting expression.
      We already know we can integrate a simplified expression, because only
      simple DiracDelta expressions are involved.

      If we couldn't simplify it, there are two cases:

      1) The expression is a simple expression: we return the integral,
         taking care if we are dealing with a Derivative or with a proper
         DiracDelta.

      2) The expression is not simple (i.e. DiracDelta(cos(x))): we can do
         nothing at all.

    - If the node is a multiplication node having a DiracDelta term:

      First we expand it.

      If the expansion did work, then we try to integrate the expansion.

      If not, we try to extract a simple DiracDelta term, then we have two
      cases:

      1) We have a simple DiracDelta term, so we return the integral.

      2) We didn't have a simple term, but we do have an expression with
         simplified DiracDelta terms, so we integrate this expression.

    Examples
    ========

        >>> from sympy.abc import x, y, z
        >>> from sympy.integrals.deltafunctions import deltaintegrate
        >>> from sympy import sin, cos, DiracDelta, Heaviside
        >>> deltaintegrate(x*sin(x)*cos(x)*DiracDelta(x - 1), x)
        sin(1)*cos(1)*Heaviside(x - 1)
        >>> deltaintegrate(y**2*DiracDelta(x - z)*DiracDelta(y - z), y)
        z**2*DiracDelta(x - z)*Heaviside(y - z)

    See Also
    ========

    sympy.functions.special.delta_functions.DiracDelta
    sympy.integrals.integrals.Integral
    i’’’’(   t   Integralt	   integrate(   t   solveR   R	   i   i    N(   t   hasR   R
   t   sympy.integralsR!   R"   t   sympy.solversR#   R   R   R   R   t   lent   argsR   t   as_polyt   LCt   is_MulR   R   R    t   difft   subsR   t   Zero(   t   fR   R!   R"   R#   t   ht   fht   gt	   deltatermt	   rest_multt   rest_mult_2t   pointt   nt   mt   r(    (    s=   lib/python2.7/site-packages/sympy/integrals/deltafunctions.pyt   deltaintegrateO   sT    5(	(&

N(   t
   __future__R    R   t
   sympy.coreR   t   sympy.functionsR   R   t   sympy.core.compatibilityR   t   sympy.core.singletonR   R    R:   (    (    (    s=   lib/python2.7/site-packages/sympy/integrals/deltafunctions.pyt   <module>   s   	F