
    wgI                    @   d 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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 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'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZE ddlFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZS ddlTmUZUmVZVmWZW ddlXmYZYmZZZm[Z[ ddl\m]Z] ddl^m_Z_ ddl`maZa d Zbd Zcd Zdd Zed Zf G d de      Zg G d de      Zh ed      Zi G d d      Zj G d d      Zk G d  d!      Zl G d" d#      Zm G d$ d%      Zn G d& d'en      Zo G d( d)en      Zp G d* d+en      Zq G d, d-en      Zr G d. d/en      Zs G d0 d1en      Zt G d2 d3en      Zu G d4 d5en      Zv G d6 d7en      Zw G d8 d9en      Zx G d: d;en      Zy G d< d=en      Zz G d> d?en      Z{ G d@ dAen      Z|dB Z}dC Z~dD ZdE ZdF ZdG ZdH ZdI ZdJ ZdK ZdL ZdMag  edN      dOddPfdQZdR ZdMa	 	 dUdSZdUdTZyM)Va@  
Expand Hypergeometric (and Meijer G) functions into named
special functions.

The algorithm for doing this uses a collection of lookup tables of
hypergeometric functions, and various of their properties, to expand
many hypergeometric functions in terms of special functions.

It is based on the following paper:
      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.

It is described in great(er) detail in the Sphinx documentation.
    )defaultdict)product)reduce)prod)SYMPY_DEBUG)SDummysymbolssympifyTupleexpandIpiMul
EulerGammaoozooexpand_funcAddnanExprRational)Moddefault_sort_key)!expsqrtrootlog
lowergammacosbesseligamma
uppergammaexpinterfsinbesseljEiCiSiShisinhcoshChifresnelsfresnelc
polar_lift	exp_polarfloorceilingrf	factoriallerchphi	Piecewisere
elliptic_k
elliptic_e)polarify
unpolarify)hyperHyperRep_atanhHyperRep_power1HyperRep_power2HyperRep_log1HyperRep_asin1HyperRep_asin2HyperRep_sqrts1HyperRep_sqrts2HyperRep_log2HyperRep_cosasinHyperRep_sinasinmeijerg)Matrixeyezeros)apartpolyPoly)residue)	powdenest)siftc                 v    | j                   rt        | d      S | j                         \  }} t        |d      | z   S N   )	is_Numberr   as_coeff_Add)xcs     _/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/simplify/hyperexpand.py_mod1r]   U   s7     	{{1ay>>DAqq!9q=    c                 84   	
 t        dt              \  
 
fd} 
fd} |ddt        
              |fdt         
              |t        j
                  z
  fdz  ft        t        
      t        t        j
                  z   
      dz  g      t        ddgg      t        t        j
                  z
  
z  d
z
  z  t        j
                  z
  
z  d
z
  z  gd
z
  z  
dz
  z  d
z
  z  gg              |d	d
t        t        
      dg      t        d
z  dgg      t        d

dz
  z  gddgg              |t        j
                  dft	        d      ft        t        
      dg      t        ddgg      t        t        dd      dd
z
  z  dz  gddgg              |t        j
                  t        j
                  ft	        d      ft        t        
      t        t        dd      
      g      t        ddgg      t        t        dd      t        j
                  gd
d
z
  z  dz  gg              |t        j
                  z   ft        j
                  ft        t         
      t         t        j
                  z
  
       g      t        ddgg      t        d g
dz  dz
  z  dz  d
z
  z  t        j
                  
dz  dz
  z  d
z
  z  z
  gg              | gt        j
                  gt        t        
      t        
      g      t        ddgg      t        d g
z  d
z
  z  dd
z
  z  dz  gg              |ddgdt        j
                  z  gt        t!        
      dg      t        ddgg      t        
t        j
                  z
  d
z
  z  dd
z
  z  dz  gddgg              |t        j
                  t        j
                  gt        j"                  gt        t%        
      t'        
      g      t        dt(        z  dgg      t        t        dd      dd
z  dz
  z  gt        dd      t        j
                  gg              |t        dd      t        j
                  gt        j"                  gt        t%        
      t'        
      g      t        ddt(        z  gg      t        t        dd      dd
z  dz
  z  gt        dd      t        j
                  gg              |t        dd      ddgt        j
                  dgt        
t        
      z  t        
      dg      t        t        dd      t        j"                   d
z  z  t        dd      gg      t        t        j
                  d
d
z
  z  dz  gdd

dz
  z  gg dg              |t        dd      ddgddgt        t        t        j
                  
      t+        
      dg      t        t        dd      dd
z  z  z
  dd
z  z  dd
z  z  gg      t        
dz  
dz
  z  ddgdd
dz
  z  z  dt        j
                  gg dg              |dggt        
dz
  z  t        
      z  t-        dz
  
      z  dg      t        dz
  dgg      t        dz
  
z   dgddgg              |gdz  gt        
t        j
                  z
  z  t        
dz        z  t/        t        j
                  z
  
dz        z  t1        t        j
                  z         z  dt        j
                  z
  z  z  
t        j
                  z
  z  t        
dz        z  t/        t        j
                  z   
dz        z  t1        t        j
                  z         z  dt        j
                  z
  z  z  g      t        ddgg      t        
dz  
dz  g
dz  
dz  dz  z
  gg             t3        d      
z  } |gdz   gt        | z  z  t-        |      z  t        
      z  g      t        ddgg      t         dgd
gg              |t        dd      gt        j
                  gt        
      t5        t(        
z        t6         z  t9        t6        t5        
      z        z  z
          |dgt        dd      t        dd      gt        t5        t(              t6        t;        dt5        
      z        z  t=        dt?        
d      z  t        t6        t(        z  dz        z  t5        t(              z        z  tA        dt5        
      z        tC        dt?        
d      z  t        t6        t(        z  dz        z  t5        t(              z        z  z   z  t        t6         t(        z  dz        z  dt?        
d      z  z  t5        t(              t?        
d      z  t;        dt5        
      z        tC        dt?        
d      z  t        t6        t(        z  dz        z  t5        t(              z        z  t6        tA        dt5        
      z        z  t=        dt?        
d      z  t        t6        t(        z  dz        z  t5        t(              z        z  z   z  t        t6         t(        z  dz        z  dz  dg      t        g dg      t        t        dd      dt        dd      g
t        dd      dgg dg              |t        j
                  gt        dd      dz   gt        dz  dz
  z  t6         z  t5        t(        
z        z  t9        t6        t5        
      z        z  dz  dz
  z  t3        d      
z   z  z  t-        t3        d      
z        z  dz  dz
  z  t        
      z  g      t        g dg      t        t        dd      ddgd dgdd
gg              |ddgddgt        tE        
      tG        
      z
  t        
      dtH        g      t        d
z  ddd
z  gg      t        g dd
ddgg dg dg              |dt        j
                  ftA        dt5        
      z                |g gt        t1              
dz
  dz  z  z  t/        dz
  dt5        
      z        z  t1              
ddz  z
  z  z  t/        dt5        
      z        z  g      t        ddgg      t        ddg
dz
  gg             d
t        dd      z  z  		fd}	fd} |g t        j
                  t        j
                  z   gt         |dz  dz
  
       |dz  
      
t        dd      z  z   |dz  dz
  
      t5        
      z   |dz  
      
t        dd      z  z  g      ddz  z  z  t1        dz        z  
ddz  z
  dz  z  z  t        g dg      t        g ddt        j
                  z
  ddgddt        j
                  dg
dddz
  gg             dd
z  t        dd      z  z  tK        t6        t(        z  dz        z  	 |g t        j
                  z   dz  gdt5        t3        d      
z        z  ddz  z
  z  t1        dz        dz  z  t        tM        dz  dz
  	      t/        dz  dz
  	      z  	t/        dz  	      tM        dz  dz
  	      z  t/        dz  dz
  	      tM        dz  	      z  z
  z  	dz  t/        dz  	      z  tM        dz  	      z  	dz  t/        dz  	      tM        dz  dz
  	      z  t/        dz  dz
  	      tM        dz  	      z  z   z  g      z  t        g dg      t        dt        dd      ddgdddz  z
  dz  t        dd      dgddddz  z
  t        dd      gd
z  dddz
  gg              |gt        j
                  z
  dz  gt        
t        j
                  z
  z  t/        t        j
                  z
  t5        
            dz  z  
dz
  z  t/        t        j
                  z
  t5        
            z  t/        t        dd      z
  t5        
            z  
t        dd      z
  z  t/        t        dd      z
  t5        
            dz  z  g      t        t1        t        j
                  z         dz   dt        j
                  z
  z  z  dt1        t        j
                  z
        z  t1        t        j
                  z         z  ddz
  z  z  dgg      t        ddz  z
  ddg
dz  t        j
                  z
  t        j
                  gd
dgg              |t        j
                  gdz
  gt(        dz
  z  tO        t(        z        z  t        t/        dz
  t5        
            t/        dz
  t5        
            z  t5        
      t/         t5        
            t/        dz
  t5        
            z  t/        dz
  t5        
            t/        t5        
            z  z   z  t/         t5        
            t/        t5        
            z  g      z  t        g dg      t        dz
  t        j
                  dg
d
gdt        j
                   gg              |t        j
                  gt        dd      t        dd      gt        tQ        dt5        
      z        dz  t5        
      z  t;        dt5        
      z        dz  t5        
      z  tA        dt5        
      z        g      t        g dg      t        t        dd      t        j
                  dgdt        dd      t        j
                  gdd
z  dgg              |t        dd      gt        dd      t        dd      gt        t=        t        t(        t6        z  dz        t?        
d      z  dz  t5        t(              z        t(        t        t(        t6        z  dz        t?        
d      z  dz  t5        t(              z  dz  z  z  t;        dt5        
      z        t5        
      z  tA        dt5        
      z        g      t        g dg      t        t        dd      t        dd      dgdt        dd      dgd
dgg              |t        dd      gt        j
                  t        dd      gt        t5        t(              t        t6         t(        z  dz        z  tC        dt?        
d      z  t        t6        t(        z  dz        z  t5        t(              z        z  dt?        
d      z  z  tA        dt5        
      z        t;        dt5        
      z        t5        
      z  g      t        g dg      t        t        dd      t        dd      dgg d d
t        j
                  gg              |t        j
                  z   gdz  dz  z
  dz   gt1              t1        dz  z
  dz         z  t5        
      dz  ddz  z
  z  z  t        t/        dz
  t5        
            t/        dz  z
  t5        
            z  t5        
      t/        t5        
            z  t/        dz  z
  t5        
            z  t5        
      t/        dz
  t5        
            z  t/        dz  z
  dz   t5        
            z  t/        t5        
            t/        dz  z
  dz   t5        
            z  g      z  t        g dg      t        dt        j
                  t        j
                  dg
dz  dz
  d
dz  g
dz  ddz  z
  
dz  gdt        j
                  t        j
                  dz  gg              |ddgddt        dd      gt        tS        dt5        
      z        tG        dt5        
      z        z
  tA        dt5        
      z        t5        
      t;        dt5        
      z        z  dtH        g      t        d
z  dddd
z  gg      t        dt        j
                  dt        dd      dgg d!d
t        j
                  ddgg d"g d"g              |ddgdddz   gt        tG        
       tU        d
       z   tH        z   z  
dz  dz  z
  dz   z  z  
  z  z  t1              tW        
       z
  z  dz
  dz  z  t        
      z  dz  dz  z
  dz   z  
dz  dz  z
  dz   z  z  g      t        dz
  dd
z  dgg      t        ddd
z  dgd ddgdd
dgg d#g             y$)%z Create our knowledge base. za b c, z)clsc           
      ^    t        | |      }j                  t        ||f             y NHyper_FunctionappendFormula)	apbqresfuncabr[   formulaezs	       r\   addzadd_formulae.<locals>.addh   s,    b"%aq!Qi89r^   c                 d    t        | |      }	j                  t        |
d f|||             y rb   rc   )rg   rh   BCMrj   rk   rl   r[   rm   rn   s         r\   addbzadd_formulae.<locals>.addbl   s2    b"%a1ay!QBCr^       rW   r   )rW   rW   )rv   z3/2   )r   r   r      	         )rW   r   r   )rW   rw   r   )r   rW   rw   r   )r   r   r   r   c                 6    t        |       t        |       z   S rb   r"   r(   rk   rn   rZ   s     r\   fpzadd_formulae.<locals>.fp       q!}wq!},,r^   c                 6    t        |       t        |       z
  S rb   r   r   s     r\   fmzadd_formulae.<locals>.fm   r   r^   )rW   r   r   r   )r   rW   r   r   i   )   r   r   )r   r   rW   )r   r   rW   r   r   )r   r   r   r   r   )r   r   r   rw   N),r
   r	   r   rA   r   HalfrL   rB   rC   r@   r   rD   rF   rG   rI   rJ   rE   Oner;   r<   r   rH   r    r"   r#   r2   r   r   r&   r-   r0   r   r.   r1   r)   r   r   r3   r(   r'   r,   r/   r%   r$   )rm   ro   rt   mzr   r   rk   rl   r[   rZ   rn   s   `     @@@@@r\   add_formulaer   d   s   /JAq!Q: :D D BA r?A2q)* 	!QZ1Q3'	A& QVVQ/13 
4	!Q		1qvv:q.!a%(166A:q.!a%*@AQU)QAYA./1 
2	3 		q!1%	&Aq	{(;	!QAY!Q(	)+ 	!&&!qxl	"A&	'	!Q		(2q/1a!e9Q;/!Q8	9; 	!&&!&&	AeH<	"OHROQ$GH	I	!Q		(2q/166*Q1q5	!,<=	>@ 	!QVVaZ166*	!Q'/1"qvv+q*I)IJ	K	!Q		!aRRTAX,q.!a%(!&&1bdQh<Q3G*GHJ 
KL 	!aR166(	!!Q')9!Q)?@	A	!Q		!aR1Q3A;1q5	!45	68 	!Q!AFF(	"A&	'!Q)9	1qvv:A&1q5	!4q!f=	>@
 	!&&!&&	AEE7	A
1.	/	!B$		(2q/2qs1u:.2q/166*, 
-.
 	(2q/166	"QUUG	A
1.	/	!QrT		(2q/2qs1u:.2q/166*, 
-. 	(2q/1a	 1661+	>!$$mA&6:	;	(2q/AEE61Q3<!Q@A	B	!&&!QAYq[)Q1q5	" 
 	(2q/1a	 1a&	+]1-=qA	B	(1a.2qs8+Q!Wb!A#h?@	A	!A#q1u+q!$q!QU)}a&@)L	MO 	!qc61q1u:A.AE11EEqIJ	!a%	vA	1~1v&>?A!qse	QVVaZQqS)'!aff*ac*BBQVV$%%&!_5QVVaZQqS)'!aff*ac*BBQVV$%%&!_56 
7 
!Q		!A#qsacAaC!A#I/0	13 
B	B!q1ug	qb!Jq"--qQx8	9	!Q		1"a1a&!	"$
 "aAFF8SVd2a4j1"oc!DG)n.L%LM 	!x1~x1~.	$r(Ad1T!W9o-hqa|C"QK7OPTUWPX7X.YY"1T!W9ohqa|C"QK7OPTUWPX7X.YYZ [2aL!"#DAJ,0 r(41:%tAd1gIx$q!*SQRSUQUVWQW[@XY]^`Ya@a7b'b()$qay/(9(1T!QZ<PSTUVXTXYZTZP[C[\`ac\dCd:e(e(f gr"uQw<  !"  
 
		(2q/8Aq>B !8Aq>BBD 
EF 	!&&!x1~q1u-	AaC!Gqb!$r!t*,S47^;AaC!GjnQ.1"55Az"~a/01AaC!GSV#% 
& 
		(2q/1a(1qb!*q!Qi@	AC 	!Q!Q	AQQJ7	8	!A#q!RT"#	$	Aq!lLI	JL QVVJQtAwY(aS	q!q1uai.(Q$q'	)BBq!a!A#g,&wq!DG)'<<> 
?	!Q	6Aq6AA<"89; 	
!Xa^
A-- 	affaQVV$	AaC!GQAaCAx1~,=!=AaC!GQQ'AaCAx1~4E)EG 
Hr!t9
1Q3Z
  !Q1WaK 0
1 
		QVVaZA&Q"Q1q5!# 
$% 	
1Q3!Q
	!B$q& 11AaQVVQqS!
DB!"
"a!A#g	.uQqSz1}	<	1q!$WQqS1Wa%88GAaCOGAaC!GQ$77acAgq)'!A#q/9: ;Agac1o%gac1o5AwqsAwqsQw':: 1q!,WQqS!_<= >	? 
@
@ 
		!Xa^Q*a!A#gq[(2q/15QAaC!Q0a%Aq1u%' 
() 	!q166z1Q3	QVVaZQVVT!W!=q!@@QUGAJQ88!hq!n,d1g67Xa^a'(Xa^1CT!W)Mq)PPR 
S 
5QVV$a''AFFQJ75QVV$$U1qvv:%66q1q5zA  
 
!ac'1a1Q3
AFF";aAYG	HJ 	!&&Aq1u:	QUC1I		QQ(QQ)@@a'1"d1g.wq1ud1g/FF#AE473GAtAw4GGH I!T!W%gaa&99; 
<
<
 
		!a%#QQVVaR" 
#	$ 	!&&HQNHQN3	QtAwY!$q')4$q'	?1+<T!W+DaQi" 
#			(2q/1661-8B?AFF/KaQRSTQTVW[Y	Z	\ 	(1a.	HQNHQN;	T!V!A !!%"!!#
 "$s2a46{41:'=a'?R'H1&L!LO Ad1gItAw&Ad1gI!
" 
		(2q/HQOQ78B?Q/AQ') 
*+& 	(1a.	AFFHQN3	RU1W&41:c!B$q&k1$r(:<< >?tAqz\K Ad1gIAd1gItAw&)
* 
		(2q/HQNA;+AAFF+- 
./" 	!QZ1Q31Q37Q;/	q%!a!$	$Q	Q1W'=	=	QQ(1q$q')BBaDG,,WQqS1Wd1g-FFaQQ001q1d1g1NNDG$WQqS1Wq[$q'%BBD 
E
E
 
		!QVVQVVQ'A#q1ua1%A#q!ac'1Q3'QVVQVVRT*, 
-
. 	!Q!QA'	QtAwY#aQi.0aQi$q'$qay/"91jJ 
K	!A#q!Q1%&	'	!QVVQQ3 Q1%  	" 
#	$( 	!QQ1Q3K	CGfQm+j891adQqSj1n;MNQB1":uQx*Q*;;<a!eaZG3q61a4!A#:>*Aq!taczA~&') 
* 
!A#q"Q$"#	$	"Qr!tAQBqAa 
	r^   c                    	
 t        t        t        d            \  	
t        d      	
 fd}fd} |z   gg z   gg t        t	        dz
        z  z  t              z  t              z  t	        dz
        z   z  z  g      t        ddgg      t        z   dgdz   gg      |       fd}t        d	t              z        }t        d	t              z        }t        d	t              z        t        d	z  z
  }t        d	t              z        } |gg t        j                  z
  gg t        t        t              t        j                  z
  z  z  ||z  ||z  z
  z  t        t              z  z  ||z  ||z  z   z  t        t              z  z  g      t        g d
g      t        t        j                  z
  ddgt        j                  gddgg      |       y )Nabczrhoc                 T    j                  t        | |||	
g||||
             y rb   )re   MeijerFormula)anrg   bmrh   rq   rr   rs   matcherrk   rl   r[   rm   r   rn   s           r\   ro   z!add_meijerg_formulae.<locals>.add  s3    b"b"a!Q3&'Aw8 	9r^   c                    | j                   d   }| j                  \  }}d}t        ||z
  j                               sd}||}}t        ||z
  j                               s||z
  dkD  ry ||g}|r||g}|||z
  it	        |gg |g       fS )Nr   FT)r   r   r]   simplify
G_Function)rj   rZ   yrn   swappedlrk   r   s         r\   detect_uppergammaz/add_meijerg_formulae.<locals>.detect_uppergamma  s    GGAJww1a!e%%'(GQ!a%!!#$A	FAAQ1q5!:qc2q"#===r^   rW   r   rw   c           
         | j                   d   }| j                  \  }}}t        ||z
  j                               dk(  rVt        ||z
  j                               dk(  ryt        j
                  t        j
                  t        j                  f}|||}}}nt        ||z
  j                               dk(  r6t        j
                  t        j                  t        j
                  f}|||}}}n5t        j                  t        j
                  t        j
                  f}|||}}}t        ||z
  j                               dk7  s\t        ||z
  j                               dk7  s=t        ||z
  j                               t        j
                  k7  s||z
  dkD  s||z
  dkD  ry
