+
    iI                    D   R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHt ^ RIHt ^ RIH t  ^ R	I!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+H,t,H-t-H.t.H/t/H0t0H1t1H2t2H3t3H4t4H5t5H6t6H7t7H8t8H9t9H:t:H;t;H<t<H=t=H>t>H?t?H@t@HAtAHBtB ^ R
ICHDtDHEtE ^ RIFHGtGHHtHHItIHJtJHKtKHLtLHMtMHNtNHOtOHPtPHQtQHRtRHStS ^ RITHUtUHVtVHWtW ^ RIXHYtYHZtZH[t[ ^ RI\H]t] ^ RI^H_t_ ^ RI`Hata R tbR tcR tdR teR tf ! R R]4      tg ! R R]4      th]! R4      ti ! R R4      tj ! R R4      tk ! R R 4      tl ! R! R"4      tm ! R# R$4      tn ! R% R&]n4      to ! R' R(]n4      tp ! R) R*]n4      tq ! R+ R,]n4      tr ! R- R.]n4      ts ! R/ R0]n4      tt ! R1 R2]n4      tu ! R3 R4]n4      tv ! R5 R6]n4      tw ! R7 R8]n4      tx ! R9 R:]n4      ty ! R; R<]n4      tz ! R= R>]n4      t{ ! R? R@]n4      t|RA t}RB t~RC tRD tRE tRF tRG tRH tRI tRJ tRK tRLs. ]! RM4      ^^ RN3RO ltRP tRLsRSRQ ltRSRR ltRL# )Ta@  
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 P                   '       d   \        V ^4      # V P                  4       w  r\        V^4      V ,           #    )	is_Numberr   as_coeff_Add)xcs   & z/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/simplify/hyperexpand.py_mod1r\   U   s7     	{{{1ay>>DAq!9q=    c                B  a aaaa	a
 \        R\        R7      w  oooo
VVVV V
3R lpVVVV V
3R lpV! R	R	\        S
4      4       V! S3R	\        S) S
4      4       V! SS\        P
                  ,
          3^S,          3\        \        SS
4      \        S\        P
                  ,           S
4      ^,          .4      \        ^^ ..4      \        S\        P
                  ,
          S
,          ^S
,
          ,          \        P
                  S,
          S
,          ^S
,
          ,          .S^S
,
          ,          SS
^,
          ,          ^S
,
          ,          ..4      4       V! R
R\        \        S
4      ^.4      \        RS
,          ^ ..4      \        ^ S
S
^,
          ,          .^ ^ ..4      4       V! \        P
                  ^3\	        R4      3\        \        S
4      ^.4      \        ^^ ..4      \        \        R^4      ^^S
,
          ,          ^,          .^ ^ ..4      4       V! \        P
                  \        P
                  3\	        R4      3\        \        S
4      \        \        R^4      S
4      .4      \        ^^ ..4      \        \        R^4      \        P
                  .^ S
^S
,
          ,          ^,          ..4      4       V! S\        P
                  S,           3\        P
                  3\        \        S) S
4      \        S) \        P
                  ,
          S
4      ) .4      \        ^^ ..4      \        ^ S) .S
RS,          ^,
          ,          ^,          ^S
,
          ,          \        P
                  S
RS,          ^,
          ,          ^S
,
          ,          ,
          ..4      4       V! SS) .\        P
                  .\        \        SS
4      \        SS
4      .4      \        ^^ ..4      \        ^ S) .SS
,          ^S
,
          ,          ^^S
,
          ,          ^,          ..4      4       V! ^^.^\        P
                  ,          .\        \!        S
4      ^.4      \        ^^ ..4      \        S
\        P
                  ,
          ^S
,
          ,          ^^S
,
          ,          ^,          .^ ^ ..4      4       V! \        P
                  \        P
                  .\        P"                  .\        \%        S
4      \'        S
4      .4      \        ^\(        ,          ^ ..4      \        \        R^4      R^S
,          ^,
          ,          .\        R^4      \        P
                  ..4      4       V! \        R^4      \        P
                  .\        P"                  .\        \%        S
4      \'        S
4      .4      \        ^ ^\(        ,          ..4      \        \        R^4      R^S
,          ^,
          ,          .\        R^4      \        P
                  ..4      4       V! \        R^4      ^^.\        P
                  ^.\        S
\        S
4      ,          \        S
4      ^.4      \        \        R^4      \        P"                  ) ^S
,          ,          \        ^^4      ..4      \        \        P
                  ^ S
^S
,
          ,          ^,          .^ ^ S
S
^,
          ,          .. RO.4      4       V! \        R^4      ^^.^^.\        \        \        P
                  S
4      \+        S
4      ^.4      \        \        ^^	4      ^^	S
,          ,          ,
          ^^S
,          ,          ^^	S
,          ,          ..4      \        S
^,          S
^,
          ,          ^ ^ .^^S
^,
          ,          ,          ^ \        P
                  .. RO.4      4       V! ^.S.\        S
^S,
          ,          \        S
4      ,          \-        S^,
          S
4      ,          ^.4      \        S^,
          ^ ..4      \        ^S,
          S
,           ^.^ ^ ..4      4       V! S.^S,          .\        S
\        P
                  S,
          ,          \        S
^,          4      ,          \/        S\        P
                  ,
          S
^,          4      ,          \1        S\        P
                  ,           4      ,          ^\        P
                  S,
          ,          ,          S
\        P
                  S,
          ,          \        S
^,          4      ,          \/        S\        P
                  ,           S
^,          4      ,          \1        S\        P
                  ,           4      ,          ^\        P
                  S,
          ,          ,          .4      \        ^^ ..4      \        S
^,          S
^,          .S
^,          S
^,          ^S,          ,
          ..4      4       \3        R4      S
,          pV! S.S^,           .\        VS) ,          S,          \-        SV4      ,          S\        S
4      ,          .4      \        ^^ ..4      \        S) ^.^ S
..4      4       V! \        R^4      .\        P
                  .\        S
4      \5        \(        S
,          4      \6        ) ,          \9        \6        \5        S
4      ,          4      ,          ,
          4       V! ^.\        ^^4      \        ^^4      .\        \5        \(        4      \6        \;        ^\5        S
4      ,          4      ,          \=        ^\?        S
^4      ,          \        \6        \(        ,          ^,          4      ,          \5        \(        4      ,          4      ,          \A        ^\5        S
4      ,          4      \C        ^\?        S
^4      ,          \        \6        \(        ,          ^,          4      ,          \5        \(        4      ,          4      ,          ,           ,          \        \6        ) \(        ,          ^,          4      ,          ^\?        S
^4      ,          ,          \5        \(        4      \?        S
^4      ,          \;        ^\5        S
4      ,          4      \C        ^\?        S
^4      ,          \        \6        \(        ,          ^,          4      ,          \5        \(        4      ,          4      ,          \6        \A        ^\5        S
4      ,          4      ,          \=        ^\?        S
^4      ,          \        \6        \(        ,          ^,          4      ,          \5        \(        4      ,          4      ,          ,           ,          \        \6        ) \(        ,          ^,          4      ,          ^,          ^.4      \        . RO.4      \        \        R^4      ^\        ^^4      .S
\        ^^4      ^ .. RO.4      4       V! \        P
                  S.\        ^^4      S^,           .\        S^S,          ^,
          ,          \6        ) ,          \5        \(        S
,          4      ,          \9        \6        \5        S
4      ,          4      ,          S^S,          ^,
          ,          \3        R4      S
,          S) ,          ,          \-        S\3        R4      S
,          4      ,          S^S,          ^,
          ,          \        S
4      ,          .4      \        . RO.4      \        \        R^4      ^ ^.^ S) ^.^ ^ S
..4      4       V! ^^.^^.\        \E        S
4      \G        S
4      ,
          \        S
4      ^\H        .4      \        ^S
,          ^ ^ RS
,          ..4      \        . RO^ S
^ ^ .. RO. RO.4      4       V! R	\        P
                  3\A        ^\5        S
4      ,          4      4       V! . S.\        \1        S4      S
^S,
          ^,          ,          ,          \/        S^,
          ^\5        S
4      ,          4      ,          \1        S4      S
^S^,          ,
          ,          ,          \/        S^\5        S
4      ,          4      ,          .4      \        ^^ ..4      \        ^ ^.S
^S,
          ..4      4       ^S
\        ^^4      ,          ,          o	V	3R lpV	3R lpV! . \        P
                  SS\        P
                  ,           .\        V! ^S,          ^,
          S
4      V! ^S,          S
4      S
\        ^^4      ,          ,          V! ^S,          ^,
          S
4      \5        S
4      ,          V! ^S,          S
4      S
\        ^^4      ,          ,          .4      ^RS,          ,          ,          \1        ^S,          4      ,          S
^^S,          ,
          ^,          ,          ,          \        . RO.4      \        . RO^ \        P
                  S,
          ^^ .^ ^ \        P
                  ^.S
^ ^ ^S,
          ..4      4       ^^S
,          \        ^^4      ,          ,          \K        \6        \(        ,          ^,          4      ,          o	V! . SS\        P
                  ,           ^S,          .^\5        \3        R4      S
,          4      ,          ^^S,          ,
          ,          \1        ^S,          4      ^,          ,          \        \M        ^S,          ^,
          S	4      \/        ^S,          ^,
          S	4      ,          S	\/        ^S,          S	4      \M        ^S,          ^,
          S	4      ,          \/        ^S,          ^,
          S	4      \M        ^S,          S	4      ,          ,
          ,          S	^,          \/        ^S,          S	4      ,          \M        ^S,          S	4      ,          S	^,          \/        ^S,          S	4      \M        ^S,          ^,
          S	4      ,          \/        ^S,          ^,
          S	4      \M        ^S,          S	4      ,          ,           ,          .4      ,          \        . RO.4      \        ^ \        ^^4      ^ ^ .^ ^^S,          ,
          ^,          \        R^4      ^ .^ ^ ^^S,          ,
          \        ^^4      .RS
,          ^ ^ ^S,
          ..4      4       V! S.S\        P
                  ,
          ^S,          .\        S
\        P
                  S,
          ,          \/        S\        P
                  ,
          \5        S
4      4      ^,          ,          S
^S,
          ,          \/        S\        P
                  ,
          \5        S
4      4      ,          \/        S\        ^^4      ,
          \5        S
4      4      ,          S
\        ^^4      S,
          ,          \/        S\        ^^4      ,
          \5        S
4      4      ^,          ,          .4      \        \1        S\        P
                  ,           4      ^,          ) ^\        P
                  S,
          ,          ,          ^\1        S\        P
                  ,
          4      ,          \1        S\        P
                  ,           4      ,          ^^S,
          ,          ,          ^ ..4      \        ^^S,          ,
          ^^ .S
^,          \        P
                  S,
          \        P
                  .^ S
^ ..4      4       V! \        P
                  .S^S,
          .\(        ^S,
          ,          \O        \(        S,          4      ,          \        \/        ^S,
          \5        S
4      4      \/        S^,
          \5        S
4      4      ,          \5        S
4      \/        S) \5        S
4      4      \/        S^,
          \5        S
4      4      ,          \/        ^S,
          \5        S
4      4      \/        S\5        S
4      4      ,          ,           ,          \/        S) \5        S
4      4      \/        S\5        S
4      4      ,          .4      ,          \        . RO.4      \        S^,
          \        P
                  ^ .S
^ S
.^ \        P
                  S) ..4      4       V! \        P
                  .\        ^^4      \        ^^4      .\        \Q        ^\5        S
4      ,          4      ^,          \5        S
4      ,          \;        ^\5        S
4      ,          4      ^,          \5        S
4      ,          \A        ^\5        S
4      ,          4      .4      \        . RO.4      \        \        R^4      \        P
                  ^ .^ \        R^4      \        P
                  .^ ^S
,          ^ ..4      4       V! \        ^^4      .\        ^^4      \        ^^4      .\        \=        \        \(        \6        ,          ^,          4      \?        S
^4      ,          ^,          \5        \(        4      ,          4      \(        \        \(        \6        ,          ^,          4      \?        S
^4      ,          ^,          \5        \(        4      ,          ^,          ,          ,          \;        ^\5        S
4      ,          4      \5        S
4      ,          \A        ^\5        S
4      ,          4      .4      \        . RO.4      \        \        R^4      \        ^^4      ^ .^ \        R^4      ^.^ S
^ ..4      4       V! \        ^^4      .\        P
                  \        ^^4      .\        \5        \(        4      \        \6        ) \(        ,          ^,          4      ,          \C        ^\?        S
^4      ,          \        \6        \(        ,          ^,          4      ,          \5        \(        4      ,          4      ,          ^\?        S
^4      ,          ,          \A        ^\5        S
4      ,          4      \;        ^\5        S
4      ,          4      \5        S
4      ,          .4      \        . RO.4      \        \        R^4      \        ^^4      ^ .. RO^ S
\        P
                  ..4      4       V! SS\        P
                  ,           .^S,          S^S,          S,
          ^,           .\1        S4      \1        ^S,          S,
          ^,           4      ,          \5        S
4      ^,          ^^S,          ,
          ,          ,          \        \/        S^,
          \5        S
4      4      \/        ^S,          S,
          \5        S
4      4      ,          \5        S
4      \/        S\5        S
4      4      ,          \/        ^S,          S,
          \5        S
4      4      ,          \5        S
4      \/        S^,
          \5        S
4      4      ,          \/        ^S,          S,
          ^,           \5        S
4      4      ,          \/        S\5        S
4      4      \/        ^S,          S,
          ^,           \5        S
4      4      ,          .4      ,          \        . RO.4      \        ^ \        P
                  \        P
                  ^ .S
^,          ^S,
          ^ S
^,          .S
^,          ^ S^S,          ,
          S
^,          .^ \        P
                  \        P
                  RS,          ..4      4       V! ^^.^^\        ^^4      .\        \S        ^\5        S
4      ,          4      \G        ^\5        S
4      ,          4      ,
          \A        ^\5        S
4      ,          4      \5        S
4      \;        ^\5        S
4      ,          4      ,          ^\H        .4      \        ^S
,          ^ ^ ^ RS
,          ..4      \        ^ \        P
                  ^ \        R^4      ^ .. RO^ S
\        P
                  ^ ^ .. RO. RO.4      4       V! ^^S.^^S^,           .\        S\G        S
) 4      \U        ^S
) 4      ,           \H        ,           ,          S
S^,          ^S,          ,
          ^,           ,          ,          SS
) S) ,          ,          \1        S4      \W        SS
) 4      ,
          ,          S^,
          ^,          ,          S\        S
4      ,          S^,          ^S,          ,
          ^,           ,          SS
S^,          ^S,          ,
          ^,           ,          ,          .4      \        ^S,
          ^RS
,          ^..4      \        R^ RS
,          ^.^ S) ^^ .^ ^ S
^ .. RO.4      4       R# )zCreate our knowledge base. za b c, z)clsc           
      ^   < \        W4      pSP                  \        VSVSSS34      4       R # NHyper_FunctionappendFormula)	apbqresfuncabrZ   formulaezs	   &&& r[   addadd_formulae.<locals>.addh   s*    b%aq!Qi89r]   c                 b   < \        W4      pS	P                  \        VS
R SSS3W#V4      4       R # ra   rb   )rf   rg   BCMri   rj   rk   rZ   rl   rm   s   &&&&& r[   addbadd_formulae.<locals>.addbl   s.    b%a1ay!BCr]   z3/2c                 >   < \        V S4      \        V S4      ,           # ra   r!   r'   rj   rm   rY   s   &&r[   fpadd_formulae.<locals>.fp       q!}wq!},,r]   c                 >   < \        V S4      \        V S4      ,
          # ra   rw   rx   s   &&r[   fmadd_formulae.<locals>.fm   r{   r]   N )rV   rV   )   )    r   r   )rV   r   r   )rV   r   r   )r   rV   r   r   )r   r   r   r   )rV   r   r   r   )r   rV   r   r   i)   r   r   )r   r   rV   )r   r   rV   r   r   )r   r   r   r   r   )r   r   r   r   ),r	   r   r   r@   r   HalfrK   rA   rB   r?   r   rC   rE   rF   rH   rI   rD   Oner:   r;   r   rG   r   r!   r"   r1   r   r   r%   r,   r/   r   r-   r0   r(   r   r   r2   r'   r&   r+   r.   r$   r#   )rl   rn   rt   mzry   r}   rj   rk   rZ   rY   rm   s   f     @@@@@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                 $  a aa	a
aa \        \        \        R 4      4      w  oo	o
o\        R4      oVV	V
V VV3R lpVV3R lpV! SS,           .. SSS,           .. \        \	        ^S,
          4      SS,          ,          \        S4      ,          \        SS4      ,          \	        ^S,
          4      SSS,           ,          ,          .4      \        ^^ ..4      \        SS,           R.^ SS,           ..4      V4       V3R lp\        ^\        S4      ,          4      p\        ^\        S4      ,          4      p\        ^\        S4      ,          4      \        ^,          ,
          p\        ^\        S4      ,          4      pV! S.. SSS\        P                  ,
          .. \        \        \        4      SS\        P                  ,
          ,          ,          WV,          WG,          ,
          ,          \        \        4      SS,          ,          WF,          WW,          ,           ,          \        \        4      SS,          ,          .4      \        . RO.4      \        S\        P                  ,
          R^ .SS\        P                  .^ ^ S..4      V4       R# )abczrhoc                 N   < SP                  \        WW#SSS	S
S.WEWg4
      4       R # ra   )rd   MeijerFormula)anrf   bmrg   rq   rr   rs   matcherrj   rk   rZ   rl   r   rm   s   &&&&&&&&r[   rn   !add_meijerg_formulae.<locals>.add  s+    bba!Q3&'A8 	9r]   c                 V  < V P                   ^ ,          pV P                  w  r#Rp\        W,
          P                  4       4      '       g   RpY2r2\        W,
          P                  4       4      '       g   W,
          ^ 8  d   R# W!.pV'       d   W.pSVSW,
          /\	        V.. V. 4      3# )r   FTN)r   r   r\   simplify
G_Function)ri   rY   yrm   swappedlrj   r   s   &     r[   detect_uppergamma/add_meijerg_formulae.<locals>.detect_uppergamma  s    GGAJwwae%%'((G!%!!#$$	FAQ15!:qc2q"#===r]   c           
       < V P                   ^ ,          pV P                  w  r#p\        W#,
          P                  4       4      ^ 8X  d[   \        W4,
          P                  4       4      ^ 8X  d   R# \        P
                  \        P
                  \        P                  3pY#TrpM\        W,
          P                  4       4      ^ 8X  d5   \        P
                  \        P                  \        P
                  3pY#TrxpM3\        P                  \        P
                  \        P
                  3pY#Trvp\        W,
          P                  4       4      ^ 8w  gq   \        W,
          P                  4       4      ^ 8w  gM   \        W,
          P                  4       4      \        P
                  8w  g   W,
          ^ 8  g   W,
          ^ 8  d   R# S
V/\        V.. V U	u. uF   q\        P
                  ,
          V	,           NK"  	  up	. 4      3# u up	i )z.https://functions.wolfram.com/07.34.03.0984.01N)r   r   r\   r   r   r   Zeror   )ri   rY   uvwsigx1x2r   trj   s   &         r[   detect_3113)add_meijerg_formulae.<locals>.detect_3113  si   GGAJ''a!%!!#$)ae%%'(A-66166166*CaABAae%%'(A-vvqvvqvv.!rrvvqvvqvv.!r16##%&!+16##%&!+15""$%/
afqj1vz1#rC+HCqJNNC+H"MMM+Hs   &HNr   )r   r   r   )listmapr   rK   r"   r   r#   r&   r   r    r*   r   r)   r   r   )rl   rn   r   r   sc_S_rr   rj   rk   rZ   r   rm   s   f       @@@@@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("%!#+6RAqtbd{+RA 	  	
|QVVR#aAFF^aAY?@r]   c                   a  V 3R lpV# )z?Create a function that simplifies rational functions in ``z``. c                   < V P                  4       w  rVP                  4       p\        VS4      P                  \        VS4      4      w  r1pW1P	                  4       ,          VP	                  4       ,          # )z5Efficiently simplify the rational function ``expr``. )as_numer_denomr   rO   cancelas_expr)exprnumerdenomrZ   rm   s   &   r[   simpmake_simp.<locals>.simp  sX    **,ua.//UA?%==?"U]]_44r]   r   )rm   r   s   f r[   	make_simpr     s    5 Kr]   c                  b    \         '       d#   V  F  p\        VR R7       K  	  \        4        R# R# ) )endN)r   print)argsrj   s   * r[   debugr     s%    {A!  r]   c                      a a ] tR tRt oRtV 3R lt]R 4       t]R 4       t]R 4       t	V 3R lt
R tR	 tR
 tR tRtVtV ;t# )rc   i  z'A generalized hypergeometric function. c                   < \         SV `  V 4      p\        \        \	        \
        V4      4      !  Vn        \        \        \	        \
        V4      4      !  Vn        V# ra   )super__new__r   r   r   r   rf   rg   )r_   rf   rg   obj	__class__s   &&& r[   r   Hyper_Function.__new__  sD    goc"S_-.S_-.
