+
    i5H                         ^ RI HtHtHtHtHt ^ RIHtHt ^ RI	H
t
 ^ RIHt ^ RIHtHtHt ^ RIHtHt ^ RIHtHt R tR	 t ! R
 R]4      tR# )    )FunctionSMulPowAdd)ordereddefault_sort_key)expand_func)Dummy)gammasqrtsin)factorcancel)siftuniqc                   V P                  \        4      p V P                  \        4      pV Uu0 uF  p\	        V\        4      '       g   K  VkK  	  ppV'       g   V # W,          pWP                  4       P                  \        4      ,          pV'       d   \        \        V4       UUu. uFB  p\        4       YDP                  ! VP                   Uu. uF  p\        VRR7      NK  	  up!  3NKD  	  upp!  w  rgpV P                  \        \        Wv4      4      4      p	\        V	RR7      P                  \        \        Wh4      4      4      # \        V RR7      # u upi u upi u uppi )a}  
Simplify expressions with gamma functions.

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

This function takes as input an expression containing gamma
functions or functions that can be rewritten in terms of gamma
functions and tries to minimize the number of those functions and
reduce the size of their arguments.

The algorithm works by rewriting all gamma functions as expressions
involving rising factorials (Pochhammer symbols) and applies
recurrence relations and other transformations applicable to rising
factorials, to reduce their arguments, possibly letting the resulting
rising factorial to cancel. Rising factorials with the second argument
being an integer are expanded into polynomial forms and finally all
other rising factorial are rewritten in terms of gamma functions.

Then the following two steps are performed.

1. Reduce the number of gammas by applying the reflection theorem
   gamma(x)*gamma(1-x) == pi/sin(pi*x).
2. Reduce the number of gammas by applying the multiplication theorem
   gamma(x)*gamma(x+1/n)*...*gamma(x+(n-1)/n) == C*gamma(n*x).

It then reduces the number of prefactors by absorbing them into gammas
where possible and expands gammas with rational argument.

All transformation rules can be found (or were derived from) here:

.. [1] https://functions.wolfram.com/GammaBetaErf/Pochhammer/17/01/02/
.. [2] https://functions.wolfram.com/GammaBetaErf/Pochhammer/27/01/0005/

Examples
========

>>> from sympy.simplify import gammasimp
>>> from sympy import gamma, Symbol
>>> from sympy.abc import x
>>> n = Symbol('n', integer = True)

>>> gammasimp(gamma(x)/gamma(x - 3))
(x - 3)*(x - 2)*(x - 1)
>>> gammasimp(gamma(n + 3))
gamma(n + 3)

F)as_comb)rewriter   atomsr   
isinstanceas_dummyzipr   r   funcargs
_gammasimpxreplacedict)
exprfigammasfiadumfunsimpds
   &         x/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/simplify/gammasimp.py	gammasimpr*   
   s*   d <<D
 	

