Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.binary-search

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

AHoF Binary Search: locate a target in a SORTED array in O(log n) by repeatedly halving the search interval -- comparing the target to the middle element and discarding the half that cannot contain it. The branch decision at each step is: search-left? target midpoint = decide (target <= midpoint) (if the target is at most the midpoint, it lies in the left half including the midpoint; otherwise in the right half), over exact-rational keys. Proved native and axiom-free: the branch test; that a target at most the midpoint searches left; the certificate that when it searches left the target really is at most the midpoint (native nnrat/at-most) so no candidate is wrongly discarded; and that a target above the midpoint searches right. The index arithmetic and the array access are executable; what is proved is the halving branch 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.binary-search` prints this classification.

binary-search/search-left?

DefinitionSource, line 57

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

ℚ≥0 = nnrat/NonnegativeRational

binary-search/small-target-searches-left

TheoremWorked exampleNo axiomsSource, line 68

binary-search/small-target-searches-left :
  → bin-packing/fits? 3 5 = data/true

= = equality/Eq

binary-search/left-branch-sound

TheoremWorked exampleNo axiomsSource, line 77

binary-search/left-branch-sound :
  → 3 ≤ 5

≤ = nnrat/at-most

binary-search/large-target-searches-right

TheoremWorked exampleNo axiomsSource, line 83

binary-search/large-target-searches-right :
  → bin-packing/fits? 8 5 = data/false

= = equality/Eq