r]   c                2    V P                   V P                  3# ra   )rf   rg   selfs   &r[   r   Hyper_Function.args  s    !!r]   c                V    \        V P                  4      \        V P                  4      3# ra   )lenrf   rg   r   s   &r[   sizesHyper_Function.sizes  s    DGGc$''l++r]   c                :    \        R V P                   4       4      # )z\
Number of upper parameters that are negative integers

This is a transformation invariant.
c              3   t   "   T F.  p\        VP                  ;'       d    VP                  4      x  K0  	  R # 5ira   )bool
is_integeris_negative.0rY   s   & r[   	<genexpr>'Hyper_Function.gamma.<locals>.<genexpr>  s(     IA46677s   88)sumrf   r   s   &r[   r"   Hyper_Function.gamma  s     IIIIr]   c                Z   < \         SV `  4       V P                  V P                  3,           # ra   )r   _hashable_contentrf   rg   r   r   s   &r[   r    Hyper_Function._hashable_content  s*    w(*dgg.  	r]   c                D    \        V P                  V P                  V4      # ra   )r>   rf   rg   )r   args   &&r[   __call__Hyper_Function.__call__  s    TWWdggs++r]   c                    \        V P                  \        4      \        V P                  \        4      r!R pV P                  V! V4      V! V4      3# )af  
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           
      F   \        V P                  4       4      p \        ;QJ d    R  V  4       F  '       g   K   RM	  RM! R  V  4       4      '       g   V P                  R R7       \	        V  UUu. uF  w  rV'       g   K  V\        V4      3NK  	  upp4      p V # u uppi )c              3   P   "   T F  p\        V^ ,          \        4      x  K  	  R# 5i)r   N)
isinstancer   r   s   & r[   r   >Hyper_Function.build_invariants.<locals>.tr.<locals>.<genexpr>$  s     =fz!A$,,fs   $&TFc                 &    \        V ^ ,          4      # r   r   rY   s   &r[   <lambda>=Hyper_Function.build_invariants.<locals>.tr.<locals>.<lambda>%  s    *:1Q4*@r]   key)r   itemsanysorttupler   )bucketmodvaluess   &  r[   tr+Hyper_Function.build_invariants.<locals>.tr"  s~    &,,.)F3=f=333=f=== @A& &;3 /S#f+.&  FMs   1B
B
)rS   rf   r\   rg   r"   )r   abucketsbbucketsr   s   &   r[   build_invariantsHyper_Function.build_invariants  sB    F "$''5143G(	 

BxL"X,77r]   c                   V P                   VP                   8w  d   R# V P                  V P                  VP                  VP                  3 Uu. uF  p\        V\        4      NK  	  upw  r4rV^ pWS3Wd33 F  w  r\        \        VP                  4       4      \        V	P                  4       4      ,           4       F  p
W9  g,   W9  g&   \        W,          4      \        W,          4      8w  d   Ru u # \        W,          4      p\        W,          4      pVP                  4        VP                  4        \        W4       F  w  rV\        W,
          4      ,          pK  	  K  	  K  	  V# u upi )zWEstimate how many steps it takes to reach ``func`` from self.
Return -1 if impossible. r   )r"   rf   rg   rS   r\   setr   keysr   r   zipabs)r   ri   params	oabuckets	obbucketsr   r   diffr   obucketr   l1l2ijs   &&             r[   
difficultyHyper_Function.difficulty,  s$    ::#I77DGGTWWdgg>4@> 594G>4@0	h !) 57LMOF4.glln1EEF%3+=v{+s7</@@I&+&','		KDACJ&D ( G  N !4@s   E,c                l   V P                    FJ  pV P                   F7  pW,
          P                  '       g   K  W,
          P                  RJ g   K5    R# 	  KL  	  V P                    F  pV^ 8X  g   K   R# 	  V P                   F,  pVP                  '       g   K  VP                  '       g   K+   R# 	  R# )aA  
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.

FT)rf   rg   r   r   is_nonpositive)r   rj   rk   s   &  r[   _is_suitable_origin"Hyper_Function._is_suitable_originC  s      AWWE%%%15*=*=*F    AAv  A||| 0 0 0  r]   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr   r   r"   r   r   r   r  r
  __static_attributes____classdictcell____classcell__r   __classdict__s   @@r[   rc   rc     sj     2 " " , , J J,-8^. r]   rc   c                   n   a a ] tR tRt oRtV 3R lt]R 4       tV 3R ltR t	R t
]R 4       tR	tVtV ;t# )
r   i`  zA Meijer G-function. c                N  < \         SV `  V 4      p\        \        \	        \
        V4      4      !  Vn        \        \        \	        \
        V4      4      !  Vn        \        \        \	        \
        V4      4      !  Vn        \        \        \	        \
        V4      4      !  Vn	        V# ra   )
