Fundamental Patterns

by Chris Korda

It's well-known that the number of permutations for a set of size N is N factorial. We will show that most of these permutations are transformations of a much smaller subset of patterns called prime forms. For N=4 there are 24 permutations, but only three prime forms, and they are:

A

[0 1 2 3]

ramp

B

[0 1 3 2]

alternating skips

C

[0 2 1 3]

ascending skips

Each of these prime forms has eight transformations, as shown below: four by cyclic rotation, and another four by cyclic rotation of the reversed pattern.

A

[0 1 2 3] [1 2 3 0] [2 3 0 1] [3 0 1 2]

cyclic rotation to the left

[3 2 1 0] [2 1 0 3] [1 0 3 2] [0 3 2 1]

reversal and cyclic rotation

B

[0 1 3 2] [1 3 2 0] [3 2 0 1] [2 0 1 3]

cyclic rotation to the left

[2 3 1 0] [3 1 0 2] [1 0 2 3] [0 2 3 1]

reversal and cyclic rotation

C

[0 2 1 3] [2 1 3 0] [1 3 0 2] [3 0 2 1]

cyclic rotation to the left

[3 1 2 0] [1 2 0 3] [2 0 3 1] [0 3 1 2]

reversal and cyclic rotation

Thus 24 permutations are reduced to a mere three patterns. The number of prime forms M for a set of size N is given by N! / (N × 2).

N

N!

M

3

6

1

4

24

3

5

120

12

6

720

60

A method for obtaining the prime forms for a given set size N is described below.

The method requires a hashing function that converts every permutation of the set to a unique integer. The function interprets the permutation as a base N number and tightly packs its digits. More succinctly, the function sums Di×N(N−i−1) for i=[0..N−1]. For example the set [1 0 3 2] is hashed to the value 78:

1×43+0×42+3×41+2×40 = 1×64×0×16+3×4+2×1 = 64+0+12+2 = 78

Using this hashing function, we can convert any given permutation of the set to its prime form. This is done by generating all the rotations and reversed rotations and hashing each of them. The transformation that produces the smallest hash is the prime form.

Now iterate through all the permutations of the given set. For each permutation, convert it to its prime form, and if that prime form hasn’t been encountered before, add it to a list. At the end of the iteration, the list contains all of the prime forms for a set of size N.

A prime form pattern can be conceptualized as a series of N intervals which generate the values [0..N−1] in a characteristic sequence. To obtain the intervals, compute the absolute difference between each pair of adjacent elements. For example, here are the prime forms and their intervals for N=4:

Pattern

Intervals

Vector

A

0 1 2 3

1 1 1 3

<301>

B

0 1 3 2

1 2 1 2

<220>

C

0 2 1 3

2 1 2 3

<121>

The vector column above is analogous to the interval vector used in musical set theory. It’s read from left to right. The leftmost element is the count of steps of size one, the next element is the count of steps of size two, and so on. The pattern [0 1 2 3] contains three steps of size one, no steps of size two, and a single step of size three, hence its interval vector is <301>. All of the transformations of a prime form have the same interval vector.

The twelve prime forms for N=5 along with their interval vectors are shown below. Multiple prime forms can share the same interval vector, and in such cases the prime forms are related.

Pattern

Vector

Related to

A

0 1 2 3 4

<4001>

B

0 1 2 4 3

<3110>

C

0 1 3 2 4

<2201>

D

0 1 3 4 2

<2300>

E

0 1 4 2 3

<2120>

F

0 1 4 3 2

<3110>

B

G

0 2 1 3 4

<2201>

C

H

0 2 1 4 3

<2120>

E

I

0 2 3 1 4

<1211>

J

0 2 4 1 3

<0320>

K

0 3 1 2 4

<1211>

 I

L

0 3 2 1 4

<2021>