+
    ‹°³j™  ã                  ó~  € ^ RI Ht ^ RIHt ^ RIHtHtHtHt ^ RI	H
t
 ^ RIHtHtHt ^ RIHt ^ RIHtHtH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%  ! R R]4      t& ! R R]&4      t! ! R R]&4      t' ! R R]&4      t( ! R R]&4      t) ! R R]&4      t* ! R R]&4      t+]*t,]+t- ! R R]&4      t.R# )é    )Úannotations)Úreduce)ÚSÚsympifyÚDummyÚMod)Úcacheit)ÚDefinedFunctionÚArgumentIndexErrorÚ	PoleError)Ú	fuzzy_and)ÚIntegerÚpiÚI)ÚEq)Úgmpy)Úsieve)Úbinomial_mod)ÚPoly)Ú	factorialÚprodÚsqrtc                  ó    € ] tR t^tRtR tRtR# )ÚCombinatorialFunctionz(Base class for combinatorial functions. c                	óz   € ^ RI Hp V! V 4      pVR,          pV! V4      VR,          V! V 4      ,          8:  d   V# V # )r   )ÚcombsimpÚmeasureÚratio)Úsympy.simplify.combsimpr   )ÚselfÚkwargsr   Úexprr   s   &,   Úi/home/luca/screen-checking/.venv/lib/python3.14/site-packages/sympy/functions/combinatorial/factorials.pyÚ_eval_simplifyÚ$CombinatorialFunction._eval_simplify   s=   € Ý4ñ ˜‹~ˆØ˜Õ#ˆÙ�4‹=˜F 7�O©G°D«MÕ9Ô9ØˆKØˆó    © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r$   Ú__static_attributes__r'   r&   r#   r   r      s
   † Ù2ör&   r   c                  ó,  € ] tR t^$t$ RtR(R lt. ^N^N^N^N^N^N^N^#N^#NRN^?NRN^çNRNRNRNRNRNR	NR
NRNRNRNRNRNRNRNRNRNRNRNRNRNt. tR]R&   ]	R 4       t
]	R 4       t]	R 4       tR tR tR)R ltR tR  tR! tR" tR# tR$ tR% tR&tR'# )*r   a¿  Implementation of factorial function over nonnegative integers.
By convention (consistent with the gamma function and the binomial
coefficients), factorial of a negative integer is complex infinity.

The factorial is very important in combinatorics where it gives
the number of ways in which `n` objects can be permuted. It also
arises in calculus, probability, number theory, etc.

There is strict relation of factorial with gamma function. In
fact `n! = gamma(n+1)` for nonnegative integers. Rewrite of this
kind is very useful in case of combinatorial simplification.

Computation of the factorial is done using two algorithms. For
small arguments a precomputed look up table is used. However for bigger
input algorithm Prime-Swing is used. It is the fastest algorithm
known and computes `n!` via prime factorization of special class
of numbers, called here the 'Swing Numbers'.

Examples
========

>>> from sympy import Symbol, factorial, S
>>> n = Symbol('n', integer=True)

>>> factorial(0)
1

>>> factorial(7)
5040

>>> factorial(-2)
zoo

>>> factorial(n)
factorial(n)

>>> factorial(2*n)
factorial(2*n)

>>> factorial(S(1)/2)
factorial(1/2)

See Also
========

factorial2, RisingFactorial, FallingFactorial
c                	óÂ   € ^ RI HpHp V^8X  dG   V! V P                  ^ ,          ^,           4      V! ^ V P                  ^ ,          ^,           4      ,          # \	        W4      h)r   )ÚgammaÚ	polygamma)Ú'sympy.functions.special.gamma_functionsr0   r1   Úargsr   )r    Úargindexr0   r1   s   &&  r#   ÚfdiffÚfactorial.fdiffU   sH   € ßNØ�qŒ=Ù˜Ÿ™ 1�¨Õ)Ó*©9°Q¸¿	¹	À!½ÀqÕ8HÓ+IÕIÐIä$ TÓ4Ð4r&   i;  iµ  i»  i­  i#  iS« i{/  i!† im´  iñÌ isX iUò iÇP
 ioãikÖ iI�i/„L iSùªi}î“ i#áéz	list[int]Ú_small_factorialsc                	ó~  € V^!8  d   V P                   V,          # \        \        V4      4      . r2\        P                  ! ^V^,           4       FK  p^Tre Wd,          pV^ 8”  d   V^,          ^8X  d   WT,          pK(  K*   T^8”  g   K:  TP                  T4       KM  	  \        P                  ! V^,           V^,          ^,           4       F*  pW,          ^,          ^8X  g   K  VP                  V4       K,  	  \        \        P                  ! V^,          ^,           V^,           4      4      p\        V4      pWx,          # )é!   )Ú_small_swingÚintÚ_sqrtr   Ú
primerangeÚappendr   )	ÚclsÚnÚNÚprimesÚprimeÚpÚqÚ	L_productÚ	R_products	   &&       r#   Ú_swingÚfactorial._swingd   s  € àˆrŒ6Ø×#Ñ# AÕ&Ð&äœE !›H› rˆvä×)Ò)¨!¨Q°­UÖ3�Ø˜!�1àØ•K�Aà˜1”uØ˜q�5 Aœ:Ø�JšAñ &ð à�q–5Ø—M‘M !Ö$ñ 4ô ×)Ò)¨!¨a­%°°Aµ¸µÖ:�Ø•J !Õ# qÖ(Ø—M‘M %Ö(ñ ;ô œU×-Ò-¨a°­d°Q­h¸¸A½Ó>Ó?ˆIÜ˜V›ˆIàÕ&Ð&r&   c                	ó~   € V^8  d   ^# V P                  V^,          4      ^,          V P                  V4      ,          # )é   )Ú
_recursiverH   )r?   r@   s   &&r#   rL   Úfactorial._recursiveƒ   s1   € àˆqŒ5Ùà—N‘N 1 a¥4Ó(¨!Õ+¨S¯Z©Z¸«]Õ:Ð:r&   c                	óþ  € \        V4      pVP                  '       Ed_   VP                  '       d   \        P                  # V\        P
                  J d   \        P
                  # VP                  '       Ed   VP                  '       d   \        P                  # VP                  pV^8  df   V P                  '       g9   ^p\        ^^4       F&  pW#,          pV P                  P                  V4       K(  	  V P                  V^,
          ,          pM^\        e   \        P                  ! V4      pM?\        V4      P!                  R4      pV P#                  V4      ^W,
          ,          ,          p\%        V4      # R# R# )é   NÚ1)r   Ú	is_NumberÚis_zeror   ÚOneÚInfinityÚ
