Permutations in Matlab and Octave

Both Matlab and Octave come equipped with a built-in function, perms(), designed to calculate permutations of a set of elements.

perms(array)

This function enables the generation of all permutations for a vector of \( n \) numbers, outputting a matrix where each row represents a different permutation.

Additionally, it provides an indirect means to explore the concept of symmetric groups within Matlab.

Note: The symmetric group \( S_n \) encompasses all permutations of \( n \) distinct elements. By establishing this group, I can perform operations like computing the composition of two permutations, exploring cycles, or examining transpositions.

    A Practical Example

    Below is a MATLAB code snippet illustrating how to generate the symmetric group \( S_3 \), the group of all permutations for three elements:

    I generate all permutations for the set {1,2,3}.

    permutations = perms([1,2,3]);

    Input the set as an array [1,2,3] when using the perms() function.

    The function efficiently generates and returns all permutations of these elements.

    disp(permutations)

    3 2 1
    3 1 2
    2 3 1
    2 1 3
    1 3 2
    1 2 3

    This code forms a basis from which I can explore further operations such as computing the product of two permutations, probing into subgroups, or analyzing permutation properties like parity (odd or even).

    Example (composition of permutations)

    To compose two permutations, use the indexing operator to apply one permutation to another.

    This sequential application is fundamental to understanding composition in symmetric groups.

    First, I define two permutations \( \sigma \) and \( \tau \) in MATLAB:

    tau = [3, 1, 2];
    sigma = [2, 3, 1];

    To calculate \( \sigma \circ \tau \) (applying \( \tau \) first), I use the indexing operator to apply \( \tau \), then \( \sigma \) to the results of \( \tau \).

    composed_permutation = sigma(tau);

    Next, I print the result:

    disp(composed_permutation);

    1 2 3

    In this example, the outcome is 1, 2, 3 because:

    $$ \tau = (1 \rightarrow 3, 2 \rightarrow 1, 3 \rightarrow 2) $$

    $$ \sigma = (1 \rightarrow 2, 2 \rightarrow 3, 3 \rightarrow 1) $$

    The composition \( \sigma \circ \tau \) first applies \( \tau \) and then \( \sigma \).

    In essence, the inner permutation \( \tau \) is processed first, followed by the outer permutation \( \sigma \) on the result.

    \begin{array}{|c|c|c|}
    \hline
    \text{Element} & \tau & \sigma(\tau) \\
    \hline
    1 & 3 & \sigma(3) = 1 \\
    2 & 1 & \sigma(1) = 2 \\
    3 & 2 & \sigma(2) = 3 \\
    \hline
    \end{array}

    This methodology can also be expanded to compose more than two permutations or to undertake more intricate calculations on symmetric groups.

    And so on.

     
     

    Please feel free to point out any errors or typos, or share suggestions to improve these notes. English isn't my first language, so if you notice any mistakes, let me know, and I'll be sure to fix them.

    FacebookTwitterLinkedinLinkedin
    knowledge base