a
    RG5d:                    @   s  d Z ddl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mZmZmZmZ ddlmZ ddlmZmZmZ ddlm Z m!Z!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- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9 ddl:m;Z;m<Z<m=Z= ddl>m?Z? ddl@mAZAmBZBmCZCmDZD ddlEmFZF ddlGmHZHmIZI ddlJmKZKmLZLmMZMmNZN ddlOmPZPmQZQmRZRmSZS ddlTmUZUmVZV ddlWmXZXmYZY ddlZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZe ddlfmgZg ddlhmiZimjZj ddlkmlZl d d!lmmnZn dd"lompZpmqZqmrZrmsZsmtZt dd#lumvZvmwZw dd$lxmyZy dd%lzm{Z| e'd&Z}d'd( Z~d)d* Zdd+lmZ ed,Zd-d. ZG d/d0 d0eZd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Zd;d< Zd=d> Zd?d@ ZdAdB ZdCdD Zi adEdF ZdGdH ZdIdJ Zd}dLdMZdNdO Zd~dQdRZdSdT ZddUdVZdWdX ZddYdZZd[d\ Zd]d^ Zd_d` Zdadb Zdcdd ZdaeeddedfZddgdhZdidj Zdkdl Zdmdn Zedodp Zdqdr Zdsdt Zdudv Zdwdx ZeddydzZd{d| ZdS )a  
Integrate functions by rewriting them as Meijer G-functions.

There are three user-visible functions that can be used by other parts of the
sympy library to solve various integration problems:

- meijerint_indefinite
- meijerint_definite
- meijerint_inversion

They can be used to compute, respectively, indefinite integrals, definite
integrals over intervals of the real line, and inverse laplace-type integrals
(from c-I*oo to c+I*oo). See the respective docstrings for details.

The main references for this are:

[L] Luke, Y. L. (1969), The Special Functions and Their Approximations,
    Volume 1

[R] Kelly B. Roach.  Meijer G Function Representations.
    In: Proceedings of the 1997 International Symposium on Symbolic and
    Algebraic Computation, pages 205-211, New York, 1997. ACM.

[P] A. P. Prudnikov, Yu. A. Brychkov and O. I. Marichev (1990).
    Integrals and Series: More Special Functions, Vol. 3,.
    Gordon and Breach Science Publisher
    N)DictTuple)SYMPY_DEBUG)SExpr)Add)cacheit)r   )factor_terms)expand
expand_mulexpand_power_baseexpand_trigFunctionMul)ilcmRationalpi)EqNe_canonical_coeff)default_sort_keyordered)DummysymbolsWild)sympify)	factorial)reimargAbssign
unpolarifypolarify
polar_liftprincipal_branchunbranched_argumentperiodic_argument)exp	exp_polarlog)ceiling)coshsinh_rewrite_hyperbolics_as_expHyperbolicFunctionsqrt)	Piecewisepiecewise_fold)cossinsincTrigonometricFunction)besseljbesselybesselibesselk)
DiracDelta	Heaviside)
elliptic_k
elliptic_e)erferfcerfiEiexpintSiCiShiChifresnelsfresnelc)gamma)hypermeijerg)SingularityFunction   )Integral)AndOrBooleanAtomNotBooleanFunction)cancelfactor)multiset_partitions)debugzc                    s6   t | } t| ddr,t fdd| jD S | j  S )Nis_PiecewiseFc                 3   s   | ]}t |g R  V  qd S N)_has.0if U/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/integrals/meijerint.py	<genexpr>R       z_has.<locals>.<genexpr>)r4   getattrallargshas)resrc   rd   rb   re   r^   M   s    r^   c                    s4	  dd }t t|d\}tddd gdt  		tjddf
fd	d
	d'
fdd	}dd }|ddfg
d< G dd dt}t	 	 d   gg g dg	 td   t	dk t	 	 d   g gdgg 	 td   t	dk tt d   	 d   gg g dg	 td   t	dk t d  t 	 d   g gdgg 	 td   t	dk 	   d gg dgg 	   t t
|d t	   d gd d gdgd d g	 dtt d  td  t   tdk  	   	  dgg dgg 	 d  tt  t  dd   	fdd}|dd |dd |tjd |tjd  fdd}|dd |dd |tjd |tjd ttd	 g g dgg  t	g dgtjgddg	d d ttdd  t	g tjgdgtjtjg	d d ttdd  t	g g tjgdg	d d tt t	g g dgtjg	d d tt t	g g dgtddg	d d ttd  	fdd	fd d!|t	 td	  d |t	 t	d  d fd"d#}|t	 |d |t	 |ttjtddgg dgdg	 fg d |tt	 |ttttddgtjgdgdtjg	 fg d |t	|tj t tjtg dgddgg 	td fg d t	dgg tjgddg	d d ttd  t	g dgddgtjg	d d tt d  t	tjgg dgtddtddgtd	d  d 	tt d  t 	g tjdgddgtjtjg	d d ttd$  d  t!	g gd dgg 	 t"	dgg tjgdg	d dtt  t#	g dgdtjgg 	d dtt  t$	tjgg dgtddg	d  	tt  t%	dgg tddgdtddgtd 	d  d% tj t&	dgg tddgdtddgtd 	d  d% tj t'	g g d g d g	d d  t(	g d  d gd  d gd  d g	d d  t)	g d d gd g d d d g	d d t t*	g g d  d gg 	d d tj t+	tjtjgg dgdg	 tj t,	tjdtj gg dgdg	 tddd  d&S )(z8 Add formulae for the function -> meijerg lookup table. c                 S   s   t | tgdS )Nexclude)r   r[   nrd   rd   re   wildX   s    z"_create_lookup_table.<locals>.wildZpqabcrp   c                 S   s   | j o| dkS Nr   )
is_Integerxrd   rd   re   <lambda>[   rg   z&_create_lookup_table.<locals>.<lambda>)
propertiesTc	           	   
      s6     t| tg | |t|||||fg||f d S r]   )
setdefault_mytyper[   appendrN   )	formulaanapbmbqr    faccondhinttablerd   re   add^   s    z!_create_lookup_table.<locals>.addc                    s$     t| tg | |||f d S r]   )rx   ry   r[   rz   )r{   instr   r   r   rd   re   addib   s
    

z"_create_lookup_table.<locals>.addic                 S   s0   | t dgg g dgtf| t g dgdgg tfgS NrP   r   )rN   r[   )ard   rd   re   constantf   s    z&_create_lookup_table.<locals>.constantrd   c                   @   s   e Zd Zedd ZdS )z2_create_lookup_table.<locals>.IsNonPositiveIntegerc                 S   s   t |}|jdu r|dkS d S )NTr   )r#   rs   )clsr    rd   rd   re   evaln   s    
z7_create_lookup_table.<locals>.IsNonPositiveInteger.evalN)__name__
__module____qualname__classmethodr   rd   rd   rd   re   IsNonPositiveIntegerl   s   r   rP   r   )r      c                 S   s(   t tdd | | d dd|     S )Nr   rP   )r   r   )rr"   nurd   rd   re   A1   s    z _create_lookup_table.<locals>.A1c                    s   t d  |   d  |   d d dd|   d  gg |  d g|  d gd  d|     | |  d S )Nr   rP   r1   r   sgn)r   r   r   btrd   re   tmpadd   s
    , *z$_create_lookup_table.<locals>.tmpaddr   c                    s   t t   |t  td     t   |   d|  | d  gd|  | d  gdtjgg t   d |    | |  d S )Nr   rP   r   )r2   r[   r   Halfr   )r   r   r   r   pqrd   re   r      s    D2(      c                    s@   |   }t j| t| tg dg|d  dg|d  g fgS r   )r   NegativeOner   rN   subsNrp   r   rd   re   	make_log1   s    "z'_create_lookup_table.<locals>.make_log1c                    s6   |   }t |tdg|d  g g dg|d  fgS r   )r   rN   r   r   rd   re   	make_log2   s    "z'_create_lookup_table.<locals>.make_log2c                    s    | |  S r]   rd   r   )r   r   rd   re   	make_log3   s    z'_create_lookup_table.<locals>.make_log3z3/2   N)T)-listmapr   r[   r   Oner   r>   rL   rR   rU   r!   r6   r   r   r   r)   r%   r.   r   r-   r2   r5   r7   r+   rN   rD   ImaginaryUnitr   rF   rG   rH   rI   rE   rA   rB   rC   rJ   rK   r9   r:   r;   r<   r?   r@   )r   rq   cr   r   r   r   r   rd   )r   r   r   r   r   r   rp   r   r   r   r   re   _create_lookup_tableV   s    
