b OR a AND b OR c AND a # first, add parentheses for better disambiguation: (b) OR (a AND b) OR (c AND a) # now, sort the AND terms alphabetically, exploiting # the commutativity of AND (b) OR (a AND b) OR (a AND c) # sort the outer terms alphabetically, exploiting # the commutativity of OR (a AND b) OR (a AND c) OR (b) # this is the conjunctive normal form (I think)