Collapsing sorted logic