Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.sliding-window

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

AHoF Sliding Window: solve subarray/substring problems in one O(n) pass by maintaining a window that slides across the data, adding the entering element and removing the leaving one instead of recomputing over each subarray. For a variable-size window under a budget (e.g. longest subarray whose sum stays within a limit), the window is VALID while its running aggregate stays within the constraint: window-valid? window-value limit = decide (window-value <= limit) over exact-rational aggregates. Proved native and axiom-free: the window-validity test; that a window within the budget is valid (the right edge may keep growing); the certificate that a valid window's value really is within the limit (native nnrat/at-most); and that a window exceeding the budget is invalid (the left edge must shrink). The incremental add/remove of window elements is executable; what is proved is the window-validity 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.sliding-window` prints this classification.

sliding-window/window-valid?

DefinitionSource, line 59

sliding-window/window-valid? :
  (x₁ x₂ : ℚ≥0)
  → data/Bool

ℚ≥0 = nnrat/NonnegativeRational

sliding-window/within-budget-valid

TheoremWorked exampleNo axiomsSource, line 70

sliding-window/within-budget-valid :
  → lis/extends? 3 5 = data/true

= = equality/Eq

sliding-window/valid-window-within-limit

TheoremWorked exampleNo axiomsSource, line 78

sliding-window/valid-window-within-limit :
  → 3 ≤ 5

≤ = nnrat/at-most

sliding-window/over-budget-invalid

TheoremWorked exampleNo axiomsSource, line 84

sliding-window/over-budget-invalid :
  → lis/extends? 8 5 = data/false

= = equality/Eq