Table of Contents
Fetching ...

Symmetries in Sorting

Vikraman Choudhury, Wind Wong

TL;DR

The paper reframes sorting as a problem in universal algebra by viewing sorting functions as sections to the surjection from free monoids to free commutative monoids, without assuming a total order. It develops multiple presentations of free (commutative) monoids (lists, arrays, bags, PList, SList) and shows how permutation relations underpin commutativity, with a formalisation in Cubical Agda. Axioms isHeadLeast and isTailSorted are introduced to capture the intrinsic correctness of sorting, and a main equivalence DecTotOrd(A) ≃ Sort(A) × Discrete(A) is established, connecting decidable total orders with constructive sorting functions. The work provides a coherent, constructive framework for reasoning about sorting across various representations and lays groundwork for extending these ideas to more general inductive types and higher-categorical structures.

Abstract

Sorting algorithms are fundamental to computer science, and their correctness criteria are well understood as rearranging elements of a list according to a specified total order on the underlying set of elements. As mathematical functions, they are functions on lists that perform combinatorial operations on the representation of the input list. In this paper, we study sorting algorithms conceptually as abstract sorting functions. There is a canonical surjection from the free monoid on a set (lists of elements) to the free commutative monoid on the same set (multisets of elements). We show that sorting functions determine a section (right inverse) to this surjection satisfying two axioms, that do not presuppose a total order on the underlying set. Then, we establish an equivalence between (decidable) total orders on the underlying set and correct sorting functions. The first part of the paper develops concepts from universal algebra from the point of view of functorial signatures, and gives constructions of free monoids and free commutative monoids in (univalent) type theory. Using these constructions, the second part of the paper develops the axiomatisation of sorting functions. The paper uses informal mathematical language, and comes with an accompanying formalisation in Cubical Agda.

Symmetries in Sorting

TL;DR

The paper reframes sorting as a problem in universal algebra by viewing sorting functions as sections to the surjection from free monoids to free commutative monoids, without assuming a total order. It develops multiple presentations of free (commutative) monoids (lists, arrays, bags, PList, SList) and shows how permutation relations underpin commutativity, with a formalisation in Cubical Agda. Axioms isHeadLeast and isTailSorted are introduced to capture the intrinsic correctness of sorting, and a main equivalence DecTotOrd(A) ≃ Sort(A) × Discrete(A) is established, connecting decidable total orders with constructive sorting functions. The work provides a coherent, constructive framework for reasoning about sorting across various representations and lays groundwork for extending these ideas to more general inductive types and higher-categorical structures.

Abstract

Sorting algorithms are fundamental to computer science, and their correctness criteria are well understood as rearranging elements of a list according to a specified total order on the underlying set of elements. As mathematical functions, they are functions on lists that perform combinatorial operations on the representation of the input list. In this paper, we study sorting algorithms conceptually as abstract sorting functions. There is a canonical surjection from the free monoid on a set (lists of elements) to the free commutative monoid on the same set (multisets of elements). We show that sorting functions determine a section (right inverse) to this surjection satisfying two axioms, that do not presuppose a total order on the underlying set. Then, we establish an equivalence between (decidable) total orders on the underlying set and correct sorting functions. The first part of the paper develops concepts from universal algebra from the point of view of functorial signatures, and gives constructions of free monoids and free commutative monoids in (univalent) type theory. Using these constructions, the second part of the paper develops the axiomatisation of sorting functions. The paper uses informal mathematical language, and comes with an accompanying formalisation in Cubical Agda.

Paper Structure

This paper contains 22 sections, 36 theorems, 28 equations, 1 figure.

Key Result

Proposition 11

The free algebra construction produces a monad on $\mathsf{Set}$.

Figures (1)

  • Figure 1: Relationship of $\mathcal{L}(A)$ and $\mathcal{M}(A)$

Theorems & Definitions (80)

  • Definition 1: https://symmetries.windtfw.com/types25pp.html#definition-signature
  • Example 2
  • Definition 3: https://symmetries.windtfw.com/types25pp.html#definition-signature-functor
  • Example 4
  • Definition 5: https://symmetries.windtfw.com/types25pp.html#definition-structure
  • Example 6
  • Definition 7: https://symmetries.windtfw.com/types25pp.html#definition-sig-homomorphism
  • Example 8
  • Definition 9: https://symmetries.windtfw.com/types25pp.html#definition-free-algebras
  • Definition 10: https://symmetries.windtfw.com/types25pp.html#definition-universal-extension
  • ...and 70 more