Clear Filters
Clear Filters

Compute permutation cycles of sets

11 views (last 30 days)
Alec Bledsoe
Alec Bledsoe on 20 Sep 2023
Answered: Infinite_king on 4 Oct 2023

Hello. Just to start, I am asking about something that I don't fully understand the terminology around yet so I will try but I apologize if there is some confusion. I am trying to find all the possible combinations of these sets (included below) which I started doing by hand but I would like to automate it with matlab to speed finding all the combinations.

a (1 3 2 4)(5 7 6 8)
b (1 4 2 3)(5 8 6 7)
c (1 5 2 6)(3 8 4 7)
d (1 8 2 7)(3 6 4 5)
e (1 6 2 5)(3 7 4 8)
f (1 7 2 8)(3 5 4 6)
g (1 2)(3 4)(5 6)(7 8)

Just in case I am mixing up the terminology, here is an example of what I am trying to do.
ac = (1 3 2 4)(5 7 6 8)(1 5 2 6)(3 8 4 7) = (1 8 2 7)(3 6 4 5) = d

I was looking at the perms() function but I am not sure how to use it to accomplish this type of result.

Thank you for any help and suggestions.

  2 Comments
Dyuman Joshi
Dyuman Joshi on 21 Sep 2023
If I am understanding this correct, Variables a, b, c, d, e, f, and g are the data you are working with, and you have to find combinations of each of them taken 2 at a time?
Also, what is the logic behind this conversion or computation -
ac = (1 3 2 4)(5 7 6 8)(1 5 2 6)(3 8 4 7) = (1 8 2 7)(3 6 4 5) = d

Sign in to comment.

Answers (1)

Infinite_king
Infinite_king on 4 Oct 2023
Hi,
I understand that you are interested in finding all the composite permutations that can be obtained from the given set of permutations.
To execute this task in MATLAB, it may be beneficial to consider utilizing the One-Line notation method.
One way to approach this is by using the 'combinations' function, which allows us to generate various combinations of the given set of elements.
Subsequently, we can iterate through each combination and calculate the composite permutations. Please refer the code below for reference
% permutation size
permutation_size = 3;
% permutations -> Enter the permutations here
p1 = int64([2 3 1]);
p2 = int64([2 1 3]);
% combining different permutations into single martix, let's call it
% permutation set
per_set = [p1;p2];
% row numbers of permutation set
per_set_nums = 1:2;
% Finding various combinations of given permutations
set_combinations = combinations(per_set_nums,per_set_nums);
% calculating number of combinations
size_of_table = size(set_combinations);
number_of_combs = size_of_table(1);
% calculating composite permutations
for comb = 1:number_of_combs
% Choosen permutations
per1 = set_combinations{comb,1};
per2 = set_combinations{comb,2};
% calculating composite permutations
composite_permutation = zeros(1,permutation_size);
for num = 1:permutation_size
composite_permutation(num) = per_set(per2,per_set(per1,num));
end
% printing the composite permutation
fprintf("composite permutation obtained by combining permutation %d and %d \n",per1,per2);
%for num = 1:permutation_size
disp(composite_permutation);
%end
fprintf("\n");
end
For more information, kindly refer the following documentations,
  1. https://en.wikipedia.org/wiki/Cyclic_permutation
  2. https://en.wikipedia.org/wiki/Permutation#Cycle_notation
  3. https://en.wikipedia.org/wiki/Permutation#Cycle_notation:~:text=unless%20otherwise%20specified.-,Two%2Dline,-notation%5Bedit
  4. https://www.mathworks.com/help/matlab/ref/combinations.html
Hope this is helpful.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!