Theory Comparison_Sort_Lower_Bound
section ‹Lower bound on costs of comparison-based sorting›
theory Comparison_Sort_Lower_Bound
imports
Complex_Main
Linorder_Relations
Stirling_Formula.Stirling_Formula
"Landau_Symbols.Landau_More"
begin
subsection ‹Abstract description of sorting algorithms›
text ‹
We have chosen to model a sorting algorithm in the following way: A sorting algorithm takes a
list with distinct elements and a linear ordering on these elements, and it returns a list
with the same elements that is sorted w.\,r.\,t.\ the given ordering.
The use of an explicit ordering means that the algorithm must look at the ordering, i.\,e.\
it has to use pair-wise comparison of elements, since all the information that is relevant
for producing the correct sorting is in the ordering; the elements themselves are irrelevant.
Furthermore, we record the number of comparisons that the algorithm makes by not giving it the
relation explicitly, but in the form of a comparison oracle that may be queried.
A sorting algorithm (or `sorter') for a fixed input list (but for arbitrary orderings) can then
be written as a recursive datatype that is either the result (the sorted list) or a comparison
query consisting of two elements and a continuation that maps the result of the comparison
to the remaining computation.
›