def clear_coefficients(expr, rhs=S.Zero):
 was = None
 free = expr.free_symbols
 if expr.is_Rational:
  return (S.Zero, (rhs - expr))
 while (expr and (was != expr)):
  was = expr
  (m, expr) = (expr.as_content_primitive() if free else factor_terms(expr).as_coeff_Mul(rational=True))
  rhs /= m
  (c, expr) = expr.as_coeff_Add(rational=True)
  rhs -= c
 expr = signsimp(expr, evaluate=False)
 if _coeff_isneg(expr):
  expr = (- expr)
  rhs = (- rhs)
 return (expr, rhs)

def clear_coefficients ( expr , rhs = S . Zero ) : was = None free = expr . free_symbols if expr . is_Rational : return ( S . Zero , ( rhs - expr ) ) while ( expr and ( was != expr ) ) : was = expr ( m , expr ) = ( expr . as_content_primitive ( ) if free else factor_terms ( expr ) . as_coeff_Mul ( rational = True ) ) rhs /= m ( c , expr ) = expr . as_coeff_Add ( rational = True ) rhs -= c expr = signsimp ( expr , evaluate = False ) if _coeff_isneg ( expr ) : expr = ( - expr ) rhs = ( - rhs ) return ( expr , rhs )
return p .