..::4
<6.



48**2  .("
248,
",,4>>.FD2(r   )timethisrN   c                    s`    | j vrdS | jrt| fS  fdd| jD }g }|D ]}|t|7 }q:|  t|S dS )z4 Create a hashable entity describing the type of f. rd   c                    s   g | ]}t | qS rd   )ry   r`   r   rt   rd   re   
<listcomp>2  rg   z_mytype.<locals>.<listcomp>N)free_symbolsis_Functiontyperj   r   sorttuple)rc   ru   typesrl   r   rd   rt   re   ry   +  s    

ry   c                   @   s   e Zd ZdZdS )_CoeffExpValueErrorzD
    Exception raised by _get_coeff_exp, for internal use only.
    N)r   r   r   __doc__rd   rd   rd   re   r   :  s   r   c                 C   sz   ddl m} t|| |\}}|s0|tjfS |\}|jrX|j|krNtd||j	fS ||krj|tj
fS td|  dS )a  
    When expr is known to be of the form c*x**b, with c and/or b possibly 1,
    return c, b.

    Examples
    ========

    >>> from sympy.abc import x, a, b
    >>> from sympy.integrals.meijerint import _get_coeff_exp
    >>> _get_coeff_exp(a*x**b, x)
    (a, b)
    >>> _get_coeff_exp(x, x)
    (1, 1)
    >>> _get_coeff_exp(2*x, x)
    (2, 1)
    >>> _get_coeff_exp(x**3, x)
    (1, 3)
    r   )powsimpzexpr not of form a*x**bzexpr not of form a*x**b: %sN)sympy.simplifyr   r   as_coeff_mulr   Zerois_Powbaser   r)   r   )exprru   r   r   mrd   rd   re   _get_coeff_expA  s    



r   c                    s"    fdd t  } | || |S )a  
    Find the exponents of ``x`` (not including zero) in ``expr``.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _exponents
    >>> from sympy.abc import x, y
    >>> from sympy import sin
    >>> _exponents(x, x)
    {1}
    >>> _exponents(x**2, x)
    {2}
    >>> _exponents(x**2 + x, x)
    {1, 2}
    >>> _exponents(x**3*sin(x + x**y) + 1/x, x)
    {-1, 1, 3, y}
    c                    sV   | |kr| dg d S | jr:| j|kr:| | jg d S | jD ]} ||| q@d S NrP   )updater   r   r)   rj   )r   ru   rl   argument_exponents_rd   re   r   v  s    
z_exponents.<locals>._exponents_set)r   ru   rl   rd   r   re   
_exponentsc  s    	r   c                    s    fdd|  tD S )zB Find the types of functions in expr, to estimate the complexity. c                    s   h | ]} |j v r|jqS rd   )r   func)r`   ert   rd   re   	<setcomp>  rg   z_functions.<locals>.<setcomp>)atomsr   )r   ru   rd   rt   re   
_functions  s    r   c                    s<   fdddD \ fdd t  } | | |S )ap  
    Find numbers a such that a linear substitution x -> x + a would
    (hopefully) simplify expr.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _find_splitting_points as fsp
    >>> from sympy import sin
    >>> from sympy.abc import x
    >>> fsp(x, x)
    {0}
    >>> fsp((x-1)**3, x)
    {1}
    >>> fsp(sin(x+3)*x, x)
    {-3, 0}
    c                    s   g | ]}t | gd qS )rm   )r   r`   rp   rt   rd   re   r     rg   z*_find_splitting_points.<locals>.<listcomp>pqc                    sp   t | tsd S |   }|rL| dkrL||  |   d S | jrVd S | jD ]} || q\d S rr   )
isinstancer   matchr   is_Atomrj   )r   rl   r   r   compute_innermostr   r   ru   rd   re   r     s    

z1_find_splitting_points.<locals>.compute_innermostr   )r   ru   	innermostrd   r   re   _find_splitting_points  s
    
r   c           	      C   s   t j}t j}t j}t| } t| }|D ]}||kr>||9 }q(||jvrR||9 }q(|jr||jjvr|j	|\}}||fkrt
|j	|\}}||fkr|||j 9 }|tt||j dd9 }q(||9 }q(|||fS )aq  
    Split expression ``f`` into fac, po, g, where fac is a constant factor,
    po = x**s for some s independent of s, and g is "the rest".

    Examples
    ========

    >>> from sympy.integrals.meijerint import _split_mul
    >>> from sympy import sin
    >>> from sympy.abc import s, x
    >>> _split_mul((3*x)**s*sin(x**2)*x, x)
    (3**s, x*x**s, sin(x**2))
    Fr   )r   r   r   r   	make_argsr   r   r)   r   r   r   r#   r$   )	rc   ru   r   pogrj   r   r   r   rd   rd   re   
_split_mul  s(    






r   c                 C   sf   t | }g }|D ]N}|jrV|jjrV|j}|j}|dk rF| }d| }||g| 7 }q|| q|S )a   
    Return a list ``L`` such that ``Mul(*L) == f``.

    If ``f`` is not a ``Mul`` or ``Pow``, ``L=[f]``.
    If ``f=g**n`` for an integer ``n``, ``L=[g]*n``.
    If ``f`` is a ``Mul``, ``L`` comes from applying ``_mul_args`` to all factors of ``f``.
    r   rP   )r   r   r   r)   rs   r   rz   )rc   rj   gsr   rp   r   rd   rd   re   	_mul_args  s    
r   c                 C   sB   t | }t|dk rdS t|dkr.t|gS dd t|dD S )a  
    Find all the ways to split ``f`` into a product of two terms.
    Return None on failure.

    Explanation
    ===========

    Although the order is canonical from multiset_partitions, this is
    not necessarily the best order to process the terms. For example,
    if the case of len(gs) == 2 is removed and multiset is allowed to
    sort the terms, some tests fail.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _mul_as_two_parts
    >>> from sympy import sin, exp, ordered
    >>> from sympy.abc import x
    >>> list(ordered(_mul_as_two_parts(x*sin(x)*exp(x))))
    [(x, exp(x)*sin(x)), (x*exp(x), sin(x)), (x*sin(x), exp(x))]
    r   Nc                 S   s    g | ]\}}t | t | fqS rd   r   )r`   ru   yrd   rd   re   r     rg   z%_mul_as_two_parts.<locals>.<listcomp>)r   lenr   rY   )rc   r   rd   rd   re   _mul_as_two_parts  s    
r   c              
   C   s   dd }t t| jt| j }|d| j |d   }|dt |d | j   }|t|| j||| j	||| j
||| j|| j| |||   fS )zO Return C, h such that h is a G function of argument z**n and
        g = C*h. c                    s    fddt | t D S )z5 (a1, .., ak) -> (a1/n, (a1+1)/n, ..., (ak + n-1)/n) c                    s   g | ]\}}||   qS rd   rd   )r`   r   ra   ro   rd   re   r     rg   z/_inflate_g.<locals>.inflate.<locals>.<listcomp>)	itertoolsproductrange)paramsrp   rd   ro   re   inflate  s    z_inflate_g.<locals>.inflaterP   r   )r   r   r}   r   r   r   deltarN   r|   aotherr~   botherr   )r   rp   r   vCrd   rd   re   
