Documentation

CslibFrontier.Foundations.Data.Nat.FindCode

First match in a bounded natural-number range #

Cslib.findCode visits consecutive candidates in order and returns the first passing one, with no allocated list of candidates. Its specification uses the existing List.find?.

Main definitions #

Main results #

def Cslib.findCode (p : ℕ → Bool) (start count : ℕ) :

Search count consecutive natural numbers from start, returning the first match. The implementation keeps only the current candidate and remaining count.

theorem Cslib.findCode_eq (p : ℕ → Bool) (i fuel : ℕ) :
findCode p i fuel = List.find? p (List.range' i fuel)

The bounded search agrees with first-match lookup in the corresponding range.