is_IntegerÚis_negativeÚComplexInfinityrD   r7   Úranger>   Ú_gmpyÚfacÚbinÚcountrL   r   )r?   r@   ÚresultÚiÚbitss   &&   r#   ÚevalÚfactorial.evalŠ   s  € ä�A‹Jˆà�;�;‰;Ø�y�yˆyÜ—u‘u�Ø”a—j‘j“Ü—z‘zÐ!Ø——‘Ø—=—=�=Ü×,Ñ,Ð,àŸ™�Aà˜2”vØ"×4×4Ð4Ø%&˜FÜ%*¨1¨b¦\ Ø &¥ Ø #× 5Ñ 5× <Ñ <¸VÖ Dñ &2ð "%×!6Ñ!6°q¸µsÕ!;™ô Ò*Ü!&§¢¨1£™ô  # 1›vŸ|™|¨CÓ0˜Ø!$§¡°Ó!2°1°qµxµ=Õ!@˜ä" 6›?Ð*ñ= ñ r&   c                	óê  € ^\        \        V4      4      rC^.V,          p^p\        P                  ! ^V^,           4       Fg  pV^8”  d$   ^ W,          r†V'       d   Wh,          pW‡,          pK  Wd8  d   WV,          V,          V,          WV&   KM  V\	        WvV4      ,          V,          pKi  	  \        V4       F9  w  ršV	^ 8X  g   V
^8X  d   K  V
^ 8X  d    ^ # V\	        W©V4      ,          V,          pK;  	  V# ©é   )r;   r<   r   r=   ÚpowÚ	enumerate)r    r@   rE   ÚresrA   ÚpwÚmrC   ÚyÚexÚbss   &&&        r#   Ú_facmodÚfactorial._facmod³   sÓ   € Ø”Cœ˜a›“MˆQð ˆS��UˆàˆÜ×%Ò% a¨¨Q­Ö/ˆEØ�1ŒuØ˜!�*�1ßØ•F�AØ•K’AØŒuØ�˜e� a��“àœ#˜e¨Ó*Õ*¨QÕ.’ñ 0ô   –m‰FˆBØ�QŒw˜" œ'ÙØ�QŒwÚØ”c˜" !“nÕ$ qÕ(ŠCñ $ð ˆ
r&   c                	ó"  € V P                   ^ ,          pVP                  '       Edi   VP                  '       EdT   VP                  '       Ed?   \        V4      pW2,
          pVP                  '       d   \
        P                  # VP                  pV^8X  dE   V'       d
   RV,          # VRJ d,   V^,
          P                  '       d   \
        P                  # R# R# VP                  '       dŸ   VP                  '       d‹   \        \        W$V34      w  r$pV'       dU   V^,
          V8  dG   V P                  V^,
          V4      p\        Wc^,
          V4      pV^,          '       d   V) pWa,          # V P                  W#4      pWa,          # R# R# R# R# R# )r   FNéÿÿÿÿ)r3   Ú
is_integerÚis_nonnegativeÚabsÚis_nonpositiver   ÚZeroÚis_primerU   Úmapr;   rm   re   )r    rE   r@   ÚaqÚdÚisprimeÚfcs   &&     r#   Ú	_eval_ModÚfactorial._eval_ModÑ   s.  € Ø�I‰I�a�LˆØ�<�<‰<˜A×,×,Ñ,°··±Ü�Q“ˆBØ•ˆAØ××ÐÜ—v‘v�àŸ+™+�Ø˜”6÷
 Ø! A�v˜Ø  EÓ)¨r°A­v×.E×.EÐ.EÜ Ÿv™v˜ñ /FÑ)à—\—\�\ a§l§l lÜ"¤3¨¨r¨
Ó3‘H�A˜"ß A¨¥E¨A¤IØ!Ÿ\™\¨!¨a­%°Ó4˜Ü  ¨!¥V¨RÓ0˜Ø˜QŸ3œ3Ø"$ ˜Bð �6�Mð "Ÿ\™\¨!Ó0˜à�6�Mñ '3‘\ñ! 2>Ñ,‰<r&   c                	ó,   € ^ RI Hp V! V^,           4      # ©r   ©r0   ©r2   r0   )r    r@   Ú	piecewiser!   r0   s   &&&, r#   Ú_eval_rewrite_as_gammaÚ factorial._eval_rewrite_as_gammaï   s   € ÝAÙ�Q˜•U‹|Ðr&   c                	óŽ   € ^ RI Hp VP                  '       d-   VP                  '       d   \	        RRR7      pV! WD^V34      # R# R# )r   )ÚProductr^   T)ÚintegerN)Úsympy.concrete.productsr†   rr   rq   r   )r    r@   r!   r†   r^   s   &&,  r#   Ú_eval_rewrite_as_ProductÚ"factorial._eval_rewrite_as_Productó   s>   € Ý3Ø××Ð §§ Ü�c 4Ô(ˆAÙ˜1 ! Q˜iÓ(Ð(ñ !-Ñr&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# ©r   TN©r3   rq   rr   ©r    s   &r#   Ú_eval_is_integerÚfactorial._eval_is_integerù   ó5   € Ø�9‰9�Q�<×"×"Ð" t§y¡y°¥|×'B×'BÐ'BÙñ (CÑ"r&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# rŒ   r�   rŽ   s   &r#   Ú_eval_is_positiveÚfactorial._eval_is_positiveý   r‘   r&   c                	óž   € V P                   ^ ,          pVP                  '       d(   VP                  '       d   V^,
          P                  # R# R# ©r   Nr�   ©r    Úxs   & r#   Ú_eval_is_evenÚfactorial._eval_is_even  ó:   € Ø�I‰I�a�LˆØ�<�<ˆ<˜A×,×,Ð,Ø˜•E×)Ñ)Ð)ñ -‰<r&   c                	óž   € V P                   ^ ,          pVP                  '       d(   VP                  '       d   V^,
          P                  # R# R# r–   r�   r—   s   & r#   Ú_eval_is_compositeÚfactorial._eval_is_composite  r›   r&   c                	óx   € V P                   ^ ,          pVP                  '       g   VP                  '       d   R# R# rŒ   )r3   rr   Úis_nonintegerr—   s   & r#   Ú_eval_is_realÚfactorial._eval_is_real  s+   € Ø�I‰I�a�LˆØ××Ð˜qŸŸ˜Ùñ  /r&   c                	ó  € V P                   ^ ,          P                  V4      pVP                  V^ 4      pVP                  '       d   \        P
                  # VP                  '       g   V P                  V4      # \        RV ,          4      h)r   zCannot expand %s around 0)	r3   Úas_leading_termÚsubsrR   r   rS   Úis_infiniteÚfuncr   )r    r˜   ÚlogxÚcdirÚargÚarg0s   &&&&  r#   Ú_eval_as_leading_termÚfactorial._eval_as_leading_term  sf   € Ø�i‰i˜�l×*Ñ*¨1Ó-ˆØ�x‰x˜˜1‹~ˆØ�<�<ˆ<Ü—5‘5ˆLØ×!×!Ð!Ø—9‘9˜S“>Ð!ÜÐ3°tÕ<Ó=Ð=r&   r'   Nrc   ©T)r(   r)   r*   r+   r,   r5   r:   r7   Ú__annotations__ÚclassmethodrH   rL   r`   rm   r|   rƒ   r‰   r�   r“   r™   r�   r¡   r¬   r-   r'   r&   r#   r   r   $   s£  ‡ ñ.ô`5ðØ	ðØðØðØðØðØðØðØ ðØ"$ðØ&)ðØ+-ðØ/2ðØ47ðØ9=ðØ?BðØDHðØJNðØPVðàðàðàðà$ðà&+ðà-4ðà6<ðà>FðàHOðð 	ðð ðð %ðð '.ðð 09ðð ;Dð€Lð $&Ð�yÓ%àñ'ó ð'ð< ñ;ó ð;ð ñ&+ó ð&+òPò<"ô<ò)òòò*ò
*ò
ö
>r&   r   c                  ó   € ] tR tRtRtR# )ÚMultiFactoriali  r'   N)r(   r)   r*   r+   r-   r'   r&   r#   r²   r²     s   † Ûr&   r²   c                  ór   € ] tR tRtRt]]R 4       4       t]R 4       tR t	R t
R tRR ltR	 tR
 tR tRtR# )Úsubfactoriali  a<  The subfactorial counts the derangements of $n$ items and is
defined for non-negative integers as:

.. math:: !n = \begin{cases} 1 & n = 0 \\ 0 & n = 1 \\
                (n-1)(!(n-1) + !(n-2)) & n > 1 \end{cases}

It can also be written as ``int(round(n!/exp(1)))`` but the
recursive definition with caching is implemented for this function.

An interesting analytic expression is the following [2]_

.. math:: !x = \Gamma(x + 1, -1)/e

which is valid for non-negative integers `x`. The above formula
is not very useful in case of non-integers. `\Gamma(x + 1, -1)` is
single-valued only for integral arguments `x`, elsewhere on the positive
real axis it has an infinite number of branches none of which are real.

References
==========

.. [1] https://en.wikipedia.org/wiki/Subfactorial
.. [2] https://mathworld.wolfram.com/Subfactorial.html

Examples
========

>>> from sympy import subfactorial
>>> from sympy.abc import n
>>> subfactorial(n + 1)
subfactorial(n + 1)
>>> subfactorial(5)
44

See Also
========

factorial, uppergamma,
sympy.utilities.iterables.generate_derangements
c                	óÊ   € V'       g   \         P                  # V^8X  d   \         P                  # ^^ r2\        ^V^,           4       F  pY4^,
          W2,           ,          r2K  	  V# rc   )r   rS   ru   rX   )r    r@   Úz1Úz2r^   s   &&   r#   Ú_evalÚsubfactorial._evalG  sP   € ÷ Ü—5‘5ˆLØ�!ŒVÜ—6‘6ˆMà˜�Ü˜1˜a !�e–_�Ø !�e b¥gÕ.’Bñ %àˆIr&   c                	ó(  € VP                   '       d€   VP                  '       d$   VP                  '       d   V P                  V4      # V\        P
                  J d   \        P
                  # V\        P                  J d   \        P                  # R # R # ©N)rQ   rU   rr   r¸   r   ÚNaNrT   )r?   rª   s   &&r#   r`   Úsubfactorial.evalT  sa   € à�=�=ˆ=Ø�~�~ˆ~ #×"4×"4Ð"4Ø—y‘y “~Ð%ØœŸ™“Ü—u‘u�ØœŸ
™
Ó"Ü—z‘zÐ!ñ #ñ r&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# rŒ   )r3   Úis_oddrr   rŽ   s   &r#   r™   Úsubfactorial._eval_is_even^  s4   € Ø�9‰9�Q�<××Ð 4§9¡9¨Q¥<×#>×#>Ð#>Ùñ $?Ñr&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# rŒ   r�   rŽ   s   &r#   r�   Úsubfactorial._eval_is_integerb  r‘   r&   c                	ó¨   € ^ RI Hp \        R4      p\        P                  V,          \        V4      ,          p\        V4      V! WT^ V34      ,          # )r   )Ú	summationr^   )Úsympy.concrete.summationsrÄ   r   r   ÚNegativeOner   )r    rª   r!   rÄ   r^   Úfs   &&,   r#   Ú_eval_rewrite_as_factorialÚ'subfactorial._eval_rewrite_as_factorialf  s?   € Ý7Ü�#‹JˆÜ�M‰M˜1Õœy¨›|Õ+ˆÜ˜‹~¡	¨!°°C¨[Ó 9Õ9Ð9r&   c                	ó  € ^ RI Hp ^ RIHpHp \
        P                  V^,           ,          V! \        ) \        ,          V,          4      ,          V! V^,           R4      ,          V! V^,           4      ,           V! R4      ,          # )r   )Úexp)r0   Ú
lowergammarp   )	Ú&sympy.functions.elementary.exponentialrË   r2   r0   rÌ   r   rÆ   r   r   )r    rª   r‚   r!   rË   r0   rÌ   s   &&&,   r#   rƒ   Ú#subfactorial._eval_rewrite_as_gammal  s\   € Ý>ßOÜ—‘  a¥Õ(©¬a¨R´­U°3­Y«Õ7¹
À3ÈÅ7ÈBÓ8OÕOÙ˜˜a�“.õ!Ù"% b£'õ*ð 	*r&   c                	óX   € ^ RI Hp V! V^,           R4      \        P                  ,          # )r   )Ú
uppergammarp   )r2   rÐ   r   ÚExp1)r    rª   r!   rÐ   s   &&, r#   Ú_eval_rewrite_as_uppergammaÚ(subfactorial._eval_rewrite_as_uppergammar  s   € ÝFÙ˜# �' 2Ó&¤q§v¡vÕ-Ð-r&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# rŒ   r�   rŽ   s   &r#   Ú_eval_is_nonnegativeÚ!subfactorial._eval_is_nonnegativev  r‘   r&   c                	óš   € V P                   ^ ,          P                  '       d(   V P                   ^ ,          P                  '       d   R# R# R# rŒ   )r3   Úis_evenrr   rŽ   s   &r#   Ú_eval_is_oddÚsubfactorial._eval_is_oddz  s5   € Ø�9‰9�Q�<××Ð D§I¡I¨a¥L×$?×$?Ð$?Ùñ %@Ñr&   r'   Nr®   )r(   r)   r*   r+   r,   r°   r	   r¸   r`   r™   r�   rÈ   rƒ   rÒ   rÕ   rÙ   r-   r'   r&   r#   r´   r´     s[   † ñ'ðR Øñ	ó ó ð	ð ñ"ó ð"òòò:ô*ò.òör&   r´   c                  óL   € ] tR tRtRt]R 4       tR tR tR t	R t
RR ltR	tR
# )Ú
factorial2i  aÕ  The double factorial `n!!`, not to be confused with `(n!)!`