|it        |gg |D 	cg c]  }	|t        j
                  z
  |	z    c}	g       fS c c}	w )z.https://functions.wolfram.com/07.34.03.0984.01r   N)r   r   r]   r   r   r   Zeror   )rj   rZ   uvwsigx1x2r   trk   s             r\   detect_3113z)add_meijerg_formulae.<locals>.detect_3113  s   GGAJ''1a!a%!!#$)a!e%%'(A-66166166*C1aABa!e%%'(A-vvqvvqvv.q!rAvvqvvqvv.q!r21r6##%&!+1r6##%&!+1q5""$%/B
a"fqj1vz1#rC+HqAJN+H"MMM+Hs   +Grv   )rx   r   r   )listmapr	   rL   r#   r   r$   r'   r   r!   r+   r   r*   r   r   )rm   ro   r   r   sc_S_rr   rk   rl   r[   r   rn   s   `       @@@@@r\   add_meijerg_formulaer     s   c%()JAq!Q
,C9 9> S	2QW~ra!eQV#CF*:a+;;a!eQS\)+ 	,Axq"1s7|,-N2 	Ad1gIA	QtAwYB	Ad1gIA	B
1T!W9AR!QAFF
#RRQZ("R%!A#+6RAqtbd{+RA 	  	
|QVVR#aAFF^aAY?@r^   c                       fd}|S )z@ Create a function that simplifies rational functions in ``z``. c                     | j                         \  }}|j                         }t        |      j                  t        |            \  }}}||j	                         z  |j	                         z  S )z6 Efficiently simplify the rational function ``expr``. )as_numer_denomr   rP   cancelas_expr)exprnumerdenomr[   rn   s       r\   simpzmake_simp.<locals>.simp  s^    **,uua.//UA?5%5==?"U]]_44r^   ru   )rn   r   s   ` r\   	make_simpr     s    5 Kr^   c                  N    t         r| D ]  }t        |d        t                y y )N )end)r   print)argsrk   s     r\   debugr     s(     	A!	 r^   c                   t     e Zd ZdZ fdZed        Zed        Zed        Z fdZ	d Z
d Zd	 Zd
 Z xZS )rd   z( A generalized hypergeometric function. c                     t         |   |       }t        t        t	        t
        |             |_        t        t        t	        t
        |             |_        |S rb   )super__new__r   r   r   r   rg   rh   )r`   rg   rh   obj	__class__s       r\   r   zHyper_Function.__new__  sD    goc"S_-.S_-.
r^   c                 2    | j                   | j                  fS rb   )rg   rh   selfs    r\   r   zHyper_Function.args  s    !!r^   c                 V    t        | j                        t        | j                        fS rb   )lenrg   rh   r   s    r\   sizeszHyper_Function.sizes  s    DGGc$''l++r^   c                 :    t        d | j                  D              S )zt
        Number of upper parameters that are negative integers

        This is a transformation invariant.
        c              3   b   K   | ]'  }t        |j                  xr |j                         ) y wrb   )bool
is_integeris_negative.0rZ   s     r\   	<genexpr>z'Hyper_Function.gamma.<locals>.<genexpr>  s"     IA467Is   -/)sumrg   r   s    r\   r#   zHyper_Function.gamma  s     IIIIr^   c                 R    t         |          | j                  | j                  fz   S rb   )r   _hashable_contentrg   rh   r   r   s    r\   r   z Hyper_Function._hashable_content  s*    w(*dgg.  	r^   c                 D    t        | j                  | j                  |      S rb   )r?   rg   rh   )r   args     r\   __call__zHyper_Function.__call__  s    TWWdggs++r^   c                     t        | j                  t              t        | j                  t              }}d }| j                   ||       ||      fS )a6  
        Compute the invariant vector.

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

        The invariant vector is:
            (gamma, ((s1, n1), ..., (sk, nk)), ((t1, m1), ..., (tr, mr)))
        where gamma is the number of integer a < 0,
              s1 < ... < sk
              nl is the number of parameters a_i congruent to sl mod 1
              t1 < ... < tr
              ml is the number of parameters b_i congruent to tl mod 1

        If the index pair contains parameters, then this is not truly an
        invariant, since the parameters cannot be sorted uniquely mod1.

        Examples
        ========

        >>> from sympy.simplify.hyperexpand import Hyper_Function
        >>> from sympy import S
        >>> ap = (S.Half, S.One/3, S(-1)/2, -2)
        >>> bq = (1, 2)

        Here gamma = 1,
             k = 3, s1 = 0, s2 = 1/3, s3 = 1/2
                    n1 = 1, n2 = 1,   n2 = 2
             r = 1, t1 = 0
                    m1 = 2:

        >>> Hyper_Function(ap, bq).build_invariants()
        (1, ((0, 1), (1/3, 1), (1/2, 2)), ((0, 2),))
        c           
          t        | j                               } t        d | D              s| j                  d        t	        | D cg c]  \  }}|r|t        |      f c}}      } | S c c}}w )Nc              3   B   K   | ]  }t        |d    t                yw)r   N)
isinstancer   r   s     r\   r   z>Hyper_Function.build_invariants.<locals>.tr.<locals>.<genexpr>$  s     =z!A$,=s   c                     t        | d         S Nr   r   rZ   s    r\   <lambda>z=Hyper_Function.build_invariants.<locals>.tr.<locals>.<lambda>%  s    *:1Q4*@ r^   key)r   itemsanysorttupler   )bucketmodvaluess      r\   trz+Hyper_Function.build_invariants.<locals>.tr"  sg    &,,.)F=f== @A& ;3 !#f+.  FMs   	A,
)rT   rg   r]   rh   r#   )r   abucketsbbucketsr   s       r\   build_invariantszHyper_Function.build_invariants  sD    F "$''5143G(	 

BxL"X,77r^   c                    | j                   |j                   k7  ry| j                  | j                  |j                  |j                  fD cg c]  }t        |t               c}\  }}}}d}||f||ffD ]  \  }}	t        t        |j                               t        |	j                               z         D ]  }
|
|vs!|
|	vst        ||
         t        |	|
         k7  r  yt        ||
         }t        |	|
         }|j                          |j                          t        ||      D ]  \  }}|t        ||z
        z  }   |S c c}w )zd Estimate how many steps it takes to reach ``func`` from self.
            Return -1 if impossible. rw   r   )r#   rg   rh   rT   r]   setr   keysr   r   zipabs)r   rj   params	oabuckets	obbucketsr   r   diffr   obucketr   l1l2ijs                  r\   
difficultyzHyper_Function.difficulty,  sD    ::#77DGGTWWdgg>4@ 594G 4@0	9h !)9 5)7LM 
	'OFG4.glln1EEF 	'v%3g+=vc{+s73</@@&+&'#,'		BK 'DAqCAJ&D'	'
	' !4@s   Ec                    | j                   D ]7  }| j                  D ]&  }||z
  j                  s||z
  j                  du s%  y 9 | j                   D ]	  }|dk(  s	 y | j                  D ]  }|j                  s|j                  s y y)a  
        Decide if ``self`` is a suitable origin.

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

        A function is a suitable origin iff:
        * none of the ai equals bj + n, with n a non-negative integer
        * none of the ai is zero
        * none of the bj is a non-positive integer

        Note that this gives meaningful results only when none of the indices
        are symbolic.

        Fr   T)rg   rh   r   r   is_nonpositive)r   rk   rl   s      r\   _is_suitable_originz"Hyper_Function._is_suitable_originC  s       	!AWW !E%%1q5*=*=*F !	!  	AAv	  	A|| 0 0	 r^   )__name__
__module____qualname____doc__r   propertyr   r   r#   r   r   r   r   r   __classcell__r   s   @r\   rd   rd     sc    2 " " , , J J,-8^.r^   rd   c                   X     e Zd ZdZ fdZed        Z fdZd Zd Z	ed        Z
 xZS )r   z A Meijer G-function. c                 F   t         |   |       }t        t        t	        t
        |             |_        t        t        t	        t
        |             |_        t        t        t	        t
        |             |_        t        t        t	        t
        |             |_	        |S rb   )
r   r   r   r   r   r   r   rg   r   rh   )r`   r   rg   r   rh   r   r   s         r\   r   zG_Function.__new__c  sr    goc"S_-.S_-.S_-.S_-.
r^   c                 ^    | j                   | j                  | j                  | j                  fS rb   )r   rg   r   rh   r   s    r\   r   zG_Function.argsk  s!    $''47733r^   c                 :    t         |          | j                  z   S rb   )r   r   r   r   s    r\   r   zG_Function._hashable_contento  s    w(*TYY66r^   c                 p    t        | j                  | j                  | j                  | j                  |      S rb   )rK   r   rg   r   rh   )r   rn   s     r\   r   zG_Function.__call__r  s%    tww$''1==r^   c                    t        d      D cg c]  }t        t               c}x}\  }}}}t        || j                  | j
                  | j                  | j                  f      D ])  \  }}|D ]  }	|t        |	         j                  |	       ! + t        |d      D ]=  \  }}
