Ranking Catamorphisms and Unranking Anamorphisms on Hereditarily Finite Datatypes

Reading time: 6 minute
...

📝 Original Info

  • Title: Ranking Catamorphisms and Unranking Anamorphisms on Hereditarily Finite Datatypes
  • ArXiv ID: 0808.0753
  • Date: 2008-08-07
  • Authors: ** Paul Tarau (University of North Texas, Department of Computer Science and Engineering) **

📝 Abstract

Using specializations of unfold and fold on a generic tree data type we derive unranking and ranking functions providing natural number encodings for various Hereditarily Finite datatypes. In this context, we interpret unranking operations as instances of a generic anamorphism and ranking operations as instances of the corresponding catamorphism. Starting with Ackerman's Encoding from Hereditarily Finite Sets to Natural Numbers we define pairings and tuple encodings that provide building blocks for a theory of Hereditarily Finite Functions. The more difficult problem of ranking and unranking Hereditarily Finite Permutations is then tackled using Lehmer codes and factoradics. The self-contained source code of the paper, as generated from a literate Haskell program, is available at \url{http://logic.csci.unt.edu/tarau/research/2008/fFUN.zip}. Keywords: ranking/unranking, pairing/tupling functions, Ackermann encoding, hereditarily finite sets, hereditarily finite functions, permutations and factoradics, computational mathematics, Haskell data representations

💡 Deep Analysis

Deep Dive into Ranking Catamorphisms and Unranking Anamorphisms on Hereditarily Finite Datatypes.

Using specializations of unfold and fold on a generic tree data type we derive unranking and ranking functions providing natural number encodings for various Hereditarily Finite datatypes. In this context, we interpret unranking operations as instances of a generic anamorphism and ranking operations as instances of the corresponding catamorphism. Starting with Ackerman’s Encoding from Hereditarily Finite Sets to Natural Numbers we define pairings and tuple encodings that provide building blocks for a theory of Hereditarily Finite Functions. The more difficult problem of ranking and unranking Hereditarily Finite Permutations is then tackled using Lehmer codes and factoradics. The self-contained source code of the paper, as generated from a literate Haskell program, is available at \url{http://logic.csci.unt.edu/tarau/research/2008/fFUN.zip}. Keywords: ranking/unranking, pairing/tupling functions, Ackermann encoding, hereditarily finite sets, hereditarily finite functions, perm

📄 Full Content

Ranking Catamorphisms and Unranking Anamorphisms on Hereditarily Finite Datatypes – unpublished draft – Paul Tarau Department of Computer Science and Engineering University of North Texas tarau@cs.unt.edu Abstract Using specializations of unfold and fold on a generic tree data type we derive unranking and ranking functions provid- ing natural number encodings for various Hereditarily Finite datatypes. In this context, we interpret unranking operations as in- stances of a generic anamorphism and ranking operations as instances of the corresponding catamorphism. Starting with Ackerman’s Encoding from Hereditarily Finite Sets to Natural Numbers we define pairings and finite tuple encodings that provide building blocks for a theory of Hereditarily Finite Functions. The more difficult problem of ranking and unrank- ing Hereditarily Finite Permutations is then tackled using Lehmer codes and factoradics. The self-contained source code of the paper, as generated from a literate Haskell program, is available at http:// logic.csci.unt.edu/tarau/research/2008/fFUN.zip. Keywords ranking/unranking, pairing/tupling functions, Ackermann encoding, hereditarily finite sets, hereditarily fi- nite functions, permutations and factoradics, computational mathematics, Haskell data representations 1. Introduction This paper is an exploration with functional programming tools of ranking and unranking problems on finite functions and bijections and their related hereditarily finite universes. The ranking problem for a family of combinatorial objects is finding a unique natural number associated to it, called its rank. The inverse unranking problem consists of generating Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Copyright c⃝ACM [to be supplied]...$5.00 a unique combinatorial object associated to each natural number. The paper is organized as follows: section 2 introduces generic ranking/unranking framework parameterized by bi- jective transformers and terminating conditions based on urelements, section 3 introduces Ackermann’s encoding and its inverse as instances of the framework. After discussing some classic pairing functions, section 4 introduces new pairing/unpairing and tuple operations on natural numbers and uses them for encodings of finite functions (section 5), resulting in encodings for “Hereditarily Finite Functions” (section 6). Ranking/unranking of permutations and Heredi- tarily Finite Permutations as well as Lehmer codes and fac- toradics are covered in section 7. Sections 8 and 9 discuss related work, future work and conclusions. The paper is part of a larger effort to cover in a declara- tive programming paradigm, arguably more elegantly, some fundamental combinatorial generation algorithms along the lines of (Knuth 2006). The practical expressiveness of func- tional programming languages (in particular Haskell) are put at test in the process. While the main focus of the paper was testdriving Haskell on the curvy tracks of non-trivial combinatorial generation problems, we have bumped, somewhat accidentally, into making a few new contributions to the field as such, that could be easily blamed on the quality of the vehicle we were testdriving: 1. the three ranking/unranking algorithms from finite func- tions to natural numbers are new 2. the universe of Hereditarily Finite Functions, as a func- tional analogue of the well known universe of Hereditar- ily Finite Sets is new 3. the universe of Hereditarily Finite Permutations, as an analogue of the well known universe of Hereditarily Fi- nite Sets is new 4. the natural number tupling/untupling functions are new arXiv:0808.0753v1 [cs.SC] 6 Aug 2008 5. the ranking/unranking algorithm for permutations of ar- bitrary sizes is new (although it is based on a known Lehmer code-based algorithm for permutations of fixed size) 6. the catamorphism/anamorphism view of ranking/unrank- ing functions is new and it is likely to be reusable for various families of combinatorial generation problems Through the paper, we will use the following set of prim- itive arithmetic functions: double n = 2∗n half n = n ‘div‘ 2 exp2 n = 2^n together with succ, pred, even, odd and sum Haskell func- tions, to emphasize that this subset is easily hardware im- plementable (by only using boolean operations, shifts and adders) and that these functions also have O(log n) or better software implementations for integers of (arbitrary) length n. When possible, we will use point-free notations (unnec- essary function arguments omitted) to emphasize the generic function composition dataflow. As we have put significant effort to ensure that all our types can be inf

…(Full text truncated)…

Reference

This content is AI-processed based on ArXiv data.

Start searching

Enter keywords to search articles

↑↓
ESC
⌘K Shortcut