human
Complete this python program:
def collect(expr, syms, func=None, evaluate=None, exact=False, distribute_order_term=True):
assistant
#Here is the Python code you requested.

    """Collect additive terms of an expression.
    This function collects additive terms of an expression with respect
    to a list of expression up to powers with rational exponents. By the
    term symbol here are meant arbitrary expressions, which can contain
    powers, products, sums etc. In other words symbol is a pattern which
    will be searched for in the expression\s terms.
    The input expression is not expanded by :func:`collect`, so user is
    expected to provide an expression is an appropriate form. This makes
    :func:`collect` more predictable as there is no magic happening behind the
    scenes. However, it is important to note, that powers of products are
    converted to products of powers using the :func:`expand_power_base`
    function.
    There are two possible types of output. First, if ``evaluate`` flag is
    set, this function will return an expression with collected terms or
    else it will return a dictionary with expressions up to rational powers
    as keys and collected coefficients as values.
    Examples
    >>> from sympy import S, collect, expand, factor, Wild
    >>> from sympy.abc import a, b, c, x, y, z
    This function can collect symbolic coefficients in polynomials or
    rational expressions. It will manage to find all integer or rational
    powers of collection variable::
    >>> collect(a*x**2 + b*x**2 + a*x - b*x + c, x)
    c + x**2*(a + b) + x*(a - b)
    The same result can be achieved in dictionary form::
    >>> d = collect(a*x**2 + b*x**2 + a*x - b*x + c, x, evaluate=False)
    >>> d[x**2]
    a + b
    >>> d[x]
    a - b
    >>> d[S.One]
    c
    You can also work with multivariate polynomials. However, remember that
    this function is greedy so it will care only about a single symbol at time,
    in specification order::
    >>> collect(x**2 + y*x**2 + x*y + y + a*y, [x, y])
    x**2*(y + 1) + x*y + y*(a + 1)
    Also more complicated expressions can be used as patterns::
    >>> from sympy import sin, log
    >>> collect(a*sin(2*x) + b*sin(2*x),..."""
    if (evaluate is None):
        evaluate = global_evaluate[0]
    def make_expression(terms):
        product = []
        for (term, rat, sym, deriv) in terms:
            if (deriv is not None):
                (var, order) = deriv
                while (order > 0):
                    (term, order) = (Derivative(term, var), (order - 1))
            if (sym is None):
                if (rat is S.One):
                    product.append(term)
                else:
                    product.append(Pow(term, rat))
            else:
                product.append(Pow(term, (rat * sym)))
        return Mul(*product)
    def parse_derivative(deriv):
        (expr, sym, order) = (deriv.expr, deriv.variables[0], 1)
        for s in deriv.variables[1:]:
            if (s == sym):
                order += 1
            else:
                raise NotImplementedError('Improve    MV    Derivative    support    in    collect')
        while isinstance(expr, Derivative):
            s0 = expr.variables[0]
            for s in expr.variables:
                if (s != s0):
                    raise NotImplementedError('Improve    MV    Derivative    support    in    collect')
            if (s0 == sym):
                (expr, order) = (expr.expr, (order + len(expr.variables)))
            else:
                break
        return (expr, (sym, Rational(order)))
    def parse_term(expr):
        'Parses    expression    expr    and    outputs    tuple    (sexpr,    rat_expo,\n                                sym_expo,    deriv)\n                                where:\n                                    -    sexpr    is    the    base    expression\n                                    -    rat_expo    is    the    rational    exponent    that    sexpr    is    raised    to\n                                    -    sym_expo    is    the    symbolic    exponent    that    sexpr    is    raised    to\n                                    -    deriv    contains    the    derivatives    the    the    expression\n\n           ...