This site is supported by donations to The OEIS Foundation.



(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A055089 List of all finite permutations in reversed colexicographic ordering. 70


%S 1,2,1,1,3,2,3,1,2,2,3,1,3,2,1,1,2,4,3,2,1,4,3,1,4,2,3,4,1,2,3,2,4,1,

%T 3,4,2,1,3,1,3,4,2,3,1,4,2,1,4,3,2,4,1,3,2,3,4,1,2,4,3,1,2,2,3,4,1,3,

%U 2,4,1,2,4,3,1,4,2,3,1,3,4,2,1,4,3,2,1,1,2,3,5,4,2,1,3,5,4,1,3,2,5,4,3,1,2

%N List of all finite permutations in reversed colexicographic ordering.

%H Antti Karttunen, <a href="/A055089/b055089.txt">Rows 0..719 of the irregular table, flattened.</a>

%H Daniel Forgues, Tilman Piesk, et al., <a href="https://oeis.org/wiki/Orderings">Orderings</a>, OEIS Wiki

%H Antti Karttunen, <a href="http://oeis.org/wiki/Ranking_and_unranking_functions">Ranking and unranking functions</a>, OEIS Wiki

%H Tilman Piesk, <a href="https://en.wikiversity.org/wiki/Permutations_and_partitions_in_the_OEIS">Permutations and partitions in the OEIS</a> (Wikiversity)

%H <a href="/index/Fa#facbase">Index entries for sequences related to factorial base representation</a>

%H <a href="/index/Per#perm">Index entries for sequences related to permutations</a>

%F [seq(op(PermRevLexUnrank(j)), j=0..)]; (see Maple code given below).

%e In this table, each row consists of A001563(n) permutations of n+1 terms; i.e., we have (1/) 2,1/ 1,3,2; 3,1,2; 2,3,1; 3,2,1/ 1,2,4,3; 2,1,4,3; ... .

%e Append to each an infinite number of fixed terms and we get a list of rearrangements of the natural numbers, but with only a finite number of terms permuted:

%e 1/2,3,4,5,6,7,8,9,...

%e 2,1/3,4,5,6,7,8,9,...

%e 1,3,2/4,5,6,7,8,9,...

%e 3,1,2/4,5,6,7,8,9,...

%e 2,3,1/4,5,6,7,8,9,...

%e 3,2,1/4,5,6,7,8,9,...

%e 1,2,4,3/5,6,7,8,9,...

%e 2,1,4,3/5,6,7,8,9,...

%e Alternatively, if we take only the first n terms of each such infinite row, then the first n! rows give all permutations of the elements 1,2,...,n.

%p factorial_base := proc(nn) local n,a,d,j,f; n := nn; if(0 = n) then RETURN([0]); fi; a := []; f := 1; j := 2; while(n > 0) do d := floor(`mod`(n,(j*f))/f); a := [d,op(a)]; n := n - (d*f); f := j*f; j := j+1; od; RETURN(a); end;

%p fexlist2permlist := proc(a) local n,b,j; n := nops(a); if(0 = n) then RETURN([1]); fi; b := fexlist2permlist(cdr(a)); for j from 1 to n do if(b[j] >= ((n+1)-a[1])) then b[j] := b[j]+1; fi; od; RETURN([op(b),(n+1)-a[1]]); end;

%p fac_base := n -> fac_base_aux(n,2); fac_base_aux := proc(n,i) if(0 = n) then RETURN([]); else RETURN([op(fac_base_aux(floor(n/i),i+1)), (n mod i)]); fi; end;

%p PermRevLexUnrank := n -> `if`((0 = n),[1],fexlist2permlist(fac_base(n)));

%p cdr := proc(l) if 0 = nops(l) then ([]) else (l[2..nops(l)]); fi; end; # "the tail of the list"

%p # Same algorithm in different guise, showing how permutations are composed of adjacent transpositions (compare to algorithm PermUnrank3R at A060117):

%p PermRevLexUnrankAMSDaux := proc(n,r, pp) local s,p,k; p := pp; if(0 = r) then RETURN(p); else s := floor(r/((n-1)!)); for k from n-s to n-1 do p := permul(p,[[k,k+1]]); od; RETURN(PermRevLexUnrankAMSDaux(n-1, r-(s*((n-1)!)), p)); fi; end;

%p PermRevLexUnrankAMSD := proc(r) local n; n := nops(factorial_base(r)); convert(PermRevLexUnrankAMSDaux(n+1,r,[]),'permlist',1+(((r+2) mod (r+1))*n)); end;

%t A055089L[n_] := Reverse@SortBy[DeleteCases[Permutations@Range@n, {__, n}], Reverse]; Flatten@Array[A055089L, 4] (* _JungHwan Min_, Aug 28 2016 *)

%o (MIT/GNU Scheme, with _Antti Karttunen_'s intseq-library):

%o ;; Note that in Scheme, vector indexing is zero-based.

%o (definec (A055089 n) (vector-ref (A055089permvec-short (A220658 n)) (A220659 n)))

%o (definec (A055089permvec-short rank) (A055089permvec (+ 1 (A084558 rank)) rank))

%o (define (A055089permvec size rank) (let ((permvec (make-initialized-vector size 1+))) (let outloop ((rank rank) (i 2)) (cond ((zero? rank) (permvec1inverse-of permvec)) (else (let inloop ((k (- i 1))) (cond ((< k (- i (remainder rank i))) (outloop (floor->exact (/ rank i)) (+ 1 i))) (else (begin (let ((tmp (vector-ref permvec (- k 1)))) (vector-set! permvec (- k 1) (vector-ref permvec k)) (vector-set! permvec k tmp)) (inloop (- k 1)))))))))))

%o (define (permvec1inverse-of permvec) (make-initialized-vector (vector-length permvec) (lambda (i) (permvec1find-pos-of-i-from (+ 1 i) permvec))))

%o (define (permvec1find-pos-of-i-from i permvec) (let loop ((k 0)) (cond ((= k (vector-length permvec)) #f) ((= i (vector-ref permvec k)) (+ 1 k)) (else (loop (+ k 1)))))) ;; _Antti Karttunen_, Dec 18 2012

%Y Inversion vectors: A007623, cycle counts: A055090, minimum number of transpositions: A055091, minimum number of adjacent transpositions: A034968, order of each permutation: A055092, number of non-fixed elements: A055093, positions of inverses: A056019, positions after Foata transform: A065181; positions of fixed-point-free involutions: A064640.

%Y Cf. A057112, A060112, A060117, A060118, A060132, A060133.

%Y Cf. A195663, array of the infinite rows.

%Y This permutation list gives essentially the same information as A030298/A030299, but in a more compact way, by skipping those permutations of A030298 that start with a fixed element.

%Y A220658(n) gives the rank r of the permutation of which the term at a(n) is an element.

%Y A220659(n) gives the zero-based position (from the left) of that a(n) in that permutation of rank r.

%Y A084558(r)+1 gives the size of the finite subsequence (of the r-th infinite, but finitary permutation) which has been included in this list.

%K nonn,tabf

%O 0,2

%A _Antti Karttunen_, Apr 18 2000

%E Name changed by _Tilman Piesk_, Feb 01 2012

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recent
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified February 22 15:49 EST 2019. Contains 320399 sequences. (Running on oeis4.)