
    \h                     .    S SK Jr  S rS rS r\4S jrg)    )as_intc                     [        U 5      n SU 4SU S4S0nSn[        SU S-  S-   5       H!  nX U-
  S-   -  U-  nU=XX-
  4'   XU-
  U4'   M#     U$ )a  Return a dictionary containing pairs :math:`{(k1,k2) : C_kn}` where
:math:`C_kn` are binomial coefficients and :math:`n=k1+k2`.

Examples
========

>>> from sympy.ntheory import binomial_coefficients
>>> binomial_coefficients(9)
{(0, 9): 1, (1, 8): 9, (2, 7): 36, (3, 6): 84,
 (4, 5): 126, (5, 4): 126, (6, 3): 84, (7, 2): 36, (8, 1): 9, (9, 0): 1}

See Also
========

binomial_coefficients_list, multinomial_coefficients
r         r   rangendaks       Q/var/www/auris/envauris/lib/python3.13/site-packages/sympy/ntheory/multinomial.pybinomial_coefficientsr      sx    " 	q	A
QQFAA	A1adQha%!)_q $%%QU(aAqk   H    c                     [        U 5      n S/U S-   -  nSn[        SU S-  S-   5       H  nX U-
  S-   -  U-  nU=X'   XU-
  '   M     U$ )a#  Return a list of binomial coefficients as rows of the Pascal's
triangle.

Examples
========

>>> from sympy.ntheory import binomial_coefficients_list
>>> binomial_coefficients_list(9)
[1, 9, 36, 84, 126, 126, 84, 36, 9, 1]

See Also
========

binomial_coefficients, multinomial_coefficients
r   r   r   r	   s       r   binomial_coefficients_listr      sg      	q	A	
q1uA	A1adQha%!)_q qQx   Hr   c                    [        U 5      n [        U5      nU (       d  U(       a  0 $ SS0$ U S:X  a  [        U5      $ U SU-  :  a  US:  a  [        [        X5      5      $ U/S/U S-
  -  -   n[	        U5      S0nU(       a  SnOU nX@S-
  :  a  X$   nU(       a  SX$'   XRS'   US:  a  X$S-   ==   S-  ss'   SnSnSnO$US-  nUS-   nU[	        U5         nX$==   S-  ss'   [        X`5       H6  nX(   (       d  M  X(==   S-  ss'   Xs[	        U5         -  nX(==   S-  ss'   M8     US==   S-  ss'   Xu-  XS   -
  -  U[	        U5      '   X@S-
  :  a  M  U$ )a  Return a dictionary containing pairs ``{(k1,k2,..,km) : C_kn}``
where ``C_kn`` are multinomial coefficients such that
``n=k1+k2+..+km``.

Examples
========

>>> from sympy.ntheory import multinomial_coefficients
>>> multinomial_coefficients(2, 5) # indirect doctest
{(0, 5): 1, (1, 4): 5, (2, 3): 10, (3, 2): 10, (4, 1): 5, (5, 0): 1}

Notes
=====

The algorithm is based on the following result:

.. math::
    \binom{n}{k_1, \ldots, k_m} =
    \frac{k_1 + 1}{n - k_1} \sum_{i=2}^m \binom{n}{k_1 + 1, \ldots, k_i - 1, \ldots}

Code contributed to Sage by Yann Laigle-Chapuy, copied with permission
of the author.

See Also
========

binomial_coefficients_list, binomial_coefficients
 r   r   r   )r   r   dict!multinomial_coefficients_iteratortupler   )	mr
   trjtjstartvr   s	            r   multinomial_coefficientsr   7   sv   : 	q	Aq	AIAwAv$Q''AaCxAE5a;<<	
qcQUmA	q1A
!e)TADaD6!eHMHAEAFAEE%(ADAID uAtt	uQx[ 		 !
 	
!	v1t8,%(1 !e)2 Hr   c           	   #     #    [        U 5      n [        U5      nU SU-  :  d  US:X  a$  [        X5      nUR                  5        Sh  vN   g[        X5      n0 nUR                  5        H  u  pVXdU" [        SU5      5      '   M     UnU/S/U S-
  -  -   nU" U5      nU" [        SU5      5      n	XU	   4v   U(       a  Sn
OU n
XS-
  :  av  Xz   nU
(       a  SXz'   XS'   US:  a  XzS-   ==   S-  ss'   Sn
OU
S-  n
Xz==   S-  ss'   US==   S-  ss'   U" U5      nU" [        SU5      5      n	XU	   4v   XS-
  :  a  Mu  gg N7f)a1  multinomial coefficient iterator

This routine has been optimized for `m` large with respect to `n` by taking
advantage of the fact that when the monomial tuples `t` are stripped of
zeros, their coefficient is the same as that of the monomial tuples from
``multinomial_coefficients(n, n)``. Therefore, the latter coefficients are
precomputed to save memory and time.

>>> from sympy.ntheory.multinomial import multinomial_coefficients
>>> m53, m33 = multinomial_coefficients(5,3), multinomial_coefficients(3,3)
>>> m53[(0,0,0,1,2)] == m53[(0,0,1,0,2)] == m53[(1,0,2,0,0)] == m33[(0,1,2)]
True

Examples
========

>>> from sympy.ntheory.multinomial import multinomial_coefficients_iterator
>>> it = multinomial_coefficients_iterator(20,3)
>>> next(it)
((3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 1)
r   r   Nr   )r   r   itemsfilter)r   r
   _tuplemcmc1r   r   r   t1br   r   s               r   r   r      sX    , 	q	Aq	A1Q3w!q&%a+88:%a+HHJDA+,vdA'( C1#Q-AY6$#$a5kAAa%iB!Ava%AQ	aDAIDBvdB'(A!u+! a%i# 	s   AEEC7E EN)sympy.utilities.miscr   r   r   r   r   r   r   r   r   <module>r)      s#    '42GT 49 ;r   