The double factorial is defined for nonnegative integers and for odd
negative integers as:

.. math:: n!! = \begin{cases} 1 & n = 0 \\
                n(n-2)(n-4) \cdots 1 & n\ \text{positive odd} \\
                n(n-2)(n-4) \cdots 2 & n\ \text{positive even} \\
                (n+2)!!/(n+2) & n\ \text{negative odd} \end{cases}

References
==========

.. [1] https://en.wikipedia.org/wiki/Double_factorial

Examples
========

>>> from sympy import factorial2, var
>>> n = var('n')
>>> n
n
>>> factorial2(n + 1)
factorial2(n + 1)
>>> factorial2(5)
15
>>> factorial2(-1)
1
>>> factorial2(-5)
1/3

See Also
========

factorial, RisingFactorial, FallingFactorial
c                	óè  € VP                   '       dà   VP                  '       g   \        R 4      hVP                  '       dW   VP                  '       d#   V^,          p^V,          \        V4      ,          # \        V4      \        V^,
          4      ,          # VP                  '       d>   V\        P                  ^V,
          ^,          ,          ,          \        V) 4      ,          # \        R 4      hR# )z<argument must be nonnegative integer or negative odd integerN)
rQ   rU   Ú
ValueErrorrr   rØ   r   rÜ   r¿   r   rÆ   )r?   rª   Úks   && r#   r`   Úfactorial2.eval¥  s½   € ð �=�=ˆ=Ø—>—>�>Ü ð ">ó ?ð ?ð
 ×!×!Ð!Ø—;—;�;Ø˜a��AØ˜a�4¤)¨A£,Õ.Ð.Ü  “~¬
