ABSTRACT
The combination of non-determinism and sorting is mostly associated with permutation sort, a sorting algorithm that is not very useful for sorting and has an awful running time. In this paper we look at the combination of non-determinism and sorting in a different light: given a sorting function, we apply it to a non-deterministic predicate to gain a function that enumerates permutations of the input list. We get to the bottom of necessary properties of the sorting algorithms and predicates in play as well as discuss variations of the modelled non-determinism. On top of that, we formulate and prove a theorem stating that no matter which sorting function we use, the corresponding permutation function enumerates all permutations of the input list. We use free theorems, which are derived from the type of a function alone, to prove the statement.
- S. Antoy and M. Hanus. New Functional Logic Design Patterns. WFLP’11, pages 19–34. Springer LNCS 6816, 2011. Google ScholarDigital Library
- Nils Anders Danielsson, John Hughes, Patrik Jansson, and Jeremy Gibbons. Fast and Loose Reasoning is Morally Correct. POPL’06, pages 206–217. ACM, 2006. Google ScholarDigital Library
- Sebastian Fischer and Jan Christiansen. Curry mailing list, July 2009.Google Scholar
- Michael Hanus. The Integration of Functions into Logic Programming: From Theory to Practice. Journal of Logic Programming, pages 583– 628, 1994.Google ScholarCross Ref
- Selmer M Johnson. Generation of Permutations by Adjacent Transposition. Mathematics of computation, pages 282–285, 1963.Google Scholar
- Sheng Liang, Paul Hudak, and Mark Jones. Monad Transformers and Modular Interpreters. In Proceedings of the 22nd ACM SIGPLANSIGACT symposium on Principles of programming languages, pages 333–343. ACM, 1995. Google ScholarDigital Library
- Colin L Mallows. Patience Sorting. SIAM review, 1963.Google Scholar
- George Pollard, Sebastian Fischer, Ganesh Sittampalam, and Ryan Ingram. Haskell mailing list, July 2009.Google Scholar
- H. F. Trotter. Algorithm 115: Perm. Commun. ACM, pages 434–435, 1962. Google ScholarDigital Library
- Twan van Laarhoven et al. Haskell mailing list, December 2007.Google Scholar
- Philip Wadler. Theorems for Free! FPCA’89, pages 347–359. ACM, 1989. Google ScholarDigital Library
Index Terms
- All sorts of permutations (functional pearl)
Recommendations
All sorts of permutations (functional pearl)
ICFP '16The combination of non-determinism and sorting is mostly associated with permutation sort, a sorting algorithm that is not very useful for sorting and has an awful running time. In this paper we look at the combination of non-determinism and sorting in ...
On the combinatorics of derangements and related permutations
Highlights- Provide a bijection combinatorial proof for the facts that The number of derangements of length n equals the number of permutations of length n that have ...
AbstractA derangement is a permutation in which no entry is at its original position. The number of derangements of [ n ] is called the “derangement number” or “de Montmort number”, and is denoted by D n. The sequence { D n } enumerates, in ...
Tighter upper bound for sorting permutations with prefix transpositions
Permutations are sequences where each symbol in the given alphabet Σ appears exactly once. A transposition is an operation that exchanges two adjacent sublists in a permutation; if one of these sublists is restricted to be a prefix then one obtains a ...
Comments