K i,ddlmZdZdZdZefdZy))as_intct|}d|fd|dfdi}d}td|dzdzD]$}|||z dzz|z}|x||||z f<|||z |f<&|S)aReturn 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 rrrangendaks _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/ntheory/multinomial.pybinomial_coefficientsrs" q A QQFAA A 1adQh & !a%!)_q $%%!QU( aAqk& Hct|}dg|dzz}d}td|dzdzD]}|||z dzz|z}|x||<|||z <|S)aL 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 rrrr s rbinomial_coefficients_listrsr q A q1u A A 1adQh  !a%!)_q !qQx Hrct|}t|}|s|riSddiS|dk(r t|S|d|zk\r|dkDrtt||S|gdg|dz zz}t |di}|rd}n|}||dz kr||}|r d||<||d<|dkDr||dzxxdz cc<d}d}d}n%|dz }|dz}|t |}||xxdz cc<t ||D]3}||s ||xxdzcc<||t |z }||xxdz cc<5|dxxdzcc<||z||dz z|t |<||dz kr|S)aReturn 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 rrr)rrdict!multinomial_coefficients_iteratortupler) mr trjtjstartvr s rmultinomial_coefficientsr7s: q Aq A IAwAv$Q''AaCxAE5a;<< qcQUmA q1 A   a!e) qT AaDAaD 6 a!eHMHAEA FAEE%( A aDAIDua At! QuQx[ !    ! 2v1qt8,%( 1 a!e)2 Hrc #Kt|}t|}|d|zks|dk(r%t||}|jEd{yt||}i}|jD]\}}|||td|<|}|gdg|dz zz}||}|td|} ||| f|rd} n|} | |dz kru|| } | r d|| <| |d<| dkDr|| dzxxdz cc<d} n| dz } || xxdz cc<|dxxdzcc<||}|td|} ||| f| |dz krtyy7w)aqmultinomial 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) rrNr)rritemsfilter) rr _tuplemcmc1r rrt1brrs rrrsx, q Aq A1Q3w!q& %a +88: %a +HHJ -DAq+,CvdA' ( -  C1#Q-  AY 6$# $2a5k AA!a%i1B!!Av!a%A Q!  aDAIDBvdB'(Ar!u+ !!a%i# sAD?D=C4D?;D?N)sympy.utilities.miscrrrrrrrrrr)s#' 4 2G T49;r