°3¸µ7Ó(;Õ;Ð;ð �z�zˆzØœAŸM™M¨a°#­g°q­[Õ9Õ9¼JÈÀtÓ<LÕLÐLÜð :ó ;ð ;ñ! r&   c                	óô   € V P                   ^ ,          pVP                  '       dS   VP                  '       d   R# VP                  '       d+   VP                  '       d   R# VP
                  '       d   R# R# R# R# ©r   FTN)r3   rq   r¿   rØ   Úis_positiverR   ©r    r@   s   & r#   r™   Úfactorial2._eval_is_even½  sT   € à�I‰I�a�LˆØ�<�<ˆ<Ø�x�xˆxÙØ�y�yˆyØ—=—=�=ÙØ—9—9�9Ù ñ ñ ñ r&   c                	óÔ   € V P                   ^ ,          pVP                  '       dC   V^,           P                  '       d   R# VP                  '       d   V^,           P                  # R# R# rŒ   )r3   rq   rr   r¿   rä   s   & r#   r�   Úfactorial2._eval_is_integerÉ  sP   € ð �I‰I�a�LˆØ�<�<ˆ<Ø�A•×%×%Ð%ÙØ�x�xˆxØ˜A�×-Ñ-Ð-ñ ñ r&   c                	óî   € V P                   ^ ,          pVP                  '       d   V^,           P                  # VP                  '       d+   VP                  '       d   R# VP
                  '       d   R# R# R# râ   )r3   r¿   rr   rØ   rã   rR   rä   s   & r#   rÙ   Úfactorial2._eval_is_oddÓ  sU   € ð �I‰I�a�LˆØ�8�8ˆ8Ø˜•E×)Ñ)Ð)Ø�9�9ˆ9Ø�}�}ˆ}ÙØ�y�yˆyÙñ ñ r&   c                	óâ   € V P                   ^ ,          pVP                  '       dJ   V^,           P                  '       d   R# VP                  '       d   V^,           ^,          P                  # R# R# rŒ   )r3   rq   rr   r¿   rØ   rä   s   & r#   r“   Úfactorial2._eval_is_positiveß  sT   € ð �I‰I�a�LˆØ�<�<ˆ<Ø�A•×%×%Ð%ÙØ�x�xˆxØ˜Q� !�×,Ñ,Ð,ñ ñ r&   c                	ó  € ^ RI Hp ^ RIHp ^ RIHp ^V^,          ,          V! V^,          ^,           4      ,          V! ^\        \        V^4      ^ 4      3V! ^\        ,          4      \        \        V^4      ^4      34      ,          # )r   )r   ©Ú	Piecewiser€   )	Ú(sympy.functions.elementary.miscellaneousr   Ú$sympy.functions.elementary.piecewiserî   r2   r0   r   r   r   )r    r@   r‚   r!   r   rî   r0   s   &&&,   r#   rƒ   Ú!factorial2._eval_rewrite_as_gammaê  si   € ÝAÝBÝAØ�1�Q•3�x™˜a �c A�g›Õ&©°A´r¼#¸aÀ»)ÀQÓ7GÐ3HÙ�aœ•d“œR¤ A q£	¨1Ó-Ð.ó*0õ 0ð 	0r&   r'   Nr®   )r(   r)   r*   r+   r,   r°   r`   r™   r�   rÙ   r“   rƒ   r-   r'   r&   r#   rÜ   rÜ     s:   † ñ#ðJ ñ;ó ð;ò.
!ò.ò
ò	-÷0ð 0r&   rÜ   c                  óV   € ] tR tRtRt]R 4       tRR ltR tR t	R t
RR	 ltR
 tRtR# )ÚRisingFactoriali÷  a´  
Rising factorial (also called Pochhammer symbol [1]_) is a double valued
function arising in concrete mathematics, hypergeometric functions
and series expansions. It is defined by:

.. math:: \texttt{rf(y, k)} = (x)^k = x \cdot (x+1) \cdots (x+k-1)

where `x` can be arbitrary expression and `k` is an integer. For
more information check "Concrete mathematics" by Graham, pp. 66
or visit https://mathworld.wolfram.com/RisingFactorial.html page.

When `x` is a `~.Poly` instance of degree $\ge 1$ with a single variable,
`(x)^k = x(y) \cdot x(y+1) \cdots x(y+k-1)`, where `y` is the
variable of `x`. This is as described in [2]_.

Examples
========

>>> from sympy import rf, Poly
>>> from sympy.abc import x
>>> rf(x, 0)
1
>>> rf(1, 5)
120
>>> rf(x, 5) == x*(1 + x)*(2 + x)*(3 + x)*(4 + x)
True
>>> rf(Poly(x**3, x), 2)
Poly(x**6 + 3*x**5 + 3*x**4 + x**3, x, domain='ZZ')

Rewriting is complicated unless the relationship between
the arguments is known, but rising factorial can
be rewritten in terms of gamma, factorial, binomial,
and falling factorial.

>>> from sympy import Symbol, factorial, ff, binomial, gamma
>>> n = Symbol('n', integer=True, positive=True)
>>> R = rf(n, n + 2)
>>> for i in (rf, ff, factorial, binomial, gamma):
...  R.rewrite(i)
...
RisingFactorial(n, n + 2)
FallingFactorial(2*n + 1, n + 2)
factorial(2*n + 1)/factorial(n - 1)
binomial(2*n + 1, n + 2)*factorial(n + 2)
gamma(2*n + 2)/gamma(n)

See Also
========

factorial, factorial2, FallingFactorial

References
==========

.. [1] https://en.wikipedia.org/wiki/Pochhammer_symbol
.. [2] Peter Paule, "Greatest Factorial Factorization and Symbolic
       Summation", Journal of Symbolic Computation, vol. 20, pp. 235-268,
       1995.

c                	óÒ  a€ \        S4      o\        V4      pS\        P                  J g   V\        P                  J d   \        P                  # S\        P                  J d   \	        V4      # VP
                  '       Ed   VP                  '       d   \        P                  # VP                  '       dî   S\        P                  J d   \        P                  # S\        P                  J d3   VP                  '       d   \        P                  # \        P                  # \        S\        4      '       dK   SP                  p\        V4      ^8w  d   \        R4      h\!        V3R l\#        \%        V4      4      ^4      # \!        V3R l\#        \%        V4      4      ^4      # S\        P                  J d   \        P                  # S\        P                  J d   \        P                  # \        S\        4      '       dc   SP                  p\        V4      ^8w  d   \        R4      h^\!        V3R l\#        ^\'        \%        V4      4      ^,           4      ^4      ,          # ^\!        V3R l\#        ^\'        \%        V4      4      ^,           4      ^4      ,          # VP(                  R8X  d9   SP(                  '       d%   SP*                  '       d   \        P,                  # R# R# R# )rd   ú0rf only defined for polynomials on one generatorc                ó4   <€ V SP                  V4      ,          # r»   ©Úshift©Úrr^   r˜   s   &&€r#   Ú<lambda>Ú&RisingFactorial.eval.<locals>.<lambda>Q  s   ø€ Ø./°·±¸³®nr&   c                ó$   <€ V SV,           ,          # r»   r'   rù   s   &&€r#   rû   rü   U  ó   ø€ °q¸!¸a½%¶yr&   c                ó6   <€ V SP                  V) 4      ,          # r»   r÷   rù   s   &&€r#   rû   rü   d  s   ø€ Ø01°1·7±7¸A¸2³;¶r&   c                ó$   <€ V SV,
          ,          # r»   r'   rù   s   &&€r#   rû   rü   h  s   ø€ Ø,-¨q°1­u®Ir&   FN)r   r   r¼   rS   r   rU   rR   rã   rT   ÚNegativeInfinityr¿   Ú
