I'm trying to examine some patterns on the permutation of elements in finite element functions. I'd like to create a list of all functions (256 of them) on 4 elements.

For example

{{(a, b), (b, c), (c, c), (d, a)}, {(a, c), (b, d), (c, c), (d, a)}, ... }

In all the methods I have tried I keep getting non-functional elements, i.e. things like

{{(a, b), (a, c), (c, d), (d, a)}, ... }

Any suggestions as for an easy way to do this?

  • 1
    $\begingroup$ You might want to look here $\endgroup$ – Sektor Mar 25 '15 at 15:54
  • $\begingroup$ What method have you tried such that you're getting 'non-functional' elements? $\endgroup$ – 2012rcampion Mar 25 '15 at 16:41
  • $\begingroup$ Your "code" is not Mathematica-compatible. Would you mind fixing the round brackets? $\endgroup$ – Jinxed Mar 25 '15 at 16:41
  • $\begingroup$ Also, let me check that I understand you correctly: you're trying to generate all mappings from the set {a, b, c, d} onto itself? $\endgroup$ – 2012rcampion Mar 25 '15 at 16:42
  • $\begingroup$ @2012rcampion yes, exactly: your answer below was exactly what I was looking for. $\endgroup$ – Bradford Mar 26 '15 at 1:45

Try this:

set = {a, b, c, d};
maps = Thread[set -> #] & /@ Tuples[set, {Length[set]}]

If you want all permutations (one-to-one mappings from set onto set) replace Tuples with Permutations[set].

  • $\begingroup$ This is great. And indeed, I was not looking for just 1-1 mappings. Thanks so much. Much better than other options using nests of combinations etc. Thanks again. $\endgroup$ – Bradford Mar 26 '15 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.