|j                         D ]%  \  }}|d   |j                  fd|
       |||<   ' ? t        |D cg c]  }t        |       c}      S c c}w c c}w )a  
        Compute buckets for the fours sets of parameters.

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

        We guarantee that any two equal Mod objects returned are actually the
        same, and that the buckets are sorted by real part (an and bq
        descendending, bm and ap ascending).

        Examples
        ========

        >>> from sympy.simplify.hyperexpand import G_Function
        >>> from sympy.abc import y
        >>> from sympy import S

        >>> a, b = [1, 3, 2, S(3)/2], [1 + y, y, 2, y + 3]
        >>> G_Function(a, b, [2], [y]).compute_buckets()
        ({0: [3, 2, 1], 1/2: [3/2]},
        {0: [2], y: [y, y + 1, y + 3]}, {0: [2]}, {y: [y]})

        rz   )TFFTr   c                     | z
  S rb   ru   )rZ   x0s    r\   r   z,G_Function.compute_buckets.<locals>.<lambda>  s    R r^   )r   reverse)ranger   r   r   r   rg   r   rh   r]   re   r   r   r   dict)r   r   dictspanpappbmpbqdiclisrZ   flipmr   r   r  s                 @r\   compute_bucketszG_Function.compute_bucketsu  s   0 BGq%JAk$&7%JJ"S#sEDGGTWWdggtww#GH 	(HC (E!H$$Q'(	( U$>? 	ICIIK 51X

/
>A	 u-!d1g-.. &K .s   D(Dc                     t        | j                        t        | j                        t        | j                        t        | j                        fS rb   )r   r   rg   r   rh   r   s    r\   	signaturezG_Function.signature  s1    DGGc$''lCL#dgg,GGr^   )r   r   r   r   r   r  r   r   r   r  r  r  r  s   @r\   r   r   `  sE      4 47>#/J H Hr^   r   rZ   c                   4    e Zd ZdZd ZddZed        Zd Zy)rf   a-  
    This class represents hypergeometric formulae.

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

    Its data members are:
    - z, the argument
    - closed_form, the closed form expression
    - symbols, the free symbols (parameters) in the formula
    - func, the function
    - B, C, M (see _compute_basis)

    Examples
    ========

    >>> from sympy.abc import a, b, z
    >>> from sympy.simplify.hyperexpand import Formula, Hyper_Function
    >>> func = Hyper_Function((a/2, a/3 + b, (1+a)/2), (a, b, (a+b)/7))
    >>> f = Formula(func, z, None, [a, b])

    c                 H   | j                   j                  D cg c]  }t        |z    }}| j                   j                  D cg c]  }t        |z   dz
   }}t        t	        | z  | j
                  t	        | z  z
  }t        |t              } |j                         dz
  }|g}t        |      D ]<  }	|j                  | j
                  |d   j                  | j
                        z         > t        |      | _        t        dgdg|z  z   g      | _        t        |      }
|
j                  dt!        |d            }
 |j"                         dd }|j%                          |
j'                  |t        |g        |j"                         d   z        | _        yc c}w c c}w )z
        Compute a set of functions B=(f1, ..., fn), a nxn matrix M
        and a 1xn matrix C such that:
           closed_form = C B
           z d/dz B = M B.
        rW   rw   r   N)rj   rg   _xrh   r   rn   rQ   degreer  re   r   rL   rq   rr   rM   
col_insertrN   
all_coeffsr  
row_insertrs   )r   closed_formrk   afactorsrl   bfactorsr   rP   n_r  r   s               r\   _compute_basiszFormula._compute_basis  s\    %)IILL1qBF11(,		51BFQJ55#x. 466#x.#88D"~DKKMAMq 	0AHHTVVAbEJJtvv../	0 !s1u&FLLE!QK(DOOab!			a&!+odoo.?.B!BC# 25s   FFNc                 
   t        |      }t        |      }t        |      D cg c]  }|j                  |      s| }}|| _        || _        || _        || _        || _        || _        || j                  |       y y c c}w rb   )	r   hasrn   r
   rq   rr   rs   rj   r'  )	r   rj   rn   ri   r
   rq   rr   rs   rZ   s	            r\   __init__zFormula.__init__  s    AJcl%g.>$((1+1>>	
 ?$  ?s
   B B c                 v    t        d t        | j                  | j                        t        j
                        S )Nc                     | |d   |d   z  z   S Nr   rW   ru   r   r  s     r\   r   z%Formula.closed_form.<locals>.<lambda>      !AaD1I+ r^   r   r   rr   rq   r   r   r   s    r\   r"  zFormula.closed_form  %    -s466466/BAFFKKr^   c                 Z   ! ddl m} |j                  }|j                  }t	        |      t	         j
                  j                        k7  s+t	        |      t	         j
                  j                        k7  rt        d      g } j                  D ]w  }| j
                  j                  j                  v r|j                  |       7| j
                  j                  j                  v r|j                  |       kt        d|       t        | D cg c]*  }t        t        t         j                  |                  , }}||fD 	cg c]  }	t        |	t                c}	\  }
}|
|fD cg c]/  }|j#                         D ci c]  \  }}|t	        |       c}}1 c}}}\  }} j                  D cg c]  }dg }}g }t%               }|D ](  ! j
                  j                   j
                  j                  fD 	cg c]  }	t        |	!fd       c}	\  }}|
|f||ffD ]3  \  }}t'        t        |j)                               t        |j)                               z         D ]  }||vs!||vst	        ||         t	        ||         k7  r mt         j                  |      D ]  \  }}!|   j*                  r||   D cg c]  }|j-                  |      s| }}!j/                         }||xx   |z  cc<   |D ]Q  }||   D ]G  } ||j1                  |      |z
  |      \  }|j*                  rt        d      |j                  |       I S   6 g }t         j                  |      D ]a  \  }}!|   }t3        t5        |            }t7        t9        |            }|j                  t;        ||dz         D  cg c]  } || z   	 c}        c |j=                   fdt        | D               + |S c c}w c c}	w c c}}w c c}}}w c c}w c c}	w c c}w c c} w )	z
        Find substitutions of the free symbols that match ``func``.

        Return the substitution dictionaries as a list. Note that the returned
        instantiations need not actually match, or be valid!

        r   )solvez-Cannot instantiate other number of parametersz?At least one of the parameters of the formula must be equal to c                 8    t        | j                              S rb   )r]   xreplace)rZ   repls    r\   r   z-Formula.find_instantiations.<locals>.<lambda>	  s    U1::d;K5L r^   zValue should not be truerW   c           	   3   n   K   | ],  }t        t        t        j                  |                   . y wrb   )r  r   r   r
   )r   r   r   s     r\   r   z.Formula.find_instantiations.<locals>.<genexpr>#  s&     Y1d4DLL!(<#=>Ys   25)sympy.solversr3  rg   rh   r   rj   	TypeErrorr
   r   re   
