Is there a way in Sage to generate a random permutation with a given cycle type?

asked 2022-11-28 21:37:38 +0200

Sébastien gravatar image

This works:

sage: P = Permutations(5)
sage: p = P.random_element()
sage: p
[2, 3, 1, 5, 4]
sage: p.cycle_type()
[3, 2]
sage: p = P.random_element()
sage: p.cycle_type()
[5]

The following does not work:

sage: p = P.random_element(cycle_type=[3,2])

Is this already written elsewhere?

edit retag flag offensive close merge delete

Comments

I don't know of a direct implementation, but you could try T = SetPartitions(5, [3,2]) and then T.random_element() to get two disjoint subsets of size 2 and 3. Then form a permutation from them.

John Palmieri gravatar imageJohn Palmieri ( 2022-11-28 21:59:08 +0200 )edit
2

conjugate any chosen permutation of the given cycle type by a random permutation

FrédéricC gravatar imageFrédéricC ( 2022-11-29 08:01:45 +0200 )edit

Yes, good idea, thank you both!

Sébastien gravatar imageSébastien ( 2022-11-29 11:16:05 +0200 )edit