Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.merge-sort

The Applied Higher-Order Functions cataloguesrc/rainbow/algorithms/proofs/ahof/merge_sort.clj1 definitions, 3 theorems

AHoF Merge Sort: a stable, worst-case O(n log n) comparison sort by divide-and-conquer -- split the list in half, recursively sort each half, then MERGE the two sorted halves. The merge repeatedly emits the smaller of the two current heads; the decision (taking the left head on a tie keeps the sort stable) is: take-from-left? left-head right-head = decide (left-head <= right-head) over exact-rational keys. Proved native and axiom-free, as worked instances: left head 2 against right head 5 takes from the left; the worked certificate 2 <= 5 (native nnrat/at-most); and left head 7 against right head 3 yields to the right. That merge sort is correct and stable, and that the merged output stays sorted, are classical and not proved here; the split, recursion, and list plumbing are executable. Requires nnrat/at-most, audit/decide-nnrat-at-most, nnrat/decide-at-most-true-sound (all in the D63 checkpoint). Scope (measured by the kernel): this module has 3 worked instances (statements about specific values). None of its theorems is a guarantee about the algorithm for all inputs; `lein verify rainbow.algorithms.proofs.ahof.merge-sort` prints this classification.

merge-sort/take-from-left?

DefinitionSource, line 58

merge-sort/take-from-left? :
  (x₁ x₂ : ℚ≥0)
  → data/Bool

ℚ≥0 = nnrat/NonnegativeRational

merge-sort/emits-smaller-left

TheoremWorked exampleNo axiomsSource, line 69

merge-sort/emits-smaller-left :
  → lis/extends? 2 5 = data/true

= = equality/Eq

merge-sort/emitted-keeps-order

TheoremWorked exampleNo axiomsSource, line 78

merge-sort/emitted-keeps-order :
  → 2 ≤ 5

≤ = nnrat/at-most

merge-sort/larger-left-yields

TheoremWorked exampleNo axiomsSource, line 84

merge-sort/larger-left-yields :
  → lis/extends? 7 3 = data/false

= = equality/Eq