ValueErrorr   r  r   r   rT   r]   r   r	   r   r   free_symbolsr)  copyr5  r4   minr5   maxr  extend)"r   rj   r3  rg   rh   symbol_valuesrk   r   	base_replr   r   r   r   valsa_invb_invr&  critical_valuesresult_nsymb_asymb_br   r   r   exprsrepl0targetn0a0min_max_r%  r6  s"   `                                @r\   find_instantiationszFormula.find_instantiations  s    	(WWWWr7c$)),,''3r7c$)),,6G+GKLL 	>ADIILL%%%$$R(diill'''$$R( 9:"= > >	> &}57 $s4<<89: 7	 7ACRIfd651I('24 4 6<\\^D'!TCID 4u(,51A355W 	ZD#yy||TYY\\:< #6+LM <NFF%-v$668J#K ZtFKKM2T',,.5IIJ 0C6)s'/A"6#;/3ws|3DD#&t||_#E 047//$29#, N$$((1+ N N $		aB$) 0D*0+ 0&+DMM%,@6,I2&N#%??*45O*P$P $B	000	0Z$ "4<<A KGAtaB T+D"3t9-DMM5tax3H"Ia26"IJ	K
 YQWHXYY7	Z8 I7ID 45< !O #JsB   /PP0PPP:
PP
P#!P#P(P)NNN)	r   r   r   r   r'  r*  r  r"  rQ  ru   r^   r\   rf   rf     s-    .D4%$ L L:r^   rf   c                       e Zd ZdZd Zd Zy)FormulaCollectionz- A collection of formulae to use as origins. c                    i | _         i | _        g | _        t        | j                         | j                  D ]  }|j                  j
                  }t        |j                        dkD  r,| j                   j                  |g       j                  |       ]|j                  j                         }|| j                  j                  |i       |<    y)z7 Doing this globally at module init time is a pain ... r   N)symbolic_formulaeconcrete_formulaerm   r   rj   r   r   r
   
setdefaultre   r   )r   fr   invs       r\   r*  zFormulaCollection.__init__,  s    !#!#T]]#
  	FAFFLLE199~!&&11%<CCAFff--/DE&&11%<SA	Fr^   c                 @   |j                         }|j                  }|| j                  v r#|| j                  |   v r| j                  |   |   S || j                  vryg }| j                  |   D ]r  }|j	                  |      }|D ]Z  }|j
                  j                  |      }|j                         s/|j                  |      }	|	dk(  rF|j                  |	|||f       \ t |j                  d        |D ]  \  }
}}}t        ||j                  dg |j                  j                  |      |j                  j                  |      |j                   j                  |            }t#        d |j                  |j                   |j                  fD              r|c S  y)a{  
        Given the suitable target ``func``, try to find an origin in our
        knowledge base.

        Examples
        ========

        >>> from sympy.simplify.hyperexpand import (FormulaCollection,
        ...     Hyper_Function)
        >>> f = FormulaCollection()
        >>> f.lookup_origin(Hyper_Function((), ())).closed_form
        exp(_z)
        >>> f.lookup_origin(Hyper_Function([1], ())).closed_form
        HyperRep_power1(-1, _z)

        >>> from sympy import S
        >>> i = Hyper_Function([S('1/4'), S('3/4 + 4')], [S.Half])
        >>> f.lookup_origin(i).closed_form
        HyperRep_sqrts1(-1/4, _z)
        Nrw   c                     | d   S r   ru   r   s    r\   r   z1FormulaCollection.lookup_origin.<locals>.<lambda>k  s
    AaD r^   r   c              3   z   K   | ]3  }|j                  t        j                  t        t         t               5 y wrb   )r)  r   NaNr   r   )r   es     r\   r   z2FormulaCollection.lookup_origin.<locals>.<genexpr>o  s%     NaquuQUUBS1Ns   9;)r   r   rV  rU  rQ  rj   r5  r   r   re   r   rf   rn   rq   subsrr   rs   r   )r   rj   rY  r   possiblerX  replsr6  func2r   r&  f2s               r\   lookup_originzFormulaCollection.lookup_origin?  s   * ##%

D***t--e44))%055 ...''. 		8A))$/E 8-002''-2:tQ 678		8 	.)!) 	AtQT2qssxx~CCHHTNACCHHTN4BNBDD"$$;MNN			 r^   Nr   r   r   r   r*  rd  ru   r^   r\   rS  rS  )  s    7F&3r^   rS  c                   ,    e Zd ZdZd Zed        Zd Zy)r   z
    This class represents a Meijer G-function formula.

    Its data members are:
    - z, the argument
    - symbols, the free symbols (parameters) in the formula
    - func, the function
    - B, C, M (c/f ordinary Formula)
    c                     ||||fD cg c]!  }t        t        t        t        |             # c}\  }}}}t	        ||||      | _        || _        || _        |
| _        || _	        || _
        |	| _        y c c}w rb   )r   r   r   r   r   rj   rn   r
   _matcherrq   rr   rs   )r   r   rg   r   rh   rn   r
   rq   rr   rs   r   r   s               r\   r*  zMeijerFormula.__init__  su    ACRR@PQ1%c&!n!56QBBr2r2.	 Rs   &A5c                 v    t        d t        | j                  | j                        t        j
                        S )Nc                     | |d   |d   z  z   S r-  ru   r.  s     r\   r   z+MeijerFormula.closed_form.<locals>.<lambda>  r/  r^   r0  r   s    r\   r"  zMeijerFormula.closed_form  r1  r^   c                    |j                   | j                  j                   k7  ry| j                  |      }||\  }}t        |j                  |j
                  |j                  |j                  | j                  g | j                  j                  |      | j                  j                  |      | j                  j                  |      d
      S y)z
        Try to instantiate the current formula to (almost) match func.
        This uses the _matcher passed on init.
        N)r  rj   rh  r   r   rg   r   rh   rn   rq   r_  rr   rs   )r   rj   ri   r_  newfuncs        r\   try_instantiatezMeijerFormula.try_instantiate  s    
 >>TYY000mmD!?MD' WZZWZZ!%!%T!2DFFKK4E!%T!2D: : r^   N)r   r   r   r   r*  r  r"  rm  ru   r^   r\   r   r   u  s'     L L:r^   r   c                       e Zd ZdZd Zd Zy)MeijerFormulaCollectionz=
    This class holds a collection of meijer g formulae.
    c                     g }t        |       t        t              | _        |D ]4  }| j                  |j                  j
                     j                  |       6 t        | j                        | _        y rb   )r   r   r   rm   rj   r  re   r  )r   rm   formulas      r\   r*  z MeijerFormulaCollection.__init__  s]    X&#D) 	BGMM',,00188A	BT]]+r^   c                     |j                   | j                  vry| j                  |j                      D ]  }|j                  |      }||c S  y)z* Try to find a formula that matches func. N)r  rm   rm  )r   rj   rq  ri   s       r\   rd  z%MeijerFormulaCollection.lookup_origin  sK    >>.}}T^^4 	G))$/C
	r^   Nre  ru   r^   r\   ro  ro    s    ,r^   ro  c                       e Zd ZdZd Zy)Operatora  
    Base class for operators to be applied to our functions.

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

    These operators are differential operators. They are by convention
    expressed in the variable D = z*d/dz (although this base class does
    not actually care).
    Note that when the operator is applied to an object, we typically do
    *not* blindly differentiate but instead use a different representation
    of the z*d/dz operator (see make_derivative_operator).

    To subclass from this, define a __init__ method that initializes a
    self._poly variable. This variable stores a polynomial. By convention
    the generator is z*d/dz, and acts to the right of all coefficients.

    Thus this poly
        x**2 + 2*z*x + 1
    represents the differential operator
        (z*d/dz)**2 + 2*z**2*d/dz.

    This class is used only in the implementation of the hypergeometric
    function expansion algorithm.
    c                    | j                   j                         }|j                          |g}|dd D ]  }|j                   ||d                 |d   |d   z  }t	        |dd |dd       D ]  \  }}|||z  z  } |S )a  
        Apply ``self`` to the object ``obj``, where the generator is ``op``.

        Examples
        ========

        >>> from sympy.simplify.hyperexpand import Operator
        >>> from sympy.polys.polytools import Poly
        >>> from sympy.abc import x, y, z
        >>> op = Operator()
        >>> op._poly = Poly(x**2 + z*x + y, x)
        >>> op.apply(z**7, lambda f: f.diff(z))
        y*z**7 + 7*z**7 + 42*z**5
        rW   Nrw   r   )_polyr   r  re   r   )r   r   opcoeffsdiffsr[   rds           r\   applyzOperator.apply  s     &&( 	(ALLE"I'	(1IeAhqr
E!"I. 	DAq1HA	r^   N)r   r   r   r   r|  ru   r^   r\   rt  rt    s    4r^   rt  c                       e Zd ZdZd Zy)MultOperatorz! Simply multiply by a "constant" c                 .    t        |t              | _        y rb   )rQ   r  rv  )r   ps     r\   r*  zMultOperator.__init__  s    !R[
r^   N)r   r   r   r   r*  ru   r^   r\   r~  r~    s
    +!r^   r~  c                       e Zd ZdZd Zd Zy)ShiftAz Increment an upper index. c                 x    t        |      }|dk(  rt        d      t        t        |z  dz   t              | _        y )Nr   z"Cannot increment zero upper index.rW   r   r:  rQ   r  rv  )r   ais     r\   r*  zShiftA.__init__  s4    R[7ABB"R%!)R(
r^   c                 H    dd| j                   j                         d   z  z  S )Nz<Increment upper %s.>rW   r   rv  r   r   s    r\   __str__zShiftA.__str__  s$    &!DJJ,A,A,CA,F*FGGr^   Nr   r   r   r   r*  r  ru   r^   r\   r  r    s    %)Hr^   r  c                       e Zd ZdZd Zd Zy)ShiftBz Decrement a lower index. c                 ~    t        |      }|dk(  rt        d      t        t        |dz
  z  dz   t              | _        y )NrW   z"Cannot decrement unit lower index.r  r   bis     r\   r*  zShiftB.__init__  s8    R[7ABB"b1f+/2.
r^   c                 N    dd| j                   j                         d   z  dz   z  S )Nz<Decrement lower %s.>rW   r   r  r   s    r\   r  zShiftB.__str__  s)    &!DJJ,A,A,CA,F*F*JKKr^   Nr  ru   r^   r\   r  r    s    $/Lr^   r  c                       e Zd ZdZd Zd Zy)UnShiftAz Decrement an upper index. c                    t        t        t        |||g            \  }}}|| _        || _        || _        t        |      }t        |      }|j                  |      dz
  }|dk(  rt        d      t        ||z  t              }|D ]  }|t        t        |z   t              z  } t        d      }t        ||z  |z
  |      x}	}
|D ]  }|	|
|dz
  j                  |      z   z  }	 |	j                  d       }|dk(  rt        d      t        t        |	j                         dd |      j                         j                  |t        |z  dz         t              }	t        |	|z
  |z  t              | _        y) Note: i counts from zero! rW   r   z"Cannot decrement unit upper index.Az0Cannot decrement upper index: cancels with lowerNrw   r   r   r   _ap_bq_ipopr:  rQ   r  r	   as_polynthr   r   r_  rv  )r   rg   rh   r   rn   r  r  rk   r  r%  Drl   b0s                r\   r*  zUnShiftA.__init__  sl   Wr2qk23	B"X"XVVAY]7ABB2rN 	"Ab1fb!!A	" #JRTBY""A 	(Aa!e__Q'''A	( eeAhY7 2 3 3 allnSb)1-557<<Q2	JBO1q5"*b)
r^   c                 V    d| j                   d| j                  d| j                  dS )Nz<Decrement upper index # of , .>r  r  r  r   s    r\   r  zUnShiftA.__str__/  "    ;?778<$((L 	Lr^   Nr  ru   r^   r\   r  r    s    %*BLr^   r  c                       e Zd ZdZd Zd Zy)UnShiftBz Increment a lower index. c                    t        t        t        |||g            \  }}}|| _        || _        || _        t        |      }t        |      }|j                  |      dz   }|dk(  rt        d      t        t        |dz
  z  t              }|D ]  }|t        t        |z   dz
  t              z  }! t        d      }t        |dz
  |z  |z
  dz   |      }	t        ||      }
|D ]  }|
|	|j                  |      z   z  }
 |
j                  d      }|dk(  rt        d      t        t        |
j                         dd |      j                         j                  |t        |dz
  z  dz         t              }
t        ||
z
  |z  t              | _        y)r  rW   r   z Cannot increment -1 lower index.rq   z*Cannot increment index: cancels with upperNrw   r  )r   rg   rh   r   rn   r  r  rl   rq   r  r%  rk   r  s                r\   r*  zUnShiftB.__init__7  s   Wr2qk23	B"X"XVVAY]7?@@R!Vb! 	&Ab1fqj"%%A	& #J"q&!b1$a(AJ 	$A!aiil"#A	$ UU1X7IJJallnSb)1-557<<r26{Q !#% 1q5"*b)
r^   c                 V    d| j                   d| j                  d| j                  dS )Nz<Increment lower index #r  r  r  r  r   s    r\   r  zUnShiftB.__str__Y  r  r^   Nr  ru   r^   r\   r  r  4  s    $ *DLr^   r  c                       e Zd ZdZd Zd Zy)MeijerShiftAz Increment an upper b index. c                 R    t        |      }t        |t        z
  t              | _        y rb   r   rQ   r  rv  r  s     r\   r*  zMeijerShiftA.__init__a  s    R["r'2&
r^   c                 B    d| j                   j                         d   z  S )Nz<Increment upper b=%s.>rW   r  r   s    r\   r  zMeijerShiftA.__str__e  s    (DJJ,A,A,CA,FGGr^   Nr  ru   r^   r\   r  r  ^  s    ''Hr^   r  c                       e Zd ZdZd Zd Zy)MeijerShiftBz Decrement an upper a index. c                 X    t        |      }t        d|z
  t        z   t              | _        y rV   r  r  s     r\   r*  zMeijerShiftB.__init__l  s!    R[!b&2+r*
r^   c                 H    dd| j                   j                         d   z
  z  S )Nz<Decrement upper a=%s.>rW   r  r   s    r\   r  zMeijerShiftB.__str__p  s$    (A

0E0E0G0J,JKKr^   Nr  ru   r^   r\   r  r  i  s    '+Lr^   r  c                       e Zd ZdZd Zd Zy)MeijerShiftCz Increment a lower b index. c                 T    t        |      }t        | t        z   t              | _        y rb   r  r  s     r\   r*  zMeijerShiftC.__init__w  s    R[2#(B'
r^   c                 D    d| j                   j                         d    z  S )Nz<Increment lower b=%s.>rW   r  r   s    r\   r  zMeijerShiftC.__str__{  s"    (TZZ-B-B-DQ-G,GHHr^   Nr  ru   r^   r\   r  r  t  s    &(Ir^   r  c                       e Zd ZdZd Zd Zy)MeijerShiftDz Decrement a lower a index. c                 X    t        |      }t        |dz
  t        z
  t              | _        y rV   r  r  s     r\   r*  zMeijerShiftD.__init__  s!    R["q&2+r*
r^   c                 H    d| j                   j                         d   dz   z  S )Nz<Decrement lower a=%s.>rW   r  r   s    r\   r  zMeijerShiftD.__str__  s$    (DJJ,A,A,CA,F,JKKr^   Nr  ru   r^   r\   r  r    s    &+Lr^   r  c                       e Zd ZdZd Zd Zy)MeijerUnShiftAz Decrement an upper b index. c           
      8   t        t        t        |||||g            \  }}}}}|| _        || _        || _        || _        || _        t        |      }t        |      }t        |      }t        |      }|j                  |      dz
  }t        dt              t        d |D              z  t        d |D              z  }t        d      }	t        ||	z
  |	      t        ||	      t        fd|D              z  t        fd|D              z  }
|
j                  d      }|dk(  rt        d      t        t        |
j                         d	d
 |	      j!                         j#                  |	|t        z
        t              }
t        ||
z
  |z  t              | _        y	)r  rW   c              3   J   K   | ]  }t        |t        z
  t                y wrb   rQ   r  r   rl   s     r\   r   z*MeijerUnShiftA.__init__.<locals>.<genexpr>  s     <AtAFB/<   !#c              3   J   K   | ]  }t        t        |z
  t                y wrb   r  r  s     r\   r   z*MeijerUnShiftA.__init__.<locals>.<genexpr>  s     CaYZDaQSDTCar  r  c              3   .   K   | ]  }d z   |z
    ywrW   Nru   r   rk   r  s     r\   r   z*MeijerUnShiftA.__init__.<locals>.<genexpr>  s     6aq1uqy6   c              3   0   K   | ]  } |z   d z
    ywr  ru   r  s     r\   r   z*MeijerUnShiftA.__init__.<locals>.<genexpr>  s     =WqrAvz=Ws   r   z(Cannot decrement upper b index (cancels)Nrw   )r   r   r   _anr  _bmr  r  r  rQ   r  r   r	   r  r:  r   r   r_  rv  )r   r   rg   r   rh   r   rn   r  r  r  r%  r  r  s               @r\   r*  zMeijerUnShiftA.__init__  sb    Wr2r2q.A!BCBB"X"X"X"XVVAY]BK$<<<<tCa^`Ca?aa#JaOAJ62666=WTV=W9WWUU1X7GHHallnSb)1-557<<QRH"M1q5"*b)
