Cyclic and Non-cyclic Permutations
Per the request, I post my comment as an answer:
First question
cy := Permute[#, CyclicGroup[Length@#]] &
cy[Range@5]
{{1, 2, 3, 4, 5}, {2, 3, 4, 5, 1}, {3, 4, 5, 1, 2}, {4, 5, 1, 2,
3}, {5, 1, 2, 3, 4}}
Second question
We can use the Complement
mentioned by J.M. in his comment. I suppose that the order is $5$; then, you can use the following method to get noncyclic permutations:
Complement[Permutations[Range[5]], cy[Range@5]]
{{1,2,3,5,4},{1,2,4,3,5},{1,2,4,5,3},{1,2,5,3,4},{1,2,5,4,3},{1,3,2,4,5},{1,3,2,5,4},<<101>>,{5,3,4,2,1},{5,4,1,2,3},{5,4,1,3,2},{5,4,2,1,3},{5,4,2,3,1},{5,4,3,1,2},{5,4,3,2,1}}
cp=HankelMatrix[#, RotateRight@#] &;
Should perform quite well and returns packed array...
At least in version 10.1 under Windows there is a performance problem with yode's Permute
solution. For comparison here is his code, Joe's original code, and a variation of my own:
fn1[list_] := RotateRight[list, #] & /@ (Range[Length[list]] - 1)
fn2 = Permute[#, CyclicGroup[Length@#]] &;
fn3[a_] := Array[RotateLeft[a, #]&, Length @ a]
The results are all equivalent under sorting:
Sort @ # @ Range @ 4 & /@ {fn1, fn2, fn3}
{{{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}, {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}, {{1, 2, 3, 4}, {2, 3, 4, 1}, {3, 4, 1, 2}, {4, 1, 2, 3}}}
The performance however is not!
AbsoluteTiming @ Timing @ Do[#@Range@500, {50}] & /@ {fn1, fn2, fn3} // Column
{0.046702, {0.0312002, Null}} {2.48765, {2.44922, Null}} {0.0456291, {0.0156001, Null}}
Permute
on CyclicGroup
is some fifty times slower than the other methods here.
My fn3
is just a hair faster than fn1
and IMHO somewhat cleaner, so it is my proposal.