implement mathematical permutation