Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.binary-heap

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

AHoF Binary Heap: the array-backed complete binary tree behind the priority queue and heapsort, maintaining the HEAP PROPERTY -- in a min-heap every parent key is at most its children's keys, so the minimum is always at the root. Insert (sift-up) and extract-min (sift-down) restore the property in O(log n) by swapping a node with a child that violates it. The heap-order test between a parent and a child is: heap-ordered? parent child = decide (parent <= child) over exact-rational keys. Proved native and axiom-free: the heap-order test; worked instances on concrete keys -- a parent 2 over a child 5 is correctly ordered (no swap needed); the certificate 2 <= 5 as a native nnrat/at-most; and a parent 7 over a child 3 violates the property (sift must swap). The array indexing and the sift-up/down loops are executable; what is proved is the heap-order comparison at these instances, not the heap invariant itself. 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.binary-heap` prints this classification.

binary-heap/heap-ordered?

DefinitionSource, line 59

binary-heap/heap-ordered? :
  (x₁ x₂ : ℚ≥0)
  → data/Bool

ℚ≥0 = nnrat/NonnegativeRational

binary-heap/parent-below-child-ordered

TheoremWorked exampleNo axiomsSource, line 70

binary-heap/parent-below-child-ordered :
  → bin-packing/fits? 2 5 = data/true

= = equality/Eq

binary-heap/ordered-parent-at-most-child

TheoremWorked exampleNo axiomsSource, line 78

binary-heap/ordered-parent-at-most-child :
  → 2 ≤ 5

≤ = nnrat/at-most

binary-heap/parent-above-child-violates

TheoremWorked exampleNo axiomsSource, line 84

binary-heap/parent-above-child-violates :
  → bin-packing/fits? 7 3 = data/false

= = equality/Eq