(A, B)
return distribute_rl
Turns an A containing Bs into a B of As

    where A, B are container types

    >>> from sympy.strategies import distribute
    >>> from sympy import Add, Mul, symbols
    >>> x, y = symbols('x,y')
    >>> dist = distribute(Mul, Add)
    >>> expr = Mul(2, x+y, evaluate=False)
    >>> expr
    2*(x + y)
    >>> dist(expr)
    2*x + 2*y
Turns an A containing Bs into a B of As
Turns an A containing Bs into a B of As
def distribute(A, B):
    """ Turns an A containing Bs into a B of As

    where A, B are container types

    >>> from sympy.strategies import distribute
    >>> from sympy import Add, Mul, symbols
    >>> x, y = symbols('x,y')
    >>> dist = distribute(Mul, Add)
    >>> expr = Mul(2, x+y, evaluate=False)
    >>> expr
    2*(x + y)
    >>> dist(expr)
    2*x + 2*y
    """

    def distribute_rl(expr):
        for i, arg in enumerate(expr.args):
            if isinstance(arg, B):
                first, b, tail = expr.args[:i], expr.args[i], expr.args[i+1:]
                return B(*[A(*(first + (arg,) + tail)) for arg in b.args])
        return expr
    return distribute_rl
def distribute ( A , B ) : def distribute_rl ( expr ) : for i , arg in enumerate ( expr . args ) : if isinstance ( arg , B ) : first , b , tail = expr . args [ : i ] , expr . args [ i ] , expr . args [ i + 1 : ] return B ( * [ A ( * ( first + ( arg , ) + tail ) ) for arg in b . args ] ) return expr return distribute_rl