Reference · The Applied Higher-Order Functions catalogue
rainbow.algorithms.proofs.ahof.union-by-rank
AHoF Union by Rank: the balancing optimization that keeps a Union-Find (disjoint set) forest shallow, so find/union run in near-constant amortized time (inverse Ackermann, with path compression). When merging two sets, the root of the SHALLOWER tree is attached under the root of the deeper one -- comparing ranks (upper bounds on tree height) decides which becomes the child: attach-under? rank-a rank-b = decide (rank-a <= rank-b) (attach root A under root B when A's rank is at most B's), over exact-rational (integer) ranks. Proved native and axiom-free: the attach decision; that the lower-rank root is attached under the higher-rank root; the certificate that the attached root really has rank at most the other's (native nnrat/at-most) -- so the merged tree's height does not grow unnecessarily; and that a higher-rank root becomes the parent. The parent pointers and path compression are executable; what is proved is the union-by-rank attach decision. 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.union-by-rank` prints this classification.
union-by-rank/attach-under?
union-by-rank/attach-under? : (x₁ x₂ : ℚ≥0) → data/Bool
ℚ≥0 = nnrat/NonnegativeRational
union-by-rank/lower-rank-attached-under
union-by-rank/lower-rank-attached-under : → lis/extends? 2 4 = data/true
= = equality/Eq
union-by-rank/attached-rank-at-most
union-by-rank/attached-rank-at-most : → 2 ≤ 4
≤ = nnrat/at-most
union-by-rank/higher-rank-becomes-parent
union-by-rank/higher-rank-becomes-parent : → lis/extends? 5 3 = data/false
= = equality/Eq