(eq, dep, others)
return [lhs, rhs]
Separate expression into two parts based on dependencies of variables.
Separate expression into two parts based on dependencies of variables.
Separate expression into two parts based on dependencies of variables .
def _separate(eq, dep, others):
    """Separate expression into two parts based on dependencies of variables."""

    # FIRST PASS
    # Extract derivatives depending our separable variable...
    terms = set()
    for term in eq.args:
        if term.is_Mul:
            for i in term.args:
                if i.is_Derivative and not i.has(*others):
                    terms.add(term)
                    continue
        elif term.is_Derivative and not term.has(*others):
            terms.add(term)
    # Find the factor that we need to divide by
    div = set()
    for term in terms:
        ext, sep = term.expand().as_independent(dep)
        # Failed?
        if sep.has(*others):
            return None
        div.add(ext)
    # FIXME: Find lcm() of all the divisors and divide with it, instead of
    # current hack :(
    # https://github.com/sympy/sympy/issues/4597
    if len(div) > 0:
        final = 0
        for term in eq.args:
            eqn = 0
            for i in div:
                eqn += term / i
            final += simplify(eqn)
        eq = final

    # SECOND PASS - separate the derivatives
    div = set()
    lhs = rhs = 0
    for term in eq.args:
        # Check, whether we have already term with independent variable...
        if not term.has(*others):
            lhs += term
            continue
        # ...otherwise, try to separate
        temp, sep = term.expand().as_independent(dep)
        # Failed?
        if sep.has(*others):
            return None
        # Extract the divisors
        div.add(sep)
        rhs -= term.expand()
    # Do the division
    fulldiv = reduce(operator.add, div)
    lhs = simplify(lhs/fulldiv).expand()
    rhs = simplify(rhs/fulldiv).expand()
    # ...and check whether we were successful :)
    if lhs.has(*others) or rhs.has(dep):
        return None
    return [lhs, rhs]
def _separate ( eq , dep , others ) : # FIRST PASS # Extract derivatives depending our separable variable... terms = set ( ) for term in eq . args : if term . is_Mul : for i in term . args : if i . is_Derivative and not i . has ( * others ) : terms . add ( term ) continue elif term . is_Derivative and not term . has ( * others ) : terms . add ( term ) # Find the factor that we need to divide by div = set ( ) for term in terms : ext , sep = term . expand ( ) . as_independent ( dep ) # Failed? if sep . has ( * others ) : return None div . add ( ext ) # FIXME: Find lcm() of all the divisors and divide with it, instead of # current hack :( # https://github.com/sympy/sympy/issues/4597 if len ( div ) > 0 : final = 0 for term in eq . args : eqn = 0 for i in div : eqn += term / i final += simplify ( eqn ) eq = final # SECOND PASS - separate the derivatives div = set ( ) lhs = rhs = 0 for term in eq . args : # Check, whether we have already term with independent variable... if not term . has ( * others ) : lhs += term continue # ...otherwise, try to separate temp , sep = term . expand ( ) . as_independent ( dep ) # Failed? if sep . has ( * others ) : return None # Extract the divisors div . add ( sep ) rhs -= term . expand ( ) # Do the division fulldiv = reduce ( operator . add , div ) lhs = simplify ( lhs / fulldiv ) . expand ( ) rhs = simplify ( rhs / fulldiv ) . expand ( ) # ...and check whether we were successful :) if lhs . has ( * others ) or rhs . has ( dep ) : return None return [ lhs , rhs ]