isinstancer   ÚgensÚlenrÞ   r   rX   r;   rs   rq   rV   ru   ©r?   r˜   rß   r  s   &f& r#   r`   ÚRisingFactorial.eval5  s,  ø€ ä�A‹JˆÜ�A‹Jˆà”—‘‹:˜œaŸe™e›Ü—5‘5ˆLØ”!—%‘%‹ZÜ˜Q“<ÐØ�\�\‰\Ø�y�yˆyÜ—u‘u�à—=—=�=ØœAŸJ™J“Ü Ÿz™zÐ)Øœa×0Ñ0Ó0ØŸ8Ÿ8˜8Ü#$×#5Ñ#5Ð5ä#$§:¡:Ð-ä% a¬×.Ò.Ø#$§6¡6˜DÜ" 4›y¨1œ}Ü&0ð 2Kó 'Lð !Lô (.ô /=ä.3´C¸³F«m¸Qó(@ð !@ô $*Ô*@Ü*/´°A³«-¸ó$<ð <ð œAŸJ™J“Ü Ÿz™zÐ)Øœa×0Ñ0Ó0Ü Ÿz™zÐ)ä% a¬×.Ò.Ø#$§6¡6˜DÜ" 4›y¨1œ}Ü&0ð 2Kó 'Lð !Lð ()¬ô 1@ä05°a¼¼SÀ»V»Àq½Ó0IÈ1ó*Nõ (Nð !Nð $%¤Vô -6ä,1°!´S¼¸Q»³[À1µ_Ó,EÀqó&Jõ $Jð Jð �<‰<˜5Ô Ø�|�|ˆ| §§ Ü—v‘v�ñ !.‰|ñ !r&   c                	óÞ  € ^ RI Hp ^ RIHp V'       gm   V^ 8*  R8X  dH   \        P
                  V,          V! ^V,
          4      ,          V! V) V,
          ^,           4      ,          # V! W,           4      V! V4      ,          # V! V! W,           4      V! V4      ,          V^ 8„  3\        P
                  V,          V! ^V,
          4      ,          V! V) V,
          ^,           4      ,          R34      # ©r   rí   r€   T©rð   rî   r2   r0   r   rÆ   ©r    r˜   rß   r‚   r!   rî   r0   s   &&&&,  r#   rƒ   Ú&RisingFactorial._eval_rewrite_as_gammap  s¸   € ÝBÝAßØ�Q‘˜4ÔÜ—}‘} aÕ'©¨a°!­e«Õ4±u¸a¸RÀ!½VÀa½ZÓ7HÕHÐHÙ˜�“<¡%¨£(Õ*Ð*ÙÙ�1•5‹\™E !›HÕ$ a¨!¡eÐ,Ü�]‰]˜AÕ™e A¨¥E›lÕ*©U°A°2¸µ6¸Aµ:Ó->Õ>ÀÐEóGð 	Gr&   c                	ó4   € \        W,           ^,
          V4      # rc   )ÚFallingFactorial©r    r˜   rß   r!   s   &&&,r#   Ú!_eval_rewrite_as_FallingFactorialÚ1RisingFactorial._eval_rewrite_as_FallingFactorial{  s   € Ü ¥¨¥	¨1Ó-Ð-r&   c                	óT  € ^ RI Hp VP                  '       d�   VP                  '       d|   V! \        W!,           ^,
          4      \        V^,
          4      ,          V^ 8„  3\        P
                  V,          \        V) 4      ,          \        V) V,
          4      ,          R34      # R# R# ©r   rí   TN©rð   rî   rq   r   r   rÆ   ©r    r˜   rß   r!   rî   s   &&&, r#   rÈ   Ú*RisingFactorial._eval_rewrite_as_factorial~  s}   € ÝBØ�<�<ˆ<˜AŸLŸL˜LÙÜ˜1�5 1�9Ó%¤i°°AµÓ&6Õ6¸¸A¹Ð>Ü—‘ Õ!¤)¨Q¨B£-Õ/´	¸1¸"¸q½&Ó0AÕAÀ4ÐHóJð Jñ )‰<r&   c                	ó|   € VP                   '       d*   \        V4      \        W,           ^,
          V4      ,          # R# )rd   N©rq   r   Úbinomialr  s   &&&,r#   Ú_eval_rewrite_as_binomialÚ)RisingFactorial._eval_rewrite_as_binomial…  s,   € Ø�<�<ˆ<Ü˜Q“<¤(¨1­5°1­9°aÓ"8Õ8Ð8ñ r&   Nc                	óú  € ^ RI Hp V'       dÍ   VP                  V\        P                  4      pV\        P                  J d-   V! W,           4      P                  RRR7      V! V4      ,          # V\        P                  J dY   \        P                  V,          V! ^V,
          4      ,          V! V) V,
          ^,           4      P                  RRR7      ,          # V P                  V4      P                  RRR7      # ©r   r€   Ú	tractableT)Údeep)r2   r0   r¥   r   rT   Úrewriter  rÆ   ©r    r˜   rß   Úlimitvarr!   r0   Úk_lims   &&&&,  r#   Ú_eval_rewrite_as_tractableÚ*RisingFactorial._eval_rewrite_as_tractable‰  s¼   € ÝAßØ—F‘F˜8¤Q§Z¡ZÓ0ˆEØœŸ
™
Ó"Ù˜a�e›×,Ñ,¨[¸tÐ,ÓDÁuÈQÃxÕOÐPØœ!×,Ñ,Ó,ÜŸ™ qÕ(©¨q°1­u«Õ5¹¸q¸bÀ1½fÀq½jÓ8I×8QÑ8QÐR]ÐdhÐ8QÓ8iÕiÐjØ�|‰|˜EÓ"×*Ñ*¨;¸TÐ*ÓBÐBr&   c                	óÀ   € \        V P                  ^ ,          P                  V P                  ^,          P                  V P                  ^,          P                  34      # ©r   ©r   r3   rq   rr   rŽ   s   &r#   r�   Ú RisingFactorial._eval_is_integer“  óE   € Ü˜$Ÿ)™) A�,×1Ñ1°4·9±9¸Qµ<×3JÑ3JØŸ)™) A�,×5Ñ5ð7ó 8ð 	8r&   r'   r®   r»   )r(   r)   r*   r+   r,   r°   r`   rƒ   r  rÈ   r  r#  r�   r-   r'   r&   r#   ró   ró   ÷  s>   † ñ;ðz ñ8ó ð8ôt	Gò.òJò9ôCö8r&   ró   c                  óV   € ] tR tRtRt]R 4       tRR ltR tR t	R t
RR	 ltR
 tRtR# )r  i˜  ap  
Falling factorial (related to rising factorial) is a double valued
function arising in concrete mathematics, hypergeometric functions
and series expansions. It is defined by

.. math:: \texttt{ff(x, k)} = (x)_k = x \cdot (x-1) \cdots (x-k+1)

where `x` can be arbitrary expression and `k` is an integer. For
more information check "Concrete mathematics" by Graham, pp. 66
or [1]_.

When `x` is a `~.Poly` instance of degree $\ge 1$ with single variable,
`(x)_k = x(y) \cdot x(y-1) \cdots x(y-k+1)`, where `y` is the
variable of `x`. This is as described in

>>> from sympy import ff, Poly, Symbol
>>> from sympy.abc import x
>>> n = Symbol('n', integer=True)

>>> ff(x, 0)
1
>>> ff(5, 5)
120
>>> ff(x, 5) == x*(x - 1)*(x - 2)*(x - 3)*(x - 4)
True
>>> ff(Poly(x**2, x), 2)
Poly(x**4 - 2*x**3 + x**2, x, domain='ZZ')
>>> ff(n, n)
factorial(n)

Rewriting is complicated unless the relationship between
the arguments is known, but falling factorial can
be rewritten in terms of gamma, factorial and binomial
and rising factorial.

>>> from sympy import factorial, rf, gamma, binomial, Symbol
>>> n = Symbol('n', integer=True, positive=True)
>>> F = ff(n, n - 2)
>>> for i in (rf, ff, factorial, binomial, gamma):
...  F.rewrite(i)
...
RisingFactorial(3, n - 2)
FallingFactorial(n, n - 2)
factorial(n)/2
binomial(n, n - 2)*factorial(n - 2)
gamma(n + 1)/2

See Also
========

factorial, factorial2, RisingFactorial

References
==========

.. [1] https://mathworld.wolfram.com/FallingFactorial.html
.. [2] Peter Paule, "Greatest Factorial Factorization and Symbolic
       Summation", Journal of Symbolic Computation, vol. 20, pp. 235-268,
       1995.

