

def product_simplify(s):
    'Main function for Product simplification'
    from sympy.concrete.products import Product
    terms = Mul.make_args(s)
    p_t = []
    o_t = []
    for term in terms:
        if isinstance(term, Product):
            p_t.append(term)
        else:
            o_t.append(term)
    used = ([False] * len(p_t))
    for method in range(2):
        for (i, p_term1) in enumerate(p_t):
            if (not used[i]):
                for (j, p_term2) in enumerate(p_t):
                    if ((not used[j]) and (i != j)):
                        if isinstance(product_mul(p_term1, p_term2, method), Product):
                            p_t[i] = product_mul(p_term1, p_term2, method)
                            used[j] = True
    result = Mul(*o_t)
    for (i, p_term) in enumerate(p_t):
        if (not used[i]):
            result = Mul(result, p_term)
    return result

dataset/ETHPy150Open sympy/sympy/sympy/simplify/simplify.py product_simplify/original