Basic properties of mergeSort. #
sorted_mergeSort:mergeSortproduces a sorted list.mergeSort_perm:mergeSortis a permutation of the input list.mergeSort_of_sorted:mergeSortdoes not change a sorted list.mergeSort_cons: provesmergeSort le (x :: xs) = l₁ ++ x :: l₂for somel₁, l₂so thatmergeSort le xs = l₁ ++ l₂, and noa ∈ l₁satisfiesle a x.sublist_mergeSort: ifcis a sorted sublist ofl, thencis still a sublist ofmergeSort le l.
splitInTwo #
zipIdxLE #
merge #
If the ordering relation le is transitive and total (i.e. le a b || le b a for all a, b)
then the merge of two sorted lists is sorted.
mergeSort #
The result of mergeSort is sorted,
as long as the comparison function is transitive (le a b → le b c → le a c)
and total in the sense that le a b || le b a.
The comparison function need not be irreflexive, i.e. le a b and le b a is allowed even when a ≠ b.
This merge sort algorithm is stable, in the sense that breaking ties in the ordering function using the position in the list has no effect on the output.
That is, elements which are equal with respect to the ordering function will remain in the same order in the output list as they were in the input list.
See also:
sublist_mergeSort: ifc <+ landc.Pairwise le, thenc <+ mergeSort le l.pair_sublist_mergeSort: if[a, b] <+ landle a b, then[a, b] <+ mergeSort le l)
Another statement of stability of merge sort.
If c is a sorted sublist of l,
then c is still a sublist of mergeSort le l.
Another statement of stability of merge sort.
If a pair [a, b] is a sublist of l and le a b,
then [a, b] is still a sublist of mergeSort le l.