Imports
Chapter 6 - Heapsort
Chapter 6 introduces heaps, the heapsort algorithm, and max-priority queues.
The current CLRS-Lean pass has two layers. The compact functional layer remains
as a small mathematical scaffold for sortedness and permutation facts. The
reader-facing array layer now contains the zero-based CLRS child/parent
formulas, an indexed heap predicate, MAX-HEAPIFY's recursive repair
theorem, bottom-up BUILD-MAX-HEAP by repeated heapify, the executable
in-place HEAPSORT loop with a proved sorted-suffix invariant and
sortedness theorem, and the array-level HEAP-MAXIMUM theorem.
Sections
-
6.1 Heaps:
provedfor the indexed heap predicate and root maximum. Main results:CLRS.Chapter06.parent_lt_self,CLRS.Chapter06.eq_left_or_right_parent,CLRS.Chapter06.ArrayMaxHeap.getElem_le_root, andCLRS.Chapter06.orderedDesc_arrayMaxHeap; localized predicates:CLRS.Chapter06.ArrayMaxHeapFrom.to_globalandCLRS.Chapter06.ArrayMaxHeapExceptFrom.to_global. -
6.2 Maintaining the heap property:
provedfor fuelledMAX-HEAPIFYrecursive repair. Main results:CLRS.Chapter06.swapAt_perm,CLRS.Chapter06.maxHeapifyFuel_perm,CLRS.Chapter06.maxHeapifyFuel_valAt_of_heapSize_le, andCLRS.Chapter06.arrayMaxHeap_of_except_of_maxChildIndex_self; recursive repair:CLRS.Chapter06.maxHeapifyFuel_child_repair_after_swap,CLRS.Chapter06.maxHeapifyFuel_swap_branch_repair,CLRS.Chapter06.maxHeapifyFuel_repair_subtreeandCLRS.Chapter06.maxHeapifyFuel_root_isMaxHeap. -
6.3 Building a heap:
provedfor the bottom-up repeatedMAX-HEAPIFYbuilder. Main results:CLRS.Chapter06.ArrayMaxHeapFrom.of_half,CLRS.Chapter06.buildMaxHeapLoop_isMaxHeap,CLRS.Chapter06.buildMaxHeapLoop_perm,CLRS.Chapter06.arrayBuildMaxHeap_isMaxHeapandCLRS.Chapter06.arrayBuildMaxHeap_correct. -
6.4 The heapsort algorithm:
provedfor the in-place CLRS loop refinement. Loop facts:CLRS.Chapter06.arrayHeapSortInPlaceLoop_length,CLRS.Chapter06.arrayHeapSortInPlaceLoop_perm,CLRS.Chapter06.arrayHeapSortInPlace_length, andCLRS.Chapter06.arrayHeapSortInPlace_perm; invariant facts:CLRS.Chapter06.HeapSortLoopInvariant.initial,CLRS.Chapter06.arrayHeapSortStep_suffix_head_eq_root,CLRS.Chapter06.arrayHeapSortStep_suffix_head_bounds_prefix,CLRS.Chapter06.HeapSortLoopInvariant.step,CLRS.Chapter06.arrayHeapSortStep_state_correct,CLRS.Chapter06.arrayHeapSortInPlaceLoop_exact_shrink_invariant,CLRS.Chapter06.arrayHeapSortInPlaceLoop_exact_terminal_invariant,CLRS.Chapter06.arrayHeapSortInPlaceLoop_terminal_invariant, andCLRS.Chapter06.arrayHeapSortInPlaceLoop_orderedAsc; state package:CLRS.Chapter06.arrayHeapSortInPlaceLoop_state_correctandCLRS.Chapter06.arrayHeapSortInPlaceLoop_exact_state_correct. Main specification results:CLRS.Chapter06.arrayHeapSortInPlace_terminal_invariant,CLRS.Chapter06.arrayHeapSortInPlace_orderedAsc,CLRS.Chapter06.arrayHeapSortInPlace_state_correct,CLRS.Chapter06.arrayHeapSortInPlace_exact_state_correct,CLRS.Chapter06.arrayHeapSortInPlace_correct,CLRS.Chapter06.arrayHeapSort_eq_arrayHeapSortInPlace,CLRS.Chapter06.arrayHeapSort_terminal_invariant,CLRS.Chapter06.arrayHeapSort_state_correct,CLRS.Chapter06.arrayHeapSort_exact_state_correct, andCLRS.Chapter06.arrayHeapSort_correct. -
6.5 Priority queues:
provedfor the functional heap interface, with array-levelHEAP-MAXIMUM, full fuelledHEAP-INCREASE-KEY,HEAP-EXTRACT-MAX, andHEAP-DELETEstate theorems. Main results:CLRS.Chapter06.heapInsert_orderedDesc,CLRS.Chapter06.heapInsert_perm,CLRS.Chapter06.heapIncreaseKey_orderedDesc, andCLRS.Chapter06.heapDelete_orderedDesc; array result:CLRS.Chapter06.arrayHeapMaximum?_max,CLRS.Chapter06.ArrayMaxHeap.set_increased_except_up,CLRS.Chapter06.ArrayMaxHeapExceptUp.bubble_step,CLRS.Chapter06.ArrayMaxHeapExceptUp.bubbleUpFuel_global,CLRS.Chapter06.arrayHeapIncreaseKey?_state_correct,CLRS.Chapter06.arrayHeapIncreaseKeyNoBubble?_state_correct,CLRS.Chapter06.arrayHeapExtractMax?_state_correct, andCLRS.Chapter06.arrayHeapDelete?_state_correct.
Current Gaps
Runtime/RAM semantics remain refinement targets.
namespace CLRSnamespace Chapter06end Chapter06end CLRS