r   r   r   r   r   r   r   rf   r   rg   )r_   r   rf   r   rg   r   r   s   &&&&& r[   r   G_Function.__new__c  sr    goc"S_-.S_-.S_-.S_-.
r]   c                ^    V P                   V P                  V P                  V P                  3# ra   )r   rf   r   rg   r   s   &r[   r   G_Function.argsk  s!    $''47733r]   c                B   < \         SV `  4       V P                  ,           # ra   )r   r   r   r   s   &r[   r   G_Function._hashable_contento  s    w(*TYY66r]   c                p    \        V P                  V P                  V P                  V P                  V4      # ra   )rJ   r   rf   r   rg   )r   rm   s   &&r[   r   G_Function.__call__r  s%    tww$''1==r]   c                2  a \        ^4       Uu. uF  p\        \        4      NK  	  up;pw  r4rV\        W P                  V P
                  V P                  V P                  34       F/  w  rxV F$  p	V\        V	4      ,          P                  V	4       K&  	  K1  	  \        VR4       FB  w  rzVP                  4        F)  w  rV^ ,          oVP                  V3R lV
R7       WV&   K+  	  KD  	  \        V Uu. uF  p\        V4      NK  	  up4      # u upi u upi )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]})

c                    < V S,
          # ra   r   )rY   x0s   &r[   r   ,G_Function.compute_buckets.<locals>.<lambda>  s	    Rr]   )r   reverse)TFFT)ranger   r   r   r   rf   r   rg   r\   rd   r   r   r   dict)r   r  dictspanpappbmpbqdiclisrY   flipmr   r   r"  s   &             @r[   compute_bucketsG_Function.compute_bucketsu  s    0 BGq%JAk$&7%JJ"#EGGTWWdggtww#GHHCE!H$$Q'  I U$>?ICIIK1X