r^   c                     d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<Decrement upper b index #r  r  r  r  r  r  r  r  r   s    r\   r  zMeijerUnShiftA.__str__  .    EIWW&*hh$((DHHN 	Nr^   Nr  ru   r^   r\   r  r    s    '*<Nr^   r  c                       e Zd ZdZd Zd Zy)MeijerUnShiftBz Increment an upper a index. c           
      p   t        t        t        |||||g            \  }}}}}|| _        || _        || _        || _        || _        t        |      }t        |      }t        |      }t        |      }|j                  |      dz   }t        |t              }|D ]  }	|t        d|	z
  t        z   t              z  }! |D ]  }	|t        |	dz
  t        z
  t              z  }! t        d      }
t        |
|z   dz
  |
      }t        d|
      }|D ]  }|| |z   z  } |D ]
  }|||z
  z  } |j                  d      }|dk(  rt        d      t        t        |j                         dd |
      j                         j!                  |
d|z
  t        z         t              }t        ||z
  |z  t              | _        y)r  rW   rq   r   z(Cannot increment upper a index (cancels)Nrw   r   r   r   r  r  r  r  r  r  rQ   r  r	   r  r:  r   r   r_  rv  r   r   rg   r   rh   r   rn   r  r  rk   rq   r  r%  rl   r  s                  r\   r*  zMeijerUnShiftB.__init__  s    Wr2r2q.A!BCBB"X"X"X"XVVAY]BK 	&Aa!ebj"%%A	& 	&Aa!ebj"%%A	& #JR!QAJ 	A1"q&MA	 	A!a%LA	 UU1X7GHHallnSb)1-557<<q2v{! 1q5"*b)
r^   c                     d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<Increment upper a index #r  r  r  r  r   s    r\   r  zMeijerUnShiftB.__str__  r  r^   Nr  ru   r^   r\   r  r    s    '%*NNr^   r  c                       e Zd ZdZd Zd Zy)MeijerUnShiftCz Decrement a lower b index. c           
      d   t        t        t        |||||g            \  }}}}}|| _        || _        || _        || _        || _        t        |      }t        |      }t        |      }t        |      }|j                  |      dz
  }t        dt              }|D ]  }	|t        |	t        z
  t              z  } |D ]  }	|t        t        |	z
  t              z  } t        d      }
t        ||
z   |
      }t        ||
      }|D ]  }||dz   |z
  z  } |D ]  }|| |z   dz
  z  } |j                  d      }|dk(  rt        d      t        t        |j                         dd |
      j                         j!                  |
t        |z
        t              }t        ||z
  |z  t              | _        y)r  rW   rr   r   z(Cannot decrement lower b index (cancels)Nrw   r  )r   r   rg   r   rh   r   rn   r  r  rl   rr   r  r%  rk   r  s                  r\   r*  zMeijerUnShiftC.__init__  s    Wr2r2q.A!BCBB"X"X"X"XVVAY]BK 	"Aa"fb!!A	" 	"Ab1fb!!A	" #JaOAJ 	A!a%!)A	 	A1"q&1*A	 UU1X7GHHallnSb)1-557<<QRH"M1q5"*b)
r^   c                     d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<Decrement lower b index #r  r  r  r  r   s    r\   r  zMeijerUnShiftC.__str__  r  r^   Nr  ru   r^   r\   r  r    s    &$*LNr^   r  c                       e Zd ZdZd Zd Zy)MeijerUnShiftDz Increment a lower a index. c           
      p   t        t        t        |||||g            \  }}}}}|| _        || _        || _        || _        || _        t        |      }t        |      }t        |      }t        |      }|j                  |      dz   }t        |t              }|D ]  }	|t        d|	z
  t        z   t              z  }! |D ]  }	|t        |	dz
  t        z
  t              z  }! t        d      }
t        |dz
  |
z
  |
      }t        d|
      }|D ]  }|| |z   z  } |D ]
  }|||z
  z  } |j                  d      }|dk(  rt        d      t        t        |j                         dd |
      j                         j!                  |
|dz
  t        z
        t              }t        ||z
  |z  t              | _        y)r  rW   rq   r   z(Cannot increment lower a index (cancels)Nrw   r  r  s                  r\   r*  zMeijerUnShiftD.__init__  s    Wr2r2q.A!BCBB"X"X"X"XVVAY]BK 	&Aa!ebj"%%A	& 	&Aa!ebj"%%A	& #Ja!QAJ 	A1"q&MA	 	A!a%LA	 UU1X7GHHallnSb)1-557<<rAv{! 1q5"*b)
r^   c                     d| j                   d| j                  d| j                  d| j                  d| j                  dS )Nz<Increment lower a index #r  r  r  r  r   s    r\   r  zMeijerUnShiftD.__str__>  r  r^   Nr  ru   r^   r\   r  r    s    &%*NNr^   r  c                   L    e Zd ZdZd Zed        Zed        Zed        Zd Z	y)ReduceOrderz8 Reduce Order by cancelling an upper and a lower index. c                 l   t        |      }t        |      }||z
  }|j                  r|dk  ry|j                  r|j                  ryt        j                  |       }t        j                  }t        |      D ]  }|t        |z   |z   ||z   z  z  } t        |t              |_        ||_        ||_        |S )z< For convenience if reduction is not possible, return None. r   N)r   
is_Integerr   r   rt  r   r   r   r  r  rQ   rv  _a_b)r`   r  bjr%  r   r  ks          r\   r   zReduceOrder.__new__F  s    R[R[G||q1u==R..$EEq 	(A"r'A+Q''A	( !R[
r^   c                    t        |      }t        |      }||z
  }|j                  s|j                  syt        j	                  |       }t
        j                  }t        |      D ]  }||t        z  |z   |z   z  } t        |t              |_
        |dk(  r||_        ||_        |S t        d|dz
  d      |_        t        d|dz
  d      |_        |S )zN Cancel b + sign*s and a + sign*s
            This is for meijer G functions. Nrw   rW   F)evaluate)r   r   r  rt  r   r   r   r  r  rQ   rv  r  r  r   )r`   rl   rk   signr%  r   r  r  s           r\   _meijerzReduceOrder._meijer\  s     AJAJE==$EEq 	#A$r'A+/"A	# !R[
2:DGDG
  !QUU3DG!QUU3DGr^   c                 (    | j                  ||d      S )Nrw   r  )r`   rl   rk   s      r\   meijer_minuszReduceOrder.meijer_minusv  s    {{1a$$r^   c                 4    | j                  d|z
  d|z
  d      S rV   r  )r`   rk   rl   s      r\   meijer_pluszReduceOrder.meijer_plusz  s    {{1q5!a%++r^   c                 <    d| j                   d| j                  dS )Nz"<Reduce order by cancelling upper z with lower r  )r  r  r   s    r\   r  zReduceOrder.__str__~  s    WWdgg 	r^   N)
r   r   r   r   r   classmethodr  r  r  r  ru   r^   r\   r  r  C  sK    B,  2 % % , ,r^   r  c                 X   t        |       } t        |      }| j                  |       |j                  |       g }g }| D ]c  }d}t        t        |            D ]#  } ||||         }||j	                  |        n ||j                  |       S|j                  |       e |||fS )z? Order reduction algorithm used in Hypergeometric and Meijer G r   N)r   r   r  r   r  re   )	rg   rh   genr   nap	operatorsrk   rw  r   s	            r\   _reduce_orderr    s    	bB	bBGGGGGG
CI 
!s2w 	AQ1B~q			
 :JJqMR 
! Ir^   c                     t        | j                  | j                  t        t              \  }}}t        t        | t        |       |fS )a  
    Given the hypergeometric function ``func``, find a sequence of operators to
    reduces order as much as possible.

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

    Return (newfunc, [operators]), where applying the operators to the
    hypergeometric function newfunc yields func.

    Examples
    ========

    >>> from sympy.simplify.hyperexpand import reduce_order, Hyper_Function
    >>> reduce_order(Hyper_Function((1, 2), (3, 4)))
    (Hyper_Function((1, 2), (3, 4)), [])
    >>> reduce_order(Hyper_Function((1,), (1,)))
    (Hyper_Function((), ()), [<Reduce order by cancelling upper 1 with lower 1.>])
    >>> reduce_order(Hyper_Function((2, 4), (3, 3)))
    (Hyper_Function((2,), (3,)), [<Reduce order by cancelling
    upper 4 with lower 3.>])
    )r  rg   rh   r  r   rd   r   )rj   r  nbqr  s       r\   reduce_orderr    s>    . (+GWXCi%+uc{3Y>>r^   c                    t        | j                  | j                  t        j                  d       \  }}}t        | j
                  | j                  t        j                  t              \  }}}t        ||||      ||z   fS )a  
    Given the Meijer G function parameters, ``func``, find a sequence of
    operators that reduces order as much as possible.

    Return newfunc, [operators].

    Examples
    ========

    >>> from sympy.simplify.hyperexpand import (reduce_order_meijer,
    ...                                         G_Function)
    >>> reduce_order_meijer(G_Function([3, 4], [5, 6], [3, 4], [1, 2]))[0]
    G_Function((4, 3), (5, 6), (3, 4), (2, 1))
    >>> reduce_order_meijer(G_Function([3, 4], [5, 6], [3, 4], [1, 8]))[0]
    G_Function((3,), (5, 6), (3, 4), (1,))
    >>> reduce_order_meijer(G_Function([3, 4], [5, 6], [7, 5], [1, 5]))[0]
    G_Function((3,), (), (), (1,))
    >>> reduce_order_meijer(G_Function([3, 4], [5, 6], [7, 5], [5, 3]))[0]
    G_Function((), (), (), ())
    c                     t        |        S rb   r   r   s    r\   r   z%reduce_order_meijer.<locals>.<lambda>  s    -=qb-A r^   )
