Documentation

CslibFrontier.Languages.Probabilistic.Traverse.FindM

Monadic list search with an oracle program #

Running an oracle test List.findM? on a list evaluates against a deterministic oracle as List.find? (Cslib.OracleComp.evalPure_findM?), satisfies a cost bound xs.length * n when each test costs at most n (Cslib.OracleComp.IsCostBounded.findM?), and preserves query predicates (Cslib.OracleComp.QueriesSatisfy.findM?). For steps returning an Option via List.findSomeM?, Cslib.OracleComp.evalPure_findSomeM? and Cslib.OracleComp.IsCostBounded.findSomeM? give the corresponding deterministic evaluation and xs.length * n cost bound. These are the search counterparts of Cslib.OracleComp.IsCostBounded.mapM and Cslib.OracleComp.QueriesSatisfy.mapM in CslibFrontier.Languages.Probabilistic.Traverse.SupportWith.

Main results #

@[simp]
theorem Cslib.OracleComp.evalPure_findSomeM? {ι : Type} {spec : OracleSpec ι} {α : Type} (h : (q : ι) → spec q) {β : Type} (f : α → OracleComp spec (Option β)) (xs : List α) :
evalPure h (List.findSomeM? f xs) = List.findSome? (fun (x : α) => evalPure h (f x)) xs

Against a deterministic oracle, findSomeM? is findSome? on the steps' values: the search returns the first some value produced.

@[simp]
theorem Cslib.OracleComp.evalPure_findM? {ι : Type} {spec : OracleSpec ι} {α : Type} (h : (q : ι) → spec q) (test : α → OracleComp spec Bool) (xs : List α) :
evalPure h (List.findM? test xs) = List.find? (fun (x : α) => evalPure h (test x)) xs

Against a deterministic oracle, findM? is find? on the tests' values: the search returns the first element whose test evaluates to true.

theorem Cslib.OracleComp.IsCostBounded.findSomeM? {ι : Type} {spec : OracleSpec ι} {α : Type} {cost : ι → ℕ} {β : Type} {f : α → OracleComp spec (Option β)} {n : ℕ} {xs : List α} (h : ∀ a ∈ xs, IsCostBounded cost (f a) n) :

A findSomeM? search whose steps each cost at most n costs at most xs.length * n on every path. The bound can be attained when no step returns some; it does not use that the search stops at the first kept result.

theorem Cslib.OracleComp.IsCostBounded.findM? {ι : Type} {spec : OracleSpec ι} {α : Type} {cost : ι → ℕ} {test : α → OracleComp spec Bool} {n : ℕ} {xs : List α} (h : ∀ a ∈ xs, IsCostBounded cost (test a) n) :
IsCostBounded cost (List.findM? test xs) (xs.length * n)

A search whose tests each cost at most n costs at most xs.length * n on every path. The bound can be attained when no test accepts; it does not use that the search stops at the first accepted element.

theorem Cslib.OracleComp.QueriesSatisfy.findM? {ι : Type} {spec : OracleSpec ι} {α : Type} {p : ι → Prop} {test : α → OracleComp spec Bool} {xs : List α} (h : ∀ a ∈ xs, QueriesSatisfy p (test a)) :

A search whose tests' calls all satisfy p makes only calls satisfying p.