/
>A ( @ u-u!d1gu-.. &K .s   D4Dc                    \        V P                  4      \        V P                  4      \        V P                  4      \        V P                  4      3# ra   )r   r   rf   r   rg   r   s   &r[   	signatureG_Function.signature  s1    DGGc$''lCL#dgg,GGr]   r   )r  r  r  r  r  r   r  r   r   r   r0  r3  r  r  r  r  s   @@r[   r   r   `  sM       4 47>#/J H H Hr]   r   rY   c                   J   a  ] tR tRt o RtR tR	R lt]R 4       tR t	Rt
V tR# )
re   i  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                   V P                   P                   Uu. uF  p\        V,           NK  	  ppV P                   P                   Uu. uF  p\        V,           ^,
          NK  	  pp\        \	        V!  ,          V P
                  \	        V!  ,          ,
          p\        V\        4      pVP                  ! 4       ^,
          pV.p\        V4       FE  p	VP                  V P
                  VR,          P                  V P
                  4      ,          4       KG  	  \        V4      V n        \        ^.^ .V,          ,           .4      V n        \        V4      p
V
P                  ^ \!        V^4      4      p
VP"                  ! 4       R,          pVP%                  4        V
P'                  V\        V.4      ) VP"                  ! 4       ^ ,          ,          4      V n        R# u upi u upi )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.
rV   NNNr   )ri   rf   _xrg   r   rm   rP   degreer%  rd   r   rK   rq   rr   rL   
col_insertrM   
all_coeffsr$  
row_insertrs   )r   closed_formrj   afactorsrk   bfactorsr   rO   n_r/  r   s   &&          r[   _compute_basisFormula._compute_basis  sU    %)IILL1LqBFFL1(,		51BFQJJ5#x. 466#x.#88D"~KKMAMqAHHTVVAbEJJtvv../  !s1u&FLLE!QK(OOb!			a&!+doo.?.B!BC# 25s   G	G Nc                   \        V4      p\        V4      p\        V4       Uu. uF  qP                  V4      '       g   K  VNK  	  ppW n        W@n        WPn        W`n        Wpn        Wn        Ve   V P                  V4       R # R # u upi ra   )	r
   hasrm   r	   rq   rr   rs   ri   rB  )	r   ri   rm   rh   r	   rq   rr   rs   rY   s	   &&&&&&&& r[   __init__Formula.__init__  sv    AJcl%g.>.((1+11.>	
 ?$  ?s   BBc                v    \        R  \        V P                  V P                  4      \        P
                  4      # )c                 <    W^ ,          V^,          ,          ,           # r   r   r   r/  s   &&r[   r   %Formula.closed_form.<locals>.<lambda>      !aD1I+r]   r   r   rr   rq   r   r   r   s   &r[   r=  Formula.closed_form  %    -s466466/BAFFKKr]   c                J	  a a! ^ RI Hp VP                  pVP                  p\	        V4      \	        S P
                  P                  4      8w  g.   \	        V4      \	        S P
                  P                  4      8w  d   \        R4      h. pS P                   F  pVS P
                  P                  P                  9   d   VP                  V4       K;  VS P
                  P                  P                  9   d   VP                  V4       Ks  \        RV: 24      h	  \        V!   Uu. uF+  p\        \        \        S P                  V4      4      4      NK-  	  ppW43 U	u. uF  p	\        V	\         4      NK  	  up	w  rW3 UUUu. uF1  pVP#                  4        UUu/ uF  w  rmV\	        V4      bK  	  uppNK3  	  upppw  rS P                   Uu. uF  p^ .NK  	  pp. p\%        4       pV EF  o!S P
                  P                  S P
                  P                  3 U	u. uF  p	\        V	V!3R l4      NK  	  up	w  ppV
V3VV33 EF  w  pp\'        \        VP)                  4       4      \        VP)                  4       4      ,           4       EF4  pVV9  g/   VV9  g(   \	        VV,          4      \	        VV,          4      8w  d    K  \        S P                  V4       F  w  rmS!V,          P*                  '       d   K   VV,           Uu. uF  pVP-                  V4      '       g   K  VNK   	  ppS!P/                  4       pVV;;,          V,          uu&   V Fb  pVV,           FR  pV! VP1                  V4      V,
          V4      w  pVP*                  '       d   \        R4      hVP                  V4       KT  	  Kd  	  K  	  EK7  	  EK  	  . p\        S P                  V4       Fo  w  rmS!V,          p\3        \5        V4      4      p\7        \9        V4      4      pTP                  \;        VV^,           4       U u. uF  p VV ,           NK  	  up 4       Kq  	  VP=                  V 3R l\        V!   4       4       EK  	  V# u upi u up	i u uppi u upppi u upi u up	i u upi u up i )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!

)solvez-Cannot instantiate other number of parametersz?At least one of the parameters of the formula must be equal to c                 8   < \        V P                  S4      4      # ra   )r\   xreplace)rY   repls   &r[   r   -Formula.find_instantiations.<locals>.<lambda>	  s    U1::d;K5Lr]   zValue should not be truec           	   3   t   <"   T F-  p\        \        \        SP                  V4      4      4      x  K/  	  R # 5ira   )r&  r   r   r	   )r   r   r   s   & r[   r   .Formula.find_instantiations.<locals>.<genexpr>#  s+     YHX1d4DLL!(<#=>>HXs   58)sympy.solversrQ  rf   rg   r   ri   	TypeErrorr	   r   rd   
ValueErrorr   r&  r   r   rS   r\   r   r   r   r   free_symbolsrE  copyrS  r3   minr4   maxr%  extend)"r   ri   rQ  rf   rg   symbol_valuesrj   r   	base_replr   r   r   r   valsa_invb_invrA  critical_valuesresult_nsymb_asymb_br  r   r   exprsrepl0targetn0a0min_max_r@  rT  s"   f&                               @r[   find_instantiationsFormula.find_instantiations  s    	(WWWWr7c$)),,''3r7c$)),,6G+GKLLADIILL%%%$$R(diill'''$$R( 9:"= > >  &}575F $s4<<89:5 	 7ACIfd651I'242F 6<\\^D^'!CI^D24(,51A35WD#yy||TYY\\:<:F #6+LM:<NFF%-v$668J#KtFKKM2T',,.5IIJC6)s'/A"6#;/3ws|3DD#&t||_#E7///$29#, N,$$((1+, N $		aB$)D*0++&+DMM%,@6,I2&N#%???*45O*P$P $B	 +6 %* $F	 K $L$ "4<<AGAaB T+D"3t9-DMM5tax3H"I3Ha2663H"IJ	  B
 YQWHXYY7 8 I7ID 45< !O #JsB   #1Q:Q? R
R/R
RRR#R4R R
)rq   rr   rs   ri   r	   rm   )NNN)r  r  r  r  r  rB  rF  r  r=  rq  r  r  r  s   @r[   re   re     s5     .D4%$ L L: :r]   re   c                   0   a  ] tR tRt o RtR tR tRtV tR# )FormulaCollectioni)  z,A collection of formulae to use as origins. c                   / V n         / V n        . V n        \        V P                  4       V P                   F  pVP                  P
                  p\        VP                  4      ^ 8  d.   V P                   P                  V. 4      P                  V4       K`  VP                  P                  4       pWP                  P                  V/ 4      V&   K  	  R# )z6Doing this globally at module init time is a pain ... N)symbolic_formulaeconcrete_formulaerl   r   ri   r   r   r	   
setdefaultrd   r   )r   fr   invs   &   r[   rF  FormulaCollection.__init__,  s    !#!#T]]#
 AFFLLE199~!&&11%<CCAFff--/DE&&11%<SA r]   c                   VP                  4       pVP                  pW0P                  9   d2   W P                  V,          9   d   V P                  V,          V,          # W0P                  9  d   R# . pV P                  V,           F}  pVP	                  V4      pV Fc  pVP
                  P                  V4      pVP                  4       '       g   K6  VP                  V4      p	V	R8X  d   KP  VP                  WWX34       Ke  	  K  	  VP                  R R7       V F  w  rrX\        WP                  R. VP                  P                  V4      VP                  P                  V4      VP                   P                  V4      4      p\"        ;QJ d=    R VP                  VP                   VP                  3 4       F  '       g   K   RM2	  RM.! R VP                  VP                   VP                  3 4       4      '       d   K  Vu # 	  R# )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)
Nc                     V ^ ,          # r   r   r   s   &r[   r   1FormulaCollection.lookup_origin.<locals>.<lambda>k  s    AaDr]   r   c              3   ~   "   T F3  qP                  \        P                  \        \        ) \        4      x  K5  	  R # 5ira   )rE  r   NaNr   r   )r   es   & r[   r   2FormulaCollection.lookup_origin.<locals>.<genexpr>o  s(     N;MauuQUUBS11;Ms   ;=TFr   )r   r   rx  rw  rq  ri   rS  r
  r  rd   r   re   rm   rq   subsrr   rs   r   )r   ri   r{  r   possiblerz  replsrT  func2r   rA  f2s   &&          r[   lookup_originFormulaCollection.lookup_origin?  s   * ##%

***--e44))%055 ...''..A))$/E-0022''-2:Q 67  / 	.)!)AQT2qssxx~CCHHTNACCHHTN4B3NBDD"$$;MN333NBDD"$$;MNNN		 "* r]   )rx  rl   rw  N	r  r  r  r  r  rF  r  r  r  rs  s   @r[   ru  ru  )  s     7F&3 3r]   ru  c                   @   a  ] tR tRt o RtR t]R 4       tR tRt	V t
R# )r   iu  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                    WW43 Uu. uF#  p\        \        \        \        V4      4      !  NK%  	  upw  rr4\	        WW44      V n        WPn        W`n        Wn        Wpn	        Wn
        Wn        R # u upi ra   )r   r   r   r   r   ri   rm   r	   _matcherrq   rr   rs   )r   r   rf   r   rg   rm   r	   rq   rr   rs   r   r   s   &&&&&&&&&&& r[   rF  MeijerFormula.__init__  sc    AC@PQ@P1%c&!n!56@PQrr.	 Rs   )A-c                v    \        R  \        V P                  V P                  4      \        P
                  4      # )c                 <    W^ ,          V^,          ,          ,           # r   r   rJ  s   &&r[   r   +MeijerFormula.closed_form.<locals>.<lambda>  rL  r]   rM  r   s   &r[   r=  MeijerFormula.closed_form  rO  r]   c                   VP                   V P                  P                   8w  d   R# V P                  V4      pVe   Vw  r4\        VP                  VP
                  VP                  VP                  V P                  . V P                  P                  V4      V P                  P                  V4      V P                  P                  V4      R4
      # R# )zg
Try to instantiate the current formula to (almost) match func.
This uses the _matcher passed on init.
N)r3  ri   r  r   r   rf   r   rg   rm   rq   r  rr   rs   )r   ri   rh   r  newfuncs   &&   r[   try_instantiateMeijerFormula.try_instantiate  s    
 >>TYY000mmD!?MD WZZWZZ!%!%T!2DFFKK4E!%T!2D: : r]   )rq   rr   rs   r  ri   r	   rm   N)r  r  r  r  r  rF  r  r=  r  r  r  rs  s   @r[   r   r   u  s/      L L: :r]   r   c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerFormulaCollectioni  z5
This class holds a collection of meijer g formulae.
c                    . p\        V4       \        \        4      V n        V F9  pV P                  VP                  P
                  ,          P                  V4       K;  	  \        V P                  4      V n        R # ra   )r   r   r   rl   ri   r3  rd   r&  )r   rl   formulas   &  r[   rF   MeijerFormulaCollection.__init__  sV    X&#D)GMM',,00188A  T]]+r]   c                    VP                   V P                  9  d   R# V P                  VP                   ,           F  pVP                  V4      pVf   K  Vu # 	  R# )z)Try to find a formula that matches func. N)r3  rl   r  )r   ri   r  rh   s   &&  r[   r  %MeijerFormulaCollection.lookup_origin  sI    >>.}}T^^44G))$/C
 5r]   )rl   Nr  rs  s   @r[   r  r    s     , r]   r  c                   *   a  ] tR tRt o RtR tRtV tR# )Operatori  aL  
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                N   V P                   P                  4       pVP                  4        V.pVR,           F!  pVP                  V! VR,          4      4       K#  	  V^ ,          V^ ,          ,          p\	        VR,          VR,          4       F  w  rWWeV,          ,          pK  	  V# )aX  
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
r7  r   )_polyr;  r$  rd   r   )r   r   opcoeffsdiffsrZ   rds   &&&     r[   applyOperator.apply  s     &&(ALLE"I' 1IeAhr
E"I.DA1HA /r]   r   N)r  r  r  r  r  r  r  r  rs  s   @r[   r  r    s     4 r]   r  c                   *   a  ] tR tRt o RtR tRtV tR# )MultOperatori  z Simply multiply by a "constant" c                0    \        V\        4      V n        R # ra   )rP   r8  r  )r   ps   &&r[   rF  MultOperator.__init__  s    !R[
r]   r  N)r  r  r  r  r  rF  r  r  rs  s   @r[   r  r    s     +! !r]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )ShiftAi  zIncrement an upper index. c                    \        V4      pV^ 8X  d   \        R4      h\        \        V,          ^,           \        4      V n        R# )r   z"Cannot increment zero upper index.Nr
   rZ  rP   r8  r  )r   ais   &&r[   rF  ShiftA.__init__  s4    R[7ABB"R%!)R(
r]   c                `    R ^V P                   P                  4       ^ ,          ,          ,          # )z<Increment upper %s.>r  r;  r   s   &r[   __str__ShiftA.__str__  s$    &!DJJ,A,A,CA,F*FGGr]   r  N	r  r  r  r  r  rF  r  r  r  rs  s   @r[   r  r    s     %)H Hr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )ShiftBi  zDecrement a lower index. c                    \        V4      pV^8X  d   \        R4      h\        \        V^,
          ,          ^,           \        4      V n        R# )rV   z"Cannot decrement unit lower index.Nr  r   bis   &&r[   rF  ShiftB.__init__  s8    R[7ABB"b1f+/2.
r]   c                n    R ^V P                   P                  4       ^ ,          ,          ^,           ,          # )z<Decrement lower %s.>r  r   s   &r[   r  ShiftB.__str__  s)    &!DJJ,A,A,CA,F*F*JKKr]   r  Nr  rs  s   @r[   r  r    s     $/L Lr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )UnShiftAi  zDecrement an upper index. c                P   \        \        \        WV.4      4      w  rpWn        W n        W0n        \        V4      p\        V4      pVP                  V4      ^,
          pV^ 8X  d   \        R4      h\        WE,          \        4      pV F%  pV\        \        V,           \        4      ,          pK'  	  \        R4      p\        WX,          V,
          V4      ;rV F(  pWV^,
          P                  V4      ,           ,          p	K*  	  V	P                  ^ 4      ) pV^ 8X  d   \        R4      h\        \        V	P                  4       RR V4      P                  4       P                  V\        V,          ^,           4      \        4      p	\        W,
          V,          \        4      V n        R# )Note: i counts from zero! z"Cannot decrement unit upper index.Az0Cannot decrement upper index: cancels with lowerNr   r   r   r
   _ap_bq_ipoprZ  rP   r8  r   as_polynthr;  r   r  r  )r   rf   rg   r  rm   r  r/  rj   r  r@  Drk   b0s   &&&&&        r[   rF  UnShiftA.__init__  sN   Wrqk23	"X"XVVAY]7ABBrNAb1fb!!A  #JRTBY""Aa!e__Q'''A  eeAhY7 2 3 3 allnSb)1-557<<Q2	JBO15"*b)
r]   c                \    R V P                   : RV P                  : RV P                  : R2# )z<Decrement upper index # of , .>r  r  r  r   s   &r[   r  UnShiftA.__str__/  "    ;?778<$((L 	Lr]   r  r  r  r  Nr  rs  s   @r[   r  r    s     %*BL Lr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )UnShiftBi4  zIncrement a lower index. c                   \        \        \        WV.4      4      w  rpWn        W n        W0n        \        V4      p\        V4      pVP                  V4      ^,           pV^ 8X  d   \        R4      h\        \        V^,
          ,          \        4      pV F,  pV\        \        V,           ^,
          \        4      ,          pK.  	  \        R4      p\        V^,
          V,          V,
          ^,           V4      p	\        WH4      p
V F!  pWVP                  V4      ,           ,          p
K#  	  V
P                  ^ 4      pV^ 8X  d   \        R4      h\        \        V
P                  4       RR V4      P                  4       P                  V\        V^,
          ,          ^,           4      \        4      p
\        Wj,
          V,          \        4      V n        R# )r  z Cannot increment -1 lower index.rq   z*Cannot increment index: cancels with upperNr   r  )r   rf   rg   r  rm   r  r/  rk   rq   r  r@  rj   r  s   &&&&&        r[   rF  UnShiftB.__init__7  sg   Wrqk23	"X"XVVAY]7?@@R!Vb!Ab1fqj"%%A  #J"q&!b1$a(JAaiil"#A  UU1X7IJJallnSb)1-557<<r26{Q !#% 15"*b)
r]   c                \    R V P                   : RV P                  : RV P                  : R2# )z<Increment lower index #r  r  r  r  r   s   &r[   r  UnShiftB.__str__Y  r  r]   r  Nr  rs  s   @r[   r  r  4  s     $ *DL Lr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerShiftAi^  zIncrement an upper b index. c                \    \        V4      p\        V\        ,
          \        4      V n        R # ra   r
   rP   r8  r  r  s   &&r[   rF  MeijerShiftA.__init__a  s    R["r'2&
r]   c                R    R V P                   P                  4       ^,          ,          # )z<Increment upper b=%s.>r  r   s   &r[   r  MeijerShiftA.__str__e  s    (DJJ,A,A,CA,FGGr]   r  Nr  rs  s   @r[   r  r  ^  s     ''H Hr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerShiftBii  zDecrement an upper a index. c                j    \        V4      p\        ^V,
          \        ,           \        4      V n        R# rV   Nr  r  s   &&r[   rF  MeijerShiftB.__init__l  s!    R[!b&2+r*
r]   c                `    R ^V P                   P                  4       ^,          ,
          ,          # )z<Decrement upper a=%s.>r  r   s   &r[   r  MeijerShiftB.__str__p  s$    (A

0E0E0G0J,JKKr]   r  Nr  rs  s   @r[   r  r  i  s     '+L Lr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerShiftCit  zIncrement a lower b index. c                ^    \        V4      p\        V) \        ,           \        4      V n        R # ra   r  r  s   &&r[   rF  MeijerShiftC.__init__w  s    R[2#(B'
r]   c                T    R V P                   P                  4       ^,          ) ,          # )z<Increment lower b=%s.>r  r   s   &r[   r  MeijerShiftC.__str__{  s"    (TZZ-B-B-DQ-G,GHHr]   r  Nr  rs  s   @r[   r  r  t  s     &(I Ir]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerShiftDi  zDecrement a lower a index. c                j    \        V4      p\        V^,
          \        ,
          \        4      V n        R# r  r  r  s   &&r[   rF  MeijerShiftD.__init__  s!    R["q&2+r*
r]   c                `    R V P                   P                  4       ^,          ^,           ,          # )z<Decrement lower a=%s.>r  r   s   &r[   r  MeijerShiftD.__str__  s$    (DJJ,A,A,CA,F,JKKr]   r  Nr  rs  s   @r[   r  r    s     &+L Lr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerUnShiftAi  zDecrement an upper b index. c           
     p  a \        \        \        WW4V.4      4      w  rr4pWn        W n        W0n        W@n        WPn        \        V4      p\        V4      p\        V4      p\        V4      pVP                  V4      ^,
          p\        ^\        4      \        R V 4       4      ,          \        R V 4       4      ,          p\        R4      p	\        Wy,
          V	4      o\        Wi4      \        V3R lV 4       4      ,          \        V3R lV 4       4      ,          p
