ó
~9­\c           @   sň  d  d l  m Z e d  Z d  d l m Z d  d l m Z m Z d  d l Z d  d l	 Z	 d  d l
 m Z e r|d  d l m Z m Z m Z m Z m Z m Z d  d l
 m Z m Z m Z m Z m Z m Z m Z m Z d  d	 l m Z m Z m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z% m& Z& m' Z' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- m. Z. m/ Z/ m0 Z0 m1 Z1 m2 Z2 m3 Z3 m4 Z4 m5 Z5 m6 Z6 m7 Z7 m8 Z8 m9 Z9 m: Z: m; Z; m< Z< m= Z= m> Z> m? Z? m@ Z@ mA ZA mB ZB mC ZC mD ZD mE ZE mF ZF mG ZG d  d
 lH mI ZI mJ ZJ mK ZK mL ZL mM ZM mN ZN mO ZO d  d lP mQ ZQ mR ZR e d d f  d    ZS eN e  ZT e d  ZU eS   \ ZV ZW ZX n  d   ZY d   ZZ d   Z[ e d d f  e\ d   Z] e d d f  e\ d   Z^ e d d f  d    Z_ d S(   i˙˙˙˙(   t   import_modulet   matchpy(   t   doctest_depends_on(   t   Integert   FloatN(   t   powsimp(   t	   Operationt   CommutativeOperationt   AssociativeOperationt   ManyToOneReplacert   OneIdentityOperationt   CustomConstraint(   t   Powt   Addt   Integralt   Basict   Mult   St   Functiont   E(,   t   logt   sint   cost   tant   cott   csct   sect   sqrtt   erft   expt   gammat   acosht   asinht   atanht   acotht   acscht   asecht   cosht   sinht   tanht   cotht   secht   cscht   atant   acsct   asint   acott   acost   asect   fresnelst   fresnelct   erfct   erfit   Eit
   uppergammat   polylogt   zetat	   factorialt	   polygammat   digammat   lit   expintt   LambertWt   loggamma(   t   Gammat   rubi_expt   rubi_logt
   ProductLogt	   PolyGammat   rubi_unevaluated_exprt   process_trig(   t   op_itert   op_lent   modulesc          C   sE  d d l  m }  d d l m } d d l m } d d l m } d d l m	 } d d l
 m } d d l m } d d	 l m } d d
 l m } d d l m }	 d d l m }
 d d l m } d d l m } d d l m } d d l m } d d l m } d d l  m! } g  } g  } | |  |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} | |	 |  7} | |
 |  7} | | |  7} | | |  7} | | |  7} | | |  7} | | |  7} t" |   } | | | f S(   s9  
        Returns rubi ManyToOneReplacer by adding all rules from different modules.

        Uncomment the lines to add integration capabilities of that module.

        Currently, there are parsing issues with special_function,
        derivative and miscellaneous_integration. Hence they are commented.
        i˙˙˙˙(   t   integrand_simplification(   t   linear_products(   t   quadratic_products(   t   binomial_products(   t   trinomial_products(   t   miscellaneous_algebraic(   t   exponential(   t
   logarithms(   t   sine(   t   tangent(   t   secant(   t   miscellaneous_trig(   t   inverse_trig(   t
   hyperbolic(   t   inverse_hyperbolic(   t   special_functions(   t   miscellaneous_integration(#   t3   sympy.integrals.rubi.rules.integrand_simplificationRJ   t*   sympy.integrals.rubi.rules.linear_productsRK   t-   sympy.integrals.rubi.rules.quadratic_productsRL   t,   sympy.integrals.rubi.rules.binomial_productsRM   t-   sympy.integrals.rubi.rules.trinomial_productsRN   t2   sympy.integrals.rubi.rules.miscellaneous_algebraicRO   t&   sympy.integrals.rubi.rules.exponentialRP   t%   sympy.integrals.rubi.rules.logarithmsRQ   t   sympy.integrals.rubi.rules.sineRR   t"   sympy.integrals.rubi.rules.tangentRS   t!   sympy.integrals.rubi.rules.secantRT   t-   sympy.integrals.rubi.rules.miscellaneous_trigRU   t'   sympy.integrals.rubi.rules.inverse_trigRV   t%   sympy.integrals.rubi.rules.hyperbolicRW   t-   sympy.integrals.rubi.rules.inverse_hyperbolicRX   t,   sympy.integrals.rubi.rules.special_functionsRY   t4   sympy.integrals.rubi.rules.miscellaneous_integrationRZ   R	   (   RJ   RK   RL   RM   RN   RO   RP   RQ   RR   RS   RT   RU   RV   RW   RX   RY   RZ   t   rulest   rules_appliedt   rubi(    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   rubi_object   sL    
t	   Integratec           C   sk   t  j t  d  d k r t St  d t  d k o^ t  d k o^ t  d k o^ t  d k n rg t Sd  S(   Ni˙˙˙˙i   iţ˙˙˙iý˙˙˙iü˙˙˙iű˙˙˙(   Rm   t   countt   Falset   True(    (    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt
   _has_cycleM   s    Fc         C   sL   |  j  t  r$ |  j t t  }  n  |  j  t  rH |  j t t  }  n  |  S(   sű  
    When there is recursion for more than 10 rules or in total 20 rules have been applied
    rubi returns `Integrate` in order to stop any further matching. After complete integration,
    Integrate needs to be replaced back to Integral. Also rubi's `exp` need to be replaced back
    to sympy's general `exp`.

    Examples
    ========
    >>> from sympy import Function, E
    >>> from sympy.integrals.rubi.rubi import process_final_integral
    >>> from sympy.integrals.rubi.utility_function import rubi_unevaluated_expr
    >>> Integrate = Function("Integrate")
    >>> from sympy.abc import a, x
    >>> _E = rubi_unevaluated_expr(E)
    >>> process_final_integral(Integrate(a, x))
    Integral(a, x)
    >>> process_final_integral(_E**5)
    exp(5)

    (   t   hasRp   t   replaceR   t   _ER   (   t   expr(    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   process_final_integralS   s
    c         C   s   g  } g  } t  |  t  r~ xF |  j D]; } t  | t t t f  rS | j |  q% | j |  q% Wt t |    t |   S|  S(   s:  
    This function is needed to preprocess an expression as done in matchpy
    `x^a*x^b` in matchpy auotmatically transforms to `x^(a+b)`

    Examples
    ========

    >>> from sympy.integrals.rubi.rubi import rubi_powsimp
    >>> from sympy.abc import a, b, x
    >>> rubi_powsimp(x**a*x**b)
    x**(a+b)

    (   t
   isinstanceR   t   argsR   R   t   sym_expt   appendR   (   Rx   t   lst_powt   lst_non_powt   i(    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   rubi_powsimpn   s    c         C   sî   |  j  t t  }  g  t (t |   }  t |   }  t |  t t f  s[ t |  t	 t
 f  ri t |   | St |  t  rĆ d } x; |  j D]0 } g  t (| t j  t | |   7} g  t (q Wt |  St j  t |  |  d d } t |  S(   sW  
    Rule based algorithm for integration. Integrates the expression by applying
    transformation rules to the expression.

    Returns `Integrate` if an expression cannot be integrated.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration

    Returns Integral object if unable to integrate.
    i    t	   max_counti
   (   Rv   R|   R   Rm   RF   R   Rz   t   intR   t   floatR   R   R   R{   Rn   R   Ry   (   Rx   t   vart	   showstepst   resultst   ex(    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   rubi_integrate   s    *
c         C   sŘ   t  |   }  |  j t t  }  t |  t t f  sH t |  t t f  rV t	 |   | St |  t
  rr t |  |  St t  d k rŻ t   s t t  d k rŻ t |  |  Sn  t j t |  |  d d } g  t (| S(   Ni
   i   R   (   RF   Rv   R|   R   Rz   R   R   R   R   R   R   R   t   lenRm   Rt   Rp   Rn   R   (   Rx   R   R   R   (    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   util_rubi_integrate§   s    *c   	      C   sÁ   t  j } | j t |  |   } x | D] \ } } d GHt j |  GHt j |  \ } } d | f GHd j |  GHd GHt t	 j d | d  j
 d   } | j | d GH| GHd	 GHq( Wd S(
   s   
    Prints the list or rules which match to `expr`.

    Parameters
    ==========
    expr : integrand expression
    var : variable of integration
    s   Rule matching: s	   On line: s   
s   Pattern matching: s   ^\s*rule(\d+)i    i   N(    (   Rn   t   matchert   matchR   t   inspectt   getsourcefilet   getsourcelinest   joinR   t   ret   groupt   patterns(	   Rx   R   R   t   mitert   funt   et   codet   linenot   pattno(    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   get_matching_rule_definitionś   s    
	%(`   t   sympy.externalR    R   t   sympy.utilities.decoratorR   t
   sympy.coreR   R   R   R   t   sympyR   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   t   sympy.functionsR   R   R   R   R   R   R   R   R   R   R|   R   R   R    R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   R.   R/   R0   R1   R2   R3   R4   R5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   t%   sympy.integrals.rubi.utility_functionR@   RA   RB   RC   RD   RE   RF   t!   sympy.utilities.matchpy_connectorRG   RH   Ro   Rw   Rp   Rn   Rm   Rl   Rt   Ry   R   Rr   R   R   R   (    (    (    s8   lib/python2.7/site-packages/sympy/integrals/rubi/rubi.pyt   <module>   s0   .:˙ 43			