_inflate_g
  s    r   c                 C   s6   dd }t || j|| j|| j|| jd| j S )zQ Turn the G function into one of inverse argument
        (i.e. G(1/x) -> G'(x)) c                 S   s   dd | D S )Nc                 S   s   g | ]}d | qS rP   rd   r   rd   rd   re   r     rg   z'_flip_g.<locals>.tr.<locals>.<listcomp>rd   lrd   rd   re   tr  s    z_flip_g.<locals>.trrP   )rN   r~   r   r|   r   r   )r   r   rd   rd   re   _flip_g  s    r   c                    s   |dk rt t| | S t|j t|j}t| |\}} | j}|dt d  d   tdd   }|    } fddt	 D }|t
| j| j| jt| j| |fS )a\  
    Let d denote the integrand in the definition of the G function ``g``.
    Consider the function H which is defined in the same way, but with
    integrand d/Gamma(a*s) (contour conventions as usual).

    If ``a`` is rational, the function H can be written as C*G, for a constant C
    and a G-function G.

    This function returns C, G.
    r   r   rP   r   c                    s   g | ]}|d    qS r   rd   r   r   rd   re   r   9  rg   z"_inflate_fox_h.<locals>.<listcomp>)_inflate_fox_hr   r   r   r   r   r   r   r   r   rN   r|   r   r~   r   r   )r   r   r   Dr[   bsrd   r   re   r   #  s    

&r   c                 K   s0   t | |fi |}||jv r,t| fi |S |S )z
    Return a dummy. This will return the same dummy if the same token+name is
    requested more than once, and it is not already in expr.
    This is for being cache-friendly.
    )_dummy_r   r   )nametokenr   kwargsdrd   rd   re   _dummy?  s    
r   c                 K   s0   | |ft vr$t| fi |t | |f< t | |f S )z`
    Return a dummy associated to name and token. Same effect as declaring
    it globally.
    )_dummiesr   )r   r   r   rd   rd   re   r   K  s    r   c                    s    t  fdd| ttD  S )z Check if f(x), when expressed using G functions on the positive reals,
        will in fact agree with the G functions almost everywhere c                 3   s   | ]} |j v V  qd S r]   )r   r`   r   rt   rd   re   rf   Y  rg   z_is_analytic.<locals>.<genexpr>)anyr   r>   r!   )rc   ru   rd   rt   re   _is_analyticV  s    r  Tc                    s    r|  dd t} d t| ts&| S tdtd\}tk tkftt	t
tkt	t
dt  tktt
t dftt	dt
 t tkt	dt
 t tktt
dftt	dt
 t tk t	dt
 t tktjftt	t
td  td kt	t
td  td ktt
dftt	t
td  td kt	t
td  td k tjftt	t
d d d tk tt	t
d d d ttjftt	t
d d d tk tdd d d  dtjftt	ttkt	ttd	t tj  tkttttj t  dftt	ttd kt	ttt tj  td kttttj t d  dftktk |kftd dd dk@ d dkftd dtt	t
t	 dk@ t	dkftdtt	t
t	 dk@ t	dkft	t
td k tt	t
tt	d  dk@ d dkfg}| jtt fd
d| j } d}|rd}t|D ]\}\}}|j| jkrqt| jD ]\}}	||jd jv r&|	|jd d}
nd}
|	|jd sDqfdd|jd|
 |j|
d d  D }|g|D ]}t| jD ]\}}|v rq||kr|g7  q|t|tr|jd |krt|tr|jd |jv r|g7  q|t|tr|jd |krt|tr|jd |jv r|g7  q|qq|tt|d krpqfddt| jD |g }tr|dvrtd| | j| } d} qʐqqʐqfdd}|  dd |} trtd|  | S )a  
    Do naive simplifications on ``cond``.

    Explanation
    ===========

    Note that this routine is completely ad-hoc, simplification rules being
    added as need arises rather than following any logical pattern.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _condsimp as simp
    >>> from sympy import Or, Eq
    >>> from sympy.abc import x, y
    >>> simp(Or(x < y, Eq(x, y)))
    x <= y
    c                 S   s   | j S r]   is_Relational_rd   rd   re   rv   p  rg   z_condsimp.<locals>.<lambda>Fzp q r)r   r   r   rP   c                    s
   t |  S r]   )	_condsimpr  )firstrd   re   rv     rg   Tc                    s   g | ]}|  qS rd   r   r`   ru   )r   rd   re   r     rg   z_condsimp.<locals>.<listcomp>Nc                    s   g | ]\}}| vr|qS rd   rd   )r`   karg_)	otherlistrd   re   r     s   )
r   r   r                        zused new rule:c                    s   | j dks| jdkr| S | j}|t  }|sJ|tt  }|st|tr|j	d j
s|j	d tju r|j	d dkS | S |  dkS )Nz==r   rP   )rel_oprhslhsr   r    r'   r%   r   r(   rj   is_polarr   Infinity)relZLHSr   )r   r   rd   re   rel_touchup  s    z_condsimp.<locals>.rel_touchupc                 S   s   | j S r]   r  r  rd   rd   re   rv     rg   z_condsimp: ) replacer   r   rV   r   r   rS   r   rR   r!   r    r   r   falser   truer'   r*   r   r5   r2   r   r   r   rj   	enumerater   r   r   r   r   print)r   r  r   ruleschangeZirulefrotorp   arg1numZ	otherargsarg2r
  Zarg3newargsr  rd   )r  r   r  r   r   re   r  \  s    
(0088:6 " $40B.









r  c                 C   s   t | tr| S t|  S )z Re-evaluate the conditions. )r   boolr  doit)r   rd   rd   re   
_eval_cond  s    
r*  Fc                 C   s"   t | |}|s|t dd }|S )z Bring expr nearer to its principal branch by removing superfluous
        factors.
        This function does *not* guarantee to yield the principal branch,
        to avoid introducing opaque principal_branch() objects,
        unless full_pb=True. c                 S   s   | S r]   rd   )ru   r   rd   rd   re   rv     rg   z&_my_principal_branch.<locals>.<lambda>)r&   r  )r   periodfull_pbrl   rd   rd   re   _my_principal_branch  s    
r-  c           	         s   t ||\}t |j|\} | }t||}| t |d   d    } fdd}|t||j||j||j||j	|| fS )z
    Rewrite the integral fac*po*g dx, from zero to infinity, as
    integral fac*G, where G has argument a*x. Note po=x**s.
    Return fac, G.
    rP   c                    s    fdd| D S )Nc                    s    g | ]}|d     d  qS r   rd   r   r   srd   re   r     rg   z1_rewrite_saxena_1.<locals>.tr.<locals>.<listcomp>rd   r   r.  rd   re   r     s    z_rewrite_saxena_1.<locals>.tr)
r   r   
get_periodr-  r!   rN   r|   r   r~   r   )	r   r   r   ru   r  r   r+  r   r   rd   r.  re   _rewrite_saxena_1  s    
 $r1  c              
   C   sn  | j }t| j|\}}tt| jt| jt| jt| jg\}}}}	||	krdd }