r  r   rh   r  r  r   rg   r  r   r   )rj   r   r  ops1nbmr  ops2s          r\   reduce_order_meijerr    so    , #477DGG[5L5L#ACNCd"477DGG[5M5M#35NCd c3S)4$;66r^   c                       fd}|S )z? Create a derivative operator, to be passed to Operator.apply. c                 p    | j                        z  | z  z   }|j                  t                    }|S rb   )r   	applyfuncr   )rr   rz  rs   rn   s     r\   doitz&make_derivative_operator.<locals>.doit  s4    affQiK!A#KK	!%r^   ru   )rs   rn   r  s   `` r\   make_derivative_operatorr    s     Kr^   c                 N    | }t        |      D ]  }|j                  ||      } |S )zk
    Apply the list of operators ``ops`` to object ``obj``, substituting
    ``op`` for the generator.
    )reversedr|  )r   opsrw  ri   os        r\   apply_operatorsr    s1    
 Cc] ggc2Jr^   c           	      n   | j                   | j                  |j                   |j                  fD cg c]  }t        |t               c}\  }}}}t	        t        |j                                     t	        t        |j                                     k7  sEt	        t        |j                                     t	        t        |j                                     k7  rt        | d|      g }d fd}	fd}
t        t        |j                               t        |j                               z   t              D ]X  }d}d}d}d}||v r
||   }||   }||v r
||   }||   }t	        |      t	        |      k7  st	        |      t	        |      k7  rt        | d|      ||||fD cg c]  }t        |t               c}\  }}}}d } |||      } |||      }t	        |      dk(  r| |
g ||||      z  }nt	        |      dk(  r| |	|g |||      z  }np|d	   }|d	   }|d   |z
  dk  s|d   |z
  dk  rt        d
      ||z
  dkD  r| |	|||||      z  }| |
|||||      z  }n| |
|||||      z  }| |	|||||      z  }|||<   |||<   [ |j                          |S c c}w c c}w )a(  
    Devise a plan (consisting of shift and un-shift operators) to be applied
    to the hypergeometric function ``target`` to yield ``origin``.
    Returns a list of operators.

    Examples
    ========

    >>> from sympy.simplify.hyperexpand import devise_plan, Hyper_Function
    >>> from sympy.abc import z

    Nothing to do:

    >>> devise_plan(Hyper_Function((1, 2), ()), Hyper_Function((1, 2), ()), z)
    []
    >>> devise_plan(Hyper_Function((), (1, 2)), Hyper_Function((), (1, 2)), z)
    []

    Very simple plans:

    >>> devise_plan(Hyper_Function((2,), ()), Hyper_Function((1,), ()), z)
    [<Increment upper 1.>]
    >>> devise_plan(Hyper_Function((), (2,)), Hyper_Function((), (1,)), z)
    [<Increment lower index #0 of [], [1].>]

    Several buckets:

    >>> from sympy import S
    >>> devise_plan(Hyper_Function((1, S.Half), ()),
    ...             Hyper_Function((2, S('3/2')), ()), z) #doctest: +NORMALIZE_WHITESPACE
    [<Decrement upper index #0 of [3/2, 1], [].>,
    <Decrement upper index #0 of [2, 3/2], [].>]

    A slightly more complicated plan:

    >>> devise_plan(Hyper_Function((1, 3), ()), Hyper_Function((2, 2), ()), z)
    [<Increment upper 2.>, <Decrement upper index #0 of [2, 2], [].>]

    Another more complicated plan: (note that the ap have to be shifted first!)

    >>> devise_plan(Hyper_Function((1, -1), (2,)), Hyper_Function((3, -2), (4,)), z)
    [<Decrement lower 3.>, <Decrement lower 4.>,
    <Decrement upper index #1 of [-1, 2], [4].>,
    <Decrement upper index #1 of [-1, 3], [4].>, <Increment upper -2.>]
    z not reachable from c                     g }t        t        |             D ]K  }||   | |   z
  dkD  r|}d}n|}d}||   | |   k7  s&| || |      gz  }| |xx   |z  cc<   ||   | |   k7  r&M |S )Nr   rW   rw   )r  r   )frotoincdecr  r   shchs           r\   	do_shiftszdevise_plan.<locals>.do_shifts"  s    s3x 
	A!us1v~!Q%3q6/3
|#A" Q%3q6/
	 
r^   c           	      .     | |d fd      S )z( Shift us from (nal, nbk) to (al, nbk). c                     t        | |         S rb   )r  r  r   s     r\   r   z2devise_plan.<locals>.do_shifts_a.<locals>.<lambda>4  s    vad| r^   c                 ,    t        | z   z   |      S rb   )r  )r  r   aotherbothernbkrn   s     r\   r   z2devise_plan.<locals>.do_shifts_a.<locals>.<lambda>5  s    hq6z3<A&N r^   ru   )nalr  alr  r  r  rn   s    ` ``r\   do_shifts_az devise_plan.<locals>.do_shifts_a2  s    b";NP 	Pr^   c                 .      || fdd       S )z( Shift us from (nal, nbk) to (nal, bk). c                 ,    t        z   | z   |      S rb   )r  )r  r   r  r  r  rn   s     r\   r   z2devise_plan.<locals>.do_shifts_b.<locals>.<lambda>:  s    hsV|QZA&N r^   c                     t        | |         S rb   )r  r  s     r\   r   z2devise_plan.<locals>.do_shifts_b.<locals>.<lambda>;  s    fQqTl r^   ru   )r  r  bkr  r  r  rn   s   `  ``r\   do_shifts_bz devise_plan.<locals>.do_shifts_b7  s    bN24 	4r^   r   ru   c                 L    g }| D ]  }||k7  s	|j                  | |           |S rb   )r?  )r  r   r   r  s       r\   otherszdevise_plan.<locals>.othersN  s4    A %8HHSV$% Hr^   r   rw   zNon-suitable parameters.)rg   rh   rT   r]   r   r   r   r:  sortedr   r  )rL  originrn   r   r   r   	nabuckets	nbbucketsr  r  r  rz  r  r  r  r  r   r  r  r  namaxamaxr  s     `                   @r\   devise_planr$    s   ^ yy&))VYY		B0D 15VU0C 0D,Hh	9 4 !Sinn.>)?%@@X]]_%&#d9>>3C.D*EEvvFGG
C P
4 D)D,AAGWX 1=!BA,C=!BA,Cr7c#h#b'SX"566JKK #r3') #1*:; )CS	 	1%	1%r7a<;r3FF;;CW\;sBFF;;CGEb6D1v~"bedla&7 !;<<t|a{3R@@{2sB?? {3R@@{3B??	!	!c1f KKMJq0Dd)s   J--J2c                    t        | j                  t              t        | j                  t              }}t	        |t
        j                           dk7  ry|t
        j                     d   }|dk  ryt
        j                  |vryt        |t
        j                           }|j                          |d   }|dk  ryt        | j                        }|j                  |       t        | j                        }|j                  |       |dz  }|D 	cg c]  }	|	|z
  	 }}	|D 	cg c]  }	|	|z
  	 }}	g }
t        |dz
        D ]  }|
j                  t        |dz                ! |
j                          t        |      ||z  z  }|t        |D cg c]  }t!        ||       c} z  }|t        |D cg c]  }t!        ||       c} z  }|
t#        |      gz  }
d}t        |      D ]^  }||z  t        |      z  }|t        |D cg c]  }t!        ||       c} z  }|t        |D cg c]  }t!        ||       c} z  }||z  }` t%        ||      |
| fS c c}	w c c}	w c c}w c c}w c c}w c c}w )z? Try to recognise a hypergeometric sum that starts from k > 0. rW   Nr   )rT   rg   r]   rh   r   r   r   r   r   remover  re   r  r  r7   r   r6   r~  rd   )rj   rn   r   r   rz  r   r  r  r  rZ   r  r%  facrl   rk   r  r  s                    r\   try_shifted_sumr(  t  s<   dggu-tDGGU/ChH
8AFF!AAvvvXXaffAFFH	!AAv
tww-CJJqM
tww-CJJqMFA
Q1q5
C

Q1q5
C

C1q5\ "

6!a%=!"KKM
A,q!t
C33'aAq'((C33'aAq'((CLC	A1X qD1	SS)2a8)**	SS)2a8)**	Q	 #s#S1",,+ 
 (' *)s$   I"II 
0I%
I*&I/c           	         t        | j                  t              t        | j                  t              }}|t        j
                     }|t        j
                     }|j                          |j                          |D cg c]
  }|dk  s	| }}|D cg c]
  }|dk  s	| c}rt        fd|D              rt        S |sy|d   }d}	t        j                  }
