Insertion Sort: Correctness and Upper Bound #
Proofs that insertionSort is a correct comparison sort and uses at most n * (n - 1) / 2
queries (with n² as a corollary). All proofs are by plain equational reasoning on
FreeM.eval and FreeM.countQueries.
Evaluation #
Evaluating query-based insertion agrees with List.orderedInsert using the relation
supplied by the oracle.
Evaluating query-based insertion sort agrees with List.insertionSort using the relation
supplied by the oracle.
This is the essential correctness statement: it identifies the query program as the
insertion sort operation, so correctness properties (permutation, sortedness) transfer
directly from the List.insertionSort API rather than being restated here.
Query count proofs #
Insertion sort makes at most n * (n - 1) / 2 queries: inserting into the sorted
prefix of length k costs at most k queries. This bound is attained by the all-false
oracle.