t	t
|
| j|
| j|
| j|
| j|| |S dd | jD dd | jD  }t| }|dd | jD 7 }|dd | jD 7 }t| }t| j |	d | d	  |	| k}d
d }|d |d||||||	f  |dt| jt| jf  |dt| jt| jf  |d|||f  g }g }d|k||	k d|kg}d|kd|kt|	|d ttt|dt||d g}d|kt|	|g}tt|d	 d D ]*}|ttt||d	|  t g7 }q|dktt||t k g}t|d|g}|rRg }|||fD ]}|t|| |  g7 }q\||7 }|d| |g}|rg }tt|d|d |k||	ktt||t k g|R  g}||7 }|d| ||g}|rg }t||	k d|k|dkttt||t g|R  g}|t||	d	 kt|dttt|dg|R  g7 }||7 }|d| g }|t||	t|dtt|dt|dg7 }|s||g7 }g }t| j| jD ]\}}||| g7 }q|tt| dk g7 }t| }||g7 }|d|g t|dktt||t k g}|sH||g7 }t| }||g7 }|d|g t| S )aV  
    Return a condition under which the mellin transform of g exists.
    Any power of x has already been absorbed into the G function,
    so this is just $\int_0^\infty g\, dx$.

    See [L, section 5.6.1]. (Note that s=1.)

    If ``helper`` is True, only check if the MT exists at infinity, i.e. if
    $\int_1^\infty g\, dx$ exists.
    c                 S   s   dd | D S )Nc                 S   s   g | ]}d | qS r   rd   r	  rd   rd   re   r     rg   z4_check_antecedents_1.<locals>.tr.<locals>.<listcomp>rd   r   rd   rd   re   r     s    z _check_antecedents_1.<locals>.trc                 S   s   g | ]}t | d k qS r   r   r`   r   rd   rd   re   r     rg   z(_check_antecedents_1.<locals>.<listcomp>c                 S   s   g | ]}d d t | k qS r   r2  r   rd   rd   re   r     rg   c                 S   s   g | ]}t | d k qS r   r2  r3  rd   rd   re   r     rg   c                 S   s   g | ]}d d t | k qS r   r2  r   rd   rd   re   r     rg   rP   r   c                  W   s   t |   d S r]   _debug)msgrd   rd   re   rZ   #  s    z#_check_antecedents_1.<locals>.debugz$Checking antecedents for 1 function:z*  delta=%s, eta=%s, m=%s, n=%s, p=%s, q=%sz  ap = %s, %sz  bq = %s, %sz"  cond_3=%s, cond_3*=%s, cond_4=%sr   z	  case 1:z	  case 2:z	  case 3:z  extra case:z  second extra case:)r   r   r   r   r   r~   r|   r}   r   _check_antecedents_1rN   r   r   rR   r   r   r   r   rU   r   r,   r   r!   r'   r   zipr   rS   )r   ru   helperr   etar  r   rp   r   r   r   tmpZcond_3Zcond_3_starZcond_4rZ   condsZcase1Ztmp1Ztmp2Ztmp3r
  extrar   Zcase2Zcase3Z
case_extrar/  r   r   Zcase_extra_2rd   rd   re   r7    s    0 $8(


*
6
,

 

r7  c                 C   s   ddl m} t| j|\}}d| }| jD ]}|t|d 9 }q*| jD ]}|td| d 9 }qF| jD ]}|td| d  }qf| jD ]}|t|d  }q|t	|S )a  
    Evaluate $\int_0^\infty g\, dx$ using G functions,
    assuming the necessary conditions are fulfilled.

    Examples
    ========

    >>> from sympy.abc import a, b, c, d, x, y
    >>> from sympy import meijerg
    >>> from sympy.integrals.meijerint import _int0oo_1
    >>> _int0oo_1(meijerg([a], [b], [c], [d], x*y), x)
    gamma(-a)*gamma(c + 1)/(y*gamma(-d)*gamma(b + 1))
    r   )	gammasimprP   )
r   r>  r   r   r~   rL   r|   r   r   r#   )r   ru   r>  r:  r  rl   r   r   rd   rd   re   	_int0oo_1p  s    



r?  c                    s  fdd}t |\}}t |j\}}	t |j\}}
|	dk dkrV|	 }	t|}|
dk dkrp|
 }
t|}|	jr||
jsdS |	j|	j }}|
j|
j }}t|| || }|||  }|||  }t||\}}t||\}}||}||}| || 9 } t |j\}}t |j\}}|d | d  | t||    }  fdd}t	||j
||j||j||j| }t	|j
|j|j|j| }dd	lm} || dd
||fS )a  
    Rewrite the integral ``fac*po*g1*g2`` from 0 to oo in terms of G
    functions with argument ``c*x``.

    Explanation
    ===========

    Return C, f1, f2 such that integral C f1 f2 from 0 to infinity equals
    integral fac ``po``, ``g1``, ``g2`` from 0 to infinity.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _rewrite_saxena
    >>> from sympy.abc import s, t, m
    >>> from sympy import meijerg
    >>> g1 = meijerg([], [], [0], [], s*t)
    >>> g2 = meijerg([], [], [m/2], [-m/2], t**2/4)
    >>> r = _rewrite_saxena(1, t**0, g1, g2, t)
    >>> r[0]
    s/(4*sqrt(pi))
    >>> r[1]
    meijerg(((), ()), ((-1/2, 0), ()), s**2*t/4)
    >>> r[2]
    meijerg(((), ()), ((m/2,), (-m/2,)), t/4)
    c              	      s@   t | j\}}|  }t| j| j| j| jt|| |  S r]   )	r   r   r0  rN   r|   r   r~   r   r-  )r   r   r   per)r,  ru   rd   re   pb  s
    z_rewrite_saxena.<locals>.pbr   TNrP   c                    s    fdd| D S )Nc                    s   g | ]}|  qS rd   rd   r   r)   rd   re   r     rg   z/_rewrite_saxena.<locals>.tr.<locals>.<listcomp>rd   r   rB  rd   re   r     s    z_rewrite_saxena.<locals>.tr	powdenestpolar)r   r   r   is_Rationalr   r   r   r   r!   rN   r|   r   r~   r   r   rD  )r   r   g1g2ru   r,  rA  r  r/  b1b2m1n1m2n2taur1r2C1C2a1r   a2r   rD  rd   )r)   r,  ru   re   _rewrite_saxena  s>    ,rW  c           +         s*  t j|\	}t j|\}ttjtjtjtjg\}}ttjtjtjtjg\}}||  d  }||  d  }	j d  d j d  d    }
d    }t	| |  t
t   t	| |  t
t	   
td td	|||f  td|||	f  td|
|
f  fdd}| }tfd	d
jD  }tfdd
jD  }tfdd
jD  }tfdd
jD  }tfdd
jD  }tfdd
jD  }t
|
dtd       d      dk}t
|
dtd       d      dk}t
t	|t	 k }tt
t	|t	 }t
t|	t	 k }tt
t|	t	 }t||	  t	 tj }t| 	 }t|	  }|d| krtt|
d||	 dktt|dt   dk t   dk }ndd }tt|
d|d |	 dkttt|d||tt   dk t|d}tt|
d|	d | dkttt|d||tt   dk t|d}t||}z t
d    t  t
	d    t
  } t| dkdkr| dk}!n:	
fdd}"t|"dd|"dd ttt	dttdf|"ttd|"ttd ttt	dttdf|"dtt	|"dtt	 ttt	dttdf|"tttt	df}#| dktt| dt|#dt|dktt| dt|#dt|dkg}$t|$ }!W n ty0   d}!Y n0 |df|df|df|df|df|df|df|df|df|df|d f|d!f|d"f|d#f|!d$ffD ]\}%}&td%|& |% qg   fd&d'}' t|| | | dk|jdu |	jdu |||||g7  |'d  ttt|d|	jdu 	jdu tdk ||||	g7  |'d  ttt|	d|jdu jdu tdk ||||	g7  |'d  tttt|dt|	d	jdu jdu tdk tdk t	|||g7  |'d  tttt|dt|	d	jdu jdu t dk t	|||g7  |'d  tk|jdu |jdu |	dk||||||
g7  |'d  tk |jdu |jdu |	dk||||||
g7  |'d  tk|jdu |	jdu |dk||||||
g7  |'d  tk |jdu |	jdu |dk||||||
g7  |'d  tktt|d|	dk	jdu tdk |||||g7  |'d  tk tt|d|	dk	jdu tdk |||||g7  |'d   ttk|dkt|	djdu tdk |||||g7  |'d!  ttk |dkt|	djdu tdk |||||g7  |'d"  tk k|dk|	dk|||||||g7  |'d#  tkk |dk|	dk|||||||g7  |'d$  tkk|dk|	dk|||||||||g7  |'d(  tk k |dk|	dk|||||||||g7  |'d)  tt|d|jdu |jdu |
jdu |||g7  |'d*  tt|d|jdu |jdu |
jdu |||g7  |'d+  tt|d|jdu |	jdu |
jdu |||g7  |'d,  tt|d|jdu |	jdu |
jdu |||g7  |'d-  tt|| d|jdu |	jdu |||||g7  |'d.  tt|| d|jdu |	jdu |||||g7  |'d/ t|dd0}(t|dd0}) t|)t|d|k |jdu ||||g7  |'d1  t|)t|d|k |jdu ||||g7  |'d2  t|(t|d|k |	jdu ||||g7  |'d3  t|(t|d|k |	jdu ||||g7  |'d4 t  }*t|*dkr|*S  t|| kt|dt|
d|jdu |jdu |	jdu t
t||  d t	 k |||||!g7  |'d5  t|| kt|dt|
d|jdu |jdu |	jdu t
t||  d t	 k |||||!g7  |'d6  ttd t|dt|
d|jdu |jdu |	dk|	t	 t
tk |||||!g7  |'d7  ttd t|dt|
d|jdu |jdu |	dk|	t	 t
tk |||||!g7  |'d8  td k t|dt|
d|jdu |jdu |	dk|	t	 t
tk t
t||  d t	 k |||||!g7  |'d9  td kt|dt|
d|jdu |jdu |	dk|	t	 t
tk t
t||  d t	 k |||||!g7  |'d:  tt|dt|
d|| dk|jdu |	jdu |jdu t
t	||  d t	 k |||||!g7  |'d;  tt|dt|
d|| k|jdu |	jdu |jdu t
t	||  d t	 k |||||!g7  |'d<  tt|dt|
dtd |jdu |	jdu |dk|t	 t
t	k t
t	|d t	 k |||||!g7  |'d=  tt|dt|
dtd |jdu |	jdu |dk|t	 t
t	k t
t	|d t	 k |||||!g7  |'d>  tt|dt|
dd k |jdu |	jdu |dk|t	 t
t	k t
t	||  d t	 k |||||!g7  |'d?  tt|dt|
dd k|jdu |	jdu |dk|t	 t
t	k t
t	||  d t	 k |||||!g7  |'d@ t  S )Az> Return a condition under which the integral theorem applies. r   rP   zChecking antecedents:z1  sigma=%s, s=%s, t=%s, u=%s, v=%s, b*=%s, rho=%sz1  omega=%s, m=%s, n=%s, p=%s, q=%s, c*=%s, mu=%s,z"  phi=%s, eta=%s, psi=%s, theta=%sc                     sH    fD ]:} t | j| jD ]$\}}|| }|jr|jr  dS qqdS )NFT)r   r   r|   r~   
is_integeris_positive)r   ra   jdiff)rH  rI  rd   re   _c1  s    z_check_antecedents.<locals>._c1c                    s,   g | ]$} j D ]}td | | dkqqS rP   r   )r~   r   r`   ra   rZ  rI  rd   re   r      rg   z&_check_antecedents.<locals>.<listcomp>c                    s,   g | ]$} j D ]}td | | dk qqS )rP   r   )r|   r   r^  r_  rd   re   r     rg   c                    s6   g | ].} t d | d   t   tddkqS rP   r   r   r   r_   mur   r   rd   re   r     rg   c                    s2   g | ]*} t d |  t   tddkqS r`  rb  r_   rc  rd   re   r     rg   c                    s6   g | ].} t d | d   t   tddkqS r`  rb  r_   rhour   rd   re   r     rg   c                    s2   g | ]*} t d |  t   tddkqS r`  rb  r_   re  rd   re   r     rg   r   c                 S   s   | dkot td|  tk S )a  Returns True if abs(arg(1-z)) < pi, avoiding arg(0).

            Explanation
            ===========

            If ``z`` is 1 then arg is NaN. This raises a
            TypeError on `NaN < pi`. Previously this gave `False` so
            this behavior has been hardcoded here but someone should
            check if this NaN is more serious! This NaN is triggered by
            test_meijerint() in test_meijerint.py:
            `meijerint_definite(exp(x), x, 0, I)`
            rP   )r!   r    r   r[   rd   rd   re   _cond"  s    z!_check_antecedents.<locals>._condFc                    sP   |   t  d    t |  t d    t  S r   )r!   r6   )c1c2)omegar   psir   sigmathetarg  r   rd   re   	lambda_s0Q  s    &&z%_check_antecedents.<locals>.lambda_s0r   Tr   r   r  r  r     	   
   r  r  r  r     z  c%s:c                    s   t d|   d  d S )Nz
  case %s:r   r4  )count)r<  rd   re   prj  s    z_check_antecedents.<locals>.prr                        )r9  E1E2E3E4                            !   "   #   )r   r   r   r   r~   r|   r}   r   r   r   r!   r'   r5  rR   r   r   r)   r   r#   rS   r   r5   r*  r3   r"   	TypeErrorrY  is_negativer7  )+rH  rI  ru   r  r/  r   r   rp   ZbstarZcstarphir:  r\  rj  rk  c3c4Zc5Zc6Zc7Zc8Zc9Zc10Zc11Zc12Zc13z0ZzosZzsoZc14ri  Zc14_altZlambda_cZc15rp  Zlambda_sr;  r   ra   rv  Z
mt1_existsZ
mt2_existsr   rd   )r<  rH  rI  rd  rl  r   rm  r   rf  rn  ro  rg  r   re   _check_antecedents  s   00$$*
*
 ""

""""
$...$$$    ((((2222 
 
,,,,6
6
0
0
.
0
6
6
0
0
0
0
r  c                 C   s   t | j|\}}t |j|\}}dd }|| jt|j }t|j|| j }|| jt|j }	t|j|| j }
t|||	|
|| | S )a  
    Express integral from zero to infinity g1*g2 using a G function,
    assuming the necessary conditions are fulfilled.

    Examples
    ========

    >>> from sympy.integrals.meijerint import _int0oo
    >>> from sympy.abc import s, t, m
    >>> from sympy import meijerg, S
    >>> g1 = meijerg([], [], [-S(1)/2, 0], [], s**2*t/4)
    >>> g2 = meijerg([], [], [m/2], [-m/2], t/4)
    >>> _int0oo(g1, g2, t)
    4*meijerg(((1/2, 0), ()), ((m/2,), (-m/2,)), s**(-2))/s**2
    c                 S   s   dd | D S )Nc                 S   s   g | ]
}| qS rd   rd   r	  rd   rd   re   r     rg   z(_int0oo.<locals>.neg.<locals>.<listcomp>rd   r   rd   rd   re   neg  s    z_int0oo.<locals>.neg)r   r   r~   r   r|   r   r   rN   )rH  rI  ru   r:  r  rl  r  rU  rV  rJ  rK  rd   rd   re   _int0oo  s    r  c                    sz   t ||\}t |j|\}  fdd}ddlm} || |    ddt||j||j||j||j|jfS )z Absorb ``po`` == x**s into g. c                    s    fdd| D S )Nc                    s   g | ]}|   qS rd   rd   )r`   r   r.  rd   re   r   *  rg   z2_rewrite_inversion.<locals>.tr.<locals>.<listcomp>rd   r   r.  rd   re   r   )  s    z_rewrite_inversion.<locals>.trr   rC  TrE  )	r   r   r   rD  rN   r|   r   r~   r   )r   r   r   ru   r  r   r   rD  rd   r.  re   _rewrite_inversion$  s    (r  c                    sP  t d  jt\}}|dk r:t d tt S fddfddtt jt jt j	t j
g\}}}}|| | }|| | }	||	 d }
|| d	krtj}nd	krd	}ntj}d	 d t j
  t j	    j}t d
