OFFSET
0,3
COMMENTS
Used to construct the inverse for A127291.
REFERENCES
Emeric Deutsch and Sergi Elizalde, A simple and unusual bijection for Dyck paths and its consequences, Annals of Combinatorics, 7 (2003), no. 3, 281-297.
LINKS
PROG
(MIT/GNU Scheme)
(define (transpos-list->A014486 tplist) (fold-left (lambda (s p) (+ s (expt 2 (max (car p) (cdr p))))) 0 tplist))
(define (a127300-aux1 n) (if (zero? n) (list) (let loop ((n n) (tplist1 (list)) (tplist2 (list)) (i 0) (j (A000523 n)) (b 1)) (cond ((zero? n) (append tplist1 tplist2)) ((even? n) (loop (/ n 2) tplist2 (cons (cons '() i) tplist1) j (+ i b) (- b))) ((assq '() tplist1) => (lambda (p) (set-car! p i) (loop (/ (- n 1) 2) tplist2 tplist1 j (+ i b) (- b)))) ((rassq '() tplist2) => (lambda (p) (set-car! p i) (loop (/ (- n 1) 2) tplist2 tplist1 j (+ i b) (- b)))) (else (error "n not in A014486!")))))) ;; Returns a list of non-crossing transpositions.
(define (rassq key al) (let loop ((al al) (last-found #f)) (cond ((null? al) last-found) ((eq? (caar al) key) (loop (cdr al) (car al))) (else (loop (cdr al) last-found))))) ;; (rassq key al) is essentially the same as: (assq key (reverse al))
CROSSREFS
KEYWORD
nonn
AUTHOR
Antti Karttunen, Jan 16 2007
STATUS
approved