ó
    ‰*£h™  ã                  ó|  • S SK Jr  S SKJr  S SKJrJrJrJr  S SK	J
r
  S SKJrJrJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJr  S S
KJr  S SKJr  S SKJr  S SK J!r"J#r#J$r%   " S S\5      r& " S S\&5      r! " S S\&5      r' " S S\&5      r( " S S\&5      r) " S S\&5      r* " S S\&5      r+\*r,\+r- " S S\&5      r.g)é    )Úannotations)Úreduce)ÚSÚsympifyÚDummyÚMod)Úcacheit)ÚDefinedFunctionÚArgumentIndexErrorÚ	PoleError)Ú	fuzzy_and)ÚIntegerÚpiÚI)ÚEq)Úgmpy)Úsieve)Úbinomial_mod)ÚPoly)Ú	factorialÚprodÚsqrtc                  ó   • \ rS rSrSrS rSrg)ÚCombinatorialFunctioné   z(Base class for combinatorial functions. c                ó`   • SSK Jn  U" U 5      nUS   nU" U5      US   U" U 5      -  ::  a  U$ U $ )Nr   )ÚcombsimpÚmeasureÚratio)Úsympy.simplify.combsimpr   )ÚselfÚkwargsr   Úexprr   s        Úe/home/mande/repo/quber/.venv/lib/python3.13/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                  óª   • \ rS rSr% SrSS jr/ SQr/ rS\S'   \	S 5       r
\	S 5       r\	S	 5       rS
 rS rSS jrS rS rS rS rS rS rS rSrg)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                ó˜   • SSK JnJn  US:X  a2  U" U R                  S   S-   5      U" SU R                  S   S-   5      -  $ [	        X5      e)Nr   )ÚgammaÚ	polygammaé   )Ú'sympy.functions.special.gamma_functionsr2   r3   Úargsr   )r!   Úargindexr2   r3   s       r$   ÚfdiffÚfactorial.fdiffU   sH   € ßNØ�q‹=Ù˜Ÿ™ 1™¨Ñ)Ó*©9°Q¸¿	¹	À!¹ÀqÑ8HÓ+IÑIÐIä$ TÓ4Ð4r'   )!r4   r4   r4   é   r:   é   é   é#   r=   i;  é?   iµ  éç   i»  i­  é#  r@   iS« i{/  i!† im´  iñÌ isX iUò iÇP
 ioãikÖ iI�i/„L iSùªi}î“ é#áérA   z	list[int]Ú_small_factorialsc                ó  • US:  a  U R                   U   $ [        [        U5      5      / p2[        R                  " SUS-   5       H;  nSUpe Xd-  nUS:”  a  US-  S:X  a  XT-  nOOM  US:”  d  M*  UR                  U5        M=     [        R                  " US-   US-  S-   5       H!  nX-  S-  S:X  d  M  UR                  U5        M#     [        [        R                  " US-  S-   US-   5      5      n[        U5      nXx-  $ )Né!   r:   r4   r   é   )Ú_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                ób   • US:  a  gU R                  US-  5      S-  U R                  U5      -  $ )NrE   r4   )Ú