8A3AjE2aaF3KA	MMO!!(++A aj" ! Wb''68gg$?6=
1e,g$? @ A " #$ MM$s3}-.!U+44T#c.5IJJdE** 4$?"s#   EE*(E#
E(
E#
E#
c                .  aa V P                  \        R 4      p S'       d   V P                  \        R 4      p MV P                  \        R 4      p RVV3R llo\        V 4      pS! V4      p W8w  d   \        V 4      p V P                  \        R 4      p V # )a  
Helper function for gammasimp and combsimp.

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

Simplifies expressions written in terms of gamma function. If
as_comb is True, it tries to preserve integer arguments. See
docstring of gammasimp for more information. This was part of
combsimp() in combsimp.py.
c                 D    \        ^V ^,
          P                  4       4      #    )_rfexpandns   &r)   <lambda>_gammasimp.<locals>.<lambda>a   s    #a!a%)*    c                 &    \        V^,           4      # r-   r   r$   bs   &&r)   r3   r4   e   s    q1ur5   c                 D    \        W,           4      \        V 4      ,          # Nr7   r8   s   &&r)   r3   r4   h   s    queAh.r5   c                .  <a(a)a*a+a,a- V P                   '       d   V # R pV+3R lo+V^ 8X  dA   V P                  ! V P                   Uu. uF  pS/! W1^,           4      NK  	  up!  p V^,          pV P                  '       g   V # V^8X  dm   V P	                  4       w  rEV'       g   V # V'       d@   S/! \
        P                  ! V4      V^,           4      \
        P                  ! V4      ,          # V^,          pV^8X  Edy   \        V P                  S+RR7      w  rg\        V!  p\        V!  p	V	P                  4       w  r\        ^4       F  p\        \        \
        P                  ! V
4      4      4      p\        V4       F  w  rVP                  '       g   K  \        VP                   Uu. uF  pS/! V! W,          4      V^,           4      NK!  	  up!  P                  4       w  rWV&   VP!                  \"        4      '       d   K   M	  \        V!  p
V^ 8X  d   S+! V
4      '       g    MYrK  	  W,          V,          p V P                  '       d   S+! V4      '       g   S+! V
4      '       g   V # V^,          pV^8X  d    T pS/! V ^4      p V V8X  g   K  V # . p. p. p. pR p\        \        V P                  4      4      pV'       d   VP%                  4       P                  4       w  pp	V! V4      w  ppV'       d   VP'                  V4       MVRJ d   VP'                  V4       V! V	4      w  ppV'       d   VP'                  V4       K  VRJ g   K  VP'                  V4       K  S.'       Eg   VVV3VVV33 EFS  w  ppp. pV'       Ed<   VP%                  4       o*S*P(                  '       d   VP+                  S*4       K>  \        V4       F  w  ppS*V,           ^,
          pVP,                  '       g   K*  VP+                  \.        P0                  4       VP+                  \3        \.        P0                  S*,          4      4       VP%                  V4       V^ 8  d&   VP'                  V*3R l\        V4       4       4       M,V^ 8  d&   VP'                  V*3R l\        V) 4       4       4        EK.  	  VP+                  S*4       EKD  VVR	&   EKV  	  VVVV3VVVV33 EF2  w  pp p!p" V F2  pV  F'  o-V^S-,          ,
          pVP,                  '       g   K'   M	  K2   M	  KD  VP5                  V4       V P5                  S-4       V^ 8  d&   V!P'                  V-3R
 l\        V4       4       4       M,V^ 8  d&   V"P'                  V-3R l\        V) 4       4       4       VP+                  S-\.        P6                  ,           4       V!P+                  ^^S-,          ^,
          ,          4       V"P+                  \9        \.        P0                  4      4       EK,  	  R o(V(3R lp#VVV3VVV33 F  w  pppV#! VVV4       K  	  V^8  Eda   V)V,3R lp$/ o,V,3R lo)V)V,3R lp%VV,           V,           V,            F  p V%! V 4       K  	  VVV3VVV33 EF  w  ppp. pV'       d   VP%                  4       p&Rp'V''       d   Rp'V$! VV&4      o-S-eK   VP5                  S-4       S-V&8w  d(   VP+                  S-V&,          4       V%! S-V&,          4       V&^,          p&Rp'V$! VV&^,
          4      o-S-f   Kw  VP5                  S-4       S-V&^,
          8w  d6   VP+                  V&^,
          S-,          4       V%! V&^,
          S-,          4       V&^,          p&Rp'K  VP+                  V&4       EK  VVR	&   EK  	  \        V U&u. uF  p&\#        V&4      NK  	  up&!  \        V U&u. uF  p&\#        V&4      NK  	  up&!  ,          \        V!  ,          \        V!  ,          # u upi u upi u up&i u up&i )z.Simplify products of gamma functions further. c                     V P                  \        4      pV P                  \        R  4      pVP                  \        4      V8  d   Tp V # )c                 n    \        ^V ^,
          P                  4       4      P                  \         R 4      # )r.   c                 D    \        W,           4      \        V 4      ,          # r;   r7   r8   s   &&r)   r3   U_gammasimp.<locals>.rule_gamma.<locals>.gamma_rat.<locals>.<lambda>.<locals>.<lambda>t   s    E!%Lq,Ar5   )r/   r0   replacer1   s   &r)   r3   C_gammasimp.<locals>.rule_gamma.<locals>.gamma_rat.<locals>.<lambda>s   s+    CAE>>3C -'#AB-Cr5   )countr   rA   )xwasxxs   &  r)   	gamma_rat1_gammasimp.<locals>.rule_gamma.<locals>.gamma_ratp   s@    ''%.C5 #C DBxx$Hr5   c                   < \        V \        4      '       d   R # V P                  '       g   V P                  '       dO   \        ;QJ d)    V3R lV P
                   4       F  '       g   K   R # 	  R# ! V3R lV P
                   4       4      # V P                  '       dK   V P                  P                  '       g   V P                  P                  '       d   S! V P                  4      # R# )Tc              3   4   <"   T F  pS! V4      x  K  	  R # 5ir;    ).0xigamma_factors   & r)   	<genexpr>G_gammasimp.<locals>.rule_gamma.<locals>.gamma_factor.<locals>.<genexpr>~   s     =f<++fs   F)r   r   is_Addis_Mulanyr   is_Powexp
is_integerbaseis_positive)rD   rN   s   &r)   rN   4_gammasimp.<locals>.rule_gamma.<locals>.gamma_factory   s    !U##xxx1888s=aff=ss=s=s=aff===xxxQUU---1C1C1C#AFF++r5   T)binaryc                    V \         P                  J d   R . 3# V P                  4       w  rVP                  '       d@   \	        V\
        4      '       d   RVP                  ^ ,          .V,          3# RV.V,          3# RV .3# )NTF)r   Oneas_base_exp
is_Integerr   r   r   )pr9   es   &  r)   	explicate1_gammasimp.<locals>.rule_gamma.<locals>.explicate   sn    AEEzRx==?DA|||a''!&&)Q.. 1#a%<'qcz!r5   Fc              3   D   <"   T F  p^S,
          V,           x  K  	  R# 5i)r.   NrK   rL   kg1s   & r)   rO   1_gammasimp.<locals>.rule_gamma.<locals>.<genexpr>   s     (FXR!X    c              3   8   <"   T F  pS) V,
          x  K  	  R # 5ir;   rK   rd   s   & r)   rO   rg      s     (D)Q"q)s   NNNc              3   D   <"   T F  p^S,          V,           x  K  	  R# 5i   NrK   rL   re   ys   & r)   rO   rg     s     !<8a!A#''8rh   c              3   R   <"   T F  p^S,          ^,
          V,
          x  K  	  R# 5irl   rK   rn   s   & r)   rO   rg     s     !Ay!!A#'A++ys   $'c                    \        \        V 4      4      p\        \        V4      4       EFM  p\        V^,           \        V4      4       Uu. uF!  q1V,          W,          ,
          ^,          V3NK#  	  ppV F  w  rSVP                  ^8X  g   K  VP
                  ^8w  g   K+  VP
                  pV.p\        \        ^V4      4      pV FU  w  rWi,          p
