

def multinomial_coefficients_iterator(m, n, _tuple=tuple):
    'multinomial coefficient iterator\n\n    This routine has been optimized for `m` large with respect to `n` by taking\n    advantage of the fact that when the monomial tuples `t` are stripped of\n    zeros, their coefficient is the same as that of the monomial tuples from\n    ``multinomial_coefficients(n, n)``. Therefore, the latter coefficients are\n    precomputed to save memory and time.\n\n    >>> from sympy.ntheory.multinomial import multinomial_coefficients\n    >>> m53, m33 = multinomial_coefficients(5,3), multinomial_coefficients(3,3)\n    >>> m53[(0,0,0,1,2)] == m53[(0,0,1,0,2)] == m53[(1,0,2,0,0)] == m33[(0,1,2)]\n    True\n\n    Examples\n    ========\n\n    >>> from sympy.ntheory.multinomial import multinomial_coefficients_iterator\n    >>> it = multinomial_coefficients_iterator(20,3)\n    >>> next(it)\n    ((3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 1)\n    '
    if ((m < (2 * n)) or (n == 1)):
        mc = multinomial_coefficients(m, n)
        for (k, v) in mc.items():
            (yield (k, v))
    else:
        mc = multinomial_coefficients(n, n)
        mc1 = {
            
        }
        for (k, v) in mc.items():
            mc1[_tuple(filter(None, k))] = v
        mc = mc1
        t = ([n] + ([0] * (m - 1)))
        t1 = _tuple(t)
        b = _tuple(filter(None, t1))
        (yield (t1, mc[b]))
        if n:
            j = 0
        else:
            j = m
        while (j < (m - 1)):
            tj = t[j]
            if j:
                t[j] = 0
                t[0] = tj
            if (tj > 1):
                t[(j + 1)] += 1
                j = 0
            else:
                j += 1
                t[j] += 1
            t[0] -= 1
            t1 = _tuple(t)
            b = _tuple(filter(None, t1))
            (yield (t1, mc[b]))

dataset/ETHPy150Open sympy/sympy/sympy/ntheory/multinomial.py multinomial_coefficients_iterator/original