V
P                  ^ 4      pV^ 8X  d   \        R4      h\        \        V
P                  4       RR V	4      P!                  4       P#                  W\        ,
          4      \        4      p
\        W,
          V,          \        4      V n        R# )	r  c              3   X   "   T F   p\        V\        ,
          \        4      x  K"  	  R # 5ira   rP   r8  r   rk   s   & r[   r   *MeijerUnShiftA.__init__.<locals>.<genexpr>  s     <AtAFB//   (*c              3   X   "   T F   p\        \        V,
          \        4      x  K"  	  R # 5ira   r  r  s   & r[   r   r     s"     Ca^`YZDaQSDTDT^`r  r  c              3   D   <"   T F  pS^,           V,
          x  K  	  R# 5ir  r   r   rj   r  s   & r[   r   r     s     62aq1uqyy2s    c              3   F   <"   T F  pS) V,           ^,
          x  K  	  R# 5ir  r   r  s   & r[   r   r     s     =WTVqrAvzzTVs   !z(Cannot decrement upper b index (cancels)Nr   )r   r   r
   _anr  _bmr  r  r  rP   r8  r   r   r  rZ  r;  r   r  r  )r   r   rf   r   rg   r  rm   r  r/  r  r@  r  r  s   &&&&&&&     @r[   rF  MeijerUnShiftA.__init__  sH    Wrrq.A!BC"X"X"X"XVVAY]BK$<<<<tCa^`Ca?aa#JOJ62666=WTV=W9WWUU1X7GHHallnSb)1-557<<QRH"M15"*b)
r]   c                    R V P                   : RV P                  : RV P                  : RV P                  : RV P                  : R2# )z<Decrement upper b index #r  r  r  r  r  r  r  r  r   s   &r[   r  MeijerUnShiftA.__str__  .    EIWW&*hh$((DHHN 	Nr]   r  r  r  r  r  r  Nr  rs  s   @r[   r  r    s     '*<N Nr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerUnShiftBi  zIncrement an upper a index. c           
        \        \        \        WW4V.4      4      w  rr4pWn        W n        W0n        W@n        WPn        \        V4      p\        V4      p\        V4      p\        V4      pVP                  V4      ^,           p\        V\        4      pV F,  p	V\        ^V	,
          \        ,           \        4      ,          pK.  	  V F,  p	V\        V	^,
          \        ,
          \        4      ,          pK.  	  \        R4      p
\        W,           ^,
          V
4      p\        ^V
4      pV F  pW) V,           ,          pK  	  V F  pWV,
          ,          pK  	  VP                  ^ 4      pV^ 8X  d   \        R4      h\        \        VP                  4       RR V
4      P                  4       P!                  V
^V,
          \        ,           4      \        4      p\        W,
          V,          \        4      V n        R# )r  rq   z(Cannot increment upper a index (cancels)Nr   r   r   r
   r  r  r  r  r  r  rP   r8  r   r  rZ  r;  r   r  r  r   r   rf   r   rg   r  rm   r  r/  rj   rq   r  r@  rk   r  s   &&&&&&&        r[   rF  MeijerUnShiftB.__init__  s    Wrrq.A!BC"X"X"X"XVVAY]BKAa!ebj"%%A Aa!ebj"%%A  #J!QAJA"q&MA Aa%LA  UU1X7GHHallnSb)1-557<<q2v{! 15"*b)
r]   c                    R V P                   : RV P                  : RV P                  : RV P                  : RV P                  : R2# )z<Increment upper a index #r  r  r  r
  r   s   &r[   r  MeijerUnShiftB.__str__  r  r]   r  Nr  rs  s   @r[   r  r    s     '%*NN Nr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerUnShiftCi  zDecrement a lower b index. c           
        \        \        \        WW4V.4      4      w  rr4pWn        W n        W0n        W@n        WPn        \        V4      p\        V4      p\        V4      p\        V4      pVP                  V4      ^,
          p\        ^\        4      pV F%  p	V\        V	\        ,
          \        4      ,          pK'  	  V F%  p	V\        \        V	,
          \        4      ,          pK'  	  \        R4      p
\        Wz,           V
4      p\        Wj4      pV F  pW^,           V,
          ,          pK  	  V F  pW) V,           ^,
          ,          pK  	  VP                  ^ 4      pV^ 8X  d   \        R4      h\        \        VP                  4       RR V
4      P                  4       P!                  V
\        V,
          4      \        4      p\        W,
          V,          \        4      V n        R# )r  rr   z(Cannot decrement lower b index (cancels)Nr   r  )r   r   rf   r   rg   r  rm   r  r/  rk   rr   r  r@  rj   r  s   &&&&&&&        r[   rF  MeijerUnShiftC.__init__  s    Wrrq.A!BC"X"X"X"XVVAY]BKAa"fb!!A Ab1fb!!A  #JOJAa%!)A A"q&1*A  UU1X7GHHallnSb)1-557<<QRH"M15"*b)
r]   c                    R V P                   : RV P                  : RV P                  : RV P                  : RV P                  : R2# )z<Decrement lower b index #r  r  r  r
  r   s   &r[   r  MeijerUnShiftC.__str__  r  r]   r  Nr  rs  s   @r[   r  r    s     &$*LN Nr]   r  c                   0   a  ] tR tRt o RtR tR tRtV tR# )MeijerUnShiftDi  zIncrement a lower a index. c           
        \        \        \        WW4V.4      4      w  rr4pWn        W n        W0n        W@n        WPn        \        V4      p\        V4      p\        V4      p\        V4      pVP                  V4      ^,           p\        V\        4      pV F,  p	V\        ^V	,
          \        ,           \        4      ,          pK.  	  V F,  p	V\        V	^,
          \        ,
          \        4      ,          pK.  	  \        R4      p
\        V^,
          V
,
          V
4      p\        ^V
4      pV F  pW) V,           ,          pK  	  V F  pWV,
          ,          pK  	  VP                  ^ 4      pV^ 8X  d   \        R4      h\        \        VP                  4       RR V
4      P                  4       P!                  W^,
          \        ,
          4      \        4      p\        W,
          V,          \        4      V n        R# )r  rq   z(Cannot increment lower a index (cancels)Nr   r  r  s   &&&&&&&        r[   rF  MeijerUnShiftD.__init__  s    Wrrq.A!BC"X"X"X"XVVAY]BKAa!ebj"%%A Aa!ebj"%%A  #Ja!QAJA"q&MA Aa%LA  UU1X7GHHallnSb)1-557<<Av{! 15"*b)
r]   c                    R V P                   : RV P                  : RV P                  : RV P                  : RV P                  : R2# )z<Increment lower a index #r  r  r  r
  r   s   &r[   r  MeijerUnShiftD.__str__>  r  r]   r  Nr  rs  s   @r[   r  r    s     &%*NN Nr]   r  c                   `   a  ] tR tRt o RtR t]R 4       t]R 4       t]R 4       t	R t
RtV tR	# )
ReduceOrderiC  z7Reduce Order by cancelling an upper and a lower index. c                   \        V4      p\        V4      pW,
          pVP                  '       d   V^ 8  d   R# VP                  '       d   VP                  '       d   R# \        P                  V 4      p\        P                  p\        V4       F+  pV\        V,           V,           W&,           ,          ,          pK-  	  \        V\        4      Vn        Wn        W$n        V# )z;For convenience if reduction is not possible, return None. N)r
   
is_Integerr   r	  r  r   r   r   r%  r8  rP   r  _a_b)r_   r  bjr@  r   r  ks   &&&    r[   r   ReduceOrder.__new__F  s    R[R[G|||q1u===R...$EEqA"r'A+''A  !R[
r]   c                   \        V4      p\        V4      pW,
          pVP                  '       g   VP                  '       g   R# \        P	                  V 4      p\
        P                  p\        V4       F$  pWc\        ,          V,           V,           ,          pK&  	  \        V\        4      Vn
        VR8X  d   Wn        W%n        V# \        ^V^,
          RR7      Vn        \        ^V^,
          RR7      Vn        V# )zACancel b + sign*s and a + sign*s
This is for meijer G functions. NF)evaluater   )r
   r   r%  r  r   r   r   r%  r8  rP   r  r&  r'  r   )r_   rk   rj   signr@  r   r  r)  s   &&&&    r[   _meijerReduceOrder._meijer\  s     AJAJE===$EEqAr'A+/"A  !R[
2:GG
  !QUU3DG!QUU3DGr]   c                &    V P                  WR4      # rV   r   r.  )r_   rk   rj   s   &&&r[   meijer_minusReduceOrder.meijer_minusv  s    {{1$$r]   c                D    V P                  ^V,
          ^V,
          ^4      # rU   r2  )r_   rj   rk   s   &&&r[   meijer_plusReduceOrder.meijer_plusz  s    {{1q5!a%++r]   c                @    R V P                   : RV P                  : R2# )z"<Reduce order by cancelling upper z with lower r  )r&  r'  r   s   &r[   r  ReduceOrder.__str__~  s    WWdgg 	r]   r   N)r  r  r  r  r  r   classmethodr.  r3  r6  r  r  r  rs  s   @r[   r#  r#  C  sS     B,  2 % % , , r]   r#  c                n   \        V 4      p \        V4      pV P                  VR7       VP                  VR7       . p. pV  Fn  pRp\        \        V4      4       F)  pV! WaV,          4      pVf   K  VP	                  V4        M	  Vf   VP                  V4       K]  VP                  V4       Kp  	  WAV3# )z>Order reduction algorithm used in Hypergeometric and Meijer G r   N)r   r   r%  r   r  rd   )	rf   rg   genr   nap	operatorsrj   r  r  s	   &&&&     r[   _reduce_orderr?    s    	bB	bBGGGGGG
CIs2wAQ1B~q		  
 :JJqMR   Ir]   c                    \        V P                  V P                  \        \        4      w  rp\        \        V!  \        V!  4      V3# )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?  rf   rg   r#  r   rc   r   )ri   r=  nbqr>  s   &   r[   reduce_orderrB    s<    . (+GWXCi%+uc{3Y>>r]   c                    \        V P                  V P                  \        P                  R 4      w  rp\        V P
                  V P                  \        P                  \        4      w  rEp\        WWB4      W6,           3# )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                     \        V ) 4      # ra   r   r   s   &r[   r   %reduce_order_meijer.<locals>.<lambda>  s    -=qb-Ar]   )
