This site is supported by donations to The OEIS Foundation.

User:Antti Karttunen/Recursive transformations of binary tree bijections

From OeisWiki
Jump to: navigation, search

Recursive transformations of binary tree bijections are transformations which transform a bijection of rooted plane binary trees recursively to another[1] bijection[2] of binary trees. Formally, if the set consists of all possible bijections , where is the set of all rooted plane binary trees[3], then a transformation of binary tree bijections is a function whose domain is the whole set .

Note that recursive doesn't refer here to recursive sets or recursive enumerability but concretely to structural recursion inherent in the structure of binary trees. Many of these transformations are based on preorder, inorder and postorder variants of the depth-first search of binary trees or general trees.

List of common recursive transformations

Below are listed some of the most essential transformations applicable to bijections of binary trees. In the explanations given, stands for the bijection given, and for the (usually different) bijection that is obtained from with some transformation as .

The notation refers to a Catalan bijection that applies only to the left-hand side child of a binary tree, and leaves the right-hand side intact, and similarly, the notation refers to a Catalan bijection that applies only to the right-hand side child of a binary tree, and leaves the left-hand side intact. In Scheme these could be expressed as:

(define (fL s) (cons (f (car s)) (cdr s)))

and

(define (fR s) (cons (car s) (f (cdr s))))

This notation comes handy for showing what are the inverse operations for each transformation.

Many of these recursive transformations can also be implemented as folds. The relationships between the recursive transformation operators, formulas for their inverses, etc. are given below without proofs. For proofs and various implications of folds, please consult[4].

FORK

In this recursion scheme the bijection is first applied at the root of binary tree, before the algorithm recurses down to the both branches (new ones, possibly changed by ). This corresponds to the pre-order (prefix) traversal of the binary tree. The name stems from the fact that the recursion "forks" into both branches of a binary tree.

If then the inverse of the resulting Catalan bijection is obtained as . See below for the definition of KROF.

FORK is a bijective function on the set , which means that any Catalan bijection can be obtained with FORK-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

The Scheme-functions FORK and !FORK given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection.

(define (FORK foo)
  (letrec ((bar (lambda (s)
                  (let ((t (foo s)))
                    (if (pair? t)
                        (cons (bar (car t)) (bar (cdr t)))
                        t
                    )
                  )
                )
          ))
     bar
  )
)

(define (!FORK foo!)
  (letrec ((bar! (lambda (s)
                    (cond ((pair? s)
                            (foo! s)
                            (bar! (car s))
                            (bar! (cdr s))
                          )
                    )
                    s
                 )
          ))
     bar!
  )
)

KROF

In this recursion scheme the algorithm first recurses down to the both branches, and the bijection is applied at the root of binary tree only after the execution has returned from the recursion. In other words, this corresponds to the post-order (postfix) traversal of a binary tree. The Scheme-functions KROF and !KROF given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection. Note how KROF has been implemented as a fold.

If then the inverse of the resulting Catalan bijection is obtained as . See above for the definition of FORK.

KROF is a bijective function on the set , which means that any Catalan bijection can be obtained with KROF-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

