This code is not pretty at the moment! It's a working rewrite of the old code. The comments are all over the place and there is redundant code. However, there has been a considerate performance boost in the code. occurrences_in probably became faster with the stricter bounds on the predicates (which have also been removed in hopes of making the code prettier and more readable) and consecutive occurrences_in calls with the same permutations (whose occurrence is being searched for in another permutation) became faster due to caching of pre-computations.
This code is not pretty at the moment! It's a working rewrite of the old code. The comments are all over the place and there is redundant code. However, there has been a considerate performance boost in the code. occurrences_in probably became faster with the stricter bounds on the predicates (which have also been removed in hopes of making the code prettier and more readable) and consecutive occurrences_in calls with the same permutations (whose occurrence is being searched for in another permutation) became faster due to caching of pre-computations.

PermutaTriangle/Permuta