r?  r   rg   r#  r6  r   rf   r3  r   r   )ri   r   rA  ops1nbmr=  ops2s   &      r[   reduce_order_meijerrI    se    , #477DGG[5L5L#ACNCd"477DGG[5M5M#35NCd c)4;66r]   c                   a a V V3R lpV# )z>Create a derivative operator, to be passed to Operator.apply. c                    < SV P                  S4      ,          V S,          ,           pVP                  \        S4      4      pV# ra   )r   	applyfuncr   )rr   r  rs   rm   s   & r[   doit&make_derivative_operator.<locals>.doit  s4    affQiK!A#KK	!%r]   r   )rs   rm   rM  s   ff r[   make_derivative_operatorrO    s     Kr]   c                P    T p\        V4       F  pVP                  W24      pK  	  V# )z_
Apply the list of operators ``ops`` to object ``obj``, substituting
``op`` for the generator.
)reversedr  )r   opsr  rh   os   &&&  r[   apply_operatorsrT    s*    
 Cc]ggc Jr]   c           	       aa V P                   V P                  VP                   VP                  3 Uu. uF  p\        V\        4      NK  	  upw  rErg\	        \        VP                  4       4      4      \	        \        VP                  4       4      4      8w  gH   \	        \        VP                  4       4      4      \	        \        VP                  4       4      4      8w  d   \        V : RV: 24      h. pR oVV3R lp	VV3R lp
\        \        VP                  4       4      \        VP                  4       4      ,           \        R7       EF  pRpRpRpRpW9   d   WK,          pWk,          pW9   d   W[,          pW{,          p\	        V4      \	        V4      8w  g   \	        V4      \	        V4      8w  d   \        V : RV: 24      hWW3 Uu. uF  p\        V\        R7      NK  	  upw  rrR pV! Wk4      pV! W{4      p\	        V4      ^ 8X  d   W! . WVV4      ,          pM\	        V4      ^ 8X  d   W! V. VVV4      ,          pMVR	,          pVR	,          pV^ ,          V,
          ^ 8:  g   V^ ,          V,
          ^ 8:  d   \        R4      hVV,
          ^ 8  d$   W! WVVV4      ,          pW! WVVV4      ,          pM"W! WVVV4      ,          pW! WVVV4      ,          pWV&   WV&   EK  	  VP                  4        V# u upi u upi )
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                     . p\        \        V 4      4       F^  pW,          W,          ,
          ^ 8  d   Tp^pMTpRpW,          W,          8w  g   K;  WF! W4      .,          pW;;,          V,          uu&   K:  	  V# )r   r   )r%  r   )frotoincdecrR  r  shchs   &&&&    r[   	do_shiftsdevise_plan.<locals>.do_shifts"  sj    s3xAusv~!%36/3
|#" ! 
r]   c           	     .   <aaa S! WR VVVV3R l4      # )z'Shift us from (nal, nbk) to (al, nbk). c                 $    \        W,          4      # ra   )r  r  r  s   &&r[   r   2devise_plan.<locals>.do_shifts_a.<locals>.<lambda>4  s
    vad|r]   c                 <   < \        V S,           SS,           VS4      # ra   )r  )r  r  aotherbothernbkrm   s   &&r[   r   rb  5  s    hq6z3<A&Nr]   r   )nalrf  alrd  re  r]  rm   s   &f&ffr[   do_shifts_a devise_plan.<locals>.do_shifts_a2  s    ";NP 	Pr]   c                .   <a aa S! WVVV V3R lR 4      # )z'Shift us from (nal, nbk) to (nal, bk). c                 <   < \        SS,           V S,           VS4      # ra   )r  )r  r  rd  re  rg  rm   s   &&r[   r   2devise_plan.<locals>.do_shifts_b.<locals>.<lambda>:  s    hsV|QZA&Nr]   c                 $    \        W,          4      # ra   )r  ra  s   &&r[   r   rm  ;  s
    fQTlr]   r   )rg  rf  bkrd  re  r]  rm   s   f&&ffr[   do_shifts_b devise_plan.<locals>.do_shifts_b7  s    N24 	4r]   r   c                 Z    . pV  F"  pW18w  g   K  VP                  W,          4       K$  	  V# ra   )r_  )r,  r   r   r)  s   &&  r[   othersdevise_plan.<locals>.othersN  s+    A8HHSV$  Hr]   zNon-suitable parameters.r   r   )rf   rg   rS   r\   r   r   r   rZ  sortedr   r$  )rl  originrm   r   r   r   	nabuckets	nbbucketsrR  ri  rp  r  rh  rg  ro  rf  r   rs  rd  re  namaxamaxr]  s   &&f                   @r[   devise_planr{    s   ^ yy&))VYY		B0DBF 15VU0CB0D,H	 4 !Sinn.>)?%@@X]]_%&#d9>>3C.D*EEvvFGG
C P
4 D)D,AAGWXX=B,C=B,Cr7c#h#b'SX"566JKK r')' #1*:;')	 	%	%r7a<;r3FF;;CW\;sBFF;;CGEb6D1v~"bedla&7 !;<<t|a{3R@@{2B?? {3R@@{3B??!!c Yf KKMJq0Dd)s   K>Lc                   \        V P                  \        4      \        V P                  \        4      r2\	        V\
        P                  ,          4      ^8w  d   R# V\
        P                  ,          ^ ,          pV^ 8:  d   R# \
        P                  V9  d   R# \        V\
        P                  ,          4      pVP                  4        V^ ,          pV^ 8:  d   R# \        V P                  4      pVP                  V4       \        V P                  4      pVP                  V4       V^,          pV U	u. uF  qV,
          NK  	  pp	V U	u. uF  qV,
          NK  	  pp	. p
\        V^,
          4       F$  pV
P                  \        V^,           4      4       K&  	  V
P                  4        \        V4      W,          ,          pT\        V Uu. uF  p\!        W4      NK  	  up!  ,          pT\        V Uu. uF  p\!        W4      NK  	  up!  ,          pV
\#        V4      .,          p
^ p\        V4       Fv  pW,          \        V4      ,          pT\        V Uu. uF  p\!        W4      NK  	  up!  ,          pT\        V Uu. uF  p\!        W4      NK  	  up!  ,          pVV,          pKx  	  \%        Wx4      W) 3# u up	i u up	i u upi u upi u upi u upi )z>Try to recognise a hypergeometric sum that starts from k > 0. N)rS   rf   r\   rg   r   r   r   r   r   remover%  rd   r  r$  r6   r   r5   r  rc   )ri   rm   r   r   r  r   r)  r=  rA  rY   rR  r@  facrk   rj   r  r/  s   &&               r[   try_shifted_sumr  t  s2   dggu-tDGGU/Ch
8AFF!AAvvvXXaffAFFH	!AAv
tww-CJJqM
tww-CJJqMFA
#Qq55#C

#Qq55#C

C1q5\

6!a%=! KKM
A,qt
C33'3aA3'((C33'3aA3'((CLC	A1XD1	SS)S2a8S)**	SS)S2a8S)**	Q	  ##S",,+ 
 (' *)s$   4J<KK
5K
KKc           	       a \        V P                  \        4      \        V P                  \        4      r2V\        P
                  ,          pV\        P
                  ,          pVP                  4        VP                  4        V Uu. uF  qf^ 8:  g   K  VNK  	  ppV Uu. uF  qf^ 8:  g   K  VNK  	  upoS'       dG   \        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       d   \        # V'       g   R# VR,          p^p	\        P                  p
\        \        \        V) 4      4      !   F  pW,          p	W^,           ,          p	T	\        V P                   Uu. uF  qV,           NK  	  up!  ,          p	T	\        V P                   Uu. uF  qV,           NK  	  up!  ,          p	W,          p
K  	  V
# u upi u upi u upi u upi )zaRecognise polynomial cases. Returns None if not such a case.
Requires order to be fully reduced. c              3   :   <"   T F  qSR,          8  x  K  	  R# 5i)rV   Nr   r   )r   rj   bl0s   & r[   r   !try_polynomial.<locals>.<genexpr>  s     ,1s2w;s   FTNr   )rS   rf   r\   rg   r   r   r   allr   r   r   r   r%  r   )ri   rm   r   r   rn  r  rY   al0rj   r~  rh   r@  rk   r  s   &&           @r[   try_polynomialr    s^    dggu-tDGGU/Ch	!&&	B	!&&	BGGIGGI
#bF11bC
#
#bF11b
#C
ss,,sss,,,,	BA
C
%%CDrO$1usDGG,GqUUG,--sDGG,GqUUG,--
 % J# $
# -,s$   GG G-G3G#Gc           	     r   \        V P                  \        4      \        V P                  \        4      r!/ pVP	                  4        FG  w  rEV^ 8w  d
   WB9  d    R# W$,          p\        V4      \        V4      3W4&   VP                  VR4       KI  	  V/ 8w  d   R# \        P                  V9  d   R# V\        P                  ,          w  rxWx^.,           3V\        P                  &   \        R4      p	\        P                  p
\        P                  pVP	                  4        F  w  pw  r\        V4      \        V4      8w  d    R# \        W4       F  w  rW,
          P                  '       d6   W,
          pV
\        W,           V4      ,          p
V\        W4      ,          pKR  W,
          pV
\        W4      ,          p
V\        W,           V4      ,          pK  	  K  	  \        W,          V	4      p\         P"                  ! V4      p. p/ pV EF  pVP%                  4       w  rVP'                  V	4      '       gQ   \)        W4      pVP*                  '       g   \-        R4      hVP/                  4       w  w  rVW,          V3.,          pK}  V
P'                  V	4      '       d   \1        R4      hVP3                  V	4      w  pw  p^pVP4                  '       d   VP6                  pVP8                  pVV	8X  d   ^ pMVP:                  '       dq   VP=                  V	4      w  pp^pVV	8w  d   VP=                  V	4      w  ppVW,          V,           8w  d   \1        RV,          4      hW,          pVVV,          ,          pM\1        R4      hVP?                  V. 4      PA                  V
V,          V34       EK  	  / p/ p\        R4      pVPC                  R R	7       ^ ^^V,
          ,          /pV'       dJ   \E        VR,          ^,          4       F,  pVVV,          PG                  V4      ,          VV^,           &   K.  	  V FC  w  ppVP?                  \        P                  . 4      PA                  VVV,          ,          4       KE  	  VP	                  4        F  w  ppV F1  w  p pVP?                  \I        VW4      . 4      PA                  V 4       K3  	  VPC                  R
 R	7       \E        ^VR,          ^,          ^,           4       F5  pV) \I        VW4      3^\I        VV^,
          V4      3.V\I        VW4      &   K7  	  V) \I        V^V4      3^^V,
          ,          \        P                  3.V\I        V^V4      &   K  	  / p!\K        \        P                  .\        VPM                  4       4      ,           4       F  w  ppVV!V&   K  	  \O        V!P	                  4       R R	7       UUu. uF  w  pp\Q        V4      NK  	  p"pp\S        V"4      p#\S        ^ .\        V#4      ,          .4      p$VP	                  4        F  w  pp \!        V !  V$V!V,          &   K  	  \U        \        V#4      4      p%VP	                  4        F'  w  ppV F  w  p p&V V%V!V,          V!V&,          3&   K  	  K)  	  \W        V VR. V#V$V%4      # u uppi )z
Try to find an expression for Hyper_Function ``func`` in terms of Lerch
Transcendents.