||||||	|
f  t d||f   j|d ksZ|d	krN||ksZt d dS t j jD ].\}}|| jrj||krjt d  dS qj||krt d tfdd jD  S  fdd}fdd}fdd}fdd}g }|td	|kd	|k|
t | td k|dk|ttjt |	d	   g7 }|t|d	 |k|d	 |k|dk|td k |dk|| d	 t | td k|ttjt ||   |ttj t ||   g7 }|t||k|dk|dk| t | td k|g7 }|ttt||d kd	|k|d kt|d	 || k|| || d k|dk|td k |d	 t | td k|ttjt |	  |ttj t |	  g7 }|td	|k|
dk|dk||
t  td k || t | td k|ttjt |	  |ttj t |	  g7 }||dkg7 }t| S )z7 Check antecedents for the laplace inversion integral. z#Checking antecedents for inversion:r   z  Flipping G.c                    s   t | \}}| |9 } ||| 9 }||9 }g }|ttjt| t d  }|ttj t| t d  }	|rv|}
n|	}
|ttt|dt|dkt| dkg7 }|tt	|dtt
|dt|dkt|
dk g7 }|tt	|dtt
|dt|dkt|
dkt| dkg7 }t| S )Nr   r   r   )r   r)   r   r   r   r   rR   rS   r   r   r   )r   r   r   r[   pluscoeffexponentr<  wpZwmwrt   rd   re   statement_half:  s      ,4,
z4_check_antecedents_inversion.<locals>.statement_halfc                    s"   t  | |||d | |||dS )zW Provide a convergence statement for z**a * exp(b*z**c),
             c/f sphinx docs. TF)rR   )r   r   r   r[   )r  rd   re   	statementL  s    z/_check_antecedents_inversion.<locals>.statementr   rP   z9  m=%s, n=%s, p=%s, q=%s, tau=%s, nu=%s, rho=%s, sigma=%sz   epsilon=%s, theta=%s, delta=%sz-  Computation not valid for these parameters.Fz  Not a valid G function.z$  Using asymptotic Slater expansion.c                    s   g | ]} |d  ddqS r]  rd   r   r  r[   rd   re   r   z  rg   z0_check_antecedents_inversion.<locals>.<listcomp>c                    s   t  fddjD  S )Nc                    s   g | ]} |d  ddqS r]  rd   r   r  rd   re   r   }  rg   z;_check_antecedents_inversion.<locals>.E.<locals>.<listcomp>)rR   r|   rh  )r   r  rh  re   E|  s    z'_check_antecedents_inversion.<locals>.Ec                    s     d  | S r   rd   rh  )rn  r  ro  rd   re   H  s    z'_check_antecedents_inversion.<locals>.Hc                    s     d  | dS )NrP   Trd   rh  rn  r  ro  rd   re   Hp  s    z(_check_antecedents_inversion.<locals>.Hpc                    s     d  | dS )NrP   Frd   rh  r  rd   re   Hm  s    z(_check_antecedents_inversion.<locals>.Hm)r5  r   r   _check_antecedents_inversionr   r   r   r~   r|   r}   r   r   NaNr   r   r   r   rX  rR   r   r)   r   rS   )r   ru   r  r   r   rp   r   r   rP  r   rf  epsilonr   r   r   r  r  r  r  r<  rd   )r   rn  r  r  ro  ru   r[   re   r  0  s    0$$
	
(.$$&(r  c              	   C   sH   t | j|\}}tt| j| j| j| j|||  | \}} || |  S )zO
    Compute the laplace inversion integral, assuming the formula applies.
    )r   r   r   rN   r|   r   r~   r   )r   ru   r   r   r   r   rd   rd   re   _int_inversion  s    ,r  c                     s<  ddl m}mm}m  ts(i att t| trt	| j
||\}}t|dkrXdS |d }|jr~|j|ksx|jjsdS n||krdS ddt| j| j| j| j|| fgdfS | }| |t} t| t}|tv rht| }	|	D ]\}
}}}| j|
dd}|ri }| D ]"\}}tt|dddd||< q|}t|tsL||}|d	krXqt|ttfsvt||}t|d	krqt|ts||}g }|D ]\}}t t||t|dd|}z||t|}W n t!y   Y qY n0 t"||f  #t$j%t$j&t$j'r qt|j|j|j|jt|j
dd}|(||f  q|r||f  S q|srdS t)d
  fdd}|} t*dd| }dd }z,|| |||d	dd\}}}|||||}W n |y   d}Y n0 |du rlt+dd}|| j,vrlt-| |rlz@|| ||| |||dd	d\}}}||||||d}W n |yj   d}Y n0 |du s|#t$j%t$j.t$j&rt)d dS t/0|}g }|D ]~} | |\}}t|dkrt1d|d }t |j