c                	óJ  a€ \        S4      o\        V4      pS\        P                  J g   V\        P                  J d   \        P                  # VP                  '       d   SV8X  d   \	        S4      # VP
                  '       Ed   VP                  '       d   \        P                  # VP                  '       dî   S\        P                  J d   \        P                  # S\        P                  J d3   VP                  '       d   \        P                  # \        P                  # \        S\        4      '       dK   SP                  p\        V4      ^8w  d   \!        R4      h\#        V3R l\%        \'        V4      4      ^4      # \#        V3R l\%        \'        V4      4      ^4      # S\        P                  J d   \        P                  # S\        P                  J d   \        P                  # \        S\        4      '       dc   SP                  p\        V4      ^8w  d   \!        R4      h^\#        V3R l\%        ^\)        \'        V4      4      ^,           4      ^4      ,          # ^\#        V3R l\%        ^\)        \'        V4      4      ^,           4      ^4      ,          # R# )rd   z0ff only defined for polynomials on one generatorc                ó6   <€ V SP                  V) 4      ,          # r»   r÷   rù   s   &&€r#   rû   Ú'FallingFactorial.eval.<locals>.<lambda>ó  s   ø€ Ø./°·±¸!¸³®or&   c                ó$   <€ V SV,
          ,          # r»   r'   rù   s   &&€r#   rû   r-  ÷  rþ   r&   rõ   c                ó4   <€ V SP                  V4      ,          # r»   r÷   rù   s   &&€r#   rû   r-    s   ø€ Ø01°1·7±7¸1³:¶r&   c                ó$   <€ V SV,           ,          # r»   r'   rù   s   &&€r#   rû   r-  	  s   ø€ ¸¸AÀ½E¾r&   N)r   r   r¼   rq   r   rU   rR   rS   rã   rT   r  r¿   r  r   r  r  rÞ   r   rX   r;   rs   r  s   &f& r#   r`   ÚFallingFactorial.eval×  sÿ  ø€ ä�A‹JˆÜ�A‹Jˆà”—‘‹:˜œaŸe™e›Ü—5‘5ˆLØ�\�\ˆ\˜a 1œfÜ˜Q“<ÐØ�\�\‰\Ø�y�yˆyÜ—u‘u�à—=—=�=ØœAŸJ™J“Ü Ÿz™zÐ)Øœa×0Ñ0Ó0ØŸ8Ÿ8˜8Ü#$×#5Ñ#5Ð5ä#$§:¡:Ð-ä% a¬×.Ò.Ø#$§6¡6˜DÜ" 4›y¨1œ}Ü&0ð 2Kó 'Lð !Lô (.ô />ä.3´C¸³F«m¸Qó(@ð !@ô $*Ô*@Ü*/´°A³«-¸ó$<ð <ð œAŸJ™J“Ü Ÿz™zÐ)Øœa×0Ñ0Ó0Ü Ÿz™zÐ)ä% a¬×.Ò.Ø#$§6¡6˜DÜ" 4›y¨1œ}Ü&0ð 2Kó 'Lð !Lð ()¬ô 1?ä05°a¼¼SÀ»V»Àq½Ó0IÈ1ó*Nõ (Nð !Nð $%¤VÔ,BÜ,1°!´S¼¸Q»³[À1µ_Ó,EÀqó&Jõ $Jð JñS r&   c                	óÚ  € ^ RI Hp ^ RIHp V'       gl   V^ 8  R8X  d9   \        P
                  V,          V! W!,
          4      ,          V! V) 4      ,          # V! V^,           4      V! W,
          ^,           4      ,          # V! V! V^,           4      V! W,
          ^,           4      ,          V^ 8¬  3\        P
                  V,          V! W!,
          4      ,          V! V) 4      ,          R34      # r  r	  r
  s   &&&&,  r#   rƒ   Ú'FallingFactorial._eval_rewrite_as_gamma  s±   € ÝBÝAßØ�A‘˜$ŒÜ—}‘} aÕ'©¨a­e«Õ4±u¸a¸R³yÕ@Ð@Ù˜˜Q�“<¡%¨­°­	Ó"2Õ2Ð2ÙÙ�1�q•5‹\™E !¥%¨!¥)Ó,Õ,¨a°1©fÐ5Ü�]‰]˜AÕ™e A¥E›lÕ*©U°A°2«YÕ6¸Ð=ó?ð 	?r&   c                	ó4   € \        W,
          ^,           V4      # rc   )Úrfr  s   &&&,r#   Ú _eval_rewrite_as_RisingFactorialÚ1FallingFactorial._eval_rewrite_as_RisingFactorial  s   € Ü�!•%˜!•)˜QÓÐr&   c                	ó`   € VP                   '       d   \        V4      \        W4      ,          # R # r»   r  r  s   &&&,r#   r  Ú*FallingFactorial._eval_rewrite_as_binomial  s#   € Ø�<�<ˆ<Ü˜Q“<¤(¨1£.Õ0Ð0ñ r&   c                	óT  € ^ RI Hp VP                  '       d�   VP                  '       d|   V! \        V4      \        V) V,           4      ,          V^ 8¬  3\        P
                  V,          \        W!,
          ^,
          4      ,          \        V) ^,
          4      ,          R34      # R# R# r  r  r  s   &&&, r#   rÈ   Ú+FallingFactorial._eval_rewrite_as_factorial  s}   € ÝBØ�<�<ˆ<˜AŸLŸL˜LÙÜ˜1“œi¨¨¨Q­Ó/Õ/°°a±Ð8Ü—‘ Õ!¤)¨A­E°A­IÓ"6Õ6´yÀ!ÀÀaÅÓ7HÕHÈ$ÐOóQð Qñ )‰<r&   Nc                	óø  € ^ RI Hp V'       dÌ   VP                  V\        P                  4      pV\        P                  J dJ   \        P
                  V,          V! W!,
          4      P                  RRR7      ,          V! V) 4      ,          # V\        P                  J d;   V! V^,           4      V! W,
          ^,           4      P                  RRR7      ,          # V P                  V4      P                  RRR7      # r  )r2   r0   r¥   r   rT   rÆ   r  r  r   s   &&&&,  r#   r#  Ú+FallingFactorial._eval_rewrite_as_tractable%  s¾   € ÝAßØ—F‘F˜8¤Q§Z¡ZÓ0ˆEØœŸ
™
Ó"ÜŸ™ qÕ(©¨q­u«×)=Ñ)=¸kÐPTÐ)=Ó)UÕUÑX]Ð_`Ð^`ÓXaÕaÐbØœ!×,Ñ,Ó,Ù˜a !�e›¡u¨Q­U°Q­YÓ'7×'?Ñ'?ÀÐRVÐ'?Ó'WÕWÐXØ�|‰|˜EÓ"×*Ñ*¨;¸TÐ*ÓBÐBr&   c                	óÀ   € \        V P                  ^ ,          P                  V P                  ^,          P                  V P                  ^,          P                  34      # r&  r'  rŽ   s   &r#   r�   Ú!FallingFactorial._eval_is_integer/  r)  r&   r'   r®   r»   )r(   r)   r*   r+   r,   r°   r`   rƒ   r6  r  rÈ   r#  r�   r-   r'   r&   r#   r  r  ˜  s?   † ñ<ð| ñ2Jó ð2Jôh	?ò ò1òQôCö8r&   r  c                  ó‚   € ] tR tRtRtRR lt]R 4       t]R 4       tR t	R t
R tRR	 ltRR ltR tR tR tR tRtR
# )r  i<  a 
  Implementation of the binomial coefficient. It can be defined
in two ways depending on its desired interpretation:

.. math:: \binom{n}{k} = \frac{n!}{k!(n-k)!}\ \text{or}\
            \binom{n}{k} = \frac{(n)_k}{k!}

First, in a strict combinatorial sense it defines the
number of ways we can choose `k` elements from a set of
`n` elements. In this case both arguments are nonnegative
integers and binomial is computed using an efficient
algorithm based on prime factorization.

The other definition is generalization for arbitrary `n`,
however `k` must also be nonnegative. This case is very
useful when evaluating summations.

For the sake of convenience, for negative integer `k` this function
will return zero no matter the other argument.

To expand the binomial when `n` is a symbol, use either
``expand_func()`` or ``expand(func=True)``. The former will keep
the polynomial in factored form while the latter will expand the
polynomial itself. See examples for details.

Examples
========