V
P                  '       g   K!  W9   g   K)  VP                  V
4       VP                  V4       V'       d   KU   M	  K  \        V4       F"  w  r#W,          pV P                  V4       WV&   K$  	  VP
                  V^ ,          VR,          3u u # 	  EKP  	  R# u upi )r.   :r.   NNN)
listr   rangelenr_   qr^   removeappend	enumerate)coeffsur!   jdjoner2   gotgetr(   mcs   &           r)   _run,_gammasimp.<locals>.rule_gamma.<locals>._run"  s'    f&s1vA;@QA;OP;OaqTAD[A-q1;OBP"$55A:#%%1* #A#$#C"&uQ{"3C(*$%C#$<<<AH$'JJqM$'JJqM+.3(- )+ !)(1#$%D &a 0)*A )7 $'55#a&#b'#99% #% 'Ps   'E=c                 D  < / pV  F6  pVP                  4       w  rVVP                  V. 4      P                  V4       K8  	  \        V\        R 7      pV EF%  p\        W6,          4      p. p	 S! V4      p
V
f   MV
w  rpV FK  pWn,           ^,
          p\        \        W,
          4      4       F  pVP                  VV,
          4       K  	  KM  	  WV,           ,          pVP                  ^\        P                  ,          \        V^,
          4      ^,          ,          V\        P                  V,
          ,          ,          4       V	P                  V4       K  V Uu. uF  qVV,           NK  	  upV	,           W6&   EK(  	  . pV F  pWCV,          ,          pK  	  W@R&   R# u upi ))keyNrj   )
as_coeff_Add
setdefaultrw   sortedr	   rs   intr   PiHalf)r"   numerdenomratsgr   residkeysry   newrunr2   uiotherrz   conre   r   s   &&&              r)   	_mult_thm1_gammasimp.<locals>.rule_gamma.<locals>._mult_thm<  se   
 A ~~/HAOOE2.55a8  
 d(89!E#DK0FC"6l;! (+u "'A"')a-C%*3qv;%7 %S1W 5 &8 "'
  n af!a%
%;%&#%6&7 8 

3 7="=f199f"="CDK? "D !Ee$A " q	 #>s   Fc                   < V '       g   R # S
! V4      w  r#V  F  pSV,          w  rVW68w  g6   VP                  V4      '       g!   V\        4       8w  g   V\        4       8w  d   KK  \        \        W,          4      P                  4      p\        VP                  4      p\        VP                  4      p	V^ 8X  g   K  V^ 8  g
   V	^ 8  g   K  Vu # 	  R # r;   )intersectionsetrt   r   free_symbols)lrD   S1T1ro   S2T2r$   r9   r   
compute_STinvs   &&        r)   
find_fuzzy2_gammasimp.<locals>.rule_gamma.<locals>.find_fuzzy{  s    #AA VFBx(;(;%'35[B#%K  F13K445AANN+AANN+AAv1q5AE  r5   c                    < V S9   d
   SV ,          # V P                   V P                  \        4      P                  V P                  \        4       Uu0 uF  qP
                  kK  	  up4      3# u upi r;   )r   r   r   unionr   rU   )r   r`   r   s   & r)   r   2_gammasimp.<locals>.rule_gamma.<locals>.compute_ST  s\    3;t9$))4::h+?+E+E(,

3818,: ; ;8s   A.
c                    < S! V 4      SV &   R # r;   rK   )r   r   r   s   &r)   	update_ST1_gammasimp.<locals>.rule_gamma.<locals>.update_ST  s    &t,D	r5   )is_Atomr   r   rR   args_cncr   
_from_argsr   as_numer_denomrs   rr   r   	make_argsrx   rQ   r   hasr   popextendrV   rw   r^   r   r   r   rv   r   r   )0r   levelrG   rD   r   ncTF	gamma_indr(   ndddipassr!   nir$   rE   numer_gammasdenom_gammasnumer_othersdenom_othersra   newargsr2   isgr   r"   r   r   r   g2ngdgnodor   r   r   r   contr   r   rf   rN   r   ro   r   
rule_gammas0   &&                                      @@@@@@r)   r   _gammasimp.<locals>.rule_gammaj   s    <<<K		 A:99KAz!QY7KLDQJE{{{K A:}}HD!#.."6	B3>>RTCUUUQJE A:		<=DAQIQA%%'FBqGCMM"$567&t_EAyyy!$LNGG'ULSqJy	BG'U ",n.  #%Q!vve}}! - $ZQ;|B'7'7B " <?DKKK\"%5%5b9I9IQJE A:!$*3;K
	" wtyy)*;;=//1DAqq\FC##A&##A&q\FC##A&##A& w lL*:!<>)@$u fB}}}

2 !*6!22GaK |||$QTT*Sb\2

1q5!LL(FU1X(FFU!LL(D%)(DD "3 

2q	1)@> %1,$0$2$0,$0$2#3BB
 !#A !AaCA ||| % "$
 %   IIaLIIaL1u		!<58!<<Q		!AuaRy!AAIIa!&&j)IIa!A#'l+IId144j)1#3T:42h &2<$N%1<$N$P5%!UE*$P A:
!0 C;-$|3lB\QQ$ R lL*:!<>)@$u 

AD$&ua0=!LLO Av %QqS 1 )!A#FA#'D&ua!e4=!LLO AEz %a!eQY 7 )1q5!) 4FA#'DJJqMq	7)@> |4|!U1X|45l3lE!Hl345< !#&#56 	6u	 L4'U@	 53s   `&%`'``
c                 d    V P                   '       d   \        \        V 4      4      # \        V 4      # r;   )is_Rationalr
   r   r1   s   &r)   r3   r4     s!    1===+eAh'FeAhFr5   )r   )rA   r   r/   r   )r   r   rE   r   s   &f @r)   r   r   T   s     <<*,D ||C%' ||C.0W6 W6r
 ,Cc?D{d|<<FHD Kr5   c                   0   a  ] tR tRt o ]R 4       tRtV tR# )r/   i  c                   VP                   '       d   V'       g   \        P                  # \        V4      pV^ 8  d)   \	        \        V4       Uu. uF  qAV,           NK  	  up!  # V^ 8  d9   ^\	        \        ^V) ^,           4       Uu. uF  qAV,
          NK  	  up!  ,          # R# VP                  '       d   VP                  4       w  rVVP                   '       d[   V^ 8  d#   \        W4      \        W,           V4      ,          # V^ 8  d+   \        W4      \        W,           V,           V) 4      ,          # VP                  '       d   VP                  4       w  rWVP                   '       d   V^ 8  d3   \        Wr4      \        Wr,           V4      ,          \        Wu4      ,          # V^ 8  dC   \        Wr4      \        Wu,           V) 4      ,          \        Wr,           V,           V) 4      ,          # R# R# R# u upi u upi )r   N)	r^   r   r\   r   r   rs   rQ   r   r/   )clsr$   r9   r2   r!   r   _b_as   &&&     r)   eval_rf.eval  s~   <<<uuAA1uE!H5HqUUH566QeArAv.>?.>1uu.>?@@@  xxx(<<<1u"1z#afa.88Q"1z#afqj1"*===xxx(<<<1u"2z#bfa.8RCCQ"2z#bfqb/9#bfqj1":MMM     6?s   G4G9
rK   N)__name__
__module____qualname____firstlineno__classmethodr   __static_attributes____classdictcell__)__classdict__s   @r)   r/   r/     s     N Nr5   r/   N)
sympy.corer   r   r   r   r   sympy.core.sortingr   r	   sympy.core.functionr
   sympy.core.symbolr   sympy.functionsr   r   r   sympy.polysr   r   sympy.utilities.iterablesr   r   r*   r   r/   rK   r5   r)   <module>r      s<    1 1 8 + # , , & 0G+TxvN( Nr5   