t        t        t        |              D ]`  }|	|z  }	|	|dz   z  }	|	t        | j                  D cg c]  }||z   	 c} z  }	|	t        | j                  D cg c]  }||z   	 c} z  }	|
|	z  }
b |
S c c}w c c}w c c}w c c}w )zj Recognise polynomial cases. Returns None if not such a case.
        Requires order to be fully reduced. r   c              3   .   K   | ]  }|d    k    yw)rw   Nru   )r   rk   bl0s     r\   r   z!try_polynomial.<locals>.<genexpr>  s     ,11s2w;,r  Nrw   rW   )rT   rg   r]   rh   r   r   r   allr   r   r   r   r  r   )rj   rn   r   r   rN  r  rZ   al0rk   r'  ri   r%  rl   r+  s                @r\   try_polynomialr.    sK    dggu-tDGGU/ChH	!&&	B	!&&	BGGIGGI
#AF1
#C
#
#AF1
#C
s,,,	BA
C
%%CDrO$ qq1usDGG,qQU,--sDGG,qQU,--s
 J# $
# -,s$    
EE
E" E"E'E,c           	         t        | j                  t              t        | j                  t              }}i }|j	                         D ]@  \  }}|dk7  r||vr y||   }t        |      t        |      f||<   |j                  |d       B |i k7  ryt        j                  |vry|t        j                     \  }}||dgz   f|t        j                  <   t        d      }	t        j                  }
t        j                  }|j	                         D ]  \  }\  }}t        |      t        |      k7  r yt        ||      D ]a  \  }}||z
  j                  r'||z
  }|
t        ||	z   |      z  }
|t        ||      z  }<||z
  }|
t        ||      z  }
|t        ||	z   |      z  }c  t        |
|z  |	      }t!        j"                  |      }g }i }|D ]a  }|j%                         \  }
}|j'                  |	      sDt)        |
|	      }|j*                  st-        d      |j/                         \  \  }}|||z  |fgz  }l|
j'                  |	      rt1        d      |j3                  |	      \  }\  }d}|j4                  r|j6                  }|j8                  }||	k(  rdk(   nm|j:                  rV|j=                  |	      \  }}d}||	k7  r|j=                  |	      \  }}|||	z  |z   k7  rt1        d|z        ||z  }|||z  z  }nt1        d      |j?                  |g       jA                  |
|z  |f       d i }i }t        d	      }|jC                  d
        ddd|z
  z  i}|r3tE        |d   d         D ]  }|||   jG                  |      z  ||dz   <   ! |D ]:  \  }}|j?                  t        j                  g       jA                  |||   z         < |j	                         D ]  \  }}|D ]1  \  } }|j?                  tI        |||      g       jA                  |        3 |jC                  d        tE        d|d   d   dz         D ]2  }| tI        |||      fdtI        ||dz
  |      fg|tI        |||      <   4 | tI        |d|      fdd|z
  z  t        j                  fg|tI        |d|      <    i }!tK        t        j                  gt        |jM                               z         D ]
  \  }}||!|<    tO        |!j	                         d       D cg c]  \  }}tQ        |       }"}}tS        |"      }#tS        dgt        |#      z  g      }$|j	                         D ]  \  }} t!        |  |$|!|   <    tU        t        |#            }%|j	                         D ]  \  }}|D ]  \  } }&| |%|!|   |!|&   f<     tW        | |dg |#|$|%      S c c}}w )z
    Try to find an expression for Hyper_Function ``func`` in terms of Lerch
    Transcendents.

    Return None if no such expression can be found.
    r   NrW   r   zp should be monomialz<Need partial fraction decomposition with linear denominatorszunrecognised form %sz%unrecognised form of partial fractionrn   c                     | d   S rV   ru   r   s    r\   r   ztry_lerchphi.<locals>.<lambda>   s
    1 r^   r   rw   c                     | d   S rV   ru   r   s    r\   r   ztry_lerchphi.<locals>.<lambda>*  s
    QqT r^   rv   c                     | d   S rV   ru   r   s    r\   r   ztry_lerchphi.<locals>.<lambda>4  s
    ad r^   ),rT   rg   r]   rh   r   r   r  r   r   r	   r   r   r   is_positiver6   rO   r   	make_argsr   r)  rQ   is_monomialr9  LTNotImplementedErroras_coeff_mulis_Powr   baseis_Addas_independentrW  re   r   r  r   r8   	enumerater   r  r   rL   rN   rf   )'rj   r   r   pairedr   valuebvalueaintsbintsr   r   r   avaluerk   rl   r  partr   	monomialstermsr   r  indepdepr%  tmpr&  derivrx  rn   monr   r[   transbasisrq   rr   rs   b2s'                                          r\   try_lerchphirO    s	    dggu-tDGGU/ChHFnn&  
U!88+#E{DL1sS$  2~vvX!&&>LE5UaS[)F166Nc
AEEEEEE!' &ffv;#f+% ' 	&DAqA""EAE1%Aq!EAq!AE1%	&&( ua D==DIE 9))+uyy|UAA== 677JUaA1U7A,'I99Q<% 'B C C))!,u::A((C!8FZZ''*FAsAax))!,1acAg~)*@3*FGGFAQTME%&MNNB&&eQ'78=9L EFc
ANN~N&aQi.Cy}Q'( 	*A3q6;;q>)CAJ	* 61!%%$++Ac!fH56 81 	?DAqhq!Q/4;;A>	?	>"q!B%(Q,' 	DA*+XaA->(?)*HQAq,A(B(DE(1a#$	D '(R!Q):$;%&AY$6$8hq!Q 8 E155'D$667 1a*05B+D EA[^ EE EuACF
|A 11g%(c!fA '1 	'EAr%&AeAhb	!"	'' 4D"aA..Es   W	c           
      r   t        d      }| j                  r| j                  D cg c]  }t        |z    }}| j                  D cg c]  }t        |z   dz
   }}t        t	        | z  |t	        | z  z
  }t        |t              } |j                         }g }	t        |      }
t        |      D ]d  }| j                  d   |z   }|	t        |gt        | j                  dd       z   | j                  |      gz  }	||dz
  k  sS| |
||f<   ||
||dz   f<   f t        |	      }t        dgdg|dz
  z  z   g      }t        |      g}t        |      D ]  }|j                  |
||   z           |j                         }|j                          dg|z  }t!        |      D ].  \  }}t!        |||   z        D ]  \  }}||xx   ||z  z  cc<    0 t!        |      D ]6  \  }}| ||dz
     d|dz
  f   z   |j                         d   z  |
|dz
  |f<   8 t#        | |dg |||
      S g }	t        | j                  dd       }t        t%        |            D ]   }|	t        g ||      gz  }	||xx   dz  cc<   " |	t        g ||      gz  }	t        |	      }t%        |      }t        dgdg|dz
  z  z   g      }t        |      }
|t	        | j                   z  |
d|dz
  f<   t        d|      D ]4  }| j                  |dz
     |
||dz
  f<   | j                  |dz
      |
||f<   6 t#        | |dg |||
      S c c}w c c}w )zU
    Create a formula object representing the hypergeometric function ``func``.

    rn   rW   r   N)r	   rg   r  rh   r   rQ   r  rN   r  r?   r   rL   rM   re   r   r  r=  rf   r   )rj   rn   rk   r#  rl   r$  r   rP   r%  rM  rs   r  rq   rr   derivsr   ri   r[   rz  r{  rh   r   s                         r\   build_hypergeometric_formularR  @  sv    	c
Aww$(GG,qBF,,(,01BFQJ00#x. 1S(^#33D"~DKKM!Hq 	 A
QAeQC$twwqr{"33TWWa@AAE1q5y"!Q$!QU(	  5MQC1#q1u+%&'a&q 	'AMM!F1I+&	'DOO			c!eaL 	DAq!!F1I+. 1A!A#	 cN 	JDAq"VAE]1a!e844_T__5Fq5IIAa!eQhK	JtQb!Q22 $''!*s2w 	AeBA&''EqEQJE	 	%B"##5MFQC1#q1u+%&'!HTWWo!QU(q! 	&A''!a%.AaQhKwwq1u~oAadG	& tQb!Q22Y -0s   L/L4c                    t        |       t        |      }}|}t        |      }|dk(  rt        j                  S ddlm} |dk(  r:|dk(  r4| |z   \  }}}	|dk(  r;t        |	|z
  |z
        t        |	      z  t        |	|z
        z  t        |	|z
        z  S |dk(  r |||z
  |	z         dk(  r||}}|dk(  r |||z
  |	z         dk(  r|j                  rh|j                  r\dt        t        |z  dz        z  t        |       z  t        ||z
  dz         z  t        | dz        z  t        |dz  |z
  dz         z  S t        |dz  dz         t        ||z
  dz         z  t        |dz         z  t        |dz  |z
  dz         z  S t        | ||      S )z
    Try to find a closed-form expression for hyper(ap, bq, z), where ``z``
    is supposed to be a "special" value, e.g. 1.

    This function tries various of the classical summation formulae
    (Gauss, Saalschuetz, etc).
    r   r   rv   rW   rw   )r   r>   r   r   sympy.simplify.simplifyr   r#   r   r   r!   r   r?   )
rg   rh   rn   r  qz_r   rk   rl   r[   s
             r\   hyperexpand_specialrX  z  s    r7CGqA	
B1AAvuu0Av!q&r'1a6Q#E!H,U1q5\9%A,FF7xA	*a/aqA7xA	*a/||RT!V}UA2Y.uQUQY/??A2a4[!!&qsQw{!34 4 QqS1W~eAEAI&661q5\""'!a!"45 5 Rr^   Nz0rW   defaultc                     j                   rt        j                  S ddlm} t        d      dk(  rdfd}t        
t               at        d|        t        |       \  } }	|	rt        d	|        nt        d
       t        |       }
|
Ot        d       t        |
|	fd      }t        |z  fd      }t         ||      j                              S t        j                  }t        |       }
|
|
\  } }}t        d|        |	|z  }	t        ||	fd      }t        |z  fd      } ||      j                        }t              dv rst!        | j"                        t!        | j$                        fdk(  rFt'        |       } |||	      j)                  t*        t,              }|j/                  t*              s||z   S t        j1                  |       }|t3        |       }|t        dd       t'        |       }t        d|j4                  d|j6                         |	t9        | |j6                        z  }	 |||	      |z   }t;        |d      j)                  t*        t,              S )a7  
    Try to find an expression for the hypergeometric function ``func``.

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

    The result is expressed in terms of a dummy variable ``z0``. Then it
    is multiplied by ``premult``. Then ``ops0`` is applied.
    ``premult`` must be a*z**prem for some a independent of ``z``.
    r   rT  F)r_  rZ  nonrepsmallc                    t        | j                  j                  | j                  
      |t	        | j
                  j                  | j                  
      
            }t        |t	        | j
                  j                  | j                  
      t        | j
                  j                  d         z  z   
            }dk(  r|j                  t        
            }t        d t        || j                  j                  | j                  
            t        j                        z  }|j                  
	      }r|j                        }|S )Nr   rW   c                     | |d   |d   z  z   S r-  ru   r.  s     r\   r   z5_hyperexpand.<locals>.carryout_plan.<locals>.<lambda>  s    q1ad{ r^   )r  rr   r_  rn   r  rs   rM   shaper  r   r   r   rq   r   r   rewrite)rX  r  rr   rz  ri   ops0prempremultr`  rn   rY  s        r\   carryout_planz#_hyperexpand.<locals>.carryout_plan  s   ACCHHQSS"-s4QSSXXacc25FKMAt4QSSXXacc25F+/ACCIIaL0A+A6BCEGH a<IbM*A*C13388ACC3D,EqvvNwVffRm++g&C
r^   z)Trying to expand hypergeometric function   Reduced order to   Could not reduce order.z  Recognised polynomial.c                 ,    | j                        z  S rb   r   rX  rY  s    r\   r   z_hyperexpand.<locals>.<lambda>  s    166": r^   c                 ,    | j                        z  S rb   rh  ri  s    r\   r   z_hyperexpand.<locals>.<lambda>  s    r!&&*} r^   z+  Recognised shifted sum, reduced order to c                 ,    | j                        z  S rb   rh  ri  s    r\   r   z_hyperexpand.<locals>.<lambda>  s    "QVVBZ- r^   c                 ,    | j                        z  S rb   rh  ri  s    r\   r   z_hyperexpand.<locals>.<lambda>  s    2affRj= r^   )rW   rw   )rv   rW   z  Could not find an origin. z@Will return answer in terms of simpler hypergeometric functions.z  Found an origin:  Tpolar)is_zeror   r   rU  r   r=   _collectionrS  r   r  r.  r  r>   r_  r   r(  r   rg   rh   rR  replacer?   rX  r)  rd  rO  r"  rj   r$  rS   )rj   rn   ra  rY  rc  rb  r`  r   rd  r  ri   r  nopsrX  rz  rq  s    ``````         r\   _hyperexpandrt    sR    	yyuu0A) * ')	
5t< T"ID#
#T*)* r
"C
()C&=>AgIt-DE(1+**2q122 	
A
$
#C
dA;TBt 	3 78A'	4)@AAQA !}S\3tww<$@F$J(.!S!))%1DEuuU|q5L ''-G t$,2	3 /t4	
!4!4c7<<H ;tW\\2..C 	gs#a'AQd#++E3FGGr^   c           	      J  	
 d }t        | j                        t        | j                        t        | j                        	t        | j                        
g }d}|rDd} ||j                  	
fdd	
z         }|	||gz  }d}0 ||j                  	
fdd	
z         }|	||gz  }d}[ |	|j                  	
fddz         }|	||gz  }d} |
|j                  	
fd	dz         }|	||gz  }d} ||j                  fd
dg       }|	||gz  }d} ||j                  fddg       }|	||gz  }d} |	|j                  	fddg       }|
||gz  }d} |
|j                  
fddg       }|
||gz  }d}C|rDt        |j                        k7  sHt        |j                        k7  s0	t        |j                        k7  s
t        |j                        k7  rt        d      |j                          |S )a  
    Find operators to convert G-function ``fro`` into G-function ``to``.

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

    It is assumed that ``fro`` and ``to`` have the same signatures, and that in fact
    any corresponding pair of parameters differs by integers, and a direct path
    is possible. I.e. if there are parameters a1 b1 c1  and a2 b2 c2 it is
    assumed that a1 can be shifted to a2, etc. The only thing this routine
    determines is the order of shifts to apply, nothing clever will be tried.
    It is also assumed that ``fro`` is suitable.

    Examples
    ========

    >>> from sympy.simplify.hyperexpand import (devise_plan_meijer,
    ...                                         G_Function)
    >>> from sympy.abc import z

    Empty plan:

    >>> devise_plan_meijer(G_Function([1], [2], [3], [4]),
    ...                    G_Function([1], [2], [3], [4]), z)
    []

    Very simple plans:

    >>> devise_plan_meijer(G_Function([0], [], [], []),
    ...                    G_Function([1], [], [], []), z)
    [<Increment upper a index #0 of [0], [], [], [].>]
    >>> devise_plan_meijer(G_Function([0], [], [], []),
    ...                    G_Function([-1], [], [], []), z)
    [<Decrement upper a=0.>]
    >>> devise_plan_meijer(G_Function([], [1], [], []),
    ...                    G_Function([], [2], [], []), z)
    [<Increment lower a index #0 of [], [1], [], [].>]

    Slightly more complicated plans:

    >>> devise_plan_meijer(G_Function([0], [], [], []),
    ...                    G_Function([2], [], [], []), z)
    [<Increment upper a index #0 of [1], [], [], [].>,
    <Increment upper a index #0 of [0], [], [], [].>]
    >>> devise_plan_meijer(G_Function([0], [], [0], []),
    ...                    G_Function([-1], [], [1], []), z)
    [<Increment upper b=0.>, <Decrement upper a=0.>]

    Order matters:

    >>> devise_plan_meijer(G_Function([0], [], [0], []),
    ...                    G_Function([1], [], [1], []), z)
    [<Increment upper a index #0 of [0], [], [1], [].>, <Increment upper b=0.>]
    c                     t        t        | |            D ]Q  \  }\  }|z
  j                  s|z
  |z  dkD  s%t        fd|D              s: ||      }| |xx   |z  cc<   |c S  y)aD   Try to apply ``shifter`` in order to bring some element in ``f``
            nearer to its counterpart in ``to``. ``diff`` is +/- 1 and
            determines the effect of ``shifter``. Counter is a list of elements
            blocking the shift.

            Return an operator if change was possible, else None.
        r   c              3   (   K   | ]	  }|k7    y wrb   ru   )r   rZ   rk   s     r\   r   z8devise_plan_meijer.<locals>.try_shift.<locals>.<genexpr>R  s     01Q0s   N)r=  r   r   r,  )	rX  r   shifterr   counteridxrl   r
  rk   s	           @r\   	try_shiftz%devise_plan_meijer.<locals>.try_shiftG  sl     %SAY/ 	KC!QQ""At|a'7000S\#$		r^   TFc                 $    t        |       S rb   )r  r   fanfapfbmfbqrn   s    r\   r   z$devise_plan_meijer.<locals>.<lambda>_      S#sAq!I r^   rW   c                 $    t        |       S rb   )r  r}  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>f  r  r^   c                 $    t        |       S rb   )r  r}  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>m  r  r^   rw   c                 $    t        |       S rb   )r  r}  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>t  r  r^   c                      t        |          S rb   )r  )r   r~  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>z      \#a&-A r^   c                      t        |          S rb   )r  )r   r  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>  r  r^   c                      t        |          S rb   )r  )r   r  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>  r  r^   c                      t        |          S rb   )r  )r   r  s    r\   r   z$devise_plan_meijer.<locals>.<lambda>  r  r^   zCould not devise plan.)r   r   rg   r   rh   r7  r  )r  r  rn   r{  r  changerw  r~  r  r  r  s     `    @@@@r\   devise_plan_meijerr    sN   t svv,C