>>> from sympy import Symbol, Rational, binomial, expand_func
>>> n = Symbol('n', integer=True, positive=True)

>>> binomial(15, 8)
6435

>>> binomial(n, -1)
0

Rows of Pascal's triangle can be generated with the binomial function:

>>> for N in range(8):
...     print([binomial(N, i) for i in range(N + 1)])
...
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
[1, 5, 10, 10, 5, 1]
[1, 6, 15, 20, 15, 6, 1]
[1, 7, 21, 35, 35, 21, 7, 1]

As can a given diagonal, e.g. the 4th diagonal:

>>> N = -4
>>> [binomial(N, i) for i in range(1 - N)]
[1, -4, 10, -20, 35]

>>> binomial(Rational(5, 4), 3)
-5/128
>>> binomial(Rational(-5, 4), 3)
-195/128

>>> binomial(n, 3)
binomial(n, 3)

>>> binomial(n, 3).expand(func=True)
n**3/6 - n**2/2 + n/3

>>> expand_func(binomial(n, 3))
n*(n - 2)*(n - 1)/6

In many cases, we can also compute binomial coefficients modulo a
prime p quickly using Lucas' Theorem [2]_, though we need to include
`evaluate=False` to postpone evaluation:

>>> from sympy import Mod
>>> Mod(binomial(156675, 4433, evaluate=False), 10**5 + 3)
28625

Using a generalisation of Lucas's Theorem given by Granville [3]_,
we can extend this to arbitrary n:

>>> Mod(binomial(10**18, 10**12, evaluate=False), (10**5 + 3)**2)
3744312326

References
==========

.. [1] https://www.johndcook.com/blog/binomial_coefficients/
.. [2] https://en.wikipedia.org/wiki/Lucas%27s_theorem
.. [3] Binomial coefficients modulo prime powers, Andrew Granville,
    Available: https://web.archive.org/web/20170202003812/http://www.dms.umontreal.ca/~andrew/PDF/BinCoeff.pdf
c                	ód  € ^ RI Hp V^8X  dJ   V P                  w  r4\        W44      V! ^ V^,           4      V! ^ W4,
          ^,           4      ,
          ,          # V^8X  dJ   V P                  w  r4\        W44      V! ^ W4,
          ^,           4      V! ^ V^,           4      ,
          ,          # \	        W4      h)r   )r1   )r2   r1   r3   r  r   )r    r4   r1   r@   rß   s   &&   r#   r5   Úbinomial.fdiffš  sœ   € ÝEØ�qŒ=à—9‘9‰DˆAÜ˜A“>¡9¨Q°°AµÓ#6Ù˜!˜Q�U Q�YÓ'õ$(õ )ð )à˜Œ]à—9‘9‰DˆAÜ˜A“>¡9¨Q°µ¸µ	Ó#:Ù˜!˜Q �UÓ#õ$$õ %ð %ô % TÓ4Ð4r&   c                	óD  € VP                   '       Ed   VP                   '       dµ   V^ 8¼  d®   \        V4      \        V4      r!W!8”  d   \        P                  # W!^,          8”  d	   W,
          p\        e    \        \        P                  ! W4      4      # W,
          ^rC\        ^V^,           4       F  pV^,          pWC,          V,          pK  	  \        V4      # W,
          ^rC\        ^V^,           4       F  pV^,          pWC,          pK  	  V\        V4      ,          # R# r–   )	rU   r;   r   ru   rY   r   ÚbincoefrX   Ú
_factorial)r    r@   rß   ry   r]   r^   s   &&&   r#   r¸   Úbinomial._eval©  så   € ð �<�<‰<Ø�|�|ˆ|  Q¤Ü˜1“vœs 1›v�1à”5ÜŸ6™6�MØ˜a�”ZØ��Aô
 Ò$Ü"¤5§=¢=°Ó#6Ó7Ð7à�E 1�6Ü˜q ! a¥%ž�AØ˜•F�AØ#�Z¨1�_’Fñ )ô ˜v“Ð&à�E 1�6Ü˜q ! a¥%ž�AØ˜•F�AØ•K’Fñ )ð ¤
¨1£Õ-Ð-ñ3 r&   c                	ó†  € \        \        W34      w  rW,
          pVP                  VP                  rTVP                  '       g!   V'       g   VR J d#   VP                  '       d   \
        P                  # V^,
          P                  '       g(   V'       g   VR J d   V^,
          P                  '       d   V# VP                  '       d†   VP                  '       g#   V'       d+   V'       d#   VP                  '       d   \
        P                  # VP                  '       d.   V P                  W4      pV'       d   VP                  RR7      # T# R# VR J d   V'       d   \
        P                  # VP                  '       dD   ^ RIHp V! V^,           4      V! V^,           4      V! W,
          ^,           4      ,          ,          # R# )FT)Úbasicr€   N)rw   r   rr   rq   rR   r   rS   rV   ru   Ú	is_numberr¸   ÚexpandrW   r2   r0   )r?   r@   rß   ry   Ún_nonnegÚn_isintrg   r0   s   &&&     r#   r`   Úbinomial.evalÈ  s$  € ä”7˜Q˜FÓ#‰ˆØ�EˆØ×,Ñ,¨a¯l©l�'Ø�9�9ˆ9Ÿ( g°Ó&6Ø—I—I�IÜ—5‘5ˆLØ��E�?�?ˆ?§¨G°uÓ,<Ø˜•U—O—O�OØˆHØ�<�<ˆ<Ø�}�}ˆ}§¯g¸!¿-¿-¸-Ü—v‘v�Ø——�Ø—i‘i “o�ß14�s—z‘z¨�zÓ-Ð=¸#Ð=ñ ð ˜Ó§7ä×$Ñ$Ð$Ø�[�[ˆ[ÝEÙ˜˜Q�“<¡ q¨1¥u£©e°AµE¸AµIÓ.>Õ!>Õ?Ð?ñ r&   c                	ó  € V P                   w  r#\        ;QJ d    R  W#V3 4       F  '       g   K   RM	  RM! R  W#V3 4       4      '       d   \        R4      h\        ;QJ d    R W#V3 4       F  '       d   K   RM	  RM! R W#V3 4       4      '       Edó   \	        \
        W#34      w  r#\        V4      ^rTV^ 8  d   \        P                  # V^ 8  d%   V) V,           ^,
          pV^,          '       d   RM^pW28”  d   \        P                  # VP                  p\        V4      pV'       Ed)   WB8  dL   Y#r‡V'       g	   V'       d8   V\        Wt,          W„,          4      ,          V,          pWt,          W„,          r‡KG  EMùW#,
          p	W98”  d   Y“r“^p
