Chain entanglements. I. Theory