Correctness of Array.qsort #
We prove that Array.qsort lt lo hi permutes its input, leaves the array unchanged outside the
range lo..=hi, and sorts that range whenever lt is asymmetric and ¬lt is transitive.
theorem Array.qsort_sorted {α : Type u_1} {xs : Array α} {lt : α → α → Bool} {lo hi : Nat} (asymm : ∀ (a b : α), lt a b = true → ¬lt b a = true) (trans : ∀ (a b c : α), ¬lt a b = true → ¬lt b c = true → ¬lt a c = true) {i j : Nat} (hlo : lo ≤ i) (hij : i < j) (hj : j ≤ hi) (hj' : j < (xs.qsort lt lo hi).size) :
Array.qsort lt lo hi sorts the range lo..=hi of the array, as long as lt is asymmetric
and its negation is transitive (¬lt a b → ¬lt b c → ¬lt a c).
theorem Array.pairwise_qsort {α : Type u_1} {xs : Array α} {lt : α → α → Bool} (asymm : ∀ (a b : α), lt a b = true → ¬lt b a = true) (trans : ∀ (a b c : α), ¬lt a b = true → ¬lt b c = true → ¬lt a c = true) :
The result of Array.qsort is sorted, as long as lt is asymmetric and its negation is
transitive (¬lt a b → ¬lt b c → ¬lt a c).