|\}}||dt|j|j|j|jtt|dddd||  fg7 }qt)d| |dfS )aH  
    Try to rewrite f as a sum of single G functions of the form
    C*x**s*G(a*x**b), where b is a rational number and C is independent of x.
    We guarantee that result.argument.as_coeff_mul(x) returns (a, (x**b,))
    or (a, ()).
    Returns a list of tuples (C, s, G) and a condition cond.
    Returns None on failure.
    rP   )mellin_transforminverse_mellin_transformIntegralTransformErrorMellinTransformStripErrorNr   T)old)lift)exponents_onlyFz)Trying recursive Mellin transform method.c                    sZ   z| |||dddW S   yT   ddl m} |tt| |||ddd Y S 0 dS )z Calling simplify() all the time is slow and not helpful, since
            most of the time it only factors things in a way that has to be
            un-done anyway. But sometimes it can remove apparent poles. T)Z
as_meijergneedevalr   )simplifyN)r   r  rW   r
   )Fr/  ru   stripr  r  r  rd   re   my_imt  s    
z_rewrite_single.<locals>.my_imtr/  zrewrite-singlec                 S   sp   t | |dd}|d ur\ddlm} |\}}t||dd}t||ft| |tjtjfdfS t| |tjtjfS )NT)only_doubler   hyperexpandZnonrepsmall)rewrite)	_meijerint_definite_4r   r  _my_unpolarifyr3   rQ   r   r   r  )rc   ru   r   r  rl   r   rd   rd   re   my_integrator  s    z&_rewrite_single.<locals>.my_integrator)
integratorr  r  r   )r  r  r  z"Recursive Mellin transform failed.zUnexpected form...z"Recursive Mellin transform worked:)2
transformsr  r  r  r  _lookup_tabler   r   rN   rX   r   r   r   r   r   r)   rG  r|   r   r~   r   r   r[   ry   r   itemsr#   r$   r(  rT   r*  r   r   
ValueErrorr   rk   r   r  ComplexInfinityNegativeInfinityrz   r5  r   r   r   r  r  r   r   NotImplementedError) rc   ru   	recursiver  r  r  r   f_r   r   r{   termsr   r   r   Zsubs_r"  r#  rl   r   r   rQ  r  r/  r  r  r  r  r   rj   r   r   rd   r  re   _rewrite_single  s    
(



 	




 

r  c                 C   s8   t | |\}}}t|||}|r4|||d |d fS dS )z
    Try to rewrite ``f`` using a (sum of) single G functions with argument a*x**b.
    Return fac, po, g such that f = fac*po*g, fac is independent of ``x``.
    and po = x**s.
    Here g is a result from _rewrite_single.
    Return None on failure.
    r   rP   N)r   r  )rc   ru   r  r   r   r   rd   rd   re   	_rewrite1H  s    r  c                    s   t |  \}}}t fddt|D r.dS t|}|s>dS tt| fdd fdd fddg}td|D ]`\}\}}t| |}	t| |}
|	rv|
rvt	|	d	 |
d	 }|d
krv|||	d |
d |f  S qvdS )a  
    Try to rewrite ``f`` as a product of two G functions of arguments a*x**b.
    Return fac, po, g1, g2 such that f = fac*po*g1*g2, where fac is
    independent of x and po is x**s.
    Here g1 and g2 are results of _rewrite_single.
    Returns None on failure.
    c                 3   s   | ]}t | d du V  qdS )FN)r  r   rt   rd   re   rf   _  rg   z_rewrite2.<locals>.<genexpr>Nc                    s&   t tt| d  tt| d  S Nr   rP   )maxr   r   r   rt   rd   re   rv   e  rg   z_rewrite2.<locals>.<lambda>c                    s&   t tt| d  tt| d  S r  )r  r   r   r   rt   rd   re   rv   f  rg   c                    s&   t tt| d  tt| d  S r  )r  r   r   r   rt   rd   re   rv   g  s   FTrP   Fr   )
r   r   r   r   r   r   r   r   r  rR   )rc   ru   r   r   r   r   r  Zfac1fac2rH  rI  r   rd   rt   re   	_rewrite2V  s$    


r  c                 C   s   t | } g }tt| |tjhB tdD ]P}t| ||| |}|sFq&|||| }t|t	t
rn|| q&|  S q&| trtd tt| |}|rt|tsddlm} |t||tS || |rtt|S dS )a#  
    Compute an indefinite integral of ``f`` by rewriting it as a G function.

    Examples
    ========

    >>> from sympy.integrals.meijerint import meijerint_indefinite
    >>> from sympy import sin
    >>> from sympy.abc import x
    >>> meijerint_indefinite(sin(x), x)
    -cos(x)
    )key*Try rewriting hyperbolics in terms of exp.r   collectN)r   sortedr   r   r   r   _meijerint_indefinite_1r   r^   rM   rN   rz   rk   r0   r5  meijerint_indefiniter/   r   r   sympy.simplify.radsimpr  r	   r   r)   extendnextr   )rc   ru   resultsr   rl   rvr  rd   rd   re   r  s  s,    



r  c                    s8  t d| d ddlm}m} t| }|du r4dS |\}}}}t d| tj}	|D ]X\}
}}t|j\}}t|\}}||7 }||
 ||d| |    }|d | d  t	dd	tj
} fd
d}tdd ||jD rt||j||jdg ||jdg ||j| }n4t||jdg ||j||j||jdg |}|jrz| dtjtjszd}nd}|||||  |d}|	||| dd7 }	qTfdd}t|	dd}	|	jrg }|	jD ]$\}}t||}|||fg7 }qt|ddi}	nt||	}	t|	t|ft| dfS )z0 Helper that does not attempt any substitution. z,Trying to compute the indefinite integral ofwrtr   )r  rD  Nz could rewrite:rP   r   zmeijerint-indefinitec                    s    fdd| D S )Nc                    s   g | ]}|  d  qS r   rd   r   rf  rd   re   r     rg   z7_meijerint_indefinite_1.<locals>.tr.<locals>.<listcomp>rd   r   r  rd   re   r     s    z#_meijerint_indefinite_1.<locals>.trc                 s   s    | ]}|j o|d kdkV  qdS )r   TN)rX  r3  rd   rd   re   rf     rg   z*_meijerint_indefinite_1.<locals>.<genexpr>)placeTrE  c                    s$   t t| dd} t|  d S )a  This multiplies out superfluous powers of x we created, and chops off
        constants:

            >> _clean(x*(exp(x)/x - 1/x) + 3)
            exp(x)

        cancel is used before mul_expand since it is possible for an
        expression to have an additive constant that does not become isolated
        with simple expansion. Such a situation was identified in issue 6369:

        Examples
        ========

        >>> from sympy import sqrt, cancel
        >>> from sympy.abc import x
        >>> a = sqrt(2*x + 1)
        >>> bad = (3*x*a**5 + 2*x - a**5 + 1)/a**2
        >>> bad.expand().as_independent(x)[0]
        0
        >>> cancel(bad).expand().as_independent(x)[0]
        1
        F)deeprP   )r   rW   r   
_from_argsas_coeff_add)rl   rt   rd   re   _clean  s    z'_meijerint_indefinite_1.<locals>._clean)evaluater  F)r5  r   r  rD  r  r   r   r   r   r   r   r   r~   rN   r|   r   r   is_extended_nonnegativer   rk   r  r  r4   r\   rj   r  r3   rQ   )rc   ru   r  rD  r   r   r   glr   rl   r   r/  r   r   r   r  r   Zfac_r   r   r   r  r  r'  r   rd   )rf  ru   re   r    sL    


.."r  c                 C   s   t d| d|||f  t| } | tr4t d dS | trJt d dS | |||f\}}}}td}| ||} |}||krtjdfS g }	|tj	u r|tj
urt| || || | S |tj	u rt d t| |}
t d	|
 t|
tdd
tjg D ]}t d| |jst d qt| ||| |}|du rDt d qt| ||| |}|du rnt d q|\}}|\}}tt||}|dkrt d q|| }||f  S n|tj
u rt| ||tj
}|d  |d fS ||ftjtj
fkr0t| |}|rnt|d tr(|	| n|S n>|tj
u rt| |D ]t}|| dkdkrFt d|  t| ||| t|| |  |}|rFt|d tr|	| n|  S qF| ||| } || }d}|tj
ur(ttjt| }t|}| ||| } | t|| | 9 } tj
}t d|| t d|  t| |}|rnt|d trj|	| n|S |trt d tt||||}|rt|tsddlm } |t!|d |d "tf|dd  }|S |	#| |	rt$t%|	S dS )a  
    Integrate ``f`` over the interval [``a``, ``b``], by rewriting it as a product
    of two G functions, or as a single G function.

    Return res, cond, where cond are convergence conditions.

    Examples
    ========

    >>> from sympy.integrals.meijerint import meijerint_definite
    >>> from sympy import exp, oo
    >>> from sympy.abc import x
    >>> meijerint_definite(exp(-x**2), x, -oo, oo)
    (sqrt(pi), True)

    This function is implemented as a succession of functions
    meijerint_definite, _meijerint_definite_2, _meijerint_definite_3,
    _meijerint_definite_4. Each function in the list calls the next one
    (presumably) several times. This means that calling meijerint_definite
    can be very costly.
    Integratingzwrt %s from %s to %s.z+Integrand has DiracDelta terms - giving up.Nz5Integrand has Singularity Function terms - giving up.ru   Tz  Integrating -oo to +oo.z  Sensible splitting points:)r  reversez  Trying to split atz  Non-real splitting point.z'  But could not compute first integral.z(  But could not compute second integral.Fz)  But combined condition is always false.r   rP   zTrying x -> x + %szChanged limits tozChanged function tor  r  )&r5  r   rk   r=   rO   r   r   r   r   r  r  meijerint_definiter   r  r   is_extended_real_meijerint_definite_2r  rR   r^   rN   rz   r>   r)   r   r    r!   r0   r/   r   r   r  r  r	   r   r  r  r   )rc   ru   r   r   r  Zx_a_Zb_r   r  r   r   res1res2cond1cond2r   rl   splitr  r  r  rd   rd   re   r    s    











*
r  c                 C   s   | dfg}|d d }|h}t |}||vrD||dfg7 }|| t|}||vrl||dfg7 }|| |ttrt t|}||vr||dfg7 }|| |ttrddl	m
} ||}||vr||dfg7 }|| |S )	z6 Try to guess sensible rewritings for integrand f(x). zoriginal integrandr   r   r   r
   zexpand_trig, expand_mul)sincos_to_sumztrig power reduction)r   r   r
   rk   r8   r0   r   r5   r6   sympy.simplify.fur  )rc   ru   rl   origsawexpandedr  reducedrd   rd   re   _guess_expansion}  s.    




r  c                 C   sj   t dd| dd}| ||} |}| dkr2tjdfS t| |D ](\}}td| t||}|r<|  S q<dS )a  
    Try to integrate f dx from zero to infinity.

    The body of this function computes various 'simplifications'
    f1, f2, ... of f (e.g. by calling expand_mul(), trigexpand()
    - see _guess_expansion) and calls _meijerint_definite_3 with each of
    these in succession.
    If _meijerint_definite_3 succeeds with any of the simplified functions,
    returns this result.
    ru   zmeijerint-definite2T)positiver   ZTryingN)r   r   r   r   r  r5  _meijerint_definite_3)rc   ru   dummyr   Zexplanationrl   rd   rd   re   r    s    


r  c                    s   t |  }|r|d dkr|S | jrtd  fdd| jD }tdd |D rg }tj}|D ]\}}||7 }||g7 }q`t| }|dkr||fS dS )	z
    Try to integrate f dx from zero to infinity.

    This function calls _meijerint_definite_4 to try to compute the
    integral. If this fails, it tries using linearity.
    rP   Fz#Expanding and evaluating all terms.c                    s   g | ]}t | qS rd   )r  )r`   r   rt   rd   re   r     rg   z)_meijerint_definite_3.<locals>.<listcomp>c                 s   s   | ]}|d uV  qd S r]   rd   )r`   r   rd   rd   re   rf     rg   z(_meijerint_definite_3.<locals>.<genexpr>N)r  is_Addr5  rj   ri   r   r   rR   )rc   ru   rl   ressr<  r   r   rd   rt   re   r    s    