(define (KROF foo) (letrec ((bar (lambda (s) (fold-right (lambda (x y) (foo (cons (bar x) y))) '() s)))) bar))

(define (!KROF foo!)
  (letrec ((bar! (lambda (s)
                    (cond ((pair? s)
                            (bar! (car s))
                            (bar! (cdr s))
                            (foo! s)
                          )
                    )
                    s
                 )
          ))
     bar!
  )
)

SPINE

In this recursion scheme the algorithm the bijection is first applied at the root of binary tree, before the algorithm recurses down to the new (possibly changed by ) right-hand side branch. The name comes from the fact in this scheme only the "spine" of the binary tree (leaning to the right) is traversed, but the recursion does not dive into the left-hand side branches.

If then the inverse of the resulting Catalan bijection is obtained as . See below for the definition of ENIPS.

SPINE is a bijective function on the set , which means that any Catalan bijection can be obtained with SPINE-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

The Scheme-functions SPINE and !SPINE given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection.

(define (SPINE foo)
  (letrec ((bar (lambda (s)
                  (let ((t (foo s)))
                    (if (pair? t)
                        (cons (car t) (bar (cdr t)))
                        t
                    )
                  )
                )
          ))
     bar
  )
)

(define (!SPINE foo!)
  (letrec ((bar! (lambda (s)
                    (cond ((pair? s)
                            (foo! s)
                            (bar! (cdr s))
                          )
                    )
                    s
                 )
          ))
     bar!
  )
)

ENIPS

In this recursion scheme the algorithm first recurses down to the right-hand side branch of the binary tree, and only after it has returned from the recursion, the bijection is applied at the root of the tree.

If then the inverse of the resulting Catalan bijection is obtained as . See above for the definition of SPINE.

ENIPS is a bijective function on the set , which means that any Catalan bijection can be obtained with ENIPS-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

The Scheme-functions ENIPS and !ENIPS given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection. Note how ENIPS has been implemented as a fold.

(define (ENIPS foo) (lambda (s) (fold-right (lambda (x y) (foo (cons x y))) '() s)))

(define (!ENIPS foo!)
  (letrec ((bar! (lambda (s)
                    (cond ((pair? s)
                            (bar! (cdr s))
                            (foo! s)
                          )
                    )
                    s
                 )
          ))
     bar!
  )
)

DEEPEN

In this recursion scheme the bijection is first applied at the root of general tree, before the algorithm recurses down to all subtrees (new ones, possibly changed by ). This corresponds to the pre-order (prefix) traversal of a Catalan structure, when it is interpreted as a general tree in the standard way. The name stems from the fact that this transformation transforms a "shallow" variant of certain Catalan bijections (when viewed as automorphisms of plane general trees) to the corresponding "deep" variants. Examples include:

Transform a shallow (ordinary) reverse of lists to "deep-reverse".

If then the inverse of the resulting Catalan bijection is obtained as . See below for the definition of NEPEED.

DEEPEN is a bijective function on the set , which means that any Catalan bijection can be obtained with DEEPEN-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition . See below for the definition of RIBS.

FORK is the composition of DEEPEN and SPINE, i.e. the following holds for all bijections : .

The Scheme-functions DEEPEN and !DEEPEN given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection.

(define (DEEPEN foo) (letrec ((bar (lambda (s) (map bar (foo s))))) bar))
;; Alternatively, implemented as a fold:
(define (DEEPEN g) (letrec ((h (lambda (s) (fold-right (lambda (x y) (cons (h x) y)) ’() (g s))))) h))

(define (!DEEPEN foo!) (letrec ((bar! (lambda (s) (foo! s) (for-each bar! s) s))) bar!))

NEPEED

In this recursion scheme the bijection the algorithm first recurses down to all subtrees, and only after it has returned from the recursion, the bijection is applied at the root of the general tree. I.e. this corresponds to the post-order (postfix) traversal of a Catalan structure, when it is interpreted as a general tree.

If then the inverse of the resulting Catalan bijection is obtained as . See above for the definition of DEEPEN.

NEPEED is a bijective function on the set , which means that any Catalan bijection can be obtained with NEPEED-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

KROF is the composition of NEPEED and ENIPS, i.e. the following holds for all bijections : .

The Scheme-functions NEPEED and !NEPEED given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection.

(define (NEPEED foo) (letrec ((bar (lambda (s) (foo (map bar s))))) bar))
;; Alternatively, implemented as a fold:
(define (NEPEED g) (letrec ((h (lambda (s) (g (fold-right (lambda (x y) (cons (h x) y)) ’() s))))) h))

(define (!NEPEED foo!) (letrec ((bar! (lambda (s) (for-each bar! s) (foo! s) s))) bar!))

INORDER

In this recursion scheme the bijection is applied at the root of binary tree after the algorithm has recursed down the car-branch (the left hand side tree in the context of binary trees), but before the algorithm recurses down to the cdr-branch (the right hand side of the binary tree, with respect to the new orientation of branches, possibly changed by the bijection ). I.e. this corresponds to the depth-first in-order traversal of a rooted plane binary tree.

If then the inverse of the resulting Catalan bijection is obtained as . See below for the definition of REDRONI.

INORDER is a bijective function on the set , which means that any Catalan bijection can be obtained with INORDER-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

The Scheme-functions INORDER and !INORDER below can be used to obtain such a transformed bijection from any constructively (or respectively: destructively) implemented bijection.

(define (INORDER f)
  (letrec ((g (lambda (s)
                (cond ((not (pair? s)) s)
                      (else (let ((t (f (cons (g (car s)) (cdr s)))))
                              (cons (car t) (g (cdr t)))
                            )
                      )
                )
              )
          ))
     g
  )
)

(define (!INORDER f!)
  (letrec ((g! (lambda (s)
                    (cond ((pair? s)
                            (g! (car s))
                            (f! s)
                            (g! (cdr s))
                          )
                    )
                    s
                 )
          ))
     g!
  )
)

REDRONI

In this recursion scheme the bijection is applied at the root of binary tree after the algorithm has recursed down the cdr-branch (the right hand side tree in the context of binary trees) and returned from that recursion, but before the algorithm recurses down to the car-branch (the left hand side of the binary tree, with respect to the new orientation of branches, possibly changed by the bijection ). I.e. this corresponds to the reversed depth-first in-order traversal of a binary tree.

If then the inverse of the resulting Catalan bijection is obtained as . See above for the definition of INORDER.

REDRONI is a bijective function on the set , which means that any Catalan bijection can be obtained with REDRONI-transform from another[1] Catalan bijection. Its inverse operator (i.e. ) is formed as a function composition .

The Scheme-functions REDRONI and !REDRONI below can be used to obtain such a transformed bijection from any constructively (or respectively: destructively) implemented bijection.

(define (REDRONI f)
   (letrec ((g (lambda (s)
                  (fold-right (lambda (x y) (let ((t (f (cons x y)))) (cons (g (car t)) (cdr t))))
                              '()
                              s
                  )
               )
           ))
           g
   )
)


(define (!REDRONI f!)
  (letrec ((g! (lambda (s)
                    (cond ((pair? s)
                            (g! (cdr s))
                            (f! s)
                            (g! (car s))
                          )
                    )
                    s
                 )
          ))
     g!
  )
)

RIBS

In this recursion scheme the bijection is applied to all (toplevel) subtrees of the Catalan structure, when it is interpreted as a general tree. In the S-expression/list-context of programming languages Lisp and Scheme, it corresponds to applying (mapcar f s) (or respectively, instead of in Scheme) to the S-expression . The name adopted here stems from the fact that the bijection affects only the "ribs" branching leftward from the "spine" of the binary tree.

If then . Note that in contrast to all previous transformations, RIBS has no inverse. That is, most of the times, when is an arbitrary Catalan bijection, it cannot be obtained as from some other bijection .

The Scheme-functions RIBS and !RIBS given below can be used to obtain such a transformed bijection from any constructively or destructively implemented bijection.

(define (RIBS foo) (lambda (s) (map foo s)))
;; Or alternatively, as a fold:
(define (RIBS f) (lambda (s) (fold-right (lambda (x y) (cons (f x) y)) ’() s)))

(define (!RIBS foo!) (lambda (s) (for-each foo! s) s))

Note that is really just a short-hand for = .

If an integer sequence counts the number of fixed points (among each A000108() structures of size ) of the Catalan bijection , then the number of fixed points of the bijection are counted respectively by , where operator increases the indices of the sequence by one (from zero to one-based sequence), and transform INVERT is the one which Cameron calls the operator in[5] and for which Bernstein and Sloane gave the name INVERT in[6].

Authorship

The first version of this page was written by Antti Karttunen Aug 22, 2012, based on sections 8 (Recursion Schemata) and 9 (Implementing Recursion Schemata as Folds, Implications of Folds) of his unfinished draft, version 26 July 2011.[4]

References & Notes

  1. 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 Usually different bijection, but not always. For example, at least the identity bijection (A001477) is always fixed by these transformations.
  2. Actually, nothing forbids applying these transformations to any functions whose domains and ranges consists of all plane binary trees, regardless whether they are injective or surjective.
  3. A bijection can be defined also on any other combinatorial interpretation of Catalan numbers, provided there is a known method to map that interpretation 1-to-1 and onto to the binary trees
  4. 4.0 4.1 A. Karttunen, CatBijections.pdf Introductory Survey of Catalan Automorphisms and Bijections, unfinished draft, version of July 2011, sections 8 (Recursion Schemata) and 9 (Implementing Recursion Schemata as Folds, Implications of Folds) Cite error: Invalid <ref> tag; name "Anttis_draft_July_2011" defined multiple times with different content
  5. P. J. Cameron, Some sequences of integers, Discrete Math., 75 (1989), 89–102.
  6. M. Bernstein and N. J. A. Sloane, Some Canonical Sequences of Integers, accepted for publication in "Linear Algebra and Its Applications" (Seidel Festschrift), 1995, http://arxiv.org/abs/math.CO/0205301

Cite this page as

A. Karttunen, <insert your name here if you added anything essential>, et al., <a href="http://oeis.org/wiki/Recursive_transformations_of_binary_tree_bijections">Recursive transformations of binary tree bijections</a>, OEIS Wiki.