Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.union-by-rank

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

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?

DefinitionSource, line 59

union-by-rank/attach-under? :
  (x₁ x₂ : ℚ≥0)
  → data/Bool

ℚ≥0 = nnrat/NonnegativeRational

union-by-rank/lower-rank-attached-under

TheoremWorked exampleNo axiomsSource, line 71

union-by-rank/lower-rank-attached-under :
  → lis/extends? 2 4 = data/true

= = equality/Eq

union-by-rank/attached-rank-at-most

TheoremWorked exampleNo axiomsSource, line 80

union-by-rank/attached-rank-at-most :
  → 2 ≤ 4

≤ = nnrat/at-most

union-by-rank/higher-rank-becomes-parent

TheoremWorked exampleNo axiomsSource, line 87

union-by-rank/higher-rank-becomes-parent :
  → lis/extends? 5 3 = data/false

= = equality/Eq