How to generate permutation matrices (fast)?

32 views
Skip to first unread message

jplab

unread,
Nov 23, 2020, 8:44:00 AM11/23/20
to sage-support
Hi all,

I would have posted this question on AskSage, but I can't seem to be able to connect through my google account (Authorization Error?). So I put the question here.

I would like to know how to iterate through permutation matrices of a fixed size ($n\times n$) by breadth-first-search (by length in the weak order poset). Somehow, this is pretty simple, but I can't seem to figure this out from the jungle of methods available.

I do know that it is possible to get the elements by lengths in the CoxeterGroup(['A',n-1]) structure, but I want the permutation matrix associate to the element.

Somehow, tons of methods are available but the obvious "permutation_matrix" is not there.

Any hint? I know I missed something somewhere!

J-P

jplab

unread,
Nov 23, 2020, 8:53:44 AM11/23/20
to sage-support
... ok! Found it:

sage: P = Permutations([1,2,3])                                                                                                                                                                                   
sage: elmts = P.elements_of_length(3)                                                                                                                                                                             
sage: e = next(elmts)                                                                                                                                                                                             
sage: e                                                                                                                                                                                                           
[3, 2, 1]
sage: e.to_matrix()                                                                                                                                                                                               
[0 0 1]
[0 1 0]
[1 0 0]

... somehow was thinking of using too technical things.
Reply all
Reply to author
Forward
0 new messages