r  c                 C   s   t t| S r]   )r*  r#   rb   rd   rd   re   r    s    r  c              
   C   sB  ddl m} td|  |st| |dd}|dur|\}}}}td||| tj}	|D ]`\}
}} |
dkrhqTt||
 |||  | |\}
} |	|
t| | 7 }	t|t	| |}|dkrT qqTt
|}|dkrtd ntd	|	 t
||	|fS t| |}|dur>d
D ]8}|\}}}}}td|||| tj}	|D ]\}}}|D ]\}}}t|| | ||||   ||||}|du rtd    dS |\}
}}td|
|| t|t|||}|dkr q|	|
t||| 7 }	q>q0 qq0t
|}|dkr
td|  n0td	|	 |r&|	|f  S t
||	|f  S qdS )a  
    Try to integrate f dx from zero to infinity.

    Explanation
    ===========

    This function tries to apply the integration theorems found in literature,
    i.e. it tries to rewrite f as either one or a product of two G-functions.

    The parameter ``only_double`` is used internally in the recursive algorithm
    to disable trying to rewrite f as a single G-function.
    r   r  r  F)r  N#Could rewrite as single G function:But cond is always False.z&Result before branch substitutions is:r  z!Could rewrite as two G functions:zNon-rational exponents.zSaxena subst for yielded:z&But cond is always False (full_pb=%s).)r   r  r5  r  r   r   r1  r?  rR   r7  r  r  rW  r  r  )rc   ru   r  r  r   r   r   r   r   rl   r   r/  r,  rH  rI  rS  s1f1rT  s2f2r   Zf1_Zf2_rd   rd   re   r    sd    












r  c                 C   sf  | }|}t ddd}| ||} td|  t| |s@td dS tj}| jrXt| j}nt	| t
rj| g}nd}|rg }g }|r| }	t	|	t
rt|	}
|
jr||
j7 }q|zt|	jd |\}}W n ty   d}Y n0 |dkr|| n
||	 q||	jrt|	}
|
jr"||
j7 }q|||	jjvr|zt|	j
|\}}W n ty\   d}Y n0 |dkr|||t|	j  ||	 q|||	 q|t| }t| } || jvrtd	| | tt|d}|d
krtd dS | t||  }td|| t||||fS t| |}|durb|\}}}}td||| tj}|D ]^\}}} t|| |||  | |\}} ||t| || 7 }t|t| |}|d
krH qqHt|}|d
krtd ntd| ddl m!} t||}|"t#s|t#|9 }|||| }t	|t$s*|||| }ddl%m&} t||||f||||||ddfS dS )a  
    Compute the inverse laplace transform
    $\int_{c+i\infty}^{c-i\infty} f(x) e^{tx}\, dx$,
    for real c larger than the real part of all singularities of ``f``.

    Note that ``t`` is always assumed real and positive.

    Return None if the integral does not exist or could not be evaluated.

    Examples
    ========

    >>> from sympy.abc import x, t
    >>> from sympy.integrals.meijerint import meijerint_inversion
    >>> meijerint_inversion(1/x, x, t)
    Heaviside(t)
    r   TrE  zLaplace-invertingzBut expression is not analytic.Nr   rP   z.Expression consists of constant and exp shift:Fz3but shift is nonreal, cannot be a Laplace transformz1Result is a delta function, possibly conditional:r  r  z"Result before branch substitution:r  )InverseLaplaceTransform)'r   r   r5  r  r   r   is_Mulr   rj   r   r)   popr
   r   r   rz   r   r   r   r+   r   r   r   r   r=   r3   r  r  r  rR   r  r  r   r  rk   r>   r(  r  r  )rc   ru   r   r  Zt_shiftrj   r'  Zexponentialsr    r&  r   r   r   rl   r   r   r   r   r   r/  r  r  rd   rd   re   meijerint_inversion  s    
















r  )T)F)F)F)T)T)F)r   r   typingr   tDictr   tTuplesympyr   
sympy.corer   r   sympy.core.addr   sympy.core.cacher   sympy.core.containerssympy.core.exprtoolsr	   sympy.core.functionr
   r   r   r   r   sympy.core.mulr   sympy.core.numbersr   r   r   sympy.core.relationalr   r   r   sympy.core.sortingr   r   sympy.core.symbolr   r   r   sympy.core.sympifyr   (sympy.functions.combinatorial.factorialsr   $sympy.functions.elementary.complexesr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   &sympy.functions.elementary.exponentialr)   r*   r+   #sympy.functions.elementary.integersr,   %sympy.functions.elementary.hyperbolicr-   r.   r/   r0   (sympy.functions.elementary.miscellaneousr2   $sympy.functions.elementary.piecewiser3   r4   (sympy.functions.elementary.trigonometricr5   r6   r7   r8   sympy.functions.special.besselr9   r:   r;   r<   'sympy.functions.special.delta_functionsr=   r>   *sympy.functions.special.elliptic_integralsr?   r@   'sympy.functions.special.error_functionsrA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   'sympy.functions.special.gamma_functionsrL   sympy.functions.special.hyperrM   rN   -sympy.functions.special.singularity_functionsrO   	integralsrQ   sympy.logic.boolalgrR   rS   rT   rU   rV   sympy.polysrW   rX   sympy.utilities.iterablesrY   sympy.utilities.miscrZ   r5  r[   r^   r   Zsympy.utilities.timeutilsr   timeitry   r  r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r*  r-  r1  r7  r?  rW  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rd   rd   rd   re   <module>   s   44	 R"!$'	
{

m
I  2z 
%Z
  G