Return None if no such expression can be found.
Nr   zp should be monomialz<Need partial fraction decomposition with linear denominatorszunrecognised form %sz%unrecognised form of partial fractionrm   c                     V ^,          # rU   r   r   s   &r[   r   try_lerchphi.<locals>.<lambda>   s    1r]   r   c                     V ^,          # rU   r   r   s   &r[   r   r  *  s    QqTr]   c                     V ^,          # rU   r   r   s   &r[   r   r  4  s    adr]   r   ),rS   rf   r\   rg   r   r   r  r   r   r   r   r   r   is_positiver5   rN   r   	make_argsr   rE  rP   is_monomialrY  LTNotImplementedErroras_coeff_mulis_Powr   baseis_Addas_independentry  rd   r   r%  r   r7   	enumerater   ru  r   rK   rM   re   )'ri   r   r   pairedr   valuebvalueaintsbintsr   r   r   avaluerj   rk   r)  partr   	monomialstermsr   r  indepdepr@  tmprA  derivr  rm   monr   rZ   transbasisrq   rr   rs   b2s'   &                                      r[   try_lerchphir    s    dggu-tDGGU/ChFnn&
!8+E{DL1S$ ' 2~vvX!&&>LEaS[)F166Nc
AEEEEEE!'fv;#f+% 'DA"""EAE1%A!EA!AE1% ( "0( a D==DIE))+yy||UA=== 677JUa17A,'I99Q<<% 'B C C))!,u:::A((C!8AZZZ''*FAsAax))!,1acAg~)*@3*FGGFAQTME%&MNNB&&eQ'78= L EFc
ANN~N&aQi.Cy}Q'(A3q6;;q>)CAJ )1!%%$++Ac!fH5 1DAqhq!/4;;A> 	>"q!B%(Q,'A*+Xa->(?)*HQAq,A(B(DE(1a#$ ( '(R!Q):$;%&AY$6$8hq!Q   E155'D$6671a 8*05B+D E +DA[^ +DE EuACF
|A11g%( c!fA1EAr%&AeAhb	!"   4D"aA..Es   $Z3c           	     
   \        R4      pV P                  '       Ed   V P                   Uu. uF  p\        V,           NK  	  ppV P                   Uu. uF  p\        V,           ^,
          NK  	  pp\        \	        V!  ,          V\	        V!  ,          ,
          p\        V\        4      pVP                  ! 4       p. p	\        V4      p
\        V4       F  pV P                  ^ ,          V,           pV	\        V.\        V P                  R,          4      ,           V P                  V4      .,          p	W^,
          8  g   Km  V) WV3&   W*W^,           3&   K  	  \        V	4      p\        ^.^ .V^,
          ,          ,           .4      p\        V4      .p\        V4       F!  pVP                  WV,          ,          4       K#  	  VP                  ! 4       pVP                  4        ^ .V,          p\!        V4       FD  w  pp\!        WV,          ,          4       F"  w  ppVV;;,          VV,          ,          uu&   K$  	  KF  	  \!        V4       FU  w  ppV) W^,
          ,          ^ V^,
          3,          ,          VP                  ! 4       ^ ,          ,          W^,
          V3&   KW  	  \#        WR. WV
4      # . p	\        V P                  R,          4      p\        \%        V4      4       F-  pV	\        . VV4      .,          p	VV;;,          ^,          uu&   K/  	  V	\        . VV4      .,          p	\        V	4      p\%        V4      p\        ^.^ .V^,
          ,          ,           .4      p\        V4      p
V\	        V P                  !  ,          V
^ V^,
          3&   \        ^V4       FG  pV P                  V^,
          ,          WV^,
          3&   V P                  V^,
          ,          ) WV3&   KI  	  \#        WR. WV
4      # u upi u upi )zM
Create a formula object representing the hypergeometric function ``func``.

rm   r7  N:NNN)r   rf   r8  rg   r   rP   r9  rM   r%  r>   r   rK   rL   rd   r;  r$  r  re   r   )ri   rm   rj   r>  rk   r?  r   rO   r@  r  rs   r)  rq   rr   derivsr   rh   rZ   r  r  rg   r  s   &                     r[   build_hypergeometric_formular  @  s5    	c
Awww$(GG,GqBFFG,(,01BFQJJ0#x. 1S(^#33D"~KKM!HqA
QAeQC$twwr{"33TWWa@AAEq5y"Q$!U(  5MQC1#q1u+%&'a&qAMM!1I+& OO			c!eaLDAq!!1I+.1A!A# / ! cNDAq"VE]1a!e844T__5Fq5IIA!eQhK #tb!22 $''!*s2wAeBA&''EqEQJE   	%B"##5MFQC1#q1u+%&'!HTWWo!QU(q!A''!a%.AQhKwwq1u~oAdG  tb!22Y -0s   O;P c                Z   \        V 4      \        V4      rCTp\        V4      pV^ 8X  d   \        P                  # ^ RIHp V^8X  Ed   V^8X  Ed   W,           w  rxp	V^8X  dU   \        W,
          V,
          4      \        V	4      ,          \        W,
          4      ,          \        W,
          4      ,          # VR8X  d   V! W,
          V	,           4      ^8X  d   YxrxVR8X  EdA   V! Wx,
          V	,           4      ^8X  Ed&   VP                  '       d   VP                  '       d   ^\        \        V,          ^,          4      ,          \        V) 4      ,          \        W,
          ^,           4      ,          \        V) ^,          4      ,          \        V^,          V,
          ^,           4      ,          # \        V^,          ^,           4      \        W,
          ^,           4      ,          \        V^,           4      ,          \        V^,          V,
          ^,           4      ,          # \        WV4      # )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   )r   r=   r   r   sympy.simplify.simplifyr   r"   r   r   r    r   r>   )
rf   rg   rm   r  qz_r   rj   rk   rZ   s
   &&&       r[   hyperexpand_specialr  z  s    r7CGq	
B1AAvuu0Av!q&'a6#E!H,U15\9%,FF7x	*a/q7x	*a/|||RT!V}UA2Y.uQUQY/??A2a4[!!&qsQw{!34 4 QqS1W~eAEAI&661q5\""'!a!"45 5 r]   Nz0defaultc                n  aaaaaa SP                   '       d   \        P                  # ^ RIHp \        SRR7      oSR8X  d   RoVVVVVV3R lp\        f   \        4       s\        RV 4       \        V 4      w  r	V	'       d   \        RV 4       M\        R	4       \        V S4      p
V
eU   \        R
4       \        WV3R l4      p\        VS,          SV3R l4      p\        V! V4      P                  SS4      4      # \        P                  p\        V S4      p
V
e   V
w  rp\        RV 4       W,          p	\        WV3R l4      p\        VS,          SV3R l4      pV! V4      P                  SS4      p\        S4      R9   d~   \!        V P"                  4      \!        V P$                  4      3R8X  dO   \'        V 4      pV! W4      P)                  \*        \,        4      pVP/                  \*        4      '       g	   W,           # \        P1                  V 4      pVf   \3        V 4      pVf   \        RR4       \'        V 4      p\        RVP4                  RVP6                  4       V	\9        WP6                  S4      ,          p	V! W4      V,           p\;        VRR7      P)                  \*        \,        4      # )a  
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  F)r  r  nonrepsmallc                   < \        V P                  P                  V P                  S
4      V\	        V P
                  P                  V P                  S
4      S
4      4      p\        VS\	        V P
                  P                  V P                  S
4      S\        V P
                  P                  ^ ,          4      ,          ,           S
4      4      pS^8X  d   VP                  \        S
4      4      p\        R \        W P                  P                  V P                  S
4      4      \        P                  4      S,          pVP                  S
S	4      pS'       d   VP                  S4      pV# )r   c                 <    W^ ,          V^,          ,          ,           # r   r   rJ  s   &&r[   r   5_hyperexpand.<locals>.carryout_plan.<locals>.<lambda>  s    q1ad{r]   )rT  rr   r  rm   rO  rs   rL   shaperL  r   r   r   rq   r   r   rewrite)rz  rR  rr   r  rh   ops0prempremultr  rm   r  s   &&   r[   carryout_plan#_hyperexpand.<locals>.carryout_plan  s   ACCHHQSS"-s4QSSXXacc25FKMAt4QSSXXacc25F+/ACCIIaL0A+A6BCEGH a<IbM*A*C3388ACC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                 4   < SV P                  S4      ,          # ra   r   rz  r  s   &r[   r   _hyperexpand.<locals>.<lambda>  s    166":r]   c                 4   < SV P                  S4      ,          # ra   r  r  s   &r[   r   r    s    r!&&*}r]   z+  Recognised shifted sum, reduced order to c                 4   < SV P                  S4      ,          # ra   r  r  s   &r[   r   r    s    "QVVBZ-r]   c                 4   < SV P                  S4      ,          # ra   r  r  s   &r[   r   r    s    2affRj=r]   z  Could not find an origin. z@Will return answer in terms of simpler hypergeometric functions.z  Found an origin:  Tpolarr1  )r   rV   )is_zeror   r   r  r   r<   _collectionru  r   rB  r  rT  r=   r  r   r  r   rf   rg   r  replacer>   r  rE  r  r  r=  ri   r{  rR   )ri   rm   r  r  r  r  r  r   r  rR  rh   r  nopsrz  r  r  s   &ffffff         r[   _hyperexpandr    sD    	yyyuu0A) * ')	
5t< T"ID
#T*)* r
"C
()C&=>AgIt-DE(1+**2q122 	
A
$
#C
A;TB 	 78A'	4)@AAQA !}S\3tww<$@F$J(.!!))%1DEuuU||5L ''-G t$,2	3 /t4	
!4!4c7<<H ;t\\2..C 	g#a'AQd#++E3FGGr]   c           	       aaaa	a
 R p\        V P                  4      o\        V P                  4      o\        V P                  4      o	\        V P                  4      o
. pRpV'       Ed   RpV! SVP                  VVV	V
V3R l^S	S
,           4      pVe   WF.,          pRpKA  V! SVP                  VVV	V
V3R l^S	S
,           4      pVe   WF.,          pRpKw  V! S	VP                  VVV	V
V3R lRSS,           4      pVe   WF.,          pRpK  V! S
VP                  VVV	V
V3R lRSS,           4      pVe   WF.,          pRpK  V! SVP                  V3R lR. 4      pVe   WF.,          pRpEK  V! SVP                  V3R	 lR. 4      pVe   WF.,          pRpEK;  V! S	VP                  V	3R
 l^. 4      pVe   WF.,          pRpEKg  V! S
VP                  V
3R l^. 4      pVf   EK  WF.,          pRpEK  S\        VP                  4      8w  gO   S\        VP                  4      8w  g5   S	\        VP                  4      8w  g   S
\        VP                  4      8w  d   \        R4      hVP                  4        V# )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                n  a \        \        W4      4       F  w  pw  opSV,
          P                  '       g   K$  VS,
          V,          ^ 8  g   K;  \        ;QJ d    V3R lV 4       F  '       d   K   RM	  RM! V3R lV 4       4      '       g   K}  V! V4      pW;;,          V,          uu&   Vu # 	  R# )a  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.
c              3   .   <"   T F
  pSV8g  x  K  	  R # 5ira   r   )r   rY   rj   s   & r[   r   8devise_plan_meijer.<locals>.try_shift.<locals>.<genexpr>R  s     01Qs   FTN)r  r   r   r  )	rz  r   shifterr   counteridxrk   r[  rj   s	   &&&&&   @r[   	try_shift%devise_plan_meijer.<locals>.try_shiftG  sy     %SY/KC!QQ"""At|a'7C00CCC0000S\$	 0r]   TFc                 $   < \        SSSSV S4      # ra   )r  r  fanfapfbmfbqrm   s   &r[   r   $devise_plan_meijer.<locals>.<lambda>_      S#sAq!Ir]   c                 $   < \        SSSSV S4      # ra   )r  r  s   &r[   r   r  f  r  r]   c                 $   < \        SSSSV S4      # ra   )r  r  s   &r[   r   r  m  r  r]   c                 $   < \        SSSSV S4      # ra   )r  r  s   &r[   r   r  t  r  r]   c                 (   < \        SV ,          4      # ra   )r  )r  r  s   &r[   r   r  z      \#a&-Ar]   c                 (   < \        SV ,          4      # ra   )r  )r  r  s   &r[   r   r    r  r]   c                 (   < \        SV ,          4      # ra   )r  )r  r  s   &r[   r   r    r  r]   c                 (   < \        SV ,          4      # ra   )r  )r  r  s   &r[   r   r    r  r]   zCould not devise plan.r   )r   r   rf   r   rg   r  r$  )rW  rX  rm   r  rR  changer  r  r  r  r  s   &&f    @@@@r[   devise_plan_meijerr    sC   t svv,C
svv,C
svv,C
svv,C
CF
&sBEEII#)% >4KCFsBEEII#)% >4KCFsBEEII39& >4KCFsBEEII39& >4KCFsBEE#A2rJ>4KCFsBEE#A2rJ>4KCFsBEE#A1bI>4KCFsBEE#A1bI>4KCF
d255kSDK/3$ruu+3E4;!":;;KKMJr]   c           
     
  aaa \         f   \        4       s VR8X  d   RpT p\        RV 4       \        R4      p\	        V 4      w  p oS'       d   \        RV 4       M\        R4       \         P                  V 4      pVe   \        RVP                  4       S\        VP                  W4      ,          o\        VP                  P                  VP                  V4      S\        VP                  P                  VP                  V4      V4      4      pVP                  \        V4      4      pWP                   P                  VP                  V4      ,          p	V	^ ,          P                  Wa4      p	\#        V	RR	7      # \        R
4       R oVVV3R lp
\        R4      oV
! V P$                  V P&                  V P(                  V P*                  Wa4      w  rR pS FE  p\-        VP.                  P                  V^S,          \0        \0        ) /4      \0        4      Vn        KG  	  V
! V! V P&                  4      V! V P$                  4      V! V P*                  4      V! V P(                  4      S^V,          4      w  pp\#        VP                  Wa4      RR	7      p\#        VP                  S^V,          4      RR	7      p\3        V\4        4      '       g   VP                  S^V,          4      pV ! V4      pVP6                  ^ 8  gt   VP6                  ^ 8X  ds   \9        VP(                  4      \9        VP*                  4      8X  dF   \;        VP<                  4      R8  RJd*   \?        V4      \?        ^4      8X  d   VRJd   RpVRJd   RpVRJ d   TPA                  T;'       g    R4      pMTPA                  T;'       g    R4      pVRJ d   TPA                  T;'       g    R4      pMTPA                  T;'       g    R4      pVRJd   VRJd   V^ 8X  d   RpV\B        8X  d   Rp\3        V\4        4      '       g   VP                  Wa4      p\3        V\4        4      '       g   VP                  Wa4      pR pV! W4      pV! VV4      p\E        VV4      ^ ^\F        38:  d   VV8  d   V# V# \I        V^ ,          V^ ,          4      ^8:  d8   \I        V^,          V^,          4      ^8:  d   \K        W3VV3V! V4      R34      # \K        W3VV3V! V4      R34      p	V	PM                  \N        4      '       d   V'       g   \        R4       V	PM                  \N        4      '       d	   V'       d   V	# V! V4      # )af  
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.
Nr  z1Try to expand Meijer G function corresponding to rm   r  r  z  Found a Meijer G formula: Tr  z;  Could not find a direct formula. Trying Slater's theorem.c                    V  FT  p\        W,          4      ^8  g   K  ^ pW!9   d   \        W,          4      pV^,           \        W,          4      8  g   KS   R# 	  R# )zTest if slater applies. FT)r   )r*  r)  r  r   s   &&  r[   can_do_meijergexpand.<locals>.can_do  sH    A36{Q8CFAq53sv;&   r]   c                 v  <a \        WW#4      pVP                  4       w  rxrS+! W4      '       g   \        P                  R 3# \	        V 4      \	        V4      ,           \	        V4      \	        V4      ,           8  p
\	        V 4      \	        V4      ,           \	        V4      \	        V4      ,           8X  d   \        S4      ^8  p
V
R J d   \        P                  R 3# \        P                  pV EF%  p\	        W,          4      ^8X  Ed   W,          ^ ,          p^p\        V4      pVP                  V4       V F  pV\        VV,
          4      ,          pK  	  V  F#  pV\        ^V,           V,
          4      ,          pK%  	  V F#  pV\        ^V,           V,
          4      ,          pK%  	  V F  pV\        VV,
          4      ,          pK  	  \        V 4      \        V4      ,            Uu. uF  p^V,           V,
          NK  	  pp\        V4      \        V4      ,            Uu. uF  p^V,           V,
          NK  	  pp\        \        P                  \	        V4      \	        V4      ,
          ,          4      pVV,          pS-V,          V,          p\        \        VV4      VS,S-VVRR7      pWV,          ,          pEK  W,          ^ ,          pW,          R,           Uu. uF  pVV,
          NK  	  pp\	        V4      pW,          RV^,             Uu. uF  pVV,
          NK  	  pp\        V4      pW,           F  pVP                  V4       K  	  \        V4      p W,          RV  F  pV P                  V4       K  	  VR,          p!\        VV4       U"Uu. uF  w  p"pV"V,
          NK  	  p#p"p\        R4      p$SV$,          p%V FT  p\        V^4      '       g'   VP                   '       d   \#        \%        V4      4      pV%\        VV$,
          4      ,          p%KV  	  V  F#  pV%\        ^V,
          V$,           4      ,          p%K%  	  V F#  pV%\        ^V,
          V$,           4      ,          p%K%  	  V F  pV%\        VV$,
          4      ,          p%K  	  \'        V%4      p%\)        \#        \%        V!4      4      4       F1  p&\+        V%V$VV&,           4      p'\-        V'S,V3R l4      p'VV',          pK3  	  VV!,           p(\        \        P                  \	        V 4      \	        V4      ,           ^,           ,          4      pVV,          pS-V,          V(,          p\        V 4      \        V4      ,            Uu. uF  p^V(,           V,
          NK  	  up^.,           p\        V4      \        V4      ,            Uu. uF  p^V(,           V,
          NK  	  pp\        \        VV4      VS,S-VV(RR7      p\        P                  V!,          \/        V!4      ,          p)\)        V4       FU  p*V)\        P                  V#V*,          ,          \1        V!VV*,          ,
          ^,           V#V*,          4      ,          ,          p)KW  	  V  F#  pV)\        ^V,
          V(,           4      ,          p)K%  	  V F  pV)\        VV(,
          4      ,          p)K  	  V  F  pV)\        VV(,
          4      ,          p)K  	  V F#  pV)\        ^V,
          V(,           4      ,          p)K%  	  VV)V,          ,          pEK(  	  W3# u upi u upi u upi u upi u upp"i u upi u upi )FNr  r7  r   c                 4   < SV P                  S4      ,          # ra   r  )rz  rm   s   &r[   r   3_meijergexpand.<locals>.do_slater.<locals>.<lambda>!	  s    !AFF1I+r]   r   )r   r0  r   r   r   r   r   r}  r"   r1   NegativeOner  rc   r   r   r   rW   introundr   r%  rQ   rT  r6   r5   ).r   r   rf   rg   rm   zfinalri   rA  r*  r)  condrh   r/  bhr~  bor(  ajrj   r=  rk   rA  r)  hargr  hypb_r  kir   r  liaolur   dir   	integrandr  residaurr   r  r  rR  r   s.   &&&&f&                                     r[   	do_slater!_meijergexpand.<locals>.do_slater  s    "")--/c665= 2wR 3r7SW#44r7SWB#b' 11q6A:D5=665= ffA36{aVAY"X		"B5b>)C B5R"--C B5R"--C B5b>)C +/8d2h+>?+>aq2vzz+>?+/8d2h+>?+>aq2vzz+>?q}}s2wR/@ABx Q3)">#s#;T3#$gr4ASy VAY(+r
3
"b2gg
3G(+vA7"b2gg7"XAIIaL  "XAIIaL $V*-b"+6+Aa!ee+6 #JqD	Aq!99aMq1u-I  Aq1uqy!11I Aq1uqy!11I 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zz+>?1#E+/8d2h+>?+>aq2vzz+>?">#s#;T3#$gr4A MMB'	"5qA1-bbeaA.GGGA "Aq1urz**A Aq2v&A Aq2v&A Aq1urz**A  qui l yQ @? 47 7: @?s*   %\\\!\&\+&\1'\6r   c                 >    V  Uu. uF  p^V,
          NK  	  up# u upi rU   r   )r   rY   s   & r[   r   _meijergexpand.<locals>.trB	  s      !q!Aq!!!s   Fnonrepr  c                     VR J d   ^ pMVRJ d   ^pM^pV P                  \        \        \        ) \        4      '       d   ^pW P	                  \
        4      V P                  4       3# )TF)rE  r   r   r   countr>   	count_ops)r   r  c0s   && r[   weight_meijergexpand.<locals>.weightr	  sX    4<BU]BB88BbS#&& BJJu%t~~'788r]   z@  Could express using hypergeometric functions, but not allowed.r   )(_meijercollectionr  r   r   rI  r  ri   r  rT  rr   r  rm   rO  rs   rL  r   rq   rR   r   r   rf   rg   rP   r  r8  r   r   deltar   r9   nur1   r  r   r]  r   r^  r8   rE  r>   )ri   r  allow_hyperr  placefunc0rm   rz  rr   r  r  slater1cond1r   r  slater2cond2r/  r  w1w2r  rR  r   s   &&&&&                @@@r[   _meijergexpandr    s_     35)E	
=tD 	c
A#D)ID#
#T*)* 	''-A},aff5!!&&$22 ACCHHQSS!,c4QSSXXacc15EqIK KK	!%cchhqssAaDIIa$''	
GH	eN 	c
Atww$''1ING" 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}//'"5"5X6//'":":];}//'"5"5X6//'":":];Ee50A:EC<EeT""

1!eT""

1!9 
	B		B
2r{q!Rj 7NN
2a5"Q%A#beRU"3q"8')GU+;eBi=NOO
 	7"We$4uRy$6GHAuuU||K ! 	"55<<;9r]   c                   aaa \        V 4      p V3R lpVVV3R lpV P                  \        V4      P                  \        V4      # )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   < \        \        W4      VSR 7      pVf   \        WV4      # V# )r  )r  rc   r>   )rf   rg   rm   r  r  s   &&& r[   
do_replacehyperexpand.<locals>.do_replace	  s-    /GD9##Hr]   c           	         < \        \        V ^ ,          V ^,          V^ ,          V^,          4      VSSSR7      pVP                  \        \        \
        \
        ) 4      '       g   V# R# )r   )r  r  N)r  r   rE  r   r   r   )rf   rg   rm   r  r  r  r  s   &&& r[   	do_meijerhyperexpand.<locals>.do_meijer	  sT    :beRUBqE2a5A1u>uuS#rB3''H (r]   )r
   r  r>   rJ   )rz  r  r  r  r!  r$  s   &fff  r[   hyperexpandr&  	  s8    2 	
A
 99UJ'//CCr]   )Fr  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.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   $sympy.functions.elementary.complexesr<   r=   sympy.functions.special.hyperr>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   sympy.matricesrK   rL   rM   sympy.polysrN   rO   rP   sympy.seriesrQ   sympy.simplify.powsimprR   sympy.utilities.iterablesrS   r\   r   r   r   r   rc   r   r8  re   ru  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r#  r?  rB  rI  rO  rT  r{  r  r  r  r  r  r  r  r  r  r  r&  r   r]   r[   <module>r7     si  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  }@'Dr]   