svv,C
svv,C
svv,C
CF
sBEEI#)% >B4KCFsBEEI#)% >B4KCFsBEEI39& >B4KCFsBEEI39& >B4KCFsBEE#A2rJ>B4KCFsBEE#A2rJ>B4KCFsBEE#A1bI>B4KCFsBEE#A1bI>B4KCFc d d255kSDK/3$ruu+3E4;!":;;KKMJr^   c           
      	   t         
t               a |dk(  rd}| }t        d|        t        d      }t	        |       \  } rt        d|        nt        d       t         j                  |       }|t        d|j                         t        |j                  | |      z  t        |j                  j                  |j                  |      t        |j                  j                  |j                  |      |            }|j                  t        |            }||j                   j                  |j                  |      z  }	|	d   j                  ||      }	t#        |	d	
      S t        d       d fd}
t        d       |
| j$                  | j&                  | j(                  | j*                  ||      \  }}d }D ]@  }t-        |j.                  j                  |dz  t0        t0         i      t0              |_        B  |
 || j&                         || j$                         || j*                         || j(                        d|z        \  }}t#        |j                  ||      d	
      }t#        |j                  d|z        d	
      }t3        |t4              s|j                  d|z        } | |      }|j6                  dkD  sk|j6                  dk(  rht9        |j(                        t9        |j*                        k(  r=t;        |j<                        dk  dur#t?        |      t?        d      k(  r|durd	}|durd	}|d	u r|jA                  |xs d      }n|jA                  |xs d      }|d	u r|jA                  |xs d      }n|jA                  |xs d      }|dur|dur|dk(  rd}|tB        k(  rd}t3        |t4              s|j                  ||      }t3        |t4              s|j                  ||      }d } |||      } |||      }tE        ||      ddtF        fk  r	||k  r|S |S tI        |d   |d         dk  r.tI        |d   |d         dk  rtK        ||f||f ||      d	f      S tK        ||f||f ||      d	f      }	|	jM                  tN              r|st        d       |	jM                  tN              r|r|	S  ||      S )a  
    Try to find an expression for the Meijer G function specified
    by the G_Function ``func``. If ``allow_hyper`` is True, then returning
    an expression in terms of hypergeometric functions is allowed.

    Currently this just does Slater's theorem.
    If expansions exist both at zero and at infinity, ``place``
    can be set to ``0`` or ``zoo`` for the preferred choice.
    NrZ  z1Try to expand Meijer G function corresponding to rn   re  rf  z  Found a Meijer G formula: r   Trn  z;  Could not find a direct formula. Trying Slater's theorem.c                     | D ]>  }t        | |         dkD  sd}||v rt        ||         }|dz   t        | |         k  s> y y)z Test if slater applies. rW   r   FT)r   )r  r  r   r   s       r\   can_doz_meijergexpand.<locals>.can_do  sU     	!A3q6{Q8CFAq53s1v;& 	! r^   c           
      &   t        | |||      }|j                         \  }}}	} +||	      st        j                  dfS t	        |       t	        |      z   t	        |      t	        |      z   k  }
t	        |       t	        |      z   t	        |      t	        |      z   k(  rt              dk  }
|
du rt        j                  dfS t        j                  }|D ]  }t	        ||         dk(  rD||   d   }d}t        |      }|j                  |       |D ]  }|t        ||z
        z  } | D ]  }|t        d|z   |z
        z  } |D ]  }|t        d|z   |z
        z  } |D ]  }|t        ||z
        z  } t        |       t        |      z   D cg c]
  }d|z   |z
   }}t        |      t        |      z   D cg c]
  }d|z   |z
   }}t        t        j                  t	        |      t	        |      z
  z        }||z  }-|z  |z  }t        t        ||      |,-||d       }|||z  z  }Z||   d   }||   dd  D cg c]  }||z
  	 }}t	        |      }|	|   d |dz    D cg c]  }||z
  	 }}t        |      }||   D ]  }|j                  |        t        |      } |	|   d | D ]  }| j                  |        |d   }!t        ||      D "cg c]
  \  }"}|"|z
   }#}"}t        d      }$|$z  }%|D ]?  }t        |d      s |j                   rt#        t%        |            }|%t        ||$z
        z  }%A | D ]  }|%t        d|z
  |$z         z  }% |D ]  }|%t        d|z
  |$z         z  }% |D ]  }|%t        ||$z
        z  }% t'        |%      }%t)        t#        t%        |!                  D ]'  }&t+        |%|$||&z         }'t-        |',fd      }'||'z  }) ||!z   }(t        t        j                  t	        |       t	        |      z   dz   z        }||z  }-|z  |(z  }t        |       t        |      z   D cg c]
  }d|(z   |z
   c}dgz   }t        |      t        |      z   D cg c]
  }d|(z   |z
   }}t        t        ||      |,-||(d       }t        j                  |!z  t/        |!      z  })t)        |      D ]4  }*|)t        j                  |#|*   z  t1        |!||*   z
  dz   |#|*         z  z  })6 | D ]  }|)t        d|z
  |(z         z  }) |D ]  }|)t        ||(z
        z  }) | D ]  }|)t        ||(z
        z  }) |D ]  }|)t        d|z
  |(z         z  }) ||)|z  z  } ||
fS c c}w c c}w c c}w c c}w c c}}"w c c}w c c}w )NFrW   r   r`  rw   r   c                 ,    | j                        z  S rb   rh  )rX  rn   s    r\   r   z3_meijergexpand.<locals>.do_slater.<locals>.<lambda>!	  s    !AFF1I+ r^   )r   r  r   r   r   r   r   r&  r#   r2   NegativeOnert  rd   r   r	   r   rX   introundr   r  rR   r  r7   r6   ).r   r   rg   rh   rn   zfinalrj   r&  r  r  condri   r  bhr'  bor  ajrk   r  rl   r  r  hargrc  hypb_r  kir   r  liaolur   dir   	integrandrz  residaurr   r   r  r  r   s.       `                                      r\   	do_slaterz!_meijergexpand.<locals>.do_slater  s    "b"b)--/3Qc3665= 2wR 3r7SW#44r7SWB#b' 11q6A:D5=665= ff T	A3q6{aVAY"X		" *B5b>)C* .B5R"--C. .B5R"--C. *B5b>)C*+/8d2h+>?aq2vz??+/8d2h+>?aq2vz??q}}s2wR/@ABx Q3)">#s#;T3#$gr4AsSy VAY(+Aqr
3"b2g33G(+AvA7"b2g77"XQ !AIIaL!"XQ !AIIaL!V*-b"+6Aa!e66 #JqD	 .Aq!9aMq1u-I.  2Aq1uqy!11I2 2Aq1uqy!11I2 .Aq1u-I.
 (	2	s59~. !A#Iq"q&9E+E38MNE5LC! "Wq}}s2wR/@1/DEFxQ3)+/8d2h+>?aq2vz?1#E+/8d2h+>?aq2vz??">#s#;T3#$gr4A MMB'	"5q HA1-bbeaA.GGGAH +Aq1urz**A+ 'Aq2v&A' 'Aq2v&A' +Aq1urz**A+ quiT	l DyQ @? 47 7: @?s*   U/:U4U9'U>V=V	,Vr   c                 2    | D cg c]  }d|z
  	 c}S c c}w rV   ru   )r   rZ   s     r\   r   z_meijergexpand.<locals>.trB	  s     !!A!!!s   rW   rw   Fnonrepr\  c                     |du rd}n	|du rd}nd}| j                  t        t        t         t              rd}|| j	                  t
              | j                         fS )NTr   FrW   rv   ry   )r)  r   r   r   countr?   	count_ops)r   r  c0s      r\   weightz_meijergexpand.<locals>.weightr	  sW    4<BU]BB88BbS#& BDJJu%t~~'788r^   z@  Could express using hypergeometric functions, but not allowed.)(_meijercollectionro  r   r	   r  rd  rj   r  r  rr   r_  rn   r  rs   r  r   rq   rS   r   r   rg   rh   rQ   rv  r  r   r   deltar   r:   nur2   r`  r   r=  r   r>  r9   r)  r?   )rj   rY  allow_hyperr`  placefunc0rn   rX  rr   rz  r  slater1cond1r   rw  slater2cond2r  r  w1w2r  r  r   s                        @@@r\   _meijergexpandr    sa     35)E	
=tD 	c
A#D)ID#
#T*)* 	''-A},aff5!!&&$22 ACCHHQSS!,c4QSSXXacc15EqIK KK	!%acchhqssAaDIIa$''	
GH	eN 	c
Atww$''1bINGU"  >q!A#rB3&78"=>r$''{BtwwKDGGbk !B$(NGU Q+48GQ"-T:GeT"

1ac"QAww{	
A#add)s144y0X]5(Z^z!}-L EE}//'"5X6//'":];}//'"5X6//'":];Ee50A:EC<EeT"

1b!eT"

1b!9 
	B		B
2r{q!Rj 7NN
2a5"Q%A#beRU"3q"8'5)GU+;eBi=NOO
 	7E"We$4uRy$6GHAuuU|K ! 	"55<;9r^   c                     t        |       } fd}fd}| j                  t        |      j                  t        |      S )a  
    Expand hypergeometric functions. If allow_hyper is True, allow partial
    simplification (that is a result different from input,
    but still containing hypergeometric functions).

    If a G-function has expansions both at zero and at infinity,
    ``place`` can be set to ``0`` or ``zoo`` to indicate the
    preferred choice.

    Examples
    ========

    >>> from sympy.simplify.hyperexpand import hyperexpand
    >>> from sympy.functions import hyper
    >>> from sympy.abc import z
    >>> hyperexpand(hyper([], [], z))
    exp(z)

    Non-hyperegeometric parts of the expression and hypergeometric expressions
    that are not recognised are left unchanged:

    >>> hyperexpand(1 + hyper([1, 1, 1], [], z))
    hyper((1, 1, 1), (), z) + 1
    c                 V    t        t        | |      |      }|t        | ||      S |S )Nr  )rt  rd   r?   )rg   rh   rn   rz  r`  s       r\   
do_replacezhyperexpand.<locals>.do_replace	  s1    B/GD9R##Hr^   c           	          t        t        | d   | d   |d   |d         |      }|j                  t        t        t
        t
               s|S y )Nr   rW   )r`  r  )r  r   r)  r   r   r   )rg   rh   rn   rz  r  r  r`  s       r\   	do_meijerzhyperexpand.<locals>.do_meijer	  sQ    :beRUBqE2a5A1u>uuS#rB3'H (r^   )r   rr  r?   rK   )rX  r  r`  r  r  r  s    ```  r\   hyperexpandr  	  s8    2 	
A
 99UJ'//CCr^   )FrZ  N)r   collectionsr   	itertoolsr   	functoolsr   mathr   sympyr   
sympy.corer   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sympy.core.modr   sympy.core.sortingr   sympy.functionsr   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<   $sympy.functions.elementary.complexesr=   r>   sympy.functions.special.hyperr?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   sympy.matricesrL   rM   rN   sympy.polysrO   rP   rQ   sympy.seriesrR   sympy.simplify.powsimprS   sympy.utilities.iterablesrT   r]   r   r   r   r   rd   r   r  rf   rS  r   ro  rt  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r$  r(  r.  rO  rR  rX  rq  rt  r  r  r  r  ru   r^   r\   <module>r     sr  t $    @ @ @ @ @  /H H H H H H H H H F5 5 5 5 . - ) )   , *]@	@FAT AH<H <H@ 3ZB BNI IX&: &:R .2 2j!8 !
HX 
H
LX 
L&Lx &LR'Lx 'LTH8 HL8 LI8 IL8 L#NX #NL,NX ,N^0NX 0Nf.NX .Nb=( =@4?87<FR*-Z8@/F73t#J   "eDk11"hHVEN   9B}@'Dr^   