permutation rewrite