_recursiverT   )rK   rL   s     r$   rW   Úfactorial._recursiveƒ   s1   € àˆq‹5Øà—N‘N 1 a¡4Ó(¨!Ñ+¨S¯Z©Z¸«]Ñ:Ð:r'   c                ó¸  • [        U5      nUR                  (       Ga=  UR                  (       a  [        R                  $ U[        R
                  L a  [        R
                  $ UR                  (       aç  UR                  (       a  [        R                  $ UR                  nUS:  aX  U R                  (       d4  Sn[        SS5       H"  nX#-  nU R                  R                  U5        M$     U R                  US-
     nOQ[        b  [        R                  " U5      nO3[        U5      R!                  S5      nU R#                  U5      SX-
  -  -  n[%        U5      $ g g )Né   r4   Ú1rE   )r   Ú	is_NumberÚis_zeror   ÚOneÚInfinityÚ
is_IntegerÚis_negativeÚComplexInfinityrP   rB   ÚrangerJ   Ú_gmpyÚfacÚbinÚcountrW   r   )rK   rL   ÚresultÚiÚbitss        r$   ÚevalÚfactorial.evalŠ   s  € ä�A‹Jˆà�;�;ˆ;Ø�y�yÜ—u‘u�Ø”a—j‘j’Ü—z‘zÐ!Ø——Ø—=—=Ü×,Ñ,Ð,àŸ™�Aà˜2“vØ"×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                óŠ  • S[        [        U5      5      pCS/U-  nSn[        R                  " SUS-   5       HK  nUS:”  a  SX-  p†U(       a  Xh-  nX‡-  nU(       a  M  Xd:  a  XV   U-  U-  XV'   M9  U[	        XvU5      -  U-  nMM     [        U5       H-  u  pšU	S:X  d  U
S:X  a  M  U
S:X  a    gU[	        X©U5      -  U-  nM/     U$ )Nr4   rE   r   )rG   rH   r   rI   ÚpowÚ	enumerate)r!   rL   rQ   ÚresrM   ÚpwÚmrO   ÚyÚexÚbss              r$   Ú_facmodÚfactorial._facmod³   sÜ   € Ø”Cœ˜a›“MˆQð ˆS�‰UˆàˆÜ×%Ò% a¨¨Q©Ö/ˆEØ�1‹uØ˜!™*�1ÞØ‘F�AØ‘K�A÷ �að ‹uØ™˜e™ a™�“àœ#˜e¨Ó*Ñ*¨QÑ.’ñ 0ô   –m‰FˆBØ�Q‹w˜" ›'ÙØ�Q‹wÙØ”c˜" !“nÑ$ qÑ(ŠCñ $ð ˆ
r'   c                óª  • U R                   S   nUR                  (       Ga2  UR                  (       Ga  UR                  (       Ga  [        U5      nX2-
  nUR                  (       a  [
        R                  $ UR                  nUS:X  a7  U(       a  SU-  $ USL a%  US-
  R                  (       a  [
        R                  $ g g UR                  (       a�  UR                  (       ao  [        [        X$U45      u  p$nU(       a>  US-
  U:  a5  U R                  US-
  U5      n[        XcS-
  U5      nUS-  (       a  U* nXa-  $ U R                  X#5      nXa-  $ g g g g g )Nr   r4   éÿÿÿÿFé   rE   )r6   Ú
is_integerÚis_nonnegativeÚabsÚis_nonpositiver   ÚZeroÚis_primer`   ÚmaprG   rv   rn   )r!   rQ   rL   Ú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Ü Ÿv™v˜ð /FÐ)à—\—\ a§l§lÜ"¤3¨¨r¨
Ó3‘H�A˜"Þ A¨¡E¨A£IØ!Ÿ\™\¨!¨a©%°Ó4˜Ü  ¨!¡V¨RÓ0˜Ø˜QŸ3Ø"$ ˜Bð ™6�Mð "Ÿ\™\¨!Ó0˜à™6�Mð '3�\ð! 2>Ð,ˆ<r'   c                ó$   • SSK Jn  U" US-   5      $ ©Nr   ©r2   r4   ©r5   r2   )r!   rL   Ú	piecewiser"   r2   s        r$   Ú_eval_rewrite_as_gammaÚ factorial._eval_rewrite_as_gammaï   s   € ÝAÙ�Q˜‘U‹|Ðr'   c                ó€   • SSK Jn  UR                  (       a'  UR                  (       a  [	        SSS9nU" XDSU45      $ g g )Nr   )ÚProductri   T)Úintegerr4   )Úsympy.concrete.productsr�   r|   r{   r   )r!   rL   r"   r�   ri   s        r$   Ú_eval_rewrite_as_ProductÚ"factorial._eval_rewrite_as_Productó   s9   € Ý3Ø×× §§Ü�c 4Ñ(ˆAÙ˜1 ! Q˜iÓ(Ð(ð !-Ðr'   c                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g ©Nr   T©r6   r{   r|   ©r!   s    r$   Ú_eval_is_integerÚfactorial._eval_is_integerù   ó/   € Ø�9‰9�Q‰<×"×" t§y¡y°¡|×'B×'BØð (CÐ"r'   c                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g r–   r—   r˜   s    r$   Ú_eval_is_positiveÚfactorial._eval_is_positiveý   r›   r'   c                ó†   • U R                   S   nUR                  (       a!  UR                  (       a  US-
  R                  $ g g )Nr   rE   r—   ©r!   Úxs     r$   Ú_eval_is_evenÚfactorial._eval_is_even  ó5   € Ø�I‰I�a‰LˆØ�<�<˜A×,×,Ø˜‘E×)Ñ)Ð)ð -ˆ<r'   c                ó†   • U R                   S   nUR                  (       a!  UR                  (       a  US-
  R                  $ g g )Nr   r:   r—   r    s     r$   Ú_eval_is_compositeÚfactorial._eval_is_composite  r¤   r'   c                óh   • U R                   S   nUR                  (       d  UR                  (       a  gg r–   )r6   r|   Úis_nonintegerr    s     r$   Ú_eval_is_realÚfactorial._eval_is_real  s&   € Ø�I‰I�a‰LˆØ××˜qŸŸØð  /r'   c                ó  • U R                   S   R                  U5      nUR                  US5      nUR                  (       a  [        R
                  $ UR                  (       d  U R                  U5      $ [        SU -  5      e)Nr   zCannot expand %s around 0)	r6   Úas_leading_termÚsubsr]   r   r^   Úis_infiniteÚfuncr   )r!   r¡   ÚlogxÚcdirÚargÚarg0s         r$   Ú_eval_as_leading_termÚfactorial._eval_as_leading_term  sa   € Ø�i‰i˜‰l×*Ñ*¨1Ó-ˆØ�x‰x˜˜1‹~ˆØ�<�<Ü—5‘5ˆLØ×!×!Ø—9‘9˜S“>Ð!ÜÐ3°tÑ<Ó=Ð=r'   r(   N©r4   ©T)r)   r*   r+   r,   r-   r8   rF   rB   Ú__annotations__ÚclassmethodrT   rW   rk   rv   r†   r�   r“   r™   r�   r¢   r¦   rª   rµ   r.   r(   r'   r$   r   r   $   sŽ   ‡ ñ.ô`5ò€Lð $&Ð�yÓ%àñ'ó ð'ð< ñ;ó ð;ð ñ&+ó ð&+òPò<"ô<ò)òòò*ò
*ò
õ
>r'   r   c                  ó   • \ rS rSrSrg)ÚMultiFactoriali  r(   N)r)   r*   r+   r,   r.   r(   r'   r$   r¼   r¼     s   † Úr'   r¼   c                  óp   • \ rS rSrSr\\S 5       5       r\S 5       rS r	S r
S rSS jrS	 rS
 rS rSrg)Ú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                ó¨   • U(       d  [         R                  $ US:X  a  [         R                  $ Su  p#[        SUS-   5       H  nX4S-
  X2-   -  p2M     U$ )Nr4   )r4   r   rE   )r   r^   r   rc   )r!   rL   Úz1Úz2ri   s        r$   Ú_evalÚsubfactorial._evalG  sP   € ö Ü—5‘5ˆLØ�!‹VÜ—6‘6ˆMà‰FˆBÜ˜1˜a !™e–_�Ø !™e b¡gÑ.’Bñ %àˆIr'   c                ó  • UR                   (       az  UR                  (       a"  UR                  (       a  U R                  U5      $ U[        R
                  L a  [        R
                  $ U[        R                  L a  [        R                  $ g g ©N)r\   r`   r|   rÂ   r   ÚNaNr_   )rK   r³   s     r$   rk   Úsubfactorial.evalT  sZ   € à�=�=Ø�~�~ #×"4×"4Ø—y‘y “~Ð%ØœŸ™’Ü—u‘u�ØœŸ
™
Ò"Ü—z‘zÐ!ð #ð r'   c                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g r–   )r6   Úis_oddr|   r˜   s    r$   r¢   Úsubfactorial._eval_is_even^  s.   € Ø�9‰9�Q‰<×× 4§9¡9¨Q¡<×#>×#>Øð $?Ðr'   c                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g r–   r—   r˜   s    r$   r™   Úsubfactorial._eval_is_integerb  r›   r'   c                ó�   • SSK Jn  [        S5      n[        R                  U-  [        U5      -  n[        U5      U" XTSU45      -  $ )Nr   )Ú	summationri   )Úsympy.concrete.summationsrÎ   r   r   ÚNegativeOner   )r!   r³   r"   rÎ   ri   Úfs         r$   Ú_eval_rewrite_as_factorialÚ'subfactorial._eval_rewrite_as_factorialf  s?   € Ý7Ü�#‹JˆÜ�M‰M˜1Ñœy¨›|Ñ+ˆÜ˜‹~¡	¨!°°C¨[Ó 9Ñ9Ð9r'   c                ó¾   • SSK Jn  SSKJnJn  [
        R                  US-   -  U" [        * [        -  U-  5      -  U" US-   S5      -  U" US-   5      -   U" S5      -  $ )Nr   )Úexp)r2   Ú
lowergammar4   ry   )	Ú&sympy.functions.elementary.exponentialrÕ   r5   r2   rÖ   r   rÐ   r   r   )r!   r³   rŒ   r"   rÕ   r2   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                óH   • SSK Jn  U" US-   S5      [        R                  -  $ )Nr   )Ú
uppergammar4   ry   )r5   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                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g r–   r—   r˜   s    r$   Ú_eval_is_nonnegativeÚ!subfactorial._eval_is_nonnegativev  r›   r'   c                ó€   • U R                   S   R                  (       a   U R                   S   R                  (       a  gg g r–   )r6   Úis_evenr|   r˜   s    r$   Ú_eval_is_oddÚsubfactorial._eval_is_oddz  s/   € Ø�9‰9�Q‰<×× D§I¡I¨a¡L×$?×$?Øð %@Ðr'   r(   Nr¸   )r)   r*   r+   r,   r-   rº   r	   rÂ   rk   r¢   r™   rÒ   r�   rÜ   rß   rã   r.   r(   r'   r$   r¾   r¾     s[   † ñ'ðR Øñ	ó ó ð	ð ñ"ó ð"òòò:ô*ò.òõr'   r¾   c                  óJ   • \ rS rSrSr\S 5       rS rS rS r	S r
SS jrS	rg
)Ú
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                óŒ  • UR                   (       a³  UR                  (       d  [        S5      eUR                  (       aA  UR                  (       a  US-  nSU-  [        U5      -  $ [        U5      [        US-
  5      -  $ UR                  (       a)  U[        R                  SU-
  S-  -  -  [        U* 5      -  $ [        S5      eg )Nz<argument must be nonnegative integer or negative odd integerrE   r4   )
r\   r`   Ú
ValueErrorr|   râ   r   ræ   rÉ   r   rÐ   )rK   r³   Úks      r$   rk   Úfactorial2.eval¥  s²   € ð �=�=Ø—>—>Ü ð ">ó ?ð ?ð
 ×!×!Ø—;—;Ø˜a™�AØ˜a™4¤)¨A£,Ñ.Ð.Ü  “~¬
°3¸±7Ó(;Ñ;Ð;ð �z�zØœAŸM™M¨a°#©g°q©[Ñ9Ñ9¼JÈÀtÓ<LÑLÐLÜð :ó ;ð ;ð! r'   c                óÖ   • U R                   S   nUR                  (       aI  UR                  (       a  gUR                  (       a%  UR                  (       a  gUR
                  (       a  gg g g )Nr   FT)r6   r{   rÉ   râ   Úis_positiver]   ©r!   rL   s     r$   r¢   Úfactorial2._eval_is_even½  sJ   € à�I‰I�a‰LˆØ�<�<Ø�x�xØØ�y�yØ—=—=ØØ—9—9Ø ð ð ð r'   c                ó°   • U R                   S   nUR                  (       a6  US-   R                  (       a  gUR                  (       a  US-   R                  $ g g )Nr   r4   Tr:   )r6   r{   r|   rÉ   rí   s     r$   r™   Úfactorial2._eval_is_integerÉ  sI   € ð �I‰I�a‰LˆØ�<�<Ø�A‘×%×%ØØ�x�xØ˜A™×-Ñ-Ð-ð ð r'   c                óÎ   • U R                   S   nUR                  (       a  US-   R                  $ UR                  (       a%  UR                  (       a  gUR
                  (       a  gg g )Nr   r:   FT)r6   rÉ   r|   râ   rì   r]   rí   s     r$   rã   Úfactorial2._eval_is_oddÓ  sM   € ð �I‰I�a‰LˆØ�8�8Ø˜‘E×)Ñ)Ð)Ø�9�9Ø�}�}ØØ�y�yØð ð r'   c                ó¶   • U R                   S   nUR                  (       a9  US-   R                  (       a  gUR                  (       a  US-   S-  R                  $ g g )Nr   r4   TrE   )r6   r{   r|   rÉ   râ   rí   s     r$   r�   Úfactorial2._eval_is_positiveß  sM   € ð �I‰I�a‰LˆØ�<�<Ø�A‘×%×%ØØ�x�xØ˜Q™ !™×,Ñ,Ð,ð ð r'   c                óÚ   • SSK Jn  SSKJn  SSKJn  SUS-  -  U" US-  S-   5      -  U" S[        [        US5      S5      4U" S[        -  5      [        [        US5      S5      45      -  $ )Nr   )r   ©Ú	PiecewiserŠ   rE   r4   )	Ú(sympy.functions.elementary.miscellaneousr   Ú$sympy.functions.elementary.piecewiser÷   r5   r2   r   r   r   )r!   rL   rŒ   r"   r   r÷   r2   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º   rk   r¢   r™   rã   r�   r�   r.   r(   r'   r$   ræ   ræ     s5   † ñ#ðJ ñ;ó ð;ò.
!ò.ò
ò	-÷0r'   ræ   c                  óT   • \ rS rSrSr\S 5       rSS jrS rS r	S r
SS	 jrS
 rSrg)Ú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                óˆ  ^• [        T5      m[        U5      nT[        R                  L d  U[        R                  L a  [        R                  $ T[        R                  L a  [	        U5      $ UR
                  (       Ga  UR                  (       a  [        R                  $ UR                  (       aè  T[        R                  L a  [        R                  $ T[        R                  L a1  UR                  (       a  [        R                  $ [        R                  $ [        T[        5      (       aI  TR                  n[        U5      S:w  a  [        S5      e[!        U4S j[#        [%        U5      5      S5      $ [!        U4S j[#        [%        U5      5      S5      $ T[        R                  L a  [        R                  $ T[        R                  L a  [        R                  $ [        T[        5      (       aY  TR                  n[        U5      S:w  a  [        S5      eS[!        U4S j[#        S['        [%        U5      5      S-   5      S5      -  $ S[!        U4S j[#        S['        [%        U5      5      S-   5      S5      -  $ UR(                  S:X  a4  TR(                  (       a"  TR*                  (       a  [        R,                  $ g g g )Nr4   ú0rf only defined for polynomials on one generatorc                ó,   >• U TR                  U5      -  $ rÅ   ©Úshift©Úrri   r¡   s     €r$   Ú<lambda>Ú&RisingFactorial.eval.<locals>.<lambda>Q  s   ø€ Ø./°·±¸³ªnr'   c                ó   >• U TU-   -  $ rÅ   r(   r  s     €r$   r  r  U  ó   ø€ °q¸!¸a¹%²yr'   c                ó.   >• U TR                  U* 5      -  $ rÅ   r   r  s     €r$   r  r  d  s   ø€ Ø01°1·7±7¸A¸2³;²r'   c                ó   >• U TU-
  -  $ rÅ   r(   r  s     €r$   r  r  h  s   ø€ Ø,-¨q°1©uªIr'   F)r   r   rÆ   r^   r   r`   r]   rì   r_   ÚNegativeInfinityrÉ   Ú
isinstancer   ÚgensÚlenrè   r   rc   rG   r}   r{   ra   r   ©rK   r¡   ré   r  s    `  r$   rk   ÚRisingFactorial.eval5  s"  ø€ ä�A‹JˆÜ�A‹Jˆà”—‘Š:˜œaŸe™ešÜ—5‘5ˆLØ”!—%‘%ŠZÜ˜Q“<ÐØ�\�\ˆ\Ø�y�yÜ—u‘u�à—=—=ØœAŸJ™J’Ü Ÿz™zÐ)Øœa×0Ñ0Ò0ØŸ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                óZ  • SSK Jn  SSKJn  U(       dK  US:*  S:X  a/  [        R
                  U-  U" SU-
  5      -  U" U* U-
  S-   5      -  $ U" X-   5      U" U5      -  $ U" U" X-   5      U" U5      -  US:„  4[        R
                  U-  U" SU-
  5      -  U" U* U-
  S-   5      -  S45      $ ©Nr   rö   rŠ   Tr4   ©rù   r÷   r5   r2   r   rÐ   ©r!   r¡   ré   rŒ   r"   r÷   r2   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                ó$   • [        X-   S-
  U5      $ ©Nr4   )ÚFallingFactorial©r!   r¡   ré   r"   s       r$   Ú!_eval_rewrite_as_FallingFactorialÚ1RisingFactorial._eval_rewrite_as_FallingFactorial{  s   € Ü ¡¨¡	¨1Ó-Ð-r'   c                ó  • SSK Jn  UR                  (       am  UR                  (       a[  U" [        X!-   S-
  5      [        US-
  5      -  US:„  4[        R
                  U-  [        U* 5      -  [        U* U-
  5      -  S45      $ g g ©Nr   rö   r4   T©rù   r÷   r{   r   r   rÐ   ©r!   r¡   ré   r"   r÷   s        r$   rÒ   Ú*RisingFactorial._eval_rewrite_as_factorial~  sy   € ÝBØ�<�<˜AŸLŸLÙÜ˜1™5 1™9Ó%¤i°°A±Ó&6Ñ6¸¸A¹Ð>Ü—‘ Ñ!¤)¨Q¨B£-Ñ/´	¸1¸"¸q¹&Ó0AÑAÀ4ÐHóJð Jð )ˆ<r'   c                ó`   • UR                   (       a  [        U5      [        X-   S-
  U5      -  $ g r  ©r{   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                ó¢  • SSK Jn  U(       a¤  UR                  U[        R                  5      nU[        R                  L a!  U" X-   5      R                  SSS9U" U5      -  $ U[        R                  L a=  [        R                  U-  U" SU-
  5      -  U" U* U-
  S-   5      R                  SSS9-  $ U R                  U5      R                  SSS9$ ©Nr   rŠ   Ú	tractableT)Údeepr4   )r5   r2   r®   r   r_   Úrewriter
  rÐ   ©r!   r¡   ré   Úlimitvarr"   r2   Ú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                ó¨   • [        U R                  S   R                  U R                  S   R                  U R                  S   R                  45      $ ©Nr   r4   ©r   r6   r{   r|   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º   rk   r�   r  rÒ   r#  r-  r™   r.   r(   r'   r$   rü   rü   ÷  s>   † ñ;ðz ñ8ó ð8ôt	Gò.òJò9ôCõ8r'   rü   c                  óT   • \ rS rSrSr\S 5       rSS jrS rS r	S r
SS	 jrS
 rSrg)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                ó  ^• [        T5      m[        U5      nT[        R                  L d  U[        R                  L a  [        R                  $ UR                  (       a  TU:X  a  [	        T5      $ UR
                  (       Ga  UR                  (       a  [        R                  $ UR                  (       aè  T[        R                  L a  [        R                  $ T[        R                  L a1  UR                  (       a  [        R                  $ [        R                  $ [        T[        5      (       aI  TR                  n[        U5      S:w  a  [!        S5      e[#        U4S j[%        ['        U5      5      S5      $ [#        U4S j[%        ['        U5      5      S5      $ T[        R                  L a  [        R                  $ T[        R                  L a  [        R                  $ [        T[        5      (       aY  TR                  n[        U5      S:w  a  [!        S5      eS[#        U4S j[%        S[)        ['        U5      5      S-   5      S5      -  $ S[#        U4S j[%        S[)        ['        U5      5      S-   5      S5      -  $ g )Nr4   z0ff only defined for polynomials on one generatorc                ó.   >• U TR                  U* 5      -  $ rÅ   r   r  s     €r$   r  Ú'FallingFactorial.eval.<locals>.<lambda>ó  s   ø€ Ø./°·±¸!¸³ªor'   c                ó   >• U TU-
  -  $ rÅ   r(   r  s     €r$   r  r7  ÷  r  r'   rþ   c                ó,   >• U TR                  U5      -  $ rÅ   r   r  s     €r$   r  r7    s   ø€ Ø01°1·7±7¸1³:²r'   c                ó   >• U TU-   -  $ rÅ   r(   r  s     €r$   r  r7  	  s   ø€ ¸¸AÀ¹Eºr'   )r   r   rÆ   r{   r   r`   r]   r^   rì   r_   r
  rÉ   r  r   r  r  rè   r   rc   rG   r}   r  s    `  r$   rk   ÚFallingFactorial.eval×  s÷  ø€ ä�A‹JˆÜ�A‹Jˆà”—‘Š:˜œaŸe™ešÜ—5‘5ˆLØ�\�\˜a 1›fÜ˜Q“<ÐØ�\�\ˆ\Ø�y�yÜ—u‘u�à—=—=ØœAŸJ™J’Ü Ÿz™zÐ)Øœa×0Ñ0Ò0ØŸ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                óV  • SSK Jn  SSKJn  U(       dJ  US:  S:X  a(  [        R
                  U-  U" X!-
  5      -  U" U* 5      -  $ U" US-   5      U" X-
  S-   5      -  $ U" U" US-   5      U" X-
  S-   5      -  US:¬  4[        R
                  U-  U" X!-
  5      -  U" U* 5      -  S45      $ 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                ó$   • [        X-
  S-   U5      $ r  )Úrfr  s       r$   Ú _eval_rewrite_as_RisingFactorialÚ1FallingFactorial._eval_rewrite_as_RisingFactorial  s   € Ü�!‘%˜!‘)˜QÓÐr'   c                óT   • UR                   (       a  [        U5      [        X5      -  $ g rÅ   r!  r  s       r$   r#  Ú*FallingFactorial._eval_rewrite_as_binomial  s!   € Ø�<�<Ü˜Q“<¤(¨1£.Ñ0Ð0ð r'   c                ó  • SSK Jn  UR                  (       am  UR                  (       a[  U" [        U5      [        U* U-   5      -  US:¬  4[        R
                  U-  [        X!-
  S-
  5      -  [        U* S-
  5      -  S45      $ g g r  r  r  s        r$   rÒ   Ú+FallingFactorial._eval_rewrite_as_factorial  sy   € ÝBØ�<�<˜AŸLŸLÙÜ˜1“œi¨¨¨Q©Ó/Ñ/°°a±Ð8Ü—‘ Ñ!¤)¨A©E°A©IÓ"6Ñ6´yÀ!ÀÀaÁÓ7HÑHÈ$ÐOóQð Qð )ˆ<r'   Nc                ó   • SSK Jn  U(       a£  UR                  U[        R                  5      nU[        R                  L a6  [        R
                  U-  U" X!-
  5      R                  SSS9-  U" U* 5      -  $ U[        R                  L a'  U" US-   5      U" X-
  S-   5      R                  SSS9-  $ U R                  U5      R                  SSS9$ r&  )r5   r2   r®   r   r_   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                ó¨   • [        U R                  S   R                  U R                  S   R                  U R                  S   R                  45      $ r0  r1  r˜   s    r$   r™   Ú!FallingFactorial._eval_is_integer/  r3  r'   r(   r¸   rÅ   )r)   r*   r+   r,   r-   rº   rk   r�   r@  r#  rÒ   r-  r™   r.   r(   r'   r$   r  r  ˜  s?   † ñ<ð| ñ2Jó ð2Jôh	?ò ò1òQôCõ8r'   r  c                  ó€   • \ rS rSrSrSS jr\S 5       r\S 5       rS r	S r
S rSS	 jrSS jrS rS rS rS rSrg
)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                ó  • SSK Jn  US:X  a5  U R                  u  p4[        X45      U" SUS-   5      U" SX4-
  S-   5      -
  -  $ US:X  a5  U R                  u  p4[        X45      U" SX4-
  S-   5      U" SUS-   5      -
  -  $ [	        X5      e)Nr   )r3   r4   rE   )r5   r3   r6   r"  r   )r!   r7   r3   rL   ré   s        r$   r8   Ú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                óÔ  • UR                   (       a×  UR                   (       a”  US:¼  aŽ  [        U5      [        U5      p!X!:”  a  [        R                  $ X!S-  :”  a  X-
  n[        b  [        [        R                  " X5      5      $ X-
  SpC[        SUS-   5       H  nUS-  nXC-  U-  nM     [        U5      $ X-
  SpC[        SUS-   5       H  nUS-  nXC-  nM     U[        U5      -  $ g )Nr   rE   r4   )	r`   rG   r   r   rd   r   Úbincoefrc   Ú
_factorial)r!   rL   ré   rƒ   rh   ri   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                ó  • [        [        X45      u  pX-
  nUR                  UR                  pTUR                  (       d  U(       d  USL a!  UR                  (       a  [
        R                  $ US-
  R                  (       d   U(       d  USL a  US-
  R                  (       a  U$ UR                  (       a{  UR                  (       d  U(       a(  U(       a!  UR                  (       a  [
        R                  $ UR                  (       a)  U R                  X5      nU(       a  UR                  SS9$ U$ g USL a  U(       a  [
        R                  $ UR                  (       a+  SSKJn  U" US-   5      U" US-   5      U" X-
  S-   5      -  -  $ g )NFr4   T)Úbasicr   rŠ   )r�   r   r|   r{   r]   r   r^   ra   r   Ú	is_numberrÂ   Úexpandrb   r5   r2   )rK   rL   ré   rƒ   Ún_nonnegÚn_isintrp   r2   s           r$   rk   Úbinomial.evalÈ  s  € ä”7˜Q˜FÓ#‰ˆØ‰EˆØ×,Ñ,¨a¯l©l�'Ø�9�9ž( g°Ò&6Ø—I—IÜ—5‘5ˆLØ�‰E�?�?¦¨G°uÒ,<Ø˜‘U—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                ó  • U R                   u  p#[        S X#U4 5       5      (       a  [        S5      e[        S X#U4 5       5      (       GaA  [	        [
        X#45      u  p#[        U5      SpTUS:  a  [        R                  $ US:  a  U* U-   S-
  nUS-  (       a  SOSnX2:”  a  [        R                  $ UR                  n[        U5      nU(       aÓ  XB:  aA  X#p‡U(       d  U(       a/  U[        Xt-  X„-  5      -  U-  nXt-  X„-  p‡U(       a  M&  U(       a  M/  GOiX#-
  n	X9:”  a  X“p“Sn
[        SUS-   5       H
  nX«-  U-  n
M     U
n[        US-   U	S-   5       H
  nXË-  U-  nM     X\-  n[        U	S-   US-   5       H
  nX[-  U-  nM     U[        X¬-  U-  US-
  U5      -  nXT-  nOÜ[        U5      U:  a  US:w  a  [        X#U5      nOº[        [        U5      5      n[        R                   " SUS-   5       Hˆ  nXâU-
  :”  a	  X^-  U-  nM  XâS-  :”  a  M  Xí:”  a  X.-  X>-  :  a	  X^-  U-  nM6  M8  X#p‡S=nnUS:”  a)  [        X~-  XŽ-  U-   :  5      nX~-  XŽ-  p‡UU-  nUS:”  a  M)  US:”  d  Mu  U[        XïU5      -  nXT-  nMŠ     [        XQ-  5      $ g )Nc              3  ó<   #   • U  H  oR                   S L v •  M     g7f)FN)r{   ©Ú.0r¡   s     r$   Ú	<genexpr>Ú%binomial._eval_Mod.<locals>.<genexpr>ã  s   é € Ð8ªi¨�|‰|˜uÕ$ªiùs   ‚z"Integers expected for binomial Modc              3  ó8   #   • U  H  oR                   v •  M     g 7frÅ   )r`   rZ  s     r$   r\  r]  æ  s   é € Ð/¢Y �|Ž|¢Yùs   ‚r4   r   rE   ry   )r6   Úanyrè   Úallr�   rG   r}   r   r   r€   r"  rc   rn   rH   r   r   rI   )r!   rQ   rL   ré   r‚   rp   r„   rM   ÚKrƒ   Úkfri   ÚdfÚMrO   rÕ   Úas                    r$   r†   Úbinomial._eval_Modà  s±  € Ø�y‰y‰ˆäÑ8¨q°Q©iÓ8×8Ñ8ÜÐAÓBÐBäÑ/ a¨A¡YÓ/×/Ò/Ü”s˜Q˜FÓ#‰DˆAÜ˜!“f˜a�ð �1‹uÜ—v‘v�Ø�1‹uØ�B˜‘F˜Q‘J�Ø˜aŸC‘b Q�ð ‹uÜ—v‘v�à—k‘kˆGÜ�R“ˆBÞØ“6à�qÞžqØ!¤(¨1©6°1±6Ó":Ñ:¸RÑ?˜Ø ™w¨©˜1÷ ˜!Ÿq˜qùð ™�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ð   !�eð
  �7Ø¤3 u°2Ó#6Ñ6˜CØ™IšCñ' 8ô* �S‘W“:ÐðW 0r'   c                óø  • U R                   S   nUR                  (       a  [        U R                   6 $ U R                   S   nX#-
  R                  (       a  X#-
  nUR                  (       a€  UR                  (       a  [
        R                  $ UR                  (       a  [
        R                  $ U R                   S   SpB[        SUS-   5       H  nXBU-
  U-   -  nM     U[        U5      -  $ [        U R                   6 $ )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)
r   r4   )r6   r\   r"  r`   r]   r   r^   ra   r   rc   rO  )r!   ÚhintsrL   ré   rh   ri   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Ü—u‘u�Ø——Ü—v‘v�à ŸI™I a™L¨!�6Ü˜q ! a¡%ž�AØ !™e a™iÑ'’Fñ )à¤
¨1£Ñ-Ð-ä˜TŸY™YÐ'Ð'r'   c                óL   • [        U5      [        U5      [        X-
  5      -  -  $ rÅ   )r   ©r!   rL   ré   r"   s       r$   rÒ   Ú#binomial._eval_rewrite_as_factorialN  s!   € Ü˜‹|œY q›\¬)°A±EÓ*:Ñ:Ñ;Ð;r'   c                óX   • SSK Jn  U" US-   5      U" US-   5      U" X-
  S-   5      -  -  $ r‰   r‹   )r!   rL   ré   rŒ   r"   r2   s         r$   r�   Úbinomial._eval_rewrite_as_gammaQ  s0   € ÝAÙ�Q˜‘U‹|™U 1 q¡5›\©%°±¸±	Ó*:Ñ:Ñ;Ð;r'   Nc                óB   • U R                  X5      R                  S5      $ )Nr'  )r�   r)  )r!   rL   ré   r+  r"   s        r$   r-  Ú#binomial._eval_rewrite_as_tractableU  s   € Ø×*Ñ*¨1Ó0×8Ñ8¸ÓEÐEr'   c                óT   • UR                   (       a  [        X5      [        U5      -  $ g rÅ   )r{   Úffr   rl  s       r$   r  Ú*binomial._eval_rewrite_as_FallingFactorialX  s!   € Ø�<�<Ü�a“8œi¨›lÑ*Ð*ð r'   c                ó†   • U R                   u  pUR                  (       a  UR                  (       a  gUR                  SL a  gg ©NTF)r6   r{   ©r!   rL   ré   s      r$   r™   Úbinomial._eval_is_integer\  s1   € Ø�y‰y‰ˆØ�<�<˜AŸLŸLØØ�\‰\˜UÒ"Øð #r'   c                óð   • U R                   u  pUR                  (       aW  UR                  (       aE  UR                  (       d"  UR                  (       d  UR                  (       a  gUR                  SL a  gg g g rv  )r6   r{   r|   ra   râ   rw  s      r$   rß   Úbinomial._eval_is_nonnegativec  sM   € Ø�y‰y‰ˆØ�<�<˜AŸLŸLØ×× 1§=§=°A·I·IØØ—‘˜eÒ#Øð $ð )ˆ<r'   c                óL   • SSK Jn  U R                  U5      R                  XUS9$ )Nr   rŠ   )r±   r²   )r5   r2   r)  rµ   )r!   r¡   r±   r²   r2   s        r$   rµ   Úbinomial._eval_as_leading_termk  s$   € ÝAØ�|‰|˜EÓ"×8Ñ8¸ÈDÐ8ÐQÐQr'   r(   r·   r¸   rÅ   )r)   r*   r+   r,   r-   r8   rº   rÂ   rk   r†   ri  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   rd   Úsympy.ntheoryr   Úsympy.ntheory.residue_ntheoryr   Úsympy.polys.polytoolsr   Úmathr   rO  r   r   rH   r   r¼   r¾   ræ   rü   r  r?  rs  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'   