\        ^V^,           4       F  pW«,          V,          p
K  	  T
p\        V^,           V	^,           4       F  pWË,          V,          pK  	  W\,          p\        V	^,           V^,           4       F  pW[,          V,          pK  	  V\        W¬,          V,          V^,
          V4      ,          pWT,          pEM"\        V4      V8  d   V^8w  d   \        W#V4      pMþ\        \        V4      4      p\        P                   ! ^V^,           4       FÈ  pWâV,
          8”  d   W^,          V,          pK!  Wâ^,          8”  d   K0  Wí8”  d'   W.,          W>,          8  d   W^,          V,          pKZ  K\  Y#r‡^ ;ppV^ 8”  d<   \        W~,          WŽ,          V,           8  4      pW~,          WŽ,          r‡VV,          pKB  V^ 8”  g   K­  V\        WïV4      ,          pWT,          pKÊ  	  \        WQ,          4      # R# )c              3  ó<   "  € T F  qP                   R J x € K  	  R# 5i)FN)rq   ©Ú.0r˜   s   & r#   Ú	<genexpr>Ú%binomial._eval_Mod.<locals>.<genexpr>ã  s   é € Ð8©i¨�|‰|˜uÕ$«iùs   ‚TFz"Integers expected for binomial Modc              3  ó8   "  € T F  qP                   x € K  	  R # 5ir»   )rU   rP  s   & r#   rR  rS  æ  s   é € Ð/¡Y �|Ž|£Yùs   ‚Nrp   )r3   ÚanyrÞ   Úallrw   r;   rs   r   ru   rv   r  rX   re   r<   r   r   r=   )r    rE   r@   rß   rx   rg   rz   rA   ÚKry   Úkfr^   ÚdfÚMrC   rË   Úas   &&               r#   r|   Úbinomial._eval_Modà  sË  € Ø�y‰y‰ˆç‹3Ñ8¨q°Q©iÓ8�3�3Š3Ñ8¨q°Q©iÓ8×8Ò8ÜÐAÓBÐBç‹3Ñ/ a¨A¡YÓ/�3�3Š3Ñ/ a¨A¡YÓ/×/Ó/Ü”s˜Q˜FÓ#‰DˆAÜ˜!“f˜a�ð �1ŒuÜ—v‘v�Ø�1ŒuØ�B˜•F˜Q•J�Ø˜aŸCœC‘b Q�ð ŒuÜ—v‘v�à—k‘kˆGÜ�R“ˆBßˆwØ”6à�qßŸqØ!¤(¨1­6°1µ6Ó":Õ:¸RÕ?˜Ø �w¨­š1ñ  !ð ��AØ”uØ ˜1Ø�BÜ" 1 a¨!¥ež_˜Ø�T B�Yšñ -à�BÜ" 1 q¥5¨!¨a­%Ö0˜Ø�T B�Yšñ 1à•I�CÜ" 1 q¥5¨!¨a­%Ö0˜Ø!�e b�jšñ 1ð œ3˜r�u r�z¨2°­6°2Ó6Õ6�CØ•I’Cä�q“˜A” ! q¤&Ü" 1¨Ó+‘ô œ˜a›“M�Ü"×-Ò-¨a°°QµÖ7�EØ 1�u”}Ø!�i¨"�nšØ a¥œÙ ØœØ�9 q¥yÔ0Ø"%¥)¨b¥.šCñ 1ð  !˜1Ø"#˜˜˜aà !œeÜ # Q¥Y°1µ9¸qµ=Ñ$AÓ B˜AØ#$¥:¨q­z˜qØ 1�HšCà ž7Ø¤3 u°2Ó#6Õ6˜CØ�IšCñ' 8ô* �S•W“:ÐñW 0r&   c                óV  € V P                   ^ ,          pVP                  '       d   \        V P                   !  # V P                   ^,          pW#,
          P                  '       d	   W#,
          pVP                  '       d›   VP                  '       d   \
        P                  # VP                  '       d   \
        P                  # V P                   ^ ,          ^rB\        ^V^,           4       F  pWBV,
          V,           ,          pK  	  V\        V4      ,          # \        V P                   !  # )z‡
Function to expand binomial(n, k) when m is positive integer
Also,
n is self.args[0] and k is self.args[1] while using binomial(n, k)
)r3   rQ   r  rU   rR   r   rS   rV   ru   rX   rE  )r    Úhintsr@   rß   r]   r^   s   &,    r#   Ú_eval_expand_funcÚbinomial._eval_expand_func3  sÉ   € ð �I‰I�a�LˆØ�;�;ˆ;Ü˜TŸY™YÑ'Ð'à�I‰I�a�LˆØ�C××ÐØ•ˆAà�<�<ˆ<Ø�y�yˆyÜ—u‘u�Ø——�Ü—v‘v�à ŸI™I a�L¨!�6Ü˜q ! a¥%ž�AØ !�e a�iÕ'’Fñ )à¤
¨1£Õ-Ð-ä˜TŸY™YÑ'Ð'r&   c                	ód   € \        V4      \        V4      \        W,
          4      ,          ,          # r»   )r   ©r    r@   rß   r!   s   &&&,r#   rÈ   Ú#binomial._eval_rewrite_as_factorialN  s!   € Ü˜‹|œY q›\¬)°AµEÓ*:Õ:Õ;Ð;r&   c                	óˆ   € ^ RI Hp V! V^,           4      V! V^,           4      V! W,
          ^,           4      ,          ,          # r   r�   )r    r@   rß   r‚   r!   r0   s   &&&&, r#   rƒ   Úbinomial._eval_rewrite_as_gammaQ  s0   € ÝAÙ�Q˜•U‹|™U 1 q¥5›\©%°µ¸µ	Ó*:Õ:Õ;Ð;r&   Nc                	óB   € V P                  W4      P                  R 4      # )r  )rƒ   r  )r    r@   rß   r!  r!   s   &&&&,r#   r#  Ú#binomial._eval_rewrite_as_tractableU  s   € Ø×*Ñ*¨1Ó0×8Ñ8¸ÓEÐEr&   c                	ó`   € VP                   '       d   \        W4      \        V4      ,          # R # r»   )rq   Úffr   rb  s   &&&,r#   r  Ú*binomial._eval_rewrite_as_FallingFactorialX  s#   € Ø�<�<ˆ<Ü�a“8œi¨›lÕ*Ð*ñ r&   c                	ó’   € V P                   w  rVP                  '       d   VP                  '       d   R # VP                  RJ d   R# R# ©TFN)r3   rq   ©r    r@   rß   s   &  r#   r�   Úbinomial._eval_is_integer\  s5   € Ø�y‰y‰ˆØ�<�<ˆ<˜AŸLŸL˜LÙØ�\‰\˜UÓ"Ùñ #r&   c                	ó  € V P                   w  rVP                  '       da   VP                  '       dM   VP                  '       g%   VP                  '       g   VP                  '       d   R # VP                  RJ d   R# R# R# R# rl  )r3   rq   rr   rV   rØ   rm  s   &  r#   rÕ   Úbinomial._eval_is_nonnegativec  sX   € Ø�y‰y‰ˆØ�<�<ˆ<˜AŸLŸL˜LØ××Ð 1§=§= =°A·I·I°IÙØ—‘˜eÓ#Ùñ $ñ )‰<r&   c                	óR   € ^ RI Hp V P                  V4      P                  WVR7      # )r   r€   )r¨   r©   )r2   r0   r  r¬   )r    r˜   r¨   r©   r0   s   &&&& r#   r¬   Úbinomial._eval_as_leading_termk  s$   € ÝAØ�|‰|˜EÓ"×8Ñ8¸ÈDÐ8ÓQÐQr&   r'   rc   r®   r»   )r(   r)   r*   r+   r,   r5   r°   r¸   r`   r|   r_  rÈ   rƒ   r#  r  r�   rÕ   r¬   r-   r'   r&   r#   r  r  <  si   † ñ[ôz5ð ñ.ó ð.ð< ñ@ó ð@ò.Qòf(ò6<ô<ôFò+òòöRr&   r  N)/Ú
__future__r   Ú	functoolsr   Ú
sympy.corer   r   r   r   Úsympy.core.cacher	   Úsympy.core.functionr
   r   r   Úsympy.core.logicr   Úsympy.core.numbersr   r   r   Úsympy.core.relationalr   Úsympy.external.gmpyr   rY   Úsympy.ntheoryr   Úsympy.ntheory.residue_ntheoryr   Úsympy.polys.polytoolsr   Úmathr   rE  r   r   r<   r   r²   r´   rÜ   ró   r  r5  ri  r  r'   r&   r#   Ú<module>r€     s¾   ðÝ "Ý ç -Ó -Ý $ß NÑ NÝ &ß -Ñ -Ý $Ý -Ý Ý 6Ý &ç =Ñ =ô˜Oô ô&s>Ð%ô s>ôj	Ð*ô 	ô_Ð(ô _ôDp0Ð&ô p0ôp^8Ð+ô ^8ôBY8Ð,ô Y8ðx €Ø€ôqRÐ$ö qRr&   