

def _separatevars_dict(expr, symbols):
    if symbols:
        if (not all((t.is_Atom for t in symbols))):
            raise ValueError('symbols must be Atoms.')
        symbols = list(symbols)
    elif (symbols is None):
        return {
            'coeff': expr,
        }
    else:
        symbols = list(expr.free_symbols)
        if (not symbols):
            return None
    ret = dict(((i, []) for i in (symbols + ['coeff'])))
    for i in Mul.make_args(expr):
        expsym = i.free_symbols
        intersection = set(symbols).intersection(expsym)
        if (len(intersection) > 1):
            return None
        if (len(intersection) == 0):
            ret['coeff'].append(i)
        else:
            ret[intersection.pop()].append(i)
    for (k, v) in ret.items():
        ret[k] = Mul(*v)
    return ret

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